o2.js 119 KB

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