o2.js 85 KB

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