o2.js 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701
  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]");
  687. for (var i=0; i<els.length; i++){
  688. var el = els.item(i);
  689. var name = el.getAttribute("data-o2-element").toString();
  690. if (name) _bindToModule(op.module, el, name);
  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 eventList = events.split(/\s*;\s*/);
  709. eventList.forEach(function(ev){
  710. var evs = ev.split(/\s*:\s*/);
  711. if (evs.length>1){
  712. node.addEventListener(evs[0], function(e){
  713. if (m[evs[1]]) m[evs[1]].apply(m, [e]);
  714. }, false);
  715. }
  716. });
  717. }
  718. var _bindToModule = function(m, node, name){
  719. // if (m[name]){
  720. // if (o2.typeOf(m[name])!=="array"){
  721. // var tmp = m[name];
  722. // m[name] = [];
  723. // m[name].push(tmp);
  724. // }
  725. // m[name].push(node);
  726. // }else{
  727. m[name] = node;
  728. // }
  729. };
  730. var _loadHtml = function(modules, options, callback){
  731. var ms = (_typeOf(modules)==="array") ? modules : [modules];
  732. var op = (_typeOf(options)==="object") ? _getHtmlOptions(options) : _getHtmlOptions(null);
  733. var cb = (_typeOf(options)==="function") ? options : callback;
  734. var thisLoaded = [];
  735. if (op.sequence){
  736. _loadSequence(ms, cb, op, 0, thisLoaded, _loadSingleHtml, null, function(html){ if (html) _injectHtml(op, html.data ); });
  737. }else{
  738. _loadDisarray(ms, cb, op, thisLoaded, _loadSingleHtml, null, function(html){ if (html) _injectHtml(op, html.data ); });
  739. }
  740. };
  741. this.o2.loadHtml = _loadHtml;
  742. if (window.Element) Element.prototype.loadHtml = function(modules, options, callback){
  743. var op = (_typeOf(options)==="object") ? options : {};
  744. var cb = (_typeOf(options)==="function") ? options : callback;
  745. op.dom = this;
  746. _loadHtml(modules, op, cb);
  747. };
  748. this.o2.injectHtml = function(html, op){
  749. _injectHtml(op, html);
  750. };
  751. if (window.Element) Element.prototype.injectHtml = function(html, options){
  752. var op = (_typeOf(options)==="object") ? options : {};
  753. op.dom = this;
  754. op.position = (options && options.position) || "beforeend"
  755. _injectHtml(op, html);
  756. };
  757. //load all
  758. _loadAll = function(modules, options, callback){
  759. //var ms = (_typeOf(modules)==="array") ? modules : [modules];
  760. var op = (_typeOf(options)==="object") ? _getAllOptions(options) : _getAllOptions(null);
  761. var cb = (_typeOf(options)==="function") ? options : callback;
  762. var ms, htmls, styles, sctipts;
  763. var _htmlLoaded=(!modules.html), _cssLoaded=(!modules.css), _jsLoaded=(!modules.js);
  764. var _checkloaded = function(){
  765. if (_htmlLoaded && _cssLoaded && _jsLoaded) if (cb) cb(htmls, styles, sctipts);
  766. };
  767. if (modules.html){
  768. _loadHtml(modules.html, op, function(h){
  769. htmls = h;
  770. _htmlLoaded = true;
  771. _checkloaded();
  772. });
  773. }
  774. if (modules.css){
  775. _loadCss(modules.css, op, function(s){
  776. styles = s;
  777. _cssLoaded = true;
  778. _checkloaded();
  779. });
  780. }
  781. if (modules.js){
  782. _load(modules.js, op, function(s){
  783. sctipts = s;
  784. _jsLoaded = true;
  785. _checkloaded();
  786. });
  787. }
  788. };
  789. this.o2.loadAll = _loadAll;
  790. if (window.Element) Element.prototype.loadAll = function(modules, options, callback){
  791. var op = (_typeOf(options)==="object") ? options : {};
  792. var cb = (_typeOf(options)==="function") ? options : callback;
  793. op.dom = this;
  794. _loadAll(modules, op, cb);
  795. };
  796. var _getIfBlockEnd = function(v){
  797. var rex = /(\{\{if\s+)|(\{\{\s*end if\s*\}\})/gmi;
  798. var rexEnd = /\{\{\s*end if\s*\}\}/gmi;
  799. var subs = 1;
  800. while ((match = rex.exec(v)) !== null) {
  801. var fullMatch = match[0];
  802. if (fullMatch.search(rexEnd)!==-1){
  803. subs--;
  804. if (subs==0) break;
  805. }else{
  806. subs++
  807. }
  808. }
  809. if (match) return {"codeIndex": match.index, "lastIndex": rex.lastIndex};
  810. return {"codeIndex": v.length-1, "lastIndex": v.length-1};
  811. }
  812. var _getEachBlockEnd = function(v){
  813. var rex = /(\{\{each\s+)|(\{\{\s*end each\s*\}\})/gmi;
  814. var rexEnd = /\{\{\s*end each\s*\}\}/gmi;
  815. var subs = 1;
  816. while ((match = rex.exec(v)) !== null) {
  817. var fullMatch = match[0];
  818. if (fullMatch.search(rexEnd)!==-1){
  819. subs--;
  820. if (subs==0) break;
  821. }else{
  822. subs++;
  823. }
  824. }
  825. if (match) return {"codeIndex": match.index, "lastIndex": rex.lastIndex};
  826. return {"codeIndex": v.length-1, "lastIndex": v.length-1};
  827. }
  828. var _parseHtml = function(str, json){
  829. var v = str;
  830. var rex = /(\{\{\s*)[\s\S]*?(\s*\}\})/gmi;
  831. var match;
  832. while ((match = rex.exec(v)) !== null) {
  833. var fullMatch = match[0];
  834. var offset = 0;
  835. //if statement begin
  836. if (fullMatch.search(/\{\{if\s+/i)!==-1){
  837. //找到对应的end if
  838. var condition = fullMatch.replace(/^\{\{if\s*/i, "");
  839. condition = condition.replace(/\s*\}\}$/i, "");
  840. var flag = _jsonText(json, condition, "boolean");
  841. var tmpStr = v.substring(rex.lastIndex, v.length);
  842. var endIfIndex = _getIfBlockEnd(tmpStr);
  843. if (flag){ //if 为 true
  844. var parseStr = _parseHtml(tmpStr.substring(0, endIfIndex.codeIndex), json);
  845. var vLeft = v.substring(0, match.index);
  846. var vRight = v.substring(rex.lastIndex+endIfIndex.lastIndex, v.length);
  847. v = vLeft + parseStr + vRight;
  848. offset = parseStr.length - fullMatch.length;
  849. }else{
  850. v = v.substring(0, match.index) + v.substring(rex.lastIndex+endIfIndex.lastIndex, v.length);
  851. offset = 0-fullMatch.length;
  852. }
  853. }else if (fullMatch.search(/\{\{each\s+/)!==-1) { //each statement
  854. var itemString = fullMatch.replace(/^\{\{each\s*/, "");
  855. itemString = itemString.replace(/\s*\}\}$/, "");
  856. var eachValue = _jsonText(json, itemString, "object");
  857. var tmpEachStr = v.substring(rex.lastIndex, v.length);
  858. var endEachIndex = _getEachBlockEnd(tmpEachStr);
  859. var parseEachStr = tmpEachStr.substring(0, endEachIndex.codeIndex);
  860. var eachResult = "";
  861. if (eachValue && _typeOf(eachValue)==="array"){
  862. for (var i=0; i<eachValue.length; i++){
  863. eachValue[i]._ = json;
  864. eachResult += _parseHtml(parseEachStr, eachValue[i]);
  865. }
  866. var eLeft = v.substring(0, match.index);
  867. var eRight = v.substring(rex.lastIndex+endEachIndex.lastIndex, v.length);
  868. v = eLeft + eachResult + eRight;
  869. offset = eachResult.length - fullMatch.length;
  870. }else{
  871. v = v.substring(0, match.index) + v.substring(rex.lastIndex+endEachIndex.lastIndex, v.length);
  872. offset = 0-fullMatch.length;
  873. }
  874. }else{ //text statement
  875. var text = fullMatch.replace(/^\{\{\s*/, "");
  876. text = text.replace(/\}\}\s*$/, "");
  877. var value = _jsonText(json, text);
  878. offset = value.length-fullMatch.length;
  879. v = v.substring(0, match.index) + value + v.substring(rex.lastIndex, v.length);
  880. }
  881. rex.lastIndex = rex.lastIndex + offset;
  882. }
  883. return v;
  884. };
  885. var _jsonText = function(json, text, type){
  886. try {
  887. var $ = json;
  888. var f = eval("(function($){\n return "+text+";\n})");
  889. returnValue = f.apply(json, [$]);
  890. if (returnValue===undefined) returnValue="";
  891. if (type==="boolean") return (!!returnValue);
  892. if (type==="object") return returnValue;
  893. returnValue = returnValue.toString();
  894. returnValue = returnValue.replace(/\&/g, "&amp;");
  895. returnValue = returnValue.replace(/>/g, "&gt;");
  896. returnValue = returnValue.replace(/</g, "&lt;");
  897. returnValue = returnValue.replace(/\"/g, "&quot;");
  898. return returnValue || "";
  899. }catch(e){
  900. if (type==="boolean") return false;
  901. if (type==="object") return null;
  902. return "";
  903. }
  904. };
  905. o2.bindJson = function(str, json){
  906. return _parseHtml(str, json);
  907. };
  908. String.prototype.bindJson = function(json){
  909. return _parseHtml(this, json);
  910. };
  911. })();
  912. /** ***** BEGIN LICENSE BLOCK *****
  913. * |------------------------------------------------------------------------------|
  914. * | O2OA 活力办公 创意无限 o2.core.js |
  915. * |------------------------------------------------------------------------------|
  916. * | Distributed under the AGPL license: |
  917. * |------------------------------------------------------------------------------|
  918. * | Copyright © 2018, o2oa.net, o2server.io O2 Team |
  919. * | All rights reserved. |
  920. * |------------------------------------------------------------------------------|
  921. *
  922. * This file is part of O2OA.
  923. *
  924. * O2OA is free software: you can redistribute it and/or modify
  925. * it under the terms of the GNU Affero General Public License as published by
  926. * the Free Software Foundation, either version 3 of the License, or
  927. * (at your option) any later version.
  928. *
  929. * O2OA is distributed in the hope that it will be useful,
  930. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  931. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  932. * GNU Affero General Public License for more details.
  933. *
  934. * You should have received a copy of the GNU General Public License
  935. * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
  936. *
  937. * ***** END LICENSE BLOCK ******/
  938. (function (){
  939. var _Class = {
  940. create: function(options) {
  941. // var newClass = function() {
  942. // this.initialize.apply(this, arguments);
  943. // };
  944. return _copyPrototype(function() {
  945. return this.initialize.apply(this, arguments) || this;
  946. }, options);
  947. //return newClass;
  948. }
  949. };
  950. var _copyPrototype = function (currentNS, props){
  951. if (!props){return currentNS;}
  952. if (!currentNS){return currentNS;}
  953. if ((typeof currentNS).toLowerCase()==="object"){
  954. for (var prop in props){
  955. currentNS[prop] = props[prop];
  956. }
  957. }
  958. if ((typeof currentNS).toLowerCase()==="function"){
  959. for (var propfun in props){
  960. currentNS.prototype[propfun] = props[propfun];
  961. }
  962. }
  963. return currentNS;
  964. };
  965. var _loaded = {};
  966. var _requireJs = function(url, callback, async, compression, module){
  967. var key = encodeURIComponent(url);
  968. if (_loaded[key]){o2.runCallback(callback, "success", [module]); return "";}
  969. var jsPath = (compression || !this.o2.session.isDebugger) ? url.replace(/\.js/, ".min.js") : url;
  970. jsPath = (jsPath.indexOf("?")!==-1) ? jsPath+"&v="+this.o2.version.v : jsPath+"?v="+this.o2.version.v;
  971. var xhr = new Request({
  972. url: o2.filterUrl(jsPath), async: async, method: "get",
  973. onSuccess: function(){
  974. //try{
  975. _loaded[key] = true;
  976. o2.runCallback(callback, "success", [module]);
  977. //}catch (e){
  978. // o2.runCallback(callback, "failure", [e]);
  979. //}
  980. },
  981. onFailure: function(r){
  982. var rex = /lp\/.+\.js/;
  983. if (rex.test(url)){
  984. var zhcnUrl = url.replace(rex, "lp/zh-cn.js");
  985. if (zhcnUrl!==url){
  986. _requireJs(zhcnUrl, callback, async, compression, module)
  987. }else{
  988. o2.runCallback(callback, "failure", [r]);
  989. }
  990. }else{
  991. o2.runCallback(callback, "failure", [r]);
  992. }
  993. }
  994. });
  995. xhr.send();
  996. };
  997. var _requireSingle = function(module, callback, async, compression){
  998. if (o2.typeOf(module)==="array"){
  999. _requireAppSingle(module, callback, async, compression);
  1000. }else{
  1001. module = module.replace("MWF.", "o2.");
  1002. var levels = module.split(".");
  1003. if (levels[levels.length-1]==="*") levels[levels.length-1] = "package";
  1004. levels.shift();
  1005. var o = o2;
  1006. var i = 0;
  1007. while (o && i<levels.length){
  1008. o = o[levels[i]];
  1009. i++
  1010. }
  1011. if (!o){
  1012. var jsPath = this.o2.session.path;
  1013. jsPath +="/"+levels.join("/")+".js";
  1014. var loadAsync = (async!==false);
  1015. _requireJs(jsPath, callback, loadAsync, compression, module);
  1016. }else{
  1017. o2.runCallback(callback, "success", [module]);
  1018. }
  1019. }
  1020. };
  1021. var _requireSequence = function(fun, module, thisLoaded, thisErrorLoaded, callback, async, compression){
  1022. var m = module.shift();
  1023. fun(m, {
  1024. "onSuccess": function(m){
  1025. thisLoaded.push(m);
  1026. o2.runCallback(callback, "every", [m]);
  1027. if (module.length){
  1028. _requireSequence(fun, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  1029. }else{
  1030. if (thisErrorLoaded.length){
  1031. o2.runCallback(callback, "failure", [thisLoaded, thisErrorLoaded]);
  1032. }else{
  1033. o2.runCallback(callback, "success", [thisLoaded, thisErrorLoaded]);
  1034. }
  1035. }
  1036. },
  1037. "onFailure": function(){
  1038. thisErrorLoaded.push(module[i]);
  1039. o2.runCallback(callback, "failure", [thisLoaded, thisErrorLoaded]);
  1040. }
  1041. }, async, compression);
  1042. };
  1043. var _requireDisarray = function(fun, module, thisLoaded, thisErrorLoaded, callback, async, compression){
  1044. for (var i=0; i<module.length; i++){
  1045. fun(module[i], {
  1046. "onSuccess": function(m){
  1047. thisLoaded.push(m);
  1048. o2.runCallback(callback, "every", [m]);
  1049. if ((thisLoaded.length+thisErrorLoaded.length)===module.length){
  1050. if (thisErrorLoaded.length){
  1051. o2.runCallback(callback, "failure", [thisLoaded, thisErrorLoaded]);
  1052. }else{
  1053. o2.runCallback(callback, "success", [thisLoaded, thisErrorLoaded]);
  1054. }
  1055. }
  1056. },
  1057. "onFailure": function(){
  1058. thisErrorLoaded.push(module[i]);
  1059. o2.runCallback(callback, "failure", [thisLoaded, thisErrorLoaded]);
  1060. }
  1061. }, async, compression);
  1062. }
  1063. };
  1064. var _require = function(module, callback, async, sequence, compression){
  1065. var type = typeOf(module);
  1066. if (type==="array"){
  1067. var sql = !!sequence;
  1068. var thisLoaded = [];
  1069. var thisErrorLoaded = [];
  1070. if (sql){
  1071. _requireSequence(_requireSingle, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  1072. }else{
  1073. _requireDisarray(_requireSingle, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  1074. }
  1075. }
  1076. if (type==="string"){
  1077. _requireSingle(module, callback, async, compression);
  1078. }
  1079. };
  1080. var _requireAppSingle = function(modules, callback, async, compression){
  1081. var module = modules[0];
  1082. var clazz = modules[1];
  1083. var levels = module.split(".");
  1084. var o = o2.xApplication;
  1085. var i = 0;
  1086. while (o && i<levels.length){
  1087. o = o[levels[i]];
  1088. i++
  1089. }
  1090. if (o) o = o[clazz || "Main"];
  1091. if (!o){
  1092. //levels.shift();
  1093. var root = "x_component_"+levels.join("_");
  1094. var clazzName = clazz || "Main";
  1095. var path = "../"+root+"/"+clazzName.replace(/\./g, "/")+".js";
  1096. var loadAsync = (async!==false);
  1097. _requireJs(path, callback, loadAsync, compression);
  1098. }else{
  1099. o2.runCallback(callback, "success");
  1100. }
  1101. };
  1102. var _requireApp = function(module, clazz, callback, async, sequence, compression){
  1103. var type = typeOf(module);
  1104. if (type==="array"){
  1105. var sql = !!sequence;
  1106. var thisLoaded = [];
  1107. var thisErrorLoaded = [];
  1108. if (sql){
  1109. _requireSequence(_requireAppSingle, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  1110. }else{
  1111. _requireDisarray(_requireAppSingle, module, thisLoaded, thisErrorLoaded, callback, async, compression);
  1112. }
  1113. }
  1114. if (type==="string"){
  1115. var modules = [module, clazz];
  1116. _requireAppSingle(modules, callback, async, compression);
  1117. }
  1118. };
  1119. JSON = window.JSON || {};
  1120. var _json = JSON;
  1121. _json.get = function(url, callback, async, nocache){
  1122. var loadAsync = (async !== false);
  1123. var noJsonCache = (nocache === true);
  1124. url = (url.indexOf("?")!==-1) ? url+"&v="+o2.version.v : url+"?v="+o2.version.v;
  1125. var json = null;
  1126. var res = new Request.JSON({
  1127. url: o2.filterUrl(url),
  1128. secure: false,
  1129. method: "get",
  1130. noCache: noJsonCache,
  1131. async: loadAsync,
  1132. withCredentials: true,
  1133. onSuccess: function(responseJSON, responseText){
  1134. json = responseJSON;
  1135. if (typeOf(callback).toLowerCase() === 'function'){
  1136. callback(responseJSON, responseText);
  1137. }else{
  1138. o2.runCallback(callback, "success", [responseJSON, responseText]);
  1139. }
  1140. }.bind(this),
  1141. onFailure: function(xhr){
  1142. o2.runCallback(callback, "requestFailure", [xhr]);
  1143. }.bind(this),
  1144. onError: function(text, error){
  1145. o2.runCallback(callback, "error", [text, error]);
  1146. }.bind(this)
  1147. });
  1148. res.send();
  1149. return json;
  1150. };
  1151. _json.getJsonp = function(url, callback, async, callbackKey){
  1152. var loadAsync = (async !== false);
  1153. var callbackKeyWord = callbackKey || "callback";
  1154. url = (url.indexOf("?")!==-1) ? url+"&v="+o2.version.v : url+"?v="+o2.version.v;
  1155. var res = new Request.JSONP({
  1156. url: o2.filterUrl(url),
  1157. secure: false,
  1158. method: "get",
  1159. noCache: true,
  1160. async: loadAsync,
  1161. callbackKey: callbackKeyWord,
  1162. onSuccess: function(responseJSON, responseText){
  1163. o2.runCallback(callback, "success",[responseJSON, responseText]);
  1164. }.bind(this),
  1165. onFailure: function(xhr){
  1166. o2.runCallback(callback, "requestFailure",[xhr]);
  1167. }.bind(this),
  1168. onError: function(text, error){
  1169. o2.runCallback(callback, "error",[text, error]);
  1170. }.bind(this)
  1171. });
  1172. res.send();
  1173. };
  1174. var _loadLP = function(name){
  1175. var jsPath = o2.session.path;
  1176. jsPath = jsPath+"/lp/"+name+".js";
  1177. var r = new Request({
  1178. url: o2.filterUrl(jsPath),
  1179. async: false,
  1180. method: "get",
  1181. onSuccess: function(responseText){
  1182. try{
  1183. Browser.exec(responseText);
  1184. }catch (e){}
  1185. },
  1186. onFailure: function(xhr){
  1187. if (name!="zh-cn"){
  1188. _loadLP("zh-cn");
  1189. }else{
  1190. throw "loadLP Error: "+xhr.responseText;
  1191. }
  1192. }
  1193. });
  1194. r.send();
  1195. };
  1196. var _cacheUrls = [
  1197. /jaxrs\/form\/workorworkcompleted\/.+/ig,
  1198. /jaxrs\/form\/.+/ig,
  1199. // /jaxrs\/script/ig,
  1200. /jaxrs\/script\/.+\/app\/.+\/imported/ig,
  1201. /jaxrs\/script\/portal\/.+\/name\/.+\/imported/ig,
  1202. /jaxrs\/script\/.+\/application\/.+\/imported/ig,
  1203. /jaxrs\/page\/.+\/portal\/.+/ig,
  1204. /jaxrs\/document\/.+/ig,
  1205. /jaxrs\/applicationdict\/.+/ig,
  1206. /jaxrs\/custom\/.+/ig,
  1207. /jaxrs\/definition\/idea.+/ig,
  1208. /jaxrs\/distribute\/assemble\/source\/.+/ig,
  1209. ///jaxrs\/form\/workorworkcompleted\/.+/ig,
  1210. // /jaxrs\/script/ig,
  1211. // /jaxrs\/script\/.+\/app\/.+\/imported/ig,
  1212. // /jaxrs\/script\/portal\/.+\/name\/.+\/imported/ig,
  1213. // /jaxrs\/script\/.+\/application\/.+\/imported/ig,
  1214. // /jaxrs\/page\/.+\/portal\/.+/ig
  1215. // /jaxrs\/authentication/ig
  1216. // /jaxrs\/statement\/.*\/execute\/page\/.*\/size\/.*/ig
  1217. ];
  1218. // _restful_bak = function(method, address, data, callback, async, withCredentials, cache){
  1219. // var loadAsync = (async !== false);
  1220. // var credentials = (withCredentials !== false);
  1221. // address = (address.indexOf("?")!==-1) ? address+"&v="+o2.version.v : address+"?v="+o2.version.v;
  1222. // //var noCache = cache===false;
  1223. // var noCache = !cache;
  1224. //
  1225. //
  1226. // //if (Browser.name == "ie")
  1227. // if (_cacheUrls.length){
  1228. // for (var i=0; i<_cacheUrls.length; i++){
  1229. // _cacheUrls[i].lastIndex = 0;
  1230. // if (_cacheUrls[i].test(address)){
  1231. // noCache = false;
  1232. // break;
  1233. // }
  1234. // }
  1235. // }
  1236. // //var noCache = false;
  1237. // var res = new Request.JSON({
  1238. // url: o2.filterUrl(address),
  1239. // secure: false,
  1240. // method: method,
  1241. // emulation: false,
  1242. // noCache: noCache,
  1243. // async: loadAsync,
  1244. // withCredentials: credentials,
  1245. // onSuccess: function(responseJSON, responseText){
  1246. // // var xToken = this.getHeader("authorization");
  1247. // // if (!xToken) xToken = this.getHeader("x-token");
  1248. // var xToken = this.getHeader("x-token");
  1249. // if (xToken){
  1250. // if (window.layout){
  1251. // if (!layout.session) layout.session = {};
  1252. // layout.session.token = xToken;
  1253. // }
  1254. // }
  1255. // o2.runCallback(callback, "success", [responseJSON]);
  1256. // },
  1257. // onFailure: function(xhr){
  1258. // o2.runCallback(callback, "requestFailure", [xhr]);
  1259. // }.bind(this),
  1260. // onError: function(text, error){
  1261. // o2.runCallback(callback, "error", [text, error]);
  1262. // }.bind(this)
  1263. // });
  1264. //
  1265. // res.setHeader("Content-Type", "application/json; charset=utf-8");
  1266. // res.setHeader("Accept", "text/html,application/json,*/*");
  1267. // if (window.layout) {
  1268. // if (layout["debugger"]){
  1269. // res.setHeader("x-debugger", "true");
  1270. // }
  1271. // if (layout.session && layout.session.user){
  1272. // if (layout.session.user.token) {
  1273. // res.setHeader("x-token", layout.session.user.token);
  1274. // res.setHeader("authorization", layout.session.user.token);
  1275. // }
  1276. // }
  1277. // }
  1278. // //Content-Type application/x-www-form-urlencoded; charset=utf-8
  1279. // res.send(data);
  1280. // return res;
  1281. // };
  1282. _restful = function(method, address, data, callback, async, withCredentials, cache){
  1283. var loadAsync = (async !== false);
  1284. var credentials = (withCredentials !== false);
  1285. address = (address.indexOf("?")!==-1) ? address+"&v="+o2.version.v : address+"?v="+o2.version.v;
  1286. //var noCache = cache===false;
  1287. var noCache = !cache;
  1288. //if (Browser.name == "ie")
  1289. if (_cacheUrls.length){
  1290. for (var i=0; i<_cacheUrls.length; i++){
  1291. _cacheUrls[i].lastIndex = 0;
  1292. if (_cacheUrls[i].test(address)){
  1293. noCache = false;
  1294. break;
  1295. }
  1296. }
  1297. }
  1298. var useWebWorker = (window.layout && layout.config && layout.config.useWebWorker);
  1299. //var noCache = false;
  1300. if (!loadAsync || !useWebWorker){
  1301. debugger;
  1302. var res;
  1303. var p = new Promise(function(s,f){
  1304. res = new Request.JSON({
  1305. url: o2.filterUrl(address),
  1306. secure: false,
  1307. method: method,
  1308. emulation: false,
  1309. noCache: noCache,
  1310. async: loadAsync,
  1311. withCredentials: credentials,
  1312. onSuccess: function(responseJSON, responseText){
  1313. // var xToken = this.getHeader("authorization");
  1314. // if (!xToken) xToken = this.getHeader("x-token");
  1315. var xToken = this.getHeader("x-token");
  1316. if (xToken){
  1317. if (window.layout){
  1318. if (!layout.session) layout.session = {};
  1319. layout.session.token = xToken;
  1320. }
  1321. }
  1322. return o2.runCallback(callback, "success", [responseJSON],null, s);
  1323. },
  1324. onFailure: function(xhr){
  1325. return o2.runCallback(callback, "requestFailure", [xhr], null, f);
  1326. }.bind(this),
  1327. onError: function(text, error){
  1328. return o2.runCallback(callback, "error", [text, error], null, f);
  1329. }.bind(this)
  1330. });
  1331. res.setHeader("Content-Type", "application/json; charset=utf-8");
  1332. res.setHeader("Accept", "text/html,application/json,*/*");
  1333. if (window.layout) {
  1334. if (layout["debugger"]){
  1335. res.setHeader("x-debugger", "true");
  1336. }
  1337. if (layout.session && layout.session.user){
  1338. if (layout.session.user.token) {
  1339. res.setHeader("x-token", layout.session.user.token);
  1340. res.setHeader("authorization", layout.session.user.token);
  1341. }
  1342. }
  1343. }
  1344. //Content-Type application/x-www-form-urlencoded; charset=utf-8
  1345. res.send(data);
  1346. }.bind(this));
  1347. //var oReturn = (callback.success && callback.success.isAG) ? callback.success : callback;
  1348. var oReturn = p;
  1349. oReturn.res = res;
  1350. return oReturn;
  1351. }else{
  1352. var workerMessage = {
  1353. method: method,
  1354. noCache: noCache,
  1355. loadAsync: loadAsync,
  1356. credentials: credentials,
  1357. address: o2.filterUrl(address),
  1358. body: data,
  1359. debug: (window.layout && layout["debugger"]),
  1360. token: (window.layout && layout.session && layout.session.user) ? layout.session.user.token : ""
  1361. }
  1362. var actionWorker = new Worker("../o2_core/o2/actionWorker.js");
  1363. var p = new Promise(function(s,f){
  1364. actionWorker.onmessage = function(e) {
  1365. result = e.data;
  1366. if (result.type==="done"){
  1367. var xToken = result.data.xToken;
  1368. if (xToken){
  1369. if (window.layout){
  1370. if (!layout.session) layout.session = {};
  1371. layout.session.token = xToken;
  1372. }
  1373. }
  1374. o2.runCallback(callback, "success", [result.data], null, s);
  1375. }else{
  1376. o2.runCallback(callback, "failure", [result.data], null, f);
  1377. }
  1378. actionWorker.terminate();
  1379. }
  1380. actionWorker.postMessage(workerMessage);
  1381. }.bind(this));
  1382. //var oReturn = (callback.success && callback.success.addResolve) ? callback.success : callback;
  1383. var oReturn = p;
  1384. oReturn.actionWorker = actionWorker;
  1385. return oReturn;
  1386. //return callback;
  1387. }
  1388. //return res;
  1389. };
  1390. var _release = function(o){
  1391. var type = typeOf(o);
  1392. switch (type){
  1393. case "object":
  1394. for (var k in o){
  1395. //if (o[k] && o[k].destroy) o[k].destroy();
  1396. o[k] = null;
  1397. }
  1398. break;
  1399. case "array":
  1400. for (var i=0; i< o.length; i++){
  1401. _release(o[i]);
  1402. if (o[i]) o[i] = null;
  1403. }
  1404. break;
  1405. }
  1406. };
  1407. var _defineProperties = Object.defineProperties || function (obj, properties) {
  1408. function convertToDescriptor(desc) {
  1409. function hasProperty(obj, prop) {
  1410. return Object.prototype.hasOwnProperty.call(obj, prop);
  1411. }
  1412. function isCallable(v) {
  1413. // NB: modify as necessary if other values than functions are callable.
  1414. return typeof v === "function";
  1415. }
  1416. if (typeof desc !== "object" || desc === null)
  1417. throw new TypeError("bad desc");
  1418. var d = {};
  1419. if (hasProperty(desc, "enumerable"))
  1420. d.enumerable = !!desc.enumerable;
  1421. if (hasProperty(desc, "configurable"))
  1422. d.configurable = !!desc.configurable;
  1423. if (hasProperty(desc, "value"))
  1424. d.value = desc.value;
  1425. if (hasProperty(desc, "writable"))
  1426. d.writable = !!desc.writable;
  1427. if (hasProperty(desc, "get")) {
  1428. var g = desc.get;
  1429. if (!isCallable(g) && typeof g !== "undefined")
  1430. throw new TypeError("bad get");
  1431. d.get = g;
  1432. }
  1433. if (hasProperty(desc, "set")) {
  1434. var s = desc.set;
  1435. if (!isCallable(s) && typeof s !== "undefined")
  1436. throw new TypeError("bad set");
  1437. d.set = s;
  1438. }
  1439. if (("get" in d || "set" in d) && ("value" in d || "writable" in d))
  1440. throw new TypeError("identity-confused descriptor");
  1441. return d;
  1442. }
  1443. if (typeof obj !== "object" || obj === null)
  1444. throw new TypeError("bad obj");
  1445. properties = Object(properties);
  1446. var keys = Object.keys(properties);
  1447. var descs = [];
  1448. for (var j = 0; j < keys.length; j++)
  1449. descs.push([keys[j], convertToDescriptor(properties[keys[j]])]);
  1450. for (var i = 0; i < descs.length; i++){
  1451. if (Object.defineProperty && (Browser.name=="ie" && Browser.version!=8)){
  1452. Object.defineProperty(obj, descs[i][0], descs[i][1]);
  1453. }else{
  1454. if (descs[i][1].value) obj[descs[i][0]] = descs[i][1].value;
  1455. if (descs[i][1].get) obj["get"+descs[i][0].capitalize()] = descs[i][1].get;
  1456. if (descs[i][1].set) obj["set"+descs[i][0].capitalize()] = descs[i][1].set;
  1457. }
  1458. }
  1459. return obj;
  1460. };
  1461. if (!Array.prototype.findIndex) {
  1462. Object.defineProperty(Array.prototype, 'findIndex', {
  1463. value: function(predicate) {
  1464. if (this == null) {
  1465. throw new TypeError('"this" is null or not defined');
  1466. }
  1467. var o = Object(this);
  1468. var len = o.length >>> 0;
  1469. if (typeof predicate !== 'function') {
  1470. throw new TypeError('predicate must be a function');
  1471. }
  1472. var thisArg = arguments[1];
  1473. var k = 0;
  1474. while (k < len) {
  1475. var kValue = o[k];
  1476. if (predicate.call(thisArg, kValue, k, o)) {
  1477. return k;
  1478. }
  1479. k++;
  1480. }
  1481. return -1;
  1482. }
  1483. });
  1484. }
  1485. if (!Array.prototype.find) {
  1486. Object.defineProperty(Array.prototype, 'find', {
  1487. value: function(predicate) {
  1488. if (this == null) {
  1489. throw new TypeError('"this" is null or not defined');
  1490. }
  1491. var o = Object(this);
  1492. var len = o.length >>> 0;
  1493. if (typeof predicate !== 'function') {
  1494. throw new TypeError('predicate must be a function');
  1495. }
  1496. var thisArg = arguments[1];
  1497. var k = 0;
  1498. while (k < len) {
  1499. var kValue = o[k];
  1500. if (predicate.call(thisArg, kValue, k, o)) {
  1501. return kValue;
  1502. }
  1503. k++;
  1504. }
  1505. return undefined;
  1506. }
  1507. });
  1508. }
  1509. var _txt = function(v){
  1510. var t = v.replace(/\</g, "&lt;");
  1511. t = t.replace(/\</g, "&gt;");
  1512. return t;
  1513. };
  1514. this.o2.Class = _Class;
  1515. this.o2.require = _require;
  1516. this.o2.requireApp = _requireApp;
  1517. this.o2.JSON = _json;
  1518. this.o2.loadLP = _loadLP;
  1519. this.o2.restful = _restful;
  1520. this.o2.release = _release;
  1521. this.o2.defineProperties = _defineProperties;
  1522. this.o2.txt = _txt;
  1523. Object.repeatArray = function(o, count){
  1524. var arr = [];
  1525. for (var i=0; i<count; i++){
  1526. arr.push(o)
  1527. }
  1528. return arr;
  1529. }
  1530. // Date.implement({
  1531. // "getFromServer": function(callback){
  1532. // if (callback){
  1533. // o2.Actions.get("x_program_center").echo(function(json){
  1534. // d = Date.parse(json.data.serverTime);
  1535. // callback(d);
  1536. // });
  1537. // }else{
  1538. // var d;
  1539. // o2.Actions.get("x_program_center").echo(function(json){
  1540. // d = Date.parse(json.data.serverTime);
  1541. // }, null, false);
  1542. // return d;
  1543. // }
  1544. // }
  1545. // });
  1546. Date.getFromServer = function(async){
  1547. var d;
  1548. var cb = ((async && o2.typeOf(async)=="function") ? async : null) || function(json){
  1549. //var cb = function(json){
  1550. d = Date.parse(json.data.serverTime);
  1551. return d;
  1552. };
  1553. var promise = o2.Actions.get("x_program_center").echo(cb, null, !!async);
  1554. return (!!async) ? promise : d;
  1555. // if (callback){
  1556. // o2.Actions.get("x_program_center").echo(function(json){
  1557. // d = Date.parse(json.data.serverTime);
  1558. // o2.runCallback(callback, "success", [d]);
  1559. // });
  1560. // }else{
  1561. // var d;
  1562. // o2.Actions.get("x_program_center").echo(function(json){
  1563. // d = Date.parse(json.data.serverTime);
  1564. // }, null, false);
  1565. // return d;
  1566. // }
  1567. };
  1568. // Object.appendChain = function(oChain, oProto) {
  1569. // if (arguments.length < 2) {
  1570. // throw new TypeError('Object.appendChain - Not enough arguments');
  1571. // }
  1572. // if (typeof oProto === 'number' || typeof oProto === 'boolean') {
  1573. // throw new TypeError('second argument to Object.appendChain must be an object or a string');
  1574. // }
  1575. //
  1576. // var oNewProto = oProto,
  1577. // oReturn,
  1578. // o2nd,
  1579. // oLast;
  1580. //
  1581. // oReturn = o2nd = oLast = oChain instanceof this ? oChain : new oChain.constructor(oChain);
  1582. //
  1583. // for (var o1st = this.getPrototypeOf(o2nd);
  1584. // o1st !== Object.prototype && o1st !== Function.prototype;
  1585. // o1st = this.getPrototypeOf(o2nd)
  1586. // ) {
  1587. // o2nd = o1st;
  1588. // }
  1589. //
  1590. // if (oProto.constructor === String) {
  1591. // oNewProto = Function.prototype;
  1592. // oReturn = Function.apply(null, Array.prototype.slice.call(arguments, 1));
  1593. // oReturn = oReturn.bind(oLast);
  1594. // this.setPrototypeOf(oReturn, oLast);
  1595. // }
  1596. //
  1597. // this.setPrototypeOf(o2nd, oNewProto);
  1598. // return oReturn;
  1599. // }
  1600. // user promise
  1601. // var _AsyncGeneratorPrototype = _Class.create({
  1602. // initialize: function(resolve, reject, name){
  1603. // this.isAG = true;
  1604. // this.name = name || "";
  1605. // this._createSuccess();
  1606. // this._createFailure();
  1607. // if (resolve) this.success.resolve = resolve;
  1608. // if (reject) this.failure.reject = reject;
  1609. // },
  1610. // //$family: function(){ return "o2_async_function"; },
  1611. // _createSuccess: function(){
  1612. // var _self = this;
  1613. // this.success = function(){
  1614. // var result;
  1615. // if (_self.success.resolve) result = _self.success.resolve.apply(this, arguments);
  1616. // if (_self.success.resolveList){
  1617. // _self.success.resolveList.each(function(r){
  1618. // result = r(result, arguments) || result;
  1619. // });
  1620. // }
  1621. // _self.isSuccess = true;
  1622. // _self.result = result;
  1623. // _self.arg = arguments;
  1624. // return result;
  1625. // }
  1626. // },
  1627. // _createFailure: function(){
  1628. // var _self = this;
  1629. // this.failure = function(){
  1630. // var result;
  1631. // if (_self.failure.reject) result = _self.failure.reject.apply(this, arguments);
  1632. // if (_self.failure.rejectList){
  1633. // _self.failure.rejectList.each(function(r){
  1634. // result = r(result, arguments) || result;
  1635. // });
  1636. // }
  1637. // _self.isFailure = true;
  1638. // _self.result = result;
  1639. // _self.arg = arguments;
  1640. // return result;
  1641. // }
  1642. // },
  1643. // setResolve: function(resolve){
  1644. // if (!this.success) this._createSuccess();
  1645. // this.success.resolve = resolve;
  1646. // return this;
  1647. // },
  1648. // setReject: function(reject){
  1649. // if (!this.failure) this._createFailure();
  1650. // this.failure.reject = reject;
  1651. // return this;
  1652. // },
  1653. // addResolve: function(resolve){
  1654. // if (!this.success) this._createSuccess();
  1655. // if (resolve){
  1656. // if (this.isSuccess){
  1657. // this.result = resolve(this.result, this.arg);
  1658. // }else{
  1659. // if (!this.success.resolve){
  1660. // this.success.resolve = resolve;
  1661. // }else{
  1662. // if (!this.success.resolveList) this.success.resolveList = [];
  1663. // this.success.resolveList.push(resolve);
  1664. // }
  1665. // }
  1666. // }
  1667. // return this;
  1668. // },
  1669. // addReject: function(reject){
  1670. // if (!this.failure) this._createFailure();
  1671. // if (reject){
  1672. // if (this.isFailure){
  1673. // this.result = reject(this.result, this.arg);
  1674. // }else{
  1675. // if (!this.failure.reject){
  1676. // this.failure.reject = reject;
  1677. // }else{
  1678. // if (!this.failure.rejectList) this.failure.rejectList = [];
  1679. // this.failure.rejectList.push(reject);
  1680. // }
  1681. // }
  1682. // }
  1683. // return this;
  1684. // },
  1685. // then: function(resolve){
  1686. // return this.addResolve(resolve);
  1687. // },
  1688. // "catch": function(reject){
  1689. // return this.addReject(reject);
  1690. // },
  1691. // });
  1692. // var _AsyncGenerator = function(resolve, reject, name){
  1693. // var asyncGeneratorPrototype = new _AsyncGeneratorPrototype(resolve, reject, name);
  1694. // return Object.appendChain(asyncGeneratorPrototype, "if (this.success) this.success.apply(this, arguments);");
  1695. // }
  1696. //
  1697. // //@todo
  1698. // _AsyncGenerator.all = function(arr){
  1699. // var result = [];
  1700. // var ag = function (){
  1701. // return result;
  1702. // }.ag();
  1703. //
  1704. // if (o2.typeOf(arr) !== "array") arr = [arr];
  1705. //
  1706. // var count = arr.length;
  1707. // var check = function(){
  1708. // count--;
  1709. // if (count<=0)ag();
  1710. // }
  1711. //
  1712. // //window.setTimeout(function(){
  1713. // arr.forEach(function(a){
  1714. // if (typeOf(a)=="array"){
  1715. // o2.AG.all(a).then(function(v){
  1716. // result = result.concat(v);
  1717. // check();
  1718. // });
  1719. // }else{
  1720. // if (a && a.isAG){
  1721. // a.then(function(v){
  1722. // o2.AG.all(v).then(function(r){
  1723. // result = result.concat(r);
  1724. // check();
  1725. // });
  1726. // });
  1727. // }else{
  1728. // result.push(a);
  1729. // check();
  1730. // }
  1731. // }
  1732. // });
  1733. // //}, 0);
  1734. // return ag;
  1735. // }
  1736. //
  1737. // o2.AsyncGenerator = o2.AG = _AsyncGenerator;
  1738. //
  1739. // Function.prototype.ag = function(){
  1740. // return o2.AG(this);
  1741. // };
  1742. var _promiseAll = function(p){
  1743. if (o2.typeOf(p)=="array"){
  1744. if (p.some(function(e){ return (o2.typeOf(e.then)=="function") })){
  1745. return Promise.all(p);
  1746. }else{
  1747. return { "then": function(s){ s(p); return this;} };
  1748. }
  1749. }else{
  1750. if (o2.typeOf(p.then)=="function"){
  1751. return Promise.resolve(p);
  1752. }else{
  1753. return { "then": function(s){ s(p); return this;} };
  1754. }
  1755. }
  1756. // var method = (o2.typeOf(p)=="array") ? "all" : "resolve";
  1757. // return Promise[method](p);
  1758. }
  1759. o2.promiseAll = _promiseAll;
  1760. })();
  1761. o2.core = true;
  1762. /** ***** BEGIN LICENSE BLOCK *****
  1763. * |------------------------------------------------------------------------------|
  1764. * | O2OA 活力办公 创意无限 o2.more.js |
  1765. * |------------------------------------------------------------------------------|
  1766. * | Distributed under the AGPL license: |
  1767. * |------------------------------------------------------------------------------|
  1768. * | Copyright © 2018, o2oa.net, o2server.io O2 Team |
  1769. * | All rights reserved. |
  1770. * |------------------------------------------------------------------------------|
  1771. *
  1772. * This file is part of O2OA.
  1773. *
  1774. * O2OA is free software: you can redistribute it and/or modify
  1775. * it under the terms of the GNU Affero General Public License as published by
  1776. * the Free Software Foundation, either version 3 of the License, or
  1777. * (at your option) any later version.
  1778. *
  1779. * O2OA is distributed in the hope that it will be useful,
  1780. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1781. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1782. * GNU Affero General Public License for more details.
  1783. *
  1784. * You should have received a copy of the GNU General Public License
  1785. * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
  1786. *
  1787. * ***** END LICENSE BLOCK ******/
  1788. (function (){
  1789. o2.getCenterPosition = function(el, width, height){
  1790. var elPositon = $(el).getPosition();
  1791. var elSize = $(el).getSize();
  1792. var node = $("layout");
  1793. var size = (node) ? $(node).getSize() : $(document.body).getSize();
  1794. var top = (elPositon.y+elSize.y)/2 - (height/2);
  1795. var left = (elPositon.x+elSize.x)/2-(width/2);
  1796. if ((left+width)>size.x){
  1797. left = size.x-width-10;
  1798. }
  1799. if ((top+height)>size.y){
  1800. top = size.y-height-10;
  1801. }
  1802. return {"x": left, "y": top};
  1803. };
  1804. o2.getMarkSize = function(node){
  1805. var size;
  1806. if (!node){
  1807. size = $(document.body).getSize();
  1808. var winSize = $(window).getSize();
  1809. var height = size.y;
  1810. var width = size.x;
  1811. if (height<winSize.y) height = winSize.y;
  1812. if (width<winSize.x) width = winSize.x;
  1813. return {x: size.x, y: height};
  1814. }else{
  1815. size = $(node).getSize();
  1816. return {x: size.x, y: size.y};
  1817. }
  1818. };
  1819. o2.json = function(jsonString, fun){
  1820. var obj = JSON.decode(jsonString);
  1821. var p = fun.split(".");
  1822. var tmp = obj;
  1823. p.each(function(item){
  1824. if (item.indexOf("[")!==-1){
  1825. var x = item.split("[");
  1826. var i = parseInt(x[1].substr(0, x[1].indexOf("]")));
  1827. tmp = tmp[x[0]][i];
  1828. }else{
  1829. tmp = tmp[item];
  1830. }
  1831. });
  1832. return tmp;
  1833. };
  1834. o2.getHTMLTemplate = function(url, callback, async){
  1835. var loadAsync = (async !== false);
  1836. var res = new Request.HTML({
  1837. url: url,
  1838. async: loadAsync,
  1839. method: "get",
  1840. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  1841. o2.runCallback(callback, "success", [responseTree, responseElements, responseHTML, responseJavaScript]);
  1842. }.bind(this),
  1843. onFailure: function(xhr){
  1844. o2.runCallback(callback, "requestFailure", [xhr]);
  1845. }
  1846. });
  1847. res.send();
  1848. };
  1849. o2.getRequestText = function(url, callback, async){
  1850. var loadAsync = (async !== false);
  1851. url = (url.indexOf("?")!==-1) ? url+"&v="+o2.version.v : url+"?v="+o2.version.v;
  1852. var res = new Request({
  1853. url: url,
  1854. async: loadAsync,
  1855. method: "get",
  1856. onSuccess: function(responseText, responseXML){
  1857. o2.runCallback(callback, "success",[responseText, responseXML]);
  1858. }.bind(this),
  1859. onFailure: function(xhr){
  1860. o2.runCallback(callback, "requestFailure",[xhr]);
  1861. }
  1862. });
  1863. res.send();
  1864. };
  1865. o2.encodeJsonString = function(str){
  1866. var tmp = [str];
  1867. var dataStr = (JSON.encode(tmp));
  1868. return dataStr.substr(2, dataStr.length-4);
  1869. };
  1870. o2.decodeJsonString = function(str){
  1871. var tmp = "[\""+str+"\"]";
  1872. var dataObj = (JSON.decode(tmp));
  1873. return dataObj[0];
  1874. };
  1875. o2.getTextSize = function(text, styles){
  1876. var tmpSpan = new Element("span", {
  1877. "text": text,
  1878. "styles": styles
  1879. }).inject($(document.body));
  1880. var size = tmpSpan.getSize();
  1881. tmpSpan.destroy();
  1882. return size;
  1883. };
  1884. o2.getCenter = function(size, target, offset){
  1885. if (!target) target = document.body;
  1886. var targetSize = target.getSize();
  1887. var targetPosition = target.getPosition(offset);
  1888. var targetScroll = target.getScroll();
  1889. var x = targetSize.x/2;
  1890. var y = targetSize.y/2;
  1891. x = x-(size.x/2);
  1892. y = y-(size.y/2);
  1893. x = x+targetPosition.x;
  1894. y = y+targetPosition.y;
  1895. x = x+targetScroll.x;
  1896. y = y+targetScroll.y;
  1897. return {"x": x, "y": y};
  1898. };
  1899. o2.getEPointer = function(e){
  1900. var x = 0;
  1901. var y = 0;
  1902. if (typeOf(e)=="element"){
  1903. var position = e.getPosition(this.content);
  1904. x = position.x;
  1905. y = position.y;
  1906. }else{
  1907. if (Browser.name=="firefox"){
  1908. x = parseFloat(e.event.clientX || e.event.x);
  1909. y = parseFloat(e.event.clientY || e.event.y);
  1910. }else{
  1911. x = parseFloat(e.event.x);
  1912. y = parseFloat(e.event.y);
  1913. }
  1914. if (e.target){
  1915. var position = e.target.getPosition(this.content);
  1916. x = position.x;
  1917. y = position.y;
  1918. }
  1919. // }
  1920. }
  1921. return {"x": x, "y": y};
  1922. };
  1923. o2.getParent = function(node, tag){
  1924. var pNode = node.parentElement;
  1925. while(pNode && pNode.tagName.toString().toLowerCase() !== tag.toString().toLowerCase()){
  1926. pNode = pNode.parentElement;
  1927. }
  1928. return pNode;
  1929. };
  1930. o2.getOffset = function(evt){
  1931. if (Browser.name==="firefox"){
  1932. return {
  1933. "offsetX": evt.layerX,
  1934. "offsetY": evt.layerY
  1935. };
  1936. }else{
  1937. return {
  1938. "offsetX": evt.offsetX,
  1939. "offsetY": evt.offsetY
  1940. }
  1941. }
  1942. };
  1943. if (String.implement) String.implement({
  1944. "getAllIndexOf": function(str){
  1945. var idxs= [];
  1946. var idx = this.indexOf(str);
  1947. while (idx !== -1){
  1948. idxs.push(idx);
  1949. idx = this.indexOf(str, idx+1);
  1950. }
  1951. return idxs;
  1952. }
  1953. });
  1954. if (Array.implement) Array.implement({
  1955. "trim": function(){
  1956. var arr = [];
  1957. this.each(function(v){
  1958. if (v) arr.push(v);
  1959. });
  1960. return arr;
  1961. },
  1962. "isIntersect": function(arr){
  1963. return this.some(function(item){ return (arr.indexOf(item)!==-1); })
  1964. }
  1965. });
  1966. if (window.Element && Element.implement) Element.implement({
  1967. "isIntoView": function() {
  1968. // var pNode = this.getParent();
  1969. // while (pNode && ((pNode.getScrollSize().y-(pNode.getComputedSize().height+1)<=0) || pNode.getStyle("overflow")==="visible")) pNode = pNode.getParent();
  1970. //
  1971. var pNode = this.getParentSrcollNode();
  1972. if (!pNode) pNode = document.body;
  1973. var size = pNode.getSize();
  1974. var srcoll = pNode.getScroll();
  1975. var p = (pNode == window) ? {"x":0, "y": 0} : this.getPosition(pNode);
  1976. var nodeSize = this.getSize();
  1977. //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);
  1978. return (p.x-srcoll.x>=0 && p.y>=0) && (p.x+nodeSize.x<size.x+srcoll.x && p.y+nodeSize.y<size.y)
  1979. },
  1980. "appendHTML": function(html, where){
  1981. if (this.insertAdjacentHTML){
  1982. var whereText = "beforeEnd";
  1983. if (where==="before") whereText = "beforeBegin";
  1984. if (where==="after") whereText = "afterEnd";
  1985. if (where==="bottom") whereText = "beforeEnd";
  1986. if (where==="top") whereText = "afterBegin";
  1987. this.insertAdjacentHTML(whereText, html);
  1988. }else {
  1989. if (where==="bottom") this.innerHTML = this.innerHTML+html;
  1990. if (where==="top") this.innerHTML = html+this.innerHTML;
  1991. }
  1992. },
  1993. "positionTo": function(x,y){
  1994. var left = x.toFloat();
  1995. var top = y.toFloat();
  1996. var offsetNode = this.getOffsetParent();
  1997. if (offsetNode){
  1998. var offsetPosition = offsetNode.getPosition();
  1999. left = left-offsetPosition.x;
  2000. top = top-offsetPosition.y;
  2001. }
  2002. this.setStyles({"top": top, "left": left});
  2003. return this;
  2004. },
  2005. "getBorder": function(){
  2006. var positions = ["top", "left", "right", "bottom"];
  2007. var styles = ["color", "style", "width"];
  2008. var obj = {};
  2009. positions.each(function (position){
  2010. styles.each(function(style){
  2011. var key = "border-"+position+"-"+style;
  2012. obj[key] = this.getStyle(key);
  2013. }.bind(this));
  2014. }.bind(this));
  2015. return obj;
  2016. },
  2017. "isOutside": function(e){
  2018. var elementCoords = this.getCoordinates();
  2019. var targetCoords = this.getCoordinates();
  2020. if(((e.page.x < elementCoords.left || e.page.x > (elementCoords.left + elementCoords.width)) ||
  2021. (e.page.y < elementCoords.top || e.page.y > (elementCoords.top + elementCoords.height))) &&
  2022. ((e.page.x < targetCoords.left || e.page.x > (targetCoords.left + targetCoords.width)) ||
  2023. (e.page.y < targetCoords.top || e.page.y > (targetCoords.top + targetCoords.height))) ) return true;
  2024. return false;
  2025. },
  2026. "getAbsolutePosition":function(){
  2027. var styleLeft = 0;
  2028. var styleTop = 0;
  2029. var node = this;
  2030. styleLeft = node.offsetLeft;
  2031. styleTop = node.offsetTop;
  2032. node = node.parentElement;
  2033. while (node && node.tagName.toString().toLowerCase()!=="body"){
  2034. styleLeft += node.offsetLeft;
  2035. styleTop += node.offsetTop;
  2036. node = node.offsetParent;
  2037. }
  2038. return {x: styleLeft, y: styleTop};
  2039. },
  2040. "tweenScroll": function(to, time){
  2041. if (!this.tweenScrollQueue){
  2042. this.tweenScrollQueue = [];
  2043. }
  2044. if (this.tweenScrollQueue.length){
  2045. this.tweenScrollQueue.push(to);
  2046. }else{
  2047. this.tweenScrollQueue.push(to);
  2048. this.doTweenScrollQueue(time);
  2049. }
  2050. },
  2051. "doTweenScrollQueue": function(time){
  2052. if (this.tweenScrollQueue.length){
  2053. var i = this.tweenScrollQueue.length;
  2054. var to = this.tweenScrollQueue[this.tweenScrollQueue.length-1];
  2055. var scroll = this.getScroll();
  2056. var dy = to - scroll.y;
  2057. var step = dy/time;
  2058. var count = 0;
  2059. var move = 0;
  2060. var id = window.setInterval(function(){
  2061. this.scrollTo(0, scroll.y+count*step);
  2062. count++;
  2063. if (count>time){
  2064. window.clearInterval(id);
  2065. for (var x=1; x<=i; x++) this.tweenScrollQueue.shift();
  2066. if (this.tweenScrollQueue.length) this.doTweenScrollQueue(time);
  2067. }
  2068. }.bind(this), 1);
  2069. }
  2070. },
  2071. "isPointIn": function(px, py, offX, offY, el){
  2072. if (!offX) offX = 0;
  2073. if (!offY) offY = 0;
  2074. var position = this.getPosition(el);
  2075. var size = this.getSize();
  2076. return (position.x-offX<=px && position.x+size.x+offX>=px && position.y-offY<=py && position.y+size.y+offY>=py);
  2077. },
  2078. "isInPointInRect": function(sx, sy, ex, ey){
  2079. var position = this.getPosition();
  2080. var size = this.getSize();
  2081. var p1 = {"x": position.x, "y": position.y};
  2082. var p2 = {"x": position.x+size.x, "y": position.y};
  2083. var p3 = {"x": position.x+size.x, "y": position.y+size.y};
  2084. var p4 = {"x": position.x, "y": position.y+size.y};
  2085. var sp = {"x": Math.min(sx, ex), "y": Math.min(sy, ey)};
  2086. var ep = {"x": Math.max(sx, ex), "y": Math.max(sy, ey)};
  2087. if (p1.x>=sp.x && p1.y>=sp.y && p1.x<=ep.x && p1.y<=ep.y) return true;
  2088. if (p2.x>=sp.x && p2.y>=sp.y && p2.x<=ep.x && p2.y<=ep.y) return true;
  2089. if (p3.x>=sp.x && p3.y>=sp.y && p3.x<=ep.x && p3.y<=ep.y) return true;
  2090. if (p4.x>=sp.x && p4.y>=sp.y && p4.x<=ep.x && p4.y<=ep.y) return true;
  2091. if (p3.x>=sp.x && p3.y>=sp.y && p1.x<=sp.x && p1.y<=sp.y) return true;
  2092. if (p3.x>=ep.x && p3.y>=ep.y && p1.x<=ep.x && p1.y<=ep.y) return true;
  2093. if (p1.x<=sp.x && p2.x>=sp.x && p1.y>=sp.y && p4.y<=ep.y) return true;
  2094. if (p1.y<=sp.y && p4.y>=sp.y && p1.x>=sp.x && p2.x<=ep.x) return true;
  2095. return false;
  2096. },
  2097. "isOverlap": function(node){
  2098. var p = node.getPosition();
  2099. var s = node.getSize();
  2100. return this.isInPointInRect(p.x, p.y, p.x+s.x, p.y+s.y);
  2101. },
  2102. "getUsefulSize": function(){
  2103. var size = this.getSize();
  2104. var borderLeft = this.getStyle("border-left").toInt();
  2105. var borderBottom = this.getStyle("border-bottom").toInt();
  2106. var borderTop = this.getStyle("border-top").toInt();
  2107. var borderRight = this.getStyle("border-right").toInt();
  2108. var paddingLeft = this.getStyle("padding-left").toInt();
  2109. var paddingBottom = this.getStyle("padding-bottom").toInt();
  2110. var paddingTop = this.getStyle("padding-top").toInt();
  2111. var paddingRight = this.getStyle("padding-right").toInt();
  2112. var x = size.x-paddingLeft-paddingRight;
  2113. var y = size.y-paddingTop-paddingBottom;
  2114. return {"x": x, "y": y};
  2115. },
  2116. "clearStyles": function(isChild){
  2117. this.removeProperty("style");
  2118. if (isChild){
  2119. var subNode = this.getFirst();
  2120. while (subNode){
  2121. subNode.clearStyles(isChild);
  2122. subNode = subNode.getNext();
  2123. }
  2124. }
  2125. },
  2126. "maskIf": function(styles, click){
  2127. var style = {
  2128. "background-color": "#666666",
  2129. "opacity": 0.4,
  2130. "z-index":100
  2131. };
  2132. if (styles){
  2133. style = Object.merge(style, styles);
  2134. }
  2135. var position = this.getPosition(this.getOffsetParent());
  2136. this.mask({
  2137. "destroyOnHide": true,
  2138. "style": style,
  2139. "useIframeShim": true,
  2140. "iframeShimOptions": {"browsers": true},
  2141. "onShow": function(){
  2142. this.shim.shim.setStyles({
  2143. "opacity": 0,
  2144. "top": ""+position.y+"px",
  2145. "left": ""+position.x+"px"
  2146. });
  2147. },
  2148. "onClick": click
  2149. });
  2150. },
  2151. "scrollIn": function(where){
  2152. var wh = (where) ? where.toString().toLowerCase() : "center";
  2153. if (Browser.name=="ie" || Browser.name=="safari"){
  2154. var scrollNode = this.getParentSrcollNode();
  2155. var scrollFx = new Fx.Scroll(scrollNode);
  2156. var scroll = scrollNode.getScroll();
  2157. var size = scrollNode.getSize();
  2158. var thisSize = this.getComputedSize();
  2159. var p = this.getPosition(scrollNode);
  2160. if (wh=="start"){
  2161. var top = 0;
  2162. scrollFx.start(scroll.x, p.y-top+scroll.y);
  2163. }else if (wh=="end"){
  2164. var bottom = size.y-thisSize.totalHeight;
  2165. scrollFx.start(scroll.x, p.y-bottom+scroll.y);
  2166. }else{
  2167. var center = size.y/2-thisSize.totalHeight/2;
  2168. scrollFx.start(scroll.x, p.y-center+scroll.y);
  2169. }
  2170. }else{
  2171. if (wh!=="start" && wh!=="end") wh = "center"
  2172. this.scrollIntoView({"behavior": "smooth", "block": wh, "inline": "nearest"});
  2173. }
  2174. },
  2175. scrollToNode: function(el, where){
  2176. var scrollSize = this.getScrollSize();
  2177. if (!scrollSize.y) return true;
  2178. var wh = (where) ? where.toString().toLowerCase() : "bottom";
  2179. var node = $(el);
  2180. var size = node.getComputedSize();
  2181. var p = node.getPosition(this);
  2182. var thisSize = this.getComputedSize();
  2183. var scroll = this.getScroll();
  2184. if (wh==="top"){
  2185. var n = (p.y-thisSize.computedTop);
  2186. if (n<0) this.scrollTo(scroll.x, scroll.y+n);
  2187. n = (size.totalHeight+p.y-thisSize.computedTop)-thisSize.height;
  2188. if (n>0) this.scrollTo(scroll.x, scroll.y+n);
  2189. }else{
  2190. var n = (size.totalHeight+p.y-thisSize.computedTop)-thisSize.height;
  2191. if (n>0) this.scrollTo(scroll.x, scroll.y+n);
  2192. n = p.y-thisSize.computedTop;
  2193. if (n<0) this.scrollTo(scroll.x, scroll.y+n);
  2194. }
  2195. },
  2196. "getInnerStyles": function(){
  2197. var styles = {};
  2198. style = this.get("style");
  2199. if (style){
  2200. var styleArr = style.split(/\s*\;\s*/g);
  2201. styleArr.each(function(s){
  2202. if (s){
  2203. var sarr = s.split(/\s*\:\s*/g);
  2204. styles[sarr[0]] = (sarr.length>1) ? sarr[1]: ""
  2205. }
  2206. }.bind(this));
  2207. }
  2208. return styles;
  2209. },
  2210. "getInnerProperties": function(){
  2211. var properties = {};
  2212. if (this.attributes.length){
  2213. for (var i=0; i<this.attributes.length; i++){
  2214. properties[this.attributes[i].nodeName] = this.attributes[i].nodeValue;
  2215. }
  2216. }
  2217. return properties;
  2218. },
  2219. "getZIndex": function(){
  2220. var n = this;
  2221. var i=0;
  2222. while (n){
  2223. if (n.getStyle("position")==="absolute"){
  2224. var idx = n.getStyle("z-index");
  2225. i = (idx && idx.toFloat()>i) ? idx.toFloat()+1 : 0;
  2226. break;
  2227. }
  2228. n = n.getParent();
  2229. }
  2230. return i;
  2231. },
  2232. "getParentSrcollNode": function(){
  2233. var node = this.getParent();
  2234. while (node && (node.getScrollSize().y-2<=node.getSize().y || (node.getStyle("overflow")!=="auto" && node.getStyle("overflow-y")!=="auto"))){
  2235. node = node.getParent();
  2236. }
  2237. return node || null;
  2238. },
  2239. "getEdgeHeight": function(notMargin){
  2240. var h = 0;
  2241. h += (this.getStyle("border-top-width").toFloat() || 0)+ (this.getStyle("border-bottom-width").toFloat() || 0);
  2242. h += (this.getStyle("padding-top").toFloat() || 0)+ (this.getStyle("padding-bottom").toFloat() || 0);
  2243. if (!notMargin) h += (this.getStyle("margin-top").toFloat() || 0)+ (this.getStyle("margin-bottom").toFloat() || 0);
  2244. return h;
  2245. },
  2246. "getEdgeWidth": function(notMargin){
  2247. var h = 0;
  2248. h += (this.getStyle("border-left-width").toFloat() || 0)+ (this.getStyle("border-right-width").toFloat() || 0);
  2249. h += (this.getStyle("padding-left").toFloat() || 0)+ (this.getStyle("padding-right").toFloat() || 0);
  2250. if (!notMargin) h += (this.getStyle("margin-left").toFloat() || 0)+ (this.getStyle("margin-right").toFloat() || 0);
  2251. return h;
  2252. }
  2253. });
  2254. Object.copy = function(from, to){
  2255. Object.each(from, function(value, key){
  2256. switch (typeOf(value)){
  2257. case "object":
  2258. if (!to[key]) to[key]={};
  2259. Object.copy(value, to[key]);
  2260. break;
  2261. default:
  2262. to[key] = value;
  2263. }
  2264. });
  2265. };
  2266. if (window.JSON) JSON.format = JSON.encode;
  2267. if (window.Slick) {
  2268. Slick.definePseudo('src', function (value) {
  2269. return Element.get(this, "src").indexOf(value) !== -1;
  2270. });
  2271. Slick.definePseudo('srcarr', function (value) {
  2272. var vList = value.split(",");
  2273. var src = Element.get(this, "src");
  2274. var flag = false;
  2275. for (var i = 0; i < vList.length; i++) {
  2276. if (src.indexOf(vList[i]) !== -1) {
  2277. flag = true;
  2278. break;
  2279. }
  2280. }
  2281. return flag;
  2282. });
  2283. Slick.definePseudo('ahref', function (value) {
  2284. var href = Element.get(this, "href");
  2285. if (!href) href = "";
  2286. href = href.toString().toLowerCase();
  2287. return (href.indexOf(value) !== -1);
  2288. });
  2289. Slick.definePseudo('rowspanBefore', function (line) {
  2290. var tr = MWF.getParent(this, "tr");
  2291. var rowspan = this.get("rowspan").toInt() || 1;
  2292. var currentRowIndex = tr.rowIndex.toInt();
  2293. return rowspan > 1 && currentRowIndex < line.toInt() && currentRowIndex + rowspan - 1 >= line;
  2294. });
  2295. Slick.definePseudo('rowspan', function () {
  2296. var rowspan = this.get("rowspan").toInt() || 1;
  2297. return rowspan > 1;
  2298. });
  2299. Slick.definePseudo('colspanBefore', function (col) {
  2300. var tr = MWF.getParent(this, "tr");
  2301. var colspan = this.get("colspan").toInt() || 1;
  2302. var currentColIndex = this.cellIndex.toInt();
  2303. return colspan > 1 && currentColIndex < col.toInt() && currentColIndex + colspan - 1 >= col.toInt();
  2304. });
  2305. Slick.definePseudo('colspan', function () {
  2306. var colspan = this.get("colspan").toInt() || 1;
  2307. return colspan > 1;
  2308. });
  2309. }
  2310. o2.common = o2.common || {};
  2311. o2.common.encodeHtml = function(str){
  2312. str = str.toString();
  2313. str = str.replace(/\&/g, "&amp;");
  2314. str = str.replace(/>/g, "&gt;");
  2315. str = str.replace(/</g, "&lt;");
  2316. return str.replace(/\"/g, "&quot;");
  2317. };
  2318. o2.common.getResponseTextPost = function(path, body, contentType){
  2319. var returnText = "";
  2320. var options = {
  2321. url: path,
  2322. async: false,
  2323. data: body,
  2324. method: "post",
  2325. onSuccess: function(esponseTree, responseElements, responseHTML, responseJavaScript){
  2326. returnText = responseHTML;
  2327. }
  2328. };
  2329. var r = new Request.HTML(options);
  2330. r.send();
  2331. return returnText;
  2332. };
  2333. o2.common.getResponseText = function(path){
  2334. var returnText = "";
  2335. var options = {
  2336. url: path,
  2337. async: false,
  2338. method: "get",
  2339. onSuccess: function(esponseTree, responseElements, responseHTML, responseJavaScript){
  2340. returnText = responseHTML;
  2341. }
  2342. };
  2343. var r = new Request.HTML(options);
  2344. r.send();
  2345. return returnText;
  2346. };
  2347. o2.common.toDate = function(str){
  2348. var tmpArr = str.split(" ");
  2349. if (!tmpArr[1]) tmpArr.push("0:0:0");
  2350. var dateArr = tmpArr[0].split("-");
  2351. var timeArr = tmpArr[1].split(":");
  2352. return new Date(dateArr[0],parseInt(dateArr[1])-1,dateArr[2],timeArr[0],timeArr[1],timeArr[2]);
  2353. };
  2354. o2.common.toDate = function(str){
  2355. var tmpArr = str.split(" ");
  2356. if (!tmpArr[1]) tmpArr.push("0:0:0");
  2357. var dateArr = tmpArr[0].split("-");
  2358. var timeArr = tmpArr[1].split(":");
  2359. return new Date(dateArr[0],parseInt(dateArr[1])-1,dateArr[2],timeArr[0],timeArr[1],timeArr[2]);
  2360. };
  2361. o2.grayscale = function(src, width, height, callback){
  2362. try {
  2363. var canvas = document.createElement('canvas');
  2364. var ctx = canvas.getContext('2d');
  2365. var imgObj = new Image();
  2366. imgObj.src = src;
  2367. canvas.width = width || imgObj.width;
  2368. canvas.height = height || imgObj.height;
  2369. ctx.drawImage(imgObj, 0, 0);
  2370. var imgPixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
  2371. for(var y = 0; y < imgPixels.height; y++){
  2372. for(var x = 0; x < imgPixels.width; x++){
  2373. var i = (y * 4) * imgPixels.width + x * 4;
  2374. var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
  2375. imgPixels.data[i] = avg;
  2376. imgPixels.data[i + 1] = avg;
  2377. imgPixels.data[i + 2] = avg;
  2378. }
  2379. }
  2380. ctx.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
  2381. var src1 = canvas.toDataURL();
  2382. //var blob = canvas.toBlob();
  2383. canvas.destroy();
  2384. return {"status": "success", "src": src1};
  2385. }catch(e){
  2386. return {"status": "error", "src": src}
  2387. }
  2388. };
  2389. o2.eventPosition = function(e){
  2390. var x = 0;
  2391. var y = 0;
  2392. if (Browser.name=="firefox"){
  2393. x = parseFloat(e.event.clientX || e.event.x);
  2394. y = parseFloat(e.event.clientY || e.event.y);
  2395. }else{
  2396. x = parseFloat(e.event.x);
  2397. y = parseFloat(e.event.y);
  2398. }
  2399. return {"x": x, "y": y};
  2400. };
  2401. if (window.Browser){
  2402. if (Browser.name==="ie" && Browser.version<9){
  2403. Browser.ieuns = true;
  2404. }else if(Browser.name==="ie" && Browser.version<10){
  2405. Browser.iecomp = true;
  2406. }
  2407. if (Browser.iecomp){
  2408. o2.load("ie_adapter", null, false);
  2409. o2.session.isDebugger = true;
  2410. //layout["debugger"] = true;
  2411. }
  2412. o2.session.isMobile = (["mac", "win", "linux"].indexOf(Browser.Platform.name)===-1);
  2413. }
  2414. })();
  2415. o2.more = true;
  2416. //o2.addReady
  2417. (function(){
  2418. //dom ready
  2419. var _dom = {
  2420. ready: false,
  2421. loaded: false,
  2422. checks: [],
  2423. shouldPoll: false,
  2424. timer: null,
  2425. testElement: document.createElement('div'),
  2426. readys: [],
  2427. domready: function(){
  2428. clearTimeout(_dom.timer);
  2429. if (_dom.ready) return;
  2430. _dom.loaded = _dom.ready = true;
  2431. o2.removeListener(document, 'DOMContentLoaded', _dom.checkReady);
  2432. o2.removeListener(document, 'readystatechange', _dom.check);
  2433. _dom.onReady();
  2434. },
  2435. check: function(){
  2436. for (var i = _dom.checks.length; i--;) if (_dom.checks[i]() && window.MooTools && o2.core && o2.more){
  2437. _dom.domready();
  2438. return true;
  2439. }
  2440. return false;
  2441. },
  2442. poll: function(){
  2443. clearTimeout(_dom.timer);
  2444. if (!_dom.check()) _dom.timer = setTimeout(_dom.poll, 10);
  2445. },
  2446. /*<ltIE8>*/
  2447. // doScroll technique by Diego Perini http://javascript.nwbox.com/IEContentLoaded/
  2448. // testElement.doScroll() throws when the DOM is not ready, only in the top window
  2449. doScrollWorks: function(){
  2450. try {
  2451. _dom.testElement.doScroll();
  2452. return true;
  2453. } catch (e){}
  2454. return false;
  2455. },
  2456. /*</ltIE8>*/
  2457. onReady: function(){
  2458. for (var i=0; i<_dom.readys.length; i++){
  2459. this.readys[i].apply(window);
  2460. }
  2461. },
  2462. addReady: function(fn){
  2463. if (_dom.loaded){
  2464. if (fn) fn.apply(window);
  2465. }else{
  2466. if (fn) _dom.readys.push(fn);
  2467. }
  2468. return _dom;
  2469. },
  2470. checkReady: function(){
  2471. _dom.checks.push(function(){return true});
  2472. _dom.check();
  2473. }
  2474. };
  2475. var _loadO2 = function(){
  2476. (!o2.core) ? this.o2.load("o2.core", _dom.check) : _dom.check();
  2477. (!o2.more) ? this.o2.load("o2.more", _dom.check) : _dom.check();
  2478. };
  2479. o2.addListener(document, 'DOMContentLoaded', _dom.checkReady);
  2480. /*<ltIE8>*/
  2481. // If doScroll works already, it can't be used to determine domready
  2482. // e.g. in an iframe
  2483. if (_dom.testElement.doScroll && !_dom.doScrollWorks()){
  2484. _dom.checks.push(_dom.doScrollWorks);
  2485. _dom.shouldPoll = true;
  2486. }
  2487. /*</ltIE8>*/
  2488. if (document.readyState) _dom.checks.push(function(){
  2489. var state = document.readyState;
  2490. return (state == 'loaded' || state == 'complete');
  2491. });
  2492. if ('onreadystatechange' in document) o2.addListener(document, 'readystatechange', _dom.check);
  2493. else _dom.shouldPoll = true;
  2494. if (_dom.shouldPoll) _dom.poll();
  2495. if (!window.MooTools){
  2496. this.o2.load("mootools", function(){ _loadO2(); _dom.check(); });
  2497. }else{
  2498. _loadO2();
  2499. }
  2500. this.o2.addReady = function(fn){ _dom.addReady.call(_dom, fn); };
  2501. })();
  2502. //compatible
  2503. COMMON = {
  2504. "DOM":{},
  2505. "setContentPath": function(path){
  2506. COMMON.contentPath = path;
  2507. },
  2508. "JSON": o2.JSON,
  2509. "Browser": Browser,
  2510. "Class": o2.Class,
  2511. "XML": o2.xml,
  2512. "AjaxModule": {
  2513. "load": function(urls, callback, async, reload){
  2514. o2.load(urls, callback, reload, document);
  2515. },
  2516. "loadDom": function(urls, callback, async, reload){
  2517. o2.load(urls, callback, reload, document);
  2518. },
  2519. "loadCss": function(urls, callback, async, reload, sourceDoc){
  2520. o2.loadCss(urls, document.body, callback, reload, sourceDoc);
  2521. }
  2522. },
  2523. "Request": Request,
  2524. "typeOf": o2.typeOf
  2525. };
  2526. COMMON.Browser.Platform.isMobile = o2.session.isMobile;
  2527. COMMON.DOM.addReady = o2.addReady;
  2528. MWF = o2;
  2529. MWF.getJSON = o2.JSON.get;
  2530. MWF.getJSONP = o2.JSON.getJsonp;
  2531. MWF.defaultPath = o2.session.path;