o2.js 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287
  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. o2.runCallback(callback, "failure", [r]);
  942. }
  943. });
  944. xhr.send();
  945. };
  946. var _requireSingle = function(module, callback, async, compression){
  947. if (o2.typeOf(module)==="array"){
  948. _requireAppSingle(module, callback, async, compression);
  949. }else{
  950. module = module.replace("MWF.", "o2.");
  951. var levels = module.split(".");
  952. if (levels[levels.length-1]==="*") levels[levels.length-1] = "package";
  953. levels.shift();
  954. var o = o2;
  955. var i = 0;
  956. while (o && i<levels.length){
  957. o = o[levels[i]];
  958. i++
  959. }
  960. if (!o){
  961. var jsPath = this.o2.session.path;
  962. jsPath +="/"+levels.join("/")+".js";
  963. var loadAsync = (async!==false);
  964. _requireJs(jsPath, callback, loadAsync, compression, module);
  965. }else{
  966. o2.runCallback(callback, "success", [module]);
  967. }
  968. }
  969. };
  970. var _requireSequence = function(fun, module, thisLoaded, thisErrorLoaded, callback, async, compression){
  971. var m = module.shift();
  972. fun(m, {
  973. "onSuccess": function(m){
  974. thisLoaded.push(m);
  975. o2.runCallback(callback, "every", [m]);
  976. if (module.length){
  977. _requireSequence(fun, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  978. }else{
  979. if (thisErrorLoaded.length){
  980. o2.runCallback(callback, "failure", [thisLoaded, thisErrorLoaded]);
  981. }else{
  982. o2.runCallback(callback, "success", [thisLoaded, thisErrorLoaded]);
  983. }
  984. }
  985. },
  986. "onFailure": function(){
  987. thisErrorLoaded.push(module[i]);
  988. o2.runCallback(callback, "failure", [thisLoaded, thisErrorLoaded]);
  989. }
  990. }, async, compression);
  991. };
  992. var _requireDisarray = function(fun, module, thisLoaded, thisErrorLoaded, callback, async, compression){
  993. for (var i=0; i<module.length; i++){
  994. fun(module[i], {
  995. "onSuccess": function(m){
  996. thisLoaded.push(m);
  997. o2.runCallback(callback, "every", [m]);
  998. if ((thisLoaded.length+thisErrorLoaded.length)===module.length){
  999. if (thisErrorLoaded.length){
  1000. o2.runCallback(callback, "failure", [thisLoaded, thisErrorLoaded]);
  1001. }else{
  1002. o2.runCallback(callback, "success", [thisLoaded, thisErrorLoaded]);
  1003. }
  1004. }
  1005. },
  1006. "onFailure": function(){
  1007. thisErrorLoaded.push(module[i]);
  1008. o2.runCallback(callback, "failure", [thisLoaded, thisErrorLoaded]);
  1009. }
  1010. }, async, compression);
  1011. }
  1012. };
  1013. var _require = function(module, callback, async, sequence, compression){
  1014. var type = typeOf(module);
  1015. if (type==="array"){
  1016. var sql = !!sequence;
  1017. var thisLoaded = [];
  1018. var thisErrorLoaded = [];
  1019. if (sql){
  1020. _requireSequence(_requireSingle, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  1021. }else{
  1022. _requireDisarray(_requireSingle, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  1023. }
  1024. }
  1025. if (type==="string"){
  1026. _requireSingle(module, callback, async, compression);
  1027. }
  1028. };
  1029. var _requireAppSingle = function(modules, callback, async, compression){
  1030. var module = modules[0];
  1031. var clazz = modules[1];
  1032. var levels = module.split(".");
  1033. var o = o2.xApplication;
  1034. var i = 0;
  1035. while (o && i<levels.length){
  1036. o = o[levels[i]];
  1037. i++
  1038. }
  1039. if (o) o = o[clazz || "Main"];
  1040. if (!o){
  1041. //levels.shift();
  1042. var root = "x_component_"+levels.join("_");
  1043. var clazzName = clazz || "Main";
  1044. var path = "../"+root+"/"+clazzName.replace(/\./g, "/")+".js";
  1045. var loadAsync = (async!==false);
  1046. _requireJs(path, callback, loadAsync, compression);
  1047. }else{
  1048. o2.runCallback(callback, "success");
  1049. }
  1050. };
  1051. var _requireApp = function(module, clazz, callback, async, sequence, compression){
  1052. var type = typeOf(module);
  1053. if (type==="array"){
  1054. var sql = !!sequence;
  1055. var thisLoaded = [];
  1056. var thisErrorLoaded = [];
  1057. if (sql){
  1058. _requireSequence(_requireAppSingle, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  1059. }else{
  1060. _requireDisarray(_requireAppSingle, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  1061. }
  1062. }
  1063. if (type==="string"){
  1064. var modules = [module, clazz];
  1065. _requireAppSingle(modules, callback, async, compression);
  1066. }
  1067. };
  1068. JSON = window.JSON || {};
  1069. var _json = JSON;
  1070. _json.get = function(url, callback, async, nocache){
  1071. var loadAsync = (async !== false);
  1072. var noJsonCache = (nocache === true);
  1073. url = (url.indexOf("?")!==-1) ? url+"&v="+o2.version.v : url+"?v="+o2.version.v;
  1074. var json = null;
  1075. var res = new Request.JSON({
  1076. url: o2.filterUrl(url),
  1077. secure: false,
  1078. method: "get",
  1079. noCache: noJsonCache,
  1080. async: loadAsync,
  1081. withCredentials: true,
  1082. onSuccess: function(responseJSON, responseText){
  1083. json = responseJSON;
  1084. if (typeOf(callback).toLowerCase() === 'function'){
  1085. callback(responseJSON, responseText);
  1086. }else{
  1087. o2.runCallback(callback, "success", [responseJSON, responseText]);
  1088. }
  1089. }.bind(this),
  1090. onFailure: function(xhr){
  1091. o2.runCallback(callback, "requestFailure", [xhr]);
  1092. }.bind(this),
  1093. onError: function(text, error){
  1094. o2.runCallback(callback, "error", [text, error]);
  1095. }.bind(this)
  1096. });
  1097. res.send();
  1098. return json;
  1099. };
  1100. _json.getJsonp = function(url, callback, async, callbackKey){
  1101. var loadAsync = (async !== false);
  1102. var callbackKeyWord = callbackKey || "callback";
  1103. url = (url.indexOf("?")!==-1) ? url+"&v="+o2.version.v : url+"?v="+o2.version.v;
  1104. var res = new Request.JSONP({
  1105. url: o2.filterUrl(url),
  1106. secure: false,
  1107. method: "get",
  1108. noCache: true,
  1109. async: loadAsync,
  1110. callbackKey: callbackKeyWord,
  1111. onSuccess: function(responseJSON, responseText){
  1112. o2.runCallback(callback, "success",[responseJSON, responseText]);
  1113. }.bind(this),
  1114. onFailure: function(xhr){
  1115. o2.runCallback(callback, "requestFailure",[xhr]);
  1116. }.bind(this),
  1117. onError: function(text, error){
  1118. o2.runCallback(callback, "error",[text, error]);
  1119. }.bind(this)
  1120. });
  1121. res.send();
  1122. };
  1123. var _loadLP = function(name){
  1124. var jsPath = o2.session.path;
  1125. jsPath = jsPath+"/lp/"+name+".js";
  1126. var r = new Request({
  1127. url: o2.filterUrl(jsPath),
  1128. async: false,
  1129. method: "get",
  1130. onSuccess: function(responseText){
  1131. try{
  1132. Browser.exec(responseText);
  1133. }catch (e){}
  1134. },
  1135. onFailure: function(xhr){
  1136. throw "loadLP Error: "+xhr.responseText;
  1137. }
  1138. });
  1139. r.send();
  1140. };
  1141. var _cacheUrls = [
  1142. /jaxrs\/form\/workorworkcompleted\/.+/ig,
  1143. // /jaxrs\/script/ig,
  1144. /jaxrs\/script\/.+\/app\/.+\/imported/ig,
  1145. /jaxrs\/script\/portal\/.+\/name\/.+\/imported/ig,
  1146. /jaxrs\/script\/.+\/application\/.+\/imported/ig,
  1147. /jaxrs\/page\/.+\/portal\/.+/ig
  1148. // /jaxrs\/authentication/ig
  1149. // /jaxrs\/statement\/.*\/execute\/page\/.*\/size\/.*/ig
  1150. ];
  1151. _restful = function(method, address, data, callback, async, withCredentials, cache){
  1152. var loadAsync = (async !== false);
  1153. var credentials = (withCredentials !== false);
  1154. address = (address.indexOf("?")!==-1) ? address+"&v="+o2.version.v : address+"?v="+o2.version.v;
  1155. //var noCache = cache===false;
  1156. var noCache = !cache;
  1157. //if (Browser.name == "ie")
  1158. if (_cacheUrls.length){
  1159. for (var i=0; i<_cacheUrls.length; i++){
  1160. if (_cacheUrls[i].test(address)){
  1161. noCache = false;
  1162. break;
  1163. }
  1164. }
  1165. }
  1166. //var noCache = false;
  1167. var res = new Request.JSON({
  1168. url: o2.filterUrl(address),
  1169. secure: false,
  1170. method: method,
  1171. emulation: false,
  1172. noCache: noCache,
  1173. async: loadAsync,
  1174. withCredentials: credentials,
  1175. onSuccess: function(responseJSON, responseText){
  1176. // var xToken = this.getHeader("authorization");
  1177. // if (!xToken) xToken = this.getHeader("x-token");
  1178. var xToken = this.getHeader("x-token");
  1179. if (xToken){
  1180. if (window.layout){
  1181. if (!layout.session) layout.session = {};
  1182. layout.session.token = xToken;
  1183. }
  1184. }
  1185. o2.runCallback(callback, "success", [responseJSON]);
  1186. },
  1187. onFailure: function(xhr){
  1188. o2.runCallback(callback, "requestFailure", [xhr]);
  1189. }.bind(this),
  1190. onError: function(text, error){
  1191. o2.runCallback(callback, "error", [text, error]);
  1192. }.bind(this)
  1193. });
  1194. res.setHeader("Content-Type", "application/json; charset=utf-8");
  1195. res.setHeader("Accept", "text/html,application/json,*/*");
  1196. if (window.layout) {
  1197. if (layout["debugger"]){
  1198. res.setHeader("x-debugger", "true");
  1199. }
  1200. if (layout.session && layout.session.user){
  1201. if (layout.session.user.token) {
  1202. res.setHeader("x-token", layout.session.user.token);
  1203. res.setHeader("authorization", layout.session.user.token);
  1204. }
  1205. }
  1206. }
  1207. //Content-Type application/x-www-form-urlencoded; charset=utf-8
  1208. res.send(data);
  1209. return res;
  1210. };
  1211. var _release = function(o){
  1212. var type = typeOf(o);
  1213. switch (type){
  1214. case "object":
  1215. for (var k in o){
  1216. //if (o[k] && o[k].destroy) o[k].destroy();
  1217. o[k] = null;
  1218. }
  1219. break;
  1220. case "array":
  1221. for (var i=0; i< o.length; i++){
  1222. _release(o[i]);
  1223. if (o[i]) o[i] = null;
  1224. }
  1225. break;
  1226. }
  1227. };
  1228. var _defineProperties = Object.defineProperties || function (obj, properties) {
  1229. function convertToDescriptor(desc) {
  1230. function hasProperty(obj, prop) {
  1231. return Object.prototype.hasOwnProperty.call(obj, prop);
  1232. }
  1233. function isCallable(v) {
  1234. // NB: modify as necessary if other values than functions are callable.
  1235. return typeof v === "function";
  1236. }
  1237. if (typeof desc !== "object" || desc === null)
  1238. throw new TypeError("bad desc");
  1239. var d = {};
  1240. if (hasProperty(desc, "enumerable"))
  1241. d.enumerable = !!desc.enumerable;
  1242. if (hasProperty(desc, "configurable"))
  1243. d.configurable = !!desc.configurable;
  1244. if (hasProperty(desc, "value"))
  1245. d.value = desc.value;
  1246. if (hasProperty(desc, "writable"))
  1247. d.writable = !!desc.writable;
  1248. if (hasProperty(desc, "get")) {
  1249. var g = desc.get;
  1250. if (!isCallable(g) && typeof g !== "undefined")
  1251. throw new TypeError("bad get");
  1252. d.get = g;
  1253. }
  1254. if (hasProperty(desc, "set")) {
  1255. var s = desc.set;
  1256. if (!isCallable(s) && typeof s !== "undefined")
  1257. throw new TypeError("bad set");
  1258. d.set = s;
  1259. }
  1260. if (("get" in d || "set" in d) && ("value" in d || "writable" in d))
  1261. throw new TypeError("identity-confused descriptor");
  1262. return d;
  1263. }
  1264. if (typeof obj !== "object" || obj === null)
  1265. throw new TypeError("bad obj");
  1266. properties = Object(properties);
  1267. var keys = Object.keys(properties);
  1268. var descs = [];
  1269. for (var j = 0; j < keys.length; j++)
  1270. descs.push([keys[j], convertToDescriptor(properties[keys[j]])]);
  1271. for (var i = 0; i < descs.length; i++){
  1272. if (Object.defineProperty && (Browser.name=="ie" && Browser.version!=8)){
  1273. Object.defineProperty(obj, descs[i][0], descs[i][1]);
  1274. }else{
  1275. if (descs[i][1].value) obj[descs[i][0]] = descs[i][1].value;
  1276. if (descs[i][1].get) obj["get"+descs[i][0].capitalize()] = descs[i][1].get;
  1277. if (descs[i][1].set) obj["set"+descs[i][0].capitalize()] = descs[i][1].set;
  1278. }
  1279. }
  1280. return obj;
  1281. };
  1282. if (!Array.prototype.findIndex) {
  1283. Object.defineProperty(Array.prototype, 'findIndex', {
  1284. value: function(predicate) {
  1285. if (this == null) {
  1286. throw new TypeError('"this" is null or not defined');
  1287. }
  1288. var o = Object(this);
  1289. var len = o.length >>> 0;
  1290. if (typeof predicate !== 'function') {
  1291. throw new TypeError('predicate must be a function');
  1292. }
  1293. var thisArg = arguments[1];
  1294. var k = 0;
  1295. while (k < len) {
  1296. var kValue = o[k];
  1297. if (predicate.call(thisArg, kValue, k, o)) {
  1298. return k;
  1299. }
  1300. k++;
  1301. }
  1302. return -1;
  1303. }
  1304. });
  1305. }
  1306. if (!Array.prototype.find) {
  1307. Object.defineProperty(Array.prototype, 'find', {
  1308. value: function(predicate) {
  1309. if (this == null) {
  1310. throw new TypeError('"this" is null or not defined');
  1311. }
  1312. var o = Object(this);
  1313. var len = o.length >>> 0;
  1314. if (typeof predicate !== 'function') {
  1315. throw new TypeError('predicate must be a function');
  1316. }
  1317. var thisArg = arguments[1];
  1318. var k = 0;
  1319. while (k < len) {
  1320. var kValue = o[k];
  1321. if (predicate.call(thisArg, kValue, k, o)) {
  1322. return kValue;
  1323. }
  1324. k++;
  1325. }
  1326. return undefined;
  1327. }
  1328. });
  1329. }
  1330. var _txt = function(v){
  1331. var t = v.replace(/\</g, "&lt;");
  1332. t = t.replace(/\</g, "&gt;");
  1333. return t;
  1334. };
  1335. this.o2.Class = _Class;
  1336. this.o2.require = _require;
  1337. this.o2.requireApp = _requireApp;
  1338. this.o2.JSON = _json;
  1339. this.o2.loadLP = _loadLP;
  1340. this.o2.restful = _restful;
  1341. this.o2.release = _release;
  1342. this.o2.defineProperties = _defineProperties;
  1343. this.o2.txt = _txt;
  1344. Object.repeatArray = function(o, count){
  1345. var arr = [];
  1346. for (var i=0; i<count; i++){
  1347. arr.push(o)
  1348. }
  1349. return arr;
  1350. }
  1351. Date.implement({
  1352. "getFromServer": function(){
  1353. var d;
  1354. o2.Actions.get("x_program_center").echo(function(json){
  1355. d = Date.parse(json.data.serverTime);
  1356. }, null, false);
  1357. return d;
  1358. }
  1359. });
  1360. })();
  1361. o2.core = true;
  1362. /** ***** BEGIN LICENSE BLOCK *****
  1363. * |------------------------------------------------------------------------------|
  1364. * | O2OA 活力办公 创意无限 o2.more.js |
  1365. * |------------------------------------------------------------------------------|
  1366. * | Distributed under the AGPL license: |
  1367. * |------------------------------------------------------------------------------|
  1368. * | Copyright © 2018, o2oa.net, o2server.io O2 Team |
  1369. * | All rights reserved. |
  1370. * |------------------------------------------------------------------------------|
  1371. *
  1372. * This file is part of O2OA.
  1373. *
  1374. * O2OA is free software: you can redistribute it and/or modify
  1375. * it under the terms of the GNU Affero General Public License as published by
  1376. * the Free Software Foundation, either version 3 of the License, or
  1377. * (at your option) any later version.
  1378. *
  1379. * O2OA is distributed in the hope that it will be useful,
  1380. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1381. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1382. * GNU Affero General Public License for more details.
  1383. *
  1384. * You should have received a copy of the GNU General Public License
  1385. * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
  1386. *
  1387. * ***** END LICENSE BLOCK ******/
  1388. (function (){
  1389. o2.getCenterPosition = function(el, width, height){
  1390. var elPositon = $(el).getPosition();
  1391. var elSize = $(el).getSize();
  1392. var node = $("layout");
  1393. var size = (node) ? $(node).getSize() : $(document.body).getSize();
  1394. var top = (elPositon.y+elSize.y)/2 - (height/2);
  1395. var left = (elPositon.x+elSize.x)/2-(width/2);
  1396. if ((left+width)>size.x){
  1397. left = size.x-width-10;
  1398. }
  1399. if ((top+height)>size.y){
  1400. top = size.y-height-10;
  1401. }
  1402. return {"x": left, "y": top};
  1403. };
  1404. o2.getMarkSize = function(node){
  1405. var size;
  1406. if (!node){
  1407. size = $(document.body).getSize();
  1408. var winSize = $(window).getSize();
  1409. var height = size.y;
  1410. var width = size.x;
  1411. if (height<winSize.y) height = winSize.y;
  1412. if (width<winSize.x) width = winSize.x;
  1413. return {x: size.x, y: height};
  1414. }else{
  1415. size = $(node).getSize();
  1416. return {x: size.x, y: size.y};
  1417. }
  1418. };
  1419. o2.json = function(jsonString, fun){
  1420. var obj = JSON.decode(jsonString);
  1421. var p = fun.split(".");
  1422. var tmp = obj;
  1423. p.each(function(item){
  1424. if (item.indexOf("[")!==-1){
  1425. var x = item.split("[");
  1426. var i = parseInt(x[1].substr(0, x[1].indexOf("]")));
  1427. tmp = tmp[x[0]][i];
  1428. }else{
  1429. tmp = tmp[item];
  1430. }
  1431. });
  1432. return tmp;
  1433. };
  1434. o2.getHTMLTemplate = function(url, callback, async){
  1435. var loadAsync = (async !== false);
  1436. var res = new Request.HTML({
  1437. url: url,
  1438. async: loadAsync,
  1439. method: "get",
  1440. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  1441. o2.runCallback(callback, "success", [responseTree, responseElements, responseHTML, responseJavaScript]);
  1442. }.bind(this),
  1443. onFailure: function(xhr){
  1444. o2.runCallback(callback, "requestFailure", [xhr]);
  1445. }
  1446. });
  1447. res.send();
  1448. };
  1449. o2.getRequestText = function(url, callback, async){
  1450. var loadAsync = (async !== false);
  1451. url = (url.indexOf("?")!==-1) ? url+"&v="+o2.version.v : url+"?v="+o2.version.v;
  1452. var res = new Request({
  1453. url: url,
  1454. async: loadAsync,
  1455. method: "get",
  1456. onSuccess: function(responseText, responseXML){
  1457. o2.runCallback(callback, "success",[responseText, responseXML]);
  1458. }.bind(this),
  1459. onFailure: function(xhr){
  1460. o2.runCallback(callback, "requestFailure",[xhr]);
  1461. }
  1462. });
  1463. res.send();
  1464. };
  1465. o2.encodeJsonString = function(str){
  1466. var tmp = [str];
  1467. var dataStr = (JSON.encode(tmp));
  1468. return dataStr.substr(2, dataStr.length-4);
  1469. };
  1470. o2.decodeJsonString = function(str){
  1471. var tmp = "[\""+str+"\"]";
  1472. var dataObj = (JSON.decode(tmp));
  1473. return dataObj[0];
  1474. };
  1475. o2.getTextSize = function(text, styles){
  1476. var tmpSpan = new Element("span", {
  1477. "text": text,
  1478. "styles": styles
  1479. }).inject($(document.body));
  1480. var size = tmpSpan.getSize();
  1481. tmpSpan.destroy();
  1482. return size;
  1483. };
  1484. o2.getCenter = function(size, target, offset){
  1485. if (!target) target = document.body;
  1486. var targetSize = target.getSize();
  1487. var targetPosition = target.getPosition(offset);
  1488. var targetScroll = target.getScroll();
  1489. var x = targetSize.x/2;
  1490. var y = targetSize.y/2;
  1491. x = x-(size.x/2);
  1492. y = y-(size.y/2);
  1493. x = x+targetPosition.x;
  1494. y = y+targetPosition.y;
  1495. x = x+targetScroll.x;
  1496. y = y+targetScroll.y;
  1497. return {"x": x, "y": y};
  1498. };
  1499. o2.getEPointer = function(e){
  1500. var x = 0;
  1501. var y = 0;
  1502. if (typeOf(e)=="element"){
  1503. var position = e.getPosition(this.content);
  1504. x = position.x;
  1505. y = position.y;
  1506. }else{
  1507. if (Browser.name=="firefox"){
  1508. x = parseFloat(e.event.clientX || e.event.x);
  1509. y = parseFloat(e.event.clientY || e.event.y);
  1510. }else{
  1511. x = parseFloat(e.event.x);
  1512. y = parseFloat(e.event.y);
  1513. }
  1514. if (e.target){
  1515. var position = e.target.getPosition(this.content);
  1516. x = position.x;
  1517. y = position.y;
  1518. }
  1519. // }
  1520. }
  1521. return {"x": x, "y": y};
  1522. };
  1523. o2.getParent = function(node, tag){
  1524. var pNode = node.parentElement;
  1525. while(pNode && pNode.tagName.toString().toLowerCase() !== tag.toString().toLowerCase()){
  1526. pNode = pNode.parentElement;
  1527. }
  1528. return pNode;
  1529. };
  1530. o2.getOffset = function(evt){
  1531. if (Browser.name==="firefox"){
  1532. return {
  1533. "offsetX": evt.layerX,
  1534. "offsetY": evt.layerY
  1535. };
  1536. }else{
  1537. return {
  1538. "offsetX": evt.offsetX,
  1539. "offsetY": evt.offsetY
  1540. }
  1541. }
  1542. };
  1543. if (String.implement) String.implement({
  1544. "getAllIndexOf": function(str){
  1545. var idxs= [];
  1546. var idx = this.indexOf(str);
  1547. while (idx !== -1){
  1548. idxs.push(idx);
  1549. idx = this.indexOf(str, idx+1);
  1550. }
  1551. return idxs;
  1552. }
  1553. });
  1554. if (Array.implement) Array.implement({
  1555. "trim": function(){
  1556. var arr = [];
  1557. this.each(function(v){
  1558. if (v) arr.push(v);
  1559. });
  1560. return arr;
  1561. },
  1562. "isIntersect": function(arr){
  1563. return this.some(function(item){ return (arr.indexOf(item)!==-1); })
  1564. }
  1565. });
  1566. if (window.Element && Element.implement) Element.implement({
  1567. "isIntoView": function() {
  1568. // var pNode = this.getParent();
  1569. // while (pNode && ((pNode.getScrollSize().y-(pNode.getComputedSize().height+1)<=0) || pNode.getStyle("overflow")==="visible")) pNode = pNode.getParent();
  1570. //
  1571. var pNode = this.getParentSrcollNode();
  1572. if (!pNode) pNode = document.body;
  1573. var size = pNode.getSize();
  1574. var srcoll = pNode.getScroll();
  1575. var p = (pNode == window) ? {"x":0, "y": 0} : this.getPosition(pNode);
  1576. var nodeSize = this.getSize();
  1577. //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);
  1578. return (p.x-srcoll.x>=0 && p.y>=0) && (p.x+nodeSize.x<size.x+srcoll.x && p.y+nodeSize.y<size.y)
  1579. },
  1580. "appendHTML": function(html, where){
  1581. if (this.insertAdjacentHTML){
  1582. var whereText = "beforeEnd";
  1583. if (where==="before") whereText = "beforeBegin";
  1584. if (where==="after") whereText = "afterEnd";
  1585. if (where==="bottom") whereText = "beforeEnd";
  1586. if (where==="top") whereText = "afterBegin";
  1587. this.insertAdjacentHTML(whereText, html);
  1588. }else {
  1589. if (where==="bottom") this.innerHTML = this.innerHTML+html;
  1590. if (where==="top") this.innerHTML = html+this.innerHTML;
  1591. }
  1592. },
  1593. "positionTo": function(x,y){
  1594. var left = x.toFloat();
  1595. var top = y.toFloat();
  1596. var offsetNode = this.getOffsetParent();
  1597. if (offsetNode){
  1598. var offsetPosition = offsetNode.getPosition();
  1599. left = left-offsetPosition.x;
  1600. top = top-offsetPosition.y;
  1601. }
  1602. this.setStyles({"top": top, "left": left});
  1603. return this;
  1604. },
  1605. "getBorder": function(){
  1606. var positions = ["top", "left", "right", "bottom"];
  1607. var styles = ["color", "style", "width"];
  1608. var obj = {};
  1609. positions.each(function (position){
  1610. styles.each(function(style){
  1611. var key = "border-"+position+"-"+style;
  1612. obj[key] = this.getStyle(key);
  1613. }.bind(this));
  1614. }.bind(this));
  1615. return obj;
  1616. },
  1617. "isOutside": function(e){
  1618. var elementCoords = this.getCoordinates();
  1619. var targetCoords = this.getCoordinates();
  1620. if(((e.page.x < elementCoords.left || e.page.x > (elementCoords.left + elementCoords.width)) ||
  1621. (e.page.y < elementCoords.top || e.page.y > (elementCoords.top + elementCoords.height))) &&
  1622. ((e.page.x < targetCoords.left || e.page.x > (targetCoords.left + targetCoords.width)) ||
  1623. (e.page.y < targetCoords.top || e.page.y > (targetCoords.top + targetCoords.height))) ) return true;
  1624. return false;
  1625. },
  1626. "getAbsolutePosition":function(){
  1627. var styleLeft = 0;
  1628. var styleTop = 0;
  1629. var node = this;
  1630. styleLeft = node.offsetLeft;
  1631. styleTop = node.offsetTop;
  1632. node = node.parentElement;
  1633. while (node && node.tagName.toString().toLowerCase()!=="body"){
  1634. styleLeft += node.offsetLeft;
  1635. styleTop += node.offsetTop;
  1636. node = node.offsetParent;
  1637. }
  1638. return {x: styleLeft, y: styleTop};
  1639. },
  1640. "tweenScroll": function(to, time){
  1641. if (!this.tweenScrollQueue){
  1642. this.tweenScrollQueue = [];
  1643. }
  1644. if (this.tweenScrollQueue.length){
  1645. this.tweenScrollQueue.push(to);
  1646. }else{
  1647. this.tweenScrollQueue.push(to);
  1648. this.doTweenScrollQueue(time);
  1649. }
  1650. },
  1651. "doTweenScrollQueue": function(time){
  1652. if (this.tweenScrollQueue.length){
  1653. var i = this.tweenScrollQueue.length;
  1654. var to = this.tweenScrollQueue[this.tweenScrollQueue.length-1];
  1655. var scroll = this.getScroll();
  1656. var dy = to - scroll.y;
  1657. var step = dy/time;
  1658. var count = 0;
  1659. var move = 0;
  1660. var id = window.setInterval(function(){
  1661. this.scrollTo(0, scroll.y+count*step);
  1662. count++;
  1663. if (count>time){
  1664. window.clearInterval(id);
  1665. for (var x=1; x<=i; x++) this.tweenScrollQueue.shift();
  1666. if (this.tweenScrollQueue.length) this.doTweenScrollQueue(time);
  1667. }
  1668. }.bind(this), 1);
  1669. }
  1670. },
  1671. "isPointIn": function(px, py, offX, offY, el){
  1672. if (!offX) offX = 0;
  1673. if (!offY) offY = 0;
  1674. var position = this.getPosition(el);
  1675. var size = this.getSize();
  1676. return (position.x-offX<=px && position.x+size.x+offX>=px && position.y-offY<=py && position.y+size.y+offY>=py);
  1677. },
  1678. "isInPointInRect": function(sx, sy, ex, ey){
  1679. var position = this.getPosition();
  1680. var size = this.getSize();
  1681. var p1 = {"x": position.x, "y": position.y};
  1682. var p2 = {"x": position.x+size.x, "y": position.y};
  1683. var p3 = {"x": position.x+size.x, "y": position.y+size.y};
  1684. var p4 = {"x": position.x, "y": position.y+size.y};
  1685. var sp = {"x": Math.min(sx, ex), "y": Math.min(sy, ey)};
  1686. var ep = {"x": Math.max(sx, ex), "y": Math.max(sy, ey)};
  1687. if (p1.x>=sp.x && p1.y>=sp.y && p1.x<=ep.x && p1.y<=ep.y) return true;
  1688. if (p2.x>=sp.x && p2.y>=sp.y && p2.x<=ep.x && p2.y<=ep.y) return true;
  1689. if (p3.x>=sp.x && p3.y>=sp.y && p3.x<=ep.x && p3.y<=ep.y) return true;
  1690. if (p4.x>=sp.x && p4.y>=sp.y && p4.x<=ep.x && p4.y<=ep.y) return true;
  1691. if (p3.x>=sp.x && p3.y>=sp.y && p1.x<=sp.x && p1.y<=sp.y) return true;
  1692. if (p3.x>=ep.x && p3.y>=ep.y && p1.x<=ep.x && p1.y<=ep.y) return true;
  1693. if (p1.x<=sp.x && p2.x>=sp.x && p1.y>=sp.y && p4.y<=ep.y) return true;
  1694. if (p1.y<=sp.y && p4.y>=sp.y && p1.x>=sp.x && p2.x<=ep.x) return true;
  1695. return false;
  1696. },
  1697. "isOverlap": function(node){
  1698. var p = node.getPosition();
  1699. var s = node.getSize();
  1700. return this.isInPointInRect(p.x, p.y, p.x+s.x, p.y+s.y);
  1701. },
  1702. "getUsefulSize": function(){
  1703. var size = this.getSize();
  1704. var borderLeft = this.getStyle("border-left").toInt();
  1705. var borderBottom = this.getStyle("border-bottom").toInt();
  1706. var borderTop = this.getStyle("border-top").toInt();
  1707. var borderRight = this.getStyle("border-right").toInt();
  1708. var paddingLeft = this.getStyle("padding-left").toInt();
  1709. var paddingBottom = this.getStyle("padding-bottom").toInt();
  1710. var paddingTop = this.getStyle("padding-top").toInt();
  1711. var paddingRight = this.getStyle("padding-right").toInt();
  1712. var x = size.x-paddingLeft-paddingRight;
  1713. var y = size.y-paddingTop-paddingBottom;
  1714. return {"x": x, "y": y};
  1715. },
  1716. "clearStyles": function(isChild){
  1717. this.removeProperty("style");
  1718. if (isChild){
  1719. var subNode = this.getFirst();
  1720. while (subNode){
  1721. subNode.clearStyles(isChild);
  1722. subNode = subNode.getNext();
  1723. }
  1724. }
  1725. },
  1726. "maskIf": function(styles, click){
  1727. var style = {
  1728. "background-color": "#666666",
  1729. "opacity": 0.4,
  1730. "z-index":100
  1731. };
  1732. if (styles){
  1733. style = Object.merge(style, styles);
  1734. }
  1735. var position = this.getPosition(this.getOffsetParent());
  1736. this.mask({
  1737. "destroyOnHide": true,
  1738. "style": style,
  1739. "useIframeShim": true,
  1740. "iframeShimOptions": {"browsers": true},
  1741. "onShow": function(){
  1742. this.shim.shim.setStyles({
  1743. "opacity": 0,
  1744. "top": ""+position.y+"px",
  1745. "left": ""+position.x+"px"
  1746. });
  1747. },
  1748. "onClick": click
  1749. });
  1750. },
  1751. "scrollIn": function(where){
  1752. var wh = (where) ? where.toString().toLowerCase() : "center";
  1753. if (Browser.name=="ie" || Browser.name=="safari"){
  1754. var scrollNode = this.getParentSrcollNode();
  1755. var scrollFx = new Fx.Scroll(scrollNode);
  1756. var scroll = scrollNode.getScroll();
  1757. var size = scrollNode.getSize();
  1758. var thisSize = this.getComputedSize();
  1759. var p = this.getPosition(scrollNode);
  1760. if (wh=="start"){
  1761. var top = 0;
  1762. scrollFx.start(scroll.x, p.y-top+scroll.y);
  1763. }else if (wh=="end"){
  1764. var bottom = size.y-thisSize.totalHeight;
  1765. scrollFx.start(scroll.x, p.y-bottom+scroll.y);
  1766. }else{
  1767. var center = size.y/2-thisSize.totalHeight/2;
  1768. scrollFx.start(scroll.x, p.y-center+scroll.y);
  1769. }
  1770. }else{
  1771. if (wh!=="start" && wh!=="end") wh = "center"
  1772. this.scrollIntoView({"behavior": "smooth", "block": wh, "inline": "nearest"});
  1773. }
  1774. },
  1775. scrollToNode: function(el, where){
  1776. var scrollSize = this.getScrollSize();
  1777. if (!scrollSize.y) return true;
  1778. var wh = (where) ? where.toString().toLowerCase() : "bottom";
  1779. var node = $(el);
  1780. var size = node.getComputedSize();
  1781. var p = node.getPosition(this);
  1782. var thisSize = this.getComputedSize();
  1783. var scroll = this.getScroll();
  1784. if (wh==="top"){
  1785. var n = (p.y-thisSize.computedTop);
  1786. if (n<0) this.scrollTo(scroll.x, scroll.y+n);
  1787. n = (size.totalHeight+p.y-thisSize.computedTop)-thisSize.height;
  1788. if (n>0) this.scrollTo(scroll.x, scroll.y+n);
  1789. }else{
  1790. var n = (size.totalHeight+p.y-thisSize.computedTop)-thisSize.height;
  1791. if (n>0) this.scrollTo(scroll.x, scroll.y+n);
  1792. n = p.y-thisSize.computedTop;
  1793. if (n<0) this.scrollTo(scroll.x, scroll.y+n);
  1794. }
  1795. },
  1796. "getInnerStyles": function(){
  1797. var styles = {};
  1798. style = this.get("style");
  1799. if (style){
  1800. var styleArr = style.split(/\s*\;\s*/g);
  1801. styleArr.each(function(s){
  1802. if (s){
  1803. var sarr = s.split(/\s*\:\s*/g);
  1804. styles[sarr[0]] = (sarr.length>1) ? sarr[1]: ""
  1805. }
  1806. }.bind(this));
  1807. }
  1808. return styles;
  1809. },
  1810. "getInnerProperties": function(){
  1811. var properties = {};
  1812. if (this.attributes.length){
  1813. for (var i=0; i<this.attributes.length; i++){
  1814. properties[this.attributes[i].nodeName] = this.attributes[i].nodeValue;
  1815. }
  1816. }
  1817. return properties;
  1818. },
  1819. "getZIndex": function(){
  1820. var n = this;
  1821. var i=0;
  1822. while (n){
  1823. if (n.getStyle("position")==="absolute"){
  1824. var idx = n.getStyle("z-index");
  1825. i = (idx && idx.toFloat()>i) ? idx.toFloat()+1 : 0;
  1826. break;
  1827. }
  1828. n = n.getParent();
  1829. }
  1830. return i;
  1831. },
  1832. "getParentSrcollNode": function(){
  1833. var node = this.getParent();
  1834. while (node && (node.getScrollSize().y-2<=node.getSize().y || (node.getStyle("overflow")!=="auto" && node.getStyle("overflow-y")!=="auto"))){
  1835. node = node.getParent();
  1836. }
  1837. return node || null;
  1838. },
  1839. "getEdgeHeight": function(notMargin){
  1840. var h = 0;
  1841. h += (this.getStyle("border-top-width").toFloat() || 0)+ (this.getStyle("border-bottom-width").toFloat() || 0);
  1842. h += (this.getStyle("padding-top").toFloat() || 0)+ (this.getStyle("padding-bottom").toFloat() || 0);
  1843. if (!notMargin) h += (this.getStyle("margin-top").toFloat() || 0)+ (this.getStyle("margin-bottom").toFloat() || 0);
  1844. return h;
  1845. },
  1846. "getEdgeWidth": function(notMargin){
  1847. var h = 0;
  1848. h += (this.getStyle("border-left-width").toFloat() || 0)+ (this.getStyle("border-right-width").toFloat() || 0);
  1849. h += (this.getStyle("padding-left").toFloat() || 0)+ (this.getStyle("padding-right").toFloat() || 0);
  1850. if (!notMargin) h += (this.getStyle("margin-left").toFloat() || 0)+ (this.getStyle("margin-right").toFloat() || 0);
  1851. return h;
  1852. }
  1853. });
  1854. Object.copy = function(from, to){
  1855. Object.each(from, function(value, key){
  1856. switch (typeOf(value)){
  1857. case "object":
  1858. if (!to[key]) to[key]={};
  1859. Object.copy(value, to[key]);
  1860. break;
  1861. default:
  1862. to[key] = value;
  1863. }
  1864. });
  1865. };
  1866. if (window.JSON) JSON.format = JSON.encode;
  1867. if (window.Slick) {
  1868. Slick.definePseudo('src', function (value) {
  1869. return Element.get(this, "src").indexOf(value) !== -1;
  1870. });
  1871. Slick.definePseudo('srcarr', function (value) {
  1872. var vList = value.split(",");
  1873. var src = Element.get(this, "src");
  1874. var flag = false;
  1875. for (var i = 0; i < vList.length; i++) {
  1876. if (src.indexOf(vList[i]) !== -1) {
  1877. flag = true;
  1878. break;
  1879. }
  1880. }
  1881. return flag;
  1882. });
  1883. Slick.definePseudo('ahref', function (value) {
  1884. var href = Element.get(this, "href");
  1885. if (!href) href = "";
  1886. href = href.toString().toLowerCase();
  1887. return (href.indexOf(value) !== -1);
  1888. });
  1889. Slick.definePseudo('rowspanBefore', function (line) {
  1890. var tr = MWF.getParent(this, "tr");
  1891. var rowspan = this.get("rowspan").toInt() || 1;
  1892. var currentRowIndex = tr.rowIndex.toInt();
  1893. return rowspan > 1 && currentRowIndex < line.toInt() && currentRowIndex + rowspan - 1 >= line;
  1894. });
  1895. Slick.definePseudo('rowspan', function () {
  1896. var rowspan = this.get("rowspan").toInt() || 1;
  1897. return rowspan > 1;
  1898. });
  1899. Slick.definePseudo('colspanBefore', function (col) {
  1900. var tr = MWF.getParent(this, "tr");
  1901. var colspan = this.get("colspan").toInt() || 1;
  1902. var currentColIndex = this.cellIndex.toInt();
  1903. return colspan > 1 && currentColIndex < col.toInt() && currentColIndex + colspan - 1 >= col.toInt();
  1904. });
  1905. Slick.definePseudo('colspan', function () {
  1906. var colspan = this.get("colspan").toInt() || 1;
  1907. return colspan > 1;
  1908. });
  1909. }
  1910. o2.common = o2.common || {};
  1911. o2.common.encodeHtml = function(str){
  1912. str = str.toString();
  1913. str = str.replace(/\&/g, "&amp;");
  1914. str = str.replace(/>/g, "&gt;");
  1915. str = str.replace(/</g, "&lt;");
  1916. return str.replace(/\"/g, "&quot;");
  1917. };
  1918. o2.common.getResponseTextPost = function(path, body, contentType){
  1919. var returnText = "";
  1920. var options = {
  1921. url: path,
  1922. async: false,
  1923. data: body,
  1924. method: "post",
  1925. onSuccess: function(esponseTree, responseElements, responseHTML, responseJavaScript){
  1926. returnText = responseHTML;
  1927. }
  1928. };
  1929. var r = new Request.HTML(options);
  1930. r.send();
  1931. return returnText;
  1932. };
  1933. o2.common.getResponseText = function(path){
  1934. var returnText = "";
  1935. var options = {
  1936. url: path,
  1937. async: false,
  1938. method: "get",
  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.toDate = function(str){
  1948. var tmpArr = str.split(" ");
  1949. if (!tmpArr[1]) tmpArr.push("0:0:0");
  1950. var dateArr = tmpArr[0].split("-");
  1951. var timeArr = tmpArr[1].split(":");
  1952. return new Date(dateArr[0],parseInt(dateArr[1])-1,dateArr[2],timeArr[0],timeArr[1],timeArr[2]);
  1953. };
  1954. o2.common.toDate = function(str){
  1955. var tmpArr = str.split(" ");
  1956. if (!tmpArr[1]) tmpArr.push("0:0:0");
  1957. var dateArr = tmpArr[0].split("-");
  1958. var timeArr = tmpArr[1].split(":");
  1959. return new Date(dateArr[0],parseInt(dateArr[1])-1,dateArr[2],timeArr[0],timeArr[1],timeArr[2]);
  1960. };
  1961. o2.grayscale = function(src, width, height, callback){
  1962. try {
  1963. var canvas = document.createElement('canvas');
  1964. var ctx = canvas.getContext('2d');
  1965. var imgObj = new Image();
  1966. imgObj.src = src;
  1967. canvas.width = width || imgObj.width;
  1968. canvas.height = height || imgObj.height;
  1969. ctx.drawImage(imgObj, 0, 0);
  1970. var imgPixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
  1971. for(var y = 0; y < imgPixels.height; y++){
  1972. for(var x = 0; x < imgPixels.width; x++){
  1973. var i = (y * 4) * imgPixels.width + x * 4;
  1974. var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
  1975. imgPixels.data[i] = avg;
  1976. imgPixels.data[i + 1] = avg;
  1977. imgPixels.data[i + 2] = avg;
  1978. }
  1979. }
  1980. ctx.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
  1981. var src1 = canvas.toDataURL();
  1982. //var blob = canvas.toBlob();
  1983. canvas.destroy();
  1984. return {"status": "success", "src": src1};
  1985. }catch(e){
  1986. return {"status": "error", "src": src}
  1987. }
  1988. };
  1989. o2.eventPosition = function(e){
  1990. var x = 0;
  1991. var y = 0;
  1992. if (Browser.name=="firefox"){
  1993. x = parseFloat(e.event.clientX || e.event.x);
  1994. y = parseFloat(e.event.clientY || e.event.y);
  1995. }else{
  1996. x = parseFloat(e.event.x);
  1997. y = parseFloat(e.event.y);
  1998. }
  1999. return {"x": x, "y": y};
  2000. };
  2001. if (window.Browser){
  2002. if (Browser.name==="ie" && Browser.version<9){
  2003. Browser.ieuns = true;
  2004. }else if(Browser.name==="ie" && Browser.version<10){
  2005. Browser.iecomp = true;
  2006. }
  2007. if (Browser.iecomp){
  2008. o2.load("ie_adapter", null, false);
  2009. o2.session.isDebugger = true;
  2010. //layout["debugger"] = true;
  2011. }
  2012. o2.session.isMobile = (["mac", "win", "linux"].indexOf(Browser.Platform.name)===-1);
  2013. }
  2014. })();
  2015. o2.more = true;
  2016. //o2.addReady
  2017. (function(){
  2018. //dom ready
  2019. var _dom = {
  2020. ready: false,
  2021. loaded: false,
  2022. checks: [],
  2023. shouldPoll: false,
  2024. timer: null,
  2025. testElement: document.createElement('div'),
  2026. readys: [],
  2027. domready: function(){
  2028. clearTimeout(_dom.timer);
  2029. if (_dom.ready) return;
  2030. _dom.loaded = _dom.ready = true;
  2031. o2.removeListener(document, 'DOMContentLoaded', _dom.checkReady);
  2032. o2.removeListener(document, 'readystatechange', _dom.check);
  2033. _dom.onReady();
  2034. },
  2035. check: function(){
  2036. for (var i = _dom.checks.length; i--;) if (_dom.checks[i]() && window.MooTools && o2.core && o2.more){
  2037. _dom.domready();
  2038. return true;
  2039. }
  2040. return false;
  2041. },
  2042. poll: function(){
  2043. clearTimeout(_dom.timer);
  2044. if (!_dom.check()) _dom.timer = setTimeout(_dom.poll, 10);
  2045. },
  2046. /*<ltIE8>*/
  2047. // doScroll technique by Diego Perini http://javascript.nwbox.com/IEContentLoaded/
  2048. // testElement.doScroll() throws when the DOM is not ready, only in the top window
  2049. doScrollWorks: function(){
  2050. try {
  2051. _dom.testElement.doScroll();
  2052. return true;
  2053. } catch (e){}
  2054. return false;
  2055. },
  2056. /*</ltIE8>*/
  2057. onReady: function(){
  2058. for (var i=0; i<_dom.readys.length; i++){
  2059. this.readys[i].apply(window);
  2060. }
  2061. },
  2062. addReady: function(fn){
  2063. if (_dom.loaded){
  2064. if (fn) fn.apply(window);
  2065. }else{
  2066. if (fn) _dom.readys.push(fn);
  2067. }
  2068. return _dom;
  2069. },
  2070. checkReady: function(){
  2071. _dom.checks.push(function(){return true});
  2072. _dom.check();
  2073. }
  2074. };
  2075. var _loadO2 = function(){
  2076. (!o2.core) ? this.o2.load("o2.core", _dom.check) : _dom.check();
  2077. (!o2.more) ? this.o2.load("o2.more", _dom.check) : _dom.check();
  2078. };
  2079. o2.addListener(document, 'DOMContentLoaded', _dom.checkReady);
  2080. /*<ltIE8>*/
  2081. // If doScroll works already, it can't be used to determine domready
  2082. // e.g. in an iframe
  2083. if (_dom.testElement.doScroll && !_dom.doScrollWorks()){
  2084. _dom.checks.push(_dom.doScrollWorks);
  2085. _dom.shouldPoll = true;
  2086. }
  2087. /*</ltIE8>*/
  2088. if (document.readyState) _dom.checks.push(function(){
  2089. var state = document.readyState;
  2090. return (state == 'loaded' || state == 'complete');
  2091. });
  2092. if ('onreadystatechange' in document) o2.addListener(document, 'readystatechange', _dom.check);
  2093. else _dom.shouldPoll = true;
  2094. if (_dom.shouldPoll) _dom.poll();
  2095. if (!window.MooTools){
  2096. this.o2.load("mootools", function(){ _loadO2(); _dom.check(); });
  2097. }else{
  2098. _loadO2();
  2099. }
  2100. this.o2.addReady = function(fn){ _dom.addReady.call(_dom, fn); };
  2101. })();
  2102. //compatible
  2103. COMMON = {
  2104. "DOM":{},
  2105. "setContentPath": function(path){
  2106. COMMON.contentPath = path;
  2107. },
  2108. "JSON": o2.JSON,
  2109. "Browser": Browser,
  2110. "Class": o2.Class,
  2111. "XML": o2.xml,
  2112. "AjaxModule": {
  2113. "load": function(urls, callback, async, reload){
  2114. o2.load(urls, callback, reload, document);
  2115. },
  2116. "loadDom": function(urls, callback, async, reload){
  2117. o2.load(urls, callback, reload, document);
  2118. },
  2119. "loadCss": function(urls, callback, async, reload, sourceDoc){
  2120. o2.loadCss(urls, document.body, callback, reload, sourceDoc);
  2121. }
  2122. },
  2123. "Request": Request,
  2124. "typeOf": o2.typeOf
  2125. };
  2126. COMMON.Browser.Platform.isMobile = o2.session.isMobile;
  2127. COMMON.DOM.addReady = o2.addReady;
  2128. MWF = o2;
  2129. MWF.getJSON = o2.JSON.get;
  2130. MWF.getJSONP = o2.JSON.getJsonp;
  2131. MWF.defaultPath = o2.session.path;