o2.js 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347
  1. /** ***** BEGIN LICENSE BLOCK *****
  2. * |------------------------------------------------------------------------------|
  3. * | O2OA 活力办公 创意无限 o2.js |
  4. * |------------------------------------------------------------------------------|
  5. * | Distributed under the AGPL license: |
  6. * |------------------------------------------------------------------------------|
  7. * | Copyright © 2018, o2oa.net, o2server.io O2 Team |
  8. * | All rights reserved. |
  9. * |------------------------------------------------------------------------------|
  10. *
  11. * This file is part of O2OA.
  12. *
  13. * O2OA is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as published by
  15. * the Free Software Foundation, either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * O2OA is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
  25. *
  26. * ***** END LICENSE BLOCK ******/
  27. /* load o2 Core
  28. * |------------------------------------------------------------------------------|
  29. * |addReady: o2.addReady(fn), |
  30. * |------------------------------------------------------------------------------|
  31. * |load: o2.load(urls, callback, reload) |
  32. * |loadCss: o2.loadCss(urls, dom, callback, reload, doc) |
  33. * |------------------------------------------------------------------------------|
  34. * |typeOf: o2.typeOf(o) |
  35. * |------------------------------------------------------------------------------|
  36. * |uuid: o2.uuid() |
  37. * |------------------------------------------------------------------------------|
  38. */
  39. //Element.firstElementChild Polyfill
  40. (function(constructor) {
  41. if (constructor &&
  42. constructor.prototype &&
  43. constructor.prototype.firstElementChild == null) {
  44. Object.defineProperty(constructor.prototype, 'firstElementChild', {
  45. get: function() {
  46. var node, nodes = this.childNodes, i = 0;
  47. while (node = nodes[i++]) {
  48. if (node.nodeType === 1) {
  49. return node;
  50. }
  51. }
  52. return null;
  53. }
  54. });
  55. }
  56. })(window.Node || window.Element);
  57. (function(){
  58. var _href = window.location.href;
  59. var _debug = (_href.indexOf("debugger")!==-1);
  60. var _par = _href.substr(_href.lastIndexOf("?")+1, _href.length);
  61. var _lp = "zh-cn";
  62. if (_par){
  63. var _parList = _par.split("&");
  64. for (var i=0; i<_parList.length; i++){
  65. var _v = _parList[i];
  66. var _kv = _v.split("=");
  67. if (_kv[0].toLowerCase()==="lg") _lp = _kv[1];
  68. if (_kv[0].toLowerCase()==="lp") _lp = _kv[1];
  69. }
  70. }
  71. this.o2 = window.o2 || {};
  72. this.o2.version = {
  73. "v": "5.1.1",
  74. "build": "2020.06.12",
  75. "info": "O2OA 活力办公 创意无限. Copyright © 2020, o2oa.net O2 Team All rights reserved."
  76. };
  77. if (!this.o2.session) this.o2.session ={
  78. "isDebugger": _debug,
  79. "path": "../o2_core/o2"
  80. };
  81. this.o2.language = _lp;
  82. this.o2.splitStr = /\s*(?:,|;)\s*/;
  83. // this.o2 = {
  84. // "version": {
  85. // "v": "2.3.1",
  86. // "build": "2019.07.31",
  87. // "info": "O2OA 活力办公 创意无限. Copyright © 2018, o2oa.net O2 Team All rights reserved."
  88. // },
  89. // "session": {
  90. // "isDebugger": _debug,
  91. // "path": "../o2_core/o2"
  92. // },
  93. // "language": _lp,
  94. // "splitStr": /\s*(?:,|;)\s*/
  95. // };
  96. this.wrdp = this.o2;
  97. var debug = function(reload){
  98. if (reload){
  99. window.location.assign(_href + ((_href.indexOf("?")==-1) ? "?" : "&")+"debugger");
  100. }else{
  101. if (!o2.session.isDebugger){
  102. o2.session.isDebugger = true;
  103. if (o2.session.isMobile || layout.mobile) o2.load("../o2_lib/eruda/eruda.js");
  104. }
  105. }
  106. };
  107. this.o2.debug = debug;
  108. var _attempt = function(){
  109. for (var i = 0, l = arguments.length; i < l; i++){
  110. try {
  111. arguments[i]();
  112. return arguments[i];
  113. } catch (e){}
  114. }
  115. return null;
  116. };
  117. var _typeOf = function(item){
  118. if (item == null) return 'null';
  119. if (item.$family != null) return item.$family();
  120. if (item.constructor == window.Array) return "array";
  121. if (item.nodeName){
  122. if (item.nodeType == 1) return 'element';
  123. if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace';
  124. } else if (typeof item.length == 'number'){
  125. if (item.callee) return 'arguments';
  126. }
  127. return typeof item;
  128. };
  129. this.o2.typeOf = _typeOf;
  130. var _addListener = function(dom, type, fn){
  131. if (type == 'unload'){
  132. var old = fn, self = this;
  133. fn = function(){
  134. _removeListener(dom, 'unload', fn);
  135. old();
  136. };
  137. }
  138. if (dom.addEventListener) dom.addEventListener(type, fn, !!arguments[2]);
  139. else dom.attachEvent('on' + type, fn);
  140. };
  141. var _removeListener = function(dom, type, fn){
  142. if (dom.removeEventListener) dom.removeEventListener(type, fn, !!arguments[2]);
  143. else dom.detachEvent('on' + type, fn);
  144. };
  145. //http request class
  146. var _request = (function(){
  147. var XMLHTTP = function(){ return new XMLHttpRequest(); };
  148. var MSXML2 = function(){ return new ActiveXObject('MSXML2.XMLHTTP'); };
  149. var MSXML = function(){ return new ActiveXObject('Microsoft.XMLHTTP'); };
  150. return _attempt(XMLHTTP, MSXML2, MSXML);
  151. })();
  152. this.o2.request = _request;
  153. var _returnBase = function(number, base) {
  154. return (number).toString(base).toUpperCase();
  155. };
  156. var _getIntegerBits = function(val, start, end){
  157. var base16 = _returnBase(val, 16);
  158. var quadArray = new Array();
  159. var quadString = '';
  160. var i = 0;
  161. for (i = 0; i < base16.length; i++) {
  162. quadArray.push(base16.substring(i, i + 1));
  163. }
  164. for (i = Math.floor(start / 4); i <= Math.floor(end / 4); i++) {
  165. if (!quadArray[i] || quadArray[i] == '')
  166. quadString += '0';
  167. else
  168. quadString += quadArray[i];
  169. }
  170. return quadString;
  171. };
  172. var _rand = function(max) {
  173. return Math.floor(Math.random() * (max + 1));
  174. };
  175. this.o2.addListener = _addListener;
  176. this.o2.removeListener = _removeListener;
  177. //uuid
  178. var _uuid = function(){
  179. var dg = new Date(1582, 10, 15, 0, 0, 0, 0);
  180. var dc = new Date();
  181. var t = dc.getTime() - dg.getTime();
  182. var tl = _getIntegerBits(t, 0, 31);
  183. var tm = _getIntegerBits(t, 32, 47);
  184. var thv = _getIntegerBits(t, 48, 59) + '1';
  185. var csar = _getIntegerBits(_rand(4095), 0, 7);
  186. var csl = _getIntegerBits(_rand(4095), 0, 7);
  187. var n = _getIntegerBits(_rand(8191), 0, 7)
  188. + _getIntegerBits(_rand(8191), 8, 15)
  189. + _getIntegerBits(_rand(8191), 0, 7)
  190. + _getIntegerBits(_rand(8191), 8, 15)
  191. + _getIntegerBits(_rand(8191), 0, 15);
  192. return tl + tm + thv + csar + csl + n;
  193. };
  194. this.o2.uuid = _uuid;
  195. var _runCallback = function(callback, key, par){
  196. if (typeOf(callback).toLowerCase() === 'function'){
  197. if (key.toLowerCase()==="success") callback.apply(callback, par);
  198. }else{
  199. if (typeOf(callback).toLowerCase()==='object'){
  200. var name = ("on-"+key).camelCase();
  201. if (callback[name]) callback[name].apply(callback, par);
  202. }
  203. }
  204. };
  205. this.o2.runCallback = _runCallback;
  206. //load js, css, html adn all.
  207. var _getAllOptions = function(options){
  208. var doc = (options && options.doc) || document;
  209. if (!doc.unid) doc.unid = _uuid();
  210. var type = (options && options.type) || "text/javascript";
  211. return {
  212. "noCache": !!(options && options.nocache),
  213. "reload": !!(options && options.reload),
  214. "sequence": !!(options && options.sequence),
  215. "type": type,
  216. "doc": doc,
  217. "dom": (options && options.dom) || document.body,
  218. "module": (options && options.module) || null,
  219. "noConflict": (options && options.noConflict) || false,
  220. "bind": (options && options.bind) || null,
  221. "position": (options && options.position) || "beforeend" //'beforebegin' 'afterbegin' 'beforeend' 'afterend'debugger
  222. }
  223. };
  224. var _getCssOptions = function(options){
  225. var doc = (options && options.doc) || document;
  226. if (!doc.unid) doc.unid = _uuid();
  227. return {
  228. "noCache": !!(options && options.nocache),
  229. "reload": !!(options && options.reload),
  230. "sequence": !!(options && options.sequence),
  231. "doc": doc,
  232. "dom": (options && options.dom) || null
  233. }
  234. };
  235. var _getJsOptions = function(options){
  236. var doc = (options && options.doc) || document;
  237. if (!doc.unid) doc.unid = _uuid();
  238. var type = (options && options.type) || "text/javascript";
  239. return {
  240. "noCache": !!(options && options.nocache),
  241. "reload": !!(options && options.reload),
  242. "sequence": (!(options && options.sequence == false)),
  243. "type": type,
  244. "doc": doc
  245. }
  246. };
  247. var _getHtmlOptions = function(options){
  248. var doc = (options && options.doc) || document;
  249. if (!doc.unid) doc.unid = _uuid();
  250. return {
  251. "noCache": !!(options && options.nocache),
  252. "reload": !!(options && options.reload),
  253. "sequence": !!(options && options.sequence),
  254. "doc": doc,
  255. "dom": (options && options.dom) || null,
  256. "module": (options && options.module) || null,
  257. "noConflict": (options && options.noConflict) || false,
  258. "bind": (options && options.bind) || null,
  259. "position": (options && options.position) || "beforeend" //'beforebegin' 'afterbegin' 'beforeend' 'afterend'
  260. }
  261. };
  262. _filterUrl = function(url){
  263. if (o2.base){
  264. if (url.indexOf(":")===-1){
  265. var s = url.substring(0, url.indexOf("/")+1);
  266. var r = url.substring(url.indexOf("/")+1, url.length);
  267. if ("../"===s || "./"===s || "/"===s){
  268. return s+o2.base+r;
  269. }else{
  270. return o2.base+url
  271. }
  272. }
  273. }
  274. // if (!window.layout) window.layout = {};
  275. // if (!window.layout.config){
  276. // new Request.JSON({
  277. // url: "../x_desktop/res/config/config.json",
  278. // secure: false,
  279. // method: "get",
  280. // noCache: true,
  281. // async: false,
  282. // onSuccess: function(responseJSON, responseText){
  283. // window.layout.config = responseJSON;
  284. // }.bind(this),
  285. // }).send();
  286. // }
  287. if (window.layout && layout.config && layout.config.urlMapping){
  288. for (var k in layout.config.urlMapping){
  289. var regex = new RegExp(k);
  290. if (regex.test(url)){
  291. return url.replace(regex, layout.config.urlMapping[k]);
  292. }
  293. }
  294. }
  295. return url;
  296. };
  297. this.o2.filterUrl = _filterUrl;
  298. var _xhr_get = function(url, success, failure, completed){
  299. var xhr = new _request();
  300. url = _filterUrl(url);
  301. xhr.open("GET", url, true);
  302. var _checkCssLoaded= function(_, err){
  303. if (!(xhr.readyState == 4)) return;
  304. if (err){
  305. if (completed) completed(xhr);
  306. return;
  307. }
  308. _removeListener(xhr, 'readystatechange', _checkCssLoaded);
  309. _removeListener(xhr, 'load', _checkCssLoaded);
  310. _removeListener(xhr, 'error', _checkCssErrorLoaded);
  311. if (err) {if (failure) failure(xhr); return}
  312. var status = xhr.status;
  313. status = (status == 1223) ? 204 : status;
  314. if ((status >= 200 && status < 300))
  315. if (success) success(xhr);
  316. else if ((status >= 300 && status < 400))
  317. if (failure) failure(xhr);
  318. else
  319. failure(xhr);
  320. if (completed) completed(xhr);
  321. };
  322. var _checkCssErrorLoaded= function(err){ _checkCssLoaded(err) };
  323. if ("load" in xhr) _addListener(xhr, "load", _checkCssLoaded);
  324. if ("error" in xhr) _addListener(xhr, "load", _checkCssErrorLoaded);
  325. _addListener(xhr, "readystatechange", _checkCssLoaded);
  326. xhr.send();
  327. };
  328. this.o2.xhr_get = _xhr_get;
  329. var _loadSequence = function(ms, cb, op, n, thisLoaded, loadSingle, uuid, fun){
  330. loadSingle(ms[n], function(module){
  331. if (module) thisLoaded.push(module);
  332. n++;
  333. if (fun) fun(module);
  334. if (n===ms.length){
  335. if (cb) cb(thisLoaded);
  336. }else{
  337. _loadSequence(ms, cb, op, n, thisLoaded, loadSingle, uuid, fun);
  338. }
  339. }, op, uuid);
  340. };
  341. var _loadDisarray = function(ms, cb, op, thisLoaded, loadSingle, uuid, fun){
  342. var count=0;
  343. for (var i=0; i<ms.length; i++){
  344. loadSingle(ms[i], function(module){
  345. if (module) thisLoaded.push(module);
  346. count++;
  347. if (fun) fun(module);
  348. if (count===ms.length) if (cb) cb(thisLoaded);
  349. }, op, uuid);
  350. }
  351. };
  352. //load js
  353. //use framework url
  354. var _frameworks = {
  355. "o2.core": ["../o2_core/o2/o2.core.js"],
  356. "o2.more": ["../o2_core/o2/o2.more.js"],
  357. "ie_adapter": ["../o2_core/o2/ie_adapter.js"],
  358. "jquery": ["../o2_lib/jquery/jquery.min.js"],
  359. "mootools": ["../o2_lib/mootools/mootools-1.6.0_all.js"],
  360. "ckeditor": ["../o2_lib/htmleditor/ckeditor4114/ckeditor.js"],
  361. "ckeditor5": ["../o2_lib/htmleditor/ckeditor5-12-1-0/ckeditor.js"],
  362. "raphael": ["../o2_lib/raphael/raphael.js"],
  363. "d3": ["../o2_lib/d3/d3.min.js"],
  364. "ace": ["../o2_lib/ace/src-min-noconflict/ace.js","../o2_lib/ace/src-min-noconflict/ext-language_tools.js"],
  365. "monaco": ["../o2_lib/vs/loader.js"],
  366. "JSBeautifier": ["../o2_lib/JSBeautifier/beautify.js"],
  367. "JSBeautifier_css": ["../o2_lib/JSBeautifier/beautify-css.js"],
  368. "JSBeautifier_html": ["../o2_lib/JSBeautifier/beautify-html.js"],
  369. "JSONTemplate": ["../o2_lib/mootools/plugin/Template.js"],
  370. "kity": ["../o2_lib/kityminder/kity/kity.js"],
  371. "kityminder": ["../o2_lib/kityminder/core/dist/kityminder.core.js"]
  372. };
  373. var _loaded = {};
  374. var _loadedCss = {};
  375. var _loadedHtml = {};
  376. var _loadCssRunning = {};
  377. var _loadCssQueue = [];
  378. var _loadingModules = {};
  379. var _loadSingle = function(module, callback, op){
  380. var url = module;
  381. var uuid = _uuid();
  382. if (op.noCache) url = (url.indexOf("?")!==-1) ? url+"&v="+uuid : addr_uri+"?v="+uuid;
  383. var key = encodeURIComponent(url+op.doc.unid);
  384. if (!op.reload) if (_loaded[key]){
  385. if (callback)callback(); return;
  386. }
  387. if (_loadingModules[key]){
  388. if (!_loadingModules[key].callbacks) _loadingModules[key].callbacks = [];
  389. _loadingModules[key].callbacks.push(callback);
  390. }else{
  391. _loadingModules[key] = { callbacks: [callback] };
  392. var head = (op.doc.head || op.doc.getElementsByTagName("head")[0] || op.doc.documentElement);
  393. var s = op.doc.createElement('script');
  394. s.type = op.type || "text/javascript";
  395. head.appendChild(s);
  396. s.id = uuid;
  397. s.src = this.o2.filterUrl(url);
  398. var _checkScriptLoaded = function(_, isAbort, err){
  399. if (isAbort || !s.readyState || s.readyState === "loaded" || s.readyState === "complete") {
  400. var scriptObj = {"module": module, "id": uuid, "script": s, "doc": op.doc};
  401. if (!err) _loaded[key] = scriptObj;
  402. _removeListener(s, 'readystatechange', _checkScriptLoaded);
  403. _removeListener(s, 'load', _checkScriptLoaded);
  404. _removeListener(s, 'error', _checkScriptErrorLoaded);
  405. if (!isAbort || err){
  406. if (err){
  407. if (s) head.removeChild(s);
  408. while (_loadingModules[key].callbacks.length){
  409. (_loadingModules[key].callbacks.shift())();
  410. }
  411. //if (callback)callback();
  412. }else{
  413. //head.removeChild(s);
  414. while (_loadingModules[key].callbacks.length){
  415. (_loadingModules[key].callbacks.shift())(scriptObj);
  416. }
  417. //if (callback)callback(scriptObj);
  418. }
  419. }
  420. }
  421. };
  422. var _checkScriptErrorLoaded = function(e, err){
  423. console.log("Error: load javascript module: "+module);
  424. _checkScriptLoaded(e, true, "error");
  425. };
  426. if ('onreadystatechange' in s) _addListener(s, 'readystatechange', _checkScriptLoaded);
  427. _addListener(s, 'load', _checkScriptLoaded);
  428. _addListener(s, 'error', _checkScriptErrorLoaded);
  429. }
  430. };
  431. var _load = function(urls, options, callback){
  432. var ms = (_typeOf(urls)==="array") ? urls : [urls];
  433. var op = (_typeOf(options)==="object") ? _getJsOptions(options) : _getJsOptions(null);
  434. var cbk = (_typeOf(options)==="function") ? options : callback;
  435. var cb = cbk;
  436. if (typeof define === 'function' && define.amd){
  437. define.amd = false;
  438. cb = (cbk) ? function(){define.amd = true; cbk();} : function(){define.amd = true;}
  439. }
  440. var modules = [];
  441. for (var i=0; i<ms.length; i++){
  442. var url = ms[i];
  443. var module = _frameworks[url] || url;
  444. if (_typeOf(module)==="array"){
  445. modules = modules.concat(module)
  446. }else{
  447. modules.push(module)
  448. }
  449. }
  450. var thisLoaded = [];
  451. if (op.sequence){
  452. _loadSequence(modules, cb, op, 0, thisLoaded, _loadSingle);
  453. }else{
  454. _loadDisarray(modules, cb, op, thisLoaded, _loadSingle);
  455. }
  456. };
  457. this.o2.load = _load;
  458. //load css
  459. var _loadSingleCss = function(module, callback, op, uuid){
  460. var url = module;
  461. var uid = _uuid();
  462. if (op.noCache) url = (url.indexOf("?")!==-1) ? url+"&v="+uid : url+"?v="+uid;
  463. var key = encodeURIComponent(url+op.doc.unid);
  464. if (_loadCssRunning[key]){
  465. _loadCssQueue.push(function(){
  466. _loadSingleCss(module, callback, op, uuid);
  467. });
  468. return;
  469. }
  470. if (_loadedCss[key]) uuid = _loadedCss[key]["class"];
  471. if (op.dom) _parseDom(op.dom, function(node){ if (node.className.indexOf(uuid) == -1) node.className += ((node.className) ? " "+uuid : uuid);}, op.doc);
  472. var completed = function(){
  473. if (_loadCssRunning[key]){
  474. _loadCssRunning[key] = false;
  475. delete _loadCssRunning[key];
  476. }
  477. if (_loadCssQueue && _loadCssQueue.length){
  478. (_loadCssQueue.shift())();
  479. }
  480. };
  481. if (_loadedCss[key])if (!op.reload){
  482. if (callback)callback(_loadedCss[key]);
  483. completed();
  484. return;
  485. }
  486. var success = function(xhr){
  487. var cssText = xhr.responseText;
  488. try{
  489. if (cssText){
  490. cssText = cssText.replace(/\/\*(\s|\S)*?\*\//g, "");
  491. if (op.bind) cssText = cssText.bindJson(op.bind);
  492. if (op.dom){
  493. var rex = new RegExp("(.+)(?=\\{)", "g");
  494. var match;
  495. var prefix = "." + uuid + " ";
  496. while ((match = rex.exec(cssText)) !== null) {
  497. // var rule = prefix + match[0];
  498. // cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  499. // rex.lastIndex = rex.lastIndex + prefix.length;
  500. var rulesStr = match[0];
  501. if (rulesStr.substr(0,1)=="@" || rulesStr.indexOf("%")!=-1){
  502. // var begin = 0;
  503. // var end = 0;
  504. }else{
  505. if (rulesStr.indexOf(",")!=-1){
  506. var rules = rulesStr.split(/\s*,\s*/g);
  507. rules = rules.map(function(r){
  508. return prefix + r;
  509. });
  510. var rule = rules.join(", ");
  511. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  512. rex.lastIndex = rex.lastIndex + (prefix.length*rules.length);
  513. }else{
  514. var rule = prefix + match[0];
  515. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  516. rex.lastIndex = rex.lastIndex + prefix.length;
  517. }
  518. }
  519. }
  520. }
  521. var style = op.doc.createElement("style");
  522. style.setAttribute("type", "text/css");
  523. var head = (op.doc.head || op.doc.getElementsByTagName("head")[0] || op.doc.documentElement);
  524. head.appendChild(style);
  525. if(style.styleSheet){
  526. var setFunc = function(){
  527. style.styleSheet.cssText = cssText;
  528. };
  529. if(style.styleSheet.disabled){
  530. setTimeout(setFunc, 10);
  531. }else{
  532. setFunc();
  533. }
  534. }else{
  535. var cssTextNode = op.doc.createTextNode(cssText);
  536. style.appendChild(cssTextNode);
  537. }
  538. }
  539. style.id = uid;
  540. var styleObj = {"module": module, "id": uid, "style": style, "doc": op.doc, "class": uuid};
  541. _loadedCss[key] = styleObj;
  542. if (callback) callback(styleObj);
  543. }catch (e){
  544. if (callback) callback();
  545. return;
  546. }
  547. };
  548. var failure = function(xhr){
  549. console.log("Error: load css module: "+module);
  550. if (callback) callback();
  551. };
  552. _loadCssRunning[key] = true;
  553. _xhr_get(url, success, failure, completed);
  554. };
  555. var _parseDomString = function(dom, fn, sourceDoc){
  556. var doc = sourceDoc || document;
  557. var list = doc.querySelectorAll(dom);
  558. if (list.length) for (var i=0; i<list.length; i++) _parseDomElement(list[i], fn);
  559. };
  560. var _parseDomElement = function(dom, fn){
  561. if (fn) fn(dom);
  562. };
  563. var _parseDom = function(dom, fn, sourceDoc){
  564. var domType = _typeOf(dom);
  565. if (domType==="string") _parseDomString(dom, fn, sourceDoc);
  566. if (domType==="element") _parseDomElement(dom, fn);
  567. if (domType==="array") for (var i=0; i<dom.length; i++) _parseDom(dom[i], fn, sourceDoc);
  568. };
  569. var _loadCss = function(modules, options, callback){
  570. var ms = (_typeOf(modules)==="array") ? modules : [modules];
  571. var op = (_typeOf(options)==="object") ? _getCssOptions(options) : _getCssOptions(null);
  572. var cb = (_typeOf(options)==="function") ? options : callback;
  573. var uuid = "css"+_uuid();
  574. var thisLoaded = [];
  575. if (op.sequence){
  576. _loadSequence(ms, cb, op, 0, thisLoaded, _loadSingleCss, uuid);
  577. }else{
  578. _loadDisarray(ms, cb, op, thisLoaded, _loadSingleCss, uuid);
  579. }
  580. };
  581. var _removeCss = function(modules, doc){
  582. var thisDoc = doc || document;
  583. var ms = (_typeOf(modules)==="array") ? modules : [modules];
  584. for (var i=0; i<ms.length; i++){
  585. var module = ms[i];
  586. var k = encodeURIComponent(module+(thisDoc.unid||""));
  587. var removeCss = _loadedCss[k];
  588. if (!removeCss) for (key in _loadedCss){
  589. if (_loadedCss[key].id==module){
  590. removeCss = _loadedCss[key];
  591. k = key;
  592. break;
  593. }
  594. }
  595. if (removeCss){
  596. delete _loadedCss[k];
  597. var styleNode = removeCss.doc.getElementById(removeCss.id);
  598. if (styleNode) styleNode.parentNode.removeChild(styleNode);
  599. removeCss = null;
  600. }
  601. }
  602. };
  603. this.o2.loadCss = _loadCss;
  604. this.o2.removeCss = _removeCss;
  605. if (window.Element) Element.prototype.loadCss = function(modules, options, callback){
  606. var op = (_typeOf(options)==="object") ? options : {};
  607. var cb = (_typeOf(options)==="function") ? options : callback;
  608. op.dom = this;
  609. _loadCss(modules, op, cb);
  610. };
  611. //load html
  612. _loadSingleHtml = function(module, callback, op){
  613. var url = module;
  614. var uid = _uuid();
  615. if (op.noCache) url = (url.indexOf("?")!==-1) ? url+"&v="+uid : url+"?v="+uid;
  616. var key = encodeURIComponent(url+op.doc.unid);
  617. if (!op.reload) if (_loadedHtml[key]){ if (callback)callback(_loadedHtml[key]); return; }
  618. var success = function(xhr){
  619. var htmlObj = {"module": module, "id": uid, "data": xhr.responseText, "doc": op.doc};
  620. _loadedHtml[key] = htmlObj;
  621. if (callback) callback(htmlObj);
  622. };
  623. var failure = function(){
  624. console.log("Error: load html module: "+module);
  625. if (callback) callback();
  626. };
  627. _xhr_get(url, success, failure);
  628. };
  629. var _injectHtml = function(op, data){
  630. if (op.bind) data = data.bindJson(op.bind);
  631. if (op.dom) _parseDom(op.dom, function(node){
  632. if (op.module){
  633. _parseModule(node, data, op);
  634. //node.insertAdjacentHTML(op.position, data);
  635. }else{
  636. node.insertAdjacentHTML(op.position, data);
  637. }
  638. }, op.doc);
  639. };
  640. var _parseModule = function(node, data, op){
  641. var dom = op.noConflict ? document.createElement("div") : node;
  642. if (op.noConflict){
  643. dom.insertAdjacentHTML("afterbegin", data);
  644. }else{
  645. dom.insertAdjacentHTML(op.position, data);
  646. }
  647. var els = dom.querySelectorAll("[data-o2-element],[data-o2-events]");
  648. for (var i=0; i<els.length; i++){
  649. var el = els.item(i);
  650. var name = el.getAttribute("data-o2-element");
  651. if (name) _bindToModule(op.module, el, name.toString());
  652. if (el.hasAttribute("data-o2-events")){
  653. var events = el.getAttribute("data-o2-events").toString();
  654. if (events) _bindToEvents(op.module, el, events);
  655. }
  656. }
  657. if (op.noConflict){
  658. var n = dom.firstElementChild;
  659. var newNode = node.insertAdjacentElement(op.position, n);
  660. nextNode = dom.firstElementChild;
  661. while (nextNode) {
  662. newNode = newNode.insertAdjacentElement("afterend", nextNode);
  663. nextNode = dom.firstElementChild;
  664. }
  665. dom.destroy();
  666. }
  667. };
  668. var _bindToEvents = function(m, node, events){
  669. var p = node.getParent("div[data-o2-$binddatadd]");
  670. var data = (p) ? _parseDataCache[p.dataset["o2-$binddataid"]]: null;
  671. var eventList = events.split(/\s*;\s*/);
  672. eventList.forEach(function(ev){
  673. var evs = ev.split(/\s*:\s*/);
  674. if (evs.length>1){
  675. node.addEventListener(evs[0], function(e){
  676. if (m[evs[1]]) m[evs[1]].apply(m, [e,data]);
  677. }, false);
  678. }
  679. });
  680. }
  681. var _bindToModule = function(m, node, name){
  682. // if (m[name]){
  683. // if (o2.typeOf(m[name])!=="array"){
  684. // var tmp = m[name];
  685. // m[name] = [];
  686. // m[name].push(tmp);
  687. // }
  688. // m[name].push(node);
  689. // }else{
  690. m[name] = node;
  691. // }
  692. };
  693. var _loadHtml = function(modules, options, callback){
  694. var ms = (_typeOf(modules)==="array") ? modules : [modules];
  695. var op = (_typeOf(options)==="object") ? _getHtmlOptions(options) : _getHtmlOptions(null);
  696. var cb = (_typeOf(options)==="function") ? options : callback;
  697. var thisLoaded = [];
  698. if (op.sequence){
  699. _loadSequence(ms, cb, op, 0, thisLoaded, _loadSingleHtml, null, function(html){ if (html) _injectHtml(op, html.data ); });
  700. }else{
  701. _loadDisarray(ms, cb, op, thisLoaded, _loadSingleHtml, null, function(html){ if (html) _injectHtml(op, html.data ); });
  702. }
  703. };
  704. this.o2.loadHtml = _loadHtml;
  705. if (window.Element) Element.prototype.loadHtml = function(modules, options, callback){
  706. var op = (_typeOf(options)==="object") ? options : {};
  707. var cb = (_typeOf(options)==="function") ? options : callback;
  708. op.dom = this;
  709. _loadHtml(modules, op, cb);
  710. };
  711. this.o2.injectHtml = function(html, op){
  712. _injectHtml(op, html);
  713. };
  714. if (window.Element) Element.prototype.injectHtml = function(html, options){
  715. var op = (_typeOf(options)==="object") ? options : {};
  716. op.dom = this;
  717. op.position = (options && options.position) || "beforeend"
  718. _injectHtml(op, html);
  719. };
  720. //load all
  721. _loadAll = function(modules, options, callback){
  722. //var ms = (_typeOf(modules)==="array") ? modules : [modules];
  723. var op = (_typeOf(options)==="object") ? _getAllOptions(options) : _getAllOptions(null);
  724. var cb = (_typeOf(options)==="function") ? options : callback;
  725. var ms, htmls, styles, sctipts;
  726. var _htmlLoaded=(!modules.html), _cssLoaded=(!modules.css), _jsLoaded=(!modules.js);
  727. var _checkloaded = function(){
  728. if (_htmlLoaded && _cssLoaded && _jsLoaded) if (cb) cb(htmls, styles, sctipts);
  729. };
  730. if (modules.html){
  731. _loadHtml(modules.html, op, function(h){
  732. htmls = h;
  733. _htmlLoaded = true;
  734. _checkloaded();
  735. });
  736. }
  737. if (modules.css){
  738. _loadCss(modules.css, op, function(s){
  739. styles = s;
  740. _cssLoaded = true;
  741. _checkloaded();
  742. });
  743. }
  744. if (modules.js){
  745. _load(modules.js, op, function(s){
  746. sctipts = s;
  747. _jsLoaded = true;
  748. _checkloaded();
  749. });
  750. }
  751. };
  752. this.o2.loadAll = _loadAll;
  753. if (window.Element) Element.prototype.loadAll = function(modules, options, callback){
  754. var op = (_typeOf(options)==="object") ? options : {};
  755. var cb = (_typeOf(options)==="function") ? options : callback;
  756. op.dom = this;
  757. _loadAll(modules, op, cb);
  758. };
  759. var _getIfBlockEnd = function(v){
  760. var rex = /(\{\{if\s+)|(\{\{\s*end if\s*\}\})/gmi;
  761. var rexEnd = /\{\{\s*end if\s*\}\}/gmi;
  762. var subs = 1;
  763. while ((match = rex.exec(v)) !== null) {
  764. var fullMatch = match[0];
  765. if (fullMatch.search(rexEnd)!==-1){
  766. subs--;
  767. if (subs==0) break;
  768. }else{
  769. subs++
  770. }
  771. }
  772. if (match) return {"codeIndex": match.index, "lastIndex": rex.lastIndex};
  773. return {"codeIndex": v.length-1, "lastIndex": v.length-1};
  774. }
  775. var _getEachBlockEnd = function(v){
  776. var rex = /(\{\{each\s+)|(\{\{\s*end each\s*\}\})/gmi;
  777. var rexEnd = /\{\{\s*end each\s*\}\}/gmi;
  778. var subs = 1;
  779. while ((match = rex.exec(v)) !== null) {
  780. var fullMatch = match[0];
  781. if (fullMatch.search(rexEnd)!==-1){
  782. subs--;
  783. if (subs==0) break;
  784. }else{
  785. subs++;
  786. }
  787. }
  788. if (match) return {"codeIndex": match.index, "lastIndex": rex.lastIndex};
  789. return {"codeIndex": v.length-1, "lastIndex": v.length-1};
  790. }
  791. var _parseDataCache = {};
  792. var _parseHtml = function(str, json, i){
  793. var v = str;
  794. if (i){
  795. var r = (Math.random()*1000000).toInt().toString();
  796. while (_parseDataCache[r]) r = (Math.random()*1000000).toInt().toString();
  797. _parseDataCache[r] = json;
  798. v = (i) ? "<div data-o2-$binddataid='"+r+"'>"+str+"</div>" : str;
  799. }
  800. var rex = /(\{\{\s*)[\s\S]*?(\s*\}\})/gmi;
  801. var match;
  802. while ((match = rex.exec(v)) !== null) {
  803. var fullMatch = match[0];
  804. var offset = 0;
  805. //if statement begin
  806. if (fullMatch.search(/\{\{if\s+/i)!==-1){
  807. //找到对应的end if
  808. var condition = fullMatch.replace(/^\{\{if\s*/i, "");
  809. condition = condition.replace(/\s*\}\}$/i, "");
  810. var flag = _jsonText(json, condition, "boolean");
  811. var tmpStr = v.substring(rex.lastIndex, v.length);
  812. var endIfIndex = _getIfBlockEnd(tmpStr);
  813. if (flag){ //if 为 true
  814. var parseStr = _parseHtml(tmpStr.substring(0, endIfIndex.codeIndex), json);
  815. var vLeft = v.substring(0, match.index);
  816. var vRight = v.substring(rex.lastIndex+endIfIndex.lastIndex, v.length);
  817. v = vLeft + parseStr + vRight;
  818. offset = parseStr.length - fullMatch.length;
  819. }else{
  820. v = v.substring(0, match.index) + v.substring(rex.lastIndex+endIfIndex.lastIndex, v.length);
  821. offset = 0-fullMatch.length;
  822. }
  823. }else if (fullMatch.search(/\{\{each\s+/)!==-1) { //each statement
  824. var itemString = fullMatch.replace(/^\{\{each\s*/, "");
  825. itemString = itemString.replace(/\s*\}\}$/, "");
  826. var eachValue = _jsonText(json, itemString, "object");
  827. var tmpEachStr = v.substring(rex.lastIndex, v.length);
  828. var endEachIndex = _getEachBlockEnd(tmpEachStr);
  829. var parseEachStr = tmpEachStr.substring(0, endEachIndex.codeIndex);
  830. var eachResult = "";
  831. if (eachValue && _typeOf(eachValue)==="array"){
  832. for (var i=0; i<eachValue.length; i++){
  833. eachValue[i]._ = json;
  834. eachResult += _parseHtml(parseEachStr, eachValue[i], i);
  835. }
  836. var eLeft = v.substring(0, match.index);
  837. var eRight = v.substring(rex.lastIndex+endEachIndex.lastIndex, v.length);
  838. v = eLeft + eachResult + eRight;
  839. offset = eachResult.length - fullMatch.length;
  840. }else{
  841. v = v.substring(0, match.index) + v.substring(rex.lastIndex+endEachIndex.lastIndex, v.length);
  842. offset = 0-fullMatch.length;
  843. }
  844. }else{ //text statement
  845. var text = fullMatch.replace(/^\{\{\s*/, "");
  846. text = text.replace(/\}\}\s*$/, "");
  847. var value = _jsonText(json, text);
  848. offset = value.length-fullMatch.length;
  849. v = v.substring(0, match.index) + value + v.substring(rex.lastIndex, v.length);
  850. }
  851. rex.lastIndex = rex.lastIndex + offset;
  852. }
  853. return v;
  854. };
  855. var _jsonText = function(json, text, type){
  856. try {
  857. var $ = json;
  858. var f = eval("(function($){\n return "+text+";\n})");
  859. returnValue = f.apply(json, [$]);
  860. if (returnValue===undefined) returnValue="";
  861. if (type==="boolean") return (!!returnValue);
  862. if (type==="object") return returnValue;
  863. returnValue = returnValue.toString();
  864. returnValue = returnValue.replace(/\&/g, "&amp;");
  865. returnValue = returnValue.replace(/>/g, "&gt;");
  866. returnValue = returnValue.replace(/</g, "&lt;");
  867. returnValue = returnValue.replace(/\"/g, "&quot;");
  868. return returnValue || "";
  869. }catch(e){
  870. if (type==="boolean") return false;
  871. if (type==="object") return null;
  872. return "";
  873. }
  874. };
  875. o2.bindJson = function(str, json){
  876. return _parseHtml(str, json);
  877. };
  878. String.prototype.bindJson = function(json){
  879. return _parseHtml(this, json);
  880. };
  881. })();
  882. /** ***** BEGIN LICENSE BLOCK *****
  883. * |------------------------------------------------------------------------------|
  884. * | O2OA 活力办公 创意无限 o2.core.js |
  885. * |------------------------------------------------------------------------------|
  886. * | Distributed under the AGPL license: |
  887. * |------------------------------------------------------------------------------|
  888. * | Copyright © 2018, o2oa.net, o2server.io O2 Team |
  889. * | All rights reserved. |
  890. * |------------------------------------------------------------------------------|
  891. *
  892. * This file is part of O2OA.
  893. *
  894. * O2OA is free software: you can redistribute it and/or modify
  895. * it under the terms of the GNU Affero General Public License as published by
  896. * the Free Software Foundation, either version 3 of the License, or
  897. * (at your option) any later version.
  898. *
  899. * O2OA is distributed in the hope that it will be useful,
  900. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  901. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  902. * GNU Affero General Public License for more details.
  903. *
  904. * You should have received a copy of the GNU General Public License
  905. * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
  906. *
  907. * ***** END LICENSE BLOCK ******/
  908. (function (){
  909. var _Class = {
  910. create: function(options) {
  911. var newClass = function() {
  912. this.initialize.apply(this, arguments);
  913. };
  914. _copyPrototype(newClass, options);
  915. return newClass;
  916. }
  917. };
  918. var _copyPrototype = function (currentNS, props){
  919. if (!props){return currentNS;}
  920. if (!currentNS){return currentNS;}
  921. if ((typeof currentNS).toLowerCase()==="object"){
  922. for (var prop in props){
  923. currentNS[prop] = props[prop];
  924. }
  925. }
  926. if ((typeof currentNS).toLowerCase()==="function"){
  927. for (var propfun in props){
  928. currentNS.prototype[propfun] = props[propfun];
  929. }
  930. }
  931. return currentNS;
  932. };
  933. var _loaded = {};
  934. var _requireJs = function(url, callback, async, compression, module){
  935. var key = encodeURIComponent(url);
  936. if (_loaded[key]){o2.runCallback(callback, "success", [module]); return "";}
  937. var jsPath = (compression || !this.o2.session.isDebugger) ? url.replace(/\.js/, ".min.js") : url;
  938. jsPath = (jsPath.indexOf("?")!==-1) ? jsPath+"&v="+this.o2.version.v : jsPath+"?v="+this.o2.version.v;
  939. var xhr = new Request({
  940. url: o2.filterUrl(jsPath), async: async, method: "get",
  941. onSuccess: function(){
  942. //try{
  943. _loaded[key] = true;
  944. o2.runCallback(callback, "success", [module]);
  945. //}catch (e){
  946. // o2.runCallback(callback, "failure", [e]);
  947. //}
  948. },
  949. onFailure: function(r){
  950. var rex = /lp\/.+\.js/;
  951. if (rex.test(url)){
  952. var zhcnUrl = url.replace(rex, "lp/zh-cn.js");
  953. if (zhcnUrl!==url){
  954. _requireJs(zhcnUrl, callback, async, compression, module)
  955. }else{
  956. o2.runCallback(callback, "failure", [r]);
  957. }
  958. }else{
  959. o2.runCallback(callback, "failure", [r]);
  960. }
  961. }
  962. });
  963. xhr.send();
  964. };
  965. var _requireSingle = function(module, callback, async, compression){
  966. if (o2.typeOf(module)==="array"){
  967. _requireAppSingle(module, callback, async, compression);
  968. }else{
  969. module = module.replace("MWF.", "o2.");
  970. var levels = module.split(".");
  971. if (levels[levels.length-1]==="*") levels[levels.length-1] = "package";
  972. levels.shift();
  973. var o = o2;
  974. var i = 0;
  975. while (o && i<levels.length){
  976. o = o[levels[i]];
  977. i++
  978. }
  979. if (!o){
  980. var jsPath = this.o2.session.path;
  981. jsPath +="/"+levels.join("/")+".js";
  982. var loadAsync = (async!==false);
  983. _requireJs(jsPath, callback, loadAsync, compression, module);
  984. }else{
  985. o2.runCallback(callback, "success", [module]);
  986. }
  987. }
  988. };
  989. var _requireSequence = function(fun, module, thisLoaded, thisErrorLoaded, callback, async, compression){
  990. var m = module.shift();
  991. fun(m, {
  992. "onSuccess": function(m){
  993. thisLoaded.push(m);
  994. o2.runCallback(callback, "every", [m]);
  995. if (module.length){
  996. _requireSequence(fun, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  997. }else{
  998. if (thisErrorLoaded.length){
  999. o2.runCallback(callback, "failure", [thisLoaded, thisErrorLoaded]);
  1000. }else{
  1001. o2.runCallback(callback, "success", [thisLoaded, thisErrorLoaded]);
  1002. }
  1003. }
  1004. },
  1005. "onFailure": function(){
  1006. thisErrorLoaded.push(module[i]);
  1007. o2.runCallback(callback, "failure", [thisLoaded, thisErrorLoaded]);
  1008. }
  1009. }, async, compression);
  1010. };
  1011. var _requireDisarray = function(fun, module, thisLoaded, thisErrorLoaded, callback, async, compression){
  1012. for (var i=0; i<module.length; i++){
  1013. fun(module[i], {
  1014. "onSuccess": function(m){
  1015. thisLoaded.push(m);
  1016. o2.runCallback(callback, "every", [m]);
  1017. if ((thisLoaded.length+thisErrorLoaded.length)===module.length){
  1018. if (thisErrorLoaded.length){
  1019. o2.runCallback(callback, "failure", [thisLoaded, thisErrorLoaded]);
  1020. }else{
  1021. o2.runCallback(callback, "success", [thisLoaded, thisErrorLoaded]);
  1022. }
  1023. }
  1024. },
  1025. "onFailure": function(){
  1026. thisErrorLoaded.push(module[i]);
  1027. o2.runCallback(callback, "failure", [thisLoaded, thisErrorLoaded]);
  1028. }
  1029. }, async, compression);
  1030. }
  1031. };
  1032. var _require = function(module, callback, async, sequence, compression){
  1033. var type = typeOf(module);
  1034. if (type==="array"){
  1035. var sql = !!sequence;
  1036. var thisLoaded = [];
  1037. var thisErrorLoaded = [];
  1038. if (sql){
  1039. _requireSequence(_requireSingle, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  1040. }else{
  1041. _requireDisarray(_requireSingle, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  1042. }
  1043. }
  1044. if (type==="string"){
  1045. _requireSingle(module, callback, async, compression);
  1046. }
  1047. };
  1048. var _requireAppSingle = function(modules, callback, async, compression){
  1049. var module = modules[0];
  1050. var clazz = modules[1];
  1051. var levels = module.split(".");
  1052. var o = o2.xApplication;
  1053. var i = 0;
  1054. while (o && i<levels.length){
  1055. o = o[levels[i]];
  1056. i++
  1057. }
  1058. if (o) o = o[clazz || "Main"];
  1059. if (!o){
  1060. //levels.shift();
  1061. var root = "x_component_"+levels.join("_");
  1062. var clazzName = clazz || "Main";
  1063. var path = "../"+root+"/"+clazzName.replace(/\./g, "/")+".js";
  1064. var loadAsync = (async!==false);
  1065. _requireJs(path, callback, loadAsync, compression);
  1066. }else{
  1067. o2.runCallback(callback, "success");
  1068. }
  1069. };
  1070. var _requireApp = function(module, clazz, callback, async, sequence, compression){
  1071. var type = typeOf(module);
  1072. if (type==="array"){
  1073. var sql = !!sequence;
  1074. var thisLoaded = [];
  1075. var thisErrorLoaded = [];
  1076. if (sql){
  1077. _requireSequence(_requireAppSingle, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  1078. }else{
  1079. _requireDisarray(_requireAppSingle, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  1080. }
  1081. }
  1082. if (type==="string"){
  1083. var modules = [module, clazz];
  1084. _requireAppSingle(modules, callback, async, compression);
  1085. }
  1086. };
  1087. JSON = window.JSON || {};
  1088. var _json = JSON;
  1089. _json.get = function(url, callback, async, nocache){
  1090. var loadAsync = (async !== false);
  1091. var noJsonCache = (nocache === true);
  1092. url = (url.indexOf("?")!==-1) ? url+"&v="+o2.version.v : url+"?v="+o2.version.v;
  1093. var json = null;
  1094. var res = new Request.JSON({
  1095. url: o2.filterUrl(url),
  1096. secure: false,
  1097. method: "get",
  1098. noCache: noJsonCache,
  1099. async: loadAsync,
  1100. withCredentials: true,
  1101. onSuccess: function(responseJSON, responseText){
  1102. json = responseJSON;
  1103. if (typeOf(callback).toLowerCase() === 'function'){
  1104. callback(responseJSON, responseText);
  1105. }else{
  1106. o2.runCallback(callback, "success", [responseJSON, responseText]);
  1107. }
  1108. }.bind(this),
  1109. onFailure: function(xhr){
  1110. o2.runCallback(callback, "requestFailure", [xhr]);
  1111. }.bind(this),
  1112. onError: function(text, error){
  1113. o2.runCallback(callback, "error", [text, error]);
  1114. }.bind(this)
  1115. });
  1116. res.send();
  1117. return json;
  1118. };
  1119. _json.getJsonp = function(url, callback, async, callbackKey){
  1120. var loadAsync = (async !== false);
  1121. var callbackKeyWord = callbackKey || "callback";
  1122. url = (url.indexOf("?")!==-1) ? url+"&v="+o2.version.v : url+"?v="+o2.version.v;
  1123. var res = new Request.JSONP({
  1124. url: o2.filterUrl(url),
  1125. secure: false,
  1126. method: "get",
  1127. noCache: true,
  1128. async: loadAsync,
  1129. callbackKey: callbackKeyWord,
  1130. onSuccess: function(responseJSON, responseText){
  1131. o2.runCallback(callback, "success",[responseJSON, responseText]);
  1132. }.bind(this),
  1133. onFailure: function(xhr){
  1134. o2.runCallback(callback, "requestFailure",[xhr]);
  1135. }.bind(this),
  1136. onError: function(text, error){
  1137. o2.runCallback(callback, "error",[text, error]);
  1138. }.bind(this)
  1139. });
  1140. res.send();
  1141. };
  1142. var _loadLP = function(name){
  1143. var jsPath = o2.session.path;
  1144. jsPath = jsPath+"/lp/"+name+".js";
  1145. var r = new Request({
  1146. url: o2.filterUrl(jsPath),
  1147. async: false,
  1148. method: "get",
  1149. onSuccess: function(responseText){
  1150. try{
  1151. Browser.exec(responseText);
  1152. }catch (e){}
  1153. },
  1154. onFailure: function(xhr){
  1155. if (name!="zh-cn"){
  1156. _loadLP("zh-cn");
  1157. }else{
  1158. throw "loadLP Error: "+xhr.responseText;
  1159. }
  1160. }
  1161. });
  1162. r.send();
  1163. };
  1164. var _cacheUrls = [
  1165. /jaxrs\/form\/workorworkcompleted\/.+/ig,
  1166. /jaxrs\/form\/.+/ig,
  1167. // /jaxrs\/script/ig,
  1168. /jaxrs\/script\/.+\/app\/.+\/imported/ig,
  1169. /jaxrs\/script\/portal\/.+\/name\/.+\/imported/ig,
  1170. /jaxrs\/script\/.+\/application\/.+\/imported/ig,
  1171. /jaxrs\/page\/.+\/portal\/.+/ig,
  1172. /jaxrs\/document\/.+/ig,
  1173. /jaxrs\/applicationdict\/.+/ig,
  1174. /jaxrs\/custom\/.+/ig,
  1175. /jaxrs\/definition\/idea.+/ig,
  1176. /jaxrs\/distribute\/assemble\/source\/.+/ig,
  1177. ///jaxrs\/form\/workorworkcompleted\/.+/ig,
  1178. // /jaxrs\/script/ig,
  1179. // /jaxrs\/script\/.+\/app\/.+\/imported/ig,
  1180. // /jaxrs\/script\/portal\/.+\/name\/.+\/imported/ig,
  1181. // /jaxrs\/script\/.+\/application\/.+\/imported/ig,
  1182. // /jaxrs\/page\/.+\/portal\/.+/ig
  1183. // /jaxrs\/authentication/ig
  1184. // /jaxrs\/statement\/.*\/execute\/page\/.*\/size\/.*/ig
  1185. ];
  1186. _restful = function(method, address, data, callback, async, withCredentials, cache){
  1187. var loadAsync = (async !== false);
  1188. var credentials = (withCredentials !== false);
  1189. address = (address.indexOf("?")!==-1) ? address+"&v="+o2.version.v : address+"?v="+o2.version.v;
  1190. //var noCache = cache===false;
  1191. var noCache = !cache;
  1192. //if (Browser.name == "ie")
  1193. if (_cacheUrls.length){
  1194. for (var i=0; i<_cacheUrls.length; i++){
  1195. _cacheUrls[i].lastIndex = 0;
  1196. if (_cacheUrls[i].test(address)){
  1197. noCache = false;
  1198. break;
  1199. }
  1200. }
  1201. }
  1202. //var noCache = false;
  1203. var res = new Request.JSON({
  1204. url: o2.filterUrl(address),
  1205. secure: false,
  1206. method: method,
  1207. emulation: false,
  1208. noCache: noCache,
  1209. async: loadAsync,
  1210. withCredentials: credentials,
  1211. onSuccess: function(responseJSON, responseText){
  1212. // var xToken = this.getHeader("authorization");
  1213. // if (!xToken) xToken = this.getHeader("x-token");
  1214. var xToken = this.getHeader("x-token");
  1215. if (xToken){
  1216. if (window.layout){
  1217. if (!layout.session) layout.session = {};
  1218. layout.session.token = xToken;
  1219. }
  1220. }
  1221. o2.runCallback(callback, "success", [responseJSON]);
  1222. },
  1223. onFailure: function(xhr){
  1224. o2.runCallback(callback, "requestFailure", [xhr]);
  1225. }.bind(this),
  1226. onError: function(text, error){
  1227. o2.runCallback(callback, "error", [text, error]);
  1228. }.bind(this)
  1229. });
  1230. res.setHeader("Content-Type", "application/json; charset=utf-8");
  1231. res.setHeader("Accept", "text/html,application/json,*/*");
  1232. if (window.layout) {
  1233. if (layout["debugger"]){
  1234. res.setHeader("x-debugger", "true");
  1235. }
  1236. if (layout.session && layout.session.user){
  1237. if (layout.session.user.token) {
  1238. res.setHeader("x-token", layout.session.user.token);
  1239. res.setHeader("authorization", layout.session.user.token);
  1240. }
  1241. }
  1242. }
  1243. //Content-Type application/x-www-form-urlencoded; charset=utf-8
  1244. res.send(data);
  1245. return res;
  1246. };
  1247. var _release = function(o){
  1248. var type = typeOf(o);
  1249. switch (type){
  1250. case "object":
  1251. for (var k in o){
  1252. //if (o[k] && o[k].destroy) o[k].destroy();
  1253. o[k] = null;
  1254. }
  1255. break;
  1256. case "array":
  1257. for (var i=0; i< o.length; i++){
  1258. _release(o[i]);
  1259. if (o[i]) o[i] = null;
  1260. }
  1261. break;
  1262. }
  1263. };
  1264. var _defineProperties = Object.defineProperties || function (obj, properties) {
  1265. function convertToDescriptor(desc) {
  1266. function hasProperty(obj, prop) {
  1267. return Object.prototype.hasOwnProperty.call(obj, prop);
  1268. }
  1269. function isCallable(v) {
  1270. // NB: modify as necessary if other values than functions are callable.
  1271. return typeof v === "function";
  1272. }
  1273. if (typeof desc !== "object" || desc === null)
  1274. throw new TypeError("bad desc");
  1275. var d = {};
  1276. if (hasProperty(desc, "enumerable"))
  1277. d.enumerable = !!desc.enumerable;
  1278. if (hasProperty(desc, "configurable"))
  1279. d.configurable = !!desc.configurable;
  1280. if (hasProperty(desc, "value"))
  1281. d.value = desc.value;
  1282. if (hasProperty(desc, "writable"))
  1283. d.writable = !!desc.writable;
  1284. if (hasProperty(desc, "get")) {
  1285. var g = desc.get;
  1286. if (!isCallable(g) && typeof g !== "undefined")
  1287. throw new TypeError("bad get");
  1288. d.get = g;
  1289. }
  1290. if (hasProperty(desc, "set")) {
  1291. var s = desc.set;
  1292. if (!isCallable(s) && typeof s !== "undefined")
  1293. throw new TypeError("bad set");
  1294. d.set = s;
  1295. }
  1296. if (("get" in d || "set" in d) && ("value" in d || "writable" in d))
  1297. throw new TypeError("identity-confused descriptor");
  1298. return d;
  1299. }
  1300. if (typeof obj !== "object" || obj === null)
  1301. throw new TypeError("bad obj");
  1302. properties = Object(properties);
  1303. var keys = Object.keys(properties);
  1304. var descs = [];
  1305. for (var j = 0; j < keys.length; j++)
  1306. descs.push([keys[j], convertToDescriptor(properties[keys[j]])]);
  1307. for (var i = 0; i < descs.length; i++){
  1308. if (Object.defineProperty && (Browser.name=="ie" && Browser.version!=8)){
  1309. Object.defineProperty(obj, descs[i][0], descs[i][1]);
  1310. }else{
  1311. if (descs[i][1].value) obj[descs[i][0]] = descs[i][1].value;
  1312. if (descs[i][1].get) obj["get"+descs[i][0].capitalize()] = descs[i][1].get;
  1313. if (descs[i][1].set) obj["set"+descs[i][0].capitalize()] = descs[i][1].set;
  1314. }
  1315. }
  1316. return obj;
  1317. };
  1318. if (!Array.prototype.findIndex) {
  1319. Object.defineProperty(Array.prototype, 'findIndex', {
  1320. value: function(predicate) {
  1321. if (this == null) {
  1322. throw new TypeError('"this" is null or not defined');
  1323. }
  1324. var o = Object(this);
  1325. var len = o.length >>> 0;
  1326. if (typeof predicate !== 'function') {
  1327. throw new TypeError('predicate must be a function');
  1328. }
  1329. var thisArg = arguments[1];
  1330. var k = 0;
  1331. while (k < len) {
  1332. var kValue = o[k];
  1333. if (predicate.call(thisArg, kValue, k, o)) {
  1334. return k;
  1335. }
  1336. k++;
  1337. }
  1338. return -1;
  1339. }
  1340. });
  1341. }
  1342. if (!Array.prototype.find) {
  1343. Object.defineProperty(Array.prototype, 'find', {
  1344. value: function(predicate) {
  1345. if (this == null) {
  1346. throw new TypeError('"this" is null or not defined');
  1347. }
  1348. var o = Object(this);
  1349. var len = o.length >>> 0;
  1350. if (typeof predicate !== 'function') {
  1351. throw new TypeError('predicate must be a function');
  1352. }
  1353. var thisArg = arguments[1];
  1354. var k = 0;
  1355. while (k < len) {
  1356. var kValue = o[k];
  1357. if (predicate.call(thisArg, kValue, k, o)) {
  1358. return kValue;
  1359. }
  1360. k++;
  1361. }
  1362. return undefined;
  1363. }
  1364. });
  1365. }
  1366. var _txt = function(v){
  1367. var t = v.replace(/\</g, "&lt;");
  1368. t = t.replace(/\</g, "&gt;");
  1369. return t;
  1370. };
  1371. this.o2.Class = _Class;
  1372. this.o2.require = _require;
  1373. this.o2.requireApp = _requireApp;
  1374. this.o2.JSON = _json;
  1375. this.o2.loadLP = _loadLP;
  1376. this.o2.restful = _restful;
  1377. this.o2.release = _release;
  1378. this.o2.defineProperties = _defineProperties;
  1379. this.o2.txt = _txt;
  1380. Object.repeatArray = function(o, count){
  1381. var arr = [];
  1382. for (var i=0; i<count; i++){
  1383. arr.push(o)
  1384. }
  1385. return arr;
  1386. }
  1387. Date.implement({
  1388. // "getFromServer": function(){
  1389. // var d;
  1390. // o2.Actions.get("x_program_center").echo(function(json){
  1391. // d = Date.parse(json.data.serverTime);
  1392. // }, null, false);
  1393. // return d;
  1394. // }
  1395. "getFromServer": function(callback){
  1396. var async = !!callback;
  1397. var d;
  1398. var r = o2.Actions.get("x_program_center").echo(function(json){
  1399. d = Date.parse(json.data.serverTime);
  1400. if (callback) callback(d);
  1401. }, null, async);
  1402. return d || r;
  1403. }
  1404. });
  1405. })();
  1406. o2.core = true;
  1407. /** ***** BEGIN LICENSE BLOCK *****
  1408. * |------------------------------------------------------------------------------|
  1409. * | O2OA 活力办公 创意无限 o2.more.js |
  1410. * |------------------------------------------------------------------------------|
  1411. * | Distributed under the AGPL license: |
  1412. * |------------------------------------------------------------------------------|
  1413. * | Copyright © 2018, o2oa.net, o2server.io O2 Team |
  1414. * | All rights reserved. |
  1415. * |------------------------------------------------------------------------------|
  1416. *
  1417. * This file is part of O2OA.
  1418. *
  1419. * O2OA is free software: you can redistribute it and/or modify
  1420. * it under the terms of the GNU Affero General Public License as published by
  1421. * the Free Software Foundation, either version 3 of the License, or
  1422. * (at your option) any later version.
  1423. *
  1424. * O2OA is distributed in the hope that it will be useful,
  1425. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1426. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1427. * GNU Affero General Public License for more details.
  1428. *
  1429. * You should have received a copy of the GNU General Public License
  1430. * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
  1431. *
  1432. * ***** END LICENSE BLOCK ******/
  1433. (function (){
  1434. o2.getCenterPosition = function(el, width, height){
  1435. var elPositon = $(el).getPosition();
  1436. var elSize = $(el).getSize();
  1437. var node = $("layout");
  1438. var size = (node) ? $(node).getSize() : $(document.body).getSize();
  1439. var top = (elPositon.y+elSize.y)/2 - (height/2);
  1440. var left = (elPositon.x+elSize.x)/2-(width/2);
  1441. if ((left+width)>size.x){
  1442. left = size.x-width-10;
  1443. }
  1444. if ((top+height)>size.y){
  1445. top = size.y-height-10;
  1446. }
  1447. return {"x": left, "y": top};
  1448. };
  1449. o2.getMarkSize = function(node){
  1450. var size;
  1451. if (!node){
  1452. size = $(document.body).getSize();
  1453. var winSize = $(window).getSize();
  1454. var height = size.y;
  1455. var width = size.x;
  1456. if (height<winSize.y) height = winSize.y;
  1457. if (width<winSize.x) width = winSize.x;
  1458. return {x: size.x, y: height};
  1459. }else{
  1460. size = $(node).getSize();
  1461. return {x: size.x, y: size.y};
  1462. }
  1463. };
  1464. o2.json = function(jsonString, fun){
  1465. var obj = JSON.decode(jsonString);
  1466. var p = fun.split(".");
  1467. var tmp = obj;
  1468. p.each(function(item){
  1469. if (item.indexOf("[")!==-1){
  1470. var x = item.split("[");
  1471. var i = parseInt(x[1].substr(0, x[1].indexOf("]")));
  1472. tmp = tmp[x[0]][i];
  1473. }else{
  1474. tmp = tmp[item];
  1475. }
  1476. });
  1477. return tmp;
  1478. };
  1479. o2.getHTMLTemplate = function(url, callback, async){
  1480. var loadAsync = (async !== false);
  1481. var res = new Request.HTML({
  1482. url: url,
  1483. async: loadAsync,
  1484. method: "get",
  1485. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  1486. o2.runCallback(callback, "success", [responseTree, responseElements, responseHTML, responseJavaScript]);
  1487. }.bind(this),
  1488. onFailure: function(xhr){
  1489. o2.runCallback(callback, "requestFailure", [xhr]);
  1490. }
  1491. });
  1492. res.send();
  1493. };
  1494. o2.getRequestText = function(url, callback, async){
  1495. var loadAsync = (async !== false);
  1496. url = (url.indexOf("?")!==-1) ? url+"&v="+o2.version.v : url+"?v="+o2.version.v;
  1497. var res = new Request({
  1498. url: url,
  1499. async: loadAsync,
  1500. method: "get",
  1501. onSuccess: function(responseText, responseXML){
  1502. o2.runCallback(callback, "success",[responseText, responseXML]);
  1503. }.bind(this),
  1504. onFailure: function(xhr){
  1505. o2.runCallback(callback, "requestFailure",[xhr]);
  1506. }
  1507. });
  1508. res.send();
  1509. };
  1510. o2.encodeJsonString = function(str){
  1511. var tmp = [str];
  1512. var dataStr = (JSON.encode(tmp));
  1513. return dataStr.substr(2, dataStr.length-4);
  1514. };
  1515. o2.decodeJsonString = function(str){
  1516. var tmp = "[\""+str+"\"]";
  1517. var dataObj = (JSON.decode(tmp));
  1518. return dataObj[0];
  1519. };
  1520. o2.getTextSize = function(text, styles){
  1521. var tmpSpan = new Element("span", {
  1522. "text": text,
  1523. "styles": styles
  1524. }).inject($(document.body));
  1525. var size = tmpSpan.getSize();
  1526. tmpSpan.destroy();
  1527. return size;
  1528. };
  1529. o2.getCenter = function(size, target, offset){
  1530. if (!target) target = document.body;
  1531. var targetSize = target.getSize();
  1532. var targetPosition = target.getPosition(offset);
  1533. var targetScroll = target.getScroll();
  1534. var x = targetSize.x/2;
  1535. var y = targetSize.y/2;
  1536. x = x-(size.x/2);
  1537. y = y-(size.y/2);
  1538. x = x+targetPosition.x;
  1539. y = y+targetPosition.y;
  1540. x = x+targetScroll.x;
  1541. y = y+targetScroll.y;
  1542. return {"x": x, "y": y};
  1543. };
  1544. o2.getEPointer = function(e){
  1545. var x = 0;
  1546. var y = 0;
  1547. if (typeOf(e)=="element"){
  1548. var position = e.getPosition(this.content);
  1549. x = position.x;
  1550. y = position.y;
  1551. }else{
  1552. if (Browser.name=="firefox"){
  1553. x = parseFloat(e.event.clientX || e.event.x);
  1554. y = parseFloat(e.event.clientY || e.event.y);
  1555. }else{
  1556. x = parseFloat(e.event.x);
  1557. y = parseFloat(e.event.y);
  1558. }
  1559. if (e.target){
  1560. var position = e.target.getPosition(this.content);
  1561. x = position.x;
  1562. y = position.y;
  1563. }
  1564. // }
  1565. }
  1566. return {"x": x, "y": y};
  1567. };
  1568. o2.getParent = function(node, tag){
  1569. var pNode = node.parentElement;
  1570. while(pNode && pNode.tagName.toString().toLowerCase() !== tag.toString().toLowerCase()){
  1571. pNode = pNode.parentElement;
  1572. }
  1573. return pNode;
  1574. };
  1575. o2.getOffset = function(evt){
  1576. if (Browser.name==="firefox"){
  1577. return {
  1578. "offsetX": evt.layerX,
  1579. "offsetY": evt.layerY
  1580. };
  1581. }else{
  1582. return {
  1583. "offsetX": evt.offsetX,
  1584. "offsetY": evt.offsetY
  1585. }
  1586. }
  1587. };
  1588. if (String.implement) String.implement({
  1589. "getAllIndexOf": function(str){
  1590. var idxs= [];
  1591. var idx = this.indexOf(str);
  1592. while (idx !== -1){
  1593. idxs.push(idx);
  1594. idx = this.indexOf(str, idx+1);
  1595. }
  1596. return idxs;
  1597. }
  1598. });
  1599. if (Array.implement) Array.implement({
  1600. "trim": function(){
  1601. var arr = [];
  1602. this.each(function(v){
  1603. if (v) arr.push(v);
  1604. });
  1605. return arr;
  1606. },
  1607. "isIntersect": function(arr){
  1608. return this.some(function(item){ return (arr.indexOf(item)!==-1); })
  1609. }
  1610. });
  1611. if (!Array.prototype.find){
  1612. if (Array.implement) Array.implement({
  1613. "find": this.find || function(callback, thisArg){
  1614. for (var i=0; i<this.length; i++){
  1615. if (callback.apply((thisArg || this), this[i], i, this)){
  1616. return this[i];
  1617. }
  1618. }
  1619. return undefined;
  1620. }
  1621. });
  1622. }
  1623. if (window.Element && Element.implement) Element.implement({
  1624. "isIntoView": function() {
  1625. // var pNode = this.getParent();
  1626. // while (pNode && ((pNode.getScrollSize().y-(pNode.getComputedSize().height+1)<=0) || pNode.getStyle("overflow")==="visible")) pNode = pNode.getParent();
  1627. //
  1628. var pNode = this.getParentSrcollNode();
  1629. if (!pNode) pNode = document.body;
  1630. var size = pNode.getSize();
  1631. var srcoll = pNode.getScroll();
  1632. var p = (pNode == window) ? {"x":0, "y": 0} : this.getPosition(pNode);
  1633. var nodeSize = this.getSize();
  1634. //return (p.x-srcoll.x>=0 && p.y-srcoll.y>=0) && (p.x+nodeSize.x<size.x+srcoll.x && p.y+nodeSize.y<size.y+srcoll.y);
  1635. return (p.x-srcoll.x>=0 && p.y>=0) && (p.x+nodeSize.x<size.x+srcoll.x && p.y+nodeSize.y<size.y)
  1636. },
  1637. "appendHTML": function(html, where){
  1638. if (this.insertAdjacentHTML){
  1639. var whereText = "beforeEnd";
  1640. if (where==="before") whereText = "beforeBegin";
  1641. if (where==="after") whereText = "afterEnd";
  1642. if (where==="bottom") whereText = "beforeEnd";
  1643. if (where==="top") whereText = "afterBegin";
  1644. this.insertAdjacentHTML(whereText, html);
  1645. }else {
  1646. if (where==="bottom") this.innerHTML = this.innerHTML+html;
  1647. if (where==="top") this.innerHTML = html+this.innerHTML;
  1648. }
  1649. },
  1650. "positionTo": function(x,y){
  1651. var left = x.toFloat();
  1652. var top = y.toFloat();
  1653. var offsetNode = this.getOffsetParent();
  1654. if (offsetNode){
  1655. var offsetPosition = offsetNode.getPosition();
  1656. left = left-offsetPosition.x;
  1657. top = top-offsetPosition.y;
  1658. }
  1659. this.setStyles({"top": top, "left": left});
  1660. return this;
  1661. },
  1662. "getBorder": function(){
  1663. var positions = ["top", "left", "right", "bottom"];
  1664. var styles = ["color", "style", "width"];
  1665. var obj = {};
  1666. positions.each(function (position){
  1667. styles.each(function(style){
  1668. var key = "border-"+position+"-"+style;
  1669. obj[key] = this.getStyle(key);
  1670. }.bind(this));
  1671. }.bind(this));
  1672. return obj;
  1673. },
  1674. "isOutside": function(e){
  1675. var elementCoords = this.getCoordinates();
  1676. var targetCoords = this.getCoordinates();
  1677. if(((e.page.x < elementCoords.left || e.page.x > (elementCoords.left + elementCoords.width)) ||
  1678. (e.page.y < elementCoords.top || e.page.y > (elementCoords.top + elementCoords.height))) &&
  1679. ((e.page.x < targetCoords.left || e.page.x > (targetCoords.left + targetCoords.width)) ||
  1680. (e.page.y < targetCoords.top || e.page.y > (targetCoords.top + targetCoords.height))) ) return true;
  1681. return false;
  1682. },
  1683. "getAbsolutePosition":function(){
  1684. var styleLeft = 0;
  1685. var styleTop = 0;
  1686. var node = this;
  1687. styleLeft = node.offsetLeft;
  1688. styleTop = node.offsetTop;
  1689. node = node.parentElement;
  1690. while (node && node.tagName.toString().toLowerCase()!=="body"){
  1691. styleLeft += node.offsetLeft;
  1692. styleTop += node.offsetTop;
  1693. node = node.offsetParent;
  1694. }
  1695. return {x: styleLeft, y: styleTop};
  1696. },
  1697. "tweenScroll": function(to, time){
  1698. if (!this.tweenScrollQueue){
  1699. this.tweenScrollQueue = [];
  1700. }
  1701. if (this.tweenScrollQueue.length){
  1702. this.tweenScrollQueue.push(to);
  1703. }else{
  1704. this.tweenScrollQueue.push(to);
  1705. this.doTweenScrollQueue(time);
  1706. }
  1707. },
  1708. "doTweenScrollQueue": function(time){
  1709. if (this.tweenScrollQueue.length){
  1710. var i = this.tweenScrollQueue.length;
  1711. var to = this.tweenScrollQueue[this.tweenScrollQueue.length-1];
  1712. var scroll = this.getScroll();
  1713. var dy = to - scroll.y;
  1714. var step = dy/time;
  1715. var count = 0;
  1716. var move = 0;
  1717. var id = window.setInterval(function(){
  1718. this.scrollTo(0, scroll.y+count*step);
  1719. count++;
  1720. if (count>time){
  1721. window.clearInterval(id);
  1722. for (var x=1; x<=i; x++) this.tweenScrollQueue.shift();
  1723. if (this.tweenScrollQueue.length) this.doTweenScrollQueue(time);
  1724. }
  1725. }.bind(this), 1);
  1726. }
  1727. },
  1728. "isPointIn": function(px, py, offX, offY, el){
  1729. if (!offX) offX = 0;
  1730. if (!offY) offY = 0;
  1731. var position = this.getPosition(el);
  1732. var size = this.getSize();
  1733. return (position.x-offX<=px && position.x+size.x+offX>=px && position.y-offY<=py && position.y+size.y+offY>=py);
  1734. },
  1735. "isInPointInRect": function(sx, sy, ex, ey){
  1736. var position = this.getPosition();
  1737. var size = this.getSize();
  1738. var p1 = {"x": position.x, "y": position.y};
  1739. var p2 = {"x": position.x+size.x, "y": position.y};
  1740. var p3 = {"x": position.x+size.x, "y": position.y+size.y};
  1741. var p4 = {"x": position.x, "y": position.y+size.y};
  1742. var sp = {"x": Math.min(sx, ex), "y": Math.min(sy, ey)};
  1743. var ep = {"x": Math.max(sx, ex), "y": Math.max(sy, ey)};
  1744. if (p1.x>=sp.x && p1.y>=sp.y && p1.x<=ep.x && p1.y<=ep.y) return true;
  1745. if (p2.x>=sp.x && p2.y>=sp.y && p2.x<=ep.x && p2.y<=ep.y) return true;
  1746. if (p3.x>=sp.x && p3.y>=sp.y && p3.x<=ep.x && p3.y<=ep.y) return true;
  1747. if (p4.x>=sp.x && p4.y>=sp.y && p4.x<=ep.x && p4.y<=ep.y) return true;
  1748. if (p3.x>=sp.x && p3.y>=sp.y && p1.x<=sp.x && p1.y<=sp.y) return true;
  1749. if (p3.x>=ep.x && p3.y>=ep.y && p1.x<=ep.x && p1.y<=ep.y) return true;
  1750. if (p1.x<=sp.x && p2.x>=sp.x && p1.y>=sp.y && p4.y<=ep.y) return true;
  1751. if (p1.y<=sp.y && p4.y>=sp.y && p1.x>=sp.x && p2.x<=ep.x) return true;
  1752. return false;
  1753. },
  1754. "isOverlap": function(node){
  1755. var p = node.getPosition();
  1756. var s = node.getSize();
  1757. return this.isInPointInRect(p.x, p.y, p.x+s.x, p.y+s.y);
  1758. },
  1759. "getUsefulSize": function(){
  1760. var size = this.getSize();
  1761. var borderLeft = this.getStyle("border-left").toInt();
  1762. var borderBottom = this.getStyle("border-bottom").toInt();
  1763. var borderTop = this.getStyle("border-top").toInt();
  1764. var borderRight = this.getStyle("border-right").toInt();
  1765. var paddingLeft = this.getStyle("padding-left").toInt();
  1766. var paddingBottom = this.getStyle("padding-bottom").toInt();
  1767. var paddingTop = this.getStyle("padding-top").toInt();
  1768. var paddingRight = this.getStyle("padding-right").toInt();
  1769. var x = size.x-paddingLeft-paddingRight;
  1770. var y = size.y-paddingTop-paddingBottom;
  1771. return {"x": x, "y": y};
  1772. },
  1773. "clearStyles": function(isChild){
  1774. this.removeProperty("style");
  1775. if (isChild){
  1776. var subNode = this.getFirst();
  1777. while (subNode){
  1778. subNode.clearStyles(isChild);
  1779. subNode = subNode.getNext();
  1780. }
  1781. }
  1782. },
  1783. "maskIf": function(styles, click){
  1784. var style = {
  1785. "background-color": "#666666",
  1786. "opacity": 0.4,
  1787. "z-index":100
  1788. };
  1789. if (styles){
  1790. style = Object.merge(style, styles);
  1791. }
  1792. var position = this.getPosition(this.getOffsetParent());
  1793. this.mask({
  1794. "destroyOnHide": true,
  1795. "style": style,
  1796. "useIframeShim": true,
  1797. "iframeShimOptions": {"browsers": true},
  1798. "onShow": function(){
  1799. this.shim.shim.setStyles({
  1800. "opacity": 0,
  1801. "top": ""+position.y+"px",
  1802. "left": ""+position.x+"px"
  1803. });
  1804. },
  1805. "onClick": click
  1806. });
  1807. },
  1808. "scrollIn": function(where){
  1809. var wh = (where) ? where.toString().toLowerCase() : "center";
  1810. if (Browser.name=="ie" || Browser.name=="safari"){
  1811. var scrollNode = this.getParentSrcollNode();
  1812. var scrollFx = new Fx.Scroll(scrollNode);
  1813. var scroll = scrollNode.getScroll();
  1814. var size = scrollNode.getSize();
  1815. var thisSize = this.getComputedSize();
  1816. var p = this.getPosition(scrollNode);
  1817. if (wh=="start"){
  1818. var top = 0;
  1819. scrollFx.start(scroll.x, p.y-top+scroll.y);
  1820. }else if (wh=="end"){
  1821. var bottom = size.y-thisSize.totalHeight;
  1822. scrollFx.start(scroll.x, p.y-bottom+scroll.y);
  1823. }else{
  1824. var center = size.y/2-thisSize.totalHeight/2;
  1825. scrollFx.start(scroll.x, p.y-center+scroll.y);
  1826. }
  1827. }else{
  1828. if (wh!=="start" && wh!=="end") wh = "center"
  1829. this.scrollIntoView({"behavior": "smooth", "block": wh, "inline": "nearest"});
  1830. }
  1831. },
  1832. scrollToNode: function(el, where){
  1833. var scrollSize = this.getScrollSize();
  1834. if (!scrollSize.y) return true;
  1835. var wh = (where) ? where.toString().toLowerCase() : "bottom";
  1836. var node = $(el);
  1837. var size = node.getComputedSize();
  1838. var p = node.getPosition(this);
  1839. var thisSize = this.getComputedSize();
  1840. var scroll = this.getScroll();
  1841. if (wh==="top"){
  1842. var n = (p.y-thisSize.computedTop);
  1843. if (n<0) this.scrollTo(scroll.x, scroll.y+n);
  1844. n = (size.totalHeight+p.y-thisSize.computedTop)-thisSize.height;
  1845. if (n>0) this.scrollTo(scroll.x, scroll.y+n);
  1846. }else{
  1847. var n = (size.totalHeight+p.y-thisSize.computedTop)-thisSize.height;
  1848. if (n>0) this.scrollTo(scroll.x, scroll.y+n);
  1849. n = p.y-thisSize.computedTop;
  1850. if (n<0) this.scrollTo(scroll.x, scroll.y+n);
  1851. }
  1852. },
  1853. "getInnerStyles": function(){
  1854. var styles = {};
  1855. style = this.get("style");
  1856. if (style){
  1857. var styleArr = style.split(/\s*\;\s*/g);
  1858. styleArr.each(function(s){
  1859. if (s){
  1860. var sarr = s.split(/\s*\:\s*/g);
  1861. styles[sarr[0]] = (sarr.length>1) ? sarr[1]: ""
  1862. }
  1863. }.bind(this));
  1864. }
  1865. return styles;
  1866. },
  1867. "getInnerProperties": function(){
  1868. var properties = {};
  1869. if (this.attributes.length){
  1870. for (var i=0; i<this.attributes.length; i++){
  1871. properties[this.attributes[i].nodeName] = this.attributes[i].nodeValue;
  1872. }
  1873. }
  1874. return properties;
  1875. },
  1876. "getZIndex": function(){
  1877. var n = this;
  1878. var i=0;
  1879. while (n){
  1880. if (n.getStyle("position")==="absolute"){
  1881. var idx = n.getStyle("z-index");
  1882. i = (idx && idx.toFloat()>i) ? idx.toFloat()+1 : 0;
  1883. break;
  1884. }
  1885. n = n.getParent();
  1886. }
  1887. return i;
  1888. },
  1889. "getParentSrcollNode": function(){
  1890. var node = this.getParent();
  1891. while (node && (node.getScrollSize().y-2<=node.getSize().y || (node.getStyle("overflow")!=="auto" && node.getStyle("overflow-y")!=="auto"))){
  1892. node = node.getParent();
  1893. }
  1894. return node || null;
  1895. },
  1896. "getEdgeHeight": function(notMargin){
  1897. var h = 0;
  1898. h += (this.getStyle("border-top-width").toFloat() || 0)+ (this.getStyle("border-bottom-width").toFloat() || 0);
  1899. h += (this.getStyle("padding-top").toFloat() || 0)+ (this.getStyle("padding-bottom").toFloat() || 0);
  1900. if (!notMargin) h += (this.getStyle("margin-top").toFloat() || 0)+ (this.getStyle("margin-bottom").toFloat() || 0);
  1901. return h;
  1902. },
  1903. "getEdgeWidth": function(notMargin){
  1904. var h = 0;
  1905. h += (this.getStyle("border-left-width").toFloat() || 0)+ (this.getStyle("border-right-width").toFloat() || 0);
  1906. h += (this.getStyle("padding-left").toFloat() || 0)+ (this.getStyle("padding-right").toFloat() || 0);
  1907. if (!notMargin) h += (this.getStyle("margin-left").toFloat() || 0)+ (this.getStyle("margin-right").toFloat() || 0);
  1908. return h;
  1909. }
  1910. });
  1911. Object.copy = function(from, to){
  1912. Object.each(from, function(value, key){
  1913. switch (typeOf(value)){
  1914. case "object":
  1915. if (!to[key]) to[key]={};
  1916. Object.copy(value, to[key]);
  1917. break;
  1918. default:
  1919. to[key] = value;
  1920. }
  1921. });
  1922. };
  1923. if (window.JSON) JSON.format = JSON.encode;
  1924. if (window.Slick) {
  1925. Slick.definePseudo('src', function (value) {
  1926. return Element.get(this, "src").indexOf(value) !== -1;
  1927. });
  1928. Slick.definePseudo('srcarr', function (value) {
  1929. var vList = value.split(",");
  1930. var src = Element.get(this, "src");
  1931. var flag = false;
  1932. for (var i = 0; i < vList.length; i++) {
  1933. if (src.indexOf(vList[i]) !== -1) {
  1934. flag = true;
  1935. break;
  1936. }
  1937. }
  1938. return flag;
  1939. });
  1940. Slick.definePseudo('ahref', function (value) {
  1941. var href = Element.get(this, "href");
  1942. if (!href) href = "";
  1943. href = href.toString().toLowerCase();
  1944. return (href.indexOf(value) !== -1);
  1945. });
  1946. Slick.definePseudo('rowspanBefore', function (line) {
  1947. var tr = MWF.getParent(this, "tr");
  1948. var rowspan = this.get("rowspan").toInt() || 1;
  1949. var currentRowIndex = tr.rowIndex.toInt();
  1950. return rowspan > 1 && currentRowIndex < line.toInt() && currentRowIndex + rowspan - 1 >= line;
  1951. });
  1952. Slick.definePseudo('rowspan', function () {
  1953. var rowspan = this.get("rowspan").toInt() || 1;
  1954. return rowspan > 1;
  1955. });
  1956. Slick.definePseudo('colspanBefore', function (col) {
  1957. var tr = MWF.getParent(this, "tr");
  1958. var colspan = this.get("colspan").toInt() || 1;
  1959. var currentColIndex = this.cellIndex.toInt();
  1960. return colspan > 1 && currentColIndex < col.toInt() && currentColIndex + colspan - 1 >= col.toInt();
  1961. });
  1962. Slick.definePseudo('colspan', function () {
  1963. var colspan = this.get("colspan").toInt() || 1;
  1964. return colspan > 1;
  1965. });
  1966. }
  1967. o2.common = o2.common || {};
  1968. o2.common.encodeHtml = function(str){
  1969. str = str.toString();
  1970. str = str.replace(/\&/g, "&amp;");
  1971. str = str.replace(/>/g, "&gt;");
  1972. str = str.replace(/</g, "&lt;");
  1973. return str.replace(/\"/g, "&quot;");
  1974. };
  1975. o2.common.getResponseTextPost = function(path, body, contentType){
  1976. var returnText = "";
  1977. var options = {
  1978. url: path,
  1979. async: false,
  1980. data: body,
  1981. method: "post",
  1982. onSuccess: function(esponseTree, responseElements, responseHTML, responseJavaScript){
  1983. returnText = responseHTML;
  1984. }
  1985. };
  1986. var r = new Request.HTML(options);
  1987. r.send();
  1988. return returnText;
  1989. };
  1990. o2.common.getResponseText = function(path){
  1991. var returnText = "";
  1992. var options = {
  1993. url: path,
  1994. async: false,
  1995. method: "get",
  1996. onSuccess: function(esponseTree, responseElements, responseHTML, responseJavaScript){
  1997. returnText = responseHTML;
  1998. }
  1999. };
  2000. var r = new Request.HTML(options);
  2001. r.send();
  2002. return returnText;
  2003. };
  2004. o2.common.toDate = function(str){
  2005. var tmpArr = str.split(" ");
  2006. if (!tmpArr[1]) tmpArr.push("0:0:0");
  2007. var dateArr = tmpArr[0].split("-");
  2008. var timeArr = tmpArr[1].split(":");
  2009. return new Date(dateArr[0],parseInt(dateArr[1])-1,dateArr[2],timeArr[0],timeArr[1],timeArr[2]);
  2010. };
  2011. o2.common.toDate = function(str){
  2012. var tmpArr = str.split(" ");
  2013. if (!tmpArr[1]) tmpArr.push("0:0:0");
  2014. var dateArr = tmpArr[0].split("-");
  2015. var timeArr = tmpArr[1].split(":");
  2016. return new Date(dateArr[0],parseInt(dateArr[1])-1,dateArr[2],timeArr[0],timeArr[1],timeArr[2]);
  2017. };
  2018. o2.grayscale = function(src, width, height, callback){
  2019. try {
  2020. var canvas = document.createElement('canvas');
  2021. var ctx = canvas.getContext('2d');
  2022. var imgObj = new Image();
  2023. imgObj.src = src;
  2024. canvas.width = width || imgObj.width;
  2025. canvas.height = height || imgObj.height;
  2026. ctx.drawImage(imgObj, 0, 0);
  2027. var imgPixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
  2028. for(var y = 0; y < imgPixels.height; y++){
  2029. for(var x = 0; x < imgPixels.width; x++){
  2030. var i = (y * 4) * imgPixels.width + x * 4;
  2031. var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
  2032. imgPixels.data[i] = avg;
  2033. imgPixels.data[i + 1] = avg;
  2034. imgPixels.data[i + 2] = avg;
  2035. }
  2036. }
  2037. ctx.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
  2038. var src1 = canvas.toDataURL();
  2039. //var blob = canvas.toBlob();
  2040. canvas.destroy();
  2041. return {"status": "success", "src": src1};
  2042. }catch(e){
  2043. return {"status": "error", "src": src}
  2044. }
  2045. };
  2046. o2.eventPosition = function(e){
  2047. var x = 0;
  2048. var y = 0;
  2049. if (Browser.name=="firefox"){
  2050. x = parseFloat(e.event.clientX || e.event.x);
  2051. y = parseFloat(e.event.clientY || e.event.y);
  2052. }else{
  2053. x = parseFloat(e.event.x);
  2054. y = parseFloat(e.event.y);
  2055. }
  2056. return {"x": x, "y": y};
  2057. };
  2058. if (window.Browser){
  2059. if (Browser.name==="ie" && Browser.version<9){
  2060. Browser.ieuns = true;
  2061. }else if(Browser.name==="ie" && Browser.version<10){
  2062. Browser.iecomp = true;
  2063. }
  2064. if (Browser.iecomp){
  2065. o2.load("ie_adapter", null, false);
  2066. o2.session.isDebugger = true;
  2067. //layout["debugger"] = true;
  2068. }
  2069. o2.session.isMobile = (["mac", "win", "linux"].indexOf(Browser.Platform.name)===-1);
  2070. }
  2071. })();
  2072. o2.more = true;
  2073. //o2.addReady
  2074. (function(){
  2075. //dom ready
  2076. var _dom = {
  2077. ready: false,
  2078. loaded: false,
  2079. checks: [],
  2080. shouldPoll: false,
  2081. timer: null,
  2082. testElement: document.createElement('div'),
  2083. readys: [],
  2084. domready: function(){
  2085. clearTimeout(_dom.timer);
  2086. if (_dom.ready) return;
  2087. _dom.loaded = _dom.ready = true;
  2088. o2.removeListener(document, 'DOMContentLoaded', _dom.checkReady);
  2089. o2.removeListener(document, 'readystatechange', _dom.check);
  2090. _dom.onReady();
  2091. },
  2092. check: function(){
  2093. for (var i = _dom.checks.length; i--;) if (_dom.checks[i]() && window.MooTools && o2.core && o2.more){
  2094. _dom.domready();
  2095. return true;
  2096. }
  2097. return false;
  2098. },
  2099. poll: function(){
  2100. clearTimeout(_dom.timer);
  2101. if (!_dom.check()) _dom.timer = setTimeout(_dom.poll, 10);
  2102. },
  2103. /*<ltIE8>*/
  2104. // doScroll technique by Diego Perini http://javascript.nwbox.com/IEContentLoaded/
  2105. // testElement.doScroll() throws when the DOM is not ready, only in the top window
  2106. doScrollWorks: function(){
  2107. try {
  2108. _dom.testElement.doScroll();
  2109. return true;
  2110. } catch (e){}
  2111. return false;
  2112. },
  2113. /*</ltIE8>*/
  2114. onReady: function(){
  2115. for (var i=0; i<_dom.readys.length; i++){
  2116. this.readys[i].apply(window);
  2117. }
  2118. },
  2119. addReady: function(fn){
  2120. if (_dom.loaded){
  2121. if (fn) fn.apply(window);
  2122. }else{
  2123. if (fn) _dom.readys.push(fn);
  2124. }
  2125. return _dom;
  2126. },
  2127. checkReady: function(){
  2128. _dom.checks.push(function(){return true});
  2129. _dom.check();
  2130. }
  2131. };
  2132. var _loadO2 = function(){
  2133. (!o2.core) ? this.o2.load("o2.core", _dom.check) : _dom.check();
  2134. (!o2.more) ? this.o2.load("o2.more", _dom.check) : _dom.check();
  2135. };
  2136. o2.addListener(document, 'DOMContentLoaded', _dom.checkReady);
  2137. /*<ltIE8>*/
  2138. // If doScroll works already, it can't be used to determine domready
  2139. // e.g. in an iframe
  2140. if (_dom.testElement.doScroll && !_dom.doScrollWorks()){
  2141. _dom.checks.push(_dom.doScrollWorks);
  2142. _dom.shouldPoll = true;
  2143. }
  2144. /*</ltIE8>*/
  2145. if (document.readyState) _dom.checks.push(function(){
  2146. var state = document.readyState;
  2147. return (state == 'loaded' || state == 'complete');
  2148. });
  2149. if ('onreadystatechange' in document) o2.addListener(document, 'readystatechange', _dom.check);
  2150. else _dom.shouldPoll = true;
  2151. if (_dom.shouldPoll) _dom.poll();
  2152. if (!window.MooTools){
  2153. this.o2.load("mootools", function(){ _loadO2(); _dom.check(); });
  2154. }else{
  2155. _loadO2();
  2156. }
  2157. this.o2.addReady = function(fn){ _dom.addReady.call(_dom, fn); };
  2158. })();
  2159. //compatible
  2160. COMMON = {
  2161. "DOM":{},
  2162. "setContentPath": function(path){
  2163. COMMON.contentPath = path;
  2164. },
  2165. "JSON": o2.JSON,
  2166. "Browser": Browser,
  2167. "Class": o2.Class,
  2168. "XML": o2.xml,
  2169. "AjaxModule": {
  2170. "load": function(urls, callback, async, reload){
  2171. o2.load(urls, callback, reload, document);
  2172. },
  2173. "loadDom": function(urls, callback, async, reload){
  2174. o2.load(urls, callback, reload, document);
  2175. },
  2176. "loadCss": function(urls, callback, async, reload, sourceDoc){
  2177. o2.loadCss(urls, document.body, callback, reload, sourceDoc);
  2178. }
  2179. },
  2180. "Request": Request,
  2181. "typeOf": o2.typeOf
  2182. };
  2183. COMMON.Browser.Platform.isMobile = o2.session.isMobile;
  2184. COMMON.DOM.addReady = o2.addReady;
  2185. MWF = o2;
  2186. MWF.getJSON = o2.JSON.get;
  2187. MWF.getJSONP = o2.JSON.getJsonp;
  2188. MWF.defaultPath = o2.session.path;