/** * jQuery ligerUI 1.3.2 * * http://ligerui.com * * Author daomi 2015 [ gd_star@163.com ] * */ (function ($) { //ligerui 继承方法 Function.prototype.ligerExtend = function (parent, overrides) { if (typeof parent != 'function') return this; //保存对父类的引用 this.base = parent.prototype; this.base.constructor = parent; //继承 var f = function () { }; f.prototype = parent.prototype; this.prototype = new f(); this.prototype.constructor = this; //附加属性方法 if (overrides) $.extend(this.prototype, overrides); }; //延时加载 Function.prototype.ligerDefer = function (o, defer, args) { var fn = this; return setTimeout(function () { fn.apply(o, args || []); }, defer); }; // 核心对象 window.liger = $.ligerui = { version: 'V1.3.2', managerCount: 0, //组件管理器池 managers: {}, managerIdPrev: 'ligerui', //管理器id已经存在时自动创建新的 autoNewId: true, //错误提示 error: { managerIsExist: '管理器id已经存在' }, pluginPrev: 'liger', attrPrev:'data', getId: function (prev) { prev = prev || this.managerIdPrev; var id = prev + (1000 + this.managerCount); this.managerCount++; return id; }, add: function (manager) { if (arguments.length == 2) { var m = arguments[1]; m.id = m.id || m.options.id || arguments[0].id; this.addManager(m); return; } if (!manager.id) manager.id = this.getId(manager.__idPrev()); //if (this.managers[manager.id]) manager.id = this.getId(manager.__idPrev()); //if (this.managers[manager.id]) //{ // throw new Error(this.error.managerIsExist); //} this.managers[manager.id] = manager; }, remove: function (arg) { if (typeof arg == "string" || typeof arg == "number") { delete liger.managers[arg]; } else if (typeof arg == "object") { if (arg instanceof liger.core.Component) { delete liger.managers[arg.id]; } else { if (!$(arg).attr(this.idAttrName)) return false; delete liger.managers[$(arg).attr(this.idAttrName)]; } } }, //获取ligerui对象 //1,传入ligerui ID //2,传入Dom Object get: function (arg, idAttrName) { idAttrName = idAttrName || "ligeruiid"; if (typeof arg == "string" || typeof arg == "number") { return liger.managers[arg]; } else if (typeof arg == "object") { var domObj = arg.length ? arg[0] : arg; var id = domObj[idAttrName] || $(domObj).attr(idAttrName); if (!id) return null; return liger.managers[id]; } return null; }, //根据类型查找某一个对象 find: function (type) { var arr = []; for (var id in this.managers) { var manager = this.managers[id]; if (type instanceof Function) { if (manager instanceof type) { arr.push(manager); } } else if (type instanceof Array) { if ($.inArray(manager.__getType(), type) != -1) { arr.push(manager); } } else { if (manager.__getType() == type) { arr.push(manager); } } } return arr; }, //$.fn.liger{Plugin} 和 $.fn.ligerGet{Plugin}Manager //会调用这个方法,并传入作用域(this) //parm [plugin] 插件名 //parm [args] 参数(数组) //parm [ext] 扩展参数,定义命名空间或者id属性名 run: function (plugin, args, ext) { if (!plugin) return; ext = $.extend({ defaultsNamespace: 'ligerDefaults', methodsNamespace: 'ligerMethods', controlNamespace: 'controls', idAttrName: 'ligeruiid', isStatic: false, hasElement: true, //是否拥有element主体(比如drag、resizable等辅助性插件就不拥有) propertyToElemnt: null //链接到element的属性名 }, ext || {}); plugin = plugin.replace(/^ligerGet/, ''); plugin = plugin.replace(/^liger/, ''); if (this == null || this == window || ext.isStatic) { if (!liger.plugins[plugin]) { liger.plugins[plugin] = { fn: $[liger.pluginPrev + plugin], isStatic: true }; } return new $.ligerui[ext.controlNamespace][plugin]($.extend({}, $[ext.defaultsNamespace][plugin] || {}, $[ext.defaultsNamespace][plugin + 'String'] || {}, args.length > 0 ? args[0] : {})); } if (!liger.plugins[plugin]) { liger.plugins[plugin] = { fn: $.fn[liger.pluginPrev + plugin], isStatic: false }; } if (/Manager$/.test(plugin)) return liger.get(this, ext.idAttrName); this.each(function () { if (this[ext.idAttrName] || $(this).attr(ext.idAttrName)) { var manager = liger.get(this[ext.idAttrName] || $(this).attr(ext.idAttrName)); if (manager && args.length > 0) manager.set(args[0]); //已经执行过 return; } if (args.length >= 1 && typeof args[0] == 'string') return; //只要第一个参数不是string类型,都执行组件的实例化工作 var options = args.length > 0 ? args[0] : null; var p = $.extend({}, $[ext.defaultsNamespace][plugin], $[ext.defaultsNamespace][plugin + 'String'], options); if (ext.propertyToElemnt) p[ext.propertyToElemnt] = this; if (ext.hasElement) { new $.ligerui[ext.controlNamespace][plugin](this, p); } else { new $.ligerui[ext.controlNamespace][plugin](p); } }); if (this.length == 0) return null; if (args.length == 0) return liger.get(this, ext.idAttrName); if (typeof args[0] == 'object') return liger.get(this, ext.idAttrName); if (typeof args[0] == 'string') { var manager = liger.get(this, ext.idAttrName); if (manager == null) return; if (args[0] == "option") { if (args.length == 2) return manager.get(args[1]); //manager get else if (args.length >= 3) return manager.set(args[1], args[2]); //manager set } else { var method = args[0]; if (!manager[method]) return; //不存在这个方法 var parms = Array.apply(null, args); parms.shift(); return manager[method].apply(manager, parms); //manager method } } return null; }, //扩展 //1,默认参数 //2,本地化扩展 defaults: {}, //3,方法接口扩展 methods: {}, //命名空间 //核心控件,封装了一些常用方法 core: {}, //命名空间 //组件的集合 controls: {}, //plugin 插件的集合 plugins: {} }; //扩展对象 $.ligerDefaults = {}; //扩展对象 $.ligerMethos = {}; //关联起来 liger.defaults = $.ligerDefaults; liger.methods = $.ligerMethos; //获取ligerui对象 //parm [plugin] 插件名,可为空 $.fn.liger = function (plugin) { if (plugin) { return liger.run.call(this, plugin, arguments); } else { return liger.get(this); } }; //组件基类 //1,完成定义参数处理方法和参数属性初始化的工作 //2,完成定义事件处理方法和事件属性初始化的工作 liger.core.Component = function (options) { //事件容器 this.events = this.events || {}; //配置参数 this.options = options || {}; //子组件集合索引 this.children = {}; }; $.extend(liger.core.Component.prototype, { __getType: function () { return 'liger.core.Component'; }, __idPrev: function () { return 'ligerui'; }, //设置属性 // arg 属性名 value 属性值 // arg 属性/值 value 是否只设置事件 set: function (arg, value,value2) { if (!arg) return; if (typeof arg == 'object') { var tmp; if (this.options != arg) { $.extend(this.options, arg); tmp = arg; } else { tmp = $.extend({}, arg); } if (value == undefined || value == true) { for (var p in tmp) { if (p.indexOf('on') == 0) this.set(p, tmp[p]); } } if (value == undefined || value == false) { for (var p in tmp) { if (p.indexOf('on') != 0) this.set(p, tmp[p], value2); } } return; } var name = arg; //事件参数 if (name.indexOf('on') == 0) { if (typeof value == 'function') this.bind(name.substr(2), value); return; } if (!this.options) this.options = {}; if (this.trigger('propertychange', [arg, value]) == false) return; this.options[name] = value; var pn = '_set' + name.substr(0, 1).toUpperCase() + name.substr(1); if (this[pn]) { this[pn].call(this, value, value2); } this.trigger('propertychanged', [arg, value]); }, //获取属性 get: function (name) { var pn = '_get' + name.substr(0, 1).toUpperCase() + name.substr(1); if (this[pn]) { return this[pn].call(this, name); } return this.options[name]; }, hasBind: function (arg) { var name = arg.toLowerCase(); var event = this.events[name]; if (event && event.length) return true; return false; }, //触发事件 //data (可选) Array(可选)传递给事件处理函数的附加参数 trigger: function (arg, data) { if (!arg) return; var name = arg.toLowerCase(); var event = this.events[name]; if (!event) return; data = data || []; if ((data instanceof Array) == false) { data = [data]; } for (var i = 0; i < event.length; i++) { var ev = event[i]; if (ev.handler.apply(ev.context, data) == false) return false; } }, //绑定事件 bind: function (arg, handler, context) { if (typeof arg == 'object') { for (var p in arg) { this.bind(p, arg[p]); } return; } if (typeof handler != 'function') return false; var name = arg.toLowerCase(); var event = this.events[name] || []; context = context || this; event.push({ handler: handler, context: context }); this.events[name] = event; }, //取消绑定 unbind: function (arg, handler) { if (!arg) { this.events = {}; return; } var name = arg.toLowerCase(); var event = this.events[name]; if (!event || !event.length) return; if (!handler) { delete this.events[name]; } else { for (var i = 0, l = event.length; i < l; i++) { if (event[i].handler == handler) { event.splice(i, 1); break; } } } }, destroy: function () { liger.remove(this); } }); //界面组件基类, //1,完成界面初始化:设置组件id并存入组件管理器池,初始化参数 //2,渲染的工作,细节交给子类实现 //parm [element] 组件对应的dom element对象 //parm [options] 组件的参数 liger.core.UIComponent = function (element, options) { liger.core.UIComponent.base.constructor.call(this, options); var extendMethods = this._extendMethods(); if (extendMethods) $.extend(this, extendMethods); this.element = element; this._init(); this._preRender(); this.trigger('render'); this._render(); this.trigger('rendered'); this._rendered(); }; liger.core.UIComponent.ligerExtend(liger.core.Component, { __getType: function () { return 'liger.core.UIComponent'; }, //扩展方法 _extendMethods: function () { }, _init: function () { this.type = this.__getType(); if (!this.element) { this.id = this.options.id || liger.getId(this.__idPrev()); } else { this.id = this.options.id || this.element.id || liger.getId(this.__idPrev()); } //存入管理器池 liger.add(this); if (!this.element) return; //读取attr方法,并加载到参数,比如['url'] var attributes = this.attr(); if (attributes && attributes instanceof Array) { for (var i = 0; i < attributes.length; i++) { var name = attributes[i]; if ($(this.element).attr(name)) { this.options[name] = $(this.element).attr(name); } } } //读取ligerui这个属性,并加载到参数,比如 ligerui = "width:120,heigth:100" var p = this.options; if ($(this.element).attr("ligerui")) { try { var attroptions = $(this.element).attr("ligerui"); if (attroptions.indexOf('{') != 0) attroptions = "{" + attroptions + "}"; eval("attroptions = " + attroptions + ";"); if (attroptions) $.extend(p, attroptions); } catch (e) { } } //v1.3.2增加 从data-XX 加载属性 function loadDataOp(control, jelement) { var op = {}; if (!control || control.indexOf('.') != -1) return op; var defaultOp = liger.defaults[control]; if (!defaultOp) return op; for (var name in defaultOp) { if (jelement.attr(liger.attrPrev + "-" + name)) { var value = jelement.attr(liger.attrPrev + "-" + name); if (typeof (defaultOp[name]) == "boolean") { op[name] = value == "true" || value == "1"; } else { op[name] = value; } } } return op; } $.extend(p, loadDataOp(this.__getType(), $(this.element))); }, //预渲染,可以用于继承扩展 _preRender: function () { }, _render: function () { }, _rendered: function () { if (this.element) { $(this.element).attr("ligeruiid", this.id); } }, _setCls: function (value) { if (this.element && value) { $(this.element).addClass(value); } }, //返回要转换成ligerui参数的属性,比如['url'] attr: function () { return []; }, destroy: function () { if (this.element) { $(this.element).remove(); } this.options = null; liger.remove(this); } }); //表单控件基类 liger.controls.Input = function (element, options) { liger.controls.Input.base.constructor.call(this, element, options); }; liger.controls.Input.ligerExtend(liger.core.UIComponent, { __getType: function () { return 'liger.controls.Input'; }, attr: function () { return ['nullText']; }, setValue: function (value) { return this.set('value', value); }, getValue: function () { return this.get('value'); }, //设置只读 _setReadonly: function (readonly) { var wrapper = this.wrapper || this.text; if (!wrapper || !wrapper.hasClass("l-text")) return; var inputText = this.inputText; if (readonly) { if (inputText) inputText.attr("readonly", "readonly"); wrapper.addClass("l-text-readonly"); } else { if (inputText) inputText.removeAttr("readonly"); wrapper.removeClass("l-text-readonly"); } }, setReadonly: function (readonly) { return this.set('readonly', readonly); }, setEnabled: function () { return this.set('disabled', false); }, setDisabled: function () { return this.set('disabled', true); }, updateStyle: function () { }, resize: function (width, height) { this.set({ width: width, height: height + 2 }); } }); //全局窗口对象 liger.win = { //顶端显示 top: false, //遮罩 mask: function (win) { function setHeight() { if (!liger.win.windowMask) return; var h = $(window).height() + $(window).scrollTop(); liger.win.windowMask.height(h); } if (!this.windowMask) { this.windowMask = $("
").appendTo('body'); $(window).bind('resize.ligeruiwin', setHeight); $(window).bind('scroll', setHeight); } this.windowMask.show(); setHeight(); this.masking = true; }, //取消遮罩 unmask: function (win) { var jwins = $("body > .l-dialog:visible,body > .l-window:visible"); for (var i = 0, l = jwins.length; i < l; i++) { var winid = jwins.eq(i).attr("ligeruiid"); if (win && win.id == winid) continue; //获取ligerui对象 var winmanager = liger.get(winid); if (!winmanager) continue; //是否模态窗口 var modal = winmanager.get('modal'); //如果存在其他模态窗口,那么不会取消遮罩 if (modal) return; } if (this.windowMask) this.windowMask.hide(); this.masking = false; }, //显示任务栏 createTaskbar: function () { if (!this.taskbar) { this.taskbar = $('
').appendTo('body'); if (this.top) this.taskbar.addClass("l-taskbar-top"); this.taskbar.tasks = $(".l-taskbar-tasks:first", this.taskbar); this.tasks = {}; } this.taskbar.show(); this.taskbar.animate({ bottom: 0 }); return this.taskbar; }, //关闭任务栏 removeTaskbar: function () { var self = this; self.taskbar.animate({ bottom: -32 }, function () { self.taskbar.remove(); self.taskbar = null; }); }, activeTask: function (win) { for (var winid in this.tasks) { var t = this.tasks[winid]; if (winid == win.id) { t.addClass("l-taskbar-task-active"); } else { t.removeClass("l-taskbar-task-active"); } } }, //获取任务 getTask: function (win) { var self = this; if (!self.taskbar) return; if (self.tasks[win.id]) return self.tasks[win.id]; return null; }, //增加任务 addTask: function (win) { var self = this; if (!self.taskbar) self.createTaskbar(); if (self.tasks[win.id]) return self.tasks[win.id]; var title = win.get('title'); var task = self.tasks[win.id] = $('
' + title + '
'); self.taskbar.tasks.append(task); self.activeTask(win); task.bind('click', function () { self.activeTask(win); if (win.actived) win.min(); else win.active(); }).hover(function () { $(this).addClass("l-taskbar-task-over"); }, function () { $(this).removeClass("l-taskbar-task-over"); }); return task; }, hasTask: function () { for (var p in this.tasks) { if (this.tasks[p]) return true; } return false; }, //移除任务 removeTask: function (win) { var self = this; if (!self.taskbar) return; if (self.tasks[win.id]) { self.tasks[win.id].unbind(); self.tasks[win.id].remove(); delete self.tasks[win.id]; } if (!self.hasTask()) { self.removeTaskbar(); } }, //前端显示 setFront: function (win) { var wins = liger.find(liger.core.Win); for (var i in wins) { var w = wins[i]; if (w == win) { $(w.element).css("z-index", "9200"); this.activeTask(w); } else { $(w.element).css("z-index", "9100"); } } } }; //窗口基类 window、dialog liger.core.Win = function (element, options) { liger.core.Win.base.constructor.call(this, element, options); }; liger.core.Win.ligerExtend(liger.core.UIComponent, { __getType: function () { return 'liger.controls.Win'; }, mask: function () { if (this.options.modal) liger.win.mask(this); }, unmask: function () { if (this.options.modal) liger.win.unmask(this); }, min: function () { }, max: function () { }, active: function () { } }); liger.draggable = { dragging: false }; liger.resizable = { reszing: false }; liger.toJSON = typeof JSON === 'object' && JSON.stringify ? JSON.stringify : function (o) { var f = function (n) { return n < 10 ? '0' + n : n; }, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, quote = function (value) { escapable.lastIndex = 0; return escapable.test(value) ? '"' + value.replace(escapable, function (a) { var c = meta[a]; return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); }) + '"' : '"' + value + '"'; }; if (o === null) return 'null'; var type = typeof o; if (type === 'undefined') return undefined; if (type === 'string') return quote(o); if (type === 'number' || type === 'boolean') return '' + o; if (type === 'object') { if (typeof o.toJSON === 'function') { return liger.toJSON(o.toJSON()); } if (o.constructor === Date) { return isFinite(this.valueOf()) ? this.getUTCFullYear() + '-' + f(this.getUTCMonth() + 1) + '-' + f(this.getUTCDate()) + 'T' + f(this.getUTCHours()) + ':' + f(this.getUTCMinutes()) + ':' + f(this.getUTCSeconds()) + 'Z' : null; } var pairs = []; if (o.constructor === Array) { for (var i = 0, l = o.length; i < l; i++) { pairs.push(liger.toJSON(o[i]) || 'null'); } return '[' + pairs.join(',') + ']'; } var name, val; for (var k in o) { type = typeof k; if (type === 'number') { name = '"' + k + '"'; } else if (type === 'string') { name = quote(k); } else { continue; } type = typeof o[k]; if (type === 'function' || type === 'undefined') { continue; } val = liger.toJSON(o[k]); pairs.push(name + ':' + val); } return '{' + pairs.join(',') + '}'; } }; //获取 默认的编辑构造器 liger.getEditor = function (e) { var type = e.type, control = e.control, master = e.master; if (!type) return null; var inputTag = 0; if (control) control = control.substr(0, 1).toUpperCase() + control.substr(1); var defaultOp = { create: function (container, editParm, controlOptions) { //field in form , column in grid var field = editParm.field || editParm.column, options = controlOptions || {}; var isInGrid = editParm.column ? true : false; var p = $.extend({}, e.options); var inputType = "text"; if ($.inArray(type, ["password", "file", "checkbox", "radio"]) != -1) inputType = type; if (e.password) inputType = "password"; var inputBody = $(""); if (e.body) { inputBody = e.body.clone(); } inputBody.appendTo(container); if (editParm.field) { var txtInputName = field.name; var prefixID = $.isFunction(options.prefixID) ? options.prefixID(master) : (options.prefixID || ""); p.id = field.id || (prefixID + field.name); if ($.inArray(type, ["select", "combobox", "autocomplete", "popup"]) != -1) { txtInputName = field.textField || field.comboboxName; if (field.comboboxName && !field.id) p.id = (options.prefixID || "") + field.comboboxName; } if ($.inArray(type, ["select", "combobox", "autocomplete", "popup", "radiolist", "checkboxlist", "listbox"]) != -1) { p.valueFieldID = prefixID + field.name; } if (!e.body) { var inputName = prefixID + txtInputName; var inputId = new Date().getTime() + "_" + ++inputTag + "_" + field.name; inputBody.attr($.extend({ id: inputId, name: inputName }, field.attr)); if (field.cssClass) { inputBody.addClass(field.cssClass); } if (field.validate && !master.options.unSetValidateAttr) { inputBody.attr('validate', liger.toJSON(field.validate)); } } $.extend(p, field.options); } if (field.dictionary) //字典字段,比如:男|女 { field.editor = field.editor || {}; if (!field.editor.data) { var dicEditorData = [], dicItems = field.dictionary.split('|'); $(dicItems).each(function (i, dicItem) { var dics = dicItem.split(','); var dicItemId = dics[0], dicItemText = dics.length >= 2 ? dics[1] : dics[0]; dicEditorData.push({ id: dicItemId, value: dicItemId, text: dicItemText }); }); field.editor.data = dicEditorData; } } if (field.editor) { if (field.editor.options) { $.extend(p, field.editor.options); delete field.editor.options; } if (field.editor.valueColumnName) { p.valueField = field.editor.valueColumnName; delete field.editor.valueColumnName; } if (field.editor.displayColumnName) { p.textField = field.editor.displayColumnName; delete field.editor.displayColumnName; } //可扩展参数,支持动态加载 var ext = field.editor.p || field.editor.ext; if (ext) { ext = typeof (ext) == 'function' ? ext(editParm) : ext; $.extend(p, ext); delete field.editor.p; delete field.editor.ext; } $.extend(p, field.editor); } if (isInGrid) { p.host_grid = this; p.host_grid_row = editParm.record; p.host_grid_column = editParm.column; } else { p.host_form = this; if (field.readonly || p.host_form.get('readonly')) { p.readonly = true; } } //返回的是ligerui对象 var lobj = inputBody['liger' + control](p); if (isInGrid) { setTimeout(function () { inputBody.focus(); }, 100); } return lobj; }, getValue: function (editor, editParm) { var field = editParm.field || editParm.column; if (editor.getValue) { var value = editor.getValue(); var edtirType = editParm.column ? editParm.column.editor.type : editParm.field.type; //isArrayValue属性可将提交字段数据改成[id1,id2,id3]的形式 if (field && field.editor && field.editor.isArrayValue && value) { value = value.split(';'); } //isRef属性可将提交字段数据改成[id,value]的形式 if (field && field.editor && field.editor.isRef && editor.getText) { value = [value, editor.getText()]; } //isRefMul属性可将提交字段数据改成[[id1,value1],[id2,value2]]的形式 if (field && field.editor && field.editor.isRefMul && editor.getText) { var vs = value.split(';'); var ts = editor.getText().split(';'); value = []; for (var i = 0; i < vs.length; i++) { value.push([vs[i], ts[i]]); } } if (edtirType == "int" || edtirType == "digits") { value = value ? parseInt(value, 10) : 0; } else if (edtirType == "float" || edtirType == "number") { value = value ? parseFloat(value) : 0; } return value; } }, setValue: function (editor, value, editParm) { var field = editParm.field || editParm.column; if (editor.setValue) { //设置了isArrayValue属性- 如果获取到的数据是[id1,id2,id3]的形式,需要合并为一个完整字符串 if (field && field.editor && field.editor.isArrayValue && value) { value = value.join(';'); } //设置了isRef属性-如果获取到的数据是[id,text]的形式,需要获取[0] if (field && field.editor && field.editor.isRef && $.isArray(value)) { value = value[0]; } //设置了isRefMul属性- 获取到[[id1,value1],[id2,value2]]的形式,需要合并为一个完整字符串 if (field && field.editor && field.editor.isRefMul && $.isArray(value)) { var vs = []; for (var i = 0; i < value.length; i++) { vs.push(value[i].length > 1 ? value[i][1] : value[i][0]); } value = vs.join(';'); } editor.setValue(value); } }, //从控件获取到文本信息 getText: function (editor, editParm) { var field = editParm.field || editParm.column; if (editor.getText) { var text = editor.getText(); if (text) return text; } }, //设置文本信息到控件去 setText: function (editor, text, editParm) { if (text && editor.setText) { editor.setText(text); } //如果没有把数据保存到 textField 字段,那么需要获取值字段 else { var field = editParm.field || editParm.column; text = editor.setValue() || editParm.value || ""; //如果获取到的数据是[id,text]的形式,需要获取[0] if (field && field.editor && field.editor.isRef && $.isArray(text) && text.length > 1) { text = text[1]; } //在grid的编辑里面 获取到[[id1,value1],[id2,value2]]的形式,需要合并为一个完整字符串 if (field && field.editor && field.editor.isRefMul && $.isArray(text) && text.length > 1) { var vs = []; for (var i = 0; i < text.length; i++) { vs.push(text[1]); } text = vs.join(';'); } if (editor.setText) { editor.setText(text); } } }, getSelected: function (editor, editParm) { if (editor.getSelected) { return editor.getSelected(); } }, resize: function (editor, width, height, editParm) { if (editParm.field) width = width - 2; if (editor.resize) editor.resize(width, height); }, setEnabled: function (editor, isEnabled) { if (isEnabled) { if (editor.setEnabled) editor.setEnabled(); } else { if (editor.setDisabled) editor.setDisabled(); } }, destroy: function (editor, editParm) { if (editor.destroy) editor.destroy(); } }; return $.extend({}, defaultOp, liger.editorCreatorDefaults || {}, e); } //几个默认的编辑器构造函数 liger.editors = { "text": { control: 'TextBox' }, "date": { control: 'DateEditor', setValue: function (editor, value, editParm) { // /Date(1328423451489)/ if (typeof value == "string" && /^\/Date/.test(value)) { value = value.replace(/^\//, "new ").replace(/\/$/, ""); eval("value = " + value); } editor.setValue(value); } }, "combobox": { control: 'ComboBox' }, "spinner": { control: 'Spinner' }, "checkbox": { control: 'CheckBox' }, "checkboxlist": { control: 'CheckBoxList', body: $('
'), resize: function (editor, width, height, editParm) { editor.set('width', width - 2); } }, "radiolist": { control: 'RadioList', body: $('
'), resize: function (editor, width, height, editParm) { editor.set('width', width - 2); } }, "listbox": { control: 'ListBox', body: $('
'), resize: function (editor, width, height, editParm) { editor.set('width', width - 2); } }, "popup": { control: 'PopupEdit' }, "number": { control: 'TextBox', options: { number: true } }, "currency": { control: 'TextBox', options: { currency: true } }, "digits": { control: 'TextBox', options: { digits: true } }, "password": { control: 'TextBox', password: true } }; liger.editors["string"] = liger.editors["text"]; liger.editors["select"] = liger.editors["combobox"]; liger.editors["int"] = liger.editors["digits"]; liger.editors["float"] = liger.editors["number"]; liger.editors["chk"] = liger.editors["checkbox"]; liger.editors["popupedit"] = liger.editors["popup"]; //jQuery version fix $.fn.live = $.fn.on ? $.fn.on : $.fn.live; if (!$.browser) { var userAgent = navigator.userAgent.toLowerCase(); $.browser = { version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [0, '0'])[1], safari: /webkit/.test(userAgent), opera: /opera/.test(userAgent), msie: /msie/.test(userAgent) && !/opera/.test(userAgent), mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent) }; } })(jQuery);/** * jQuery ligerUI 1.3.2 * * http://ligerui.com * * Author daomi 2015 [ gd_star@163.com ] * */ (function ($) { /* 以html的方式加载组件 程序会查询以 liger-插件名 类名的Dom,从dom加载相应的参数并调用插件 比如遇到 .liger-grid 的dom,会找到 liger.defaults.Grid 加载需要的参数 而在config.Grid中配置了这些参数的类型,会动态得加载data,而columns会设置为数组 参数处理的优先级为: 1,ignores 忽略不处理的参数 2,dom存在 {属性名} 的类名 ,比如 ,便会将这个参数设置为复杂属性(object或array):找到相应的defaults和config来加载 defaults是先找$.liger.inject.defaults,找不到再找liger.defaults的 config为{父配置}.{属性名},比如 config.Grid.columns 3,直接读取 data-{属性名} 或者 {属性名} 的dom属性 */ liger.inject = { prev: 'liger-', /* 命名规则:插件名_属性名(包括第N级的属性) (插件名首字母大写,属性名首字母小写) 获取规则:获取default时会先找这里,找不到再找liger.defaults,比如 liger.defaults.Grid_columns 备注:这里只定义了参数的列表 */ defaults: { Grid_detail: { height: null, onShowDetail: null }, Grid_editor: 'ComboBox,DateEditor,Spinner,TextBox,PopupEdit,CheckBoxList,RadioList,Grid_editor', Grid_popup: 'PopupEdit', Grid_grid: 'Grid', Grid_condition: 'Form', Grid_toolbar: 'Toolbar', Grid_fields: 'Form_fields', Form_editor: 'ComboBox,DateEditor,Spinner,TextBox,PopupEdit,CheckBoxList,RadioList,Form_editor', Form_grid: 'Grid', Form_columns: 'Grid_columns', Form_condition: 'Form', Form_popup: 'PopupEdit', Form_buttons: 'Button', Portal_panel: 'Panel' }, /* config里面配置了某插件参数或者复杂属性参数的类型(动态加载、数组、默认参数) */ config: { Grid: { //动态 dynamics: 'data,isChecked,detail,rowDraggingRender,toolbar,columns', //数组 arrays: 'columns', //复杂属性columns columns: { dynamics: 'render,totalSummary,headerRender,columns,editor,columns', arrays: 'columns', textProperty: 'display', columns: 'liger.inject.config.Grid.columns', editor: { dynamics: 'data,columns,render,renderItem,grid,condition,ext', grid: 'liger.inject.config.Grid', condition: 'liger.inject.config.Form' } }, toolbar: { arrays: 'items' } }, Form: { dynamics: 'validate,fields,buttons', arrays: 'fields,buttons', fields: { textProperty: 'label', dynamics: 'validate,editor', editor: { dynamics: 'data,columns,render,renderItem,grid,condition,attr', grid: 'liger.inject.config.Grid', condition: 'liger.inject.config.Form' } }, buttons: 'liger.inject.config.Button' }, PopupEdit: { dynamics: 'grid,condition' }, Button: { textProperty: 'text', dynamics: 'click' }, ComboBox: { dynamics: 'columns,data,tree,grid,condition,render,parms,renderItem' }, ListBox: { dynamics: 'columns,data,render,parms' }, RadioList: { dynamics: 'data,parms' }, CheckBoxList: { dynamics: 'data,parms' }, Panel: { }, Portal: { //动态 dynamics: 'rows,columns', //数组 arrays: 'rows,columns', //复杂属性 columns columns: { dynamics: 'panels', arrays: 'panels' }, //复杂属性 rows rows: { dynamics: 'panels', arrays: 'panels' }, toolbar: { arrays: 'items' } } }, parse: function (code) { try { if (code == null) return null; return new Function("return " + code + ";")(); } catch (e) { return null; } }, parseDefault: function (value) { var g = this; if (!value) return value; var result = {}; $(value.split(',')).each(function (index, name) { if (!name) return; name = name.substr(0, 1).toUpperCase() + name.substr(1); $.extend(result, g.parse("liger.defaults." + name)); }); return result; }, fotmatValue: function (value, type) { if (type == "boolean") return value == "true" || value == "1"; if (type == "number" && value) return parseFloat(value.toString()); return value; }, getOptions: function (e) { var jelement = e.jelement, defaults = e.defaults, config = e.config; config = $.extend({ ignores: "", dynamics: "", arrays: "" }, config); var g = this, options = {}, value; if (config.textProperty) options[config.textProperty] = jelement.text(); for (var proName in defaults) { var className = proName.toLowerCase(); var subElement = $("> ." + className, jelement); //忽略 if ($.inArray(proName, config.ignores.split(',')) != -1) continue; //判断子节点 (复杂属性) if (subElement.length) { var defaultName = e.controlName + "_" + proName; var subDefaults = g.defaults[defaultName] || liger.defaults[defaultName], subConfig = config[proName]; if (typeof (subDefaults) == "string") subDefaults = g.parseDefault(subDefaults); else if (typeof (subDefaults) == "funcion") subDefaults = subDefaults(); if (typeof (subConfig) == "string") subConfig = g.parse(subConfig); else if (typeof (subConfig) == "funcion") subConfig = subConfig(); if (subDefaults) { if ($.inArray(proName, config.arrays.split(',')) != -1) { value = []; $(">div,>li,>input", subElement).each(function () { value.push(g.getOptions({ defaults: subDefaults, controlName: e.controlName, config: subConfig, jelement: $(this) })); }); options[proName] = value; } else { options[proName] = g.getOptions({ defaults: subDefaults, controlName: e.controlName, config: subConfig, jelement: subElement }); } } subElement.remove(); } //动态值 else if ($.inArray(proName, config.dynamics.split(',')) != -1 || proName.indexOf('on') == 0) { value = g.parse(jelement.attr("data-" + proName) || jelement.attr(proName)); if (value) { options[proName] = g.fotmatValue(value, typeof (defaults[proName])); } } //默认处理 else { value = jelement.attr("data-" + proName) || jelement.attr(proName); if (value) { options[proName] = g.fotmatValue(value, typeof (defaults[proName])); } } } var dataOptions = jelement.attr("data-options") || jelement.attr("data-property"); if (dataOptions) dataOptions = g.parse("{" + dataOptions + "}"); if (dataOptions) $.extend(options, dataOptions); return options; }, init: function () { var g = this, configs = this.config; for (var name in g.defaults) { if (typeof (g.defaults[name]) == "string") { g.defaults[name] = g.parseDefault(g.defaults[name]); } } for (var controlName in liger.controls) { var config = configs[controlName] || {}; var className = g.prev + controlName.toLowerCase(); $("." + className).each(function () { var jelement = $(this), value; var defaults = $.extend({ onrender: null, onrendered: null }, liger.defaults[controlName]); var options = g.getOptions({ defaults: defaults, controlName: controlName, config: config, jelement: jelement }); jelement[liger.pluginPrev + controlName](options); }); } } } $(function () { liger.inject.init(); }); })(jQuery);/** * jQuery ligerUI 1.3.2 * * http://ligerui.com * * Author daomi 2015 [ gd_star@163.com ] * */ (function ($) { $.fn.ligerAccordion = function (options) { return $.ligerui.run.call(this, "ligerAccordion", arguments); }; $.fn.ligerGetAccordionManager = function () { return $.ligerui.get(this); }; $.ligerDefaults.Accordion = { height: null, speed: "normal", changeHeightOnResize: false, heightDiff: 0 // 高度补差 }; $.ligerMethos.Accordion = {}; $.ligerui.controls.Accordion = function (element, options) { $.ligerui.controls.Accordion.base.constructor.call(this, element, options); }; $.ligerui.controls.Accordion.ligerExtend($.ligerui.core.UIComponent, { __getType: function () { return 'Accordion'; }, __idPrev: function () { return 'Accordion'; }, _extendMethods: function () { return $.ligerMethos.Accordion; }, _render: function () { var g = this, p = this.options; g.accordion = $(g.element); if (!g.accordion.hasClass("l-accordion-panel")) g.accordion.addClass("l-accordion-panel"); var selectedIndex = 0; if ($("> div[lselected=true]", g.accordion).length > 0) selectedIndex = $("> div", g.accordion).index($("> div[lselected=true]", g.accordion)); $("> div", g.accordion).each(function (i, box) { var header = $('
'); if (i == selectedIndex) $(".l-accordion-toggle", header).addClass("l-accordion-toggle-open"); if ($(box).attr("title")) { $(".l-accordion-header-inner", header).html($(box).attr("title")); $(box).attr("title", ""); } $(box).before(header); if (!$(box).hasClass("l-accordion-content")) $(box).addClass("l-accordion-content"); if ($(box).attr("data-icon")) { header.addClass("l-accordion-header-hasicon"); header.append(''); } }); $(".l-accordion-header", g.accordion).removeClass("l-accordion-header-downfirst"); $(".l-accordion-content:visible", g.accordion).next(".l-accordion-header:first").addClass("l-accordion-header-downfirst"); //add Even $(".l-accordion-toggle", g.accordion).each(function () { if (!$(this).hasClass("l-accordion-toggle-open") && !$(this).hasClass("l-accordion-toggle-close")) { $(this).addClass("l-accordion-toggle-close"); } if ($(this).hasClass("l-accordion-toggle-close")) { $(this).parent().next(".l-accordion-content:visible").hide(); } }); $(".l-accordion-header", g.accordion).hover(function () { $(this).addClass("l-accordion-header-over"); }, function () { $(this).removeClass("l-accordion-header-over"); }); $(".l-accordion-toggle", g.accordion).hover(function () { if ($(this).hasClass("l-accordion-toggle-open")) $(this).addClass("l-accordion-toggle-open-over"); else if ($(this).hasClass("l-accordion-toggle-close")) $(this).addClass("l-accordion-toggle-close-over"); }, function () { if ($(this).hasClass("l-accordion-toggle-open")) $(this).removeClass("l-accordion-toggle-open-over"); else if ($(this).hasClass("l-accordion-toggle-close")) $(this).removeClass("l-accordion-toggle-close-over"); }); $(">.l-accordion-header", g.accordion).click(function () { var togglebtn = $(".l-accordion-toggle:first", this); if (togglebtn.hasClass("l-accordion-toggle-close")) { togglebtn.removeClass("l-accordion-toggle-close") .removeClass("l-accordion-toggle-close-over l-accordion-toggle-open-over") togglebtn.addClass("l-accordion-toggle-open"); $(this).next(".l-accordion-content") .show(p.speed) .siblings(".l-accordion-content:visible").hide(p.speed); $(this).siblings(".l-accordion-header").find(".l-accordion-toggle").removeClass("l-accordion-toggle-open").addClass("l-accordion-toggle-close"); } else { togglebtn.removeClass("l-accordion-toggle-open") .removeClass("l-accordion-toggle-close-over l-accordion-toggle-open-over") .addClass("l-accordion-toggle-close"); $(this).next(".l-accordion-content").hide(p.speed); } $(".l-accordion-header", g.accordion).removeClass("l-accordion-header-downfirst"); $(".l-accordion-content:visible", g.accordion).next(".l-accordion-header:first").addClass("l-accordion-header-downfirst"); }); //init g.headerHoldHeight = 0; $("> .l-accordion-header", g.accordion).each(function () { g.headerHoldHeight += $(this).height(); }); if (p.height && typeof (p.height) == 'string' && p.height.indexOf('%') > 0) { g.onResize(); if (p.changeHeightOnResize) { $(window).resize(function () { g.onResize(); }); } } else { if (p.height) { g.height = p.heightDiff + p.height; g.accordion.height(g.height); g.setHeight(p.height); } else { g.header = g.accordion.height(); } } g.set(p); }, onResize: function () { var g = this, p = this.options; if (!p.height || typeof (p.height) != 'string' || p.height.indexOf('%') == -1) return false; //set accordion height if (g.accordion.parent()[0].tagName.toLowerCase() == "body") { var windowHeight = $(window).height(); windowHeight -= parseInt(g.layout.parent().css('paddingTop')); windowHeight -= parseInt(g.layout.parent().css('paddingBottom')); g.height = p.heightDiff + windowHeight * parseFloat(g.height) * 0.01; } else { g.height = p.heightDiff + (g.accordion.parent().height() * parseFloat(p.height) * 0.01); } g.accordion.height(g.height); g.setContentHeight(g.height - g.headerHoldHeight); }, setHeight: function (height) { var g = this, p = this.options; g.accordion.height(height); height -= g.headerHoldHeight; $("> .l-accordion-content", g.accordion).height(height); } }); })(jQuery);/** * jQuery ligerUI 1.3.2 * * http://ligerui.com * * Author daomi 2015 [ gd_star@163.com ] * */ (function ($) { $.fn.ligerButton = function (options) { return $.ligerui.run.call(this, "ligerButton", arguments); }; $.fn.ligerGetButtonManager = function () { return $.ligerui.run.call(this, "ligerGetButtonManager", arguments); }; $.ligerDefaults.Button = { width: 60, text: 'Button', disabled: false, click: null, icon : null }; $.ligerMethos.Button = {}; $.ligerui.controls.Button = function (element, options) { $.ligerui.controls.Button.base.constructor.call(this, element, options); }; $.ligerui.controls.Button.ligerExtend($.ligerui.controls.Input, { __getType: function () { return 'Button'; }, __idPrev: function () { return 'Button'; }, _extendMethods: function () { return $.ligerMethos.Button; }, _render: function () { var g = this, p = this.options; g.button = $(g.element); g.button.addClass("l-button"); g.button.append('
'); g.button.hover(function () { if (p.disabled) return; g.button.addClass("l-button-over"); }, function () { if (p.disabled) return; g.button.removeClass("l-button-over"); }); p.click && g.button.click(function () { if (!p.disabled) p.click(); }); g.set(p); }, _setIcon : function(url) { var g = this; if (!url) { g.button.removeClass("l-button-hasicon"); g.button.find('img').remove(); } else { g.button.addClass("l-button-hasicon"); g.button.append(''); } }, _setEnabled: function (value) { if (value) this.button.removeClass("l-button-disabled"); }, _setDisabled: function (value) { if (value) { this.button.addClass("l-button-disabled"); this.options.disabled = true; } else { this.button.removeClass("l-button-disabled"); this.options.disabled = false; } }, _setWidth: function (value) { this.button.width(value); }, _setText: function (value) { $("span", this.button).html(value); }, setValue: function (value) { this.set('text', value); }, getValue: function () { return this.options.text; }, setEnabled: function () { this.set('disabled', false); }, setDisabled: function () { this.set('disabled', true); } }); })(jQuery);/** * jQuery ligerUI 1.3.2 * * http://ligerui.com * * Author daomi 2015 [ gd_star@163.com ] * */ (function ($) { $.fn.ligerCheckBox = function (options) { return $.ligerui.run.call(this, "ligerCheckBox", arguments); }; $.fn.ligerGetCheckBoxManager = function () { return $.ligerui.run.call(this, "ligerGetCheckBoxManager", arguments); }; $.ligerDefaults.CheckBox = { disabled: false, readonly : false //只读 }; $.ligerMethos.CheckBox = {}; $.ligerui.controls.CheckBox = function (element, options) { $.ligerui.controls.CheckBox.base.constructor.call(this, element, options); }; $.ligerui.controls.CheckBox.ligerExtend($.ligerui.controls.Input, { __getType: function () { return 'CheckBox'; }, __idPrev: function () { return 'CheckBox'; }, _extendMethods: function () { return $.ligerMethos.CheckBox; }, _render: function () { var g = this, p = this.options; g.input = $(g.element); g.link = $(''); g.wrapper = g.input.addClass('l-hidden').wrap('
').parent(); g.wrapper.prepend(g.link); g.link.click(function () { if (g.input.attr('disabled') || g.input.attr('readonly')) { return false; } if (p.disabled || p.readonly) return false; if (g.trigger('beforeClick', [g.element]) == false) return false; if ($(this).hasClass("l-checkbox-checked")) { g._setValue(false); } else { g._setValue(true); } g.input.trigger("change"); }); g.wrapper.hover(function () { if (!p.disabled) $(this).addClass("l-over"); }, function () { $(this).removeClass("l-over"); }); this.set(p); this.updateStyle(); }, _setCss: function (value) { this.wrapper.css(value); }, _setValue: function (value) { var g = this, p = this.options; if (!value) { g.input[0].checked = false; g.link.removeClass('l-checkbox-checked'); } else { g.input[0].checked = true; g.link.addClass('l-checkbox-checked'); } }, _setDisabled: function (value) { if (value) { this.input.attr('disabled', true); this.wrapper.addClass("l-disabled"); } else { this.input.attr('disabled', false); this.wrapper.removeClass("l-disabled"); } }, _getValue: function () { return this.element.checked; }, updateStyle: function () { if (this.input.attr('disabled')) { this.wrapper.addClass("l-disabled"); this.options.disabled = true; } if (this.input[0].checked) { this.link.addClass('l-checkbox-checked'); } else { this.link.removeClass('l-checkbox-checked'); } } }); })(jQuery);/** * jQuery ligerUI 1.3.2 * * http://ligerui.com * * Author daomi 2015 [ gd_star@163.com ] * */ (function ($) { $.fn.ligerCheckBoxList = function (options) { return $.ligerui.run.call(this, "ligerCheckBoxList", arguments); }; $.ligerDefaults.CheckBoxList = { rowSize: 3, //每行显示元素数 valueField: 'id', //值成员 textField: 'text', //显示成员 valueFieldID:null, //隐藏域 name : null, //表单名 split: ";", //分隔符 data: null, //数据 parms: null, //ajax提交表单 url: null, //数据源URL(需返回JSON) ajaxType : 'post', onSuccess: null, onError: null, css: null, //附加css value: null, //值 valueFieldCssClass : null }; //扩展方法 $.ligerMethos.CheckBoxList = $.ligerMethos.CheckBoxList || {}; $.ligerui.controls.CheckBoxList = function (element, options) { $.ligerui.controls.CheckBoxList.base.constructor.call(this, element, options); }; $.ligerui.controls.CheckBoxList.ligerExtend($.ligerui.controls.Input, { __getType: function () { return 'CheckBoxList'; }, _extendMethods: function () { return $.ligerMethos.CheckBoxList; }, _init: function () { $.ligerui.controls.CheckBoxList.base._init.call(this); }, _render: function () { var g = this, p = this.options; g.data = p.data; g.valueField = null; //隐藏域(保存值) if ($(this.element).is(":hidden") || $(this.element).is(":text")) { g.valueField = $(this.element); if ($(this.element).is(":text")) { g.valueField.hide(); } } else if (p.valueFieldID) { g.valueField = $("#" + p.valueFieldID + ":input,[name=" + p.valueFieldID + "]:input"); if (g.valueField.length == 0) g.valueField = $(''); g.valueField[0].id = g.valueField[0].name = p.valueFieldID; } else { g.valueField = $(''); g.valueField[0].id = g.valueField[0].name = g.id + "_val"; } if (g.valueField[0].name == null) g.valueField[0].name = g.valueField[0].id; if (p.valueFieldCssClass) { g.valueField.addClass(p.valueFieldCssClass); } g.valueField.attr("data-ligerid", g.id); if ($(this.element).is(":hidden") || $(this.element).is(":text")) { g.checkboxList = $('
').insertBefore(this.element); } else { g.checkboxList = $(this.element); } g.checkboxList.html('
').addClass("l-checkboxlist").append(g.valueField); g.checkboxList.table = $("table:first", g.checkboxList); g.set(p); g._addClickEven(); }, destroy: function () { if (this.checkboxList) this.checkboxList.remove(); this.options = null; $.ligerui.remove(this); }, clear : function() { this._changeValue(""); this.trigger('clear'); }, _setCss : function(css) { if (css) { this.checkboxList.addClass(css); } }, _setDisabled: function (value) { //禁用样式 if (value) { this.checkboxList.addClass('l-checkboxlist-disabled'); $("input:checkbox", this.radioList).attr("disabled", true); } else { this.checkboxList.removeClass('l-checkboxlist-disabled'); $("input:checkbox", this.radioList).removeAttr("disabled"); } }, _setWidth: function (value) { this.checkboxList.width(value); }, _setHeight: function (value) { this.checkboxList.height(value); }, indexOf : function(item) { var g = this, p = this.options; if (!g.data) return -1; for (var i = 0, l = g.data.length; i < l; i++) { if (typeof (item) == "object") { if (g.data[i] == item) return i; } else { if (g.data[i][p.valueField].toString() == item.toString()) return i; } } return -1; }, removeItems : function(items) { var g = this; if (!g.data) return; $(items).each(function (i,item) { var index = g.indexOf(item); if (index == -1) return; g.data.splice(index, 1); }); g.refresh(); }, removeItem: function (item) { if (!this.data) return; var index = this.indexOf(item); if (index == -1) return; this.data.splice(index, 1); this.refresh(); }, insertItem: function (item,index) { var g = this; if (!g.data) g.data = []; g.data.splice(index, 0, item); g.refresh(); }, addItems: function (items) { var g = this; if (!g.data) g.data = []; $(items).each(function (i, item) { g.data.push(item); }); g.refresh(); }, addItem: function (item) { var g = this; if (!g.data) g.data = []; g.data.push(item); g.refresh(); }, _setValue: function (value) { var g = this, p = this.options; p.value = value; g.valueField.val(p.value); this._dataInit(); }, setValue: function (value) { this._setValue(value); }, _setUrl: function (url) { if (!url) return; var g = this, p = this.options; var parms = $.isFunction(p.parms) ? p.parms() : p.parms; $.ajax({ type: p.ajaxType || 'post', url: url, data: parms, cache: false, dataType: 'json', success: function (data) { g.setData(data); g.trigger('success', [data]); }, error: function (XMLHttpRequest, textStatus) { g.trigger('error', [XMLHttpRequest, textStatus]); } }); }, setUrl: function (url) { return this._setUrl(url); }, setParm: function (name, value) { if (!name) return; var g = this; var parms = g.get('parms'); if (!parms) parms = {}; parms[name] = value; g.set('parms', parms); }, clearContent: function () { var g = this, p = this.options; $("table", g.checkboxList).html(""); }, _setData : function(data) { this.setData(data); }, setData: function (data) { var g = this, p = this.options; if (!data || !data.length) return; g.data = data; g.refresh(); g.updateStyle(); }, refresh:function() { var g = this, p = this.options, data = this.data; this.clearContent(); if (!data) return; var out = [], rowSize = p.rowSize, appendRowStart = false, name = p.name || g.id; for (var i = 0; i < data.length; i++) { var val = data[i][p.valueField], txt = data[i][p.textField], id = g.id + "-" + i; var newRow = i % rowSize == 0; //0,5,10 if (newRow) { if (appendRowStart) out.push(''); out.push(""); appendRowStart = true; } out.push(""); } if (appendRowStart) out.push(''); g.checkboxList.table.append(out.join('')); }, _getValue: function () { var g = this, p = this.options, name = p.name || g.id; var values = []; $('input:checkbox[name="' + name + '"]:checked').each(function () { values.push(this.value); }); if (!values.length) return null; return values.join(p.split); }, getValue: function () { //获取值 return this._getValue(); }, getText : function() { var g = this, p = this.options, name = p.name || g.id; var values = []; $('input:checkbox[name="' + name + '"]:checked').each(function () { values.push($(this).next("label").text()); }); if (!values.length) return null; return values.join(p.split); }, updateStyle: function () { this._dataInit(); }, _dataInit: function () { var g = this, p = this.options; var value = g.valueField.val(); g._changeValue(value); }, //设置值到 隐藏域 _changeValue: function (value) { var g = this, p = this.options, name = p.name || g.id; var valueArr = value ? value.split(p.split) : []; $("input:checkbox[name='" + name + "']", g.checkboxList).each(function () { this.checked = $.inArray(this.value, valueArr) > -1; }); g.valueField.val(value); g.selectedValue = value; }, _addClickEven: function () { var g = this, p = this.options; //选项点击 g.checkboxList.click(function (e) { var value = g.getValue(); if (value) g.valueField.val(value); }); } }); })(jQuery);/** * jQuery ligerUI 1.3.2 * * http://ligerui.com * * Author daomi 2015 [ gd_star@163.com ] * */ (function ($) { $.fn.ligerComboBox = function (options) { return $.ligerui.run.call(this, "ligerComboBox", arguments); }; $.fn.ligerGetComboBoxManager = function () { return $.ligerui.run.call(this, "ligerGetComboBoxManager", arguments); }; $.ligerDefaults.ComboBox = { resize: true, //是否调整大小 isMultiSelect: false, //是否多选 isShowCheckBox: false, //是否选择复选框 columns: null, //表格状态 width : null, selectBoxWidth: null, //宽度 selectBoxHeight: 120, //高度 selectBoxPosYDiff : -3, //下拉框位置y坐标调整 onBeforeSelect: false, //选择前事件 onAfterShowData : null, onSelected: null, //选择值事件 initValue: null, value : null, initText: null, valueField: 'id', textField: 'text', dataParmName : null, valueFieldID: null, ajaxComplete: null, ajaxBeforeSend: null, ajaxContentType : null, slide: false, //是否以动画的形式显示 split: ";", data: null, dataGetter : null, //下拉框数据集获取函数 tree: null, //下拉框以树的形式显示,tree的参数跟LigerTree的参数一致 treeLeafOnly: true, //是否只选择叶子 condition: null, //列表条件搜索 参数同 ligerForm grid: null, //表格 参数同 ligerGrid onStartResize: null, onEndResize: null, hideOnLoseFocus: true, hideGridOnLoseFocus: false, url: null, //数据源URL(需返回JSON) urlParms: null, //url带参数 selectBoxRender: null, //自定义selectbox的内容 selectBoxRenderUpdate: null, //自定义selectbox(发生值改变) detailEnabled : true, //detailUrl是否有效 detailUrl: null, //确定选项的时候,使用这个detailUrl加载到详细的数据 detailPostIdField : null, //提交数据id字段名 detailDataParmName:null, //返回数据data字段名 detailParms: null, //附加参数 detailDataGetter: null, delayLoad: false, //是否延时加载 triggerToLoad : false, //是否在点击下拉按钮时加载 emptyText: null, //空行 addRowButton: '新增', //新增按钮 addRowButtonClick: null, //新增事件 triggerIcon: null, // onSuccess: null, onBeforeSetData: null, onError: null, onBeforeOpen: null, //打开下拉框前事件,可以通过return false来阻止继续操作,利用这个参数可以用来调用其他函数,比如打开一个新窗口来选择值 onButtonClick: null, //右侧图标按钮事件,可以通过return false来阻止继续操作,利用这个参数可以用来调用其他函数,比如打开一个新窗口来选择值 onTextBoxKeyDown: null, onTextBoxKeyEnter : null, render: null, //文本框显示html函数 absolute: true, //选择框是否在附加到body,并绝对定位 cancelable: true, //可取消选择 css: null, //附加css parms: null, //ajax提交表单 renderItem: null, //选项自定义函数 autocomplete: false, //自动完成 autocompleteAllowEmpty : true, //是否允许空值搜索 highLight: false, //自动完成是否匹配字符高亮显示 readonly: false, //是否只读 ajaxType: 'post', alwayShowInTop: false, //下拉框是否一直显示在上方 alwayShowInDown: false, //下拉框是否一直显示在上方 valueFieldCssClass: null, isRowReadOnly: null, //选项是否只读的判定函数 rowClsRender: null, //选项行 class name 自定义函数 keySupport: false, //按键支持: 上、下、回车 支 initIsTriggerEvent: false, //初始化时是否触发选择事件 conditionSearchClick: null //下拉框表格搜索按钮自定义函数 }; $.ligerDefaults.ComboBoxString = { Search: "搜索" }; //扩展方法 $.ligerMethos.ComboBox = $.ligerMethos.ComboBox || {}; $.ligerui.controls.ComboBox = function (element, options) { $.ligerui.controls.ComboBox.base.constructor.call(this, element, options); }; $.ligerui.controls.ComboBox.ligerExtend($.ligerui.controls.Input, { __getType: function () { return 'ComboBox'; }, _extendMethods: function () { return $.ligerMethos.ComboBox; }, _init: function () { $.ligerui.controls.ComboBox.base._init.call(this); var p = this.options; if (p.columns) { p.isShowCheckBox = true; } if (p.isMultiSelect) { p.isShowCheckBox = true; } if (p.triggerToLoad) { p.delayLoad = true; } }, _render: function () { var g = this, p = this.options; g.data = p.data; g.inputText = null; g.select = null; g.textFieldID = ""; g.valueFieldID = ""; g.valueField = null; //隐藏域(保存值) if ($(this.element).is(":hidden")) { g.valueField = $(this.element); g.textFieldID = p.textFieldID || (this.element.id + "_txt"); g.inputText = $(''); g.inputText.attr("id", g.textFieldID).insertAfter($(this.element)); if (g.valueField.attr("validate")) { g.inputText.attr("validate", g.valueField.attr("validate")); g.valueField.removeAttr("validate"); } if (g.valueField.attr("validateMessage")) { g.inputText.attr("validateMessage", g.valueField.attr("validateMessage")); g.valueField.removeAttr("validateMessage"); } } else if (this.element.tagName.toLowerCase() == "input") { this.element.readOnly = true; g.inputText = $(this.element); g.textFieldID = this.element.id; } else if (this.element.tagName.toLowerCase() == "select") { $(this.element).hide(); g.select = $(this.element); p.isMultiSelect = false; p.isShowCheckBox = false; p.cancelable = false; g.textFieldID = p.textFieldID || (this.element.id + "_txt"); g.inputText = $(''); g.inputText.attr("id", g.textFieldID).insertAfter($(this.element)); if (g.select.attr("validate")) { g.inputText.attr("validate", g.select.attr("validate")); g.select.removeAttr("validate"); } if (g.select.attr("validateMessage")) { g.inputText.attr("validateMessage", g.select.attr("validateMessage")); g.select.removeAttr("validateMessage"); } if (!p.value && this.element.value) { p.value = this.element.value; } } if (g.inputText[0].name == undefined) g.inputText[0].name = g.textFieldID; g.inputText.attr("data-comboboxid", g.id); if (g.valueField == null) { if (p.valueFieldID) { g.valueField = $("#" + p.valueFieldID + ":input,[name=" + p.valueFieldID + "]:input").filter("input:hidden"); if (g.valueField.length == 0) g.valueField = $(''); g.valueField[0].id = g.valueField[0].name = p.valueFieldID; } else { g.valueField = $(''); g.valueField[0].id = g.valueField[0].name = g.textFieldID + "_val"; } } if (p.valueFieldCssClass) { g.valueField.addClass(p.valueFieldCssClass); } if (g.valueField[0].name == undefined) g.valueField[0].name = g.valueField[0].id; //update by superzoc 增加初始值 if (p.initValue != null) g.valueField[0].value = p.initValue; g.valueField.attr("data-ligerid", g.id); //开关 g.link = $('
'); if (p.triggerIcon) g.link.find("div:first").addClass(p.triggerIcon); //下拉框 g.selectBox = $(''); g.selectBox.table = $("table:first", g.selectBox); g.selectBoxInner = g.selectBox.find(".l-box-select-inner:first"); //外层 g.wrapper = g.inputText.wrap('
').parent(); g.wrapper.append('
'); g.wrapper.append(g.link); //添加个包裹, g.textwrapper = g.wrapper.wrap('
').parent(); if (p.absolute) g.selectBox.appendTo('body').addClass("l-box-select-absolute"); else g.textwrapper.append(g.selectBox); g.textwrapper.append(g.valueField); g.inputText.addClass("l-text-field"); if (p.isShowCheckBox && !g.select) { $("table", g.selectBox).addClass("l-table-checkbox"); } else { p.isShowCheckBox = false; $("table", g.selectBox).addClass("l-table-nocheckbox"); } //开关 事件 g.link.hover(function () { if (p.disabled || p.readonly) return; this.className = "l-trigger-hover"; }, function () { if (p.disabled || p.readonly) return; this.className = "l-trigger"; }).mousedown(function () { if (p.disabled || p.readonly) return; this.className = "l-trigger-pressed"; }).mouseup(function () { if (p.disabled || p.readonly) return; this.className = "l-trigger-hover"; }).click(function () { if (p.disabled || p.readonly) return; if (g.trigger('buttonClick') == false) return false; if (g.trigger('beforeOpen') == false) return false; if (p.triggerToLoad && !g.triggerLoaded) { g.triggerLoaded = true; g._setUrl(p.url, function () { g._toggleSelectBox(g.selectBox.is(":visible")); }); } else { g._toggleSelectBox(g.selectBox.is(":visible")); } }); g.inputText.click(function () { if (p.disabled || p.readonly) return; if (g.trigger('beforeOpen') == false) return false; if (!p.autocomplete) { if (p.triggerToLoad && !g.triggerLoaded) { g.triggerLoaded = true; g._setUrl(p.url, function () { g._toggleSelectBox(g.selectBox.is(":visible")); }); } else { g._toggleSelectBox(g.selectBox.is(":visible")); } } else { g.updateSelectBoxPosition(); } }).blur(function () { if (p.disabled) return; g.wrapper.removeClass("l-text-focus"); }).focus(function () { if (p.disabled || p.readonly) return; g.wrapper.addClass("l-text-focus"); }); g.wrapper.hover(function () { if (p.disabled || p.readonly) return; g.wrapper.addClass("l-text-over"); }, function () { if (p.disabled || p.readonly) return; g.wrapper.removeClass("l-text-over"); }); g.resizing = false; g.selectBox.hover(null, function (e) { if (p.hideOnLoseFocus && g.selectBox.is(":visible") && !g.boxToggling && !g.resizing) { g._toggleSelectBox(true); } }); //下拉框内容初始化 g.bulidContent(); g.set(p, null, "init"); //下拉框宽度、高度初始化 if (p.selectBoxWidth) { g.selectBox.width(p.selectBoxWidth); } else { g.selectBox.css('width', g.wrapper.css('width')); } if (p.grid) { g.bind('show', function () { if (!g.grid) { g.setGrid(p.grid); g.set('SelectBoxHeight', p.selectBoxHeight); } }); } g.updateSelectBoxPosition(); $(document).bind("click.combobox", function (e) { //修改点击空白处隐藏下拉框功能 if (g.selectBox.is(":visible") && $((e.target || e.srcElement)).closest(".l-box-select, .l-text-combobox").length == 0) { g._toggleSelectBox(true); } }); }, destroy: function () { if (this.wrapper) this.wrapper.remove(); if (this.selectBox) this.selectBox.remove(); this.options = null; $.ligerui.remove(this); }, clear: function () { this._changeValue("", ""); $("a.l-checkbox-checked", this.selectBox).removeClass("l-checkbox-checked"); $("td.l-selected", this.selectBox).removeClass("l-selected"); $(":checkbox", this.selectBox).each(function () { this.checked = false; }); this.trigger('clear'); }, _setSelectBoxHeight: function (height) { if (!height) return; var g = this, p = this.options; if (p.grid) { g.grid && g.grid.set('height', g.getGridHeight(height)); } else if (!p.tree) { var itemsleng = $("tr", g.selectBox.table).length; if (!p.selectBoxHeight && itemsleng < 8) p.selectBoxHeight = itemsleng * 30; if (p.selectBoxHeight) { if (itemsleng < 8) { g.selectBoxInner.height('auto'); } else { g.selectBoxInner.height(p.selectBoxHeight); } } } }, _setCss: function (css) { if (css) { this.wrapper.addClass(css); } }, //取消选择 _setCancelable: function (value) { var g = this, p = this.options; if (!value && g.unselect) { g.unselect.remove(); g.unselect = null; } if (!value && !g.unselect) return; g.unselect = $('
').hide(); g.wrapper.hover(function () { g.unselect.show(); }, function () { g.unselect.hide(); }) if (!p.disabled && !p.readonly && p.cancelable) { g.wrapper.append(g.unselect); } g.unselect.hover(function () { this.className = "l-trigger-hover l-trigger-cancel"; }, function () { this.className = "l-trigger l-trigger-cancel"; }).click(function () { g.clear(); }); }, _setDisabled: function (value) { //禁用样式 if (value) { this.wrapper.addClass('l-text-disabled'); } else { this.wrapper.removeClass('l-text-disabled'); } }, _setReadonly: function (readonly) { if (readonly) { this.wrapper.addClass("l-text-readonly"); } else { this.wrapper.removeClass("l-text-readonly"); } }, _setLable: function (label) { var g = this, p = this.options; if (label) { if (g.labelwrapper) { g.labelwrapper.find(".l-text-label:first").html(label + ': '); } else { g.labelwrapper = g.textwrapper.wrap('
').parent(); g.labelwrapper.prepend('
' + label + ': 
'); g.textwrapper.css('float', 'left'); } if (!p.labelWidth) { p.labelWidth = $('.l-text-label', g.labelwrapper).outerWidth(); } else { $('.l-text-label', g.labelwrapper).outerWidth(p.labelWidth); } $('.l-text-label', g.labelwrapper).width(p.labelWidth); $('.l-text-label', g.labelwrapper).height(g.wrapper.height()); g.labelwrapper.append('
'); if (p.labelAlign) { $('.l-text-label', g.labelwrapper).css('text-align', p.labelAlign); } g.textwrapper.css({ display: 'inline' }); g.labelwrapper.width(g.wrapper.outerWidth() + p.labelWidth + 2); } }, _setWidth: function (value) { var g = this, p = this.options; if (value > 20) { g.wrapper.css({ width: value }); g.inputText.css({ width: value - 20 }); if (!p.selectBoxWidth) { g.selectBox.css({ width: value }); } } }, _setHeight: function (value) { var g = this; if (value > 10) { g.wrapper.height(value); g.inputText.height(value - 2); } }, _setResize: function (resize) { var g = this, p = this.options; if (p.columns) { return; } //调整大小支持 if (resize && $.fn.ligerResizable) { var handles = p.selectBoxHeight ? 'e' : 'se,s,e'; g.selectBox.ligerResizable({ handles: handles, onStartResize: function () { g.resizing = true; g.trigger('startResize'); }, onEndResize: function () { g.resizing = false; if (g.trigger('endResize') == false) return false; }, onStopResize: function (current, e) { if (g.grid) { if (current.newWidth) { g.selectBox.width(current.newWidth); } if (current.newHeight) { g.set({ selectBoxHeight: current.newHeight }); } g.grid.refreshSize(); g.trigger('endResize'); return false; } return true; } }); g.selectBox.append("
"); } }, //查找Text,适用多选和单选 findTextByValue: function (value) { var g = this, p = this.options; if (value == null) return ""; var texts = ""; var contain = function (checkvalue) { var targetdata = value.toString().split(p.split); for (var i = 0; i < targetdata.length; i++) { if (targetdata[i] == checkvalue) return true; } return false; }; //当combobox下拉一个grid时, 不能直接取data. 必须取grid的data. //原写法$(g.data) 仅适用于无grid时的典型情形 var d; if (g.options.grid && g.options.grid.data) d = g.options.grid.data.Rows; else d = g.data; $(d).each(function (i, item) { var val = item[p.valueField]; var txt = item[p.textField]; if (contain(val)) { texts += txt + p.split; } }); if (texts.length > 0) texts = texts.substr(0, texts.length - 1); return texts; }, //查找Value,适用多选和单选 findValueByText: function (text) { var g = this, p = this.options; if (!text && text == "") return ""; var contain = function (checkvalue) { var targetdata = text.toString().split(p.split); for (var i = 0; i < targetdata.length; i++) { if (targetdata[i] == checkvalue) return true; } return false; }; var values = ""; $(g.data).each(function (i, item) { var val = item[p.valueField]; var txt = item[p.textField]; if (contain(txt)) { values += val + p.split; } }); if (values.length > 0) values = values.substr(0, values.length - 1); return values; }, insertItem: function (data, index) { var g = this, p = this.options; g.data = g.data || []; g.data.splice(index, 0, data); g.setData(g.data); }, addItem: function (data) { var g = this, p = this.options; g.insertItem(data, (g.data || []).length); }, _setValue: function (value, text) { var g = this, p = this.options; var isInit = false, isTriggerEvent = true; if (text == "init") { text = null; isInit = true; isTriggerEvent = p.initIsTriggerEvent ? true : false; } text = text || g.findTextByValue(value); if (p.tree) { g.selectValueByTree(value); } else if (!p.isMultiSelect) { g._changeValue(value, text, isTriggerEvent); $("tr[value='" + value + "'] td", g.selectBox).addClass("l-selected"); $("tr[value!='" + value + "'] td", g.selectBox).removeClass("l-selected"); } else { g._changeValue(value, text, isTriggerEvent); if (value != null) { var targetdata = value.toString().split(p.split); $("table.l-table-checkbox :checkbox", g.selectBox).each(function () { this.checked = false; }); for (var i = 0; i < targetdata.length; i++) { $("table.l-table-checkbox tr[value=" + targetdata[i] + "] :checkbox", g.selectBox).each(function () { this.checked = true; }); } } } if (p.selectBoxRenderUpdate) { p.selectBoxRenderUpdate.call(g, { selectBox: g.selectBox, value: value, text: text }); } }, selectValue: function (value) { this._setValue(value); }, bulidContent: function () { var g = this, p = this.options; this.clearContent(); if (g.select) { g.setSelect(); } else if (p.tree) { g.setTree(p.tree); } }, reload: function () { var g = this, p = this.options; if (p.url) { g.set('url', p.url); } else if (g.grid) { g.grid.reload(); } }, _setUrl: function (url,callback) { if (!url) return; var g = this, p = this.options; if (p.readonly) //只读状态不加载数据 { return; } if (p.delayLoad && !g.isAccessDelay && !g.triggerLoaded) { g.isAccessDelay = true;//已经有一次延时加载了 return; } url = $.isFunction(url) ? url.call(g) : url; var urlParms = $.isFunction(p.urlParms) ? p.urlParms.call(g) : p.urlParms; if (urlParms) { for (name in urlParms) { url += url.indexOf('?') == -1 ? "?" : "&"; url += name + "=" + urlParms[name]; } } var parms = $.isFunction(p.parms) ? p.parms.call(g) : p.parms; if (p.ajaxContentType == "application/json" && typeof (parms) != "string") { parms = liger.toJSON(parms); } var ajaxOp = { type: p.ajaxType, url: url, data: parms, cache: false, dataType: 'json', beforeSend: p.ajaxBeforeSend, complete: p.ajaxComplete, success: function (result) { var data = $.isFunction(p.dataGetter) ? data = p.dataGetter.call(g, result) : result; data = p.dataParmName && data ? data[p.dataParmName] : data; if (g.trigger('beforeSetData', [data]) == false) { return; } g.setData(data); g.trigger('success', [data]); if ($.isFunction(callback)) callback(data); }, error: function (XMLHttpRequest, textStatus) { g.trigger('error', [XMLHttpRequest, textStatus]); } }; if (p.ajaxContentType) { ajaxOp.contentType = p.ajaxContentType; } $.ajax(ajaxOp); }, setUrl: function (url,callback) { return this._setUrl(url, callback); }, setParm: function (name, value) { if (!name) return; var g = this; var parms = g.get('parms'); if (!parms) parms = {}; parms[name] = value; g.set('parms', parms); }, clearContent: function () { var g = this, p = this.options; if (!g) return; $("table", g.selectBox).html(""); if (!g) return; //清除下拉框内容的时候重设高度 g._setSelectBoxHeight(p.selectBoxHeight); //modify end //g.inputText.val(""); //g.valueField.val(""); }, setSelect: function () { var g = this, p = this.options; this.clearContent(); g.data = []; $('option', g.select).each(function (i) { var val = $(this).val(); var txt = $(this).html(); g.data.push({ text: txt, id: val }); var tr = $("" + txt + ""); $("table.l-table-nocheckbox", g.selectBox).append(tr); $("td", tr).hover(function () { $(this).addClass("l-over").siblings("td").removeClass("l-over"); }, function () { $(this).removeClass("l-over"); }); }); $('td:eq(' + g.select[0].selectedIndex + ')', g.selectBox).each(function () { if ($(this).hasClass("l-selected")) { g.selectBox.hide(); return; } $(".l-selected", g.selectBox).removeClass("l-selected"); $(this).addClass("l-selected"); if (g.select[0].selectedIndex != $(this).attr('index') && g.select[0].onchange) { g.select[0].selectedIndex = $(this).attr('index'); g.select[0].onchange(); } var newIndex = parseInt($(this).attr('index')); g.select[0].selectedIndex = newIndex; g.select.trigger("change"); g.selectBox.hide(); var value = $(this).attr("value"); var text = $(this).html(); if (p.render) { g.inputText.val(p.render(value, text)); } else { g.inputText.val(text); } }); g._addClickEven(); }, _setData: function (data) { this.setData(data); }, getRowIndex : function(value) { var g = this, p = this.options; if (!value) return -1; if (!g.data || !g.data.length) return -1; for (var i = 0; i < g.data.length; i++) { var val = g.data[i][p.valueField]; if (val == value) return i; } return -1; }, //获取行数据 getRow : function(value) { var g = this, p = this.options; if (!value) return null; if (!g.data || !g.data.length) return null; for (var i = 0; i < g.data.length; i++) { var val = g.data[i][p.valueField]; if (val == value) return g.data[i]; } return null; }, setData: function (data) { var g = this, p = this.options; if (g.select) return; if (p.selectBoxRender) { p.selectBoxRender.call(g, { selectBox: g.selectBox, data : data }); return; } if (!data || !data.length) data = []; if (g.data != data) g.data = data; g.data = $.isFunction(g.data) ? g.data() : g.data; this.clearContent(); if (p.columns) { g.selectBox.table.headrow = $(""); g.selectBox.table.append(g.selectBox.table.headrow); g.selectBox.table.addClass("l-box-select-grid"); for (var j = 0; j < p.columns.length; j++) { var headrow = $("" + p.columns[j].header + ""); if (p.columns[j].width) { headrow.width(p.columns[j].width); } g.selectBox.table.headrow.append(headrow); } } var out = []; if (p.emptyText) { g.emptyRow = {}; g.emptyRow[p.textField] = p.emptyText; g.emptyRow[p.valueField] = p.emptyValue != undefined ? p.emptyValue : ""; data.splice(0, 0, g.emptyRow); } for (var i = 0; i < data.length; i++) { var val = data[i][p.valueField]; var txt = data[i][p.textField]; var isRowReadOnly = $.isFunction(p.isRowReadOnly) ? p.isRowReadOnly(data[i]) : false; if (!p.columns) { out.push(""); if (p.isShowCheckBox) { out.push(""); } var itemHtml = txt; if (p.renderItem) { itemHtml = p.renderItem.call(g, { data: data[i], value: val, text: txt, key: g.inputText.val() }); } else if (p.autocomplete && p.highLight) { itemHtml = g._highLight(txt, g.inputText.val()); } else { itemHtml = "" + itemHtml + ""; } out.push("" + itemHtml + ""); } else { out.push(""); out.push(""); for (var j = 0; j < p.columns.length; j++) { var columnname = p.columns[j].name; out.push("" + data[i][columnname] + ""); } out.push(''); } } if (!p.columns) { if (p.isShowCheckBox) { $("table.l-table-checkbox", g.selectBox).append(out.join('')); } else { $("table.l-table-nocheckbox", g.selectBox).append(out.join('')); } } else { g.selectBox.table.append(out.join('')); } if (p.addRowButton && p.addRowButtonClick && !g.addRowButton) { g.addRowButton = $('
'); g.addRowButton.find(".link").append(p.addRowButton).click(p.addRowButtonClick); g.selectBoxInner.after(g.addRowButton); } g.set('selectBoxHeight', p.selectBoxHeight); //自定义复选框支持 if (p.isShowCheckBox && $.fn.ligerCheckBox) { $("table input:checkbox", g.selectBox).ligerCheckBox(); } $(".l-table-checkbox input:checkbox", g.selectBox).change(function () { if (this.checked && g.hasBind('beforeSelect')) { var parentTD = null; if ($(this).parent().get(0).tagName.toLowerCase() == "div") { parentTD = $(this).parent().parent(); } else { parentTD = $(this).parent(); } if (parentTD != null && g.trigger('beforeSelect', [parentTD.attr("value"), parentTD.attr("text")]) == false) { g.selectBox.slideToggle("fast"); return false; } } if (!p.isMultiSelect) { if (this.checked) { $("input:checked", g.selectBox).not(this).each(function () { this.checked = false; $(".l-checkbox-checked", $(this).parent()).removeClass("l-checkbox-checked"); }); g.selectBox.slideToggle("fast"); } } g._checkboxUpdateValue(); }); $("table.l-table-nocheckbox td", g.selectBox).hover(function () { if (!$(this).parent().hasClass("rowreadonly")) { $(this).addClass("l-over"); } }, function () { $(this).removeClass("l-over"); }); g._addClickEven(); //选择项初始化 if (!p.autocomplete) { g.updateStyle(); } g.trigger('afterShowData', [data]); }, //树 setTree: function (tree) { var g = this, p = this.options; this.clearContent(); g.selectBox.table.remove(); if (tree.checkbox != false) { tree.onCheck = function () { var nodes = g.treeManager.getChecked(); var value = []; var text = []; $(nodes).each(function (i, node) { if (p.treeLeafOnly && node.data.children) return; value.push(node.data[p.valueField]); text.push(node.data[p.textField]); }); g._changeValue(value.join(p.split), text.join(p.split), true); }; } else { tree.onSelect = function (node) { if (g.trigger('BeforeSelect',[node]) == false) return; if (p.treeLeafOnly && node.data.children) return; var value = node.data[p.valueField]; var text = node.data[p.textField]; g._changeValue(value, text,true); g.selectBox.hide(); }; tree.onCancelSelect = function (node) { g._changeValue("", "", true); }; } tree.onAfterAppend = function (domnode, nodedata) { if (!g.treeManager) return; var value = null; if (p.initValue) value = p.initValue; else if (g.valueField.val() != "") value = g.valueField.val(); g.selectValueByTree(value); }; g.tree = $(""); $("div:first", g.selectBox).append(g.tree); //新增下拉框中获取树对象的接口 g.innerTree = g.tree.ligerTree(tree); g.treeManager = g.tree.ligerGetTreeManager(); }, //新增下拉框中获取树对象的接口 getTree: function () { return this.innerTree; }, selectValueByTree: function (value) { var g = this, p = this.options; if (value != null) { var text = ""; var valuelist = value.toString().split(p.split); $(valuelist).each(function (i, item) { g.treeManager.selectNode(item.toString(),false); text += g.treeManager.getTextByID(item); if (i < valuelist.length - 1) text += p.split; }); g._changeValue(value, text, p.initIsTriggerEvent); } }, //表格 setGrid: function (grid) { var g = this, p = this.options; if (g.grid) return; p.hideOnLoseFocus = p.hideGridOnLoseFocus ? true : false; this.clearContent(); g.selectBox.addClass("l-box-select-lookup"); g.selectBox.table.remove(); var panel = $("div:first", g.selectBox); var conditionPanel = $("
").appendTo(panel); var gridPanel = $("
").appendTo(panel); g.conditionPanel = conditionPanel; //搜索框 if (p.condition) { var conditionParm = $.extend({ labelWidth: 60, space: 20, width: p.selectBoxWidth }, p.condition); g.condition = conditionPanel.ligerForm(conditionParm); } else { conditionPanel.remove(); } //列表 grid = $.extend({ columnWidth: 120, alternatingRow: false, frozen: true, rownumbers: true, allowUnSelectRow: true }, grid, { width: "100%", height: g.getGridHeight(), inWindow: false, parms: p.parms, isChecked: function (rowdata) { var value = g.getValue(); if (!value) return false; if (!p.valueField || !rowdata[p.valueField]) return false; return $.inArray(rowdata[p.valueField].toString(), value.split(p.split)) != -1; } }); g.grid = g.gridManager = gridPanel.ligerGrid(grid); g.grid.bind('afterShowData', function () { g.updateSelectBoxPosition(); }); var selecteds = [], onGridSelect = function () { var value = [], text = []; $(selecteds).each(function (i, rowdata) { value.push(rowdata[p.valueField]); text.push(rowdata[p.textField]); }); if (grid.checkbox) g.selected = selecteds; else if (selecteds.length) g.selected = selecteds[0]; else g.selected = null; g._changeValue(value.join(p.split), text.join(p.split),true); g.trigger('gridSelect', { value: value.join(p.split), text: text.join(p.split), data: selecteds }); }, removeSelected = function (rowdata) { for (var i = selecteds.length - 1; i >= 0; i--) { if (selecteds[i][p.valueField] == rowdata[p.valueField]) { selecteds.splice(i, 1); } } }, addSelected = function (rowdata) { for (var i = selecteds.length - 1; i >= 0; i--) { if (selecteds[i][p.valueField] == rowdata[p.valueField]) { return; } } selecteds.push(rowdata); }; if (grid.checkbox) { var onCheckRow = function (checked, rowdata) { checked && addSelected(rowdata); !checked && removeSelected(rowdata); }; g.grid.bind('CheckAllRow', function (checked) { $(g.grid.rows).each(function (i, rowdata) { onCheckRow(checked, rowdata); }); onGridSelect(); }); g.grid.bind('CheckRow', function (checked, rowdata) { onCheckRow(checked, rowdata); onGridSelect(); }); } else { g.grid.bind('SelectRow', function (rowdata) { selecteds = [rowdata]; onGridSelect(); g._toggleSelectBox(true); }); g.grid.bind('UnSelectRow', function () { selecteds = []; onGridSelect(); }); } g.bind('show', function () { g.grid.refreshSize(); }); g.bind("clear", function () { selecteds = []; g.grid.selecteds = []; g.grid._showData(); }); if (p.condition) { var containerBtn1 = $('
  • '); var containerBtn2 = $('
  • '); $("ul:first", conditionPanel).append(containerBtn1).append(containerBtn2).after('
    '); $("div", containerBtn1).ligerButton({ text: p.Search, width: 40, click: function () { var rules = g.condition.toConditions(); if (p.conditionSearchClick) { p.conditionSearchClick({ grid: g.grid, rules: rules }); } else { if (g.grid.url) { g.grid.setParm(grid.conditionParmName || 'condition', $.ligerui.toJSON(rules)); g.grid.reload(); } else { g.grid.loadData($.ligerFilter.getFilterFunction(rules)); } } } }); $("div", containerBtn2).ligerButton({ text: '关闭', width: 40, click: function () { g.selectBox.hide(); } }); } g.grid.refreshSize(); }, getGridHeight: function (height) { var g = this, p = this.options; height = height || g.selectBox.height(); height -= g.conditionPanel.height(); return height; }, _getValue: function () { return $(this.valueField).val(); }, getValue: function () { //获取值 return this._getValue(); }, getSelected: function () { return this.selected; }, upFocus : function() { var g = this, p = this.options; var currentIndex = g.selectBox.table.find("td.l-over").attr("index"); if (currentIndex == undefined || currentIndex == "0") { return; } else { currentIndex = parseInt(currentIndex) - 1; } g.selectBox.table.find("td.l-over").removeClass("l-over"); g.selectBox.table.find("td[index=" + currentIndex + "]").addClass("l-over"); g._scrollAdjust(currentIndex); }, downFocus : function() { var g = this, p = this.options; var currentIndex = g.selectBox.table.find("td.l-over").attr("index"); if (currentIndex == g.data.length - 1) return; if (currentIndex == undefined) { currentIndex = 0; } else { currentIndex = parseInt(currentIndex) + 1; } g.selectBox.table.find("td.l-over").removeClass("l-over"); g.selectBox.table.find("td[index=" + currentIndex + "]").addClass("l-over"); g._scrollAdjust(currentIndex); }, _scrollAdjust:function(currentIndex) { var g = this, p = this.options; var boxHeight = $(".l-box-select-inner", g.selectBox).height(); var fullHeight = $(".l-box-select-inner table", g.selectBox).height(); if (fullHeight <= boxHeight) return; var pageSplit = parseInt(fullHeight / boxHeight) + ((fullHeight % boxHeight) ? 1 : 0);//分割成几屏 var itemHeight = fullHeight / g.data.length; //单位高度 //计算出位于第几屏 var pageCurrent = parseInt((currentIndex + 1) * itemHeight / boxHeight) + (((currentIndex + 1) * itemHeight % boxHeight) ? 1 : 0); $(".l-box-select-inner", g.selectBox).scrollTop((pageCurrent - 1) * boxHeight); }, getText: function () { return this.inputText.val(); }, setText: function (value) { this.inputText.val(value); }, updateStyle: function () { var g = this, p = this.options; p.initValue = g._getValue(); g._dataInit(); }, _dataInit: function () { var g = this, p = this.options; var value = null; if (p.initValue != null && p.initText != null) { g._changeValue(p.initValue, p.initText); } //根据值来初始化 if (p.initValue != null) { value = p.initValue; if (p.tree) { if (value) g.selectValueByTree(value); } else if (g.data) { var text = g.findTextByValue(value); g._changeValue(value, text); } } else if (g.valueField.val() != "") { value = g.valueField.val(); if (p.tree) { if (value) g.selectValueByTree(value); } else if (g.data) { var text = g.findTextByValue(value); g._changeValue(value, text); } } if (!p.isShowCheckBox) { $("table tr", g.selectBox).find("td:first").each(function () { if (value != null && value == $(this).attr("value")) { $(this).addClass("l-selected"); } else { $(this).removeClass("l-selected"); } }); } else { $(":checkbox", g.selectBox).each(function () { var parentTD = null; var checkbox = $(this); if (checkbox.parent().get(0).tagName.toLowerCase() == "div") { parentTD = checkbox.parent().parent(); } else { parentTD = checkbox.parent(); } if (parentTD == null) return; $(".l-checkbox", parentTD).removeClass("l-checkbox-checked"); checkbox[0].checked = false; var valuearr = (value || "").toString().split(p.split); $(valuearr).each(function (i, item) { if (value != null && item == parentTD.attr("value")) { $(".l-checkbox", parentTD).addClass("l-checkbox-checked"); checkbox[0].checked = true; } }); }); } }, //设置值到 文本框和隐藏域 //isSelectEvent:是否选择事件 _changeValue: function (newValue, newText,isSelectEvent) { var g = this, p = this.options; g.valueField.val(newValue); if (p && p.render) { g.inputText.val(p.render(newValue, newText)); } else { g.inputText.val(newText); } if (g.select) { $("option", g.select).each(function () { $(this).attr("selected", $(this).attr("value") == newValue); }); } g.selectedValue = newValue; g.selectedText = newText; g.inputText.trigger("change"); if (isSelectEvent && newText) { g.inputText.focus(); } var rowData = null; if (newValue && typeof(newValue) == "string" && newValue.indexOf(p.split) > -1) { rowData = []; var values = newValue.split(p.split); $(values).each(function (i, v) { rowData.push(g.getRow(v)); }); } else if(newValue) { rowData = g.getRow(newValue); } if (isSelectEvent) { g.trigger('selected', [newValue, newText, rowData]); } }, //更新选中的值(复选框) _checkboxUpdateValue: function () { var g = this, p = this.options; var valueStr = ""; var textStr = ""; $("input:checked", g.selectBox).each(function () { var parentTD = null; if ($(this).parent().get(0).tagName.toLowerCase() == "div") { parentTD = $(this).parent().parent(); } else { parentTD = $(this).parent(); } if (!parentTD) return; valueStr += parentTD.attr("value") + p.split; textStr += parentTD.attr("text") + p.split; }); if (valueStr.length > 0) valueStr = valueStr.substr(0, valueStr.length - 1); if (textStr.length > 0) textStr = textStr.substr(0, textStr.length - 1); g._changeValue(valueStr, textStr); }, loadDetail : function(value,callback) { var g = this, p = this.options; var parms = $.isFunction(p.detailParms) ? p.detailParms.call(g) : p.detailParms; parms[p.detailPostIdField || "id"] = value; if (p.ajaxContentType == "application/json") { parms = liger.toJSON(parms); } var ajaxOp = { type: p.ajaxType, url: p.detailUrl, data: parms, cache: true, dataType: 'json', beforeSend: p.ajaxBeforeSend, complete: p.ajaxComplete, success: function (result) { var data = $.isFunction(p.detailDataGetter) ? p.detailDataGetter(result) : result; data = p.detailDataParmName ? data[p.detailDataParmName] : data; callback && callback(data); } }; if (p.ajaxContentType) { ajaxOp.contentType = p.ajaxContentType; } $.ajax(ajaxOp); }, enabledLoadDetail : function() { var g = this, p = this.options; return p.detailUrl && p.detailEnabled ? true : false; }, _addClickEven: function () { var g = this, p = this.options; //选项点击 $(".l-table-nocheckbox td", g.selectBox).click(function () { var jcell = $(this); var value = jcell.attr("value"); var index = parseInt($(this).attr('index')); var data = g.data[index]; var text = jcell.attr("text"); var isRowReadonly = jcell.parent().hasClass("rowreadonly"); if (isRowReadonly) return; if (g.enabledLoadDetail()) { g.loadDetail(value,function (rd) { g.data[index] = data = rd; onItemClick(); }); } else { onItemClick(); } function onItemClick() { if (g.hasBind('beforeSelect') && g.trigger('beforeSelect', [value, text, data]) == false) { if (p.slide) g.selectBox.slideToggle("fast"); else g.selectBox.hide(); return false; } g.selected = data; if ($(this).hasClass("l-selected")) { if (p.slide) g.selectBox.slideToggle("fast"); else g.selectBox.hide(); return; } $(".l-selected", g.selectBox).removeClass("l-selected"); jcell.addClass("l-selected"); if (g.select) { if (g.select[0].selectedIndex != index) { g.select[0].selectedIndex = index; g.select.trigger("change"); } } if (p.slide) { g.boxToggling = true; g.selectBox.hide("fast", function () { g.boxToggling = false; }) } else g.selectBox.hide(); g.lastInputText = text; g._changeValue(value, text, true); } }); }, updateSelectBoxPosition: function () { var g = this, p = this.options; if (p && p.absolute) { var contentHeight = $(document).height(); if (p.alwayShowInTop || Number(g.wrapper.offset().top + 1 + g.wrapper.outerHeight() + g.selectBox.height()) > contentHeight && contentHeight > Number(g.selectBox.height() + 1)) { //若下拉框大小超过当前document下边框,且当前document上留白大于下拉内容高度,下拉内容向上展现 g.selectBox.css({ left: g.wrapper.offset().left, top: g.wrapper.offset().top - 1 - g.selectBox.height() + (p.selectBoxPosYDiff || 0) }); } else { g.selectBox.css({ left: g.wrapper.offset().left, top: g.wrapper.offset().top + 1 + g.wrapper.outerHeight() + (p.selectBoxPosYDiff || 0) }); } if (p.alwayShowInDown) { g.selectBox.css({ left: g.wrapper.offset().left, top: g.wrapper.offset().top + 1 + g.wrapper.outerHeight() }); } } else { var topheight = g.wrapper.offset().top - $(window).scrollTop(); var selfheight = g.selectBox.height() + textHeight + 4; if (topheight + selfheight > $(window).height() && topheight > selfheight) { g.selectBox.css("marginTop", -1 * (g.selectBox.height() + textHeight + 5) + (p.selectBoxPosYDiff || 0)); } } }, _toggleSelectBox: function (isHide) { var g = this, p = this.options; if (!g || !p) return; //避免同一界面弹出多个菜单的问题 var managers = $.ligerui.find($.ligerui.controls.ComboBox); for (var i = 0, l = managers.length; i < l; i++) { var o = managers[i]; if (o.id != g.id) { if (o.selectBox.is(":visible") != null && o.selectBox.is(":visible")) { o.selectBox.hide(); } } } managers = $.ligerui.find($.ligerui.controls.DateEditor); for (var i = 0, l = managers.length; i < l; i++) { var o = managers[i]; if (o.id != g.id) { if (o.dateeditor.is(":visible") != null && o.dateeditor.is(":visible")) { o.dateeditor.hide(); } } } var textHeight = g.wrapper.height(); g.boxToggling = true; if (isHide) { if (p.slide) { g.selectBox.slideToggle('fast', function () { g.boxToggling = false; }); } else { g.selectBox.hide(); g.boxToggling = false; } } else { g.updateSelectBoxPosition(); if (p.slide) { g.selectBox.slideToggle('fast', function () { g.boxToggling = false; if (!p.isShowCheckBox && $('td.l-selected', g.selectBox).length > 0) { var offSet = ($('td.l-selected', g.selectBox).offset().top - g.selectBox.offset().top); $(".l-box-select-inner", g.selectBox).animate({ scrollTop: offSet }); } }); } else { g._selectBoxShow(); g.boxToggling = false; if (!g.tree && !g.grid && !p.isShowCheckBox && $('td.l-selected', g.selectBox).length > 0) { var offSet = ($('td.l-selected', g.selectBox).offset().top - g.selectBox.offset().top); $(".l-box-select-inner", g.selectBox).animate({ scrollTop: offSet }); } } } g.isShowed = g.selectBox.is(":visible"); g.trigger('toggle', [isHide]); g.trigger(isHide ? 'hide' : 'show'); }, _selectBoxShow : function() { var g = this, p = this.options; if (!p.grid && !p.tree) { if (g.selectBox.table.find("tr").length || (p.selectBoxRender && g.selectBoxInner.html())) { g.selectBox.show(); } else { g.selectBox.hide(); } return; } g.selectBox.show(); return; }, _highLight: function (str, key) { if (!str) return str; var index = str.indexOf(key); if (index == -1) return str; return str.substring(0, index) + "" + key + "" + str.substring(key.length + index); }, _setAutocomplete: function (value) { var g = this, p = this.options; if (!value) return; g.inputText.removeAttr("readonly"); g.lastInputText = g.inputText.val(); g.inputText.keyup(function (event) { if (event.keyCode == 38 || event.keyCode == 40 || event.keyCode == 13) //up 、down、enter { return; } if (this._acto) clearTimeout(this._acto); this._acto = setTimeout(function () { if (g.lastInputText == g.inputText.val()) return; p.initValue = ""; g.valueField.val(""); var currentKey = g.inputText.val(); if (currentKey) currentKey = currentKey.replace(/(^\s*)|(\s*$)/g, ""); if ($.isFunction(value)) { value.call(g, { key: currentKey, show: function () { g._selectBoxShow(); } }); return; } if (!p.autocompleteAllowEmpty && !currentKey) { g.clear(); g.selectBox.hide(); return; } if (p.url) { g.setParm('key', currentKey); g.setUrl(p.url, function () { g._selectBoxShow(); }); } else if (p.grid) { g.grid.setParm('key', currentKey); g.grid.reload(); } g.lastInputText = g.inputText.val(); this._acto = null; }, 300); }); } }); $.ligerui.controls.ComboBox.prototype.setValue = $.ligerui.controls.ComboBox.prototype.selectValue; //设置文本框和隐藏控件的值 $.ligerui.controls.ComboBox.prototype.setInputValue = $.ligerui.controls.ComboBox.prototype._changeValue; //Key Init (function () { $(document).unbind('keydown.ligercombobox'); $(document).bind('keydown.ligercombobox',function (event) { function down() { if (!combobox.selectBox.is(":visible")) { combobox.selectBox.show(); } combobox.downFocus(); } function toSelect() { combobox._changeValue(value, curTd.attr("text"), true); combobox.selectBox.hide(); combobox.trigger('textBoxKeyEnter', [{ element: curTd.get(0) }]); } var curInput = $("input:focus"); if (curInput.length && curInput.attr("data-comboboxid")) { var combobox = liger.get(curInput.attr("data-comboboxid")); if (!combobox) return; if (!combobox.get("keySupport")) return; if (event.keyCode == 38) //up { combobox.upFocus(); } else if (event.keyCode == 40) //down { if (combobox.hasBind('textBoxKeyDown')) { combobox.trigger('textBoxKeyDown', [ { callback: function () { down(); } }]); } else { down(); } } else if (event.keyCode == 13) //enter { if (!combobox.selectBox.is(":visible")) return; var curTd = combobox.selectBox.table.find("td.l-over"); if (curTd.length) { var value = curTd.attr("value"); if (combobox.enabledLoadDetail()) { combobox.loadDetail(value, function (data) { var index = combobox.getRowIndex(value); if (index == -1) return; combobox.data = combobox.data || []; combobox.data[index] = combobox.selected = data; toSelect(); }); } else { toSelect(); } } } } }); })(); })(jQuery);/** * jQuery ligerUI 1.3.2 * * http://ligerui.com * * Author daomi 2015 [ gd_star@163.com ] * */ (function ($) { $.fn.ligerDateEditor = function () { return $.ligerui.run.call(this, "ligerDateEditor", arguments); }; $.fn.ligerGetDateEditorManager = function () { return $.ligerui.run.call(this, "ligerGetDateEditorManager", arguments); }; $.ligerDefaults.DateEditor = { format: "yyyy-MM-dd hh:mm", width : null, showTime: false, onChangeDate: false, absolute: true, //选择框是否在附加到body,并绝对定位 cancelable: true, //可取消选择 readonly: false //是否只读 }; $.ligerDefaults.DateEditorString = { dayMessage: ["日", "一", "二", "三", "四", "五", "六"], monthMessage: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"], todayMessage: "今天", closeMessage: "关闭" }; $.ligerMethos.DateEditor = {}; $.ligerui.controls.DateEditor = function (element, options) { $.ligerui.controls.DateEditor.base.constructor.call(this, element, options); }; $.ligerui.controls.DateEditor.ligerExtend($.ligerui.controls.Input, { __getType: function () { return 'DateEditor'; }, __idPrev: function () { return 'DateEditor'; }, _extendMethods: function () { return $.ligerMethos.DateEditor; }, _render: function () { var g = this, p = this.options; if (!p.showTime && p.format.indexOf(" hh:mm") > -1) p.format = p.format.replace(" hh:mm", ""); if (this.element.tagName.toLowerCase() != "input" || this.element.type != "text") return; g.inputText = $(this.element); if (!g.inputText.hasClass("l-text-field")) g.inputText.addClass("l-text-field"); g.link = $('
    '); g.text = g.inputText.wrap('
    ').parent(); g.text.append('
    '); g.text.append(g.link); //添加个包裹, g.textwrapper = g.text.wrap('
    ').parent(); var dateeditorHTML = ""; dateeditorHTML += ""; g.dateeditor = $(dateeditorHTML); if (p.absolute) g.dateeditor.appendTo('body').addClass("l-box-dateeditor-absolute"); else g.textwrapper.append(g.dateeditor); g.header = $(".l-box-dateeditor-header", g.dateeditor); g.body = $(".l-box-dateeditor-body", g.dateeditor); g.toolbar = $(".l-box-dateeditor-toolbar", g.dateeditor); g.body.thead = $("thead", g.body); g.body.tbody = $("tbody", g.body); g.body.monthselector = $(".l-box-dateeditor-monthselector", g.body); g.body.yearselector = $(".l-box-dateeditor-yearselector", g.body); g.body.hourselector = $(".l-box-dateeditor-hourselector", g.body); g.body.minuteselector = $(".l-box-dateeditor-minuteselector", g.body); g.toolbar.time = $(".l-box-dateeditor-time", g.toolbar); g.toolbar.time.hour = $(""); g.toolbar.time.minute = $(""); g.buttons = { btnPrevYear: $(".l-box-dateeditor-header-prevyear", g.header), btnNextYear: $(".l-box-dateeditor-header-nextyear", g.header), btnPrevMonth: $(".l-box-dateeditor-header-prevmonth", g.header), btnNextMonth: $(".l-box-dateeditor-header-nextmonth", g.header), btnYear: $(".l-box-dateeditor-header-year", g.header), btnMonth: $(".l-box-dateeditor-header-month", g.header), btnToday: $(".l-button-today", g.toolbar), btnClose: $(".l-button-close", g.toolbar) }; var nowDate = new Date(); g.now = { year: nowDate.getFullYear(), month: nowDate.getMonth() + 1, //注意这里 day: nowDate.getDay(), date: nowDate.getDate(), hour: nowDate.getHours(), minute: nowDate.getMinutes() }; //当前的时间 g.currentDate = { year: nowDate.getFullYear(), month: nowDate.getMonth() + 1, day: nowDate.getDay(), date: nowDate.getDate(), hour: nowDate.getHours(), minute: nowDate.getMinutes() }; //选择的时间 g.selectedDate = null; //使用的时间 g.usedDate = null; //初始化数据 //设置周日至周六 $("td", g.body.thead).each(function (i, td) { $(td).html(p.dayMessage[i]); }); //设置一月到十一二月 $("li", g.body.monthselector).each(function (i, li) { $(li).html(p.monthMessage[i]); }); //设置按钮 g.buttons.btnToday.html(p.todayMessage); g.buttons.btnClose.html(p.closeMessage); //设置时间 if (p.showTime) { g.toolbar.time.show(); g.toolbar.time.append(g.toolbar.time.hour).append(":").append(g.toolbar.time.minute); $("li", g.body.hourselector).each(function (i, item) { var str = i; if (i < 10) str = "0" + i.toString(); $(this).html(str); }); $("li", g.body.minuteselector).each(function (i, item) { var str = i; if (i < 10) str = "0" + i.toString(); $(this).html(str); }); } //设置主体 g.bulidContent(); //初始化 //初始值 if (p.initValue) { g.inputText.val(p.initValue); } if (g.inputText.val() != "") { g.onTextChange(); } /************** **bulid evens** *************/ g.dateeditor.hover(null, function (e) { if (g.dateeditor.is(":visible") && !g.editorToggling) { g.toggleDateEditor(true); } }); //toggle even g.link.hover(function () { if (p.disabled) return; this.className = "l-trigger-hover"; }, function () { if (p.disabled) return; this.className = "l-trigger"; }).mousedown(function () { if (p.disabled) return; this.className = "l-trigger-pressed"; }).mouseup(function () { if (p.disabled) return; this.className = "l-trigger-hover"; }).click(function () { if (p.disabled) return; g.bulidContent(); g.toggleDateEditor(g.dateeditor.is(":visible")); }); //不可用属性时处理 if (p.disabled) { g.inputText.attr("readonly", "readonly"); g.text.addClass('l-text-disabled'); } g.buttons.btnClose.click(function () { g.toggleDateEditor(true); }); //日期 点击 $("td", g.body.tbody).hover(function () { if ($(this).hasClass("l-box-dateeditor-today")) return; $(this).addClass("l-box-dateeditor-over"); }, function () { $(this).removeClass("l-box-dateeditor-over"); }).click(function () { $(".l-box-dateeditor-selected", g.body.tbody).removeClass("l-box-dateeditor-selected"); if (!$(this).hasClass("l-box-dateeditor-today")) $(this).addClass("l-box-dateeditor-selected"); g.currentDate.date = parseInt($(this).html()); g.currentDate.day = new Date(g.currentDate.year, g.currentDate.month - 1, 1).getDay(); if ($(this).hasClass("l-box-dateeditor-out")) { if ($("tr", g.body.tbody).index($(this).parent()) == 0) { if (--g.currentDate.month == 0) { g.currentDate.month = 12; g.currentDate.year--; } } else { if (++g.currentDate.month == 13) { g.currentDate.month = 1; g.currentDate.year++; } } } g.selectedDate = { year: g.currentDate.year, month: g.currentDate.month, date: g.currentDate.date }; g.showDate(); g.editorToggling = true; g.dateeditor.slideToggle('fast', function () { g.editorToggling = false; }); }); $(".l-box-dateeditor-header-btn", g.header).hover(function () { $(this).addClass("l-box-dateeditor-header-btn-over"); }, function () { $(this).removeClass("l-box-dateeditor-header-btn-over"); }); //选择年份 g.buttons.btnYear.click(function () { //build year list if (!g.body.yearselector.is(":visible")) { $("li", g.body.yearselector).each(function (i, item) { var currentYear = g.currentDate.year + (i - 4); if (currentYear == g.currentDate.year) $(this).addClass("l-selected"); else $(this).removeClass("l-selected"); $(this).html(currentYear); }); } g.body.yearselector.slideToggle(); }); g.body.yearselector.hover(function () { }, function () { $(this).slideUp(); }); $("li", g.body.yearselector).click(function () { g.currentDate.year = parseInt($(this).html()); g.body.yearselector.slideToggle(); g.bulidContent(); }); //select month g.buttons.btnMonth.click(function () { $("li", g.body.monthselector).each(function (i, item) { //add selected style if (g.currentDate.month == i + 1) $(this).addClass("l-selected"); else $(this).removeClass("l-selected"); }); g.body.monthselector.slideToggle(); }); g.body.monthselector.hover(function () { }, function () { $(this).slideUp("fast"); }); $("li", g.body.monthselector).click(function () { var index = $("li", g.body.monthselector).index(this); g.currentDate.month = index + 1; g.body.monthselector.slideToggle(); g.bulidContent(); }); //选择小时 g.toolbar.time.hour.click(function () { $("li", g.body.hourselector).each(function (i, item) { //add selected style if (g.currentDate.hour == i) $(this).addClass("l-selected"); else $(this).removeClass("l-selected"); }); g.body.hourselector.slideToggle(); }); g.body.hourselector.hover(function () { }, function () { $(this).slideUp("fast"); }); $("li", g.body.hourselector).click(function () { var index = $("li", g.body.hourselector).index(this); g.currentDate.hour = index; g.body.hourselector.slideToggle(); g.bulidContent(); g.showDate(); }); //选择分钟 g.toolbar.time.minute.click(function () { $("li", g.body.minuteselector).each(function (i, item) { //add selected style if (g.currentDate.minute == i) $(this).addClass("l-selected"); else $(this).removeClass("l-selected"); }); g.body.minuteselector.slideToggle("fast", function () { var index = $("li", this).index($('li.l-selected', this)); if (index > 29) { var offSet = ($('li.l-selected', this).offset().top - $(this).offset().top); $(this).animate({ scrollTop: offSet }); } }); }); g.body.minuteselector.hover(function () { }, function () { $(this).slideUp("fast"); }); $("li", g.body.minuteselector).click(function () { var index = $("li", g.body.minuteselector).index(this); g.currentDate.minute = index; g.body.minuteselector.slideToggle("fast"); g.bulidContent(); g.showDate(); }); //上个月 g.buttons.btnPrevMonth.click(function () { if (--g.currentDate.month == 0) { g.currentDate.month = 12; g.currentDate.year--; } g.bulidContent(); }); //下个月 g.buttons.btnNextMonth.click(function () { if (++g.currentDate.month == 13) { g.currentDate.month = 1; g.currentDate.year++; } g.bulidContent(); }); //上一年 g.buttons.btnPrevYear.click(function () { g.currentDate.year--; g.bulidContent(); }); //下一年 g.buttons.btnNextYear.click(function () { g.currentDate.year++; g.bulidContent(); }); //今天 g.buttons.btnToday.click(function () { g.currentDate = { year: g.now.year, month: g.now.month, day: g.now.day, date: g.now.date }; g.selectedDate = { year: g.now.year, month: g.now.month, day: g.now.day, date: g.now.date }; g.showDate(); g.dateeditor.slideToggle("fast"); }); //文本框 g.inputText.change(function () { g.onTextChange(); }).blur(function () { g.text.removeClass("l-text-focus"); }).focus(function () { g.text.addClass("l-text-focus"); }); g.text.hover(function () { g.text.addClass("l-text-over"); }, function () { g.text.removeClass("l-text-over"); }); //LEABEL 支持 if (p.label) { g.labelwrapper = g.textwrapper.wrap('
    ').parent(); g.labelwrapper.prepend('
    ' + p.label + ': 
    '); g.textwrapper.css('float', 'left'); if (!p.labelWidth) { p.labelWidth = $('.l-text-label', g.labelwrapper).outerWidth(); } else { $('.l-text-label', g.labelwrapper).outerWidth(p.labelWidth); } $('.l-text-label', g.labelwrapper).width(p.labelWidth); $('.l-text-label', g.labelwrapper).height(g.text.height()); g.labelwrapper.append('
    '); if (p.labelAlign) { $('.l-text-label', g.labelwrapper).css('text-align', p.labelAlign); } g.textwrapper.css({ display: 'inline' }); g.labelwrapper.width(g.text.outerWidth() + p.labelWidth + 2); } g.set(p); //增加鼠标在日期控件外点击隐藏日期选择框功能 $(document).bind("click.dateeditor", function (e) { if (g.dateeditor.is(":visible") && $((e.target || e.srcElement)).closest( ".l-box-dateeditor, .l-text-date" ).length == 0) { g.toggleDateEditor(true); } }); }, destroy: function () { if (this.textwrapper) this.textwrapper.remove(); if (this.dateeditor) this.dateeditor.remove(); this.options = null; $.ligerui.remove(this); }, bulidContent: function () { var g = this, p = this.options; //当前月第一天星期 var thismonthFirstDay = new Date(g.currentDate.year, g.currentDate.month - 1, 1).getDay(); //当前月天数 var nextMonth = g.currentDate.month; var nextYear = g.currentDate.year; if (++nextMonth == 13) { nextMonth = 1; nextYear++; } var monthDayNum = new Date(nextYear, nextMonth - 1, 0).getDate(); //当前上个月天数 var prevMonthDayNum = new Date(g.currentDate.year, g.currentDate.month - 1, 0).getDate(); g.buttons.btnMonth.html(p.monthMessage[g.currentDate.month - 1]); g.buttons.btnYear.html(g.currentDate.year); g.toolbar.time.hour.html(g.currentDate.hour); g.toolbar.time.minute.html(g.currentDate.minute); if (g.toolbar.time.hour.html().length == 1) g.toolbar.time.hour.html("0" + g.toolbar.time.hour.html()); if (g.toolbar.time.minute.html().length == 1) g.toolbar.time.minute.html("0" + g.toolbar.time.minute.html()); $("td", this.body.tbody).each(function () { this.className = "" }); $("tr", this.body.tbody).each(function (i, tr) { $("td", tr).each(function (j, td) { var id = i * 7 + (j - thismonthFirstDay); var showDay = id + 1; if (g.selectedDate && g.currentDate.year == g.selectedDate.year && g.currentDate.month == g.selectedDate.month && id + 1 == g.selectedDate.date) { if (j == 0 || j == 6) { $(td).addClass("l-box-dateeditor-holiday") } $(td).addClass("l-box-dateeditor-selected"); $(td).siblings().removeClass("l-box-dateeditor-selected"); } else if (g.currentDate.year == g.now.year && g.currentDate.month == g.now.month && id + 1 == g.now.date) { if (j == 0 || j == 6) { $(td).addClass("l-box-dateeditor-holiday") } $(td).addClass("l-box-dateeditor-today"); } else if (id < 0) { showDay = prevMonthDayNum + showDay; $(td).addClass("l-box-dateeditor-out") .removeClass("l-box-dateeditor-selected"); } else if (id > monthDayNum - 1) { showDay = showDay - monthDayNum; $(td).addClass("l-box-dateeditor-out") .removeClass("l-box-dateeditor-selected"); } else if (j == 0 || j == 6) { $(td).addClass("l-box-dateeditor-holiday") .removeClass("l-box-dateeditor-selected"); } else { td.className = ""; } $(td).html(showDay); }); }); }, updateSelectBoxPosition: function () { var g = this, p = this.options; if (p.absolute) { var contentHeight = $(document).height(); if (Number(g.text.offset().top + 1 + g.text.outerHeight() + g.dateeditor.height()) > contentHeight && contentHeight > Number(g.dateeditor.height() + 1)) { //若下拉框大小超过当前document下边框,且当前document上留白大于下拉内容高度,下拉内容向上展现 g.dateeditor.css({ left: g.text.offset().left, top: g.text.offset().top - 1 - g.dateeditor.height() }); } else { g.dateeditor.css({ left: g.text.offset().left, top: g.text.offset().top + 1 + g.text.outerHeight() }); } } else { if (g.text.offset().top + 4 > g.dateeditor.height() && g.text.offset().top + g.dateeditor.height() + textHeight + 4 - $(window).scrollTop() > $(window).height()) { g.dateeditor.css("marginTop", -1 * (g.dateeditor.height() + textHeight + 5)); g.showOnTop = true; } else { g.showOnTop = false; } } }, toggleDateEditor: function (isHide) { var g = this, p = this.options; //避免同一界面弹出过个菜单的问题 var managers = $.ligerui.find($.ligerui.controls.ComboBox); for ( var i = 0, l = managers.length; i < l; i++) { var o = managers[i]; if(o.id!=g.id){ if(o.selectBox.is(":visible")!=null&&o.selectBox.is(":visible")){ o.selectBox.hide(); } } } managers = $.ligerui.find($.ligerui.controls.DateEditor); for ( var i = 0, l = managers.length; i < l; i++) { var o = managers[i]; if(o.id!=g.id){ if(o.dateeditor.is(":visible")!=null&&o.dateeditor.is(":visible")){ o.dateeditor.hide(); } } } var textHeight = g.text.height(); g.editorToggling = true; if (isHide) { g.dateeditor.hide('fast', function () { g.editorToggling = false; }); } else { g.updateSelectBoxPosition(); g.dateeditor.slideDown('fast', function () { g.editorToggling = false; }); } }, showDate: function () { var g = this, p = this.options; if (!this.currentDate) return; this.currentDate.hour = parseInt(g.toolbar.time.hour.html(), 10); this.currentDate.minute = parseInt(g.toolbar.time.minute.html(), 10); var dateStr = this.currentDate.year + '/' + this.currentDate.month + '/' + this.currentDate.date + ' ' + this.currentDate.hour + ':' + this.currentDate.minute; var myDate = new Date(dateStr); dateStr = g.getFormatDate(myDate); this.inputText.val(dateStr); this.onTextChange(); }, isDateTime: function (dateStr) { var g = this, p = this.options; var r = dateStr.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); if (r == null) return false; var d = new Date(r[1], r[3] - 1, r[4]); if (d == "NaN") return false; return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4]); }, isLongDateTime: function (dateStr) { var g = this, p = this.options; var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2})$/; var r = dateStr.match(reg); if (r == null) return false; var d = new Date(r[1], r[3] - 1, r[4], r[5], r[6]); if (d == "NaN") return false; return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4] && d.getHours() == r[5] && d.getMinutes() == r[6]); }, getFormatDate: function (date) { if (date === null || date == "NaN") return null; var g = this, p = this.options; var format = p.format; var o = { "M+": date.getMonth() + 1, "d+": date.getDate(), "h+": date.getHours(), "m+": date.getMinutes(), "s+": date.getSeconds(), "q+": Math.floor((date.getMonth() + 3) / 3), "S": date.getMilliseconds() } if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (date.getFullYear() + "") .substr(4 - RegExp.$1.length)); } for (var k in o) { if (new RegExp("(" + k + ")").test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); } } return format; }, clear: function () { this.set('value', ''); this.usedDate = null; }, //取消选择 _setCancelable: function (value) { var g = this, p = this.options; if (!value && g.unselect) { g.unselect.remove(); g.unselect = null; } if (!value && !g.unselect) return; g.unselect = $('
    ').hide(); g.text.hover(function () { g.unselect.show(); }, function () { g.unselect.hide(); }) if (!p.disabled && p.cancelable) { g.text.append(g.unselect); } g.unselect.hover(function () { this.className = "l-trigger-hover l-trigger-cancel"; }, function () { this.className = "l-trigger l-trigger-cancel"; }).click(function () { if (p.readonly) return; g.clear(); }); }, //恢复 _rever: function () { var g = this, p = this.options; if (!g.usedDate) { g.inputText.val(""); } else { g.inputText.val(g.getFormatDate(g.usedDate)); } }, _getMatch: function (format) { var r = [-1, -1, -1, -1, -1, -1], groupIndex = 0, regStr = "^", str = format || this.options.format; while (true) { var tmp_r = str.match(/^yyyy|MM|dd|mm|hh|HH|ss|-|\/|:|\s/); if (tmp_r) { var c = tmp_r[0].charAt(0); var mathLength = tmp_r[0].length; var index = 'yMdhms'.indexOf(c); if (index != -1) { r[index] = groupIndex + 1; regStr += "(\\d{1," + mathLength + "})"; } else { var st = c == ' ' ? '\\s' : c; regStr += "(" + st + ")"; } groupIndex++; if (mathLength == str.length) { regStr += "$"; break; } str = str.substring(mathLength); } else { return null; } } return { reg: new RegExp(regStr), position: r }; }, _bulidDate: function (dateStr) { var g = this, p = this.options; var r = this._getMatch(); if (!r) return null; var t = dateStr.match(r.reg); if (!t) return null; var tt = { y: r.position[0] == -1 ? 1900 : t[r.position[0]], M: r.position[1] == -1 ? 0 : parseInt(t[r.position[1]], 10) - 1, d: r.position[2] == -1 ? 1 : parseInt(t[r.position[2]], 10), h: r.position[3] == -1 ? 0 : parseInt(t[r.position[3]], 10), m: r.position[4] == -1 ? 0 : parseInt(t[r.position[4]], 10), s: r.position[5] == -1 ? 0 : parseInt(t[r.position[5]], 10) }; if (tt.M < 0 || tt.M > 11 || tt.d < 0 || tt.d > 31) return null; var d = new Date(tt.y, tt.M, tt.d); if (p.showTime) { if (tt.m < 0 || tt.m > 59 || tt.h < 0 || tt.h > 23 || tt.s < 0 || tt.s > 59) return null; d.setHours(tt.h); d.setMinutes(tt.m); d.setSeconds(tt.s); } return d; }, updateStyle: function () { this.onTextChange(); }, onTextChange: function () { var g = this, p = this.options; var val = g.inputText.val(); if (!val) { g.selectedDate = null; return true; } var newDate = g._bulidDate(val); if (!newDate) { g._rever(); return; } else { g.usedDate = newDate; } g.selectedDate = { year: g.usedDate.getFullYear(), month: g.usedDate.getMonth() + 1, //注意这里 day: g.usedDate.getDay(), date: g.usedDate.getDate(), hour: g.usedDate.getHours(), minute: g.usedDate.getMinutes() }; g.currentDate = { year: g.usedDate.getFullYear(), month: g.usedDate.getMonth() + 1, //注意这里 day: g.usedDate.getDay(), date: g.usedDate.getDate(), hour: g.usedDate.getHours(), minute: g.usedDate.getMinutes() }; var formatVal = g.getFormatDate(newDate); g.inputText.val(formatVal); g.trigger('changeDate', [formatVal]); if ($(g.dateeditor).is(":visible")) g.bulidContent(); }, _setHeight: function (value) { var g = this; if (value > 4) { g.text.css({ height: value }); g.inputText.css({ height: value }); g.textwrapper.css({ height: value }); } }, _setWidth: function (value) { var g = this; if (value > 20) { g.text.css({ width: value }); g.inputText.css({ width: value - 20 }); g.textwrapper.css({ width: value }); } }, _setValue: function (value) { var g = this; if (!value) g.inputText.val(''); if (typeof value == "string") { if (/^\/Date/.test(value)) { value = value.replace(/^\//, "new ").replace(/\/$/, ""); eval("value = " + value); } g.inputText.val(value); g.usedDate = value; } if (typeof value == "object") { if (value instanceof Date) { g.inputText.val(g.getFormatDate(value)); g.onTextChange(); } } }, _getValue: function () { return this.usedDate; }, setEnabled: function () { var g = this, p = this.options; this.inputText.removeAttr("readonly"); this.text.removeClass('l-text-disabled'); p.disabled = false; }, setDisabled: function () { var g = this, p = this.options; this.inputText.attr("readonly", "readonly"); this.text.addClass('l-text-disabled'); p.disabled = true; } }); })(jQuery);/** * jQuery ligerUI 1.3.2 * * http://ligerui.com * * Author daomi 2015 [ gd_star@163.com ] * */ (function ($) { var l = $.ligerui; //全局事件 $(".l-dialog-btn").live('mouseover', function () { $(this).addClass("l-dialog-btn-over"); }).live('mouseout', function () { $(this).removeClass("l-dialog-btn-over"); }); $(".l-dialog-tc .l-dialog-close").live('mouseover', function () { $(this).addClass("l-dialog-close-over"); }).live('mouseout', function () { $(this).removeClass("l-dialog-close-over"); }); $.ligerDialog = function () { return l.run.call(null, "ligerDialog", arguments, { isStatic: true }); }; //dialog 图片文件夹的路径 预加载 $.ligerui.DialogImagePath = "../../lib/ligerUI/skins/Aqua/images/win/"; function prevImage(paths) { for (var i in paths) { $('').attr('src', l.DialogImagePath + paths[i]); } } //prevImage(['dialog.gif', 'dialog-winbtns.gif', 'dialog-bc.gif', 'dialog-tc.gif']); $.ligerDefaults.Dialog = { cls: null, //给dialog附加css class contentCls: null, id: null, //给dialog附加id buttons: null, //按钮集合 isDrag: true, //是否拖动 width: 280, //宽度 height: null, //高度,默认自适应 content: '', //内容 target: null, //目标对象,指定它将以appendTo()的方式载入 url: null, //目标页url,默认以iframe的方式载入 urlParms: null, //传参 load: false, //是否以load()的方式加载目标页的内容 type: 'none', //类型 warn、success、error、question left: null, //位置left top: null, //位置top modal: true, //是否模态对话框 data: null, //传递数据容器 name: null, //创建iframe时 作为iframe的name和id isResize: false, // 是否调整大小 allowClose: true, //允许关闭 opener: null, timeParmName: null, //是否给URL后面加上值为new Date().getTime()的参数,如果需要指定一个参数名即可 closeWhenEnter: null, //回车时是否关闭dialog isHidden: true, //关闭对话框时是否只是隐藏,还是销毁对话框 show: true, //初始化时是否马上显示 title: '提示', //头部 showMax: false, //是否显示最大化按钮 showToggle: false, //是否显示收缩窗口按钮 showMin: false, //是否显示最小化按钮 slide: $.browser.msie ? false : true, //是否以动画的形式显示 fixedType: null, //在固定的位置显示, 可以设置的值有n, e, s, w, ne, se, sw, nw showType: null, //显示类型,可以设置为slide(固定显示时有效) layoutMode : 1, //1 九宫布局, 2 上中下布局 onLoaded: null, onExtend: null, onExtended: null, onCollapse: null, onCollapseed: null, onContentHeightChange: null, onClose: null, onClosed: null, onStopResize: null }; $.ligerDefaults.DialogString = { titleMessage: '提示', //提示文本标题 ok: '确定', yes: '是', no: '否', cancel: '取消', waittingMessage: '正在等待中,请稍候...' }; $.ligerMethos.Dialog = $.ligerMethos.Dialog || {}; l.controls.Dialog = function (options) { l.controls.Dialog.base.constructor.call(this, null, options); }; l.controls.Dialog.ligerExtend(l.core.Win, { __getType: function () { return 'Dialog'; }, __idPrev: function () { return 'Dialog'; }, _extendMethods: function () { return $.ligerMethos.Dialog; }, _render: function () { var g = this, p = this.options; var tmpId = ""; g.set(p, true); var dialog = $('
    '); $('body').append(dialog); g.dialog = dialog; if (p.layoutMode == 2) //上中下布局,不再需要这左右的单元格了 { dialog.find("td.l-dialog-tl,td.l-dialog-cl,td.l-dialog-bl,td.l-dialog-tr,td.l-dialog-cr,td.l-dialog-br").remove(); } g.element = dialog[0]; g.dialog.body = $(".l-dialog-body:first", g.dialog); g.dialog.header = $(".l-dialog-tc-inner:first", g.dialog); g.dialog.winbtns = $(".l-dialog-winbtns:first", g.dialog.header); g.dialog.buttons = $(".l-dialog-buttons:first", g.dialog); g.dialog.content = $(".l-dialog-content:first", g.dialog); g.set(p, false); if (p.allowClose == false) $(".l-dialog-close", g.dialog).remove(); if (p.target || p.url || p.type == "none") { p.type = null; g.dialog.addClass("l-dialog-win"); } if (p.cls) g.dialog.addClass(p.cls); if (p.id) g.dialog.attr("id", p.id); //设置锁定屏幕、拖动支持 和设置图片 g.mask(); if (p.isDrag) g._applyDrag(); if (p.isResize) g._applyResize(); if (p.type) g._setImage(); else { $(".l-dialog-image", g.dialog).remove(); g.dialog.content.addClass("l-dialog-content-noimage"); } if (p.contentCls) g.dialog.content.addClass(p.contentCls); if (!p.show) { g.unmask(); g.dialog.hide(); } //设置主体内容 if (p.target) { g.dialog.content.prepend(p.target); $(p.target).show(); } else if (p.url) { var url = $.isFunction(p.url) ? p.url.call(g) : p.url; var urlParms = $.isFunction(p.urlParms) ? p.urlParms.call(g) : p.urlParms; if (p.timeParmName) { urlParms = urlParms || {}; urlParms[p.timeParmName] = new Date().getTime(); } if (urlParms) { for (var name in urlParms) { url += url.indexOf('?') == -1 ? "?" : "&"; url += name + "=" + urlParms[name]; } } if (p.load) { g.dialog.body.load(url, function () { g._saveStatus(); g.trigger('loaded'); }); } else { g.jiframe = $(""); var framename = p.name ? p.name : "ligerwindow" + new Date().getTime(); g.jiframe.attr("name", framename); g.jiframe.attr("id", framename); g.dialog.content.prepend(g.jiframe); g.dialog.content.addClass("l-dialog-content-nopadding l-dialog-content-frame"); setTimeout(function () { if (g.dialog.body.find(".l-dialog-loading:first").length == 0) g.dialog.body.append("
    "); var iframeloading = $(".l-dialog-loading:first", g.dialog.body); g.jiframe[0].dialog = g;//增加窗口对dialog对象的引用 /* 可以在子窗口这样使用: var dialog = frameElement.dialog; var dialogData = dialog.get('data');//获取data参数 dialog.set('title','新标题'); //设置标题 dialog.close();//关闭dialog */ g.jiframe.attr("src", url).bind('load.dialog', function () { iframeloading.hide(); g.trigger('loaded'); }); g.frame = window.frames[g.jiframe.attr("name")]; }, 0); // 为了解决ie下对含有iframe的div窗口销毁不正确,进而导致第二次打开时焦点不在当前图层的问题 // 加入以下代码 tmpId = 'jquery_ligerui_' + new Date().getTime(); g.tmpInput = $(""); g.tmpInput.attr("id", tmpId); g.dialog.content.prepend(g.tmpInput); } } if (p.opener) g.dialog.opener = p.opener; //设置按钮 if (p.buttons) { $(p.buttons).each(function (i, item) { var btn = $('
    '); $(".l-dialog-btn-inner", btn).html(item.text); $(".l-dialog-buttons-inner", g.dialog.buttons).prepend(btn); item.width && btn.width(item.width); item.onclick && btn.click(function () { item.onclick(item, g, i) }); item.cls && btn.addClass(item.cls); }); } else { g.dialog.buttons.remove(); } $(".l-dialog-buttons-inner", g.dialog.buttons).append("
    "); $(".l-dialog-title", g.dialog) .bind("selectstart", function () { return false; }); g.dialog.click(function () { l.win.setFront(g); }); //设置事件 $(".l-dialog-tc .l-dialog-close", g.dialog).click(function () { if (p.isHidden) g.hide(); else g.close(); }); if (!p.fixedType) { if (p.width == 'auto') { setTimeout(function () { resetPos() }, 100); } else { resetPos(); } } function resetPos() { //位置初始化 var left = 0; var top = 0; var width = p.width || g.dialog.width(); if (p.slide == true) p.slide = 'fast'; if (p.left != null) left = p.left; else p.left = left = 0.5 * ($(window).width() - width); if (p.top != null) top = p.top; else p.top = top = 0.5 * ($(window).height() - g.dialog.height()) + $(window).scrollTop() - 10; if (left < 0) p.left = left = 0; if (top < 0) p.top = top = 0; g.dialog.css({ left: left, top: top }); } g.show(); $('body').bind('keydown.dialog', function (e) { var key = e.which; if (key == 13) { g.enter(); } else if (key == 27) { g.esc(); } }); g._updateBtnsWidth(); g._saveStatus(); g._onReisze(); if (tmpId != "") { $("#" + tmpId).focus(); $("#" + tmpId).remove(); } }, _borderX: 12, _borderY: 32, doMax: function (slide) { var g = this, p = this.options; var width = $(window).width(), height = $(window).height(), left = 0, top = 0; if (l.win.taskbar) { height -= l.win.taskbar.outerHeight(); if (l.win.top) top += l.win.taskbar.outerHeight(); } if (slide) { g.dialog.body.animate({ width: width - g._borderX }, p.slide); g.dialog.animate({ left: left, top: top }, p.slide); g.dialog.content.animate({ height: height - g._borderY - g.dialog.buttons.outerHeight() }, p.slide, function () { g._onReisze(); }); } else { g.set({ width: width, height: height, left: left, top: top }); g._onReisze(); } }, //最大化 max: function () { var g = this, p = this.options; if (g.winmax) { g.winmax.addClass("l-dialog-recover"); g.doMax(p.slide); if (g.wintoggle) { if (g.wintoggle.hasClass("l-dialog-extend")) g.wintoggle.addClass("l-dialog-toggle-disabled l-dialog-extend-disabled"); else g.wintoggle.addClass("l-dialog-toggle-disabled l-dialog-collapse-disabled"); } if (g.resizable) g.resizable.set({ disabled: true }); if (g.draggable) g.draggable.set({ disabled: true }); g.maximum = true; $(window).bind('resize.dialogmax', function () { g.doMax(false); }); } }, //恢复 recover: function () { var g = this, p = this.options; if (g.winmax) { g.winmax.removeClass("l-dialog-recover"); if (p.slide) { g.dialog.body.animate({ width: g._width - g._borderX }, p.slide); g.dialog.animate({ left: g._left, top: g._top }, p.slide); g.dialog.content.animate({ height: g._height - g._borderY - g.dialog.buttons.outerHeight() }, p.slide, function () { g._onReisze(); }); } else { g.set({ width: g._width, height: g._height, left: g._left, top: g._top }); g._onReisze(); } if (g.wintoggle) { g.wintoggle.removeClass("l-dialog-toggle-disabled l-dialog-extend-disabled l-dialog-collapse-disabled"); } $(window).unbind('resize.dialogmax'); } if (this.resizable) this.resizable.set({ disabled: false }); if (g.draggable) g.draggable.set({ disabled: false }); g.maximum = false; }, //最小化 min: function () { var g = this, p = this.options; var task = l.win.getTask(this); if (p.slide) { g.dialog.body.animate({ width: 1 }, p.slide); task.y = task.offset().top + task.height(); task.x = task.offset().left + task.width() / 2; g.dialog.animate({ left: task.x, top: task.y }, p.slide, function () { g.dialog.hide(); }); } else { g.dialog.hide(); } g.unmask(); g.minimize = true; g.actived = false; }, active: function () { var g = this, p = this.options; if (g.minimize) { var width = g._width, height = g._height, left = g._left, top = g._top; if (g.maximum) { width = $(window).width(); height = $(window).height(); left = top = 0; if (l.win.taskbar) { height -= l.win.taskbar.outerHeight(); if (l.win.top) top += l.win.taskbar.outerHeight(); } } if (p.slide) { g.dialog.body.animate({ width: width - g._borderX }, p.slide); g.dialog.animate({ left: left, top: top }, p.slide); } else { g.set({ width: width, height: height, left: left, top: top }); } } g.actived = true; g.minimize = false; l.win.setFront(g); g.show(); }, //展开 收缩 toggle: function () { var g = this, p = this.options; if (!g.wintoggle) return; if (g.wintoggle.hasClass("l-dialog-extend")) g.extend(); else g.collapse(); }, //收缩 collapse: function (slide) { var g = this, p = this.options; if (!g.wintoggle) return; if (p.slide && slide != false) g.dialog.content.animate({ height: 1 }, p.slide); else g.dialog.content.height(1); if (this.resizable) this.resizable.set({ disabled: true }); g.wintoggle.addClass("l-dialog-extend"); }, //展开 extend: function () { var g = this, p = this.options; if (!g.wintoggle) return; var contentHeight = g._height - g._borderY - g.dialog.buttons.outerHeight(); if (p.slide) g.dialog.content.animate({ height: contentHeight }, p.slide); else g.dialog.content.height(contentHeight); if (this.resizable) this.resizable.set({ disabled: false }); g.wintoggle.removeClass("l-dialog-extend"); }, _updateBtnsWidth: function () { var g = this; var btnscount = $(">div", g.dialog.winbtns).length; g.dialog.winbtns.width(22 * btnscount); }, _setLeft: function (value) { if (!this.dialog) return; if (value != null) this.dialog.css({ left: value }); }, _setTop: function (value) { if (!this.dialog) return; if (value != null) this.dialog.css({ top: value }); }, _setWidth: function (value) { if (!this.dialog) return; if (value >= this._borderX) { this.dialog.body.width(value - this._borderX); } }, _setHeight: function (value) { var g = this, p = this.options; if (!this.dialog) return; if (value == "auto") { g.dialog.content.height('auto'); } else if (value >= this._borderY) { var height = value - this._borderY - g.dialog.buttons.outerHeight(); if (g.trigger('ContentHeightChange', [height]) == false) return; if (p.load) { g.dialog.body.height(height); } else { g.dialog.content.height(height); } g.trigger('ContentHeightChanged', [height]); } }, _setShowMax: function (value) { var g = this, p = this.options; if (value) { if (!g.winmax) { g.winmax = $('
    ').appendTo(g.dialog.winbtns) .hover(function () { if ($(this).hasClass("l-dialog-recover")) $(this).addClass("l-dialog-recover-over"); else $(this).addClass("l-dialog-max-over"); }, function () { $(this).removeClass("l-dialog-max-over l-dialog-recover-over"); }).click(function () { if ($(this).hasClass("l-dialog-recover")) g.recover(); else g.max(); }); } } else if (g.winmax) { g.winmax.remove(); g.winmax = null; } g._updateBtnsWidth(); }, _setShowMin: function (value) { var g = this, p = this.options; if (value) { if (!g.winmin) { g.winmin = $('
    ').appendTo(g.dialog.winbtns) .hover(function () { $(this).addClass("l-dialog-min-over"); }, function () { $(this).removeClass("l-dialog-min-over"); }).click(function () { g.min(); }); l.win.addTask(g); } } else if (g.winmin) { g.winmin.remove(); g.winmin = null; } g._updateBtnsWidth(); }, _setShowToggle: function (value) { var g = this, p = this.options; if (value) { if (!g.wintoggle) { g.wintoggle = $('
    ').appendTo(g.dialog.winbtns) .hover(function () { if ($(this).hasClass("l-dialog-toggle-disabled")) return; if ($(this).hasClass("l-dialog-extend")) $(this).addClass("l-dialog-extend-over"); else $(this).addClass("l-dialog-collapse-over"); }, function () { $(this).removeClass("l-dialog-extend-over l-dialog-collapse-over"); }).click(function () { if ($(this).hasClass("l-dialog-toggle-disabled")) return; if (g.wintoggle.hasClass("l-dialog-extend")) { if (g.trigger('extend') == false) return; g.wintoggle.removeClass("l-dialog-extend"); g.extend(); g.trigger('extended'); } else { if (g.trigger('collapse') == false) return; g.wintoggle.addClass("l-dialog-extend"); g.collapse(); g.trigger('collapseed') } }); } } else if (g.wintoggle) { g.wintoggle.remove(); g.wintoggle = null; } }, //按下回车 enter: function () { var g = this, p = this.options; var isClose; if (p.closeWhenEnter != undefined) { isClose = p.closeWhenEnter; } else if (p.type == "warn" || p.type == "error" || p.type == "success" || p.type == "question") { isClose = true; } if (isClose) { g.close(); } }, esc: function () { }, _removeDialog: function () { var g = this, p = this.options; if (p.showType && p.fixedType) { g.dialog.animate({ bottom: -1 * p.height }, function () { remove(); }); } else { remove(); } function remove() { var jframe = $('iframe', g.dialog); if (jframe.length) { var frame = jframe[0]; frame.src = "about:blank"; if (frame.contentWindow && frame.contentWindow.document) { try { frame.contentWindow.document.write(''); } catch (e) { } } $.browser.msie && CollectGarbage(); jframe.remove(); } g.dialog.remove(); } }, close: function () { var g = this, p = this.options; if (g.trigger('Close') == false) return; g.doClose(); if (g.trigger('Closed') == false) return; }, doClose: function () { var g = this; l.win.removeTask(this); $.ligerui.remove(this); g.unmask(); g._removeDialog(); $('body').unbind('keydown.dialog'); }, _getVisible: function () { return this.dialog.is(":visible"); }, _setUrl: function (url) { var g = this, p = this.options; p.url = url; if (p.load) { g.dialog.body.html("").load(p.url, function () { g.trigger('loaded'); }); } else if (g.jiframe) { g.jiframe.attr("src", p.url); } }, _setContent: function (content) { this.dialog.content.html(content); }, _setTitle: function (value) { var g = this; var p = this.options; if (value) { $(".l-dialog-title", g.dialog).html(value); } }, _hideDialog: function () { var g = this, p = this.options; if (p.showType && p.fixedType) { g.dialog.animate({ bottom: -1 * p.height }, function () { g.dialog.hide(); }); } else { g.dialog.hide(); } }, hidden: function () { var g = this; l.win.removeTask(g); g.dialog.hide(); g.unmask(); }, show: function () { var g = this, p = this.options; g.mask(); if (p.fixedType) { if (p.showType) { g.dialog.css({ bottom: -1 * p.height }).addClass("l-dialog-fixed"); g.dialog.show().animate({ bottom: 0 }); } else { g.dialog.show().css({ bottom: 0 }).addClass("l-dialog-fixed"); } } else { g.dialog.show(); } //前端显示 $.ligerui.win.setFront.ligerDefer($.ligerui.win, 100, [g]); }, setUrl: function (url) { this._setUrl(url); }, _saveStatus: function () { var g = this; g._width = g.dialog.body.width(); g._height = g.dialog.body.height(); var top = 0; var left = 0; if (!isNaN(parseInt(g.dialog.css('top')))) top = parseInt(g.dialog.css('top')); if (!isNaN(parseInt(g.dialog.css('left')))) left = parseInt(g.dialog.css('left')); g._top = top; g._left = left; }, _applyDrag: function () { var g = this, p = this.options; if ($.fn.ligerDrag) { g.draggable = g.dialog.ligerDrag({ handler: '.l-dialog-title', animate: false, onStartDrag: function () { l.win.setFront(g); var mask = $("
    ").height(g.dialog.height()); g.dialog.append(mask); g.dialog.content.addClass('l-dialog-content-dragging'); }, onDrag: function (current, e) { var pageY = e.pageY || e.screenY; if (pageY < 0) return false; }, onStopDrag: function () { g.dialog.find("div.l-dragging-mask:first").remove(); g.dialog.content.removeClass('l-dialog-content-dragging'); if (p.target) { var triggers1 = l.find($.ligerui.controls.DateEditor); var triggers2 = l.find($.ligerui.controls.ComboBox); //更新所有下拉选择框的位置 $($.merge(triggers1, triggers2)).each(function () { if (this.updateSelectBoxPosition) this.updateSelectBoxPosition(); }); } g._saveStatus(); } }); } }, _onReisze: function () { var g = this, p = this.options; if (p.target || p.url) { var manager = $(p.target).liger(); if (!manager) manager = $(p.target).find(":first").liger(); if (!manager) return; var contentHeight = g.dialog.content.height(); var contentWidth = g.dialog.content.width(); manager.trigger('resize', [{ width: contentWidth, height: contentHeight }]); } }, _applyResize: function () { var g = this, p = this.options; if ($.fn.ligerResizable) { g.resizable = g.dialog.ligerResizable({ onStopResize: function (current, e) { var top = 0; var left = 0; if (!isNaN(parseInt(g.dialog.css('top')))) top = parseInt(g.dialog.css('top')); if (!isNaN(parseInt(g.dialog.css('left')))) left = parseInt(g.dialog.css('left')); if (current.diffLeft) { g.set({ left: left + current.diffLeft }); } if (current.diffTop) { g.set({ top: top + current.diffTop }); } if (current.newWidth) { g.set({ width: current.newWidth }); g.dialog.body.css({ width: current.newWidth - g._borderX }); } if (current.newHeight) { g.set({ height: current.newHeight }); } g._onReisze(); g._saveStatus(); g.trigger('stopResize'); return false; }, animate: false }); } }, _setImage: function () { var g = this, p = this.options; if (p.type) { var alertCss = { paddingLeft: 74, paddingRight: 15, paddingBottom: 30 }; if (p.type == 'success' || p.type == 'donne' || p.type == 'ok') { $(".l-dialog-image", g.dialog).addClass("l-dialog-image-donne").show(); g.dialog.content.css(alertCss); } else if (p.type == 'error') { $(".l-dialog-image", g.dialog).addClass("l-dialog-image-error").show(); g.dialog.content.css(alertCss); } else if (p.type == 'warn') { $(".l-dialog-image", g.dialog).addClass("l-dialog-image-warn").show(); g.dialog.content.css(alertCss); } else if (p.type == 'question') { $(".l-dialog-image", g.dialog).addClass("l-dialog-image-question").show(); g.dialog.content.css(alertCss); } } } }); l.controls.Dialog.prototype.hide = l.controls.Dialog.prototype.hidden; $.ligerDialog.open = function (p) { return $.ligerDialog(p); }; $.ligerDialog.close = function () { var dialogs = l.find(l.controls.Dialog.prototype.__getType()); for (var i in dialogs) { var d = dialogs[i]; d.destroy.ligerDefer(d, 5); } l.win.unmask(); }; $.ligerDialog.show = function (p) { var dialogs = l.find(l.controls.Dialog.prototype.__getType()); if (dialogs.length) { for (var i in dialogs) { dialogs[i].show(); return; } } return $.ligerDialog(p); }; $.ligerDialog.hide = function () { var dialogs = l.find(l.controls.Dialog.prototype.__getType()); for (var i in dialogs) { var d = dialogs[i]; d.hide(); } }; $.ligerDialog.tip = function (options) { options = $.extend({ showType: 'slide', width: 240, modal: false, height: 100 }, options || {}); $.extend(options, { fixedType: 'se', type: 'none', isDrag: false, isResize: false, showMax: false, showToggle: false, showMin: false }); return $.ligerDialog.open(options); }; $.ligerDialog.alert = function (content, title, type, callback, options) { content = content || ""; if (typeof (title) == "function") { callback = title; type = null; } else if (typeof (type) == "function") { callback = type; } var btnclick = function (item, Dialog, index) { Dialog.close(); if (callback) callback(item, Dialog, index); }; p = { content: content, buttons: [{ text: $.ligerDefaults.DialogString.ok, onclick: btnclick }] }; if (typeof (title) == "string" && title != "") p.title = title; if (typeof (type) == "string" && type != "") p.type = type; $.extend(p, { showMax: false, showToggle: false, showMin: false }, options || {}); return $.ligerDialog(p); }; $.ligerDialog.confirm = function (content, title, callback) { if (typeof (title) == "function") { callback = title; type = null; } var btnclick = function (item, Dialog) { Dialog.close(); if (callback) { callback(item.type == 'ok'); } }; p = { type: 'question', content: content, buttons: [ { text: $.ligerDefaults.DialogString.yes, onclick: btnclick, type: 'ok', cls: 'l-dialog-btn-ok' }, { text: $.ligerDefaults.DialogString.no, onclick: btnclick, type: 'no', cls: 'l-dialog-btn-no' } ] }; if (typeof (title) == "string" && title != "") p.title = title; $.extend(p, { showMax: false, showToggle: false, showMin: false }); return $.ligerDialog(p); }; $.ligerDialog.warning = function (content, title, callback, options) { if (typeof (title) == "function") { callback = title; type = null; } var btnclick = function (item, Dialog) { Dialog.close(); if (callback) { callback(item.type); } }; p = { type: 'question', content: content, buttons: [{ text: $.ligerDefaults.DialogString.yes, onclick: btnclick, type: 'yes' }, { text: $.ligerDefaults.DialogString.no, onclick: btnclick, type: 'no' }, { text: $.ligerDefaults.DialogString.cancel, onclick: btnclick, type: 'cancel' }] }; if (typeof (title) == "string" && title != "") p.title = title; $.extend(p, { showMax: false, showToggle: false, showMin: false }, options || {}); return $.ligerDialog(p); }; $.ligerDialog.waitting = function (title) { title = title || $.ligerDefaults.Dialog.waittingMessage; return $.ligerDialog.open({ cls: 'l-dialog-waittingdialog', type: 'none', content: '
    ' + title + '
    ', allowClose: false }); }; $.ligerDialog.closeWaitting = function () { var dialogs = l.find(l.controls.Dialog); for (var i in dialogs) { var d = dialogs[i]; if (d.dialog.hasClass("l-dialog-waittingdialog")) d.close(); } }; $.ligerDialog.success = function (content, title, onBtnClick, options) { return $.ligerDialog.alert(content, title, 'success', onBtnClick, options); }; $.ligerDialog.error = function (content, title, onBtnClick, options) { return $.ligerDialog.alert(content, title, 'error', onBtnClick, options); }; $.ligerDialog.warn = function (content, title, onBtnClick, options) { return $.ligerDialog.alert(content, title, 'warn', onBtnClick, options); }; $.ligerDialog.question = function (content, title, options) { return $.ligerDialog.alert(content, title, 'question', null, options); }; $.ligerDialog.prompt = function (title, value, multi, callback) { var target = $(''); if (typeof (multi) == "function") { callback = multi; } if (typeof (value) == "function") { callback = value; } else if (typeof (value) == "boolean") { multi = value; } if (typeof (multi) == "boolean" && multi) { target = $(''); } if (typeof (value) == "string" || typeof (value) == "int") { target.val(value); } var btnclick = function (item, Dialog, index) { Dialog.close(); if (callback) { callback(item.type == 'yes', target.val()); } } p = { title: title, target: target, width: 320, buttons: [{ text: $.ligerDefaults.DialogString.ok, onclick: btnclick, type: 'yes' }, { text: $.ligerDefaults.DialogString.cancel, onclick: btnclick, type: 'cancel' }] }; return $.ligerDialog(p); }; })(jQuery);/** * jQuery ligerUI 1.3.2 * * http://ligerui.com * * Author daomi 2015 [ gd_star@163.com ] * */ (function ($) { var l = $.ligerui; $.fn.ligerDrag = function (options) { return l.run.call(this, "ligerDrag", arguments, { idAttrName: 'ligeruidragid', hasElement: false, propertyToElemnt: 'target' } ); }; $.fn.ligerGetDragManager = function () { return l.run.call(this, "ligerGetDragManager", arguments, { idAttrName: 'ligeruidragid', hasElement: false, propertyToElemnt: 'target' }); }; $.ligerDefaults.Drag = { onStartDrag: false, onDrag: false, onStopDrag: false, handler: null, //鼠标按下再弹起,如果中间的间隔小于[dragDelay]毫秒,那么认为是点击,不会进行拖拽操作 clickDelay : 100, //代理 拖动时的主体,可以是'clone'或者是函数,放回jQuery 对象 proxy: true, revert: false, animate: true, onRevert: null, onEndRevert: null, //接收区域 jQuery对象或者jQuery选择字符 receive: null, //进入区域 onDragEnter: null, //在区域移动 onDragOver: null, //离开区域 onDragLeave: null, //在区域释放 onDrop: null, disabled: false, proxyX: null, //代理相对鼠标指针的位置,如果不设置则对应target的left proxyY: null }; l.controls.Drag = function (options) { l.controls.Drag.base.constructor.call(this, null, options); }; l.controls.Drag.ligerExtend(l.core.UIComponent, { __getType: function () { return 'Drag'; }, __idPrev: function () { return 'Drag'; }, _render: function () { var g = this, p = this.options; this.set(p); g.cursor = "move"; g.handler.css('cursor', g.cursor); g.mouseDowned = false; g.handler.bind('mousedown.drag', function (e) { if (p.disabled) return; if (e.button == 2) return; g.mouseDowned = true; $(document).bind("selectstart.drag", function () { return false; }); setTimeout(function () { //如果过了N毫秒,鼠标还没有弹起来,才认为是启动drag if (g.mouseDowned) { g._start.call(g, e); } }, p.clickDelay || 100); }).bind('mousemove.drag', function () { if (p.disabled) return; g.handler.css('cursor', g.cursor); }).bind('mouseup.drag', function () { $(document).unbind("selectstart.drag"); }); $(document).bind('mouseup', function () { g.mouseDowned = false; }); }, _rendered: function () { this.options.target.ligeruidragid = this.id; }, _start: function (e) { var g = this, p = this.options; if (g.reverting) return; if (p.disabled) return; g.current = { target: g.target, left: g.target.offset().left, top: g.target.offset().top, startX: e.pageX || e.screenX, startY: e.pageY || e.clientY }; if (g.trigger('startDrag', [g.current, e]) == false) return false; g.cursor = "move"; g._createProxy(p.proxy, e); //代理没有创建成功 if (p.proxy && !g.proxy) return false; (g.proxy || g.handler).css('cursor', g.cursor); $(document).bind('mousemove.drag', function () { g._drag.apply(g, arguments); }); l.draggable.dragging = true; $(document).bind('mouseup.drag', function () { l.draggable.dragging = false; g._stop.apply(g, arguments); }); }, _drag: function (e) { var g = this, p = this.options; if (!g.current) return; var pageX = e.pageX || e.screenX; var pageY = e.pageY || e.screenY; g.current.diffX = pageX - g.current.startX; g.current.diffY = pageY - g.current.startY; (g.proxy || g.handler).css('cursor', g.cursor); if (g.receive) { g.receive.each(function (i, obj) { var receive = $(obj); var xy = receive.offset(); if (pageX > xy.left && pageX < xy.left + receive.width() && pageY > xy.top && pageY < xy.top + receive.height()) { if (!g.receiveEntered[i]) { g.receiveEntered[i] = true; g.trigger('dragEnter', [obj, g.proxy || g.target, e]); } else { g.trigger('dragOver', [obj, g.proxy || g.target, e]); } } else if (g.receiveEntered[i]) { g.receiveEntered[i] = false; g.trigger('dragLeave', [obj, g.proxy || g.target, e]); } }); } if (g.hasBind('drag')) { if (g.trigger('drag', [g.current, e]) != false) { g._applyDrag(); } else { if (g.proxy) { g._removeProxy(); } else { g._stop(); } } } else { g._applyDrag(); } }, _stop: function (e) { var g = this, p = this.options; $(document).unbind('mousemove.drag'); $(document).unbind('mouseup.drag'); $(document).unbind("selectstart.drag"); if (g.receive) { g.receive.each(function (i, obj) { if (g.receiveEntered[i]) { g.trigger('drop', [obj, g.proxy || g.target, e]); } }); } if (g.proxy) { if (p.revert) { if (g.hasBind('revert')) { if (g.trigger('revert', [g.current, e]) != false) g._revert(e); else g._removeProxy(); } else { g._revert(e); } } else { g._applyDrag(g.target); g._removeProxy(); } } g.cursor = 'move'; g.trigger('stopDrag', [g.current, e]); g.current = null; g.handler.css('cursor', g.cursor); }, _revert: function (e) { var g = this; g.reverting = true; g.proxy.animate({ left: g.current.left, top: g.current.top }, function () { g.reverting = false; g._removeProxy(); g.trigger('endRevert', [g.current, e]); g.current = null; }); }, _applyDrag: function (applyResultBody) { var g = this, p = this.options; applyResultBody = applyResultBody || g.proxy || g.target; var cur = {}, changed = false; var noproxy = applyResultBody == g.target; if (g.current.diffX) { if (noproxy || p.proxyX == null) cur.left = g.current.left + g.current.diffX; else cur.left = g.current.startX + p.proxyX + g.current.diffX; changed = true; } if (g.current.diffY) { if (noproxy || p.proxyY == null) cur.top = g.current.top + g.current.diffY; else cur.top = g.current.startY + p.proxyY + g.current.diffY; changed = true; } if (applyResultBody == g.target && g.proxy && p.animate) { g.reverting = true; applyResultBody.animate(cur, function () { g.reverting = false; }); } else { applyResultBody.css(cur); } }, _setReceive: function (receive) { this.receiveEntered = {}; if (!receive) return; if (typeof receive == 'string') this.receive = $(receive); else this.receive = receive; }, _setHandler: function (handler) { var g = this, p = this.options; if (!handler) g.handler = $(p.target); else g.handler = (typeof handler == 'string' ? $(handler, p.target) : handler); }, _setTarget: function (target) { this.target = $(target); }, _setCursor: function (cursor) { this.cursor = cursor; (this.proxy || this.handler).css('cursor', cursor); }, _createProxy: function (proxy, e) { if (!proxy) return; var g = this, p = this.options; if (typeof proxy == 'function') { g.proxy = proxy.call(this.options.target, g, e); } else if (proxy == 'clone') { g.proxy = g.target.clone().css('position', 'absolute'); g.proxy.appendTo('body'); } else { g.proxy = $("
    "); g.proxy.width(g.target.width()).height(g.target.height()) g.proxy.attr("dragid", g.id).appendTo('body'); } g.proxy.css({ left: p.proxyX == null ? g.current.left : g.current.startX + p.proxyX, top: p.proxyY == null ? g.current.top : g.current.startY + p.proxyY }).show(); }, _removeProxy: function () { var g = this; if (g.proxy) { g.proxy.remove(); g.proxy = null; } } }); })(jQuery);/** * jQuery ligerUI 1.3.2 * * http://ligerui.com * * Author daomi 2015 [ gd_star@163.com ] * */ (function ($) { $.fn.ligerEasyTab = function () { return $.ligerui.run.call(this, "ligerEasyTab", arguments); }; $.fn.ligerGetEasyTabManager = function () { return $.ligerui.run.call(this, "ligerGetEasyTabManager", arguments); }; $.ligerDefaults.EasyTab = {}; $.ligerMethos.EasyTab = {}; $.ligerui.controls.EasyTab = function (element, options) { $.ligerui.controls.EasyTab.base.constructor.call(this, element, options); }; $.ligerui.controls.EasyTab.ligerExtend($.ligerui.core.UIComponent, { __getType: function () { return 'EasyTab'; }, __idPrev: function () { return 'EasyTab'; }, _extendMethods: function () { return $.ligerMethos.EasyTab; }, _render: function () { var g = this, p = this.options; g.tabs = $(this.element); g.tabs.addClass("l-easytab"); var selectedIndex = 0; if ($("> div[lselected=true]", g.tabs).length > 0) selectedIndex = $("> div", g.tabs).index($("> div[lselected=true]", g.tabs)); g.tabs.ul = $(''); $("> div", g.tabs).each(function (i, box) { var li = $('
  • '); if (i == selectedIndex) $("span", li).addClass("l-selected"); if ($(box).attr("title")) { $("span", li).html($(box).attr("title")); $(box).removeAttr("title"); } g.tabs.ul.append(li); if (!$(box).hasClass("l-easytab-panelbox")) $(box).addClass("l-easytab-panelbox"); }); g.tabs.ul.prependTo(g.tabs); //init $(".l-easytab-panelbox:eq(" + selectedIndex + ")", g.tabs).show().siblings(".l-easytab-panelbox").hide(); //add even $("> ul:first span", g.tabs).click(function () { if ($(this).hasClass("l-selected")) return; var i = $("> ul:first span", g.tabs).index(this); $(this).addClass("l-selected").parent().siblings().find("span.l-selected").removeClass("l-selected"); $(".l-easytab-panelbox:eq(" + i + ")", g.tabs).show().siblings(".l-easytab-panelbox").hide(); }).not("l-selected").hover(function () { $(this).addClass("l-over"); }, function () { $(this).removeClass("l-over"); }); g.set(p); } }); })(jQuery);/** * jQuery ligerUI 1.3.2 * * http://ligerui.com * * Author daomi 2015 [ gd_star@163.com ] * */ (function ($) { $.fn.ligerFilter = function () { return $.ligerui.run.call(this, "ligerFilter", arguments); }; $.fn.ligerGetFilterManager = function () { return $.ligerui.run.call(this, "ligerGetFilterManager", arguments); }; $.ligerDefaults.Filter = { //字段列表 fields: [], //字段类型 - 运算符 的对应关系 operators: {}, //自定义输入框(如下拉框、日期) editors: {}, buttonCls : null }; $.ligerDefaults.FilterString = { strings: { "and": "并且", "or": "或者", "equal": "相等", "notequal": "不相等", "startwith": "以..开始", "endwith": "以..结束", "like": "相似", "greater": "大于", "greaterorequal": "大于或等于", "less": "小于", "lessorequal": "小于或等于", "in": "包括在...", "notin": "不包括...", "addgroup": "增加分组", "addrule": "增加条件", "deletegroup": "删除分组" } }; $.ligerDefaults.Filter.operators['string'] = $.ligerDefaults.Filter.operators['text'] = ["equal", "notequal", "startwith", "endwith", "like", "greater", "greaterorequal", "less", "lessorequal", "in", "notin"]; $.ligerDefaults.Filter.operators['number'] = $.ligerDefaults.Filter.operators['int'] = $.ligerDefaults.Filter.operators['float'] = $.ligerDefaults.Filter.operators['date'] = ["equal", "notequal", "greater", "greaterorequal", "less", "lessorequal", "in", "notin"]; $.ligerDefaults.Filter.editors['string'] = { create: function (container, field) { var input = $(""); container.append(input); input.ligerTextBox(field.editor.options || {}); return input; }, setValue: function (input, value) { input.val(value); }, getValue: function (input) { return input.liger('option', 'value'); }, destroy: function (input) { input.liger('destroy'); } }; $.ligerDefaults.Filter.editors['date'] = { create: function (container, field) { var input = $(""); container.append(input); input.ligerDateEditor(field.editor.options || {}); return input; }, setValue: function (input, value) { input.liger('option', 'value', value); }, getValue: function (input, field) { return input.liger('option', 'value'); }, destroy: function (input) { input.liger('destroy'); } }; $.ligerDefaults.Filter.editors['number'] = { create: function (container, field) { var input = $(""); container.append(input); var options = { minValue: field.editor.minValue, maxValue: field.editor.maxValue }; input.ligerSpinner($.extend(options, field.editor.options || {})); return input; }, setValue: function (input, value) { input.val(value); }, getValue: function (input, field) { var isInt = field.editor.type == "int"; if (isInt) return parseInt(input.val(), 10); else return parseFloat(input.val()); }, destroy: function (input) { input.liger('destroy'); } }; $.ligerDefaults.Filter.editors['combobox'] = { create: function (container, field) { var input = $(""); container.append(input); var options = { data: field.data, slide: false, valueField: field.editor.valueField || field.editor.valueColumnName, textField: field.editor.textField || field.editor.displayColumnName }; $.extend(options, field.editor.options || {}); input.ligerComboBox(options); return input; }, setValue: function (input, value) { input.liger('option', 'value', value); }, getValue: function (input) { return input.liger('option', 'value'); }, destroy: function (input) { input.liger('destroy'); } }; //过滤器组件 $.ligerui.controls.Filter = function (element, options) { $.ligerui.controls.Filter.base.constructor.call(this, element, options); }; $.ligerui.controls.Filter.ligerExtend($.ligerui.core.UIComponent, { __getType: function () { return 'Filter' }, __idPrev: function () { return 'Filter'; }, _init: function () { var g = this, p = this.options; $.ligerui.controls.Filter.base._init.call(this); //编辑构造器初始化 for (var type in liger.editors) { var editor = liger.editors[type]; //如果没有默认的或者已经定义 if (!editor || type in p.editors) continue; p.editors[type] = liger.getEditor($.extend({ type: type, master: g }, editor)); } }, _render: function () { var g = this, p = this.options; g.set(p); //事件:增加分组 $(g.element).bind("click", function (e) { e.preventDefault(); var jthis = $((e.target || e.srcElement)); var cn = jthis.get(0).className; if (cn.indexOf("addgroup") >= 0) { var jtable = jthis.parent().parent().parent().parent(); g.addGroup(jtable); } else if (cn.indexOf("deletegroup") >= 0) { var jtable = jthis.parent().parent().parent().parent(); g.deleteGroup(jtable); } else if (cn.indexOf("addrule") >= 0) { var jtable = jthis.parent().parent().parent().parent(); g.addRule(jtable); } else if (cn.indexOf("deleterole") >= 0) { var rulerow = jthis.parent().parent(); g.deleteRule(rulerow); } }); }, //设置字段列表 _setFields: function (fields) { var g = this, p = this.options; if (g.group) g.group.remove(); g.group = $(g._bulidGroupTableHtml()).appendTo(g.element); p.buttonCls && g.group.find(".addgroup,.addrule,.deletegroup").addClass(p.buttonCls); }, //输入框列表 editors: {}, //输入框计算器 editorCounter: 0, //增加分组 //parm [jgroup] jQuery对象(主分组的table dom元素) addGroup: function (jgroup) { var g = this, p = this.options; jgroup = $(jgroup || g.group); var lastrow = $(">tbody:first > tr:last", jgroup); var groupHtmlArr = []; groupHtmlArr.push(''); var altering = !jgroup.hasClass("l-filter-group-alt"); groupHtmlArr.push(g._bulidGroupTableHtml(altering, true)); groupHtmlArr.push(''); var row = $(groupHtmlArr.join('')); p.buttonCls && row.find(".addgroup,.addrule,.deletegroup").addClass(p.buttonCls); lastrow.before(row); var jtable = row.find("table:first"); if (p.addDefult) { g.addRule(jtable); } return jtable; }, //删除分组 deleteGroup: function (group) { var g = this, p = this.options; $("td.l-filter-value", group).each(function () { var rulerow = $(this).parent(); $("select.fieldsel", rulerow).unbind(); g.removeEditor(rulerow); }); $(group).parent().parent().remove(); }, //删除编辑器 removeEditor: function (rulerow) { var g = this, p = this.options; var type = $(rulerow).attr("editortype"); var id = $(rulerow).attr("editorid"); var editor = g.editors[id]; if (editor && p.editors[type].destroy) { p.editors[type].destroy(editor); } $("td.l-filter-value:first", rulerow).html(""); }, //设置规则 //parm [group] 分组数据 //parm [jgruop] 分组table dom jQuery对象 setData: function (group, jgroup) { var g = this, p = this.options; jgroup = jgroup || g.group; var lastrow = $(">tbody:first > tr:last", jgroup); if (jgroup) { jgroup.find(">tbody:first > tr").not(lastrow).remove(); } $("select:first", lastrow).val(group.op); if (group.rules) { $(group.rules).each(function () { var rulerow = g.addRule(jgroup); $("select.opsel", rulerow).html(g._bulidOpSelectOptionsHtml(this.type || "string")); rulerow.attr("fieldtype", this.type || "string"); $("select.opsel", rulerow).val(this.op); $("select.fieldsel", rulerow).val(this.field).trigger('change'); var editorid = rulerow.attr("editorid"); if (editorid && g.editors[editorid]) { var field = g.getField(this.field); if (field && field.editor) { var editParm = { field: field, filter: g }; p.editors[field.editor.type].setValue.call(g, g.editors[editorid], this.value, editParm); } } else { $(":text", rulerow).val(this.value); } }); } if (group.groups) { $(group.groups).each(function () { var subjgroup = g.addGroup(jgroup); g.setData(this, subjgroup); }); } }, //增加一个条件 //parm [jgroup] 分组的jQuery对象 addRule: function (jgroup) { var g = this, p = this.options; jgroup = jgroup || g.group; var lastrow = $(">tbody:first > tr:last", jgroup); var rulerow = $(g._bulidRuleRowHtml()); lastrow.before(rulerow); if (p.fields.length) { //如果第一个字段启用了自定义输入框 g.appendEditor(rulerow, p.fields[0]); } //事件:字段列表改变时 $("select.fieldsel", rulerow).bind('change', function () { var jopsel = $(this).parent().next().find("select:first"); var fieldName = $(this).val(); if (!fieldName) return; var field = g.getField(fieldName); //字段类型处理 var fieldType = field.type || "string"; var oldFieldtype = rulerow.attr("fieldtype"); if (fieldType != oldFieldtype) { jopsel.html(g._bulidOpSelectOptionsHtml(fieldType)); rulerow.attr("fieldtype", fieldType); } //当前的编辑器 var editorType = null; //上一次的编辑器 var oldEditorType = rulerow.attr("editortype"); if (g.enabledEditor(field)) editorType = field.editor.type; if (oldEditorType) { //如果存在旧的输入框 g.removeEditor(rulerow); } if (editorType) { //如果当前选择的字段定义了输入框 g.appendEditor(rulerow, field); } else { rulerow.removeAttr("editortype").removeAttr("editorid"); $("td.l-filter-value:first", rulerow).html(''); } }); return rulerow; }, //删除一个条件 deleteRule: function (rulerow) { $("select.fieldsel", rulerow).unbind(); this.removeEditor(rulerow); $(rulerow).remove(); }, //附加一个输入框 appendEditor: function (rulerow, field) { var g = this, p = this.options; if (g.enabledEditor(field)) { var container = $("td.l-filter-value:first", rulerow).html(""); var editor = p.editors[field.editor.type]; var editorTag = ++g.editorCounter; var editParm = { filter: g }; editParm.field = $.extend(true, {}, field); editParm.field.name = field.name + "_" + editorTag; g.editors[editorTag] = editor.create.call(this, container, editParm); rulerow.attr("editortype", field.editor.type).attr("editorid", editorTag); } }, //获取分组数据 getData: function (group) { var g = this, p = this.options; group = group || g.group; var groupData = {}; $("> tbody > tr", group).each(function (i, row) { var rowlast = $(row).hasClass("l-filter-rowlast"); var rowgroup = $(row).hasClass("l-filter-rowgroup"); if (rowgroup) { var groupTable = $("> td:first > table:first", row); if (groupTable.length) { if (!groupData.groups) groupData.groups = []; groupData.groups.push(g.getData(groupTable)); } } else if (rowlast) { groupData.op = $(".groupopsel:first", row).val(); } else { var fieldName = $("select.fieldsel:first", row).val(); var field = g.getField(fieldName); var op = $(".opsel:first", row).val(); var value = g._getRuleValue(row, field); var type = $(row).attr("fieldtype") || "string"; if (!groupData.rules) groupData.rules = []; if (value) { groupData.rules.push({ field: fieldName, op: op, value: value, type: type }); } } }); return groupData; }, _getRuleValue: function (rulerow, field) { var g = this, p = this.options; var editorid = $(rulerow).attr("editorid"); var editortype = $(rulerow).attr("editortype"); var editor = g.editors[editorid]; var editParm = { field: field, filter: g }; if (editor) { return p.editors[editortype].getValue.call(g, editor, editParm); } return $(".valtxt:first", rulerow).val(); }, //判断某字段是否启用自定义的输入框 enabledEditor: function (field) { var g = this, p = this.options; if (!field.editor || !field.editor.type) return false; return (field.editor.type in p.editors); }, //根据fieldName 获取 字段 getField: function (fieldname) { var g = this, p = this.options; for (var i = 0, l = p.fields.length; i < l; i++) { var field = p.fields[i]; if (field.name == fieldname) return field; } return null; }, //获取一个分组的html _bulidGroupTableHtml: function (altering, allowDelete) { var g = this, p = this.options; var tableHtmlArr = []; tableHtmlArr.push(''); tableHtmlArr.push(''); tableHtmlArr.push('
    '); //and or tableHtmlArr.push(''); //add group tableHtmlArr.push(''); //add rule tableHtmlArr.push(''); if (allowDelete) tableHtmlArr.push(''); tableHtmlArr.push('
    '); return tableHtmlArr.join(''); }, //获取字段值规则的html _bulidRuleRowHtml: function (fields) { var g = this, p = this.options; fields = fields || p.fields; var rowHtmlArr = []; var fieldType = fields[0].type || "string"; rowHtmlArr.push(''); rowHtmlArr.push('"); rowHtmlArr.push(''); rowHtmlArr.push(''); rowHtmlArr.push(''); rowHtmlArr.push(''); rowHtmlArr.push(''); rowHtmlArr.push(''); rowHtmlArr.push(''); rowHtmlArr.push(''); rowHtmlArr.push('
    '); rowHtmlArr.push(''); rowHtmlArr.push(''); return rowHtmlArr.join(''); }, //获取一个运算符选择框的html _bulidOpSelectOptionsHtml: function (fieldType) { var g = this, p = this.options; var ops = p.operators[fieldType]; var opHtmlArr = []; if (!ops || !ops.length) { ops = ["equal", "notequal"]; } for (var i = 0, l = ops.length; i < l; i++) { var op = ops[i]; opHtmlArr[opHtmlArr.length] = ''; } return opHtmlArr.join(''); } }); $.ligerFilter = function () { }; $.ligerFilter.filterTranslator = { translateGroup: function (group) { var out = []; if (group == null) return " 1==1 "; var appended = false; out.push('('); if (group.rules != null) { for (var i in group.rules) { if (i == "indexOf") continue; var rule = group.rules[i]; if (appended) out.push(this.getOperatorQueryText(group.op)); out.push(this.translateRule(rule)); appended = true; } } if (group.groups != null) { for (var j in group.groups) { var subgroup = group.groups[j]; if (appended) out.push(this.getOperatorQueryText(group.op)); out.push(this.translateGroup(subgroup)); appended = true; } } out.push(')'); if (appended == false) return " 1==1 "; return out.join(''); }, translateRule: function (rule) { var out = []; if (rule == null) return " 1==1 "; if (rule.op == "like" || rule.op == "startwith" || rule.op == "endwith") { out.push('/'); if (rule.op == "startwith") out.push('^'); out.push(rule.value); if (rule.op == "endwith") out.push('$'); out.push('/i.test('); out.push('o["'); out.push(rule.field); out.push('"]'); out.push(')'); return out.join(''); } out.push('o["'); out.push(rule.field); out.push('"]'); out.push(this.getOperatorQueryText(rule.op)); out.push('"'); out.push(rule.value); out.push('"'); return out.join(''); }, getOperatorQueryText: function (op) { switch (op) { case "equal": return " == "; case "notequal": return " != "; case "greater": return " > "; case "greaterorequal": return " >= "; case "less": return " < "; case "lessorequal": return " <= "; case "and": return " && "; case "or": return " || "; default: return " == "; } } }; $.ligerFilter.getFilterFunction = function (condition) { if ($.isArray(condition)) condition = { op: "and", rules: condition }; var fnbody = ' return ' + $.ligerFilter.filterTranslator.translateGroup(condition); return new Function("o", fnbody); }; })(jQuery);/** * jQuery ligerUI 1.3.2 * * http://ligerui.com * * Author daomi 2015 [ gd_star@163.com ] * */ (function ($) { $.fn.ligerForm = function () { return $.ligerui.run.call(this, "ligerForm", arguments); }; $.ligerui.getConditions = function (form, options) { if (!form) return null; form = liger.get($(form)); if (form && form.toConditions) return form.toConditions(); }; $.ligerDefaults = $.ligerDefaults || {}; $.ligerDefaults.Form = { width: null, // 表单的宽度 //控件宽度 inputWidth: 180, //标签宽度 labelWidth: 90, //间隔宽度 space: 40, rightToken: ':', //标签对齐方式 labelAlign: 'left', //控件对齐方式 align: 'left', autoTypePrev : 'ui-', //字段 /* 数组的集合,支持的类型包括在$.ligerDefaults.Form.editors,这个editors同Grid的editors继承于base.js中提供的编辑器集合,具体可以看liger.editors 字段的参数参考 127行左右的 $.ligerDefaults.Form_fields, ui内置的编辑表单元素都会调用ui的表单插件集合,所以这些字段都有属于自己的"liger对象",可以同liger.get("[ID]")的方式获取,这里的[ID]获取方式优先级如下: 1,定义了field.id 则取field.id 2,如果是下拉框和PopupEdit,并且定义了comboboxName,则取comboboxName(如果表单定义了prefixID,需要加上) 3,默认取field.name(如果表单定义了prefixID,需要加上) */ fields: [], //创建的表单元素是否附加ID appendID: true, //生成表单元素ID、Name的前缀 prefixID: null, //json解析函数 toJSON: $.ligerui.toJSON, labelCss: null, fieldCss: null, spaceCss: null, onAfterSetFields: null, // 参数同 ligerButton buttons: null, //按钮组 readonly: false, //是否只读 editors: {}, //编辑器集合,使用同$.ligerDefaults.Grid.editors //验证 validate: null, //不设置validate属性到inuput unSetValidateAttr: false, tab: null, clsTab: 'ui-tabs-nav ui-helper-clearfix', clsTabItem: 'ui-state-default', clsTabItemSelected: 'ui-tabs-selected', clsTabContent: 'ui-tabs-panel ui-widget-content' }; $.ligerDefaults.FormString = { invalidMessage: '存在{errorCount}个字段验证不通过,请检查!', detailMessage: '详细', okMessage: '确定' }; $.ligerDefaults.Form.editors.textarea = { create: function (container, editParm, p) { var editor = $('