This commit is contained in:
季圣华
2016-10-30 17:13:58 +08:00
parent 6c2a372179
commit a67629d0f7
530 changed files with 63963 additions and 0 deletions

View File

@@ -0,0 +1,405 @@
/**
* easyloader - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*
*/
(function(){
var modules = {
draggable:{
js:'jquery.draggable.js'
},
droppable:{
js:'jquery.droppable.js'
},
resizable:{
js:'jquery.resizable.js'
},
linkbutton:{
js:'jquery.linkbutton.js',
css:'linkbutton.css'
},
progressbar:{
js:'jquery.progressbar.js',
css:'progressbar.css'
},
tooltip:{
js:'jquery.tooltip.js',
css:'tooltip.css'
},
pagination:{
js:'jquery.pagination.js',
css:'pagination.css',
dependencies:['linkbutton']
},
datagrid:{
js:'jquery.datagrid.js',
css:'datagrid.css',
dependencies:['panel','resizable','linkbutton','pagination']
},
treegrid:{
js:'jquery.treegrid.js',
css:'tree.css',
dependencies:['datagrid']
},
propertygrid:{
js:'jquery.propertygrid.js',
css:'propertygrid.css',
dependencies:['datagrid']
},
panel: {
js:'jquery.panel.js',
css:'panel.css'
},
window:{
js:'jquery.window.js',
css:'window.css',
dependencies:['resizable','draggable','panel']
},
dialog:{
js:'jquery.dialog.js',
css:'dialog.css',
dependencies:['linkbutton','window']
},
messager:{
js:'jquery.messager.js',
css:'messager.css',
dependencies:['linkbutton','window','progressbar']
},
layout:{
js:'jquery.layout.js',
css:'layout.css',
dependencies:['resizable','panel']
},
form:{
js:'jquery.form.js'
},
menu:{
js:'jquery.menu.js',
css:'menu.css'
},
tabs:{
js:'jquery.tabs.js',
css:'tabs.css',
dependencies:['panel','linkbutton']
},
menubutton:{
js:'jquery.menubutton.js',
css:'menubutton.css',
dependencies:['linkbutton','menu']
},
splitbutton:{
js:'jquery.splitbutton.js',
css:'splitbutton.css',
dependencies:['menubutton']
},
accordion:{
js:'jquery.accordion.js',
css:'accordion.css',
dependencies:['panel']
},
calendar:{
js:'jquery.calendar.js',
css:'calendar.css'
},
combo:{
js:'jquery.combo.js',
css:'combo.css',
dependencies:['panel','validatebox']
},
combobox:{
js:'jquery.combobox.js',
css:'combobox.css',
dependencies:['combo']
},
combotree:{
js:'jquery.combotree.js',
dependencies:['combo','tree']
},
combogrid:{
js:'jquery.combogrid.js',
dependencies:['combo','datagrid']
},
validatebox:{
js:'jquery.validatebox.js',
css:'validatebox.css',
dependencies:['tooltip']
},
numberbox:{
js:'jquery.numberbox.js',
dependencies:['validatebox']
},
searchbox:{
js:'jquery.searchbox.js',
css:'searchbox.css',
dependencies:['menubutton']
},
spinner:{
js:'jquery.spinner.js',
css:'spinner.css',
dependencies:['validatebox']
},
numberspinner:{
js:'jquery.numberspinner.js',
dependencies:['spinner','numberbox']
},
timespinner:{
js:'jquery.timespinner.js',
dependencies:['spinner']
},
tree:{
js:'jquery.tree.js',
css:'tree.css',
dependencies:['draggable','droppable']
},
datebox:{
js:'jquery.datebox.js',
css:'datebox.css',
dependencies:['calendar','combo']
},
datetimebox:{
js:'jquery.datetimebox.js',
dependencies:['datebox','timespinner']
},
slider:{
js:'jquery.slider.js',
dependencies:['draggable']
},
tooltip:{
js:'jquery.tooltip.js'
},
parser:{
js:'jquery.parser.js'
}
};
var locales = {
'af':'easyui-lang-af.js',
'ar':'easyui-lang-ar.js',
'bg':'easyui-lang-bg.js',
'ca':'easyui-lang-ca.js',
'cs':'easyui-lang-cs.js',
'cz':'easyui-lang-cz.js',
'da':'easyui-lang-da.js',
'de':'easyui-lang-de.js',
'el':'easyui-lang-el.js',
'en':'easyui-lang-en.js',
'es':'easyui-lang-es.js',
'fr':'easyui-lang-fr.js',
'it':'easyui-lang-it.js',
'jp':'easyui-lang-jp.js',
'nl':'easyui-lang-nl.js',
'pl':'easyui-lang-pl.js',
'pt_BR':'easyui-lang-pt_BR.js',
'ru':'easyui-lang-ru.js',
'sv_SE':'easyui-lang-sv_SE.js',
'tr':'easyui-lang-tr.js',
'zh_CN':'easyui-lang-zh_CN.js',
'zh_TW':'easyui-lang-zh_TW.js'
};
var queues = {};
function loadJs(url, callback){
var done = false;
var script = document.createElement('script');
script.type = 'text/javascript';
script.language = 'javascript';
script.src = url;
script.onload = script.onreadystatechange = function(){
if (!done && (!script.readyState || script.readyState == 'loaded' || script.readyState == 'complete')){
done = true;
script.onload = script.onreadystatechange = null;
if (callback){
callback.call(script);
}
}
}
document.getElementsByTagName("head")[0].appendChild(script);
}
function runJs(url, callback){
loadJs(url, function(){
document.getElementsByTagName("head")[0].removeChild(this);
if (callback){
callback();
}
});
}
function loadCss(url, callback){
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.media = 'screen';
link.href = url;
document.getElementsByTagName('head')[0].appendChild(link);
if (callback){
callback.call(link);
}
}
function loadSingle(name, callback){
queues[name] = 'loading';
var module = modules[name];
var jsStatus = 'loading';
var cssStatus = (easyloader.css && module['css']) ? 'loading' : 'loaded';
if (easyloader.css && module['css']){
if (/^http/i.test(module['css'])){
var url = module['css'];
} else {
var url = easyloader.base + 'themes/' + easyloader.theme + '/' + module['css'];
}
loadCss(url, function(){
cssStatus = 'loaded';
if (jsStatus == 'loaded' && cssStatus == 'loaded'){
finish();
}
});
}
if (/^http/i.test(module['js'])){
var url = module['js'];
} else {
var url = easyloader.base + 'plugins/' + module['js'];
}
loadJs(url, function(){
jsStatus = 'loaded';
if (jsStatus == 'loaded' && cssStatus == 'loaded'){
finish();
}
});
function finish(){
queues[name] = 'loaded';
easyloader.onProgress(name);
if (callback){
callback();
}
}
}
function loadModule(name, callback){
var mm = [];
var doLoad = false;
if (typeof name == 'string'){
add(name);
} else {
for(var i=0; i<name.length; i++){
add(name[i]);
}
}
function add(name){
if (!modules[name]) return;
var d = modules[name]['dependencies'];
if (d){
for(var i=0; i<d.length; i++){
add(d[i]);
}
}
mm.push(name);
}
function finish(){
if (callback){
callback();
}
easyloader.onLoad(name);
}
var time = 0;
function loadMm(){
if (mm.length){
var m = mm[0]; // the first module
if (!queues[m]){
doLoad = true;
loadSingle(m, function(){
mm.shift();
loadMm();
});
} else if (queues[m] == 'loaded'){
mm.shift();
loadMm();
} else {
if (time < easyloader.timeout){
time += 10;
setTimeout(arguments.callee, 10);
}
}
} else {
if (easyloader.locale && doLoad == true && locales[easyloader.locale]){
var url = easyloader.base + 'locale/' + locales[easyloader.locale];
runJs(url, function(){
finish();
});
} else {
finish();
}
}
}
loadMm();
}
easyloader = {
modules:modules,
locales:locales,
base:'.',
theme:'default',
css:true,
locale:null,
timeout:2000,
load: function(name, callback){
if (/\.css$/i.test(name)){
if (/^http/i.test(name)){
loadCss(name, callback);
} else {
loadCss(easyloader.base + name, callback);
}
} else if (/\.js$/i.test(name)){
if (/^http/i.test(name)){
loadJs(name, callback);
} else {
loadJs(easyloader.base + name, callback);
}
} else {
loadModule(name, callback);
}
},
onProgress: function(name){},
onLoad: function(name){}
};
var scripts = document.getElementsByTagName('script');
for(var i=0; i<scripts.length; i++){
var src = scripts[i].src;
if (!src) continue;
var m = src.match(/easyloader\.js(\W|$)/i);
if (m){
easyloader.base = src.substring(0, m.index);
}
}
window.using = easyloader.load;
if (window.jQuery){
jQuery(function(){
easyloader.load('parser', function(){
jQuery.parser.parse();
});
});
}
})();

View File

@@ -0,0 +1,410 @@
/**
* accordion - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*
* Dependencies:
* panel
*
*/
(function($){
function setSize(container){
var state = $.data(container, 'accordion');
var opts = state.options;
var panels = state.panels;
var cc = $(container);
opts.fit ? $.extend(opts, cc._fit()) : cc._fit(false);
if (!isNaN(opts.width)){
cc._outerWidth(opts.width);
} else {
cc.css('width', '');
}
var headerHeight = 0;
var bodyHeight = 'auto';
var headers = cc.find('>div.panel>div.accordion-header');
if (headers.length){
headerHeight = $(headers[0]).css('height', '')._outerHeight();
}
if (!isNaN(opts.height)){
cc._outerHeight(opts.height);
bodyHeight = cc.height() - headerHeight*headers.length;
} else {
cc.css('height', '');
}
_resize(true, bodyHeight - _resize(false) + 1);
function _resize(collapsible, height){
var totalHeight = 0;
for(var i=0; i<panels.length; i++){
var p = panels[i];
var h = p.panel('header')._outerHeight(headerHeight);
if (p.panel('options').collapsible == collapsible){
var pheight = isNaN(height) ? undefined : (height+headerHeight*h.length);
p.panel('resize', {
width: cc.width(),
height: (collapsible ? pheight : undefined)
});
totalHeight += p.panel('panel').outerHeight()-headerHeight;
}
}
return totalHeight;
}
}
/**
* find a panel by specified property, return the panel object or panel index.
*/
function findBy(container, property, value, all){
var panels = $.data(container, 'accordion').panels;
var pp = [];
for(var i=0; i<panels.length; i++){
var p = panels[i];
if (property){
if (p.panel('options')[property] == value){
pp.push(p);
}
} else {
if (p[0] == $(value)[0]){
return i;
}
}
}
if (property){
return all ? pp : (pp.length ? pp[0] : null);
} else {
return -1;
}
}
function getSelections(container){
return findBy(container, 'collapsed', false, true);
}
function getSelected(container){
var pp = getSelections(container);
return pp.length ? pp[0] : null;
}
/**
* get panel index, start with 0
*/
function getPanelIndex(container, panel){
return findBy(container, null, panel);
}
/**
* get the specified panel.
*/
function getPanel(container, which){
var panels = $.data(container, 'accordion').panels;
if (typeof which == 'number'){
if (which < 0 || which >= panels.length){
return null;
} else {
return panels[which];
}
}
return findBy(container, 'title', which);
}
function setProperties(container){
var opts = $.data(container, 'accordion').options;
var cc = $(container);
if (opts.border){
cc.removeClass('accordion-noborder');
} else {
cc.addClass('accordion-noborder');
}
}
function init(container){
var state = $.data(container, 'accordion');
var cc = $(container);
cc.addClass('accordion');
state.panels = [];
cc.children('div').each(function(){
var opts = $.extend({}, $.parser.parseOptions(this), {
selected: ($(this).attr('selected') ? true : undefined)
});
var pp = $(this);
state.panels.push(pp);
createPanel(container, pp, opts);
});
cc.bind('_resize', function(e,force){
var opts = $.data(container, 'accordion').options;
if (opts.fit == true || force){
setSize(container);
}
return false;
});
}
function createPanel(container, pp, options){
var opts = $.data(container, 'accordion').options;
pp.panel($.extend({}, {
collapsible: true,
minimizable: false,
maximizable: false,
closable: false,
doSize: false,
collapsed: true,
headerCls: 'accordion-header',
bodyCls: 'accordion-body'
}, options, {
onBeforeExpand: function(){
if (options.onBeforeExpand){
if (options.onBeforeExpand.call(this) == false){return false}
}
if (!opts.multiple){
// get all selected panel
var all = $.grep(getSelections(container), function(p){
return p.panel('options').collapsible;
});
for(var i=0; i<all.length; i++){
unselect(container, getPanelIndex(container, all[i]));
}
}
var header = $(this).panel('header');
header.addClass('accordion-header-selected');
header.find('.accordion-collapse').removeClass('accordion-expand');
},
onExpand: function(){
if (options.onExpand){options.onExpand.call(this)}
opts.onSelect.call(container, $(this).panel('options').title, getPanelIndex(container, this));
},
onBeforeCollapse: function(){
if (options.onBeforeCollapse){
if (options.onBeforeCollapse.call(this) == false){return false}
}
var header = $(this).panel('header');
header.removeClass('accordion-header-selected');
header.find('.accordion-collapse').addClass('accordion-expand');
},
onCollapse: function(){
if (options.onCollapse){options.onCollapse.call(this)}
opts.onUnselect.call(container, $(this).panel('options').title, getPanelIndex(container, this));
}
}));
var header = pp.panel('header');
var tool = header.children('div.panel-tool');
tool.children('a.panel-tool-collapse').hide(); // hide the old collapse button
var t = $('<a href="javascript:void(0)"></a>').addClass('accordion-collapse accordion-expand').appendTo(tool);
t.bind('click', function(){
var index = getPanelIndex(container, pp);
if (pp.panel('options').collapsed){
select(container, index);
} else {
unselect(container, index);
}
return false;
});
pp.panel('options').collapsible ? t.show() : t.hide();
header.click(function(){
$(this).find('a.accordion-collapse:visible').triggerHandler('click');
return false;
});
}
/**
* select and set the specified panel active
*/
function select(container, which){
var p = getPanel(container, which);
if (!p){return}
stopAnimate(container);
var opts = $.data(container, 'accordion').options;
p.panel('expand', opts.animate);
}
function unselect(container, which){
var p = getPanel(container, which);
if (!p){return}
stopAnimate(container);
var opts = $.data(container, 'accordion').options;
p.panel('collapse', opts.animate);
}
function doFirstSelect(container){
var opts = $.data(container, 'accordion').options;
var p = findBy(container, 'selected', true);
if (p){
_select(getPanelIndex(container, p));
} else {
_select(opts.selected);
}
function _select(index){
var animate = opts.animate;
opts.animate = false;
select(container, index);
opts.animate = animate;
}
}
/**
* stop the animation of all panels
*/
function stopAnimate(container){
var panels = $.data(container, 'accordion').panels;
for(var i=0; i<panels.length; i++){
panels[i].stop(true,true);
}
}
function add(container, options){
var state = $.data(container, 'accordion');
var opts = state.options;
var panels = state.panels;
if (options.selected == undefined) options.selected = true;
stopAnimate(container);
var pp = $('<div></div>').appendTo(container);
panels.push(pp);
createPanel(container, pp, options);
setSize(container);
opts.onAdd.call(container, options.title, panels.length-1);
if (options.selected){
select(container, panels.length-1);
}
}
function remove(container, which){
var state = $.data(container, 'accordion');
var opts = state.options;
var panels = state.panels;
stopAnimate(container);
var panel = getPanel(container, which);
var title = panel.panel('options').title;
var index = getPanelIndex(container, panel);
if (!panel){return}
if (opts.onBeforeRemove.call(container, title, index) == false){return}
panels.splice(index, 1);
panel.panel('destroy');
if (panels.length){
setSize(container);
var curr = getSelected(container);
if (!curr){
select(container, 0);
}
}
opts.onRemove.call(container, title, index);
}
$.fn.accordion = function(options, param){
if (typeof options == 'string'){
return $.fn.accordion.methods[options](this, param);
}
options = options || {};
return this.each(function(){
var state = $.data(this, 'accordion');
if (state){
$.extend(state.options, options);
} else {
$.data(this, 'accordion', {
options: $.extend({}, $.fn.accordion.defaults, $.fn.accordion.parseOptions(this), options),
accordion: $(this).addClass('accordion'),
panels: []
});
init(this);
}
setProperties(this);
setSize(this);
doFirstSelect(this);
});
};
$.fn.accordion.methods = {
options: function(jq){
return $.data(jq[0], 'accordion').options;
},
panels: function(jq){
return $.data(jq[0], 'accordion').panels;
},
resize: function(jq){
return jq.each(function(){
setSize(this);
});
},
getSelections: function(jq){
return getSelections(jq[0]);
},
getSelected: function(jq){
return getSelected(jq[0]);
},
getPanel: function(jq, which){
return getPanel(jq[0], which);
},
getPanelIndex: function(jq, panel){
return getPanelIndex(jq[0], panel);
},
select: function(jq, which){
return jq.each(function(){
select(this, which);
});
},
unselect: function(jq, which){
return jq.each(function(){
unselect(this, which);
});
},
add: function(jq, options){
return jq.each(function(){
add(this, options);
});
},
remove: function(jq, which){
return jq.each(function(){
remove(this, which);
});
}
};
$.fn.accordion.parseOptions = function(target){
var t = $(target);
return $.extend({}, $.parser.parseOptions(target, [
'width','height',
{fit:'boolean',border:'boolean',animate:'boolean',multiple:'boolean',selected:'number'}
]));
};
$.fn.accordion.defaults = {
width: 'auto',
height: 'auto',
fit: false,
border: true,
animate: true,
multiple: false,
selected: 0,
onSelect: function(title, index){},
onUnselect: function(title, index){},
onAdd: function(title, index){},
onBeforeRemove: function(title, index){},
onRemove: function(title, index){}
};
})(jQuery);

View File

