UU跑腿标准版

base.js 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  1. /**
  2. * jQuery ligerUI 1.2.1
  3. *
  4. * http://ligerui.com
  5. *
  6. * Author daomi 2013 [ gd_star@163.com ]
  7. *
  8. */
  9. (function ($)
  10. {
  11. //ligerui 继承方法
  12. Function.prototype.ligerExtend = function (parent, overrides)
  13. {
  14. if (typeof parent != 'function') return this;
  15. //保存对父类的引用
  16. this.base = parent.prototype;
  17. this.base.constructor = parent;
  18. //继承
  19. var f = function () { };
  20. f.prototype = parent.prototype;
  21. this.prototype = new f();
  22. this.prototype.constructor = this;
  23. //附加属性方法
  24. if (overrides) $.extend(this.prototype, overrides);
  25. };
  26. //延时加载
  27. Function.prototype.ligerDefer = function (o, defer, args)
  28. {
  29. var fn = this;
  30. return setTimeout(function () { fn.apply(o, args || []); }, defer);
  31. };
  32. // 核心对象
  33. window.liger = $.ligerui = {
  34. version: 'V1.2.0',
  35. managerCount: 0,
  36. //组件管理器池
  37. managers: {},
  38. managerIdPrev: 'ligerui',
  39. //管理器id已经存在时自动创建新的
  40. autoNewId: true,
  41. //错误提示
  42. error: {
  43. managerIsExist: '管理器id已经存在'
  44. },
  45. pluginPrev: 'liger',
  46. getId: function (prev)
  47. {
  48. prev = prev || this.managerIdPrev;
  49. var id = prev + (1000 + this.managerCount);
  50. this.managerCount++;
  51. return id;
  52. },
  53. add: function (manager)
  54. {
  55. if (arguments.length == 2)
  56. {
  57. var m = arguments[1];
  58. m.id = m.id || m.options.id || arguments[0].id;
  59. this.addManager(m);
  60. return;
  61. }
  62. if (!manager.id) manager.id = this.getId(manager.__idPrev());
  63. if (this.managers[manager.id]) manager.id = this.getId(manager.__idPrev());
  64. if (this.managers[manager.id])
  65. {
  66. throw new Error(this.error.managerIsExist);
  67. }
  68. this.managers[manager.id] = manager;
  69. },
  70. remove: function (arg)
  71. {
  72. if (typeof arg == "string" || typeof arg == "number")
  73. {
  74. delete liger.managers[arg];
  75. }
  76. else if (typeof arg == "object")
  77. {
  78. if (arg instanceof liger.core.Component)
  79. {
  80. delete liger.managers[arg.id];
  81. }
  82. else
  83. {
  84. if (!$(arg).attr(this.idAttrName)) return false;
  85. delete liger.managers[$(arg).attr(this.idAttrName)];
  86. }
  87. }
  88. },
  89. //获取ligerui对象
  90. //1,传入ligerui ID
  91. //2,传入Dom Object
  92. get: function (arg, idAttrName)
  93. {
  94. idAttrName = idAttrName || "ligeruiid";
  95. if (typeof arg == "string" || typeof arg == "number")
  96. {
  97. return liger.managers[arg];
  98. }
  99. else if (typeof arg == "object")
  100. {
  101. var domObj = arg.length ? arg[0] : arg;
  102. var id = domObj[idAttrName] || $(domObj).attr(idAttrName);
  103. if (!id) return null;
  104. return liger.managers[id];
  105. }
  106. return null;
  107. },
  108. //根据类型查找某一个对象
  109. find: function (type)
  110. {
  111. var arr = [];
  112. for (var id in this.managers)
  113. {
  114. var manager = this.managers[id];
  115. if (type instanceof Function)
  116. {
  117. if (manager instanceof type)
  118. {
  119. arr.push(manager);
  120. }
  121. }
  122. else if (type instanceof Array)
  123. {
  124. if ($.inArray(manager.__getType(), type) != -1)
  125. {
  126. arr.push(manager);
  127. }
  128. }
  129. else
  130. {
  131. if (manager.__getType() == type)
  132. {
  133. arr.push(manager);
  134. }
  135. }
  136. }
  137. return arr;
  138. },
  139. //$.fn.liger{Plugin} 和 $.fn.ligerGet{Plugin}Manager
  140. //会调用这个方法,并传入作用域(this)
  141. //parm [plugin] 插件名
  142. //parm [args] 参数(数组)
  143. //parm [ext] 扩展参数,定义命名空间或者id属性名
  144. run: function (plugin, args, ext)
  145. {
  146. if (!plugin) return;
  147. ext = $.extend({
  148. defaultsNamespace: 'ligerDefaults',
  149. methodsNamespace: 'ligerMethods',
  150. controlNamespace: 'controls',
  151. idAttrName: 'ligeruiid',
  152. isStatic: false,
  153. hasElement: true, //是否拥有element主体(比如drag、resizable等辅助性插件就不拥有)
  154. propertyToElemnt: null //链接到element的属性名
  155. }, ext || {});
  156. plugin = plugin.replace(/^ligerGet/, '');
  157. plugin = plugin.replace(/^liger/, '');
  158. if (this == null || this == window || ext.isStatic)
  159. {
  160. if (!liger.plugins[plugin])
  161. {
  162. liger.plugins[plugin] = {
  163. fn: $[liger.pluginPrev + plugin],
  164. isStatic: true
  165. };
  166. }
  167. return new $.ligerui[ext.controlNamespace][plugin]($.extend({}, $[ext.defaultsNamespace][plugin] || {}, $[ext.defaultsNamespace][plugin + 'String'] || {}, args.length > 0 ? args[0] : {}));
  168. }
  169. if (!liger.plugins[plugin])
  170. {
  171. liger.plugins[plugin] = {
  172. fn: $.fn[liger.pluginPrev + plugin],
  173. isStatic: false
  174. };
  175. }
  176. if (/Manager$/.test(plugin)) return liger.get(this, ext.idAttrName);
  177. this.each(function ()
  178. {
  179. if (this[ext.idAttrName] || $(this).attr(ext.idAttrName))
  180. {
  181. var manager = liger.get(this[ext.idAttrName] || $(this).attr(ext.idAttrName));
  182. if (manager && args.length > 0) manager.set(args[0]);
  183. //已经执行过
  184. return;
  185. }
  186. if (args.length >= 1 && typeof args[0] == 'string') return;
  187. //只要第一个参数不是string类型,都执行组件的实例化工作
  188. var options = args.length > 0 ? args[0] : null;
  189. var p = $.extend({}, $[ext.defaultsNamespace][plugin], $[ext.defaultsNamespace][plugin + 'String'], options);
  190. if (ext.propertyToElemnt) p[ext.propertyToElemnt] = this;
  191. if (ext.hasElement)
  192. {
  193. new $.ligerui[ext.controlNamespace][plugin](this, p);
  194. }
  195. else
  196. {
  197. new $.ligerui[ext.controlNamespace][plugin](p);
  198. }
  199. });
  200. if (this.length == 0) return null;
  201. if (args.length == 0) return liger.get(this, ext.idAttrName);
  202. if (typeof args[0] == 'object') return liger.get(this, ext.idAttrName);
  203. if (typeof args[0] == 'string')
  204. {
  205. var manager = liger.get(this, ext.idAttrName);
  206. if (manager == null) return;
  207. if (args[0] == "option")
  208. {
  209. if (args.length == 2)
  210. return manager.get(args[1]); //manager get
  211. else if (args.length >= 3)
  212. return manager.set(args[1], args[2]); //manager set
  213. }
  214. else
  215. {
  216. var method = args[0];
  217. if (!manager[method]) return; //不存在这个方法
  218. var parms = Array.apply(null, args);
  219. parms.shift();
  220. return manager[method].apply(manager, parms); //manager method
  221. }
  222. }
  223. return null;
  224. },
  225. //扩展
  226. //1,默认参数
  227. //2,本地化扩展
  228. defaults: {},
  229. //3,方法接口扩展
  230. methods: {},
  231. //命名空间
  232. //核心控件,封装了一些常用方法
  233. core: {},
  234. //命名空间
  235. //组件的集合
  236. controls: {},
  237. //plugin 插件的集合
  238. plugins: {}
  239. };
  240. //扩展对象
  241. $.ligerDefaults = {};
  242. //扩展对象
  243. $.ligerMethos = {};
  244. //关联起来
  245. liger.defaults = $.ligerDefaults;
  246. liger.methods = $.ligerMethos;
  247. //获取ligerui对象
  248. //parm [plugin] 插件名,可为空
  249. $.fn.liger = function (plugin)
  250. {
  251. if (plugin)
  252. {
  253. return liger.run.call(this, plugin, arguments);
  254. }
  255. else
  256. {
  257. return liger.get(this);
  258. }
  259. };
  260. //组件基类
  261. //1,完成定义参数处理方法和参数属性初始化的工作
  262. //2,完成定义事件处理方法和事件属性初始化的工作
  263. liger.core.Component = function (options)
  264. {
  265. //事件容器
  266. this.events = this.events || {};
  267. //配置参数
  268. this.options = options || {};
  269. //子组件集合索引
  270. this.children = {};
  271. };
  272. $.extend(liger.core.Component.prototype, {
  273. __getType: function ()
  274. {
  275. return 'liger.core.Component';
  276. },
  277. __idPrev: function ()
  278. {
  279. return 'ligerui';
  280. },
  281. //设置属性
  282. // arg 属性名 value 属性值
  283. // arg 属性/值 value 是否只设置事件
  284. set: function (arg, value)
  285. {
  286. if (!arg) return;
  287. if (typeof arg == 'object')
  288. {
  289. var tmp;
  290. if (this.options != arg)
  291. {
  292. $.extend(this.options, arg);
  293. tmp = arg;
  294. }
  295. else
  296. {
  297. tmp = $.extend({}, arg);
  298. }
  299. if (value == undefined || value == true)
  300. {
  301. for (var p in tmp)
  302. {
  303. if (p.indexOf('on') == 0)
  304. this.set(p, tmp[p]);
  305. }
  306. }
  307. if (value == undefined || value == false)
  308. {
  309. for (var p in tmp)
  310. {
  311. if (p.indexOf('on') != 0)
  312. this.set(p, tmp[p]);
  313. }
  314. }
  315. return;
  316. }
  317. var name = arg;
  318. //事件参数
  319. if (name.indexOf('on') == 0)
  320. {
  321. if (typeof value == 'function')
  322. this.bind(name.substr(2), value);
  323. return;
  324. }
  325. if (!this.options) this.options = {};
  326. if (this.trigger('propertychange', [arg, value]) == false) return;
  327. this.options[name] = value;
  328. var pn = '_set' + name.substr(0, 1).toUpperCase() + name.substr(1);
  329. if (this[pn])
  330. {
  331. this[pn].call(this, value);
  332. }
  333. this.trigger('propertychanged', [arg, value]);
  334. },
  335. //获取属性
  336. get: function (name)
  337. {
  338. var pn = '_get' + name.substr(0, 1).toUpperCase() + name.substr(1);
  339. if (this[pn])
  340. {
  341. return this[pn].call(this, name);
  342. }
  343. return this.options[name];
  344. },
  345. hasBind: function (arg)
  346. {
  347. var name = arg.toLowerCase();
  348. var event = this.events[name];
  349. if (event && event.length) return true;
  350. return false;
  351. },
  352. //触发事件
  353. //data (可选) Array(可选)传递给事件处理函数的附加参数
  354. trigger: function (arg, data)
  355. {
  356. if (!arg) return;
  357. var name = arg.toLowerCase();
  358. var event = this.events[name];
  359. if (!event) return;
  360. data = data || [];
  361. if ((data instanceof Array) == false)
  362. {
  363. data = [data];
  364. }
  365. for (var i = 0; i < event.length; i++)
  366. {
  367. var ev = event[i];
  368. if (ev.handler.apply(ev.context, data) == false)
  369. return false;
  370. }
  371. },
  372. //绑定事件
  373. bind: function (arg, handler, context)
  374. {
  375. if (typeof arg == 'object')
  376. {
  377. for (var p in arg)
  378. {
  379. this.bind(p, arg[p]);
  380. }
  381. return;
  382. }
  383. if (typeof handler != 'function') return false;
  384. var name = arg.toLowerCase();
  385. var event = this.events[name] || [];
  386. context = context || this;
  387. event.push({ handler: handler, context: context });
  388. this.events[name] = event;
  389. },
  390. //取消绑定
  391. unbind: function (arg, handler)
  392. {
  393. if (!arg)
  394. {
  395. this.events = {};
  396. return;
  397. }
  398. var name = arg.toLowerCase();
  399. var event = this.events[name];
  400. if (!event || !event.length) return;
  401. if (!handler)
  402. {
  403. delete this.events[name];
  404. }
  405. else
  406. {
  407. for (var i = 0, l = event.length; i < l; i++)
  408. {
  409. if (event[i].handler == handler)
  410. {
  411. event.splice(i, 1);
  412. break;
  413. }
  414. }
  415. }
  416. },
  417. destroy: function ()
  418. {
  419. liger.remove(this);
  420. }
  421. });
  422. //界面组件基类,
  423. //1,完成界面初始化:设置组件id并存入组件管理器池,初始化参数
  424. //2,渲染的工作,细节交给子类实现
  425. //parm [element] 组件对应的dom element对象
  426. //parm [options] 组件的参数
  427. liger.core.UIComponent = function (element, options)
  428. {
  429. liger.core.UIComponent.base.constructor.call(this, options);
  430. var extendMethods = this._extendMethods();
  431. if (extendMethods) $.extend(this, extendMethods);
  432. this.element = element;
  433. this._init();
  434. this._preRender();
  435. this.trigger('render');
  436. this._render();
  437. this.trigger('rendered');
  438. this._rendered();
  439. };
  440. liger.core.UIComponent.ligerExtend(liger.core.Component, {
  441. __getType: function ()
  442. {
  443. return 'liger.core.UIComponent';
  444. },
  445. //扩展方法
  446. _extendMethods: function ()
  447. {
  448. },
  449. _init: function ()
  450. {
  451. this.type = this.__getType();
  452. if (!this.element)
  453. {
  454. this.id = this.options.id || liger.getId(this.__idPrev());
  455. }
  456. else
  457. {
  458. this.id = this.options.id || this.element.id || liger.getId(this.__idPrev());
  459. }
  460. //存入管理器池
  461. liger.add(this);
  462. if (!this.element) return;
  463. //读取attr方法,并加载到参数,比如['url']
  464. var attributes = this.attr();
  465. if (attributes && attributes instanceof Array)
  466. {
  467. for (var i = 0; i < attributes.length; i++)
  468. {
  469. var name = attributes[i];
  470. this.options[name] = $(this.element).attr(name);
  471. }
  472. }
  473. //读取ligerui这个属性,并加载到参数,比如 ligerui = "width:120,heigth:100"
  474. var p = this.options;
  475. if ($(this.element).attr("ligerui"))
  476. {
  477. try
  478. {
  479. var attroptions = $(this.element).attr("ligerui");
  480. if (attroptions.indexOf('{') != 0) attroptions = "{" + attroptions + "}";
  481. eval("attroptions = " + attroptions + ";");
  482. if (attroptions) $.extend(p, attroptions);
  483. }
  484. catch (e) { }
  485. }
  486. },
  487. //预渲染,可以用于继承扩展
  488. _preRender: function ()
  489. {
  490. },
  491. _render: function ()
  492. {
  493. },
  494. _rendered: function ()
  495. {
  496. if (this.element)
  497. {
  498. $(this.element).attr("ligeruiid", this.id);
  499. }
  500. },
  501. //返回要转换成ligerui参数的属性,比如['url']
  502. attr: function ()
  503. {
  504. return [];
  505. },
  506. destroy: function ()
  507. {
  508. if (this.element)
  509. {
  510. $(this.element).remove();
  511. }
  512. this.options = null;
  513. liger.remove(this);
  514. }
  515. });
  516. //表单控件基类
  517. liger.controls.Input = function (element, options)
  518. {
  519. liger.controls.Input.base.constructor.call(this, element, options);
  520. };
  521. liger.controls.Input.ligerExtend(liger.core.UIComponent, {
  522. __getType: function ()
  523. {
  524. return 'liger.controls.Input';
  525. },
  526. attr: function ()
  527. {
  528. return ['nullText'];
  529. },
  530. setValue: function (value)
  531. {
  532. return this.set('value', value);
  533. },
  534. getValue: function ()
  535. {
  536. return this.get('value');
  537. },
  538. //设置只读
  539. _setReadonly: function (readonly)
  540. {
  541. var wrapper = this.wrapper || this.text;
  542. if (!wrapper || !wrapper.hasClass("l-text")) return;
  543. var inputText = this.inputText;
  544. if (readonly)
  545. {
  546. if (inputText) inputText.attr("readonly", "readonly");
  547. wrapper.addClass("l-text-readonly");
  548. } else
  549. {
  550. if (inputText) inputText.removeAttr("readonly");
  551. wrapper.removeClass("l-text-readonly");
  552. }
  553. },
  554. setEnabled: function ()
  555. {
  556. return this.set('disabled', false);
  557. },
  558. setDisabled: function ()
  559. {
  560. return this.set('disabled', true);
  561. },
  562. updateStyle: function ()
  563. {
  564. },
  565. resize: function (width, height)
  566. {
  567. this.set({ width: width, height: height });
  568. }
  569. });
  570. //全局窗口对象
  571. liger.win = {
  572. //顶端显示
  573. top: false,
  574. //遮罩
  575. mask: function (win)
  576. {
  577. function setHeight()
  578. {
  579. if (!liger.win.windowMask) return;
  580. var h = $(window).height() + $(window).scrollTop();
  581. liger.win.windowMask.height(h);
  582. }
  583. if (!this.windowMask)
  584. {
  585. this.windowMask = $("<div class='l-window-mask' style='display: block;'></div>").appendTo('body');
  586. $(window).bind('resize.ligeruiwin', setHeight);
  587. $(window).bind('scroll', setHeight);
  588. }
  589. this.windowMask.show();
  590. setHeight();
  591. this.masking = true;
  592. },
  593. //取消遮罩
  594. unmask: function (win)
  595. {
  596. var jwins = $("body > .l-dialog:visible,body > .l-window:visible");
  597. for (var i = 0, l = jwins.length; i < l; i++)
  598. {
  599. var winid = jwins.eq(i).attr("ligeruiid");
  600. if (win && win.id == winid) continue;
  601. //获取ligerui对象
  602. var winmanager = liger.get(winid);
  603. if (!winmanager) continue;
  604. //是否模态窗口
  605. var modal = winmanager.get('modal');
  606. //如果存在其他模态窗口,那么不会取消遮罩
  607. if (modal) return;
  608. }
  609. if (this.windowMask)
  610. this.windowMask.hide();
  611. this.masking = false;
  612. },
  613. //显示任务栏
  614. createTaskbar: function ()
  615. {
  616. if (!this.taskbar)
  617. {
  618. this.taskbar = $('<div class="l-taskbar"><div class="l-taskbar-tasks"></div><div class="l-clear"></div></div>').appendTo('body');
  619. if (this.top) this.taskbar.addClass("l-taskbar-top");
  620. this.taskbar.tasks = $(".l-taskbar-tasks:first", this.taskbar);
  621. this.tasks = {};
  622. }
  623. this.taskbar.show();
  624. this.taskbar.animate({ bottom: 0 });
  625. return this.taskbar;
  626. },
  627. //关闭任务栏
  628. removeTaskbar: function ()
  629. {
  630. var self = this;
  631. self.taskbar.animate({ bottom: -32 }, function ()
  632. {
  633. self.taskbar.remove();
  634. self.taskbar = null;
  635. });
  636. },
  637. activeTask: function (win)
  638. {
  639. for (var winid in this.tasks)
  640. {
  641. var t = this.tasks[winid];
  642. if (winid == win.id)
  643. {
  644. t.addClass("l-taskbar-task-active");
  645. }
  646. else
  647. {
  648. t.removeClass("l-taskbar-task-active");
  649. }
  650. }
  651. },
  652. //获取任务
  653. getTask: function (win)
  654. {
  655. var self = this;
  656. if (!self.taskbar) return;
  657. if (self.tasks[win.id]) return self.tasks[win.id];
  658. return null;
  659. },
  660. //增加任务
  661. addTask: function (win)
  662. {
  663. var self = this;
  664. if (!self.taskbar) self.createTaskbar();
  665. if (self.tasks[win.id]) return self.tasks[win.id];
  666. var title = win.get('title');
  667. 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>');
  668. self.taskbar.tasks.append(task);
  669. self.activeTask(win);
  670. task.bind('click', function ()
  671. {
  672. self.activeTask(win);
  673. if (win.actived)
  674. win.min();
  675. else
  676. win.active();
  677. }).hover(function ()
  678. {
  679. $(this).addClass("l-taskbar-task-over");
  680. }, function ()
  681. {
  682. $(this).removeClass("l-taskbar-task-over");
  683. });
  684. return task;
  685. },
  686. hasTask: function ()
  687. {
  688. for (var p in this.tasks)
  689. {
  690. if (this.tasks[p])
  691. return true;
  692. }
  693. return false;
  694. },
  695. //移除任务
  696. removeTask: function (win)
  697. {
  698. var self = this;
  699. if (!self.taskbar) return;
  700. if (self.tasks[win.id])
  701. {
  702. self.tasks[win.id].unbind();
  703. self.tasks[win.id].remove();
  704. delete self.tasks[win.id];
  705. }
  706. if (!self.hasTask())
  707. {
  708. self.removeTaskbar();
  709. }
  710. },
  711. //前端显示
  712. setFront: function (win)
  713. {
  714. var wins = liger.find(liger.core.Win);
  715. for (var i in wins)
  716. {
  717. var w = wins[i];
  718. if (w == win)
  719. {
  720. $(w.element).css("z-index", "9200");
  721. this.activeTask(w);
  722. }
  723. else
  724. {
  725. $(w.element).css("z-index", "9100");
  726. }
  727. }
  728. }
  729. };
  730. //窗口基类 window、dialog
  731. liger.core.Win = function (element, options)
  732. {
  733. liger.core.Win.base.constructor.call(this, element, options);
  734. };
  735. liger.core.Win.ligerExtend(liger.core.UIComponent, {
  736. __getType: function ()
  737. {
  738. return 'liger.controls.Win';
  739. },
  740. mask: function ()
  741. {
  742. if (this.options.modal)
  743. liger.win.mask(this);
  744. },
  745. unmask: function ()
  746. {
  747. if (this.options.modal)
  748. liger.win.unmask(this);
  749. },
  750. min: function ()
  751. {
  752. },
  753. max: function ()
  754. {
  755. },
  756. active: function ()
  757. {
  758. }
  759. });
  760. liger.draggable = {
  761. dragging: false
  762. };
  763. liger.resizable = {
  764. reszing: false
  765. };
  766. liger.toJSON = typeof JSON === 'object' && JSON.stringify ? JSON.stringify : function (o)
  767. {
  768. var f = function (n)
  769. {
  770. return n < 10 ? '0' + n : n;
  771. },
  772. escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  773. quote = function (value)
  774. {
  775. escapable.lastIndex = 0;
  776. return escapable.test(value) ?
  777. '"' + value.replace(escapable, function (a)
  778. {
  779. var c = meta[a];
  780. return typeof c === 'string' ? c :
  781. '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  782. }) + '"' :
  783. '"' + value + '"';
  784. };
  785. if (o === null) return 'null';
  786. var type = typeof o;
  787. if (type === 'undefined') return undefined;
  788. if (type === 'string') return quote(o);
  789. if (type === 'number' || type === 'boolean') return '' + o;
  790. if (type === 'object')
  791. {
  792. if (typeof o.toJSON === 'function')
  793. {
  794. return liger.toJSON(o.toJSON());
  795. }
  796. if (o.constructor === Date)
  797. {
  798. return isFinite(this.valueOf()) ?
  799. this.getUTCFullYear() + '-' +
  800. f(this.getUTCMonth() + 1) + '-' +
  801. f(this.getUTCDate()) + 'T' +
  802. f(this.getUTCHours()) + ':' +
  803. f(this.getUTCMinutes()) + ':' +
  804. f(this.getUTCSeconds()) + 'Z' : null;
  805. }
  806. var pairs = [];
  807. if (o.constructor === Array)
  808. {
  809. for (var i = 0, l = o.length; i < l; i++)
  810. {
  811. pairs.push(liger.toJSON(o[i]) || 'null');
  812. }
  813. return '[' + pairs.join(',') + ']';
  814. }
  815. var name, val;
  816. for (var k in o)
  817. {
  818. type = typeof k;
  819. if (type === 'number')
  820. {
  821. name = '"' + k + '"';
  822. } else if (type === 'string')
  823. {
  824. name = quote(k);
  825. } else
  826. {
  827. continue;
  828. }
  829. type = typeof o[k];
  830. if (type === 'function' || type === 'undefined')
  831. {
  832. continue;
  833. }
  834. val = liger.toJSON(o[k]);
  835. pairs.push(name + ':' + val);
  836. }
  837. return '{' + pairs.join(',') + '}';
  838. }
  839. };
  840. //获取 默认的编辑构造器
  841. liger.getEditor = function (e)
  842. {
  843. var type = e.type, control = e.control;
  844. if (!type) return null;
  845. if (control) control = control.substr(0, 1).toUpperCase() + control.substr(1);
  846. return $.extend({
  847. create: function (container, editParm, controlOptions)
  848. {
  849. //field in form , column in grid
  850. var field = editParm.field || editParm.column, options = controlOptions || {};
  851. var p = $.extend({}, e.options);
  852. var inputBody = $("<input type='text'/>");
  853. if (e.body)
  854. {
  855. inputBody = e.body.clone();
  856. }
  857. inputBody.appendTo(container);
  858. if (editParm.field)
  859. {
  860. var txtInputName = field.name;
  861. if ($.inArray(type, ["select", "combobox", "autocomplete", "popup"]) != -1)
  862. {
  863. txtInputName = field.textField || field.comboboxName;
  864. }
  865. if ($.inArray(type, ["select", "combobox", "autocomplete", "popup", "radiolist", "checkboxlist", "listbox"]) != -1)
  866. {
  867. p.valueFieldID = (options.prefixID || "") + field.name;
  868. }
  869. p.id = (options.prefixID || "") + field.name;
  870. if (!e.body)
  871. {
  872. var inputName = (options.prefixID || "") + txtInputName;
  873. inputBody.attr({
  874. id: field.id || inputName,
  875. name: inputName
  876. });
  877. }
  878. $.extend(p, field.options);
  879. }
  880. if (field.editor)
  881. {
  882. $.extend(p, field.editor.options);
  883. if (field.editor.valueColumnName) p.valueField = field.editor.valueColumnName;
  884. if (field.editor.displayColumnName) p.textField = field.editor.displayColumnName;
  885. if (control)
  886. {
  887. var defaults = liger.defaults[control];
  888. for (var proName in defaults)
  889. {
  890. if (proName in field.editor)
  891. {
  892. p[proName] = field.editor[proName];
  893. }
  894. }
  895. }
  896. //可扩展参数,支持动态加载
  897. var ext = field.editor.p || field.editor.ext;
  898. ext = typeof (ext) == 'function' ? ext(editParm) : ext;
  899. $.extend(p, ext);
  900. }
  901. //返回的是ligerui对象
  902. return inputBody['liger' + control](p);
  903. },
  904. getValue: function (editor, editParm)
  905. {
  906. if (editor.getValue)
  907. {
  908. return editor.getValue();
  909. }
  910. },
  911. setValue: function (editor, value, editParm)
  912. {
  913. if (editor.setValue)
  914. {
  915. editor.setValue(value);
  916. }
  917. },
  918. getText: function (editor, editParm)
  919. {
  920. if (editor.getText)
  921. {
  922. return editor.getText();
  923. }
  924. },
  925. setText: function (editor, value, editParm)
  926. {
  927. if (editor.setText)
  928. {
  929. editor.setText(value);
  930. }
  931. },
  932. getSelected: function (editor, editParm)
  933. {
  934. if (editor.getSelected)
  935. {
  936. return editor.getSelected();
  937. }
  938. },
  939. resize: function (editor, width, height, editParm)
  940. {
  941. if (editParm.field) width = width - 2;
  942. if (editor.resize) editor.resize(width, height);
  943. },
  944. destroy: function (editor, editParm)
  945. {
  946. if (editor.destroy) editor.destroy();
  947. }
  948. }, e);
  949. }
  950. //几个默认的编辑器构造函数
  951. liger.editors = {
  952. "text": {
  953. control: 'TextBox'
  954. },
  955. "date": {
  956. control: 'DateEditor',
  957. setValue: function (editor, value, editParm)
  958. {
  959. // /Date(1328423451489)/
  960. if (typeof value == "string" && /^\/Date/.test(value))
  961. {
  962. value = value.replace(/^\//, "new ").replace(/\/$/, "");
  963. eval("value = " + value);
  964. }
  965. editor.setValue(value);
  966. }
  967. },
  968. "combobox": {
  969. control: 'ComboBox'
  970. },
  971. "spinner": {
  972. control: 'Spinner'
  973. },
  974. "checkbox": {
  975. control: 'CheckBox'
  976. },
  977. "checkboxlist": {
  978. control: 'CheckBoxList',
  979. body: $('<div></div>'),
  980. resize: function (editor, width, height, editParm)
  981. {
  982. editor.set('width', width - 2);
  983. }
  984. },
  985. "radiolist": {
  986. control: 'RadioList',
  987. body: $('<div></div>'),
  988. resize: function (editor, width, height, editParm)
  989. {
  990. editor.set('width', width - 2);
  991. }
  992. },
  993. "listbox": {
  994. control: 'ListBox',
  995. body: $('<div></div>'),
  996. resize: function (editor, width, height, editParm)
  997. {
  998. editor.set('width', width - 2);
  999. }
  1000. },
  1001. "popup": {
  1002. control: 'PopupEdit'
  1003. },
  1004. "number": {
  1005. control: 'TextBox',
  1006. options: { number: true }
  1007. },
  1008. "currency": {
  1009. control: 'TextBox',
  1010. options: { currency: true }
  1011. },
  1012. "digits": {
  1013. control: 'TextBox',
  1014. options: { digits: true }
  1015. }
  1016. };
  1017. liger.editors["string"] = liger.editors["text"];
  1018. liger.editors["select"] = liger.editors["combobox"];
  1019. liger.editors["int"] = liger.editors["digits"];
  1020. liger.editors["float"] = liger.editors["number"];
  1021. liger.editors["chk"] = liger.editors["checkbox"];
  1022. liger.editors["popupedit"] = liger.editors["popup"];
  1023. //jQuery version fix
  1024. $.fn.live = $.fn.on ? $.fn.on : $.fn.live;
  1025. if (!$.browser)
  1026. {
  1027. var userAgent = navigator.userAgent.toLowerCase();
  1028. $.browser = {
  1029. version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [0, '0'])[1],
  1030. safari: /webkit/.test(userAgent),
  1031. opera: /opera/.test(userAgent),
  1032. msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
  1033. mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
  1034. };
  1035. }
  1036. })(jQuery);