o2.js 87 KB

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