| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083 |
- /**
- * jQuery ligerUI 1.2.1
- *
- * http://ligerui.com
- *
- * Author daomi 2013 [ 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.2.0',
- managerCount: 0,
- //组件管理器池
- managers: {},
- managerIdPrev: 'ligerui',
- //管理器id已经存在时自动创建新的
- autoNewId: true,
- //错误提示
- error: {
- managerIsExist: '管理器id已经存在'
- },
- pluginPrev: 'liger',
- 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)
- {
- 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]);
- }
- }
- 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);
- }
- 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];
- 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) { }
- }
- },
- //预渲染,可以用于继承扩展
- _preRender: function ()
- {
- },
- _render: function ()
- {
- },
- _rendered: function ()
- {
- if (this.element)
- {
- $(this.element).attr("ligeruiid", this.id);
- }
- },
- //返回要转换成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");
- }
- },
- 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 });
- }
- });
- //全局窗口对象
- 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 = $("<div class='l-window-mask' style='display: block;'></div>").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 = $('<div class="l-taskbar"><div class="l-taskbar-tasks"></div><div class="l-clear"></div></div>').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] = $('<div class="l-taskbar-task"><div class="l-taskbar-task-icon"></div><div class="l-taskbar-task-content">' + title + '</div></div>');
- 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;
- if (!type) return null;
- if (control) control = control.substr(0, 1).toUpperCase() + control.substr(1);
- return $.extend({
- create: function (container, editParm, controlOptions)
- {
- //field in form , column in grid
- var field = editParm.field || editParm.column, options = controlOptions || {};
- var p = $.extend({}, e.options);
- var inputBody = $("<input type='text'/>");
- if (e.body)
- {
- inputBody = e.body.clone();
- }
- inputBody.appendTo(container);
- if (editParm.field)
- {
- var txtInputName = field.name;
- if ($.inArray(type, ["select", "combobox", "autocomplete", "popup"]) != -1)
- {
- txtInputName = field.textField || field.comboboxName;
- }
- if ($.inArray(type, ["select", "combobox", "autocomplete", "popup", "radiolist", "checkboxlist", "listbox"]) != -1)
- {
- p.valueFieldID = (options.prefixID || "") + field.name;
- }
- p.id = (options.prefixID || "") + field.name;
- if (!e.body)
- {
- var inputName = (options.prefixID || "") + txtInputName;
- inputBody.attr({
- id: field.id || inputName,
- name: inputName
- });
- }
- $.extend(p, field.options);
- }
- if (field.editor)
- {
- $.extend(p, field.editor.options);
- if (field.editor.valueColumnName) p.valueField = field.editor.valueColumnName;
- if (field.editor.displayColumnName) p.textField = field.editor.displayColumnName;
- if (control)
- {
- var defaults = liger.defaults[control];
- for (var proName in defaults)
- {
- if (proName in field.editor)
- {
- p[proName] = field.editor[proName];
- }
- }
- }
- //可扩展参数,支持动态加载
- var ext = field.editor.p || field.editor.ext;
- ext = typeof (ext) == 'function' ? ext(editParm) : ext;
- $.extend(p, ext);
- }
- //返回的是ligerui对象
- return inputBody['liger' + control](p);
- },
- getValue: function (editor, editParm)
- {
- if (editor.getValue)
- {
- return editor.getValue();
- }
- },
- setValue: function (editor, value, editParm)
- {
- if (editor.setValue)
- {
- editor.setValue(value);
- }
- },
- getText: function (editor, editParm)
- {
- if (editor.getText)
- {
- return editor.getText();
- }
- },
- setText: function (editor, value, editParm)
- {
- if (editor.setText)
- {
- editor.setText(value);
- }
- },
- 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);
- },
- destroy: function (editor, editParm)
- {
- if (editor.destroy) editor.destroy();
- }
- }, 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: $('<div></div>'),
- resize: function (editor, width, height, editParm)
- {
- editor.set('width', width - 2);
- }
- },
- "radiolist": {
- control: 'RadioList',
- body: $('<div></div>'),
- resize: function (editor, width, height, editParm)
- {
- editor.set('width', width - 2);
- }
- },
- "listbox": {
- control: 'ListBox',
- body: $('<div></div>'),
- 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 }
- }
- };
- 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);
|