o2.js 104 KB

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