o2.js 100 KB

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