o2.js 125 KB

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