o2.js 97 KB

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