@@ -0,0 +1,392 @@
/**
* calendar - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*
*/
(function($){
function setSize(target){
var opts = $.data(target, 'calendar').options;
var t = $(target);
// if (opts.fit == true){
// var p = t.parent();
// opts.width = p.width();
// opts.height = p.height();
// }
opts.fit ? $.extend(opts, t._fit()) : t._fit(false);
var header = t.find('.calendar-header');
t._outerWidth(opts.width);
t._outerHeight(opts.height);
t.find('.calendar-body')._outerHeight(t.height() - header._outerHeight());
}
function init(target){
$(target).addClass('calendar').html(
'<div class="calendar-header">' +
'<div class="calendar-prevmonth"></div>' +
'<div class="calendar-nextmonth"></div>' +
'<div class="calendar-prevyear"></div>' +
'<div class="calendar-nextyear"></div>' +
'<div class="calendar-title">' +
'<span>Aprial 2010</span>' +
'</div>' +
'</div>' +
'<div class="calendar-body">' +
'<div class="calendar-menu">' +
'<div class="calendar-menu-year-inner">' +
'<span class="calendar-menu-prev"></span>' +
'<span><input class="calendar-menu-year" type="text"></input></span>' +
'<span class="calendar-menu-next"></span>' +
'</div>' +
'<div class="calendar-menu-month-inner">' +
'</div>' +
'</div>' +
'</div>'
);
$(target).find('.calendar-title span').hover(
function(){$(this).addClass('calendar-menu-hover');},
function(){$(this).removeClass('calendar-menu-hover');}
).click(function(){
var menu = $(target).find('.calendar-menu');
if (menu.is(':visible')){
menu.hide();
} else {
showSelectMenus(target);
}
});
$('.calendar-prevmonth,.calendar-nextmonth,.calendar-prevyear,.calendar-nextyear', target).hover(
function(){$(this).addClass('calendar-nav-hover');},
function(){$(this).removeClass('calendar-nav-hover');}
);
$(target).find('.calendar-nextmonth').click(function(){
showMonth(target, 1);
});
$(target).find('.calendar-prevmonth').click(function(){
showMonth(target, -1);
});
$(target).find('.calendar-nextyear').click(function(){
showYear(target, 1);
});
$(target).find('.calendar-prevyear').click(function(){
showYear(target, -1);
});
$(target).bind('_resize', function(){
var opts = $.data(target, 'calendar').options;
if (opts.fit == true){
setSize(target);
}
return false;
});
}
/**
* show the calendar corresponding to the current month.
*/
function showMonth(target, delta){
var opts = $.data(target, 'calendar').options;
opts.month += delta;
if (opts.month > 12){
opts.year++;
opts.month = 1;
} else if (opts.month < 1){
opts.year--;
opts.month = 12;
}
show(target);
var menu = $(target).find('.calendar-menu-month-inner');
menu.find('td.calendar-selected').removeClass('calendar-selected');
menu.find('td:eq(' + (opts.month-1) + ')').addClass('calendar-selected');
}
/**
* show the calendar corresponding to the current year.
*/
function showYear(target, delta){
var opts = $.data(target, 'calendar').options;
opts.year += delta;
show(target);
var menu = $(target).find('.calendar-menu-year');
menu.val(opts.year);
}
/**
* show the select menu that can change year or month, if the menu is not be created then create it.
*/
function showSelectMenus(target){
var opts = $.data(target, 'calendar').options;
$(target).find('.calendar-menu').show();
if ($(target).find('.calendar-menu-month-inner').is(':empty')){
$(target).find('.calendar-menu-month-inner').empty();
var t = $('<table></table>').appendTo($(target).find('.calendar-menu-month-inner'));
var idx = 0;
for(var i=0; i<3; i++){
var tr = $('<tr></tr>').appendTo(t);
for(var j=0; j<4; j++){
$('<td class="calendar-menu-month"></td>').html(opts.months[idx++]).attr('abbr',idx).appendTo(tr);
}
}
$(target).find('.calendar-menu-prev,.calendar-menu-next').hover(
function(){$(this).addClass('calendar-menu-hover');},
function(){$(this).removeClass('calendar-menu-hover');}
);
$(target).find('.calendar-menu-next').click(function(){
var y = $(target).find('.calendar-menu-year');
if (!isNaN(y.val())){
y.val(parseInt(y.val()) + 1);
}
});
$(target).find('.calendar-menu-prev').click(function(){
var y = $(target).find('.calendar-menu-year');
if (!isNaN(y.val())){
y.val(parseInt(y.val() - 1));
}
});
$(target).find('.calendar-menu-year').keypress(function(e){
if (e.keyCode == 13){
setDate();
}
});
$(target).find('.calendar-menu-month').hover(
function(){$(this).addClass('calendar-menu-hover');},
function(){$(this).removeClass('calendar-menu-hover');}
).click(function(){
var menu = $(target).find('.calendar-menu');
menu.find('.calendar-selected').removeClass('calendar-selected');
$(this).addClass('calendar-selected');
setDate();
});
}
function setDate(){
var menu = $(target).find('.calendar-menu');
var year = menu.find('.calendar-menu-year').val();
var month = menu.find('.calendar-selected').attr('abbr');
if (!isNaN(year)){
opts.year = parseInt(year);
opts.month = parseInt(month);
show(target);
}
menu.hide();
}
var body = $(target).find('.calendar-body');
var sele = $(target).find('.calendar-menu');
var seleYear = sele.find('.calendar-menu-year-inner');
var seleMonth = sele.find('.calendar-menu-month-inner');
seleYear.find('input').val(opts.year).focus();
seleMonth.find('td.calendar-selected').removeClass('calendar-selected');
seleMonth.find('td:eq('+(opts.month-1)+')').addClass('calendar-selected');
sele._outerWidth(body._outerWidth());
sele._outerHeight(body._outerHeight());
seleMonth._outerHeight(sele.height() - seleYear._outerHeight());
}
/**
* get weeks data.
*/
function getWeeks(target, year, month){
var opts = $.data(target, 'calendar').options;
var dates = [];
var lastDay = new Date(year, month, 0).getDate();
for(var i=1; i<=lastDay; i++) dates.push([year,month,i]);
// group date by week
var weeks = [], week = [];
// var memoDay = 0;
var memoDay = -1;
while(dates.length > 0){
var date = dates.shift();
week.push(date);
var day = new Date(date[0],date[1]-1,date[2]).getDay();
if (memoDay == day){
day = 0;
} else if (day == (opts.firstDay==0 ? 7 : opts.firstDay) - 1){
weeks.push(week);
week = [];
}
memoDay = day;
}
if (week.length){
weeks.push(week);
}
var firstWeek = weeks[0];
if (firstWeek.length < 7){
while(firstWeek.length < 7){
var firstDate = firstWeek[0];
var date = new Date(firstDate[0],firstDate[1]-1,firstDate[2]-1)
firstWeek.unshift([date.getFullYear(), date.getMonth()+1, date.getDate()]);
}
} else {
var firstDate = firstWeek[0];
var week = [];
for(var i=1; i<=7; i++){
var date = new Date(firstDate[0], firstDate[1]-1, firstDate[2]-i);
week.unshift([date.getFullYear(), date.getMonth()+1, date.getDate()]);
}
weeks.unshift(week);
}
var lastWeek = weeks[weeks.length-1];
while(lastWeek.length < 7){
var lastDate = lastWeek[lastWeek.length-1];
var date = new Date(lastDate[0], lastDate[1]-1, lastDate[2]+1);
lastWeek.push([date.getFullYear(), date.getMonth()+1, date.getDate()]);
}
if (weeks.length < 6){
var lastDate = lastWeek[lastWeek.length-1];
var week = [];
for(var i=1; i<=7; i++){
var date = new Date(lastDate[0], lastDate[1]-1, lastDate[2]+i);
week.push([date.getFullYear(), date.getMonth()+1, date.getDate()]);
}
weeks.push(week);
}
return weeks;
}
/**
* show the calendar day.
*/
function show(target){
var opts = $.data(target, 'calendar').options;
$(target).find('.calendar-title span').html(opts.months[opts.month-1] + ' ' + opts.year);
var body = $(target).find('div.calendar-body');
body.find('>table').remove();
var t = $('<table cellspacing="0" cellpadding="0" border="0"><thead></thead><tbody></tbody></table>').prependTo(body);
var tr = $('<tr></tr>').appendTo(t.find('thead'));
for(var i=opts.firstDay; i<opts.weeks.length; i++){
tr.append('<th>'+opts.weeks[i]+'</th>');
}
for(var i=0; i<opts.firstDay; i++){
tr.append('<th>'+opts.weeks[i]+'</th>');
}
var weeks = getWeeks(target, opts.year, opts.month);
for(var i=0; i<weeks.length; i++){
var week = weeks[i];
var tr = $('<tr></tr>').appendTo(t.find('tbody'));
for(var j=0; j<week.length; j++){
var day = week[j];
$('<td class="calendar-day calendar-other-month"></td>').attr('abbr',day[0]+','+day[1]+','+day[2]).html(day[2]).appendTo(tr);
}
}
t.find('td[abbr^="'+opts.year+','+opts.month+'"]').removeClass('calendar-other-month');
var now = new Date();
var today = now.getFullYear()+','+(now.getMonth()+1)+','+now.getDate();
t.find('td[abbr="'+today+'"]').addClass('calendar-today');
if (opts.current){
t.find('.calendar-selected').removeClass('calendar-selected');
var current = opts.current.getFullYear()+','+(opts.current.getMonth()+1)+','+opts.current.getDate();
t.find('td[abbr="'+current+'"]').addClass('calendar-selected');
}
// calulate the saturday and sunday index
var saIndex = 6 - opts.firstDay;
var suIndex = saIndex + 1;
if (saIndex >= 7) saIndex -= 7;
if (suIndex >= 7) suIndex -= 7;
t.find('tr').find('td:eq('+saIndex+')').addClass('calendar-saturday');
t.find('tr').find('td:eq('+suIndex+')').addClass('calendar-sunday');
t.find('td').hover(
function(){$(this).addClass('calendar-hover');},
function(){$(this).removeClass('calendar-hover');}
).click(function(){
t.find('.calendar-selected').removeClass('calendar-selected');
$(this).addClass('calendar-selected');
var parts = $(this).attr('abbr').split(',');
opts.current = new Date(parts[0], parseInt(parts[1])-1, parts[2]);
opts.onSelect.call(target, opts.current);
});
}
$.fn.calendar = function(options, param){
if (typeof options == 'string'){
return $.fn.calendar.methods[options](this, param);
}
options = options || {};
return this.each(function(){
var state = $.data(this, 'calendar');
if (state){
$.extend(state.options, options);
} else {
state = $.data(this, 'calendar', {
options:$.extend({}, $.fn.calendar.defaults, $.fn.calendar.parseOptions(this), options)
});
init(this);
}
if (state.options.border == false){
$(this).addClass('calendar-noborder');
}
setSize(this);
show(this);
$(this).find('div.calendar-menu').hide(); // hide the calendar menu
});
};
$.fn.calendar.methods = {
options: function(jq){
return $.data(jq[0], 'calendar').options;
},
resize: function(jq){
return jq.each(function(){
setSize(this);
});
},
moveTo: function(jq, date){
return jq.each(function(){
$(this).calendar({
year: date.getFullYear(),
month: date.getMonth()+1,
current: date
});
});
}
};
$.fn.calendar.parseOptions = function(target){
var t = $(target);
return $.extend({}, $.parser.parseOptions(target, [
'width','height',{firstDay:'number',fit:'boolean',border:'boolean'}
]));
};
$.fn.calendar.defaults = {
width:180,
height:180,
fit:false,
border:true,
firstDay:0,
weeks:['S','M','T','W','T','F','S'],
months:['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
year:new Date().getFullYear(),
month:new Date().getMonth()+1,
current:new Date(),
onSelect: function(date){}
};
})(jQuery);

View File

@@ -0,0 +1,539 @@
/**
* combobox - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*
* Dependencies:
* combo
*
*/
(function($){
function findRowBy(target, value, param, isGroup){
var state = $.data(target, 'combobox');
var opts = state.options;
if (isGroup){
return _findRow(state.groups, param, value);
} else {
return _findRow(state.data, (param ? param : state.options.valueField), value);
}
function _findRow(data,key,value){
for(var i=0; i<data.length; i++){
var row = data[i];
if (row[key] == value){return row}
}
return null;
}
}
/**
* scroll panel to display the specified item
*/
function scrollTo(target, value){
var panel = $(target).combo('panel');
var row = findRowBy(target, value);
if (row){
var item = $('#'+row.domId);
if (item.position().top <= 0){
var h = panel.scrollTop() + item.position().top;
panel.scrollTop(h);
} else if (item.position().top + item.outerHeight() > panel.height()){
var h = panel.scrollTop() + item.position().top + item.outerHeight() - panel.height();
panel.scrollTop(h);
}
}
}
function nav(target, dir){
var opts = $.data(target, 'combobox').options;
var panel = $(target).combobox('panel');
var item = panel.children('div.combobox-item-hover');
if (!item.length){
item = panel.children('div.combobox-item-selected');
}
item.removeClass('combobox-item-hover');
var firstSelector = 'div.combobox-item:visible:not(.combobox-item-disabled):first';
var lastSelector = 'div.combobox-item:visible:not(.combobox-item-disabled):last';
if (!item.length){
item = panel.children(dir=='next' ? firstSelector : lastSelector);
// item = panel.children('div.combobox-item:visible:' + (dir=='next'?'first':'last'));
} else {
if (dir == 'next'){
item = item.nextAll(firstSelector);
// item = item.nextAll('div.combobox-item:visible:first');
if (!item.length){
item = panel.children(firstSelector);
// item = panel.children('div.combobox-item:visible:first');
}
} else {
item = item.prevAll(firstSelector);
// item = item.prevAll('div.combobox-item:visible:first');
if (!item.length){
item = panel.children(lastSelector);
// item = panel.children('div.combobox-item:visible:last');
}
}
}
if (item.length){
item.addClass('combobox-item-hover');
var row = findRowBy(target, item.attr('id'), 'domId');
if (row){
scrollTo(target, row[opts.valueField]);
if (opts.selectOnNavigation){
select(target, row[opts.valueField]);
}
}
}
}
/**
* select the specified value
*/
function select(target, value){
var opts = $.data(target, 'combobox').options;
var values = $(target).combo('getValues');
if ($.inArray(value+'', values) == -1){
if (opts.multiple){
values.push(value);
} else {
values = [value];
}
setValues(target, values);
opts.onSelect.call(target, findRowBy(target, value));
}
}
/**
* unselect the specified value
*/
function unselect(target, value){
var opts = $.data(target, 'combobox').options;
var values = $(target).combo('getValues');
var index = $.inArray(value+'', values);
if (index >= 0){
values.splice(index, 1);
setValues(target, values);
opts.onUnselect.call(target, findRowBy(target, value));
}
}
/**
* set values
*/
function setValues(target, values, remainText){
var opts = $.data(target, 'combobox').options;
var panel = $(target).combo('panel');
panel.find('div.combobox-item-selected').removeClass('combobox-item-selected');
var vv = [], ss = [];
for(var i=0; i<values.length; i++){
var v = values[i];
var s = v;
var row = findRowBy(target, v);
if (row){
s = row[opts.textField];
$('#'+row.domId).addClass('combobox-item-selected');
}
vv.push(v);
ss.push(s);
}
$(target).combo('setValues', vv);
if (!remainText){
$(target).combo('setText', ss.join(opts.separator));
}
}
/**
* load data, the old list items will be removed.
*/
var itemIndex = 1;
function loadData(target, data, remainText){
var state = $.data(target, 'combobox');
var opts = state.options;
state.data = opts.loadFilter.call(target, data);
state.groups = [];
data = state.data;
var selected = $(target).combobox('getValues');
var dd = [];
var group = undefined;
for(var i=0; i<data.length; i++){
var row = data[i];
var v = row[opts.valueField]+'';
var s = row[opts.textField];
var g = row[opts.groupField];
if (g){
if (group != g){
group = g;
var grow = {value:g, domId:('_easyui_combobox_'+itemIndex++)};
state.groups.push(grow);
dd.push('<div id="' + grow.domId + '" class="combobox-group">');
dd.push(opts.groupFormatter ? opts.groupFormatter.call(target, g) : g);
dd.push('</div>');
}
} else {
group = undefined;
}
var cls = 'combobox-item' + (row.disabled ? ' combobox-item-disabled' : '') + (g ? ' combobox-gitem' : '');
row.domId = '_easyui_combobox_' + itemIndex++;
dd.push('<div id="' + row.domId + '" class="' + cls + '">');
dd.push(opts.formatter ? opts.formatter.call(target, row) : s);
dd.push('</div>');
// if (item['selected']){
// (function(){
// for(var i=0; i<selected.length; i++){
// if (v == selected[i]) return;
// }
// selected.push(v);
// })();
// }
if (row['selected'] && $.inArray(v, selected) == -1){
selected.push(v);
}
}
$(target).combo('panel').html(dd.join(''));
if (opts.multiple){
setValues(target, selected, remainText);
} else {
setValues(target, selected.length ? [selected[selected.length-1]] : [], remainText);
}
opts.onLoadSuccess.call(target, data);
}
/**
* request remote data if the url property is setted.
*/
function request(target, url, param, remainText){
var opts = $.data(target, 'combobox').options;
if (url){
opts.url = url;
}
// if (!opts.url) return;
param = param || {};
if (opts.onBeforeLoad.call(target, param) == false) return;
opts.loader.call(target, param, function(data){
loadData(target, data, remainText);
}, function(){
opts.onLoadError.apply(this, arguments);
});
}
/**
* do the query action
*/
function doQuery(target, q){
var state = $.data(target, 'combobox');
var opts = state.options;
if (opts.multiple && !q){
setValues(target, [], true);
} else {
setValues(target, [q], true);
}
if (opts.mode == 'remote'){
request(target, null, {q:q}, true);
} else {
var panel = $(target).combo('panel');
panel.find('div.combobox-item,div.combobox-group').hide();
var data = state.data;
var group = undefined;
for(var i=0; i<data.length; i++){
var row = data[i];
if (opts.filter.call(target, q, row)){
var v = row[opts.valueField];
var s = row[opts.textField];
var g = row[opts.groupField];
var item = $('#'+row.domId).show();
if (s.toLowerCase() == q.toLowerCase()){
// setValues(target, [v], true);
setValues(target, [v]);
item.addClass('combobox-item-selected');
}
if (opts.groupField && group != g){
var grow = findRowBy(target, g, 'value', true);
if (grow){
$('#'+grow.domId).show();
}
group = g;
}
}
}
}
}
function doEnter(target){
var t = $(target);
var opts = t.combobox('options');
var panel = t.combobox('panel');
var item = panel.children('div.combobox-item-hover');
if (!item.length){
item = panel.children('div.combobox-item-selected');
}
if (!item.length){return}
var row = findRowBy(target, item.attr('id'), 'domId');
if (!row){return}
var value = row[opts.valueField];
if (opts.multiple){
if (item.hasClass('combobox-item-selected')){
t.combobox('unselect', value);
} else {
t.combobox('select', value);
}
} else {
t.combobox('select', value);
t.combobox('hidePanel');
}
var vv = [];
var values = t.combobox('getValues');
for(var i=0; i<values.length; i++){
if (findRowBy(target, values[i])){
vv.push(values[i]);
}
}
t.combobox('setValues', vv);
}
/**
* create the component
*/
function create(target){
var opts = $.data(target, 'combobox').options;
$(target).addClass('combobox-f');
$(target).combo($.extend({}, opts, {
onShowPanel: function(){
$(target).combo('panel').find('div.combobox-item,div.combobox-group').show();
scrollTo(target, $(target).combobox('getValue'));
opts.onShowPanel.call(target);
}
}));
$(target).combo('panel').unbind().bind('mouseover', function(e){
$(this).children('div.combobox-item-hover').removeClass('combobox-item-hover');
var item = $(e.target).closest('div.combobox-item');
if (!item.hasClass('combobox-item-disabled')){
item.addClass('combobox-item-hover');
}
e.stopPropagation();
}).bind('mouseout', function(e){
$(e.target).closest('div.combobox-item').removeClass('combobox-item-hover');
e.stopPropagation();
}).bind('click', function(e){
var item = $(e.target).closest('div.combobox-item');
if (!item.length || item.hasClass('combobox-item-disabled')){return}
var row = findRowBy(target, item.attr('id'), 'domId');
if (!row){return}
var value = row[opts.valueField];
if (opts.multiple){
if (item.hasClass('combobox-item-selected')){
unselect(target, value);
} else {
select(target, value);
}
} else {
select(target, value);
$(target).combo('hidePanel');
}
e.stopPropagation();
});
}
$.fn.combobox = function(options, param){
if (typeof options == 'string'){
var method = $.fn.combobox.methods[options];
if (method){
return method(this, param);
} else {
return this.combo(options, param);
}
}
options = options || {};
return this.each(function(){
var state = $.data(this, 'combobox');
if (state){
$.extend(state.options, options);
create(this);
} else {
state = $.data(this, 'combobox', {
options: $.extend({}, $.fn.combobox.defaults, $.fn.combobox.parseOptions(this), options),
data: []
});
create(this);
var data = $.fn.combobox.parseData(this);
if (data.length){
loadData(this, data);
}
}
if (state.options.data){
loadData(this, state.options.data);
}
request(this);
});
};
$.fn.combobox.methods = {
options: function(jq){
var copts = jq.combo('options');
return $.extend($.data(jq[0], 'combobox').options, {
originalValue: copts.originalValue,
disabled: copts.disabled,
readonly: copts.readonly
});
},
getData: function(jq){
return $.data(jq[0], 'combobox').data;
},
setValues: function(jq, values){
return jq.each(function(){
setValues(this, values);
});
},
setValue: function(jq, value){
return jq.each(function(){
setValues(this, [value]);
});
},
clear: function(jq){
return jq.each(function(){
$(this).combo('clear');
var panel = $(this).combo('panel');
panel.find('div.combobox-item-selected').removeClass('combobox-item-selected');
});
},
reset: function(jq){
return jq.each(function(){
var opts = $(this).combobox('options');
if (opts.multiple){
$(this).combobox('setValues', opts.originalValue);
} else {
$(this).combobox('setValue', opts.originalValue);
}
});
},
loadData: function(jq, data){
return jq.each(function(){
loadData(this, data);
});
},
reload: function(jq, url){
return jq.each(function(){
request(this, url);
});
},
select: function(jq, value){
return jq.each(function(){
select(this, value);
});
},
unselect: function(jq, value){
return jq.each(function(){
unselect(this, value);
});
}
};
$.fn.combobox.parseOptions = function(target){
var t = $(target);
return $.extend({}, $.fn.combo.parseOptions(target), $.parser.parseOptions(target,[
'valueField','textField','groupField','mode','method','url'
]));
};
$.fn.combobox.parseData = function(target){
var data = [];
var opts = $(target).combobox('options');
$(target).children().each(function(){
if (this.tagName.toLowerCase() == 'optgroup'){
var group = $(this).attr('label');
$(this).children().each(function(){
_parseItem(this, group);
});
} else {
_parseItem(this);
}
});
return data;
function _parseItem(el, group){
var t = $(el);
var row = {};
row[opts.valueField] = t.attr('value')!=undefined ? t.attr('value') : t.html();
row[opts.textField] = t.html();
row['selected'] = t.is(':selected');
row['disabled'] = t.is(':disabled');
if (group){
opts.groupField = opts.groupField || 'group';
row[opts.groupField] = group;
}
data.push(row);
}
};
$.fn.combobox.defaults = $.extend({}, $.fn.combo.defaults, {
valueField: 'value',
textField: 'text',
groupField: null,
groupFormatter: function(group){return group;},
mode: 'local', // or 'remote'
method: 'post',
url: null,
data: null,
keyHandler: {
up: function(e){nav(this,'prev');e.preventDefault()},
down: function(e){nav(this,'next');e.preventDefault()},
left: function(e){},
right: function(e){},
enter: function(e){doEnter(this)},
query: function(q,e){doQuery(this, q)}
},
filter: function(q, row){
var opts = $(this).combobox('options');
return row[opts.textField].toLowerCase().indexOf(q.toLowerCase()) == 0;
},
formatter: function(row){
var opts = $(this).combobox('options');
return row[opts.textField];
},
loader: function(param, success, error){
var opts = $(this).combobox('options');
if (!opts.url) return false;
$.ajax({
type: opts.method,
url: opts.url,
data: param,
dataType: 'json',
success: function(data){
success(data);
},
error: function(){
error.apply(this, arguments);
}
});
},
loadFilter: function(data){
return data;
},
onBeforeLoad: function(param){},
onLoadSuccess: function(){},
onLoadError: function(){},
onSelect: function(record){},
onUnselect: function(record){}
});
})(jQuery);

View File

@@ -0,0 +1,223 @@
/**
* datebox - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*
* Dependencies:
* calendar
* combo
*
*/
(function($){
/**
* create date box
*/
function createBox(target){
var state = $.data(target, 'datebox');
var opts = state.options;
$(target).addClass('datebox-f').combo($.extend({}, opts, {
onShowPanel:function(){
setCalendar();
setValue(target, $(target).datebox('getText'));
opts.onShowPanel.call(target);
}
}));
$(target).combo('textbox').parent().addClass('datebox');
/**
* if the calendar isn't created, create it.
*/
if (!state.calendar){
createCalendar();
}
function createCalendar(){
var panel = $(target).combo('panel').css('overflow','hidden');
var cc = $('<div class="datebox-calendar-inner"></div>').appendTo(panel);
if (opts.sharedCalendar){
state.calendar = $(opts.sharedCalendar).appendTo(cc);
if (!state.calendar.hasClass('calendar')){
state.calendar.calendar();
}
} else {
state.calendar = $('<div></div>').appendTo(cc).calendar();
}
$.extend(state.calendar.calendar('options'), {
fit:true,
border:false,
onSelect:function(date){
var opts = $(this.target).datebox('options');
setValue(this.target, opts.formatter(date));
$(this.target).combo('hidePanel');
opts.onSelect.call(target, date);
}
});
setValue(target, opts.value);
var button = $('<div class="datebox-button"><table cellspacing="0" cellpadding="0" style="width:100%"><tr></tr></table></div>').appendTo(panel);
var tr = button.find('tr');
for(var i=0; i<opts.buttons.length; i++){
var td = $('<td></td>').appendTo(tr);
var btn = opts.buttons[i];
var t = $('<a href="javascript:void(0)"></a>').html($.isFunction(btn.text) ? btn.text(target) : btn.text).appendTo(td);
t.bind('click', {target: target, handler: btn.handler}, function(e){
e.data.handler.call(this, e.data.target);
});
}
tr.find('td').css('width', (100/opts.buttons.length)+'%');
}
function setCalendar(){
var panel = $(target).combo('panel');
var cc = panel.children('div.datebox-calendar-inner');
panel.children()._outerWidth(panel.width());
state.calendar.appendTo(cc);
state.calendar[0].target = target;
if (opts.panelHeight != 'auto'){
var height = panel.height();
panel.children().not(cc).each(function(){
height -= $(this).outerHeight();
});
cc._outerHeight(height);
}
state.calendar.calendar('resize');
}
}
/**
* called when user inputs some value in text box
*/
function doQuery(target, q){
setValue(target, q);
}
/**
* called when user press enter key
*/
function doEnter(target){
var state = $.data(target, 'datebox');
var opts = state.options;
var value = opts.formatter(state.calendar.calendar('options').current);
setValue(target, value);
$(target).combo('hidePanel');
}
function setValue(target, value){
var state = $.data(target, 'datebox');
var opts = state.options;
$(target).combo('setValue', value).combo('setText', value);
state.calendar.calendar('moveTo', opts.parser(value));
}
$.fn.datebox = function(options, param){
if (typeof options == 'string'){
var method = $.fn.datebox.methods[options];
if (method){
return method(this, param);
} else {
return this.combo(options, param);
}
}
options = options || {};
return this.each(function(){
var state = $.data(this, 'datebox');
if (state){
$.extend(state.options, options);
} else {
$.data(this, 'datebox', {
options: $.extend({}, $.fn.datebox.defaults, $.fn.datebox.parseOptions(this), options)
});
}
createBox(this);
});
};
$.fn.datebox.methods = {
options: function(jq){
var copts = jq.combo('options');
return $.extend($.data(jq[0], 'datebox').options, {
originalValue: copts.originalValue,
disabled: copts.disabled,
readonly: copts.readonly
});
},
calendar: function(jq){ // get the calendar object
return $.data(jq[0], 'datebox').calendar;
},
setValue: function(jq, value){
return jq.each(function(){
setValue(this, value);
});
},
reset: function(jq){
return jq.each(function(){
var opts = $(this).datebox('options');
$(this).datebox('setValue', opts.originalValue);
});
}
};
$.fn.datebox.parseOptions = function(target){
return $.extend({}, $.fn.combo.parseOptions(target), $.parser.parseOptions(target, ['sharedCalendar']));
};
$.fn.datebox.defaults = $.extend({}, $.fn.combo.defaults, {
panelWidth:180,
panelHeight:'auto',
sharedCalendar:null,
keyHandler: {
up:function(e){},
down:function(e){},
left: function(e){},
right: function(e){},
enter:function(e){doEnter(this)},
query:function(q,e){doQuery(this, q)}
},
currentText:'Today',
closeText:'Close',
okText:'Ok',
buttons:[{
text: function(target){return $(target).datebox('options').currentText;},
handler: function(target){
$(target).datebox('calendar').calendar({
year:new Date().getFullYear(),
month:new Date().getMonth()+1,
current:new Date()
});
doEnter(target);
}
},{
text: function(target){return $(target).datebox('options').closeText;},
handler: function(target){
$(this).closest('div.combo-panel').panel('close');
}
}],
formatter:function(date){
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
return m+'/'+d+'/'+y;
},
parser:function(s){
var t = Date.parse(s);
if (!isNaN(t)){
return new Date(t);
} else {
return new Date();
}
},
onSelect:function(date){}
});
})(jQuery);

View File

@@ -0,0 +1,417 @@
/**
* draggable - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*/
(function($){
// var isDragging = false;
function drag(e){
var state = $.data(e.data.target, 'draggable');
var opts = state.options;
var proxy = state.proxy;
var dragData = e.data;
var left = dragData.startLeft + e.pageX - dragData.startX;
var top = dragData.startTop + e.pageY - dragData.startY;
if (proxy){
if (proxy.parent()[0] == document.body){
if (opts.deltaX != null && opts.deltaX != undefined){
left = e.pageX + opts.deltaX;
} else {
left = e.pageX - e.data.offsetWidth;
}
if (opts.deltaY != null && opts.deltaY != undefined){
top = e.pageY + opts.deltaY;
} else {
top = e.pageY - e.data.offsetHeight;
}
} else {
if (opts.deltaX != null && opts.deltaX != undefined){
left += e.data.offsetWidth + opts.deltaX;
}
if (opts.deltaY != null && opts.deltaY != undefined){
top += e.data.offsetHeight + opts.deltaY;
}
}
}
// if (opts.deltaX != null && opts.deltaX != undefined){
// left = e.pageX + opts.deltaX;
// }
// if (opts.deltaY != null && opts.deltaY != undefined){
// top = e.pageY + opts.deltaY;
// }
if (e.data.parent != document.body) {
left += $(e.data.parent).scrollLeft();
top += $(e.data.parent).scrollTop();
}
if (opts.axis == 'h') {
dragData.left = left;
} else if (opts.axis == 'v') {
dragData.top = top;
} else {
dragData.left = left;
dragData.top = top;
}
}
function applyDrag(e){
var state = $.data(e.data.target, 'draggable');
var opts = state.options;
var proxy = state.proxy;
if (!proxy){
proxy = $(e.data.target);
}
// if (proxy){
// proxy.css('cursor', opts.cursor);
// } else {
// proxy = $(e.data.target);
// $.data(e.data.target, 'draggable').handle.css('cursor', opts.cursor);
// }
proxy.css({
left:e.data.left,
top:e.data.top
});
$('body').css('cursor', opts.cursor);
}
function doDown(e){
// isDragging = true;
$.fn.draggable.isDragging = true;
var state = $.data(e.data.target, 'draggable');
var opts = state.options;
var droppables = $('.droppable').filter(function(){
return e.data.target != this;
}).filter(function(){
var accept = $.data(this, 'droppable').options.accept;
if (accept){
return $(accept).filter(function(){
return this == e.data.target;
}).length > 0;
} else {
return true;
}
});
state.droppables = droppables;
var proxy = state.proxy;
if (!proxy){
if (opts.proxy){
if (opts.proxy == 'clone'){
proxy = $(e.data.target).clone().insertAfter(e.data.target);
} else {
proxy = opts.proxy.call(e.data.target, e.data.target);
}
state.proxy = proxy;
} else {
proxy = $(e.data.target);
}
}
proxy.css('position', 'absolute');
drag(e);
applyDrag(e);
opts.onStartDrag.call(e.data.target, e);
return false;
}
function doMove(e){
var state = $.data(e.data.target, 'draggable');
drag(e);
if (state.options.onDrag.call(e.data.target, e) != false){
applyDrag(e);
}
var source = e.data.target;
state.droppables.each(function(){
var dropObj = $(this);
if (dropObj.droppable('options').disabled){return;}
var p2 = dropObj.offset();
if (e.pageX > p2.left && e.pageX < p2.left + dropObj.outerWidth()
&& e.pageY > p2.top && e.pageY < p2.top + dropObj.outerHeight()){
if (!this.entered){
$(this).trigger('_dragenter', [source]);
this.entered = true;
}
$(this).trigger('_dragover', [source]);
} else {
if (this.entered){
$(this).trigger('_dragleave', [source]);
this.entered = false;
}
}
});
return false;
}
function doUp(e){
// isDragging = false;
$.fn.draggable.isDragging = false;
// drag(e);
doMove(e);
var state = $.data(e.data.target, 'draggable');
var proxy = state.proxy;
var opts = state.options;
if (opts.revert){
if (checkDrop() == true){
$(e.data.target).css({
position:e.data.startPosition,
left:e.data.startLeft,
top:e.data.startTop
});
} else {
if (proxy){
var left, top;
if (proxy.parent()[0] == document.body){
left = e.data.startX - e.data.offsetWidth;
top = e.data.startY - e.data.offsetHeight;
} else {
left = e.data.startLeft;
top = e.data.startTop;
}
proxy.animate({
left: left,
top: top
}, function(){
removeProxy();
});
} else {
$(e.data.target).animate({
left:e.data.startLeft,
top:e.data.startTop
}, function(){
$(e.data.target).css('position', e.data.startPosition);
});
}
}
} else {
$(e.data.target).css({
position:'absolute',
left:e.data.left,
top:e.data.top
});
checkDrop();
}
opts.onStopDrag.call(e.data.target, e);
$(document).unbind('.draggable');
setTimeout(function(){
$('body').css('cursor','');
},100);
function removeProxy(){
if (proxy){
proxy.remove();
}
state.proxy = null;
}
function checkDrop(){
var dropped = false;
state.droppables.each(function(){
var dropObj = $(this);
if (dropObj.droppable('options').disabled){return;}
var p2 = dropObj.offset();
if (e.pageX > p2.left && e.pageX < p2.left + dropObj.outerWidth()
&& e.pageY > p2.top && e.pageY < p2.top + dropObj.outerHeight()){
if (opts.revert){
$(e.data.target).css({
position:e.data.startPosition,
left:e.data.startLeft,
top:e.data.startTop
});
}
$(this).trigger('_drop', [e.data.target]);
removeProxy();
dropped = true;
this.entered = false;
return false;
}
});
if (!dropped && !opts.revert){
removeProxy();
}
return dropped;
}
return false;
}
$.fn.draggable = function(options, param){
if (typeof options == 'string'){
return $.fn.draggable.methods[options](this, param);
}
return this.each(function(){
var opts;
var state = $.data(this, 'draggable');
if (state) {
state.handle.unbind('.draggable');
opts = $.extend(state.options, options);
} else {
opts = $.extend({}, $.fn.draggable.defaults, $.fn.draggable.parseOptions(this), options || {});
}
var handle = opts.handle ? (typeof opts.handle=='string' ? $(opts.handle, this) : opts.handle) : $(this);
$.data(this, 'draggable', {
options: opts,
handle: handle
});
if (opts.disabled) {
$(this).css('cursor', '');
return;
}
handle.unbind('.draggable').bind('mousemove.draggable', {target:this}, function(e){
// if (isDragging) return;
if ($.fn.draggable.isDragging){return}
var opts = $.data(e.data.target, 'draggable').options;
if (checkArea(e)){
$(this).css('cursor', opts.cursor);
} else {
$(this).css('cursor', '');
}
}).bind('mouseleave.draggable', {target:this}, function(e){
$(this).css('cursor', '');
}).bind('mousedown.draggable', {target:this}, function(e){
if (checkArea(e) == false) return;
$(this).css('cursor', '');
var position = $(e.data.target).position();
var offset = $(e.data.target).offset();
var data = {
startPosition: $(e.data.target).css('position'),
startLeft: position.left,
startTop: position.top,
left: position.left,
top: position.top,
startX: e.pageX,
startY: e.pageY,
offsetWidth: (e.pageX - offset.left),
offsetHeight: (e.pageY - offset.top),
target: e.data.target,
parent: $(e.data.target).parent()[0]
};
$.extend(e.data, data);
var opts = $.data(e.data.target, 'draggable').options;
if (opts.onBeforeDrag.call(e.data.target, e) == false) return;
$(document).bind('mousedown.draggable', e.data, doDown);
$(document).bind('mousemove.draggable', e.data, doMove);
$(document).bind('mouseup.draggable', e.data, doUp);
// $('body').css('cursor', opts.cursor);
});
// check if the handle can be dragged
function checkArea(e) {
var state = $.data(e.data.target, 'draggable');
var handle = state.handle;
var offset = $(handle).offset();
var width = $(handle).outerWidth();
var height = $(handle).outerHeight();
var t = e.pageY - offset.top;
var r = offset.left + width - e.pageX;
var b = offset.top + height - e.pageY;
var l = e.pageX - offset.left;
return Math.min(t,r,b,l) > state.options.edge;
}
});
};
$.fn.draggable.methods = {
options: function(jq){
return $.data(jq[0], 'draggable').options;
},
proxy: function(jq){
return $.data(jq[0], 'draggable').proxy;
},
enable: function(jq){
return jq.each(function(){
$(this).draggable({disabled:false});
});
},
disable: function(jq){
return jq.each(function(){
$(this).draggable({disabled:true});
});
}
};
$.fn.draggable.parseOptions = function(target){
var t = $(target);
return $.extend({},
$.parser.parseOptions(target, ['cursor','handle','axis',
{'revert':'boolean','deltaX':'number','deltaY':'number','edge':'number'}]), {
disabled: (t.attr('disabled') ? true : undefined)
});
};
$.fn.draggable.defaults = {
proxy:null, // 'clone' or a function that will create the proxy object,
// the function has the source parameter that indicate the source object dragged.
revert:false,
cursor:'move',
deltaX:null,
deltaY:null,
handle: null,
disabled: false,
edge:0,
axis:null, // v or h
onBeforeDrag: function(e){},
onStartDrag: function(e){},
onDrag: function(e){},
onStopDrag: function(e){}
};
$.fn.draggable.isDragging = false;
// $(function(){
// function touchHandler(e) {
// var touches = e.changedTouches, first = touches[0], type = "";
//
// switch(e.type) {
// case "touchstart": type = "mousedown"; break;
// case "touchmove": type = "mousemove"; break;
// case "touchend": type = "mouseup"; break;
// default: return;
// }
// var simulatedEvent = document.createEvent("MouseEvent");
// simulatedEvent.initMouseEvent(type, true, true, window, 1,
// first.screenX, first.screenY,
// first.clientX, first.clientY, false,
// false, false, false, 0/*left*/, null);
//
// first.target.dispatchEvent(simulatedEvent);
// if (isDragging){
// e.preventDefault();
// }
// }
//
// if (document.addEventListener){
// document.addEventListener("touchstart", touchHandler, true);
// document.addEventListener("touchmove", touchHandler, true);
// document.addEventListener("touchend", touchHandler, true);
// document.addEventListener("touchcancel", touchHandler, true);
// }
// });
})(jQuery);

View File

@@ -0,0 +1,78 @@
/**
* droppable - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*/
(function($){
function init(target){
$(target).addClass('droppable');
$(target).bind('_dragenter', function(e, source){
$.data(target, 'droppable').options.onDragEnter.apply(target, [e, source]);
});
$(target).bind('_dragleave', function(e, source){
$.data(target, 'droppable').options.onDragLeave.apply(target, [e, source]);
});
$(target).bind('_dragover', function(e, source){
$.data(target, 'droppable').options.onDragOver.apply(target, [e, source]);
});
$(target).bind('_drop', function(e, source){
$.data(target, 'droppable').options.onDrop.apply(target, [e, source]);
});
}
$.fn.droppable = function(options, param){
if (typeof options == 'string'){
return $.fn.droppable.methods[options](this, param);
}
options = options || {};
return this.each(function(){
var state = $.data(this, 'droppable');
if (state){
$.extend(state.options, options);
} else {
init(this);
$.data(this, 'droppable', {
options: $.extend({}, $.fn.droppable.defaults, $.fn.droppable.parseOptions(this), options)
});
}
});
};
$.fn.droppable.methods = {
options: function(jq){
return $.data(jq[0], 'droppable').options;
},
enable: function(jq){
return jq.each(function(){
$(this).droppable({disabled:false});
});
},
disable: function(jq){
return jq.each(function(){
$(this).droppable({disabled:true});
});
}
};
$.fn.droppable.parseOptions = function(target){
var t = $(target);
return $.extend({}, $.parser.parseOptions(target, ['accept']), {
disabled: (t.attr('disabled') ? true : undefined)
});
};
$.fn.droppable.defaults = {
accept:null,
disabled:false,
onDragEnter:function(e, source){},
onDragOver:function(e, source){},
onDragLeave:function(e, source){},
onDrop:function(e, source){}
};
})(jQuery);

View File

@@ -0,0 +1,378 @@
/**
* form - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*/
(function($){
/**
* submit the form
*/
function ajaxSubmit(target, options){
options = options || {};
var param = {};
if (options.onSubmit){
if (options.onSubmit.call(target, param) == false) {
return;
}
}
var form = $(target);
if (options.url){
form.attr('action', options.url);
}
var frameId = 'easyui_frame_' + (new Date().getTime());
var frame = $('<iframe id='+frameId+' name='+frameId+'></iframe>')
.attr('src', window.ActiveXObject ? 'javascript:false' : 'about:blank')
.css({
position:'absolute',
top:-1000,
left:-1000
});
var t = form.attr('target'), a = form.attr('action');
form.attr('target', frameId);
var paramFields = $();
try {
frame.appendTo('body');
frame.bind('load', cb);
for(var n in param){
var f = $('<input type="hidden" name="' + n + '">').val(param[n]).appendTo(form);
paramFields = paramFields.add(f);
}
checkState();
form[0].submit();
} finally {
form.attr('action', a);
t ? form.attr('target', t) : form.removeAttr('target');
paramFields.remove();
}
function checkState(){
var f = $('#'+frameId);
if (!f.length){return}
try{
var s = f.contents()[0].readyState;
if (s && s.toLowerCase() == 'uninitialized'){
setTimeout(checkState, 100);
}
} catch(e){
cb();
}
}
var checkCount = 10;
function cb(){
var frame = $('#'+frameId);
if (!frame.length){return}
frame.unbind();
var data = '';
try{
var body = frame.contents().find('body');
data = body.html();
if (data == ''){
if (--checkCount){
setTimeout(cb, 100);
return;
}
// return;
}
var ta = body.find('>textarea');
if (ta.length){
data = ta.val();
} else {
var pre = body.find('>pre');
if (pre.length){
data = pre.html();
}
}
} catch(e){
}
if (options.success){
options.success(data);
}
setTimeout(function(){
frame.unbind();
frame.remove();
}, 100);
}
}
/**
* load form data
* if data is a URL string type load from remote site,
* otherwise load from local data object.
*/
function load(target, data){
if (!$.data(target, 'form')){
$.data(target, 'form', {
options: $.extend({}, $.fn.form.defaults)
});
}
var opts = $.data(target, 'form').options;
if (typeof data == 'string'){
var param = {};
if (opts.onBeforeLoad.call(target, param) == false) return;
$.ajax({
url: data,
data: param,
dataType: 'json',
success: function(data){
_load(data);
},
error: function(){
opts.onLoadError.apply(target, arguments);
}
});
} else {
_load(data);
}
function _load(data){
var form = $(target);
for(var name in data){
var val = data[name];
var rr = _checkField(name, val);
if (!rr.length){
// var f = form.find('input[numberboxName="'+name+'"]');
// if (f.length){
// f.numberbox('setValue', val); // set numberbox value
// } else {
// $('input[name="'+name+'"]', form).val(val);
// $('textarea[name="'+name+'"]', form).val(val);
// $('select[name="'+name+'"]', form).val(val);
// }
var count = _loadOther(name, val);
if (!count){
$('input[name="'+name+'"]', form).val(val);
$('textarea[name="'+name+'"]', form).val(val);
$('select[name="'+name+'"]', form).val(val);
}
}
_loadCombo(name, val);
}
opts.onLoadSuccess.call(target, data);
validate(target);
}
/**
* check the checkbox and radio fields
*/
function _checkField(name, val){
var rr = $(target).find('input[name="'+name+'"][type=radio], input[name="'+name+'"][type=checkbox]');
rr._propAttr('checked', false);
rr.each(function(){
var f = $(this);
if (f.val() == String(val) || $.inArray(f.val(), $.isArray(val)?val:[val]) >= 0){
f._propAttr('checked', true);
}
});
return rr;
}
function _loadOther(name, val){
var count = 0;
var pp = ['numberbox','slider'];
for(var i=0; i<pp.length; i++){
var p = pp[i];
var f = $(target).find('input['+p+'Name="'+name+'"]');
if (f.length){
f[p]('setValue', val);
count += f.length;
}
}
return count;
}
function _loadCombo(name, val){
var form = $(target);
var cc = ['combobox','combotree','combogrid','datetimebox','datebox','combo'];
var c = form.find('[comboName="' + name + '"]');
if (c.length){
for(var i=0; i<cc.length; i++){
var type = cc[i];
if (c.hasClass(type+'-f')){
if (c[type]('options').multiple){
c[type]('setValues', val);
} else {
c[type]('setValue', val);
}
return;
}
}
}
}
}
/**
* clear the form fields
*/
function clear(target){
$('input,select,textarea', target).each(function(){
var t = this.type, tag = this.tagName.toLowerCase();
if (t == 'text' || t == 'hidden' || t == 'password' || tag == 'textarea'){
this.value = '';
} else if (t == 'file'){
var file = $(this);
file.after(file.clone().val(''));
file.remove();
} else if (t == 'checkbox' || t == 'radio'){
this.checked = false;
} else if (tag == 'select'){
this.selectedIndex = -1;
}
});
// if ($.fn.combo) $('.combo-f', target).combo('clear');
// if ($.fn.combobox) $('.combobox-f', target).combobox('clear');
// if ($.fn.combotree) $('.combotree-f', target).combotree('clear');
// if ($.fn.combogrid) $('.combogrid-f', target).combogrid('clear');
var t = $(target);
var plugins = ['combo','combobox','combotree','combogrid','slider'];
for(var i=0; i<plugins.length; i++){
var plugin = plugins[i];
var r = t.find('.'+plugin+'-f');
if (r.length && r[plugin]){
r[plugin]('clear');
}
}
validate(target);
}
function reset(target){
target.reset();
var t = $(target);
// if ($.fn.combo){t.find('.combo-f').combo('reset');}
// if ($.fn.combobox){t.find('.combobox-f').combobox('reset');}
// if ($.fn.combotree){t.find('.combotree-f').combotree('reset');}
// if ($.fn.combogrid){t.find('.combogrid-f').combogrid('reset');}
// if ($.fn.datebox){t.find('.datebox-f').datebox('reset');}
// if ($.fn.datetimebox){t.find('.datetimebox-f').datetimebox('reset');}
// if ($.fn.spinner){t.find('.spinner-f').spinner('reset');}
// if ($.fn.timespinner){t.find('.timespinner-f').timespinner('reset');}
// if ($.fn.numberbox){t.find('.numberbox-f').numberbox('reset');}
// if ($.fn.numberspinner){t.find('.numberspinner-f').numberspinner('reset');}
var plugins = ['combo','combobox','combotree','combogrid','datebox','datetimebox','spinner','timespinner','numberbox','numberspinner','slider'];
for(var i=0; i<plugins.length; i++){
var plugin = plugins[i];
var r = t.find('.'+plugin+'-f');
if (r.length && r[plugin]){
r[plugin]('reset');
}
}
validate(target);
}
/**
* set the form to make it can submit with ajax.
*/
function setForm(target){
var options = $.data(target, 'form').options;
var form = $(target);
form.unbind('.form').bind('submit.form', function(){
setTimeout(function(){
ajaxSubmit(target, options);
}, 0);
return false;
});
}
// function validate(target){
// if ($.fn.validatebox){
// var box = $('.validatebox-text', target);
// if (box.length){
// box.validatebox('validate');
//// box.trigger('focus');
//// box.trigger('blur');
// var invalidbox = $('.validatebox-invalid:first', target).focus();
// return invalidbox.length == 0;
// }
// }
// return true;
// }
function validate(target){
if ($.fn.validatebox){
var t = $(target);
t.find('.validatebox-text:not(:disabled)').validatebox('validate');
var invalidbox = t.find('.validatebox-invalid');
invalidbox.filter(':not(:disabled):first').focus();
return invalidbox.length == 0;
}
return true;
}
function setValidation(target, novalidate){
$(target).find('.validatebox-text:not(:disabled)').validatebox(novalidate ? 'disableValidation' : 'enableValidation');
}
$.fn.form = function(options, param){
if (typeof options == 'string'){
return $.fn.form.methods[options](this, param);
}
options = options || {};
return this.each(function(){
if (!$.data(this, 'form')){
$.data(this, 'form', {
options: $.extend({}, $.fn.form.defaults, options)
});
}
setForm(this);
});
};
$.fn.form.methods = {
submit: function(jq, options){
return jq.each(function(){
ajaxSubmit(this, $.extend({}, $.fn.form.defaults, options||{}));
});
},
load: function(jq, data){
return jq.each(function(){
load(this, data);
});
},
clear: function(jq){
return jq.each(function(){
clear(this);
});
},
reset: function(jq){
return jq.each(function(){
reset(this);
});
},
validate: function(jq){
return validate(jq[0]);
},
disableValidation: function(jq){
return jq.each(function(){
setValidation(this, true);
});
},
enableValidation: function(jq){
return jq.each(function(){
setValidation(this, false);
});
}
};
$.fn.form.defaults = {
url: null,
onSubmit: function(param){return $(this).form('validate');},
success: function(data){},
onBeforeLoad: function(param){},
onLoadSuccess: function(data){},
onLoadError: function(){}
};
})(jQuery);

View File

@@ -0,0 +1,181 @@
/**
* linkbutton - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*/
(function($){
function createButton(target) {
var opts = $.data(target, 'linkbutton').options;
var t = $(target);
t.addClass('l-btn').removeClass('l-btn-plain l-btn-selected l-btn-plain-selected');
if (opts.plain){t.addClass('l-btn-plain')}
if (opts.selected){
t.addClass(opts.plain ? 'l-btn-selected l-btn-plain-selected' : 'l-btn-selected');
}
t.attr('group', opts.group || '');
t.attr('id', opts.id || '');
t.html(
'<span class="l-btn-left">' +
'<span class="l-btn-text"></span>' +
'</span>'
);
if (opts.text){
t.find('.l-btn-text').html(opts.text);
if (opts.iconCls){
t.find('.l-btn-text').addClass(opts.iconCls).addClass(opts.iconAlign=='left' ? 'l-btn-icon-left' : 'l-btn-icon-right');
}
} else {
t.find('.l-btn-text').html('<span class="l-btn-empty">&nbsp;</span>');
if (opts.iconCls){
t.find('.l-btn-empty').addClass(opts.iconCls);
}
}
t.unbind('.linkbutton').bind('focus.linkbutton',function(){
if (!opts.disabled){
$(this).find('.l-btn-text').addClass('l-btn-focus');
}
}).bind('blur.linkbutton',function(){
$(this).find('.l-btn-text').removeClass('l-btn-focus');
});
if (opts.toggle && !opts.disabled){
t.bind('click.linkbutton', function(){
if (opts.selected){
$(this).linkbutton('unselect');
} else {
$(this).linkbutton('select');
}
});
}
setSelected(target, opts.selected)
setDisabled(target, opts.disabled);
}
function setSelected(target, selected){
var opts = $.data(target, 'linkbutton').options;
if (selected){
if (opts.group){
$('a.l-btn[group="'+opts.group+'"]').each(function(){
var o = $(this).linkbutton('options');
if (o.toggle){
$(this).removeClass('l-btn-selected l-btn-plain-selected');
o.selected = false;
}
});
}
$(target).addClass(opts.plain ? 'l-btn-selected l-btn-plain-selected' : 'l-btn-selected');
opts.selected = true;
} else {
if (!opts.group){
$(target).removeClass('l-btn-selected l-btn-plain-selected');
opts.selected = false;
}
}
}
function setDisabled(target, disabled){
var state = $.data(target, 'linkbutton');
var opts = state.options;
$(target).removeClass('l-btn-disabled l-btn-plain-disabled');
if (disabled){
opts.disabled = true;
var href = $(target).attr('href');
if (href){
state.href = href;
$(target).attr('href', 'javascript:void(0)');
}
if (target.onclick){
state.onclick = target.onclick;
target.onclick = null;
}
opts.plain ? $(target).addClass('l-btn-disabled l-btn-plain-disabled') : $(target).addClass('l-btn-disabled');
} else {
opts.disabled = false;
if (state.href) {
$(target).attr('href', state.href);
}
if (state.onclick) {
target.onclick = state.onclick;
}
}
}
$.fn.linkbutton = function(options, param){
if (typeof options == 'string'){
return $.fn.linkbutton.methods[options](this, param);
}
options = options || {};
return this.each(function(){
var state = $.data(this, 'linkbutton');
if (state){
$.extend(state.options, options);
} else {
$.data(this, 'linkbutton', {
options: $.extend({}, $.fn.linkbutton.defaults, $.fn.linkbutton.parseOptions(this), options)
});
$(this).removeAttr('disabled');
}
createButton(this);
});
};
$.fn.linkbutton.methods = {
options: function(jq){
return $.data(jq[0], 'linkbutton').options;
},
enable: function(jq){
return jq.each(function(){
setDisabled(this, false);
});
},
disable: function(jq){
return jq.each(function(){
setDisabled(this, true);
});
},
select: function(jq){
return jq.each(function(){
setSelected(this, true);
});
},
unselect: function(jq){
return jq.each(function(){
setSelected(this, false);
});
}
};
$.fn.linkbutton.parseOptions = function(target){
var t = $(target);
return $.extend({}, $.parser.parseOptions(target,
['id','iconCls','iconAlign','group',{plain:'boolean',toggle:'boolean',selected:'boolean'}]
), {
disabled: (t.attr('disabled') ? true : undefined),
text: $.trim(t.html()),
iconCls: (t.attr('icon') || t.attr('iconCls'))
});
};
$.fn.linkbutton.defaults = {
id: null,
disabled: false,
toggle: false,
selected: false,
group: null,
plain: false,
text: '',
iconCls: null,
iconAlign: 'left'
};
})(jQuery);

View File

@@ -0,0 +1,543 @@
/**
* menu - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*/
(function($){
/**
* initialize the target menu, the function can be invoked only once
*/
function init(target){
$(target).appendTo('body');
$(target).addClass('menu-top'); // the top menu
$(document).unbind('.menu').bind('mousedown.menu', function(e){
var allMenu = $('body>div.menu:visible');
var m = $(e.target).closest('div.menu', allMenu);
if (m.length){return}
$('body>div.menu-top:visible').menu('hide');
});
var menus = splitMenu($(target));
for(var i=0; i<menus.length; i++){
createMenu(menus[i]);
}
function splitMenu(menu){
var menus = [];
menu.addClass('menu');
menus.push(menu);
if (!menu.hasClass('menu-content')){
menu.children('div').each(function(){
var submenu = $(this).children('div');
if (submenu.length){
submenu.insertAfter(target);
this.submenu = submenu; // point to the sub menu
var mm = splitMenu(submenu);
menus = menus.concat(mm);
}
});
}
return menus;
}
function createMenu(menu){
var width = $.parser.parseOptions(menu[0], ['width']).width;
if (menu.hasClass('menu-content')){
menu[0].originalWidth = width || menu._outerWidth();
} else {
menu[0].originalWidth = width || 0;
menu.children('div').each(function(){
var item = $(this);
var itemOpts = $.extend({}, $.parser.parseOptions(this,['name','iconCls','href',{separator:'boolean'}]), {
disabled: (item.attr('disabled') ? true : undefined)
});
if (itemOpts.separator){
item.addClass('menu-sep');
}
if (!item.hasClass('menu-sep')){
item[0].itemName = itemOpts.name || '';
item[0].itemHref = itemOpts.href || '';
var text = item.addClass('menu-item').html();
item.empty().append($('<div class="menu-text"></div>').html(text));
if (itemOpts.iconCls){
$('<div class="menu-icon"></div>').addClass(itemOpts.iconCls).appendTo(item);
}
if (itemOpts.disabled){
setDisabled(target, item[0], true);
}
if (item[0].submenu){
$('<div class="menu-rightarrow"></div>').appendTo(item); // has sub menu
}
bindMenuItemEvent(target, item);
}
});
$('<div class="menu-line"></div>').prependTo(menu);
}
setMenuWidth(target, menu);
menu.hide();
bindMenuEvent(target, menu);
}
}
function setMenuWidth(target, menu){
var opts = $.data(target, 'menu').options;
// var d = menu.css('display');
var style = menu.attr('style');
menu.css({
display: 'block',
left:-10000,
height: 'auto',
overflow: 'hidden'
});
// menu.find('div.menu-item')._outerHeight(22);
var width = 0;
menu.find('div.menu-text').each(function(){
if (width < $(this)._outerWidth()){
width = $(this)._outerWidth();
}
$(this).closest('div.menu-item')._outerHeight($(this)._outerHeight()+2);
});
width += 65;
menu._outerWidth(Math.max((menu[0].originalWidth || 0), width, opts.minWidth));
menu.children('div.menu-line')._outerHeight(menu.outerHeight());
// menu.css('display', d);
menu.attr('style', style);
}
/**
* bind menu event
*/
function bindMenuEvent(target, menu){
var state = $.data(target, 'menu');
menu.unbind('.menu').bind('mouseenter.menu', function(){
if (state.timer){
clearTimeout(state.timer);
state.timer = null;
}
}).bind('mouseleave.menu', function(){
if (state.options.hideOnUnhover){
state.timer = setTimeout(function(){
hideAll(target);
}, 100);
}
});
}
/**
* bind menu item event
*/
function bindMenuItemEvent(target, item){
if (!item.hasClass('menu-item')){return}
item.unbind('.menu');
item.bind('click.menu', function(){
if ($(this).hasClass('menu-item-disabled')){
return;
}
// only the sub menu clicked can hide all menus
if (!this.submenu){
hideAll(target);
var href = $(this).attr('href');
if (href){
location.href = href;
}
}
var item = $(target).menu('getItem', this);
$.data(target, 'menu').options.onClick.call(target, item);
}).bind('mouseenter.menu', function(e){
// hide other menu
item.siblings().each(function(){
if (this.submenu){
hideMenu(this.submenu);
}
$(this).removeClass('menu-active');
});
// show this menu
item.addClass('menu-active');
if ($(this).hasClass('menu-item-disabled')){
item.addClass('menu-active-disabled');
return;
}
var submenu = item[0].submenu;
if (submenu){
$(target).menu('show', {
menu: submenu,
parent: item
});
}
}).bind('mouseleave.menu', function(e){
item.removeClass('menu-active menu-active-disabled');
var submenu = item[0].submenu;
if (submenu){
if (e.pageX>=parseInt(submenu.css('left'))){
item.addClass('menu-active');
} else {
hideMenu(submenu);
}
} else {
item.removeClass('menu-active');
}
});
}
/**
* hide top menu and it's all sub menus
*/
function hideAll(target){
var state = $.data(target, 'menu');
if (state){
if ($(target).is(':visible')){
hideMenu($(target));
state.options.onHide.call(target);
}
}
return false;
}
/**
* show the menu, the 'param' object has one or more properties:
* left: the left position to display
* top: the top position to display
* menu: the menu to display, if not defined, the 'target menu' is used
* parent: the parent menu item to align to
* alignTo: the element object to align to
*/
function showMenu(target, param){
var left,top;
param = param || {};
var menu = $(param.menu || target);
if (menu.hasClass('menu-top')){
var opts = $.data(target, 'menu').options;
$.extend(opts, param);
left = opts.left;
top = opts.top;
if (opts.alignTo){
var at = $(opts.alignTo);
left = at.offset().left;
top = at.offset().top + at._outerHeight();
}
// if (param.left != undefined){left = param.left}
// if (param.top != undefined){top = param.top}
if (left + menu.outerWidth() > $(window)._outerWidth() + $(document)._scrollLeft()){
left = $(window)._outerWidth() + $(document).scrollLeft() - menu.outerWidth() - 5;
}
if (top + menu.outerHeight() > $(window)._outerHeight() + $(document).scrollTop()){
// top -= menu.outerHeight();
top = $(window)._outerHeight() + $(document).scrollTop() - menu.outerHeight() - 5;
}
} else {
var parent = param.parent; // the parent menu item
left = parent.offset().left + parent.outerWidth() - 2;
if (left + menu.outerWidth() + 5 > $(window)._outerWidth() + $(document).scrollLeft()){
left = parent.offset().left - menu.outerWidth() + 2;
}
var top = parent.offset().top - 3;
if (top + menu.outerHeight() > $(window)._outerHeight() + $(document).scrollTop()){
top = $(window)._outerHeight() + $(document).scrollTop() - menu.outerHeight() - 5;
}
}
menu.css({left:left,top:top});
menu.show(0, function(){
if (!menu[0].shadow){
menu[0].shadow = $('<div class="menu-shadow"></div>').insertAfter(menu);
}
menu[0].shadow.css({
display:'block',
zIndex:$.fn.menu.defaults.zIndex++,
left:menu.css('left'),
top:menu.css('top'),
width:menu.outerWidth(),
height:menu.outerHeight()
});
menu.css('z-index', $.fn.menu.defaults.zIndex++);
if (menu.hasClass('menu-top')){
$.data(menu[0], 'menu').options.onShow.call(menu[0]);
}
});
}
function hideMenu(menu){
if (!menu) return;
hideit(menu);
menu.find('div.menu-item').each(function(){
if (this.submenu){
hideMenu(this.submenu);
}
$(this).removeClass('menu-active');
});
function hideit(m){
m.stop(true,true);
if (m[0].shadow){
m[0].shadow.hide();
}
m.hide();
}
}
function findItem(target, text){
var result = null;
var tmp = $('<div></div>');
function find(menu){
menu.children('div.menu-item').each(function(){
var item = $(target).menu('getItem', this);
var s = tmp.empty().html(item.text).text();
if (text == $.trim(s)) {
result = item;
} else if (this.submenu && !result){
find(this.submenu);
}
});
}
find($(target));
tmp.remove();
return result;
}
function setDisabled(target, itemEl, disabled){
var t = $(itemEl);
if (!t.hasClass('menu-item')){return}
if (disabled){
t.addClass('menu-item-disabled');
if (itemEl.onclick){
itemEl.onclick1 = itemEl.onclick;
itemEl.onclick = null;
}
} else {
t.removeClass('menu-item-disabled');
if (itemEl.onclick1){
itemEl.onclick = itemEl.onclick1;
itemEl.onclick1 = null;
}
}
}
function appendItem(target, param){
var menu = $(target);
if (param.parent){
if (!param.parent.submenu){
var submenu = $('<div class="menu"><div class="menu-line"></div></div>').appendTo('body');
submenu.hide();
param.parent.submenu = submenu;
$('<div class="menu-rightarrow"></div>').appendTo(param.parent);
}
menu = param.parent.submenu;
}
if (param.separator){
var item = $('<div class="menu-sep"></div>').appendTo(menu);
} else {
var item = $('<div class="menu-item"></div>').appendTo(menu);
$('<div class="menu-text"></div>').html(param.text).appendTo(item);
}
if (param.iconCls) $('<div class="menu-icon"></div>').addClass(param.iconCls).appendTo(item);
if (param.id) item.attr('id', param.id);
if (param.name){item[0].itemName = param.name}
if (param.href){item[0].itemHref = param.href}
if (param.onclick){
if (typeof param.onclick == 'string'){
item.attr('onclick', param.onclick);
} else {
item[0].onclick = eval(param.onclick);
}
}
if (param.handler){item[0].onclick = eval(param.handler)}
if (param.disabled){setDisabled(target, item[0], true)}
bindMenuItemEvent(target, item);
bindMenuEvent(target, menu);
setMenuWidth(target, menu);
}
function removeItem(target, itemEl){
function removeit(el){
if (el.submenu){
el.submenu.children('div.menu-item').each(function(){
removeit(this);
});
var shadow = el.submenu[0].shadow;
if (shadow) shadow.remove();
el.submenu.remove();
}
$(el).remove();
}
removeit(itemEl);
}
function destroyMenu(target){
$(target).children('div.menu-item').each(function(){
removeItem(target, this);
});
if (target.shadow) target.shadow.remove();
$(target).remove();
}
$.fn.menu = function(options, param){
if (typeof options == 'string'){
return $.fn.menu.methods[options](this, param);
}
options = options || {};
return this.each(function(){
var state = $.data(this, 'menu');
if (state){
$.extend(state.options, options);
} else {
state = $.data(this, 'menu', {
options: $.extend({}, $.fn.menu.defaults, $.fn.menu.parseOptions(this), options)
});
init(this);
}
$(this).css({
left: state.options.left,
top: state.options.top
});
});
};
$.fn.menu.methods = {
options: function(jq){
return $.data(jq[0], 'menu').options;
},
show: function(jq, pos){
return jq.each(function(){
showMenu(this, pos);
});
},
hide: function(jq){
return jq.each(function(){
hideAll(this);
});
},
destroy: function(jq){
return jq.each(function(){
destroyMenu(this);
});
},
/**
* set the menu item text
* param: {
* target: DOM object, indicate the menu item
* text: string, the new text
* }
*/
setText: function(jq, param){
return jq.each(function(){
$(param.target).children('div.menu-text').html(param.text);
});
},
/**
* set the menu icon class
* param: {
* target: DOM object, indicate the menu item
* iconCls: the menu item icon class
* }
*/
setIcon: function(jq, param){
return jq.each(function(){
var item = $(this).menu('getItem', param.target);
if (item.iconCls){
$(item.target).children('div.menu-icon').removeClass(item.iconCls).addClass(param.iconCls);
} else {
$('<div class="menu-icon"></div>').addClass(param.iconCls).appendTo(param.target);
}
});
},
/**
* get the menu item data that contains the following property:
* {
* target: DOM object, the menu item
* id: the menu id
* text: the menu item text
* iconCls: the icon class
* href: a remote address to redirect to
* onclick: a function to be called when the item is clicked
* }
*/
getItem: function(jq, itemEl){
var t = $(itemEl);
var item = {
target: itemEl,
id: t.attr('id'),
text: $.trim(t.children('div.menu-text').html()),
disabled: t.hasClass('menu-item-disabled'),
// href: t.attr('href'),
// name: t.attr('name'),
name: itemEl.itemName,
href: itemEl.itemHref,
onclick: itemEl.onclick
}
var icon = t.children('div.menu-icon');
if (icon.length){
var cc = [];
var aa = icon.attr('class').split(' ');
for(var i=0; i<aa.length; i++){
if (aa[i] != 'menu-icon'){
cc.push(aa[i]);
}
}
item.iconCls = cc.join(' ');
}
return item;
},
findItem: function(jq, text){
return findItem(jq[0], text);
},
/**
* append menu item, the param contains following properties:
* parent,id,text,iconCls,href,onclick
* when parent property is assigned, append menu item to it
*/
appendItem: function(jq, param){
return jq.each(function(){
appendItem(this, param);
});
},
removeItem: function(jq, itemEl){
return jq.each(function(){
removeItem(this, itemEl);
});
},
enableItem: function(jq, itemEl){
return jq.each(function(){
setDisabled(this, itemEl, false);
});
},
disableItem: function(jq, itemEl){
return jq.each(function(){
setDisabled(this, itemEl, true);
});
}
};
$.fn.menu.parseOptions = function(target){
return $.extend({}, $.parser.parseOptions(target, ['left','top',{minWidth:'number',hideOnUnhover:'boolean'}]));
};
$.fn.menu.defaults = {
zIndex:110000,
left: 0,
top: 0,
minWidth: 120,
hideOnUnhover: true, // Automatically hides the menu when mouse exits it
onShow: function(){},
onHide: function(){},
onClick: function(item){}
};
})(jQuery);

View File

@@ -0,0 +1,263 @@
/**
* parser - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*
*/
(function($){
$.parser = {
auto: true,
onComplete: function(context){},
plugins:['draggable','droppable','resizable','pagination','tooltip',
'linkbutton','menu','menubutton','splitbutton','progressbar',
'tree','combobox','combotree','combogrid','numberbox','validatebox','searchbox',
'numberspinner','timespinner','calendar','datebox','datetimebox','slider',
'layout','panel','datagrid','propertygrid','treegrid','tabs','accordion','window','dialog'
],
parse: function(context){
var aa = [];
for(var i=0; i<$.parser.plugins.length; i++){
var name = $.parser.plugins[i];
var r = $('.easyui-' + name, context);
if (r.length){
if (r[name]){
r[name]();
} else {
aa.push({name:name,jq:r});
}
}
}
if (aa.length && window.easyloader){
var names = [];
for(var i=0; i<aa.length; i++){
names.push(aa[i].name);
}
easyloader.load(names, function(){
for(var i=0; i<aa.length; i++){
var name = aa[i].name;
var jq = aa[i].jq;
jq[name]();
}
$.parser.onComplete.call($.parser, context);
});
} else {
$.parser.onComplete.call($.parser, context);
}
},
/**
* parse options, including standard 'data-options' attribute.
*
* calling examples:
* $.parser.parseOptions(target);
* $.parser.parseOptions(target, ['id','title','width',{fit:'boolean',border:'boolean'},{min:'number'}]);
*/
parseOptions: function(target, properties){
var t = $(target);
var options = {};
var s = $.trim(t.attr('data-options'));
if (s){
// var first = s.substring(0,1);
// var last = s.substring(s.length-1,1);
// if (first != '{') s = '{' + s;
// if (last != '}') s = s + '}';
if (s.substring(0, 1) != '{'){
s = '{' + s + '}';
}
options = (new Function('return ' + s))();
}
if (properties){
var opts = {};
for(var i=0; i<properties.length; i++){
var pp = properties[i];
if (typeof pp == 'string'){
if (pp == 'width' || pp == 'height' || pp == 'left' || pp == 'top'){
opts[pp] = parseInt(target.style[pp]) || undefined;
} else {
opts[pp] = t.attr(pp);
}
} else {
for(var name in pp){
var type = pp[name];
if (type == 'boolean'){
opts[name] = t.attr(name) ? (t.attr(name) == 'true') : undefined;
} else if (type == 'number'){
opts[name] = t.attr(name)=='0' ? 0 : parseFloat(t.attr(name)) || undefined;
}
}
}
}
$.extend(options, opts);
}
return options;
}
};
$(function(){
var d = $('<div style="position:absolute;top:-1000px;width:100px;height:100px;padding:5px"></div>').appendTo('body');
d.width(100);
$._boxModel = parseInt(d.width()) == 100;
d.remove();
if (!window.easyloader && $.parser.auto){
$.parser.parse();
}
});
/**
* extend plugin to set box model width
*/
$.fn._outerWidth = function(width){
if (width == undefined){
if (this[0] == window){
return this.width() || document.body.clientWidth;
}
return this.outerWidth()||0;
}
return this.each(function(){
if ($._boxModel){
$(this).width(width - ($(this).outerWidth() - $(this).width()));
} else {
$(this).width(width);
}
});
};
/**
* extend plugin to set box model height
*/
$.fn._outerHeight = function(height){
if (height == undefined){
if (this[0] == window){
return this.height() || document.body.clientHeight;
}
return this.outerHeight()||0;
}
return this.each(function(){
if ($._boxModel){
$(this).height(height - ($(this).outerHeight() - $(this).height()));
} else {
$(this).height(height);
}
});
};
$.fn._scrollLeft = function(left){
if (left == undefined){
return this.scrollLeft();
} else {
return this.each(function(){$(this).scrollLeft(left)});
}
}
$.fn._propAttr = $.fn.prop || $.fn.attr;
/**
* set or unset the fit property of parent container, return the width and height of parent container
*/
$.fn._fit = function(fit){
fit = fit == undefined ? true : fit;
var t = this[0];
var p = (t.tagName == 'BODY' ? t : this.parent()[0]);
var fcount = p.fcount || 0;
if (fit){
if (!t.fitted){
t.fitted = true;
p.fcount = fcount + 1;
$(p).addClass('panel-noscroll');
if (p.tagName == 'BODY'){
$('html').addClass('panel-fit');
}
}
} else {
if (t.fitted){
t.fitted = false;
p.fcount = fcount - 1;
if (p.fcount == 0){
$(p).removeClass('panel-noscroll');
if (p.tagName == 'BODY'){
$('html').removeClass('panel-fit');
}
}
}
}
return {
width: $(p).width(),
height: $(p).height()
}
}
})(jQuery);
/**
* support for mobile devices
*/
(function($){
var longTouchTimer = null;
var dblTouchTimer = null;
var isDblClick = false;
function onTouchStart(e){
if (e.touches.length != 1){return}
if (!isDblClick){
isDblClick = true;
dblClickTimer = setTimeout(function(){
isDblClick = false;
}, 500);
} else {
clearTimeout(dblClickTimer);
isDblClick = false;
fire(e, 'dblclick');
// e.preventDefault();
}
longTouchTimer = setTimeout(function(){
fire(e, 'contextmenu', 3);
}, 1000);
fire(e, 'mousedown');
if ($.fn.draggable.isDragging || $.fn.resizable.isResizing){
e.preventDefault();
}
}
function onTouchMove(e){
if (e.touches.length != 1){return}
if (longTouchTimer){
clearTimeout(longTouchTimer);
}
fire(e, 'mousemove');
if ($.fn.draggable.isDragging || $.fn.resizable.isResizing){
e.preventDefault();
}
}
function onTouchEnd(e){
// if (e.touches.length > 0){return}
if (longTouchTimer){
clearTimeout(longTouchTimer);
}
fire(e, 'mouseup');
if ($.fn.draggable.isDragging || $.fn.resizable.isResizing){
e.preventDefault();
}
}
function fire(e, name, which){
var event = new $.Event(name);
event.pageX = e.changedTouches[0].pageX;
event.pageY = e.changedTouches[0].pageY;
event.which = which || 1;
$(e.target).trigger(event);
}
if (document.addEventListener){
document.addEventListener("touchstart", onTouchStart, true);
document.addEventListener("touchmove", onTouchMove, true);
document.addEventListener("touchend", onTouchEnd, true);
}
})(jQuery);

View File

@@ -0,0 +1,99 @@
/**
* progressbar - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*
* Dependencies:
* none
*
*/
(function($){
function init(target){
$(target).addClass('progressbar');
$(target).html('<div class="progressbar-text"></div><div class="progressbar-value"><div class="progressbar-text"></div></div>');
return $(target);
}
function setSize(target,width){
var opts = $.data(target, 'progressbar').options;
var bar = $.data(target, 'progressbar').bar;
if (width) opts.width = width;
bar._outerWidth(opts.width)._outerHeight(opts.height);
bar.find('div.progressbar-text').width(bar.width());
bar.find('div.progressbar-text,div.progressbar-value').css({
height: bar.height()+'px',
lineHeight: bar.height()+'px'
});
}
$.fn.progressbar = function(options, param){
if (typeof options == 'string'){
var method = $.fn.progressbar.methods[options];
if (method){
return method(this, param);
}
}
options = options || {};
return this.each(function(){
var state = $.data(this, 'progressbar');
if (state){
$.extend(state.options, options);
} else {
state = $.data(this, 'progressbar', {
options: $.extend({}, $.fn.progressbar.defaults, $.fn.progressbar.parseOptions(this), options),
bar: init(this)
});
}
$(this).progressbar('setValue', state.options.value);
setSize(this);
});
};
$.fn.progressbar.methods = {
options: function(jq){
return $.data(jq[0], 'progressbar').options;
},
resize: function(jq, width){
return jq.each(function(){
setSize(this, width);
});
},
getValue: function(jq){
return $.data(jq[0], 'progressbar').options.value;
},
setValue: function(jq, value){
if (value < 0) value = 0;
if (value > 100) value = 100;
return jq.each(function(){
var opts = $.data(this, 'progressbar').options;
var text = opts.text.replace(/{value}/, value);
var oldValue = opts.value;
opts.value = value;
$(this).find('div.progressbar-value').width(value+'%');
$(this).find('div.progressbar-text').html(text);
if (oldValue != value){
opts.onChange.call(this, value, oldValue);
}
});
}
};
$.fn.progressbar.parseOptions = function(target){
return $.extend({}, $.parser.parseOptions(target, ['width','height','text',{value:'number'}]));
};
$.fn.progressbar.defaults = {
width: 'auto',
height: 22,
value: 0, // percentage value
text: '{value}%',
onChange:function(newValue,oldValue){}
};
})(jQuery);

View File

@@ -0,0 +1,315 @@
/**
* propertygrid - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*
* Dependencies:
* datagrid
*
*/
(function($){
var currTarget;
function buildGrid(target){
var state = $.data(target, 'propertygrid');
var opts = $.data(target, 'propertygrid').options;
$(target).datagrid($.extend({}, opts, {
cls:'propertygrid',
view:(opts.showGroup ? opts.groupView : opts.view),
onClickRow:function(index, row){
if (currTarget != this){
// leaveCurrRow();
stopEditing(currTarget);
currTarget = this;
}
if (opts.editIndex != index && row.editor){
var col = $(this).datagrid('getColumnOption', "value");
col.editor = row.editor;
// leaveCurrRow();
stopEditing(currTarget);
$(this).datagrid('beginEdit', index);
$(this).datagrid('getEditors', index)[0].target.focus();
opts.editIndex = index;
}
opts.onClickRow.call(target, index, row);
},
loadFilter:function(data){
stopEditing(this);
return opts.loadFilter.call(this, data);
}
}));
$(document).unbind('.propertygrid').bind('mousedown.propertygrid', function(e){
var p = $(e.target).closest('div.datagrid-view,div.combo-panel');
// var p = $(e.target).closest('div.propertygrid,div.combo-panel');
if (p.length){return;}
stopEditing(currTarget);
currTarget = undefined;
});
// function leaveCurrRow(){
// var t = $(currTarget);
// if (!t.length){return;}
// var opts = $.data(currTarget, 'propertygrid').options;
// var index = opts.editIndex;
// if (index == undefined){return;}
// var ed = t.datagrid('getEditors', index)[0];
// if (ed){
// ed.target.blur();
// if (t.datagrid('validateRow', index)){
// t.datagrid('endEdit', index);
// } else {
// t.datagrid('cancelEdit', index);
// }
// }
// opts.editIndex = undefined;
// }
}
function stopEditing(target){
var t = $(target);
if (!t.length){return}
var opts = $.data(target, 'propertygrid').options;
var index = opts.editIndex;
if (index == undefined){return;}
var ed = t.datagrid('getEditors', index)[0];
if (ed){
ed.target.blur();
if (t.datagrid('validateRow', index)){
t.datagrid('endEdit', index);
} else {
t.datagrid('cancelEdit', index);
}
}
opts.editIndex = undefined;
}
$.fn.propertygrid = function(options, param){
if (typeof options == 'string'){
var method = $.fn.propertygrid.methods[options];
if (method){
return method(this, param);
} else {
return this.datagrid(options, param);
}
}
options = options || {};
return this.each(function(){
var state = $.data(this, 'propertygrid');
if (state){
$.extend(state.options, options);
} else {
var opts = $.extend({}, $.fn.propertygrid.defaults, $.fn.propertygrid.parseOptions(this), options);
opts.frozenColumns = $.extend(true, [], opts.frozenColumns);
opts.columns = $.extend(true, [], opts.columns);
$.data(this, 'propertygrid', {
options: opts
});
}
buildGrid(this);
});
}
$.fn.propertygrid.methods = {
options: function(jq){
return $.data(jq[0], 'propertygrid').options;
}
};
$.fn.propertygrid.parseOptions = function(target){
return $.extend({}, $.fn.datagrid.parseOptions(target), $.parser.parseOptions(target,[{showGroup:'boolean'}]));
};
// the group view definition
var groupview = $.extend({}, $.fn.datagrid.defaults.view, {
render: function(target, container, frozen){
var table = [];
var groups = this.groups;
for(var i=0; i<groups.length; i++){
table.push(this.renderGroup.call(this, target, i, groups[i], frozen));
}
$(container).html(table.join(''));
},
renderGroup: function(target, groupIndex, group, frozen){
var state = $.data(target, 'datagrid');
var opts = state.options;
var fields = $(target).datagrid('getColumnFields', frozen);
var table = [];
table.push('<div class="datagrid-group" group-index=' + groupIndex + '>');
table.push('<table cellspacing="0" cellpadding="0" border="0" style="height:100%"><tbody>');
table.push('<tr>');
if ((frozen && (opts.rownumbers || opts.frozenColumns.length)) ||
(!frozen && !(opts.rownumbers || opts.frozenColumns.length))){
table.push('<td style="border:0;text-align:center;width:25px"><span class="datagrid-row-expander datagrid-row-collapse" style="display:inline-block;width:16px;height:16px;cursor:pointer">&nbsp;</span></td>');
}
table.push('<td style="border:0;">');
if (!frozen){
table.push('<span class="datagrid-group-title">');
table.push(opts.groupFormatter.call(target, group.value, group.rows));
table.push('</span>');
}
table.push('</td>');
table.push('</tr>');
table.push('</tbody></table>');
table.push('</div>');
table.push('<table class="datagrid-btable" cellspacing="0" cellpadding="0" border="0"><tbody>');
var index = group.startIndex;
for(var j=0; j<group.rows.length; j++) {
var css = opts.rowStyler ? opts.rowStyler.call(target, index, group.rows[j]) : '';
var classValue = '';
var styleValue = '';
if (typeof css == 'string'){
styleValue = css;
} else if (css){
classValue = css['class'] || '';
styleValue = css['style'] || '';
}
var cls = 'class="datagrid-row ' + (index % 2 && opts.striped ? 'datagrid-row-alt ' : ' ') + classValue + '"';
var style = styleValue ? 'style="' + styleValue + '"' : '';
var rowId = state.rowIdPrefix + '-' + (frozen?1:2) + '-' + index;
table.push('<tr id="' + rowId + '" datagrid-row-index="' + index + '" ' + cls + ' ' + style + '>');
table.push(this.renderRow.call(this, target, fields, frozen, index, group.rows[j]));
table.push('</tr>');
index++;
}
table.push('</tbody></table>');
return table.join('');
},
bindEvents: function(target){
var state = $.data(target, 'datagrid');
var dc = state.dc;
var body = dc.body1.add(dc.body2);
var clickHandler = ($.data(body[0],'events')||$._data(body[0],'events')).click[0].handler;
body.unbind('click').bind('click', function(e){
var tt = $(e.target);
var expander = tt.closest('span.datagrid-row-expander');
if (expander.length){
var gindex = expander.closest('div.datagrid-group').attr('group-index');
if (expander.hasClass('datagrid-row-collapse')){
$(target).datagrid('collapseGroup', gindex);
} else {
$(target).datagrid('expandGroup', gindex);
}
} else {
clickHandler(e);
}
e.stopPropagation();
});
},
onBeforeRender: function(target, rows){
var state = $.data(target, 'datagrid');
var opts = state.options;
initCss();
var groups = [];
for(var i=0; i<rows.length; i++){
var row = rows[i];
var group = getGroup(row[opts.groupField]);
if (!group){
group = {
value: row[opts.groupField],
rows: [row]
};
groups.push(group);
} else {
group.rows.push(row);
}
}
var index = 0;
var newRows = [];
for(var i=0; i<groups.length; i++){
var group = groups[i];
group.startIndex = index;
index += group.rows.length;
newRows = newRows.concat(group.rows);
}
state.data.rows = newRows;
this.groups = groups;
var that = this;
setTimeout(function(){
that.bindEvents(target);
},0);
function getGroup(value){
for(var i=0; i<groups.length; i++){
var group = groups[i];
if (group.value == value){
return group;
}
}
return null;
}
function initCss(){
if (!$('#datagrid-group-style').length){
$('head').append(
'<style id="datagrid-group-style">' +
'.datagrid-group{height:25px;overflow:hidden;font-weight:bold;border-bottom:1px solid #ccc;}' +
'</style>'
);
}
}
}
});
$.extend($.fn.datagrid.methods, {
expandGroup:function(jq, groupIndex){
return jq.each(function(){
var view = $.data(this, 'datagrid').dc.view;
var group = view.find(groupIndex!=undefined ? 'div.datagrid-group[group-index="'+groupIndex+'"]' : 'div.datagrid-group');
var expander = group.find('span.datagrid-row-expander');
if (expander.hasClass('datagrid-row-expand')){
expander.removeClass('datagrid-row-expand').addClass('datagrid-row-collapse');
group.next('table').show();
}
$(this).datagrid('fixRowHeight');
});
},
collapseGroup:function(jq, groupIndex){
return jq.each(function(){
var view = $.data(this, 'datagrid').dc.view;
var group = view.find(groupIndex!=undefined ? 'div.datagrid-group[group-index="'+groupIndex+'"]' : 'div.datagrid-group');
var expander = group.find('span.datagrid-row-expander');
if (expander.hasClass('datagrid-row-collapse')){
expander.removeClass('datagrid-row-collapse').addClass('datagrid-row-expand');
group.next('table').hide();
}
$(this).datagrid('fixRowHeight');
});
}
});
// end of group view definition
$.fn.propertygrid.defaults = $.extend({}, $.fn.datagrid.defaults, {
singleSelect:true,
remoteSort:false,
fitColumns:true,
loadMsg:'',
frozenColumns:[[
{field:'f',width:16,resizable:false}
]],
columns:[[
{field:'name',title:'Name',width:100,sortable:true},
{field:'value',title:'Value',width:100,resizable:false}
]],
showGroup:false,
groupView:groupview,
groupField:'group',
groupFormatter:function(fvalue,rows){return fvalue}
});
})(jQuery);

View File

@@ -0,0 +1,244 @@
/**
* resizable - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*/
(function($){
// var isResizing = false;
$.fn.resizable = function(options, param){
if (typeof options == 'string'){
return $.fn.resizable.methods[options](this, param);
}
function resize(e){
var resizeData = e.data;
var options = $.data(resizeData.target, 'resizable').options;
if (resizeData.dir.indexOf('e') != -1) {
var width = resizeData.startWidth + e.pageX - resizeData.startX;
width = Math.min(
Math.max(width, options.minWidth),
options.maxWidth
);
resizeData.width = width;
}
if (resizeData.dir.indexOf('s') != -1) {
var height = resizeData.startHeight + e.pageY - resizeData.startY;
height = Math.min(
Math.max(height, options.minHeight),
options.maxHeight
);
resizeData.height = height;
}
if (resizeData.dir.indexOf('w') != -1) {
var width = resizeData.startWidth - e.pageX + resizeData.startX;
width = Math.min(
Math.max(width, options.minWidth),
options.maxWidth
);
resizeData.width = width;
resizeData.left = resizeData.startLeft + resizeData.startWidth - resizeData.width;
// resizeData.width = resizeData.startWidth - e.pageX + resizeData.startX;
// if (resizeData.width >= options.minWidth && resizeData.width <= options.maxWidth) {
// resizeData.left = resizeData.startLeft + e.pageX - resizeData.startX;
// }
}
if (resizeData.dir.indexOf('n') != -1) {
var height = resizeData.startHeight - e.pageY + resizeData.startY;
height = Math.min(
Math.max(height, options.minHeight),
options.maxHeight
);
resizeData.height = height;
resizeData.top = resizeData.startTop + resizeData.startHeight - resizeData.height;
// resizeData.height = resizeData.startHeight - e.pageY + resizeData.startY;
// if (resizeData.height >= options.minHeight && resizeData.height <= options.maxHeight) {
// resizeData.top = resizeData.startTop + e.pageY - resizeData.startY;
// }
}
}
function applySize(e){
var resizeData = e.data;
var t = $(resizeData.target);
t.css({
left: resizeData.left,
top: resizeData.top
});
if (t.outerWidth() != resizeData.width){t._outerWidth(resizeData.width)}
if (t.outerHeight() != resizeData.height){t._outerHeight(resizeData.height)}
// t._outerWidth(resizeData.width)._outerHeight(resizeData.height);
}
function doDown(e){
// isResizing = true;
$.fn.resizable.isResizing = true;
$.data(e.data.target, 'resizable').options.onStartResize.call(e.data.target, e);
return false;
}
function doMove(e){
resize(e);
if ($.data(e.data.target, 'resizable').options.onResize.call(e.data.target, e) != false){
applySize(e)
}
return false;
}
function doUp(e){
// isResizing = false;
$.fn.resizable.isResizing = false;
resize(e, true);
applySize(e);
$.data(e.data.target, 'resizable').options.onStopResize.call(e.data.target, e);
$(document).unbind('.resizable');
$('body').css('cursor','');
// $('body').css('cursor','auto');
return false;
}
return this.each(function(){
var opts = null;
var state = $.data(this, 'resizable');
if (state) {
$(this).unbind('.resizable');
opts = $.extend(state.options, options || {});
} else {
opts = $.extend({}, $.fn.resizable.defaults, $.fn.resizable.parseOptions(this), options || {});
$.data(this, 'resizable', {
options:opts
});
}
if (opts.disabled == true) {
return;
}
// bind mouse event using namespace resizable
$(this).bind('mousemove.resizable', {target:this}, function(e){
// if (isResizing) return;
if ($.fn.resizable.isResizing){return}
var dir = getDirection(e);
if (dir == '') {
$(e.data.target).css('cursor', '');
} else {
$(e.data.target).css('cursor', dir + '-resize');
}
}).bind('mouseleave.resizable', {target:this}, function(e){
$(e.data.target).css('cursor', '');
}).bind('mousedown.resizable', {target:this}, function(e){
var dir = getDirection(e);
if (dir == '') return;
function getCssValue(css) {
var val = parseInt($(e.data.target).css(css));
if (isNaN(val)) {
return 0;
} else {
return val;
}
}
var data = {
target: e.data.target,
dir: dir,
startLeft: getCssValue('left'),
startTop: getCssValue('top'),
left: getCssValue('left'),
top: getCssValue('top'),
startX: e.pageX,
startY: e.pageY,
startWidth: $(e.data.target).outerWidth(),
startHeight: $(e.data.target).outerHeight(),
width: $(e.data.target).outerWidth(),
height: $(e.data.target).outerHeight(),
deltaWidth: $(e.data.target).outerWidth() - $(e.data.target).width(),
deltaHeight: $(e.data.target).outerHeight() - $(e.data.target).height()
};
$(document).bind('mousedown.resizable', data, doDown);
$(document).bind('mousemove.resizable', data, doMove);
$(document).bind('mouseup.resizable', data, doUp);
$('body').css('cursor', dir+'-resize');
});
// get the resize direction
function getDirection(e) {
var tt = $(e.data.target);
var dir = '';
var offset = tt.offset();
var width = tt.outerWidth();
var height = tt.outerHeight();
var edge = opts.edge;
if (e.pageY > offset.top && e.pageY < offset.top + edge) {
dir += 'n';
} else if (e.pageY < offset.top + height && e.pageY > offset.top + height - edge) {
dir += 's';
}
if (e.pageX > offset.left && e.pageX < offset.left + edge) {
dir += 'w';
} else if (e.pageX < offset.left + width && e.pageX > offset.left + width - edge) {
dir += 'e';
}
var handles = opts.handles.split(',');
for(var i=0; i<handles.length; i++) {
var handle = handles[i].replace(/(^\s*)|(\s*$)/g, '');
if (handle == 'all' || handle == dir) {
return dir;
}
}
return '';
}
});
};
$.fn.resizable.methods = {
options: function(jq){
return $.data(jq[0], 'resizable').options;
},
enable: function(jq){
return jq.each(function(){
$(this).resizable({disabled:false});
});
},
disable: function(jq){
return jq.each(function(){
$(this).resizable({disabled:true});
});
}
};
$.fn.resizable.parseOptions = function(target){
var t = $(target);
return $.extend({},
$.parser.parseOptions(target, [
'handles',{minWidth:'number',minHeight:'number',maxWidth:'number',maxHeight:'number',edge:'number'}
]), {
disabled: (t.attr('disabled') ? true : undefined)
})
};
$.fn.resizable.defaults = {
disabled:false,
handles:'n, e, s, w, ne, se, sw, nw, all',
minWidth: 10,
minHeight: 10,
maxWidth: 10000,//$(document).width(),
maxHeight: 10000,//$(document).height(),
edge:5,
onStartResize: function(e){},
onResize: function(e){},
onStopResize: function(e){}
};
$.fn.resizable.isResizing = false;
})(jQuery);

View File

@@ -0,0 +1,368 @@
/**
* slider - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*
* Dependencies:
* draggable
*
*/
(function($){
function init(target){
var slider = $('<div class="slider">' +
'<div class="slider-inner">' +
'<a href="javascript:void(0)" class="slider-handle"></a>' +
'<span class="slider-tip"></span>' +
'</div>' +
'<div class="slider-rule"></div>' +
'<div class="slider-rulelabel"></div>' +
'<div style="clear:both"></div>' +
'<input type="hidden" class="slider-value">' +
'</div>').insertAfter(target);
var t = $(target);
t.addClass('slider-f').hide();
var name = t.attr('name');
if (name){
slider.find('input.slider-value').attr('name', name);
t.removeAttr('name').attr('sliderName', name);
}
return slider;
}
/**
* set the slider size, for vertical slider, the height property is required
*/
function setSize(target, param){
var state = $.data(target, 'slider');
var opts = state.options;
var slider = state.slider;
if (param){
if (param.width) opts.width = param.width;
if (param.height) opts.height = param.height;
}
if (opts.mode == 'h'){
slider.css('height', '');
slider.children('div').css('height', '');
if (!isNaN(opts.width)){
slider.width(opts.width);
}
} else {
slider.css('width', '');
slider.children('div').css('width', '');
if (!isNaN(opts.height)){
slider.height(opts.height);
slider.find('div.slider-rule').height(opts.height);
slider.find('div.slider-rulelabel').height(opts.height);
slider.find('div.slider-inner')._outerHeight(opts.height);
}
}
initValue(target);
}
/**
* show slider rule if needed
*/
function showRule(target){
var state = $.data(target, 'slider');
var opts = state.options;
var slider = state.slider;
var aa = opts.mode == 'h' ? opts.rule : opts.rule.slice(0).reverse();
if (opts.reversed){
aa = aa.slice(0).reverse();
}
_build(aa);
function _build(aa){
var rule = slider.find('div.slider-rule');
var label = slider.find('div.slider-rulelabel');
rule.empty();
label.empty();
for(var i=0; i<aa.length; i++){
var distance = i*100/(aa.length-1)+'%';
var span = $('<span></span>').appendTo(rule);
span.css((opts.mode=='h'?'left':'top'), distance);
// show the labels
if (aa[i] != '|'){
span = $('<span></span>').appendTo(label);
span.html(aa[i]);
if (opts.mode == 'h'){
span.css({
left: distance,
marginLeft: -Math.round(span.outerWidth()/2)
});
} else {
span.css({
top: distance,
marginTop: -Math.round(span.outerHeight()/2)
});
}
}
}
}
}
/**
* build the slider and set some properties
*/
function buildSlider(target){
var state = $.data(target, 'slider');
var opts = state.options;
var slider = state.slider;
slider.removeClass('slider-h slider-v slider-disabled');
slider.addClass(opts.mode == 'h' ? 'slider-h' : 'slider-v');
slider.addClass(opts.disabled ? 'slider-disabled' : '');
slider.find('a.slider-handle').draggable({
axis:opts.mode,
cursor:'pointer',
disabled: opts.disabled,
onDrag:function(e){
var left = e.data.left;
var width = slider.width();
if (opts.mode!='h'){
left = e.data.top;
width = slider.height();
}
if (left < 0 || left > width) {
return false;
} else {
var value = pos2value(target, left);
adjustValue(value);
return false;
}
},
onBeforeDrag:function(){
state.isDragging = true;
},
onStartDrag:function(){
opts.onSlideStart.call(target, opts.value);
},
onStopDrag:function(e){
var value = pos2value(target, (opts.mode=='h'?e.data.left:e.data.top));
adjustValue(value);
opts.onSlideEnd.call(target, opts.value);
opts.onComplete.call(target, opts.value);
state.isDragging = false;
}
});
slider.find('div.slider-inner').unbind('.slider').bind('mousedown.slider', function(e){
if (state.isDragging){return}
var pos = $(this).offset();
var value = pos2value(target, (opts.mode=='h'?(e.pageX-pos.left):(e.pageY-pos.top)));
adjustValue(value);
opts.onComplete.call(target, opts.value);
});
function adjustValue(value){
var s = Math.abs(value % opts.step);
if (s < opts.step/2){
value -= s;
} else {
value = value - s + opts.step;
}
setValue(target, value);
}
}
/**
* set a specified value to slider
*/
function setValue(target, value){
var state = $.data(target, 'slider');
var opts = state.options;
var slider = state.slider;
var oldValue = opts.value;
if (value < opts.min) value = opts.min;
if (value > opts.max) value = opts.max;
opts.value = value;
$(target).val(value);
slider.find('input.slider-value').val(value);
var pos = value2pos(target, value);
var tip = slider.find('.slider-tip');
if (opts.showTip){
tip.show();
tip.html(opts.tipFormatter.call(target, opts.value));
} else {
tip.hide();
}
if (opts.mode == 'h'){
var style = 'left:'+pos+'px;';
slider.find('.slider-handle').attr('style', style);
tip.attr('style', style + 'margin-left:' + (-Math.round(tip.outerWidth()/2)) + 'px');
} else {
var style = 'top:' + pos + 'px;';
slider.find('.slider-handle').attr('style', style);
tip.attr('style', style + 'margin-left:' + (-Math.round(tip.outerWidth())) + 'px');
}
if (oldValue != value){
opts.onChange.call(target, value, oldValue);
}
}
function initValue(target){
var opts = $.data(target, 'slider').options;
var fn = opts.onChange;
opts.onChange = function(){};
setValue(target, opts.value);
opts.onChange = fn;
}
/**
* translate value to slider position
*/
function value2pos(target, value){
var state = $.data(target, 'slider');
var opts = state.options;
var slider = state.slider;
if (opts.mode == 'h'){
var pos = (value-opts.min)/(opts.max-opts.min)*slider.width();
if (opts.reversed){
pos = slider.width() - pos;
}
} else {
var pos = slider.height() - (value-opts.min)/(opts.max-opts.min)*slider.height();
if (opts.reversed){
pos = slider.height() - pos;
}
}
return pos.toFixed(0);
}
/**
* translate slider position to value
*/
function pos2value(target, pos){
var state = $.data(target, 'slider');
var opts = state.options;
var slider = state.slider;
if (opts.mode == 'h'){
var value = opts.min + (opts.max-opts.min)*(pos/slider.width());
} else {
var value = opts.min + (opts.max-opts.min)*((slider.height()-pos)/slider.height());
}
return opts.reversed ? opts.max - value.toFixed(0) : value.toFixed(0);
}
$.fn.slider = function(options, param){
if (typeof options == 'string'){
return $.fn.slider.methods[options](this, param);
}
options = options || {};
return this.each(function(){
var state = $.data(this, 'slider');
if (state){
$.extend(state.options, options);
} else {
state = $.data(this, 'slider', {
options: $.extend({}, $.fn.slider.defaults, $.fn.slider.parseOptions(this), options),
slider: init(this)
});
$(this).removeAttr('disabled');
}
var opts = state.options;
opts.min = parseFloat(opts.min);
opts.max = parseFloat(opts.max);
opts.value = parseFloat(opts.value);
opts.step = parseFloat(opts.step);
opts.originalValue = opts.value;
buildSlider(this);
showRule(this);
setSize(this);
});
};
$.fn.slider.methods = {
options: function(jq){
return $.data(jq[0], 'slider').options;
},
destroy: function(jq){
return jq.each(function(){
$.data(this, 'slider').slider.remove();
$(this).remove();
});
},
resize: function(jq, param){
return jq.each(function(){
setSize(this, param);
});
},
getValue: function(jq){
return jq.slider('options').value;
},
setValue: function(jq, value){
return jq.each(function(){
setValue(this, value);
});
},
clear: function(jq){
return jq.each(function(){
var opts = $(this).slider('options');
setValue(this, opts.min);
});
},
reset: function(jq){
return jq.each(function(){
var opts = $(this).slider('options');
setValue(this, opts.originalValue);
});
},
enable: function(jq){
return jq.each(function(){
$.data(this, 'slider').options.disabled = false;
buildSlider(this);
});
},
disable: function(jq){
return jq.each(function(){
$.data(this, 'slider').options.disabled = true;
buildSlider(this);
});
}
};
$.fn.slider.parseOptions = function(target){
var t = $(target);
return $.extend({}, $.parser.parseOptions(target, [
'width','height','mode',{reversed:'boolean',showTip:'boolean',min:'number',max:'number',step:'number'}
]), {
value: (t.val() || undefined),
disabled: (t.attr('disabled') ? true : undefined),
rule: (t.attr('rule') ? eval(t.attr('rule')) : undefined)
});
};
$.fn.slider.defaults = {
width: 'auto',
height: 'auto',
mode: 'h', // 'h'(horizontal) or 'v'(vertical)
reversed: false,
showTip: false,
disabled: false,
value: 0,
min: 0,
max: 100,
step: 1,
rule: [], // [0,'|',100]
tipFormatter: function(value){return value},
onChange: function(value, oldValue){},
onSlideStart: function(value){},
onSlideEnd: function(value){},
onComplete: function(value){}
};
})(jQuery);

View File

@@ -0,0 +1,787 @@
/**
* tabs - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*
* Dependencies:
* panel
* linkbutton
*
*/
(function($){
/**
* set the tabs scrollers to show or not,
* dependent on the tabs count and width
*/
function setScrollers(container) {
var opts = $.data(container, 'tabs').options;
if (opts.tabPosition == 'left' || opts.tabPosition == 'right' || !opts.showHeader){return}
var header = $(container).children('div.tabs-header');
var tool = header.children('div.tabs-tool');
var sLeft = header.children('div.tabs-scroller-left');
var sRight = header.children('div.tabs-scroller-right');
var wrap = header.children('div.tabs-wrap');
// set the tool height
var tHeight = header.outerHeight();
if (opts.plain){
tHeight -= tHeight - header.height();
}
tool._outerHeight(tHeight);
var tabsWidth = 0;
$('ul.tabs li', header).each(function(){
tabsWidth += $(this).outerWidth(true);
});
var cWidth = header.width() - tool._outerWidth();
if (tabsWidth > cWidth) {
sLeft.add(sRight).show()._outerHeight(tHeight);
if (opts.toolPosition == 'left'){
tool.css({
left: sLeft.outerWidth(),
right: ''
});
wrap.css({
marginLeft: sLeft.outerWidth() + tool._outerWidth(),
marginRight: sRight._outerWidth(),
width: cWidth - sLeft.outerWidth() - sRight.outerWidth()
});
} else {
tool.css({
left: '',
right: sRight.outerWidth()
});
wrap.css({
marginLeft: sLeft.outerWidth(),
marginRight: sRight.outerWidth() + tool._outerWidth(),
width: cWidth - sLeft.outerWidth() - sRight.outerWidth()
});
}
} else {
sLeft.add(sRight).hide();
if (opts.toolPosition == 'left'){
tool.css({
left: 0,
right: ''
});
wrap.css({
marginLeft: tool._outerWidth(),
marginRight: 0,
width: cWidth
});
} else {
tool.css({
left: '',
right: 0
});
wrap.css({
marginLeft: 0,
marginRight: tool._outerWidth(),
width: cWidth
});
}
}
}
function addTools(container){
var opts = $.data(container, 'tabs').options;
var header = $(container).children('div.tabs-header');
if (opts.tools) {
if (typeof opts.tools == 'string'){
$(opts.tools).addClass('tabs-tool').appendTo(header);
$(opts.tools).show();
} else {
header.children('div.tabs-tool').remove();
var tools = $('<div class="tabs-tool"><table cellspacing="0" cellpadding="0" style="height:100%"><tr></tr></table></div>').appendTo(header);
var tr = tools.find('tr');
for(var i=0; i<opts.tools.length; i++){
var td = $('<td></td>').appendTo(tr);
var tool = $('<a href="javascript:void(0);"></a>').appendTo(td);
tool[0].onclick = eval(opts.tools[i].handler || function(){});
tool.linkbutton($.extend({}, opts.tools[i], {
plain: true
}));
}
}
} else {
header.children('div.tabs-tool').remove();
}
}
function setSize(container) {
var state = $.data(container, 'tabs');
var opts = state.options;
var cc = $(container);
opts.fit ? $.extend(opts, cc._fit()) : cc._fit(false);
cc.width(opts.width).height(opts.height);
var header = $(container).children('div.tabs-header');
var panels = $(container).children('div.tabs-panels');
var wrap = header.find('div.tabs-wrap');
var ul = wrap.find('.tabs');
for(var i=0; i<state.tabs.length; i++){
var p_opts = state.tabs[i].panel('options');
var p_t = p_opts.tab.find('a.tabs-inner');
var width = parseInt(p_opts.tabWidth || opts.tabWidth) || undefined;
if (width){
p_t._outerWidth(width);
} else {
p_t.css('width', '');
}
p_t._outerHeight(opts.tabHeight);
p_t.css('lineHeight', p_t.height()+'px');
}
if (opts.tabPosition == 'left' || opts.tabPosition == 'right'){
header._outerWidth(opts.showHeader ? opts.headerWidth : 0);
// header._outerWidth(opts.headerWidth);
panels._outerWidth(cc.width() - header.outerWidth());
header.add(panels)._outerHeight(opts.height);
wrap._outerWidth(header.width());
ul._outerWidth(wrap.width()).css('height','');
} else {
var lrt = header.children('div.tabs-scroller-left,div.tabs-scroller-right,div.tabs-tool');
header._outerWidth(opts.width).css('height','');
if (opts.showHeader){
header.css('background-color','');
wrap.css('height','');
lrt.show();
} else {
header.css('background-color','transparent');
header._outerHeight(0);
wrap._outerHeight(0);
lrt.hide();
}
ul._outerHeight(opts.tabHeight).css('width','');
setScrollers(container);
var height = opts.height;
if (!isNaN(height)) {
panels._outerHeight(height - header.outerHeight());
} else {
panels.height('auto');
}
var width = opts.width;
if (!isNaN(width)){
panels._outerWidth(width);
} else {
panels.width('auto');
}
}
}
/**
* set selected tab panel size
*/
function setSelectedSize(container){
var opts = $.data(container, 'tabs').options;
var tab = getSelectedTab(container);
if (tab){
var panels = $(container).children('div.tabs-panels');
var width = opts.width=='auto' ? 'auto' : panels.width();
var height = opts.height=='auto' ? 'auto' : panels.height();
tab.panel('resize', {
width: width,
height: height
});
}
}
/**
* wrap the tabs header and body
*/
function wrapTabs(container) {
var tabs = $.data(container, 'tabs').tabs;
var cc = $(container);
cc.addClass('tabs-container');
var pp = $('<div class="tabs-panels"></div>').insertBefore(cc);
cc.children('div').each(function(){
pp[0].appendChild(this);
});
cc[0].appendChild(pp[0]);
// cc.wrapInner('<div class="tabs-panels"/>');
$('<div class="tabs-header">'
+ '<div class="tabs-scroller-left"></div>'
+ '<div class="tabs-scroller-right"></div>'
+ '<div class="tabs-wrap">'
+ '<ul class="tabs"></ul>'
+ '</div>'
+ '</div>').prependTo(container);
cc.children('div.tabs-panels').children('div').each(function(i){
var opts = $.extend({}, $.parser.parseOptions(this), {
selected: ($(this).attr('selected') ? true : undefined)
});
var pp = $(this);
tabs.push(pp);
createTab(container, pp, opts);
});
cc.children('div.tabs-header').find('.tabs-scroller-left, .tabs-scroller-right').hover(
function(){$(this).addClass('tabs-scroller-over');},
function(){$(this).removeClass('tabs-scroller-over');}
);
cc.bind('_resize', function(e,force){
var opts = $.data(container, 'tabs').options;
if (opts.fit == true || force){
setSize(container);
setSelectedSize(container);
}
return false;
});
}
function bindEvents(container){
var state = $.data(container, 'tabs')
var opts = state.options;
$(container).children('div.tabs-header').unbind().bind('click', function(e){
if ($(e.target).hasClass('tabs-scroller-left')){
$(container).tabs('scrollBy', -opts.scrollIncrement);
} else if ($(e.target).hasClass('tabs-scroller-right')){
$(container).tabs('scrollBy', opts.scrollIncrement);
} else {
var li = $(e.target).closest('li');
if (li.hasClass('tabs-disabled')){return;}
var a = $(e.target).closest('a.tabs-close');
if (a.length){
closeTab(container, getLiIndex(li));
} else if (li.length){
// selectTab(container, getLiIndex(li));
var index = getLiIndex(li);
var popts = state.tabs[index].panel('options');
if (popts.collapsible){
popts.closed ? selectTab(container, index) : unselectTab(container, index);
} else {
selectTab(container, index);
}
}
}
}).bind('contextmenu', function(e){
var li = $(e.target).closest('li');
if (li.hasClass('tabs-disabled')){return;}
if (li.length){
opts.onContextMenu.call(container, e, li.find('span.tabs-title').html(), getLiIndex(li));
}
});
function getLiIndex(li){
var index = 0;
li.parent().children('li').each(function(i){
if (li[0] == this){
index = i;
return false;
}
});
return index;
}
}
function setProperties(container){
var opts = $.data(container, 'tabs').options;
var header = $(container).children('div.tabs-header');
var panels = $(container).children('div.tabs-panels');
header.removeClass('tabs-header-top tabs-header-bottom tabs-header-left tabs-header-right');
panels.removeClass('tabs-panels-top tabs-panels-bottom tabs-panels-left tabs-panels-right');
if (opts.tabPosition == 'top'){
header.insertBefore(panels);
} else if (opts.tabPosition == 'bottom'){
header.insertAfter(panels);
header.addClass('tabs-header-bottom');
panels.addClass('tabs-panels-top');
} else if (opts.tabPosition == 'left'){
header.addClass('tabs-header-left');
panels.addClass('tabs-panels-right');
} else if (opts.tabPosition == 'right'){
header.addClass('tabs-header-right');
panels.addClass('tabs-panels-left');
}
if (opts.plain == true) {
header.addClass('tabs-header-plain');
} else {
header.removeClass('tabs-header-plain');
}
if (opts.border == true){
header.removeClass('tabs-header-noborder');
panels.removeClass('tabs-panels-noborder');
} else {
header.addClass('tabs-header-noborder');
panels.addClass('tabs-panels-noborder');
}
}
function createTab(container, pp, options) {
var state = $.data(container, 'tabs');
options = options || {};
// create panel
pp.panel($.extend({}, options, {
border: false,
noheader: true,
closed: true,
doSize: false,
iconCls: (options.icon ? options.icon : undefined),
onLoad: function(){
if (options.onLoad){
options.onLoad.call(this, arguments);
}
state.options.onLoad.call(container, $(this));
}
}));
var opts = pp.panel('options');
var tabs = $(container).children('div.tabs-header').find('ul.tabs');
opts.tab = $('<li></li>').appendTo(tabs); // set the tab object in panel options
opts.tab.append(
'<a href="javascript:void(0)" class="tabs-inner">' +
'<span class="tabs-title"></span>' +
'<span class="tabs-icon"></span>' +
'</a>'
);
$(container).tabs('update', {
tab: pp,
options: opts
});
}
function addTab(container, options) {
var opts = $.data(container, 'tabs').options;
var tabs = $.data(container, 'tabs').tabs;
if (options.selected == undefined) options.selected = true;
var pp = $('<div></div>').appendTo($(container).children('div.tabs-panels'));
tabs.push(pp);
createTab(container, pp, options);
opts.onAdd.call(container, options.title, tabs.length-1);
// setScrollers(container);
setSize(container);
if (options.selected){
selectTab(container, tabs.length-1); // select the added tab panel
}
}
/**
* update tab panel, param has following properties:
* tab: the tab panel to be updated
* options: the tab panel options
*/
function updateTab(container, param){
var selectHis = $.data(container, 'tabs').selectHis;
var pp = param.tab; // the tab panel
var oldTitle = pp.panel('options').title;
pp.panel($.extend({}, param.options, {
iconCls: (param.options.icon ? param.options.icon : undefined)
}));
var opts = pp.panel('options'); // get the tab panel options
var tab = opts.tab;
var s_title = tab.find('span.tabs-title');
var s_icon = tab.find('span.tabs-icon');
s_title.html(opts.title);
s_icon.attr('class', 'tabs-icon');
tab.find('a.tabs-close').remove();
if (opts.closable){
s_title.addClass('tabs-closable');
$('<a href="javascript:void(0)" class="tabs-close"></a>').appendTo(tab);
} else{
s_title.removeClass('tabs-closable');
}
if (opts.iconCls){
s_title.addClass('tabs-with-icon');
s_icon.addClass(opts.iconCls);
} else {
s_title.removeClass('tabs-with-icon');
}
if (oldTitle != opts.title){
for(var i=0; i<selectHis.length; i++){
if (selectHis[i] == oldTitle){
selectHis[i] = opts.title;
}
}
}
tab.find('span.tabs-p-tool').remove();
if (opts.tools){
var p_tool = $('<span class="tabs-p-tool"></span>').insertAfter(tab.find('a.tabs-inner'));
if ($.isArray(opts.tools)){
for(var i=0; i<opts.tools.length; i++){
var t = $('<a href="javascript:void(0)"></a>').appendTo(p_tool);
t.addClass(opts.tools[i].iconCls);
if (opts.tools[i].handler){
t.bind('click', {handler:opts.tools[i].handler}, function(e){
if ($(this).parents('li').hasClass('tabs-disabled')){return;}
e.data.handler.call(this);
});
}
}
} else {
$(opts.tools).children().appendTo(p_tool);
}
var pr = p_tool.children().length * 12;
if (opts.closable) {
pr += 8;
} else {
pr -= 3;
p_tool.css('right','5px');
}
s_title.css('padding-right', pr+'px');
}
// setProperties(container);
// setScrollers(container);
setSize(container);
$.data(container, 'tabs').options.onUpdate.call(container, opts.title, getTabIndex(container, pp));
}
/**
* close a tab with specified index or title
*/
function closeTab(container, which) {
var opts = $.data(container, 'tabs').options;
var tabs = $.data(container, 'tabs').tabs;
var selectHis = $.data(container, 'tabs').selectHis;
if (!exists(container, which)) return;
var tab = getTab(container, which);
var title = tab.panel('options').title;
var index = getTabIndex(container, tab);
if (opts.onBeforeClose.call(container, title, index) == false) return;
var tab = getTab(container, which, true);
tab.panel('options').tab.remove();
tab.panel('destroy');
opts.onClose.call(container, title, index);
// setScrollers(container);
setSize(container);
// remove the select history item
for(var i=0; i<selectHis.length; i++){
if (selectHis[i] == title){
selectHis.splice(i, 1);
i --;
}
}
// select the nearest tab panel
var hisTitle = selectHis.pop();
if (hisTitle){
selectTab(container, hisTitle);
} else if (tabs.length){
selectTab(container, 0);
}
}
/**
* get the specified tab panel
*/
function getTab(container, which, removeit){
var tabs = $.data(container, 'tabs').tabs;
if (typeof which == 'number'){
if (which < 0 || which >= tabs.length){
return null;
} else {
var tab = tabs[which];
if (removeit) {
tabs.splice(which, 1);
}
return tab;
}
}
for(var i=0; i<tabs.length; i++){
var tab = tabs[i];
if (tab.panel('options').title == which){
if (removeit){
tabs.splice(i, 1);
}
return tab;
}
}
return null;
}
function getTabIndex(container, tab){
var tabs = $.data(container, 'tabs').tabs;
for(var i=0; i<tabs.length; i++){
if (tabs[i][0] == $(tab)[0]){
return i;
}
}
return -1;
}
function getSelectedTab(container){
var tabs = $.data(container, 'tabs').tabs;
for(var i=0; i<tabs.length; i++){
var tab = tabs[i];
if (tab.panel('options').closed == false){
return tab;
}
}
return null;
}
/**
* do first select action, if no tab is setted the first tab will be selected.
*/
function doFirstSelect(container){
var state = $.data(container, 'tabs')
var tabs = state.tabs;
for(var i=0; i<tabs.length; i++){
if (tabs[i].panel('options').selected){
selectTab(container, i);
return;
}
}
// if (tabs.length){
// selectTab(container, 0);
// }
selectTab(container, state.options.selected);
}
function selectTab(container, which){
var state = $.data(container, 'tabs');
var opts = state.options;
var tabs = state.tabs;
var selectHis = state.selectHis;
if (tabs.length == 0) {return;}
var panel = getTab(container, which); // get the panel to be activated
if (!panel){return}
var selected = getSelectedTab(container);
if (selected){
if (panel[0] == selected[0]){return}
unselectTab(container, getTabIndex(container, selected));
if (!selected.panel('options').closed){return}
}
panel.panel('open');
var title = panel.panel('options').title; // the panel title
selectHis.push(title); // push select history
var tab = panel.panel('options').tab; // get the tab object
tab.addClass('tabs-selected');
// scroll the tab to center position if required.
var wrap = $(container).find('>div.tabs-header>div.tabs-wrap');
var left = tab.position().left;
var right = left + tab.outerWidth();
if (left < 0 || right > wrap.width()){
var deltaX = left - (wrap.width()-tab.width()) / 2;
$(container).tabs('scrollBy', deltaX);
} else {
$(container).tabs('scrollBy', 0);
}
setSelectedSize(container);
opts.onSelect.call(container, title, getTabIndex(container, panel));
}
function unselectTab(container, which){
var state = $.data(container, 'tabs');
var p = getTab(container, which);
if (p){
var opts = p.panel('options');
if (!opts.closed){
p.panel('close');
if (opts.closed){
opts.tab.removeClass('tabs-selected');
state.options.onUnselect.call(container, opts.title, getTabIndex(container, p));
}
}
}
}
function exists(container, which){
return getTab(container, which) != null;
}
function showHeader(container, visible){
var opts = $.data(container, 'tabs').options;
opts.showHeader = visible;
$(container).tabs('resize');
}
$.fn.tabs = function(options, param){
if (typeof options == 'string') {
return $.fn.tabs.methods[options](this, param);
}
options = options || {};
return this.each(function(){
var state = $.data(this, 'tabs');
var opts;
if (state) {
opts = $.extend(state.options, options);
state.options = opts;
} else {
$.data(this, 'tabs', {
options: $.extend({},$.fn.tabs.defaults, $.fn.tabs.parseOptions(this), options),
tabs: [],
selectHis: []
});
wrapTabs(this);
}
addTools(this);
setProperties(this);
setSize(this);
bindEvents(this);
doFirstSelect(this);
});
};
$.fn.tabs.methods = {
options: function(jq){
var cc = jq[0];
var opts = $.data(cc, 'tabs').options;
var s = getSelectedTab(cc);
opts.selected = s ? getTabIndex(cc, s) : -1;
return opts;
},
tabs: function(jq){
return $.data(jq[0], 'tabs').tabs;
},
resize: function(jq){
return jq.each(function(){
setSize(this);
setSelectedSize(this);
});
},
add: function(jq, options){
return jq.each(function(){
addTab(this, options);
});
},
close: function(jq, which){
return jq.each(function(){
closeTab(this, which);
});
},
getTab: function(jq, which){
return getTab(jq[0], which);
},
getTabIndex: function(jq, tab){
return getTabIndex(jq[0], tab);
},
getSelected: function(jq){
return getSelectedTab(jq[0]);
},
select: function(jq, which){
return jq.each(function(){
selectTab(this, which);
});
},
unselect: function(jq, which){
return jq.each(function(){
unselectTab(this, which);
});
},
exists: function(jq, which){
return exists(jq[0], which);
},
update: function(jq, options){
return jq.each(function(){
updateTab(this, options);
});
},
enableTab: function(jq, which){
return jq.each(function(){
$(this).tabs('getTab', which).panel('options').tab.removeClass('tabs-disabled');
});
},
disableTab: function(jq, which){
return jq.each(function(){
$(this).tabs('getTab', which).panel('options').tab.addClass('tabs-disabled');
});
},
showHeader: function(jq){
return jq.each(function(){
showHeader(this, true);
});
},
hideHeader: function(jq){
return jq.each(function(){
showHeader(this, false);
});
},
scrollBy: function(jq, deltaX){ // scroll the tab header by the specified amount of pixels
return jq.each(function(){
var opts = $(this).tabs('options');
var wrap = $(this).find('>div.tabs-header>div.tabs-wrap');
var pos = Math.min(wrap._scrollLeft() + deltaX, getMaxScrollWidth());
wrap.animate({scrollLeft: pos}, opts.scrollDuration);
function getMaxScrollWidth(){
var w = 0;
var ul = wrap.children('ul');
ul.children('li').each(function(){
w += $(this).outerWidth(true);
});
return w - wrap.width() + (ul.outerWidth() - ul.width());
}
});
}
};
$.fn.tabs.parseOptions = function(target){
return $.extend({}, $.parser.parseOptions(target, [
'width','height','tools','toolPosition','tabPosition',
{fit:'boolean',border:'boolean',plain:'boolean',headerWidth:'number',tabWidth:'number',tabHeight:'number',selected:'number',showHeader:'boolean'}
]));
};
$.fn.tabs.defaults = {
width: 'auto',
height: 'auto',
headerWidth: 150, // the tab header width, it is valid only when tabPosition set to 'left' or 'right'
tabWidth: 'auto', // the tab width
tabHeight: 27, // the tab height
selected: 0, // the initialized selected tab index
showHeader: true,
plain: false,
fit: false,
border: true,
tools: null,
toolPosition: 'right', // left,right
tabPosition: 'top', // possible values: top,bottom
scrollIncrement: 100,
scrollDuration: 400,
onLoad: function(panel){},
onSelect: function(title, index){},
onUnselect: function(title, index){},
onBeforeClose: function(title, index){},
onClose: function(title, index){},
onAdd: function(title, index){},
onUpdate: function(title, index){},
onContextMenu: function(e, title, index){}
};
})(jQuery);

View File

@@ -0,0 +1,409 @@
/**
* window - jQuery EasyUI
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: info@jeasyui.com
* http://www.gnu.org/licenses/gpl.txt
* http://www.jeasyui.com/license_commercial.php
*
* Dependencies:
* panel
* draggable
* resizable
*
*/
(function($){
function setSize(target, param){
var opts = $.data(target, 'window').options;
if (param){
$.extend(opts, param);
// if (param.width) opts.width = param.width;
// if (param.height) opts.height = param.height;
// if (param.left != null) opts.left = param.left;
// if (param.top != null) opts.top = param.top;
}
$(target).panel('resize', opts);
}
function moveWindow(target, param){
var state = $.data(target, 'window');
if (param){
if (param.left != null) state.options.left = param.left;
if (param.top != null) state.options.top = param.top;
}
$(target).panel('move', state.options);
if (state.shadow){
state.shadow.css({
left: state.options.left,
top: state.options.top
});
}
}
/**
* center the window only horizontally
*/
function hcenter(target, tomove){
var state = $.data(target, 'window');
var opts = state.options;
var width = opts.width;
if (isNaN(width)){
width = state.window._outerWidth();
}
if (opts.inline){
var parent = state.window.parent();
opts.left = (parent.width() - width) / 2 + parent.scrollLeft();
} else {
opts.left = ($(window)._outerWidth() - width) / 2 + $(document).scrollLeft();
}
if (tomove){moveWindow(target);}
}
/**
* center the window only vertically
*/
function vcenter(target, tomove){
var state = $.data(target, 'window');
var opts = state.options;
var height = opts.height;
if (isNaN(height)){
height = state.window._outerHeight();
}
if (opts.inline){
var parent = state.window.parent();
opts.top = (parent.height() - height) / 2 + parent.scrollTop();
} else {
opts.top = ($(window)._outerHeight() - height) / 2 + $(document).scrollTop();
}
if (tomove){moveWindow(target);}
}
function create(target){
var state = $.data(target, 'window');
var win = $(target).panel($.extend({}, state.options, {
border: false,
doSize: true, // size the panel, the property undefined in window component
closed: true, // close the panel
cls: 'window',
headerCls: 'window-header',
bodyCls: 'window-body ' + (state.options.noheader ? 'window-body-noheader' : ''),
onBeforeDestroy: function(){
if (state.options.onBeforeDestroy.call(target) == false) return false;
if (state.shadow) state.shadow.remove();
if (state.mask) state.mask.remove();
},
onClose: function(){
if (state.shadow) state.shadow.hide();
if (state.mask) state.mask.hide();
state.options.onClose.call(target);
},
onOpen: function(){
if (state.mask){
state.mask.css({
display:'block',
zIndex: $.fn.window.defaults.zIndex++
});
}
if (state.shadow){
state.shadow.css({
display:'block',
zIndex: $.fn.window.defaults.zIndex++,
left: state.options.left,
top: state.options.top,
width: state.window._outerWidth(),
height: state.window._outerHeight()
});
}
state.window.css('z-index', $.fn.window.defaults.zIndex++);
state.options.onOpen.call(target);
},
onResize: function(width, height){
var opts = $(this).panel('options');
$.extend(state.options, {
width: opts.width,
height: opts.height,
left: opts.left,
top: opts.top
});
if (state.shadow){
state.shadow.css({
left: state.options.left,
top: state.options.top,
width: state.window._outerWidth(),
height: state.window._outerHeight()
});
}
state.options.onResize.call(target, width, height);
},
onMinimize: function(){
if (state.shadow) state.shadow.hide();
if (state.mask) state.mask.hide();
state.options.onMinimize.call(target);
},
onBeforeCollapse: function(){
if (state.options.onBeforeCollapse.call(target) == false) return false;
if (state.shadow) state.shadow.hide();
},
onExpand: function(){
if (state.shadow) state.shadow.show();
state.options.onExpand.call(target);
}
}));
state.window = win.panel('panel');
// create mask
if (state.mask) state.mask.remove();
if (state.options.modal == true){
state.mask = $('<div class="window-mask"></div>').insertAfter(state.window);
state.mask.css({
width: (state.options.inline ? state.mask.parent().width() : getPageArea().width),
height: (state.options.inline ? state.mask.parent().height() : getPageArea().height),
display: 'none'
});
}
// create shadow
if (state.shadow) state.shadow.remove();
if (state.options.shadow == true){
state.shadow = $('<div class="window-shadow"></div>').insertAfter(state.window);
state.shadow.css({
display: 'none'
});
}
// if require center the window
if (state.options.left == null){hcenter(target);}
if (state.options.top == null){vcenter(target);}
moveWindow(target);
if (state.options.closed == false){
win.window('open'); // open the window
}
}
/**
* set window drag and resize property
*/
function setProperties(target){
var state = $.data(target, 'window');
state.window.draggable({
handle: '>div.panel-header>div.panel-title',
disabled: state.options.draggable == false,
onStartDrag: function(e){
if (state.mask) state.mask.css('z-index', $.fn.window.defaults.zIndex++);
if (state.shadow) state.shadow.css('z-index', $.fn.window.defaults.zIndex++);
state.window.css('z-index', $.fn.window.defaults.zIndex++);
if (!state.proxy){
state.proxy = $('<div class="window-proxy"></div>').insertAfter(state.window);
}
state.proxy.css({
display:'none',
zIndex: $.fn.window.defaults.zIndex++,
left: e.data.left,
top: e.data.top
});
state.proxy._outerWidth(state.window._outerWidth());
state.proxy._outerHeight(state.window._outerHeight());
setTimeout(function(){
if (state.proxy) state.proxy.show();
}, 500);
},
onDrag: function(e){
state.proxy.css({
display:'block',
left: e.data.left,
top: e.data.top
});
return false;
},
onStopDrag: function(e){
state.options.left = e.data.left;
state.options.top = e.data.top;
$(target).window('move');
state.proxy.remove();
state.proxy = null;
}
});
state.window.resizable({
disabled: state.options.resizable == false,
onStartResize:function(e){
state.pmask = $('<div class="window-proxy-mask"></div>').insertAfter(state.window);
state.pmask.css({
zIndex: $.fn.window.defaults.zIndex++,
left: e.data.left,
top: e.data.top,
width: state.window._outerWidth(),
height: state.window._outerHeight()
});
if (!state.proxy){
state.proxy = $('<div class="window-proxy"></div>').insertAfter(state.window);
}
state.proxy.css({
zIndex: $.fn.window.defaults.zIndex++,
left: e.data.left,
top: e.data.top
});
state.proxy._outerWidth(e.data.width);
state.proxy._outerHeight(e.data.height);
},
onResize: function(e){
state.proxy.css({
left: e.data.left,
top: e.data.top
});
state.proxy._outerWidth(e.data.width);
state.proxy._outerHeight(e.data.height);
return false;
},
onStopResize: function(e){
$.extend(state.options, {
left: e.data.left,
top: e.data.top,
width: e.data.width,
height: e.data.height
});
setSize(target);
state.pmask.remove();
state.pmask = null;
state.proxy.remove();
state.proxy = null;
}
});
}
function getPageArea() {
if (document.compatMode == 'BackCompat') {
return {
width: Math.max(document.body.scrollWidth, document.body.clientWidth),
height: Math.max(document.body.scrollHeight, document.body.clientHeight)
}
} else {
return {
width: Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth),
height: Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight)
}
}
}
// when window resize, reset the width and height of the window's mask
$(window).resize(function(){
$('body>div.window-mask').css({
width: $(window)._outerWidth(),
height: $(window)._outerHeight()
});
setTimeout(function(){
$('body>div.window-mask').css({
width: getPageArea().width,
height: getPageArea().height
});
}, 50);
});
$.fn.window = function(options, param){
if (typeof options == 'string'){
var method = $.fn.window.methods[options];
if (method){
return method(this, param);
} else {
return this.panel(options, param);
}
}
options = options || {};
return this.each(function(){
var state = $.data(this, 'window');
if (state){
$.extend(state.options, options);
} else {
state = $.data(this, 'window', {
options: $.extend({}, $.fn.window.defaults, $.fn.window.parseOptions(this), options)
});
if (!state.options.inline){
// $(this).appendTo('body');
document.body.appendChild(this);
}
}
create(this);
setProperties(this);
});
};
$.fn.window.methods = {
options: function(jq){
var popts = jq.panel('options');
var wopts = $.data(jq[0], 'window').options;
return $.extend(wopts, {
closed: popts.closed,
collapsed: popts.collapsed,
minimized: popts.minimized,
maximized: popts.maximized
});
},
window: function(jq){
return $.data(jq[0], 'window').window;
},
resize: function(jq, param){
return jq.each(function(){
setSize(this, param);
});
},
move: function(jq, param){
return jq.each(function(){
moveWindow(this, param);
});
},
hcenter: function(jq){
return jq.each(function(){
hcenter(this, true);
});
},
vcenter: function(jq){
return jq.each(function(){
vcenter(this, true);
});
},
center: function(jq){
return jq.each(function(){
hcenter(this);
vcenter(this);
moveWindow(this);
});
}
};
$.fn.window.parseOptions = function(target){
return $.extend({}, $.fn.panel.parseOptions(target), $.parser.parseOptions(target, [
{draggable:'boolean',resizable:'boolean',shadow:'boolean',modal:'boolean',inline:'boolean'}
]));
};
// Inherited from $.fn.panel.defaults
$.fn.window.defaults = $.extend({}, $.fn.panel.defaults, {
zIndex: 9000,
draggable: true,
resizable: true,
shadow: true,
modal: false,
inline: false, // true to stay inside its parent, false to go on top of all elements
// window's property which difference from panel
title: 'New Window',
collapsible: true,
minimizable: true,
maximizable: true,
closable: true,
closed: false
});
})(jQuery);