o2.js 119 KB

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