o2.js 86 KB

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