o2.js 86 KB

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