o2.js 117 KB

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