o2.js 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660
  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.isAG) ? 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 = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  1530. //var cb = function(json){
  1531. d = Date.parse(json.data.serverTime);
  1532. return d;
  1533. }.ag().catch(function(json){ return d; });
  1534. o2.Actions.get("x_program_center").echo(cb, null, !!async);
  1535. return (!!async) ? cb : d;
  1536. // if (callback){
  1537. // o2.Actions.get("x_program_center").echo(function(json){
  1538. // d = Date.parse(json.data.serverTime);
  1539. // o2.runCallback(callback, "success", [d]);
  1540. // });
  1541. // }else{
  1542. // var d;
  1543. // o2.Actions.get("x_program_center").echo(function(json){
  1544. // d = Date.parse(json.data.serverTime);
  1545. // }, null, false);
  1546. // return d;
  1547. // }
  1548. };
  1549. Object.appendChain = function(oChain, oProto) {
  1550. if (arguments.length < 2) {
  1551. throw new TypeError('Object.appendChain - Not enough arguments');
  1552. }
  1553. if (typeof oProto === 'number' || typeof oProto === 'boolean') {
  1554. throw new TypeError('second argument to Object.appendChain must be an object or a string');
  1555. }
  1556. var oNewProto = oProto,
  1557. oReturn,
  1558. o2nd,
  1559. oLast;
  1560. oReturn = o2nd = oLast = oChain instanceof this ? oChain : new oChain.constructor(oChain);
  1561. for (var o1st = this.getPrototypeOf(o2nd);
  1562. o1st !== Object.prototype && o1st !== Function.prototype;
  1563. o1st = this.getPrototypeOf(o2nd)
  1564. ) {
  1565. o2nd = o1st;
  1566. }
  1567. if (oProto.constructor === String) {
  1568. oNewProto = Function.prototype;
  1569. oReturn = Function.apply(null, Array.prototype.slice.call(arguments, 1));
  1570. oReturn = oReturn.bind(oLast);
  1571. this.setPrototypeOf(oReturn, oLast);
  1572. }
  1573. this.setPrototypeOf(o2nd, oNewProto);
  1574. return oReturn;
  1575. }
  1576. var _AsyncGeneratorPrototype = _Class.create({
  1577. initialize: function(resolve, reject, name){
  1578. debugger;
  1579. this.isAG = true;
  1580. this.name = name || "";
  1581. this._createSuccess();
  1582. this._createFailure();
  1583. if (resolve) this.success.resolve = resolve;
  1584. if (reject) this.failure.reject = reject;
  1585. },
  1586. //$family: function(){ return "o2_async_function"; },
  1587. _createSuccess: function(){
  1588. var _self = this;
  1589. this.success = function(){
  1590. var result;
  1591. if (_self.success.resolve) result = _self.success.resolve.apply(this, arguments);
  1592. if (_self.success.resolveList){
  1593. _self.success.resolveList.each(function(r){
  1594. result = r(result, arguments) || result;
  1595. });
  1596. }
  1597. _self.isSuccess = true;
  1598. _self.result = result;
  1599. _self.arg = arguments;
  1600. return result;
  1601. }
  1602. },
  1603. _createFailure: function(){
  1604. var _self = this;
  1605. this.failure = function(){
  1606. var result;
  1607. if (_self.failure.reject) result = _self.failure.reject(arguments);
  1608. if (_self.failure.rejectList){
  1609. _self.failure.rejectList.each(function(r){
  1610. result = r(result, arguments) || result;
  1611. });
  1612. }
  1613. _self.isFailure = true;
  1614. _self.result = result;
  1615. _self.arg = arguments;
  1616. return result;
  1617. }
  1618. },
  1619. setResolve: function(resolve){
  1620. if (!this.success) this._createSuccess();
  1621. this.success.resolve = resolve;
  1622. return this;
  1623. },
  1624. setReject: function(reject){
  1625. if (!this.failure) this._createFailure();
  1626. this.failure.reject = reject;
  1627. return this;
  1628. },
  1629. addResolve: function(resolve){
  1630. if (!this.success) this._createSuccess();
  1631. if (resolve){
  1632. if (this.isSuccess){
  1633. this.result = resolve(this.result, this.arg);
  1634. }else{
  1635. if (!this.success.resolve){
  1636. this.success.resolve = resolve;
  1637. }else{
  1638. if (!this.success.resolveList) this.success.resolveList = [];
  1639. this.success.resolveList.push(resolve);
  1640. }
  1641. }
  1642. }
  1643. return this;
  1644. },
  1645. addReject: function(reject){
  1646. if (!this.failure) this._createFailure();
  1647. if (reject){
  1648. if (this.isFailure){
  1649. this.result = reject(this.result, this.arg);
  1650. }else{
  1651. if (!this.failure.reject){
  1652. this.failure.reject = reject;
  1653. }else{
  1654. if (!this.failure.rejectList) this.failure.rejectList = [];
  1655. this.failure.rejectList.push(reject);
  1656. }
  1657. }
  1658. }
  1659. return this;
  1660. },
  1661. then: function(resolve){
  1662. return this.addResolve(resolve);
  1663. },
  1664. "catch": function(reject){
  1665. return this.addReject(reject);
  1666. },
  1667. });
  1668. var _AsyncGenerator = function(resolve, reject, name){
  1669. var asyncGeneratorPrototype = new _AsyncGeneratorPrototype(resolve, reject, name);
  1670. return Object.appendChain(asyncGeneratorPrototype, "if (this.success) this.success.apply(this, arguments);");
  1671. }
  1672. //@todo
  1673. _AsyncGenerator.all = function(arr){
  1674. var result = [];
  1675. var ag = function (){
  1676. return result;
  1677. }.ag();
  1678. if (o2.typeOf(arr) !== "array") arr = [arr];
  1679. var count = arr.length;
  1680. var check = function(){
  1681. count--;
  1682. if (count<=0)ag();
  1683. }
  1684. //window.setTimeout(function(){
  1685. arr.forEach(function(a){
  1686. if (typeOf(a)=="array"){
  1687. o2.AG.all(a).then(function(v){
  1688. result = result.concat(v);
  1689. check();
  1690. });
  1691. }else{
  1692. if (a && a.isAG){
  1693. a.then(function(v){
  1694. o2.AG.all(v).then(function(r){
  1695. result = result.concat(r);
  1696. check();
  1697. });
  1698. });
  1699. }else{
  1700. result.push(a);
  1701. check();
  1702. }
  1703. }
  1704. });
  1705. //}, 0);
  1706. return ag;
  1707. }
  1708. o2.AsyncGenerator = o2.AG = _AsyncGenerator;
  1709. Function.prototype.ag = function(){
  1710. return o2.AG(this);
  1711. }
  1712. })();
  1713. o2.core = true;
  1714. /** ***** BEGIN LICENSE BLOCK *****
  1715. * |------------------------------------------------------------------------------|
  1716. * | O2OA 活力办公 创意无限 o2.more.js |
  1717. * |------------------------------------------------------------------------------|
  1718. * | Distributed under the AGPL license: |
  1719. * |------------------------------------------------------------------------------|
  1720. * | Copyright © 2018, o2oa.net, o2server.io O2 Team |
  1721. * | All rights reserved. |
  1722. * |------------------------------------------------------------------------------|
  1723. *
  1724. * This file is part of O2OA.
  1725. *
  1726. * O2OA is free software: you can redistribute it and/or modify
  1727. * it under the terms of the GNU Affero General Public License as published by
  1728. * the Free Software Foundation, either version 3 of the License, or
  1729. * (at your option) any later version.
  1730. *
  1731. * O2OA is distributed in the hope that it will be useful,
  1732. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1733. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1734. * GNU Affero General Public License for more details.
  1735. *
  1736. * You should have received a copy of the GNU General Public License
  1737. * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
  1738. *
  1739. * ***** END LICENSE BLOCK ******/
  1740. (function (){
  1741. o2.getCenterPosition = function(el, width, height){
  1742. var elPositon = $(el).getPosition();
  1743. var elSize = $(el).getSize();
  1744. var node = $("layout");
  1745. var size = (node) ? $(node).getSize() : $(document.body).getSize();
  1746. var top = (elPositon.y+elSize.y)/2 - (height/2);
  1747. var left = (elPositon.x+elSize.x)/2-(width/2);
  1748. if ((left+width)>size.x){
  1749. left = size.x-width-10;
  1750. }
  1751. if ((top+height)>size.y){
  1752. top = size.y-height-10;
  1753. }
  1754. return {"x": left, "y": top};
  1755. };
  1756. o2.getMarkSize = function(node){
  1757. var size;
  1758. if (!node){
  1759. size = $(document.body).getSize();
  1760. var winSize = $(window).getSize();
  1761. var height = size.y;
  1762. var width = size.x;
  1763. if (height<winSize.y) height = winSize.y;
  1764. if (width<winSize.x) width = winSize.x;
  1765. return {x: size.x, y: height};
  1766. }else{
  1767. size = $(node).getSize();
  1768. return {x: size.x, y: size.y};
  1769. }
  1770. };
  1771. o2.json = function(jsonString, fun){
  1772. var obj = JSON.decode(jsonString);
  1773. var p = fun.split(".");
  1774. var tmp = obj;
  1775. p.each(function(item){
  1776. if (item.indexOf("[")!==-1){
  1777. var x = item.split("[");
  1778. var i = parseInt(x[1].substr(0, x[1].indexOf("]")));
  1779. tmp = tmp[x[0]][i];
  1780. }else{
  1781. tmp = tmp[item];
  1782. }
  1783. });
  1784. return tmp;
  1785. };
  1786. o2.getHTMLTemplate = function(url, callback, async){
  1787. var loadAsync = (async !== false);
  1788. var res = new Request.HTML({
  1789. url: url,
  1790. async: loadAsync,
  1791. method: "get",
  1792. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  1793. o2.runCallback(callback, "success", [responseTree, responseElements, responseHTML, responseJavaScript]);
  1794. }.bind(this),
  1795. onFailure: function(xhr){
  1796. o2.runCallback(callback, "requestFailure", [xhr]);
  1797. }
  1798. });
  1799. res.send();
  1800. };
  1801. o2.getRequestText = function(url, callback, async){
  1802. var loadAsync = (async !== false);
  1803. url = (url.indexOf("?")!==-1) ? url+"&v="+o2.version.v : url+"?v="+o2.version.v;
  1804. var res = new Request({
  1805. url: url,
  1806. async: loadAsync,
  1807. method: "get",
  1808. onSuccess: function(responseText, responseXML){
  1809. o2.runCallback(callback, "success",[responseText, responseXML]);
  1810. }.bind(this),
  1811. onFailure: function(xhr){
  1812. o2.runCallback(callback, "requestFailure",[xhr]);
  1813. }
  1814. });
  1815. res.send();
  1816. };
  1817. o2.encodeJsonString = function(str){
  1818. var tmp = [str];
  1819. var dataStr = (JSON.encode(tmp));
  1820. return dataStr.substr(2, dataStr.length-4);
  1821. };
  1822. o2.decodeJsonString = function(str){
  1823. var tmp = "[\""+str+"\"]";
  1824. var dataObj = (JSON.decode(tmp));
  1825. return dataObj[0];
  1826. };
  1827. o2.getTextSize = function(text, styles){
  1828. var tmpSpan = new Element("span", {
  1829. "text": text,
  1830. "styles": styles
  1831. }).inject($(document.body));
  1832. var size = tmpSpan.getSize();
  1833. tmpSpan.destroy();
  1834. return size;
  1835. };
  1836. o2.getCenter = function(size, target, offset){
  1837. if (!target) target = document.body;
  1838. var targetSize = target.getSize();
  1839. var targetPosition = target.getPosition(offset);
  1840. var targetScroll = target.getScroll();
  1841. var x = targetSize.x/2;
  1842. var y = targetSize.y/2;
  1843. x = x-(size.x/2);
  1844. y = y-(size.y/2);
  1845. x = x+targetPosition.x;
  1846. y = y+targetPosition.y;
  1847. x = x+targetScroll.x;
  1848. y = y+targetScroll.y;
  1849. return {"x": x, "y": y};
  1850. };
  1851. o2.getEPointer = function(e){
  1852. var x = 0;
  1853. var y = 0;
  1854. if (typeOf(e)=="element"){
  1855. var position = e.getPosition(this.content);
  1856. x = position.x;
  1857. y = position.y;
  1858. }else{
  1859. if (Browser.name=="firefox"){
  1860. x = parseFloat(e.event.clientX || e.event.x);
  1861. y = parseFloat(e.event.clientY || e.event.y);
  1862. }else{
  1863. x = parseFloat(e.event.x);
  1864. y = parseFloat(e.event.y);
  1865. }
  1866. if (e.target){
  1867. var position = e.target.getPosition(this.content);
  1868. x = position.x;
  1869. y = position.y;
  1870. }
  1871. // }
  1872. }
  1873. return {"x": x, "y": y};
  1874. };
  1875. o2.getParent = function(node, tag){
  1876. var pNode = node.parentElement;
  1877. while(pNode && pNode.tagName.toString().toLowerCase() !== tag.toString().toLowerCase()){
  1878. pNode = pNode.parentElement;
  1879. }
  1880. return pNode;
  1881. };
  1882. o2.getOffset = function(evt){
  1883. if (Browser.name==="firefox"){
  1884. return {
  1885. "offsetX": evt.layerX,
  1886. "offsetY": evt.layerY
  1887. };
  1888. }else{
  1889. return {
  1890. "offsetX": evt.offsetX,
  1891. "offsetY": evt.offsetY
  1892. }
  1893. }
  1894. };
  1895. if (String.implement) String.implement({
  1896. "getAllIndexOf": function(str){
  1897. var idxs= [];
  1898. var idx = this.indexOf(str);
  1899. while (idx !== -1){
  1900. idxs.push(idx);
  1901. idx = this.indexOf(str, idx+1);
  1902. }
  1903. return idxs;
  1904. }
  1905. });
  1906. if (Array.implement) Array.implement({
  1907. "trim": function(){
  1908. var arr = [];
  1909. this.each(function(v){
  1910. if (v) arr.push(v);
  1911. });
  1912. return arr;
  1913. },
  1914. "isIntersect": function(arr){
  1915. return this.some(function(item){ return (arr.indexOf(item)!==-1); })
  1916. }
  1917. });
  1918. if (window.Element && Element.implement) Element.implement({
  1919. "isIntoView": function() {
  1920. // var pNode = this.getParent();
  1921. // while (pNode && ((pNode.getScrollSize().y-(pNode.getComputedSize().height+1)<=0) || pNode.getStyle("overflow")==="visible")) pNode = pNode.getParent();
  1922. //
  1923. var pNode = this.getParentSrcollNode();
  1924. if (!pNode) pNode = document.body;
  1925. var size = pNode.getSize();
  1926. var srcoll = pNode.getScroll();
  1927. var p = (pNode == window) ? {"x":0, "y": 0} : this.getPosition(pNode);
  1928. var nodeSize = this.getSize();
  1929. //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);
  1930. return (p.x-srcoll.x>=0 && p.y>=0) && (p.x+nodeSize.x<size.x+srcoll.x && p.y+nodeSize.y<size.y)
  1931. },
  1932. "appendHTML": function(html, where){
  1933. if (this.insertAdjacentHTML){
  1934. var whereText = "beforeEnd";
  1935. if (where==="before") whereText = "beforeBegin";
  1936. if (where==="after") whereText = "afterEnd";
  1937. if (where==="bottom") whereText = "beforeEnd";
  1938. if (where==="top") whereText = "afterBegin";
  1939. this.insertAdjacentHTML(whereText, html);
  1940. }else {
  1941. if (where==="bottom") this.innerHTML = this.innerHTML+html;
  1942. if (where==="top") this.innerHTML = html+this.innerHTML;
  1943. }
  1944. },
  1945. "positionTo": function(x,y){
  1946. var left = x.toFloat();
  1947. var top = y.toFloat();
  1948. var offsetNode = this.getOffsetParent();
  1949. if (offsetNode){
  1950. var offsetPosition = offsetNode.getPosition();
  1951. left = left-offsetPosition.x;
  1952. top = top-offsetPosition.y;
  1953. }
  1954. this.setStyles({"top": top, "left": left});
  1955. return this;
  1956. },
  1957. "getBorder": function(){
  1958. var positions = ["top", "left", "right", "bottom"];
  1959. var styles = ["color", "style", "width"];
  1960. var obj = {};
  1961. positions.each(function (position){
  1962. styles.each(function(style){
  1963. var key = "border-"+position+"-"+style;
  1964. obj[key] = this.getStyle(key);
  1965. }.bind(this));
  1966. }.bind(this));
  1967. return obj;
  1968. },
  1969. "isOutside": function(e){
  1970. var elementCoords = this.getCoordinates();
  1971. var targetCoords = this.getCoordinates();
  1972. if(((e.page.x < elementCoords.left || e.page.x > (elementCoords.left + elementCoords.width)) ||
  1973. (e.page.y < elementCoords.top || e.page.y > (elementCoords.top + elementCoords.height))) &&
  1974. ((e.page.x < targetCoords.left || e.page.x > (targetCoords.left + targetCoords.width)) ||
  1975. (e.page.y < targetCoords.top || e.page.y > (targetCoords.top + targetCoords.height))) ) return true;
  1976. return false;
  1977. },
  1978. "getAbsolutePosition":function(){
  1979. var styleLeft = 0;
  1980. var styleTop = 0;
  1981. var node = this;
  1982. styleLeft = node.offsetLeft;
  1983. styleTop = node.offsetTop;
  1984. node = node.parentElement;
  1985. while (node && node.tagName.toString().toLowerCase()!=="body"){
  1986. styleLeft += node.offsetLeft;
  1987. styleTop += node.offsetTop;
  1988. node = node.offsetParent;
  1989. }
  1990. return {x: styleLeft, y: styleTop};
  1991. },
  1992. "tweenScroll": function(to, time){
  1993. if (!this.tweenScrollQueue){
  1994. this.tweenScrollQueue = [];
  1995. }
  1996. if (this.tweenScrollQueue.length){
  1997. this.tweenScrollQueue.push(to);
  1998. }else{
  1999. this.tweenScrollQueue.push(to);
  2000. this.doTweenScrollQueue(time);
  2001. }
  2002. },
  2003. "doTweenScrollQueue": function(time){
  2004. if (this.tweenScrollQueue.length){
  2005. var i = this.tweenScrollQueue.length;
  2006. var to = this.tweenScrollQueue[this.tweenScrollQueue.length-1];
  2007. var scroll = this.getScroll();
  2008. var dy = to - scroll.y;
  2009. var step = dy/time;
  2010. var count = 0;
  2011. var move = 0;
  2012. var id = window.setInterval(function(){
  2013. this.scrollTo(0, scroll.y+count*step);
  2014. count++;
  2015. if (count>time){
  2016. window.clearInterval(id);
  2017. for (var x=1; x<=i; x++) this.tweenScrollQueue.shift();
  2018. if (this.tweenScrollQueue.length) this.doTweenScrollQueue(time);
  2019. }
  2020. }.bind(this), 1);
  2021. }
  2022. },
  2023. "isPointIn": function(px, py, offX, offY, el){
  2024. if (!offX) offX = 0;
  2025. if (!offY) offY = 0;
  2026. var position = this.getPosition(el);
  2027. var size = this.getSize();
  2028. return (position.x-offX<=px && position.x+size.x+offX>=px && position.y-offY<=py && position.y+size.y+offY>=py);
  2029. },
  2030. "isInPointInRect": function(sx, sy, ex, ey){
  2031. var position = this.getPosition();
  2032. var size = this.getSize();
  2033. var p1 = {"x": position.x, "y": position.y};
  2034. var p2 = {"x": position.x+size.x, "y": position.y};
  2035. var p3 = {"x": position.x+size.x, "y": position.y+size.y};
  2036. var p4 = {"x": position.x, "y": position.y+size.y};
  2037. var sp = {"x": Math.min(sx, ex), "y": Math.min(sy, ey)};
  2038. var ep = {"x": Math.max(sx, ex), "y": Math.max(sy, ey)};
  2039. if (p1.x>=sp.x && p1.y>=sp.y && p1.x<=ep.x && p1.y<=ep.y) return true;
  2040. if (p2.x>=sp.x && p2.y>=sp.y && p2.x<=ep.x && p2.y<=ep.y) return true;
  2041. if (p3.x>=sp.x && p3.y>=sp.y && p3.x<=ep.x && p3.y<=ep.y) return true;
  2042. if (p4.x>=sp.x && p4.y>=sp.y && p4.x<=ep.x && p4.y<=ep.y) return true;
  2043. if (p3.x>=sp.x && p3.y>=sp.y && p1.x<=sp.x && p1.y<=sp.y) return true;
  2044. if (p3.x>=ep.x && p3.y>=ep.y && p1.x<=ep.x && p1.y<=ep.y) return true;
  2045. if (p1.x<=sp.x && p2.x>=sp.x && p1.y>=sp.y && p4.y<=ep.y) return true;
  2046. if (p1.y<=sp.y && p4.y>=sp.y && p1.x>=sp.x && p2.x<=ep.x) return true;
  2047. return false;
  2048. },
  2049. "isOverlap": function(node){
  2050. var p = node.getPosition();
  2051. var s = node.getSize();
  2052. return this.isInPointInRect(p.x, p.y, p.x+s.x, p.y+s.y);
  2053. },
  2054. "getUsefulSize": function(){
  2055. var size = this.getSize();
  2056. var borderLeft = this.getStyle("border-left").toInt();
  2057. var borderBottom = this.getStyle("border-bottom").toInt();
  2058. var borderTop = this.getStyle("border-top").toInt();
  2059. var borderRight = this.getStyle("border-right").toInt();
  2060. var paddingLeft = this.getStyle("padding-left").toInt();
  2061. var paddingBottom = this.getStyle("padding-bottom").toInt();
  2062. var paddingTop = this.getStyle("padding-top").toInt();
  2063. var paddingRight = this.getStyle("padding-right").toInt();
  2064. var x = size.x-paddingLeft-paddingRight;
  2065. var y = size.y-paddingTop-paddingBottom;
  2066. return {"x": x, "y": y};
  2067. },
  2068. "clearStyles": function(isChild){
  2069. this.removeProperty("style");
  2070. if (isChild){
  2071. var subNode = this.getFirst();
  2072. while (subNode){
  2073. subNode.clearStyles(isChild);
  2074. subNode = subNode.getNext();
  2075. }
  2076. }
  2077. },
  2078. "maskIf": function(styles, click){
  2079. var style = {
  2080. "background-color": "#666666",
  2081. "opacity": 0.4,
  2082. "z-index":100
  2083. };
  2084. if (styles){
  2085. style = Object.merge(style, styles);
  2086. }
  2087. var position = this.getPosition(this.getOffsetParent());
  2088. this.mask({
  2089. "destroyOnHide": true,
  2090. "style": style,
  2091. "useIframeShim": true,
  2092. "iframeShimOptions": {"browsers": true},
  2093. "onShow": function(){
  2094. this.shim.shim.setStyles({
  2095. "opacity": 0,
  2096. "top": ""+position.y+"px",
  2097. "left": ""+position.x+"px"
  2098. });
  2099. },
  2100. "onClick": click
  2101. });
  2102. },
  2103. "scrollIn": function(where){
  2104. var wh = (where) ? where.toString().toLowerCase() : "center";
  2105. if (Browser.name=="ie" || Browser.name=="safari"){
  2106. var scrollNode = this.getParentSrcollNode();
  2107. var scrollFx = new Fx.Scroll(scrollNode);
  2108. var scroll = scrollNode.getScroll();
  2109. var size = scrollNode.getSize();
  2110. var thisSize = this.getComputedSize();
  2111. var p = this.getPosition(scrollNode);
  2112. if (wh=="start"){
  2113. var top = 0;
  2114. scrollFx.start(scroll.x, p.y-top+scroll.y);
  2115. }else if (wh=="end"){
  2116. var bottom = size.y-thisSize.totalHeight;
  2117. scrollFx.start(scroll.x, p.y-bottom+scroll.y);
  2118. }else{
  2119. var center = size.y/2-thisSize.totalHeight/2;
  2120. scrollFx.start(scroll.x, p.y-center+scroll.y);
  2121. }
  2122. }else{
  2123. if (wh!=="start" && wh!=="end") wh = "center"
  2124. this.scrollIntoView({"behavior": "smooth", "block": wh, "inline": "nearest"});
  2125. }
  2126. },
  2127. scrollToNode: function(el, where){
  2128. var scrollSize = this.getScrollSize();
  2129. if (!scrollSize.y) return true;
  2130. var wh = (where) ? where.toString().toLowerCase() : "bottom";
  2131. var node = $(el);
  2132. var size = node.getComputedSize();
  2133. var p = node.getPosition(this);
  2134. var thisSize = this.getComputedSize();
  2135. var scroll = this.getScroll();
  2136. if (wh==="top"){
  2137. var n = (p.y-thisSize.computedTop);
  2138. if (n<0) this.scrollTo(scroll.x, scroll.y+n);
  2139. n = (size.totalHeight+p.y-thisSize.computedTop)-thisSize.height;
  2140. if (n>0) this.scrollTo(scroll.x, scroll.y+n);
  2141. }else{
  2142. var n = (size.totalHeight+p.y-thisSize.computedTop)-thisSize.height;
  2143. if (n>0) this.scrollTo(scroll.x, scroll.y+n);
  2144. n = p.y-thisSize.computedTop;
  2145. if (n<0) this.scrollTo(scroll.x, scroll.y+n);
  2146. }
  2147. },
  2148. "getInnerStyles": function(){
  2149. var styles = {};
  2150. style = this.get("style");
  2151. if (style){
  2152. var styleArr = style.split(/\s*\;\s*/g);
  2153. styleArr.each(function(s){
  2154. if (s){
  2155. var sarr = s.split(/\s*\:\s*/g);
  2156. styles[sarr[0]] = (sarr.length>1) ? sarr[1]: ""
  2157. }
  2158. }.bind(this));
  2159. }
  2160. return styles;
  2161. },
  2162. "getInnerProperties": function(){
  2163. var properties = {};
  2164. if (this.attributes.length){
  2165. for (var i=0; i<this.attributes.length; i++){
  2166. properties[this.attributes[i].nodeName] = this.attributes[i].nodeValue;
  2167. }
  2168. }
  2169. return properties;
  2170. },
  2171. "getZIndex": function(){
  2172. var n = this;
  2173. var i=0;
  2174. while (n){
  2175. if (n.getStyle("position")==="absolute"){
  2176. var idx = n.getStyle("z-index");
  2177. i = (idx && idx.toFloat()>i) ? idx.toFloat()+1 : 0;
  2178. break;
  2179. }
  2180. n = n.getParent();
  2181. }
  2182. return i;
  2183. },
  2184. "getParentSrcollNode": function(){
  2185. var node = this.getParent();
  2186. while (node && (node.getScrollSize().y-2<=node.getSize().y || (node.getStyle("overflow")!=="auto" && node.getStyle("overflow-y")!=="auto"))){
  2187. node = node.getParent();
  2188. }
  2189. return node || null;
  2190. },
  2191. "getEdgeHeight": function(notMargin){
  2192. var h = 0;
  2193. h += (this.getStyle("border-top-width").toFloat() || 0)+ (this.getStyle("border-bottom-width").toFloat() || 0);
  2194. h += (this.getStyle("padding-top").toFloat() || 0)+ (this.getStyle("padding-bottom").toFloat() || 0);
  2195. if (!notMargin) h += (this.getStyle("margin-top").toFloat() || 0)+ (this.getStyle("margin-bottom").toFloat() || 0);
  2196. return h;
  2197. },
  2198. "getEdgeWidth": function(notMargin){
  2199. var h = 0;
  2200. h += (this.getStyle("border-left-width").toFloat() || 0)+ (this.getStyle("border-right-width").toFloat() || 0);
  2201. h += (this.getStyle("padding-left").toFloat() || 0)+ (this.getStyle("padding-right").toFloat() || 0);
  2202. if (!notMargin) h += (this.getStyle("margin-left").toFloat() || 0)+ (this.getStyle("margin-right").toFloat() || 0);
  2203. return h;
  2204. }
  2205. });
  2206. Object.copy = function(from, to){
  2207. Object.each(from, function(value, key){
  2208. switch (typeOf(value)){
  2209. case "object":
  2210. if (!to[key]) to[key]={};
  2211. Object.copy(value, to[key]);
  2212. break;
  2213. default:
  2214. to[key] = value;
  2215. }
  2216. });
  2217. };
  2218. if (window.JSON) JSON.format = JSON.encode;
  2219. if (window.Slick) {
  2220. Slick.definePseudo('src', function (value) {
  2221. return Element.get(this, "src").indexOf(value) !== -1;
  2222. });
  2223. Slick.definePseudo('srcarr', function (value) {
  2224. var vList = value.split(",");
  2225. var src = Element.get(this, "src");
  2226. var flag = false;
  2227. for (var i = 0; i < vList.length; i++) {
  2228. if (src.indexOf(vList[i]) !== -1) {
  2229. flag = true;
  2230. break;
  2231. }
  2232. }
  2233. return flag;
  2234. });
  2235. Slick.definePseudo('ahref', function (value) {
  2236. var href = Element.get(this, "href");
  2237. if (!href) href = "";
  2238. href = href.toString().toLowerCase();
  2239. return (href.indexOf(value) !== -1);
  2240. });
  2241. Slick.definePseudo('rowspanBefore', function (line) {
  2242. var tr = MWF.getParent(this, "tr");
  2243. var rowspan = this.get("rowspan").toInt() || 1;
  2244. var currentRowIndex = tr.rowIndex.toInt();
  2245. return rowspan > 1 && currentRowIndex < line.toInt() && currentRowIndex + rowspan - 1 >= line;
  2246. });
  2247. Slick.definePseudo('rowspan', function () {
  2248. var rowspan = this.get("rowspan").toInt() || 1;
  2249. return rowspan > 1;
  2250. });
  2251. Slick.definePseudo('colspanBefore', function (col) {
  2252. var tr = MWF.getParent(this, "tr");
  2253. var colspan = this.get("colspan").toInt() || 1;
  2254. var currentColIndex = this.cellIndex.toInt();
  2255. return colspan > 1 && currentColIndex < col.toInt() && currentColIndex + colspan - 1 >= col.toInt();
  2256. });
  2257. Slick.definePseudo('colspan', function () {
  2258. var colspan = this.get("colspan").toInt() || 1;
  2259. return colspan > 1;
  2260. });
  2261. }
  2262. o2.common = o2.common || {};
  2263. o2.common.encodeHtml = function(str){
  2264. str = str.toString();
  2265. str = str.replace(/\&/g, "&amp;");
  2266. str = str.replace(/>/g, "&gt;");
  2267. str = str.replace(/</g, "&lt;");
  2268. return str.replace(/\"/g, "&quot;");
  2269. };
  2270. o2.common.getResponseTextPost = function(path, body, contentType){
  2271. var returnText = "";
  2272. var options = {
  2273. url: path,
  2274. async: false,
  2275. data: body,
  2276. method: "post",
  2277. onSuccess: function(esponseTree, responseElements, responseHTML, responseJavaScript){
  2278. returnText = responseHTML;
  2279. }
  2280. };
  2281. var r = new Request.HTML(options);
  2282. r.send();
  2283. return returnText;
  2284. };
  2285. o2.common.getResponseText = function(path){
  2286. var returnText = "";
  2287. var options = {
  2288. url: path,
  2289. async: false,
  2290. method: "get",
  2291. onSuccess: function(esponseTree, responseElements, responseHTML, responseJavaScript){
  2292. returnText = responseHTML;
  2293. }
  2294. };
  2295. var r = new Request.HTML(options);
  2296. r.send();
  2297. return returnText;
  2298. };
  2299. o2.common.toDate = function(str){
  2300. var tmpArr = str.split(" ");
  2301. if (!tmpArr[1]) tmpArr.push("0:0:0");
  2302. var dateArr = tmpArr[0].split("-");
  2303. var timeArr = tmpArr[1].split(":");
  2304. return new Date(dateArr[0],parseInt(dateArr[1])-1,dateArr[2],timeArr[0],timeArr[1],timeArr[2]);
  2305. };
  2306. o2.common.toDate = function(str){
  2307. var tmpArr = str.split(" ");
  2308. if (!tmpArr[1]) tmpArr.push("0:0:0");
  2309. var dateArr = tmpArr[0].split("-");
  2310. var timeArr = tmpArr[1].split(":");
  2311. return new Date(dateArr[0],parseInt(dateArr[1])-1,dateArr[2],timeArr[0],timeArr[1],timeArr[2]);
  2312. };
  2313. o2.grayscale = function(src, width, height, callback){
  2314. try {
  2315. var canvas = document.createElement('canvas');
  2316. var ctx = canvas.getContext('2d');
  2317. var imgObj = new Image();
  2318. imgObj.src = src;
  2319. canvas.width = width || imgObj.width;
  2320. canvas.height = height || imgObj.height;
  2321. ctx.drawImage(imgObj, 0, 0);
  2322. var imgPixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
  2323. for(var y = 0; y < imgPixels.height; y++){
  2324. for(var x = 0; x < imgPixels.width; x++){
  2325. var i = (y * 4) * imgPixels.width + x * 4;
  2326. var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
  2327. imgPixels.data[i] = avg;
  2328. imgPixels.data[i + 1] = avg;
  2329. imgPixels.data[i + 2] = avg;
  2330. }
  2331. }
  2332. ctx.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
  2333. var src1 = canvas.toDataURL();
  2334. //var blob = canvas.toBlob();
  2335. canvas.destroy();
  2336. return {"status": "success", "src": src1};
  2337. }catch(e){
  2338. return {"status": "error", "src": src}
  2339. }
  2340. };
  2341. o2.eventPosition = function(e){
  2342. var x = 0;
  2343. var y = 0;
  2344. if (Browser.name=="firefox"){
  2345. x = parseFloat(e.event.clientX || e.event.x);
  2346. y = parseFloat(e.event.clientY || e.event.y);
  2347. }else{
  2348. x = parseFloat(e.event.x);
  2349. y = parseFloat(e.event.y);
  2350. }
  2351. return {"x": x, "y": y};
  2352. };
  2353. if (window.Browser){
  2354. if (Browser.name==="ie" && Browser.version<9){
  2355. Browser.ieuns = true;
  2356. }else if(Browser.name==="ie" && Browser.version<10){
  2357. Browser.iecomp = true;
  2358. }
  2359. if (Browser.iecomp){
  2360. o2.load("ie_adapter", null, false);
  2361. o2.session.isDebugger = true;
  2362. //layout["debugger"] = true;
  2363. }
  2364. o2.session.isMobile = (["mac", "win", "linux"].indexOf(Browser.Platform.name)===-1);
  2365. }
  2366. })();
  2367. o2.more = true;
  2368. //o2.addReady
  2369. (function(){
  2370. //dom ready
  2371. var _dom = {
  2372. ready: false,
  2373. loaded: false,
  2374. checks: [],
  2375. shouldPoll: false,
  2376. timer: null,
  2377. testElement: document.createElement('div'),
  2378. readys: [],
  2379. domready: function(){
  2380. clearTimeout(_dom.timer);
  2381. if (_dom.ready) return;
  2382. _dom.loaded = _dom.ready = true;
  2383. o2.removeListener(document, 'DOMContentLoaded', _dom.checkReady);
  2384. o2.removeListener(document, 'readystatechange', _dom.check);
  2385. _dom.onReady();
  2386. },
  2387. check: function(){
  2388. for (var i = _dom.checks.length; i--;) if (_dom.checks[i]() && window.MooTools && o2.core && o2.more){
  2389. _dom.domready();
  2390. return true;
  2391. }
  2392. return false;
  2393. },
  2394. poll: function(){
  2395. clearTimeout(_dom.timer);
  2396. if (!_dom.check()) _dom.timer = setTimeout(_dom.poll, 10);
  2397. },
  2398. /*<ltIE8>*/
  2399. // doScroll technique by Diego Perini http://javascript.nwbox.com/IEContentLoaded/
  2400. // testElement.doScroll() throws when the DOM is not ready, only in the top window
  2401. doScrollWorks: function(){
  2402. try {
  2403. _dom.testElement.doScroll();
  2404. return true;
  2405. } catch (e){}
  2406. return false;
  2407. },
  2408. /*</ltIE8>*/
  2409. onReady: function(){
  2410. for (var i=0; i<_dom.readys.length; i++){
  2411. this.readys[i].apply(window);
  2412. }
  2413. },
  2414. addReady: function(fn){
  2415. if (_dom.loaded){
  2416. if (fn) fn.apply(window);
  2417. }else{
  2418. if (fn) _dom.readys.push(fn);
  2419. }
  2420. return _dom;
  2421. },
  2422. checkReady: function(){
  2423. _dom.checks.push(function(){return true});
  2424. _dom.check();
  2425. }
  2426. };
  2427. var _loadO2 = function(){
  2428. (!o2.core) ? this.o2.load("o2.core", _dom.check) : _dom.check();
  2429. (!o2.more) ? this.o2.load("o2.more", _dom.check) : _dom.check();
  2430. };
  2431. o2.addListener(document, 'DOMContentLoaded', _dom.checkReady);
  2432. /*<ltIE8>*/
  2433. // If doScroll works already, it can't be used to determine domready
  2434. // e.g. in an iframe
  2435. if (_dom.testElement.doScroll && !_dom.doScrollWorks()){
  2436. _dom.checks.push(_dom.doScrollWorks);
  2437. _dom.shouldPoll = true;
  2438. }
  2439. /*</ltIE8>*/
  2440. if (document.readyState) _dom.checks.push(function(){
  2441. var state = document.readyState;
  2442. return (state == 'loaded' || state == 'complete');
  2443. });
  2444. if ('onreadystatechange' in document) o2.addListener(document, 'readystatechange', _dom.check);
  2445. else _dom.shouldPoll = true;
  2446. if (_dom.shouldPoll) _dom.poll();
  2447. if (!window.MooTools){
  2448. this.o2.load("mootools", function(){ _loadO2(); _dom.check(); });
  2449. }else{
  2450. _loadO2();
  2451. }
  2452. this.o2.addReady = function(fn){ _dom.addReady.call(_dom, fn); };
  2453. })();
  2454. //compatible
  2455. COMMON = {
  2456. "DOM":{},
  2457. "setContentPath": function(path){
  2458. COMMON.contentPath = path;
  2459. },
  2460. "JSON": o2.JSON,
  2461. "Browser": Browser,
  2462. "Class": o2.Class,
  2463. "XML": o2.xml,
  2464. "AjaxModule": {
  2465. "load": function(urls, callback, async, reload){
  2466. o2.load(urls, callback, reload, document);
  2467. },
  2468. "loadDom": function(urls, callback, async, reload){
  2469. o2.load(urls, callback, reload, document);
  2470. },
  2471. "loadCss": function(urls, callback, async, reload, sourceDoc){
  2472. o2.loadCss(urls, document.body, callback, reload, sourceDoc);
  2473. }
  2474. },
  2475. "Request": Request,
  2476. "typeOf": o2.typeOf
  2477. };
  2478. COMMON.Browser.Platform.isMobile = o2.session.isMobile;
  2479. COMMON.DOM.addReady = o2.addReady;
  2480. MWF = o2;
  2481. MWF.getJSON = o2.JSON.get;
  2482. MWF.getJSONP = o2.JSON.getJsonp;
  2483. MWF.defaultPath = o2.session.path;