ext-dev.js 965 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399
  1. /*
  2. Ext JS 4.1 - JavaScript Library
  3. Copyright (c) 2006-2012, Sencha Inc.
  4. All rights reserved.
  5. licensing@sencha.com
  6. http://www.sencha.com/license
  7. Open Source License
  8. ------------------------------------------------------------------------------------------
  9. This version of Ext JS is licensed under the terms of the Open Source GPL 3.0 license.
  10. http://www.gnu.org/licenses/gpl.html
  11. There are several FLOSS exceptions available for use with this release for
  12. open source applications that are distributed under a license other than GPL.
  13. * Open Source License Exception for Applications
  14. http://www.sencha.com/products/floss-exception.php
  15. * Open Source License Exception for Development
  16. http://www.sencha.com/products/ux-exception.php
  17. Alternate Licensing
  18. ------------------------------------------------------------------------------------------
  19. Commercial and OEM Licenses are available for an alternate download of Ext JS.
  20. This is the appropriate option if you are creating proprietary applications and you are
  21. not prepared to distribute and share the source code of your application under the
  22. GPL v3 license. Please visit http://www.sencha.com/license for more details.
  23. --
  24. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF THIRD-PARTY INTELLECTUAL PROPERTY RIGHTS. See the GNU General Public License for more details.
  25. */
  26. //@tag foundation,core
  27. /**
  28. * @class Ext
  29. * @singleton
  30. */
  31. var Ext = Ext || {};
  32. Ext._startTime = new Date().getTime();
  33. (function() {
  34. var global = this,
  35. objectPrototype = Object.prototype,
  36. toString = objectPrototype.toString,
  37. enumerables = true,
  38. enumerablesTest = { toString: 1 },
  39. emptyFn = function () {},
  40. // This is the "$previous" method of a hook function on an instance. When called, it
  41. // calls through the class prototype by the name of the called method.
  42. callOverrideParent = function () {
  43. var method = callOverrideParent.caller.caller; // skip callParent (our caller)
  44. return method.$owner.prototype[method.$name].apply(this, arguments);
  45. },
  46. i;
  47. Ext.global = global;
  48. for (i in enumerablesTest) {
  49. enumerables = null;
  50. }
  51. if (enumerables) {
  52. enumerables = ['hasOwnProperty', 'valueOf', 'isPrototypeOf', 'propertyIsEnumerable',
  53. 'toLocaleString', 'toString', 'constructor'];
  54. }
  55. /**
  56. * An array containing extra enumerables for old browsers
  57. * @property {String[]}
  58. */
  59. Ext.enumerables = enumerables;
  60. /**
  61. * Copies all the properties of config to the specified object.
  62. * Note that if recursive merging and cloning without referencing the original objects / arrays is needed, use
  63. * {@link Ext.Object#merge} instead.
  64. * @param {Object} object The receiver of the properties
  65. * @param {Object} config The source of the properties
  66. * @param {Object} [defaults] A different object that will also be applied for default values
  67. * @return {Object} returns obj
  68. */
  69. Ext.apply = function(object, config, defaults) {
  70. if (defaults) {
  71. Ext.apply(object, defaults);
  72. }
  73. if (object && config && typeof config === 'object') {
  74. var i, j, k;
  75. for (i in config) {
  76. object[i] = config[i];
  77. }
  78. if (enumerables) {
  79. for (j = enumerables.length; j--;) {
  80. k = enumerables[j];
  81. if (config.hasOwnProperty(k)) {
  82. object[k] = config[k];
  83. }
  84. }
  85. }
  86. }
  87. return object;
  88. };
  89. Ext.buildSettings = Ext.apply({
  90. baseCSSPrefix: 'x-',
  91. scopeResetCSS: false
  92. }, Ext.buildSettings || {});
  93. Ext.apply(Ext, {
  94. /**
  95. * @property {String} [name='Ext']
  96. * <p>The name of the property in the global namespace (The <code>window</code> in browser environments) which refers to the current instance of Ext.</p>
  97. * <p>This is usually <code>"Ext"</code>, but if a sandboxed build of ExtJS is being used, this will be an alternative name.</p>
  98. * <p>If code is being generated for use by <code>eval</code> or to create a <code>new Function</code>, and the global instance
  99. * of Ext must be referenced, this is the name that should be built into the code.</p>
  100. */
  101. name: Ext.sandboxName || 'Ext',
  102. /**
  103. * A reusable empty function
  104. */
  105. emptyFn: emptyFn,
  106. /**
  107. * A zero length string which will pass a truth test. Useful for passing to methods
  108. * which use a truth test to reject <i>falsy</i> values where a string value must be cleared.
  109. */
  110. emptyString: new String(),
  111. baseCSSPrefix: Ext.buildSettings.baseCSSPrefix,
  112. /**
  113. * Copies all the properties of config to object if they don't already exist.
  114. * @param {Object} object The receiver of the properties
  115. * @param {Object} config The source of the properties
  116. * @return {Object} returns obj
  117. */
  118. applyIf: function(object, config) {
  119. var property;
  120. if (object) {
  121. for (property in config) {
  122. if (object[property] === undefined) {
  123. object[property] = config[property];
  124. }
  125. }
  126. }
  127. return object;
  128. },
  129. /**
  130. * Iterates either an array or an object. This method delegates to
  131. * {@link Ext.Array#each Ext.Array.each} if the given value is iterable, and {@link Ext.Object#each Ext.Object.each} otherwise.
  132. *
  133. * @param {Object/Array} object The object or array to be iterated.
  134. * @param {Function} fn The function to be called for each iteration. See and {@link Ext.Array#each Ext.Array.each} and
  135. * {@link Ext.Object#each Ext.Object.each} for detailed lists of arguments passed to this function depending on the given object
  136. * type that is being iterated.
  137. * @param {Object} scope (Optional) The scope (`this` reference) in which the specified function is executed.
  138. * Defaults to the object being iterated itself.
  139. * @markdown
  140. */
  141. iterate: function(object, fn, scope) {
  142. if (Ext.isEmpty(object)) {
  143. return;
  144. }
  145. if (scope === undefined) {
  146. scope = object;
  147. }
  148. if (Ext.isIterable(object)) {
  149. Ext.Array.each.call(Ext.Array, object, fn, scope);
  150. }
  151. else {
  152. Ext.Object.each.call(Ext.Object, object, fn, scope);
  153. }
  154. }
  155. });
  156. Ext.apply(Ext, {
  157. /**
  158. * This method deprecated. Use {@link Ext#define Ext.define} instead.
  159. * @method
  160. * @param {Function} superclass
  161. * @param {Object} overrides
  162. * @return {Function} The subclass constructor from the <tt>overrides</tt> parameter, or a generated one if not provided.
  163. * @deprecated 4.0.0 Use {@link Ext#define Ext.define} instead
  164. */
  165. extend: (function() {
  166. // inline overrides
  167. var objectConstructor = objectPrototype.constructor,
  168. inlineOverrides = function(o) {
  169. for (var m in o) {
  170. if (!o.hasOwnProperty(m)) {
  171. continue;
  172. }
  173. this[m] = o[m];
  174. }
  175. };
  176. return function(subclass, superclass, overrides) {
  177. // First we check if the user passed in just the superClass with overrides
  178. if (Ext.isObject(superclass)) {
  179. overrides = superclass;
  180. superclass = subclass;
  181. subclass = overrides.constructor !== objectConstructor ? overrides.constructor : function() {
  182. superclass.apply(this, arguments);
  183. };
  184. }
  185. if (!superclass) {
  186. Ext.Error.raise({
  187. sourceClass: 'Ext',
  188. sourceMethod: 'extend',
  189. msg: 'Attempting to extend from a class which has not been loaded on the page.'
  190. });
  191. }
  192. // We create a new temporary class
  193. var F = function() {},
  194. subclassProto, superclassProto = superclass.prototype;
  195. F.prototype = superclassProto;
  196. subclassProto = subclass.prototype = new F();
  197. subclassProto.constructor = subclass;
  198. subclass.superclass = superclassProto;
  199. if (superclassProto.constructor === objectConstructor) {
  200. superclassProto.constructor = superclass;
  201. }
  202. subclass.override = function(overrides) {
  203. Ext.override(subclass, overrides);
  204. };
  205. subclassProto.override = inlineOverrides;
  206. subclassProto.proto = subclassProto;
  207. subclass.override(overrides);
  208. subclass.extend = function(o) {
  209. return Ext.extend(subclass, o);
  210. };
  211. return subclass;
  212. };
  213. }()),
  214. /**
  215. * Overrides members of the specified `target` with the given values.
  216. *
  217. * If the `target` is a class declared using {@link Ext#define Ext.define}, the
  218. * `override` method of that class is called (see {@link Ext.Base#override}) given
  219. * the `overrides`.
  220. *
  221. * If the `target` is a function, it is assumed to be a constructor and the contents
  222. * of `overrides` are applied to its `prototype` using {@link Ext#apply Ext.apply}.
  223. *
  224. * If the `target` is an instance of a class declared using {@link Ext#define Ext.define},
  225. * the `overrides` are applied to only that instance. In this case, methods are
  226. * specially processed to allow them to use {@link Ext.Base#callParent}.
  227. *
  228. * var panel = new Ext.Panel({ ... });
  229. *
  230. * Ext.override(panel, {
  231. * initComponent: function () {
  232. * // extra processing...
  233. *
  234. * this.callParent();
  235. * }
  236. * });
  237. *
  238. * If the `target` is none of these, the `overrides` are applied to the `target`
  239. * using {@link Ext#apply Ext.apply}.
  240. *
  241. * Please refer to {@link Ext#define Ext.define} and {@link Ext.Base#override} for
  242. * further details.
  243. *
  244. * @param {Object} target The target to override.
  245. * @param {Object} overrides The properties to add or replace on `target`.
  246. * @method override
  247. */
  248. override: function (target, overrides) {
  249. if (target.$isClass) {
  250. target.override(overrides);
  251. } else if (typeof target == 'function') {
  252. Ext.apply(target.prototype, overrides);
  253. } else {
  254. var owner = target.self,
  255. name, value;
  256. if (owner && owner.$isClass) { // if (instance of Ext.define'd class)
  257. for (name in overrides) {
  258. if (overrides.hasOwnProperty(name)) {
  259. value = overrides[name];
  260. if (typeof value == 'function') {
  261. if (owner.$className) {
  262. value.displayName = owner.$className + '#' + name;
  263. }
  264. value.$name = name;
  265. value.$owner = owner;
  266. value.$previous = target.hasOwnProperty(name)
  267. ? target[name] // already hooked, so call previous hook
  268. : callOverrideParent; // calls by name on prototype
  269. }
  270. target[name] = value;
  271. }
  272. }
  273. } else {
  274. Ext.apply(target, overrides);
  275. }
  276. }
  277. return target;
  278. }
  279. });
  280. // A full set of static methods to do type checking
  281. Ext.apply(Ext, {
  282. /**
  283. * Returns the given value itself if it's not empty, as described in {@link Ext#isEmpty}; returns the default
  284. * value (second argument) otherwise.
  285. *
  286. * @param {Object} value The value to test
  287. * @param {Object} defaultValue The value to return if the original value is empty
  288. * @param {Boolean} allowBlank (optional) true to allow zero length strings to qualify as non-empty (defaults to false)
  289. * @return {Object} value, if non-empty, else defaultValue
  290. */
  291. valueFrom: function(value, defaultValue, allowBlank){
  292. return Ext.isEmpty(value, allowBlank) ? defaultValue : value;
  293. },
  294. /**
  295. * Returns the type of the given variable in string format. List of possible values are:
  296. *
  297. * - `undefined`: If the given value is `undefined`
  298. * - `null`: If the given value is `null`
  299. * - `string`: If the given value is a string
  300. * - `number`: If the given value is a number
  301. * - `boolean`: If the given value is a boolean value
  302. * - `date`: If the given value is a `Date` object
  303. * - `function`: If the given value is a function reference
  304. * - `object`: If the given value is an object
  305. * - `array`: If the given value is an array
  306. * - `regexp`: If the given value is a regular expression
  307. * - `element`: If the given value is a DOM Element
  308. * - `textnode`: If the given value is a DOM text node and contains something other than whitespace
  309. * - `whitespace`: If the given value is a DOM text node and contains only whitespace
  310. *
  311. * @param {Object} value
  312. * @return {String}
  313. * @markdown
  314. */
  315. typeOf: function(value) {
  316. var type,
  317. typeToString;
  318. if (value === null) {
  319. return 'null';
  320. }
  321. type = typeof value;
  322. if (type === 'undefined' || type === 'string' || type === 'number' || type === 'boolean') {
  323. return type;
  324. }
  325. typeToString = toString.call(value);
  326. switch(typeToString) {
  327. case '[object Array]':
  328. return 'array';
  329. case '[object Date]':
  330. return 'date';
  331. case '[object Boolean]':
  332. return 'boolean';
  333. case '[object Number]':
  334. return 'number';
  335. case '[object RegExp]':
  336. return 'regexp';
  337. }
  338. if (type === 'function') {
  339. return 'function';
  340. }
  341. if (type === 'object') {
  342. if (value.nodeType !== undefined) {
  343. if (value.nodeType === 3) {
  344. return (/\S/).test(value.nodeValue) ? 'textnode' : 'whitespace';
  345. }
  346. else {
  347. return 'element';
  348. }
  349. }
  350. return 'object';
  351. }
  352. Ext.Error.raise({
  353. sourceClass: 'Ext',
  354. sourceMethod: 'typeOf',
  355. msg: 'Failed to determine the type of the specified value "' + value + '". This is most likely a bug.'
  356. });
  357. },
  358. /**
  359. * Returns true if the passed value is empty, false otherwise. The value is deemed to be empty if it is either:
  360. *
  361. * - `null`
  362. * - `undefined`
  363. * - a zero-length array
  364. * - a zero-length string (Unless the `allowEmptyString` parameter is set to `true`)
  365. *
  366. * @param {Object} value The value to test
  367. * @param {Boolean} allowEmptyString (optional) true to allow empty strings (defaults to false)
  368. * @return {Boolean}
  369. * @markdown
  370. */
  371. isEmpty: function(value, allowEmptyString) {
  372. return (value === null) || (value === undefined) || (!allowEmptyString ? value === '' : false) || (Ext.isArray(value) && value.length === 0);
  373. },
  374. /**
  375. * Returns true if the passed value is a JavaScript Array, false otherwise.
  376. *
  377. * @param {Object} target The target to test
  378. * @return {Boolean}
  379. * @method
  380. */
  381. isArray: ('isArray' in Array) ? Array.isArray : function(value) {
  382. return toString.call(value) === '[object Array]';
  383. },
  384. /**
  385. * Returns true if the passed value is a JavaScript Date object, false otherwise.
  386. * @param {Object} object The object to test
  387. * @return {Boolean}
  388. */
  389. isDate: function(value) {
  390. return toString.call(value) === '[object Date]';
  391. },
  392. /**
  393. * Returns true if the passed value is a JavaScript Object, false otherwise.
  394. * @param {Object} value The value to test
  395. * @return {Boolean}
  396. * @method
  397. */
  398. isObject: (toString.call(null) === '[object Object]') ?
  399. function(value) {
  400. // check ownerDocument here as well to exclude DOM nodes
  401. return value !== null && value !== undefined && toString.call(value) === '[object Object]' && value.ownerDocument === undefined;
  402. } :
  403. function(value) {
  404. return toString.call(value) === '[object Object]';
  405. },
  406. /**
  407. * @private
  408. */
  409. isSimpleObject: function(value) {
  410. return value instanceof Object && value.constructor === Object;
  411. },
  412. /**
  413. * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.
  414. * @param {Object} value The value to test
  415. * @return {Boolean}
  416. */
  417. isPrimitive: function(value) {
  418. var type = typeof value;
  419. return type === 'string' || type === 'number' || type === 'boolean';
  420. },
  421. /**
  422. * Returns true if the passed value is a JavaScript Function, false otherwise.
  423. * @param {Object} value The value to test
  424. * @return {Boolean}
  425. * @method
  426. */
  427. isFunction:
  428. // Safari 3.x and 4.x returns 'function' for typeof <NodeList>, hence we need to fall back to using
  429. // Object.prototype.toString (slower)
  430. (typeof document !== 'undefined' && typeof document.getElementsByTagName('body') === 'function') ? function(value) {
  431. return toString.call(value) === '[object Function]';
  432. } : function(value) {
  433. return typeof value === 'function';
  434. },
  435. /**
  436. * Returns true if the passed value is a number. Returns false for non-finite numbers.
  437. * @param {Object} value The value to test
  438. * @return {Boolean}
  439. */
  440. isNumber: function(value) {
  441. return typeof value === 'number' && isFinite(value);
  442. },
  443. /**
  444. * Validates that a value is numeric.
  445. * @param {Object} value Examples: 1, '1', '2.34'
  446. * @return {Boolean} True if numeric, false otherwise
  447. */
  448. isNumeric: function(value) {
  449. return !isNaN(parseFloat(value)) && isFinite(value);
  450. },
  451. /**
  452. * Returns true if the passed value is a string.
  453. * @param {Object} value The value to test
  454. * @return {Boolean}
  455. */
  456. isString: function(value) {
  457. return typeof value === 'string';
  458. },
  459. /**
  460. * Returns true if the passed value is a boolean.
  461. *
  462. * @param {Object} value The value to test
  463. * @return {Boolean}
  464. */
  465. isBoolean: function(value) {
  466. return typeof value === 'boolean';
  467. },
  468. /**
  469. * Returns true if the passed value is an HTMLElement
  470. * @param {Object} value The value to test
  471. * @return {Boolean}
  472. */
  473. isElement: function(value) {
  474. return value ? value.nodeType === 1 : false;
  475. },
  476. /**
  477. * Returns true if the passed value is a TextNode
  478. * @param {Object} value The value to test
  479. * @return {Boolean}
  480. */
  481. isTextNode: function(value) {
  482. return value ? value.nodeName === "#text" : false;
  483. },
  484. /**
  485. * Returns true if the passed value is defined.
  486. * @param {Object} value The value to test
  487. * @return {Boolean}
  488. */
  489. isDefined: function(value) {
  490. return typeof value !== 'undefined';
  491. },
  492. /**
  493. * Returns true if the passed value is iterable, false otherwise
  494. * @param {Object} value The value to test
  495. * @return {Boolean}
  496. */
  497. isIterable: function(value) {
  498. var type = typeof value,
  499. checkLength = false;
  500. if (value && type != 'string') {
  501. // Functions have a length property, so we need to filter them out
  502. if (type == 'function') {
  503. // In Safari, NodeList/HTMLCollection both return "function" when using typeof, so we need
  504. // to explicitly check them here.
  505. if (Ext.isSafari) {
  506. checkLength = value instanceof NodeList || value instanceof HTMLCollection;
  507. }
  508. } else {
  509. checkLength = true;
  510. }
  511. }
  512. return checkLength ? value.length !== undefined : false;
  513. }
  514. });
  515. Ext.apply(Ext, {
  516. /**
  517. * Clone simple variables including array, {}-like objects, DOM nodes and Date without keeping the old reference.
  518. * A reference for the object itself is returned if it's not a direct decendant of Object. For model cloning,
  519. * see {@link Ext.data.Model#copy Model.copy}.
  520. *
  521. * @param {Object} item The variable to clone
  522. * @return {Object} clone
  523. */
  524. clone: function(item) {
  525. var type,
  526. i,
  527. j,
  528. k,
  529. clone,
  530. key;
  531. if (item === null || item === undefined) {
  532. return item;
  533. }
  534. // DOM nodes
  535. // TODO proxy this to Ext.Element.clone to handle automatic id attribute changing
  536. // recursively
  537. if (item.nodeType && item.cloneNode) {
  538. return item.cloneNode(true);
  539. }
  540. type = toString.call(item);
  541. // Date
  542. if (type === '[object Date]') {
  543. return new Date(item.getTime());
  544. }
  545. // Array
  546. if (type === '[object Array]') {
  547. i = item.length;
  548. clone = [];
  549. while (i--) {
  550. clone[i] = Ext.clone(item[i]);
  551. }
  552. }
  553. // Object
  554. else if (type === '[object Object]' && item.constructor === Object) {
  555. clone = {};
  556. for (key in item) {
  557. clone[key] = Ext.clone(item[key]);
  558. }
  559. if (enumerables) {
  560. for (j = enumerables.length; j--;) {
  561. k = enumerables[j];
  562. clone[k] = item[k];
  563. }
  564. }
  565. }
  566. return clone || item;
  567. },
  568. /**
  569. * @private
  570. * Generate a unique reference of Ext in the global scope, useful for sandboxing
  571. */
  572. getUniqueGlobalNamespace: function() {
  573. var uniqueGlobalNamespace = this.uniqueGlobalNamespace,
  574. i;
  575. if (uniqueGlobalNamespace === undefined) {
  576. i = 0;
  577. do {
  578. uniqueGlobalNamespace = 'ExtBox' + (++i);
  579. } while (Ext.global[uniqueGlobalNamespace] !== undefined);
  580. Ext.global[uniqueGlobalNamespace] = Ext;
  581. this.uniqueGlobalNamespace = uniqueGlobalNamespace;
  582. }
  583. return uniqueGlobalNamespace;
  584. },
  585. /**
  586. * @private
  587. */
  588. functionFactoryCache: {},
  589. cacheableFunctionFactory: function() {
  590. var me = this,
  591. args = Array.prototype.slice.call(arguments),
  592. cache = me.functionFactoryCache,
  593. idx, fn, ln;
  594. if (Ext.isSandboxed) {
  595. ln = args.length;
  596. if (ln > 0) {
  597. ln--;
  598. args[ln] = 'var Ext=window.' + Ext.name + ';' + args[ln];
  599. }
  600. }
  601. idx = args.join('');
  602. fn = cache[idx];
  603. if (!fn) {
  604. fn = Function.prototype.constructor.apply(Function.prototype, args);
  605. cache[idx] = fn;
  606. }
  607. return fn;
  608. },
  609. functionFactory: function() {
  610. var me = this,
  611. args = Array.prototype.slice.call(arguments),
  612. ln;
  613. if (Ext.isSandboxed) {
  614. ln = args.length;
  615. if (ln > 0) {
  616. ln--;
  617. args[ln] = 'var Ext=window.' + Ext.name + ';' + args[ln];
  618. }
  619. }
  620. return Function.prototype.constructor.apply(Function.prototype, args);
  621. },
  622. /**
  623. * @private
  624. * @property
  625. */
  626. Logger: {
  627. verbose: emptyFn,
  628. log: emptyFn,
  629. info: emptyFn,
  630. warn: emptyFn,
  631. error: function(message) {
  632. throw new Error(message);
  633. },
  634. deprecate: emptyFn
  635. }
  636. });
  637. /**
  638. * Old alias to {@link Ext#typeOf}
  639. * @deprecated 4.0.0 Use {@link Ext#typeOf} instead
  640. * @method
  641. * @inheritdoc Ext#typeOf
  642. */
  643. Ext.type = Ext.typeOf;
  644. }());
  645. /*
  646. * This method evaluates the given code free of any local variable. In some browsers this
  647. * will be at global scope, in others it will be in a function.
  648. * @parma {String} code The code to evaluate.
  649. * @private
  650. * @method
  651. */
  652. Ext.globalEval = Ext.global.execScript
  653. ? function(code) {
  654. execScript(code);
  655. }
  656. : function($$code) {
  657. // IMPORTANT: because we use eval we cannot place this in the above function or it
  658. // will break the compressor's ability to rename local variables...
  659. (function(){
  660. eval($$code);
  661. }());
  662. };
  663. //@tag foundation,core
  664. //@require ../Ext.js
  665. /**
  666. * @author Jacky Nguyen <jacky@sencha.com>
  667. * @docauthor Jacky Nguyen <jacky@sencha.com>
  668. * @class Ext.Version
  669. *
  670. * A utility class that wrap around a string version number and provide convenient
  671. * method to perform comparison. See also: {@link Ext.Version#compare compare}. Example:
  672. *
  673. * var version = new Ext.Version('1.0.2beta');
  674. * console.log("Version is " + version); // Version is 1.0.2beta
  675. *
  676. * console.log(version.getMajor()); // 1
  677. * console.log(version.getMinor()); // 0
  678. * console.log(version.getPatch()); // 2
  679. * console.log(version.getBuild()); // 0
  680. * console.log(version.getRelease()); // beta
  681. *
  682. * console.log(version.isGreaterThan('1.0.1')); // True
  683. * console.log(version.isGreaterThan('1.0.2alpha')); // True
  684. * console.log(version.isGreaterThan('1.0.2RC')); // False
  685. * console.log(version.isGreaterThan('1.0.2')); // False
  686. * console.log(version.isLessThan('1.0.2')); // True
  687. *
  688. * console.log(version.match(1.0)); // True
  689. * console.log(version.match('1.0.2')); // True
  690. *
  691. */
  692. (function() {
  693. // Current core version
  694. var version = '4.1.1.1', Version;
  695. Ext.Version = Version = Ext.extend(Object, {
  696. /**
  697. * @param {String/Number} version The version number in the following standard format:
  698. *
  699. * major[.minor[.patch[.build[release]]]]
  700. *
  701. * Examples:
  702. *
  703. * 1.0
  704. * 1.2.3beta
  705. * 1.2.3.4RC
  706. *
  707. * @return {Ext.Version} this
  708. */
  709. constructor: function(version) {
  710. var parts, releaseStartIndex;
  711. if (version instanceof Version) {
  712. return version;
  713. }
  714. this.version = this.shortVersion = String(version).toLowerCase().replace(/_/g, '.').replace(/[\-+]/g, '');
  715. releaseStartIndex = this.version.search(/([^\d\.])/);
  716. if (releaseStartIndex !== -1) {
  717. this.release = this.version.substr(releaseStartIndex, version.length);
  718. this.shortVersion = this.version.substr(0, releaseStartIndex);
  719. }
  720. this.shortVersion = this.shortVersion.replace(/[^\d]/g, '');
  721. parts = this.version.split('.');
  722. this.major = parseInt(parts.shift() || 0, 10);
  723. this.minor = parseInt(parts.shift() || 0, 10);
  724. this.patch = parseInt(parts.shift() || 0, 10);
  725. this.build = parseInt(parts.shift() || 0, 10);
  726. return this;
  727. },
  728. /**
  729. * Override the native toString method
  730. * @private
  731. * @return {String} version
  732. */
  733. toString: function() {
  734. return this.version;
  735. },
  736. /**
  737. * Override the native valueOf method
  738. * @private
  739. * @return {String} version
  740. */
  741. valueOf: function() {
  742. return this.version;
  743. },
  744. /**
  745. * Returns the major component value
  746. * @return {Number} major
  747. */
  748. getMajor: function() {
  749. return this.major || 0;
  750. },
  751. /**
  752. * Returns the minor component value
  753. * @return {Number} minor
  754. */
  755. getMinor: function() {
  756. return this.minor || 0;
  757. },
  758. /**
  759. * Returns the patch component value
  760. * @return {Number} patch
  761. */
  762. getPatch: function() {
  763. return this.patch || 0;
  764. },
  765. /**
  766. * Returns the build component value
  767. * @return {Number} build
  768. */
  769. getBuild: function() {
  770. return this.build || 0;
  771. },
  772. /**
  773. * Returns the release component value
  774. * @return {Number} release
  775. */
  776. getRelease: function() {
  777. return this.release || '';
  778. },
  779. /**
  780. * Returns whether this version if greater than the supplied argument
  781. * @param {String/Number} target The version to compare with
  782. * @return {Boolean} True if this version if greater than the target, false otherwise
  783. */
  784. isGreaterThan: function(target) {
  785. return Version.compare(this.version, target) === 1;
  786. },
  787. /**
  788. * Returns whether this version if greater than or equal to the supplied argument
  789. * @param {String/Number} target The version to compare with
  790. * @return {Boolean} True if this version if greater than or equal to the target, false otherwise
  791. */
  792. isGreaterThanOrEqual: function(target) {
  793. return Version.compare(this.version, target) >= 0;
  794. },
  795. /**
  796. * Returns whether this version if smaller than the supplied argument
  797. * @param {String/Number} target The version to compare with
  798. * @return {Boolean} True if this version if smaller than the target, false otherwise
  799. */
  800. isLessThan: function(target) {
  801. return Version.compare(this.version, target) === -1;
  802. },
  803. /**
  804. * Returns whether this version if less than or equal to the supplied argument
  805. * @param {String/Number} target The version to compare with
  806. * @return {Boolean} True if this version if less than or equal to the target, false otherwise
  807. */
  808. isLessThanOrEqual: function(target) {
  809. return Version.compare(this.version, target) <= 0;
  810. },
  811. /**
  812. * Returns whether this version equals to the supplied argument
  813. * @param {String/Number} target The version to compare with
  814. * @return {Boolean} True if this version equals to the target, false otherwise
  815. */
  816. equals: function(target) {
  817. return Version.compare(this.version, target) === 0;
  818. },
  819. /**
  820. * Returns whether this version matches the supplied argument. Example:
  821. *
  822. * var version = new Ext.Version('1.0.2beta');
  823. * console.log(version.match(1)); // True
  824. * console.log(version.match(1.0)); // True
  825. * console.log(version.match('1.0.2')); // True
  826. * console.log(version.match('1.0.2RC')); // False
  827. *
  828. * @param {String/Number} target The version to compare with
  829. * @return {Boolean} True if this version matches the target, false otherwise
  830. */
  831. match: function(target) {
  832. target = String(target);
  833. return this.version.substr(0, target.length) === target;
  834. },
  835. /**
  836. * Returns this format: [major, minor, patch, build, release]. Useful for comparison
  837. * @return {Number[]}
  838. */
  839. toArray: function() {
  840. return [this.getMajor(), this.getMinor(), this.getPatch(), this.getBuild(), this.getRelease()];
  841. },
  842. /**
  843. * Returns shortVersion version without dots and release
  844. * @return {String}
  845. */
  846. getShortVersion: function() {
  847. return this.shortVersion;
  848. },
  849. /**
  850. * Convenient alias to {@link Ext.Version#isGreaterThan isGreaterThan}
  851. * @param {String/Number} target
  852. * @return {Boolean}
  853. */
  854. gt: function() {
  855. return this.isGreaterThan.apply(this, arguments);
  856. },
  857. /**
  858. * Convenient alias to {@link Ext.Version#isLessThan isLessThan}
  859. * @param {String/Number} target
  860. * @return {Boolean}
  861. */
  862. lt: function() {
  863. return this.isLessThan.apply(this, arguments);
  864. },
  865. /**
  866. * Convenient alias to {@link Ext.Version#isGreaterThanOrEqual isGreaterThanOrEqual}
  867. * @param {String/Number} target
  868. * @return {Boolean}
  869. */
  870. gtEq: function() {
  871. return this.isGreaterThanOrEqual.apply(this, arguments);
  872. },
  873. /**
  874. * Convenient alias to {@link Ext.Version#isLessThanOrEqual isLessThanOrEqual}
  875. * @param {String/Number} target
  876. * @return {Boolean}
  877. */
  878. ltEq: function() {
  879. return this.isLessThanOrEqual.apply(this, arguments);
  880. }
  881. });
  882. Ext.apply(Version, {
  883. // @private
  884. releaseValueMap: {
  885. 'dev': -6,
  886. 'alpha': -5,
  887. 'a': -5,
  888. 'beta': -4,
  889. 'b': -4,
  890. 'rc': -3,
  891. '#': -2,
  892. 'p': -1,
  893. 'pl': -1
  894. },
  895. /**
  896. * Converts a version component to a comparable value
  897. *
  898. * @static
  899. * @param {Object} value The value to convert
  900. * @return {Object}
  901. */
  902. getComponentValue: function(value) {
  903. return !value ? 0 : (isNaN(value) ? this.releaseValueMap[value] || value : parseInt(value, 10));
  904. },
  905. /**
  906. * Compare 2 specified versions, starting from left to right. If a part contains special version strings,
  907. * they are handled in the following order:
  908. * 'dev' < 'alpha' = 'a' < 'beta' = 'b' < 'RC' = 'rc' < '#' < 'pl' = 'p' < 'anything else'
  909. *
  910. * @static
  911. * @param {String} current The current version to compare to
  912. * @param {String} target The target version to compare to
  913. * @return {Number} Returns -1 if the current version is smaller than the target version, 1 if greater, and 0 if they're equivalent
  914. */
  915. compare: function(current, target) {
  916. var currentValue, targetValue, i;
  917. current = new Version(current).toArray();
  918. target = new Version(target).toArray();
  919. for (i = 0; i < Math.max(current.length, target.length); i++) {
  920. currentValue = this.getComponentValue(current[i]);
  921. targetValue = this.getComponentValue(target[i]);
  922. if (currentValue < targetValue) {
  923. return -1;
  924. } else if (currentValue > targetValue) {
  925. return 1;
  926. }
  927. }
  928. return 0;
  929. }
  930. });
  931. /**
  932. * @class Ext
  933. */
  934. Ext.apply(Ext, {
  935. /**
  936. * @private
  937. */
  938. versions: {},
  939. /**
  940. * @private
  941. */
  942. lastRegisteredVersion: null,
  943. /**
  944. * Set version number for the given package name.
  945. *
  946. * @param {String} packageName The package name, for example: 'core', 'touch', 'extjs'
  947. * @param {String/Ext.Version} version The version, for example: '1.2.3alpha', '2.4.0-dev'
  948. * @return {Ext}
  949. */
  950. setVersion: function(packageName, version) {
  951. Ext.versions[packageName] = new Version(version);
  952. Ext.lastRegisteredVersion = Ext.versions[packageName];
  953. return this;
  954. },
  955. /**
  956. * Get the version number of the supplied package name; will return the last registered version
  957. * (last Ext.setVersion call) if there's no package name given.
  958. *
  959. * @param {String} packageName (Optional) The package name, for example: 'core', 'touch', 'extjs'
  960. * @return {Ext.Version} The version
  961. */
  962. getVersion: function(packageName) {
  963. if (packageName === undefined) {
  964. return Ext.lastRegisteredVersion;
  965. }
  966. return Ext.versions[packageName];
  967. },
  968. /**
  969. * Create a closure for deprecated code.
  970. *
  971. * // This means Ext.oldMethod is only supported in 4.0.0beta and older.
  972. * // If Ext.getVersion('extjs') returns a version that is later than '4.0.0beta', for example '4.0.0RC',
  973. * // the closure will not be invoked
  974. * Ext.deprecate('extjs', '4.0.0beta', function() {
  975. * Ext.oldMethod = Ext.newMethod;
  976. *
  977. * ...
  978. * });
  979. *
  980. * @param {String} packageName The package name
  981. * @param {String} since The last version before it's deprecated
  982. * @param {Function} closure The callback function to be executed with the specified version is less than the current version
  983. * @param {Object} scope The execution scope (`this`) if the closure
  984. */
  985. deprecate: function(packageName, since, closure, scope) {
  986. if (Version.compare(Ext.getVersion(packageName), since) < 1) {
  987. closure.call(scope);
  988. }
  989. }
  990. }); // End Versioning
  991. Ext.setVersion('core', version);
  992. }());
  993. //@tag foundation,core
  994. //@require ../version/Version.js
  995. /**
  996. * @class Ext.String
  997. *
  998. * A collection of useful static methods to deal with strings
  999. * @singleton
  1000. */
  1001. Ext.String = (function() {
  1002. var trimRegex = /^[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000]+|[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000]+$/g,
  1003. escapeRe = /('|\\)/g,
  1004. formatRe = /\{(\d+)\}/g,
  1005. escapeRegexRe = /([-.*+?\^${}()|\[\]\/\\])/g,
  1006. basicTrimRe = /^\s+|\s+$/g,
  1007. whitespaceRe = /\s+/,
  1008. varReplace = /(^[^a-z]*|[^\w])/gi,
  1009. charToEntity,
  1010. entityToChar,
  1011. charToEntityRegex,
  1012. entityToCharRegex,
  1013. htmlEncodeReplaceFn = function(match, capture) {
  1014. return charToEntity[capture];
  1015. },
  1016. htmlDecodeReplaceFn = function(match, capture) {
  1017. return (capture in entityToChar) ? entityToChar[capture] : String.fromCharCode(parseInt(capture.substr(2), 10));
  1018. };
  1019. return {
  1020. /**
  1021. * Converts a string of characters into a legal, parseable Javascript `var` name as long as the passed
  1022. * string contains at least one alphabetic character. Non alphanumeric characters, and *leading* non alphabetic
  1023. * characters will be removed.
  1024. * @param {String} s A string to be converted into a `var` name.
  1025. * @return {String} A legal Javascript `var` name.
  1026. */
  1027. createVarName: function(s) {
  1028. return s.replace(varReplace, '');
  1029. },
  1030. /**
  1031. * Convert certain characters (&, <, >, ', and ") to their HTML character equivalents for literal display in web pages.
  1032. * @param {String} value The string to encode
  1033. * @return {String} The encoded text
  1034. * @method
  1035. */
  1036. htmlEncode: function(value) {
  1037. return (!value) ? value : String(value).replace(charToEntityRegex, htmlEncodeReplaceFn);
  1038. },
  1039. /**
  1040. * Convert certain characters (&, <, >, ', and ") from their HTML character equivalents.
  1041. * @param {String} value The string to decode
  1042. * @return {String} The decoded text
  1043. * @method
  1044. */
  1045. htmlDecode: function(value) {
  1046. return (!value) ? value : String(value).replace(entityToCharRegex, htmlDecodeReplaceFn);
  1047. },
  1048. /**
  1049. * Adds a set of character entity definitions to the set used by
  1050. * {@link Ext.String#htmlEncode} and {@link Ext.String#htmlDecode}.
  1051. *
  1052. * This object should be keyed by the entity name sequence,
  1053. * with the value being the textual representation of the entity.
  1054. *
  1055. * Ext.String.addCharacterEntities({
  1056. * '&amp;Uuml;':'Ü',
  1057. * '&amp;ccedil;':'ç',
  1058. * '&amp;ntilde;':'ñ',
  1059. * '&amp;egrave;':'è'
  1060. * });
  1061. * var s = Ext.String.htmlEncode("A string with entities: èÜçñ");
  1062. *
  1063. * Note: the values of the character entites defined on this object are expected
  1064. * to be single character values. As such, the actual values represented by the
  1065. * characters are sensitive to the character encoding of the javascript source
  1066. * file when defined in string literal form. Script tasgs referencing server
  1067. * resources with character entities must ensure that the 'charset' attribute
  1068. * of the script node is consistent with the actual character encoding of the
  1069. * server resource.
  1070. *
  1071. * The set of character entities may be reset back to the default state by using
  1072. * the {@link Ext.String#resetCharacterEntities} method
  1073. *
  1074. * @param {Object} entities The set of character entities to add to the current
  1075. * definitions.
  1076. */
  1077. addCharacterEntities: function(newEntities) {
  1078. var charKeys = [],
  1079. entityKeys = [],
  1080. key, echar;
  1081. for (key in newEntities) {
  1082. echar = newEntities[key];
  1083. entityToChar[key] = echar;
  1084. charToEntity[echar] = key;
  1085. charKeys.push(echar);
  1086. entityKeys.push(key);
  1087. }
  1088. charToEntityRegex = new RegExp('(' + charKeys.join('|') + ')', 'g');
  1089. entityToCharRegex = new RegExp('(' + entityKeys.join('|') + '|&#[0-9]{1,5};' + ')', 'g');
  1090. },
  1091. /**
  1092. * Resets the set of character entity definitions used by
  1093. * {@link Ext.String#htmlEncode} and {@link Ext.String#htmlDecode} back to the
  1094. * default state.
  1095. */
  1096. resetCharacterEntities: function() {
  1097. charToEntity = {};
  1098. entityToChar = {};
  1099. // add the default set
  1100. this.addCharacterEntities({
  1101. '&amp;' : '&',
  1102. '&gt;' : '>',
  1103. '&lt;' : '<',
  1104. '&quot;' : '"',
  1105. '&#39;' : "'"
  1106. });
  1107. },
  1108. /**
  1109. * Appends content to the query string of a URL, handling logic for whether to place
  1110. * a question mark or ampersand.
  1111. * @param {String} url The URL to append to.
  1112. * @param {String} string The content to append to the URL.
  1113. * @return {String} The resulting URL
  1114. */
  1115. urlAppend : function(url, string) {
  1116. if (!Ext.isEmpty(string)) {
  1117. return url + (url.indexOf('?') === -1 ? '?' : '&') + string;
  1118. }
  1119. return url;
  1120. },
  1121. /**
  1122. * Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
  1123. * @example
  1124. var s = ' foo bar ';
  1125. alert('-' + s + '-'); //alerts "- foo bar -"
  1126. alert('-' + Ext.String.trim(s) + '-'); //alerts "-foo bar-"
  1127. * @param {String} string The string to escape
  1128. * @return {String} The trimmed string
  1129. */
  1130. trim: function(string) {
  1131. return string.replace(trimRegex, "");
  1132. },
  1133. /**
  1134. * Capitalize the given string
  1135. * @param {String} string
  1136. * @return {String}
  1137. */
  1138. capitalize: function(string) {
  1139. return string.charAt(0).toUpperCase() + string.substr(1);
  1140. },
  1141. /**
  1142. * Uncapitalize the given string
  1143. * @param {String} string
  1144. * @return {String}
  1145. */
  1146. uncapitalize: function(string) {
  1147. return string.charAt(0).toLowerCase() + string.substr(1);
  1148. },
  1149. /**
  1150. * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
  1151. * @param {String} value The string to truncate
  1152. * @param {Number} length The maximum length to allow before truncating
  1153. * @param {Boolean} word True to try to find a common word break
  1154. * @return {String} The converted text
  1155. */
  1156. ellipsis: function(value, len, word) {
  1157. if (value && value.length > len) {
  1158. if (word) {
  1159. var vs = value.substr(0, len - 2),
  1160. index = Math.max(vs.lastIndexOf(' '), vs.lastIndexOf('.'), vs.lastIndexOf('!'), vs.lastIndexOf('?'));
  1161. if (index !== -1 && index >= (len - 15)) {
  1162. return vs.substr(0, index) + "...";
  1163. }
  1164. }
  1165. return value.substr(0, len - 3) + "...";
  1166. }
  1167. return value;
  1168. },
  1169. /**
  1170. * Escapes the passed string for use in a regular expression
  1171. * @param {String} string
  1172. * @return {String}
  1173. */
  1174. escapeRegex: function(string) {
  1175. return string.replace(escapeRegexRe, "\\$1");
  1176. },
  1177. /**
  1178. * Escapes the passed string for ' and \
  1179. * @param {String} string The string to escape
  1180. * @return {String} The escaped string
  1181. */
  1182. escape: function(string) {
  1183. return string.replace(escapeRe, "\\$1");
  1184. },
  1185. /**
  1186. * Utility function that allows you to easily switch a string between two alternating values. The passed value
  1187. * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
  1188. * they are already different, the first value passed in is returned. Note that this method returns the new value
  1189. * but does not change the current string.
  1190. * <pre><code>
  1191. // alternate sort directions
  1192. sort = Ext.String.toggle(sort, 'ASC', 'DESC');
  1193. // instead of conditional logic:
  1194. sort = (sort == 'ASC' ? 'DESC' : 'ASC');
  1195. </code></pre>
  1196. * @param {String} string The current string
  1197. * @param {String} value The value to compare to the current string
  1198. * @param {String} other The new value to use if the string already equals the first value passed in
  1199. * @return {String} The new value
  1200. */
  1201. toggle: function(string, value, other) {
  1202. return string === value ? other : value;
  1203. },
  1204. /**
  1205. * Pads the left side of a string with a specified character. This is especially useful
  1206. * for normalizing number and date strings. Example usage:
  1207. *
  1208. * <pre><code>
  1209. var s = Ext.String.leftPad('123', 5, '0');
  1210. // s now contains the string: '00123'
  1211. </code></pre>
  1212. * @param {String} string The original string
  1213. * @param {Number} size The total length of the output string
  1214. * @param {String} character (optional) The character with which to pad the original string (defaults to empty string " ")
  1215. * @return {String} The padded string
  1216. */
  1217. leftPad: function(string, size, character) {
  1218. var result = String(string);
  1219. character = character || " ";
  1220. while (result.length < size) {
  1221. result = character + result;
  1222. }
  1223. return result;
  1224. },
  1225. /**
  1226. * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
  1227. * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
  1228. * <pre><code>
  1229. var cls = 'my-class', text = 'Some text';
  1230. var s = Ext.String.format('&lt;div class="{0}">{1}&lt;/div>', cls, text);
  1231. // s now contains the string: '&lt;div class="my-class">Some text&lt;/div>'
  1232. </code></pre>
  1233. * @param {String} string The tokenized string to be formatted
  1234. * @param {String} value1 The value to replace token {0}
  1235. * @param {String} value2 Etc...
  1236. * @return {String} The formatted string
  1237. */
  1238. format: function(format) {
  1239. var args = Ext.Array.toArray(arguments, 1);
  1240. return format.replace(formatRe, function(m, i) {
  1241. return args[i];
  1242. });
  1243. },
  1244. /**
  1245. * Returns a string with a specified number of repititions a given string pattern.
  1246. * The pattern be separated by a different string.
  1247. *
  1248. * var s = Ext.String.repeat('---', 4); // = '------------'
  1249. * var t = Ext.String.repeat('--', 3, '/'); // = '--/--/--'
  1250. *
  1251. * @param {String} pattern The pattern to repeat.
  1252. * @param {Number} count The number of times to repeat the pattern (may be 0).
  1253. * @param {String} sep An option string to separate each pattern.
  1254. */
  1255. repeat: function(pattern, count, sep) {
  1256. for (var buf = [], i = count; i--; ) {
  1257. buf.push(pattern);
  1258. }
  1259. return buf.join(sep || '');
  1260. },
  1261. /**
  1262. * Splits a string of space separated words into an array, trimming as needed. If the
  1263. * words are already an array, it is returned.
  1264. *
  1265. * @param {String/Array} words
  1266. */
  1267. splitWords: function (words) {
  1268. if (words && typeof words == 'string') {
  1269. return words.replace(basicTrimRe, '').split(whitespaceRe);
  1270. }
  1271. return words || [];
  1272. }
  1273. };
  1274. }());
  1275. // initialize the default encode / decode entities
  1276. Ext.String.resetCharacterEntities();
  1277. /**
  1278. * Old alias to {@link Ext.String#htmlEncode}
  1279. * @deprecated Use {@link Ext.String#htmlEncode} instead
  1280. * @method
  1281. * @member Ext
  1282. * @inheritdoc Ext.String#htmlEncode
  1283. */
  1284. Ext.htmlEncode = Ext.String.htmlEncode;
  1285. /**
  1286. * Old alias to {@link Ext.String#htmlDecode}
  1287. * @deprecated Use {@link Ext.String#htmlDecode} instead
  1288. * @method
  1289. * @member Ext
  1290. * @inheritdoc Ext.String#htmlDecode
  1291. */
  1292. Ext.htmlDecode = Ext.String.htmlDecode;
  1293. /**
  1294. * Old alias to {@link Ext.String#urlAppend}
  1295. * @deprecated Use {@link Ext.String#urlAppend} instead
  1296. * @method
  1297. * @member Ext
  1298. * @inheritdoc Ext.String#urlAppend
  1299. */
  1300. Ext.urlAppend = Ext.String.urlAppend;
  1301. //@tag foundation,core
  1302. //@require String.js
  1303. //@define Ext.Number
  1304. /**
  1305. * @class Ext.Number
  1306. *
  1307. * A collection of useful static methods to deal with numbers
  1308. * @singleton
  1309. */
  1310. Ext.Number = new function() {
  1311. var me = this,
  1312. isToFixedBroken = (0.9).toFixed() !== '1',
  1313. math = Math;
  1314. Ext.apply(this, {
  1315. /**
  1316. * Checks whether or not the passed number is within a desired range. If the number is already within the
  1317. * range it is returned, otherwise the min or max value is returned depending on which side of the range is
  1318. * exceeded. Note that this method returns the constrained value but does not change the current number.
  1319. * @param {Number} number The number to check
  1320. * @param {Number} min The minimum number in the range
  1321. * @param {Number} max The maximum number in the range
  1322. * @return {Number} The constrained value if outside the range, otherwise the current value
  1323. */
  1324. constrain: function(number, min, max) {
  1325. var x = parseFloat(number);
  1326. // Watch out for NaN in Chrome 18
  1327. // V8bug: http://code.google.com/p/v8/issues/detail?id=2056
  1328. // Operators are faster than Math.min/max. See http://jsperf.com/number-constrain
  1329. // ... and (x < Nan) || (x < undefined) == false
  1330. // ... same for (x > NaN) || (x > undefined)
  1331. // so if min or max are undefined or NaN, we never return them... sadly, this
  1332. // is not true of null (but even Math.max(-1,null)==0 and isNaN(null)==false)
  1333. return (x < min) ? min : ((x > max) ? max : x);
  1334. },
  1335. /**
  1336. * Snaps the passed number between stopping points based upon a passed increment value.
  1337. *
  1338. * The difference between this and {@link #snapInRange} is that {@link #snapInRange} uses the minValue
  1339. * when calculating snap points:
  1340. *
  1341. * r = Ext.Number.snap(56, 2, 55, 65); // Returns 56 - snap points are zero based
  1342. *
  1343. * r = Ext.Number.snapInRange(56, 2, 55, 65); // Returns 57 - snap points are based from minValue
  1344. *
  1345. * @param {Number} value The unsnapped value.
  1346. * @param {Number} increment The increment by which the value must move.
  1347. * @param {Number} minValue The minimum value to which the returned value must be constrained. Overrides the increment.
  1348. * @param {Number} maxValue The maximum value to which the returned value must be constrained. Overrides the increment.
  1349. * @return {Number} The value of the nearest snap target.
  1350. */
  1351. snap : function(value, increment, minValue, maxValue) {
  1352. var m;
  1353. // If no value passed, or minValue was passed and value is less than minValue (anything < undefined is false)
  1354. // Then use the minValue (or zero if the value was undefined)
  1355. if (value === undefined || value < minValue) {
  1356. return minValue || 0;
  1357. }
  1358. if (increment) {
  1359. m = value % increment;
  1360. if (m !== 0) {
  1361. value -= m;
  1362. if (m * 2 >= increment) {
  1363. value += increment;
  1364. } else if (m * 2 < -increment) {
  1365. value -= increment;
  1366. }
  1367. }
  1368. }
  1369. return me.constrain(value, minValue, maxValue);
  1370. },
  1371. /**
  1372. * Snaps the passed number between stopping points based upon a passed increment value.
  1373. *
  1374. * The difference between this and {@link #snap} is that {@link #snap} does not use the minValue
  1375. * when calculating snap points:
  1376. *
  1377. * r = Ext.Number.snap(56, 2, 55, 65); // Returns 56 - snap points are zero based
  1378. *
  1379. * r = Ext.Number.snapInRange(56, 2, 55, 65); // Returns 57 - snap points are based from minValue
  1380. *
  1381. * @param {Number} value The unsnapped value.
  1382. * @param {Number} increment The increment by which the value must move.
  1383. * @param {Number} [minValue=0] The minimum value to which the returned value must be constrained.
  1384. * @param {Number} [maxValue=Infinity] The maximum value to which the returned value must be constrained.
  1385. * @return {Number} The value of the nearest snap target.
  1386. */
  1387. snapInRange : function(value, increment, minValue, maxValue) {
  1388. var tween;
  1389. // default minValue to zero
  1390. minValue = (minValue || 0);
  1391. // If value is undefined, or less than minValue, use minValue
  1392. if (value === undefined || value < minValue) {
  1393. return minValue;
  1394. }
  1395. // Calculate how many snap points from the minValue the passed value is.
  1396. if (increment && (tween = ((value - minValue) % increment))) {
  1397. value -= tween;
  1398. tween *= 2;
  1399. if (tween >= increment) {
  1400. value += increment;
  1401. }
  1402. }
  1403. // If constraining within a maximum, ensure the maximum is on a snap point
  1404. if (maxValue !== undefined) {
  1405. if (value > (maxValue = me.snapInRange(maxValue, increment, minValue))) {
  1406. value = maxValue;
  1407. }
  1408. }
  1409. return value;
  1410. },
  1411. /**
  1412. * Formats a number using fixed-point notation
  1413. * @param {Number} value The number to format
  1414. * @param {Number} precision The number of digits to show after the decimal point
  1415. */
  1416. toFixed: isToFixedBroken ? function(value, precision) {
  1417. precision = precision || 0;
  1418. var pow = math.pow(10, precision);
  1419. return (math.round(value * pow) / pow).toFixed(precision);
  1420. } : function(value, precision) {
  1421. return value.toFixed(precision);
  1422. },
  1423. /**
  1424. * Validate that a value is numeric and convert it to a number if necessary. Returns the specified default value if
  1425. * it is not.
  1426. Ext.Number.from('1.23', 1); // returns 1.23
  1427. Ext.Number.from('abc', 1); // returns 1
  1428. * @param {Object} value
  1429. * @param {Number} defaultValue The value to return if the original value is non-numeric
  1430. * @return {Number} value, if numeric, defaultValue otherwise
  1431. */
  1432. from: function(value, defaultValue) {
  1433. if (isFinite(value)) {
  1434. value = parseFloat(value);
  1435. }
  1436. return !isNaN(value) ? value : defaultValue;
  1437. },
  1438. /**
  1439. * Returns a random integer between the specified range (inclusive)
  1440. * @param {Number} from Lowest value to return.
  1441. * @param {Number} to Highst value to return.
  1442. * @return {Number} A random integer within the specified range.
  1443. */
  1444. randomInt: function (from, to) {
  1445. return math.floor(math.random() * (to - from + 1) + from);
  1446. }
  1447. });
  1448. /**
  1449. * @deprecated 4.0.0 Please use {@link Ext.Number#from} instead.
  1450. * @member Ext
  1451. * @method num
  1452. * @inheritdoc Ext.Number#from
  1453. */
  1454. Ext.num = function() {
  1455. return me.from.apply(this, arguments);
  1456. };
  1457. };
  1458. //@tag foundation,core
  1459. //@require Number.js
  1460. /**
  1461. * @class Ext.Array
  1462. * @singleton
  1463. * @author Jacky Nguyen <jacky@sencha.com>
  1464. * @docauthor Jacky Nguyen <jacky@sencha.com>
  1465. *
  1466. * A set of useful static methods to deal with arrays; provide missing methods for older browsers.
  1467. */
  1468. (function() {
  1469. var arrayPrototype = Array.prototype,
  1470. slice = arrayPrototype.slice,
  1471. supportsSplice = (function () {
  1472. var array = [],
  1473. lengthBefore,
  1474. j = 20;
  1475. if (!array.splice) {
  1476. return false;
  1477. }
  1478. // This detects a bug in IE8 splice method:
  1479. // see http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/6e946d03-e09f-4b22-a4dd-cd5e276bf05a/
  1480. while (j--) {
  1481. array.push("A");
  1482. }
  1483. array.splice(15, 0, "F", "F", "F", "F", "F","F","F","F","F","F","F","F","F","F","F","F","F","F","F","F","F");
  1484. lengthBefore = array.length; //41
  1485. array.splice(13, 0, "XXX"); // add one element
  1486. if (lengthBefore+1 != array.length) {
  1487. return false;
  1488. }
  1489. // end IE8 bug
  1490. return true;
  1491. }()),
  1492. supportsForEach = 'forEach' in arrayPrototype,
  1493. supportsMap = 'map' in arrayPrototype,
  1494. supportsIndexOf = 'indexOf' in arrayPrototype,
  1495. supportsEvery = 'every' in arrayPrototype,
  1496. supportsSome = 'some' in arrayPrototype,
  1497. supportsFilter = 'filter' in arrayPrototype,
  1498. supportsSort = (function() {
  1499. var a = [1,2,3,4,5].sort(function(){ return 0; });
  1500. return a[0] === 1 && a[1] === 2 && a[2] === 3 && a[3] === 4 && a[4] === 5;
  1501. }()),
  1502. supportsSliceOnNodeList = true,
  1503. ExtArray,
  1504. erase,
  1505. replace,
  1506. splice;
  1507. try {
  1508. // IE 6 - 8 will throw an error when using Array.prototype.slice on NodeList
  1509. if (typeof document !== 'undefined') {
  1510. slice.call(document.getElementsByTagName('body'));
  1511. }
  1512. } catch (e) {
  1513. supportsSliceOnNodeList = false;
  1514. }
  1515. function fixArrayIndex (array, index) {
  1516. return (index < 0) ? Math.max(0, array.length + index)
  1517. : Math.min(array.length, index);
  1518. }
  1519. /*
  1520. Does the same work as splice, but with a slightly more convenient signature. The splice
  1521. method has bugs in IE8, so this is the implementation we use on that platform.
  1522. The rippling of items in the array can be tricky. Consider two use cases:
  1523. index=2
  1524. removeCount=2
  1525. /=====\
  1526. +---+---+---+---+---+---+---+---+
  1527. | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
  1528. +---+---+---+---+---+---+---+---+
  1529. / \/ \/ \/ \
  1530. / /\ /\ /\ \
  1531. / / \/ \/ \ +--------------------------+
  1532. / / /\ /\ +--------------------------+ \
  1533. / / / \/ +--------------------------+ \ \
  1534. / / / /+--------------------------+ \ \ \
  1535. / / / / \ \ \ \
  1536. v v v v v v v v
  1537. +---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+
  1538. | 0 | 1 | 4 | 5 | 6 | 7 | | 0 | 1 | a | b | c | 4 | 5 | 6 | 7 |
  1539. +---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+
  1540. A B \=========/
  1541. insert=[a,b,c]
  1542. In case A, it is obvious that copying of [4,5,6,7] must be left-to-right so
  1543. that we don't end up with [0,1,6,7,6,7]. In case B, we have the opposite; we
  1544. must go right-to-left or else we would end up with [0,1,a,b,c,4,4,4,4].
  1545. */
  1546. function replaceSim (array, index, removeCount, insert) {
  1547. var add = insert ? insert.length : 0,
  1548. length = array.length,
  1549. pos = fixArrayIndex(array, index),
  1550. remove,
  1551. tailOldPos,
  1552. tailNewPos,
  1553. tailCount,
  1554. lengthAfterRemove,
  1555. i;
  1556. // we try to use Array.push when we can for efficiency...
  1557. if (pos === length) {
  1558. if (add) {
  1559. array.push.apply(array, insert);
  1560. }
  1561. } else {
  1562. remove = Math.min(removeCount, length - pos);
  1563. tailOldPos = pos + remove;
  1564. tailNewPos = tailOldPos + add - remove;
  1565. tailCount = length - tailOldPos;
  1566. lengthAfterRemove = length - remove;
  1567. if (tailNewPos < tailOldPos) { // case A
  1568. for (i = 0; i < tailCount; ++i) {
  1569. array[tailNewPos+i] = array[tailOldPos+i];
  1570. }
  1571. } else if (tailNewPos > tailOldPos) { // case B
  1572. for (i = tailCount; i--; ) {
  1573. array[tailNewPos+i] = array[tailOldPos+i];
  1574. }
  1575. } // else, add == remove (nothing to do)
  1576. if (add && pos === lengthAfterRemove) {
  1577. array.length = lengthAfterRemove; // truncate array
  1578. array.push.apply(array, insert);
  1579. } else {
  1580. array.length = lengthAfterRemove + add; // reserves space
  1581. for (i = 0; i < add; ++i) {
  1582. array[pos+i] = insert[i];
  1583. }
  1584. }
  1585. }
  1586. return array;
  1587. }
  1588. function replaceNative (array, index, removeCount, insert) {
  1589. if (insert && insert.length) {
  1590. if (index < array.length) {
  1591. array.splice.apply(array, [index, removeCount].concat(insert));
  1592. } else {
  1593. array.push.apply(array, insert);
  1594. }
  1595. } else {
  1596. array.splice(index, removeCount);
  1597. }
  1598. return array;
  1599. }
  1600. function eraseSim (array, index, removeCount) {
  1601. return replaceSim(array, index, removeCount);
  1602. }
  1603. function eraseNative (array, index, removeCount) {
  1604. array.splice(index, removeCount);
  1605. return array;
  1606. }
  1607. function spliceSim (array, index, removeCount) {
  1608. var pos = fixArrayIndex(array, index),
  1609. removed = array.slice(index, fixArrayIndex(array, pos+removeCount));
  1610. if (arguments.length < 4) {
  1611. replaceSim(array, pos, removeCount);
  1612. } else {
  1613. replaceSim(array, pos, removeCount, slice.call(arguments, 3));
  1614. }
  1615. return removed;
  1616. }
  1617. function spliceNative (array) {
  1618. return array.splice.apply(array, slice.call(arguments, 1));
  1619. }
  1620. erase = supportsSplice ? eraseNative : eraseSim;
  1621. replace = supportsSplice ? replaceNative : replaceSim;
  1622. splice = supportsSplice ? spliceNative : spliceSim;
  1623. // NOTE: from here on, use erase, replace or splice (not native methods)...
  1624. ExtArray = Ext.Array = {
  1625. /**
  1626. * Iterates an array or an iterable value and invoke the given callback function for each item.
  1627. *
  1628. * var countries = ['Vietnam', 'Singapore', 'United States', 'Russia'];
  1629. *
  1630. * Ext.Array.each(countries, function(name, index, countriesItSelf) {
  1631. * console.log(name);
  1632. * });
  1633. *
  1634. * var sum = function() {
  1635. * var sum = 0;
  1636. *
  1637. * Ext.Array.each(arguments, function(value) {
  1638. * sum += value;
  1639. * });
  1640. *
  1641. * return sum;
  1642. * };
  1643. *
  1644. * sum(1, 2, 3); // returns 6
  1645. *
  1646. * The iteration can be stopped by returning false in the function callback.
  1647. *
  1648. * Ext.Array.each(countries, function(name, index, countriesItSelf) {
  1649. * if (name === 'Singapore') {
  1650. * return false; // break here
  1651. * }
  1652. * });
  1653. *
  1654. * {@link Ext#each Ext.each} is alias for {@link Ext.Array#each Ext.Array.each}
  1655. *
  1656. * @param {Array/NodeList/Object} iterable The value to be iterated. If this
  1657. * argument is not iterable, the callback function is called once.
  1658. * @param {Function} fn The callback function. If it returns false, the iteration stops and this method returns
  1659. * the current `index`.
  1660. * @param {Object} fn.item The item at the current `index` in the passed `array`
  1661. * @param {Number} fn.index The current `index` within the `array`
  1662. * @param {Array} fn.allItems The `array` itself which was passed as the first argument
  1663. * @param {Boolean} fn.return Return false to stop iteration.
  1664. * @param {Object} scope (Optional) The scope (`this` reference) in which the specified function is executed.
  1665. * @param {Boolean} reverse (Optional) Reverse the iteration order (loop from the end to the beginning)
  1666. * Defaults false
  1667. * @return {Boolean} See description for the `fn` parameter.
  1668. */
  1669. each: function(array, fn, scope, reverse) {
  1670. array = ExtArray.from(array);
  1671. var i,
  1672. ln = array.length;
  1673. if (reverse !== true) {
  1674. for (i = 0; i < ln; i++) {
  1675. if (fn.call(scope || array[i], array[i], i, array) === false) {
  1676. return i;
  1677. }
  1678. }
  1679. }
  1680. else {
  1681. for (i = ln - 1; i > -1; i--) {
  1682. if (fn.call(scope || array[i], array[i], i, array) === false) {
  1683. return i;
  1684. }
  1685. }
  1686. }
  1687. return true;
  1688. },
  1689. /**
  1690. * Iterates an array and invoke the given callback function for each item. Note that this will simply
  1691. * delegate to the native Array.prototype.forEach method if supported. It doesn't support stopping the
  1692. * iteration by returning false in the callback function like {@link Ext.Array#each}. However, performance
  1693. * could be much better in modern browsers comparing with {@link Ext.Array#each}
  1694. *
  1695. * @param {Array} array The array to iterate
  1696. * @param {Function} fn The callback function.
  1697. * @param {Object} fn.item The item at the current `index` in the passed `array`
  1698. * @param {Number} fn.index The current `index` within the `array`
  1699. * @param {Array} fn.allItems The `array` itself which was passed as the first argument
  1700. * @param {Object} scope (Optional) The execution scope (`this`) in which the specified function is executed.
  1701. */
  1702. forEach: supportsForEach ? function(array, fn, scope) {
  1703. return array.forEach(fn, scope);
  1704. } : function(array, fn, scope) {
  1705. var i = 0,
  1706. ln = array.length;
  1707. for (; i < ln; i++) {
  1708. fn.call(scope, array[i], i, array);
  1709. }
  1710. },
  1711. /**
  1712. * Get the index of the provided `item` in the given `array`, a supplement for the
  1713. * missing arrayPrototype.indexOf in Internet Explorer.
  1714. *
  1715. * @param {Array} array The array to check
  1716. * @param {Object} item The item to look for
  1717. * @param {Number} from (Optional) The index at which to begin the search
  1718. * @return {Number} The index of item in the array (or -1 if it is not found)
  1719. */
  1720. indexOf: supportsIndexOf ? function(array, item, from) {
  1721. return array.indexOf(item, from);
  1722. } : function(array, item, from) {
  1723. var i, length = array.length;
  1724. for (i = (from < 0) ? Math.max(0, length + from) : from || 0; i < length; i++) {
  1725. if (array[i] === item) {
  1726. return i;
  1727. }
  1728. }
  1729. return -1;
  1730. },
  1731. /**
  1732. * Checks whether or not the given `array` contains the specified `item`
  1733. *
  1734. * @param {Array} array The array to check
  1735. * @param {Object} item The item to look for
  1736. * @return {Boolean} True if the array contains the item, false otherwise
  1737. */
  1738. contains: supportsIndexOf ? function(array, item) {
  1739. return array.indexOf(item) !== -1;
  1740. } : function(array, item) {
  1741. var i, ln;
  1742. for (i = 0, ln = array.length; i < ln; i++) {
  1743. if (array[i] === item) {
  1744. return true;
  1745. }
  1746. }
  1747. return false;
  1748. },
  1749. /**
  1750. * Converts any iterable (numeric indices and a length property) into a true array.
  1751. *
  1752. * function test() {
  1753. * var args = Ext.Array.toArray(arguments),
  1754. * fromSecondToLastArgs = Ext.Array.toArray(arguments, 1);
  1755. *
  1756. * alert(args.join(' '));
  1757. * alert(fromSecondToLastArgs.join(' '));
  1758. * }
  1759. *
  1760. * test('just', 'testing', 'here'); // alerts 'just testing here';
  1761. * // alerts 'testing here';
  1762. *
  1763. * Ext.Array.toArray(document.getElementsByTagName('div')); // will convert the NodeList into an array
  1764. * Ext.Array.toArray('splitted'); // returns ['s', 'p', 'l', 'i', 't', 't', 'e', 'd']
  1765. * Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l']
  1766. *
  1767. * {@link Ext#toArray Ext.toArray} is alias for {@link Ext.Array#toArray Ext.Array.toArray}
  1768. *
  1769. * @param {Object} iterable the iterable object to be turned into a true Array.
  1770. * @param {Number} start (Optional) a zero-based index that specifies the start of extraction. Defaults to 0
  1771. * @param {Number} end (Optional) a 1-based index that specifies the end of extraction. Defaults to the last
  1772. * index of the iterable value
  1773. * @return {Array} array
  1774. */
  1775. toArray: function(iterable, start, end){
  1776. if (!iterable || !iterable.length) {
  1777. return [];
  1778. }
  1779. if (typeof iterable === 'string') {
  1780. iterable = iterable.split('');
  1781. }
  1782. if (supportsSliceOnNodeList) {
  1783. return slice.call(iterable, start || 0, end || iterable.length);
  1784. }
  1785. var array = [],
  1786. i;
  1787. start = start || 0;
  1788. end = end ? ((end < 0) ? iterable.length + end : end) : iterable.length;
  1789. for (i = start; i < end; i++) {
  1790. array.push(iterable[i]);
  1791. }
  1792. return array;
  1793. },
  1794. /**
  1795. * Plucks the value of a property from each item in the Array. Example:
  1796. *
  1797. * Ext.Array.pluck(Ext.query("p"), "className"); // [el1.className, el2.className, ..., elN.className]
  1798. *
  1799. * @param {Array/NodeList} array The Array of items to pluck the value from.
  1800. * @param {String} propertyName The property name to pluck from each element.
  1801. * @return {Array} The value from each item in the Array.
  1802. */
  1803. pluck: function(array, propertyName) {
  1804. var ret = [],
  1805. i, ln, item;
  1806. for (i = 0, ln = array.length; i < ln; i++) {
  1807. item = array[i];
  1808. ret.push(item[propertyName]);
  1809. }
  1810. return ret;
  1811. },
  1812. /**
  1813. * Creates a new array with the results of calling a provided function on every element in this array.
  1814. *
  1815. * @param {Array} array
  1816. * @param {Function} fn Callback function for each item
  1817. * @param {Object} scope Callback function scope
  1818. * @return {Array} results
  1819. */
  1820. map: supportsMap ? function(array, fn, scope) {
  1821. if (!fn) {
  1822. Ext.Error.raise('Ext.Array.map must have a callback function passed as second argument.');
  1823. }
  1824. return array.map(fn, scope);
  1825. } : function(array, fn, scope) {
  1826. if (!fn) {
  1827. Ext.Error.raise('Ext.Array.map must have a callback function passed as second argument.');
  1828. }
  1829. var results = [],
  1830. i = 0,
  1831. len = array.length;
  1832. for (; i < len; i++) {
  1833. results[i] = fn.call(scope, array[i], i, array);
  1834. }
  1835. return results;
  1836. },
  1837. /**
  1838. * Executes the specified function for each array element until the function returns a falsy value.
  1839. * If such an item is found, the function will return false immediately.
  1840. * Otherwise, it will return true.
  1841. *
  1842. * @param {Array} array
  1843. * @param {Function} fn Callback function for each item
  1844. * @param {Object} scope Callback function scope
  1845. * @return {Boolean} True if no false value is returned by the callback function.
  1846. */
  1847. every: supportsEvery ? function(array, fn, scope) {
  1848. if (!fn) {
  1849. Ext.Error.raise('Ext.Array.every must have a callback function passed as second argument.');
  1850. }
  1851. return array.every(fn, scope);
  1852. } : function(array, fn, scope) {
  1853. if (!fn) {
  1854. Ext.Error.raise('Ext.Array.every must have a callback function passed as second argument.');
  1855. }
  1856. var i = 0,
  1857. ln = array.length;
  1858. for (; i < ln; ++i) {
  1859. if (!fn.call(scope, array[i], i, array)) {
  1860. return false;
  1861. }
  1862. }
  1863. return true;
  1864. },
  1865. /**
  1866. * Executes the specified function for each array element until the function returns a truthy value.
  1867. * If such an item is found, the function will return true immediately. Otherwise, it will return false.
  1868. *
  1869. * @param {Array} array
  1870. * @param {Function} fn Callback function for each item
  1871. * @param {Object} scope Callback function scope
  1872. * @return {Boolean} True if the callback function returns a truthy value.
  1873. */
  1874. some: supportsSome ? function(array, fn, scope) {
  1875. if (!fn) {
  1876. Ext.Error.raise('Ext.Array.some must have a callback function passed as second argument.');
  1877. }
  1878. return array.some(fn, scope);
  1879. } : function(array, fn, scope) {
  1880. if (!fn) {
  1881. Ext.Error.raise('Ext.Array.some must have a callback function passed as second argument.');
  1882. }
  1883. var i = 0,
  1884. ln = array.length;
  1885. for (; i < ln; ++i) {
  1886. if (fn.call(scope, array[i], i, array)) {
  1887. return true;
  1888. }
  1889. }
  1890. return false;
  1891. },
  1892. /**
  1893. * Filter through an array and remove empty item as defined in {@link Ext#isEmpty Ext.isEmpty}
  1894. *
  1895. * See {@link Ext.Array#filter}
  1896. *
  1897. * @param {Array} array
  1898. * @return {Array} results
  1899. */
  1900. clean: function(array) {
  1901. var results = [],
  1902. i = 0,
  1903. ln = array.length,
  1904. item;
  1905. for (; i < ln; i++) {
  1906. item = array[i];
  1907. if (!Ext.isEmpty(item)) {
  1908. results.push(item);
  1909. }
  1910. }
  1911. return results;
  1912. },
  1913. /**
  1914. * Returns a new array with unique items
  1915. *
  1916. * @param {Array} array
  1917. * @return {Array} results
  1918. */
  1919. unique: function(array) {
  1920. var clone = [],
  1921. i = 0,
  1922. ln = array.length,
  1923. item;
  1924. for (; i < ln; i++) {
  1925. item = array[i];
  1926. if (ExtArray.indexOf(clone, item) === -1) {
  1927. clone.push(item);
  1928. }
  1929. }
  1930. return clone;
  1931. },
  1932. /**
  1933. * Creates a new array with all of the elements of this array for which
  1934. * the provided filtering function returns true.
  1935. *
  1936. * @param {Array} array
  1937. * @param {Function} fn Callback function for each item
  1938. * @param {Object} scope Callback function scope
  1939. * @return {Array} results
  1940. */
  1941. filter: supportsFilter ? function(array, fn, scope) {
  1942. if (!fn) {
  1943. Ext.Error.raise('Ext.Array.filter must have a callback function passed as second argument.');
  1944. }
  1945. return array.filter(fn, scope);
  1946. } : function(array, fn, scope) {
  1947. if (!fn) {
  1948. Ext.Error.raise('Ext.Array.filter must have a callback function passed as second argument.');
  1949. }
  1950. var results = [],
  1951. i = 0,
  1952. ln = array.length;
  1953. for (; i < ln; i++) {
  1954. if (fn.call(scope, array[i], i, array)) {
  1955. results.push(array[i]);
  1956. }
  1957. }
  1958. return results;
  1959. },
  1960. /**
  1961. * Converts a value to an array if it's not already an array; returns:
  1962. *
  1963. * - An empty array if given value is `undefined` or `null`
  1964. * - Itself if given value is already an array
  1965. * - An array copy if given value is {@link Ext#isIterable iterable} (arguments, NodeList and alike)
  1966. * - An array with one item which is the given value, otherwise
  1967. *
  1968. * @param {Object} value The value to convert to an array if it's not already is an array
  1969. * @param {Boolean} newReference (Optional) True to clone the given array and return a new reference if necessary,
  1970. * defaults to false
  1971. * @return {Array} array
  1972. */
  1973. from: function(value, newReference) {
  1974. if (value === undefined || value === null) {
  1975. return [];
  1976. }
  1977. if (Ext.isArray(value)) {
  1978. return (newReference) ? slice.call(value) : value;
  1979. }
  1980. var type = typeof value;
  1981. // Both strings and functions will have a length property. In phantomJS, NodeList
  1982. // instances report typeof=='function' but don't have an apply method...
  1983. if (value && value.length !== undefined && type !== 'string' && (type !== 'function' || !value.apply)) {
  1984. return ExtArray.toArray(value);
  1985. }
  1986. return [value];
  1987. },
  1988. /**
  1989. * Removes the specified item from the array if it exists
  1990. *
  1991. * @param {Array} array The array
  1992. * @param {Object} item The item to remove
  1993. * @return {Array} The passed array itself
  1994. */
  1995. remove: function(array, item) {
  1996. var index = ExtArray.indexOf(array, item);
  1997. if (index !== -1) {
  1998. erase(array, index, 1);
  1999. }
  2000. return array;
  2001. },
  2002. /**
  2003. * Push an item into the array only if the array doesn't contain it yet
  2004. *
  2005. * @param {Array} array The array
  2006. * @param {Object} item The item to include
  2007. */
  2008. include: function(array, item) {
  2009. if (!ExtArray.contains(array, item)) {
  2010. array.push(item);
  2011. }
  2012. },
  2013. /**
  2014. * Clone a flat array without referencing the previous one. Note that this is different
  2015. * from Ext.clone since it doesn't handle recursive cloning. It's simply a convenient, easy-to-remember method
  2016. * for Array.prototype.slice.call(array)
  2017. *
  2018. * @param {Array} array The array
  2019. * @return {Array} The clone array
  2020. */
  2021. clone: function(array) {
  2022. return slice.call(array);
  2023. },
  2024. /**
  2025. * Merge multiple arrays into one with unique items.
  2026. *
  2027. * {@link Ext.Array#union} is alias for {@link Ext.Array#merge}
  2028. *
  2029. * @param {Array} array1
  2030. * @param {Array} array2
  2031. * @param {Array} etc
  2032. * @return {Array} merged
  2033. */
  2034. merge: function() {
  2035. var args = slice.call(arguments),
  2036. array = [],
  2037. i, ln;
  2038. for (i = 0, ln = args.length; i < ln; i++) {
  2039. array = array.concat(args[i]);
  2040. }
  2041. return ExtArray.unique(array);
  2042. },
  2043. /**
  2044. * Merge multiple arrays into one with unique items that exist in all of the arrays.
  2045. *
  2046. * @param {Array} array1
  2047. * @param {Array} array2
  2048. * @param {Array} etc
  2049. * @return {Array} intersect
  2050. */
  2051. intersect: function() {
  2052. var intersection = [],
  2053. arrays = slice.call(arguments),
  2054. arraysLength,
  2055. array,
  2056. arrayLength,
  2057. minArray,
  2058. minArrayIndex,
  2059. minArrayCandidate,
  2060. minArrayLength,
  2061. element,
  2062. elementCandidate,
  2063. elementCount,
  2064. i, j, k;
  2065. if (!arrays.length) {
  2066. return intersection;
  2067. }
  2068. // Find the smallest array
  2069. arraysLength = arrays.length;
  2070. for (i = minArrayIndex = 0; i < arraysLength; i++) {
  2071. minArrayCandidate = arrays[i];
  2072. if (!minArray || minArrayCandidate.length < minArray.length) {
  2073. minArray = minArrayCandidate;
  2074. minArrayIndex = i;
  2075. }
  2076. }
  2077. minArray = ExtArray.unique(minArray);
  2078. erase(arrays, minArrayIndex, 1);
  2079. // Use the smallest unique'd array as the anchor loop. If the other array(s) do contain
  2080. // an item in the small array, we're likely to find it before reaching the end
  2081. // of the inner loop and can terminate the search early.
  2082. minArrayLength = minArray.length;
  2083. arraysLength = arrays.length;
  2084. for (i = 0; i < minArrayLength; i++) {
  2085. element = minArray[i];
  2086. elementCount = 0;
  2087. for (j = 0; j < arraysLength; j++) {
  2088. array = arrays[j];
  2089. arrayLength = array.length;
  2090. for (k = 0; k < arrayLength; k++) {
  2091. elementCandidate = array[k];
  2092. if (element === elementCandidate) {
  2093. elementCount++;
  2094. break;
  2095. }
  2096. }
  2097. }
  2098. if (elementCount === arraysLength) {
  2099. intersection.push(element);
  2100. }
  2101. }
  2102. return intersection;
  2103. },
  2104. /**
  2105. * Perform a set difference A-B by subtracting all items in array B from array A.
  2106. *
  2107. * @param {Array} arrayA
  2108. * @param {Array} arrayB
  2109. * @return {Array} difference
  2110. */
  2111. difference: function(arrayA, arrayB) {
  2112. var clone = slice.call(arrayA),
  2113. ln = clone.length,
  2114. i, j, lnB;
  2115. for (i = 0,lnB = arrayB.length; i < lnB; i++) {
  2116. for (j = 0; j < ln; j++) {
  2117. if (clone[j] === arrayB[i]) {
  2118. erase(clone, j, 1);
  2119. j--;
  2120. ln--;
  2121. }
  2122. }
  2123. }
  2124. return clone;
  2125. },
  2126. /**
  2127. * Returns a shallow copy of a part of an array. This is equivalent to the native
  2128. * call "Array.prototype.slice.call(array, begin, end)". This is often used when "array"
  2129. * is "arguments" since the arguments object does not supply a slice method but can
  2130. * be the context object to Array.prototype.slice.
  2131. *
  2132. * @param {Array} array The array (or arguments object).
  2133. * @param {Number} begin The index at which to begin. Negative values are offsets from
  2134. * the end of the array.
  2135. * @param {Number} end The index at which to end. The copied items do not include
  2136. * end. Negative values are offsets from the end of the array. If end is omitted,
  2137. * all items up to the end of the array are copied.
  2138. * @return {Array} The copied piece of the array.
  2139. * @method slice
  2140. */
  2141. // Note: IE6 will return [] on slice.call(x, undefined).
  2142. slice: ([1,2].slice(1, undefined).length ?
  2143. function (array, begin, end) {
  2144. return slice.call(array, begin, end);
  2145. } :
  2146. // at least IE6 uses arguments.length for variadic signature
  2147. function (array, begin, end) {
  2148. // After tested for IE 6, the one below is of the best performance
  2149. // see http://jsperf.com/slice-fix
  2150. if (typeof begin === 'undefined') {
  2151. return slice.call(array);
  2152. }
  2153. if (typeof end === 'undefined') {
  2154. return slice.call(array, begin);
  2155. }
  2156. return slice.call(array, begin, end);
  2157. }
  2158. ),
  2159. /**
  2160. * Sorts the elements of an Array.
  2161. * By default, this method sorts the elements alphabetically and ascending.
  2162. *
  2163. * @param {Array} array The array to sort.
  2164. * @param {Function} sortFn (optional) The comparison function.
  2165. * @return {Array} The sorted array.
  2166. */
  2167. sort: supportsSort ? function(array, sortFn) {
  2168. if (sortFn) {
  2169. return array.sort(sortFn);
  2170. } else {
  2171. return array.sort();
  2172. }
  2173. } : function(array, sortFn) {
  2174. var length = array.length,
  2175. i = 0,
  2176. comparison,
  2177. j, min, tmp;
  2178. for (; i < length; i++) {
  2179. min = i;
  2180. for (j = i + 1; j < length; j++) {
  2181. if (sortFn) {
  2182. comparison = sortFn(array[j], array[min]);
  2183. if (comparison < 0) {
  2184. min = j;
  2185. }
  2186. } else if (array[j] < array[min]) {
  2187. min = j;
  2188. }
  2189. }
  2190. if (min !== i) {
  2191. tmp = array[i];
  2192. array[i] = array[min];
  2193. array[min] = tmp;
  2194. }
  2195. }
  2196. return array;
  2197. },
  2198. /**
  2199. * Recursively flattens into 1-d Array. Injects Arrays inline.
  2200. *
  2201. * @param {Array} array The array to flatten
  2202. * @return {Array} The 1-d array.
  2203. */
  2204. flatten: function(array) {
  2205. var worker = [];
  2206. function rFlatten(a) {
  2207. var i, ln, v;
  2208. for (i = 0, ln = a.length; i < ln; i++) {
  2209. v = a[i];
  2210. if (Ext.isArray(v)) {
  2211. rFlatten(v);
  2212. } else {
  2213. worker.push(v);
  2214. }
  2215. }
  2216. return worker;
  2217. }
  2218. return rFlatten(array);
  2219. },
  2220. /**
  2221. * Returns the minimum value in the Array.
  2222. *
  2223. * @param {Array/NodeList} array The Array from which to select the minimum value.
  2224. * @param {Function} comparisonFn (optional) a function to perform the comparision which determines minimization.
  2225. * If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1
  2226. * @return {Object} minValue The minimum value
  2227. */
  2228. min: function(array, comparisonFn) {
  2229. var min = array[0],
  2230. i, ln, item;
  2231. for (i = 0, ln = array.length; i < ln; i++) {
  2232. item = array[i];
  2233. if (comparisonFn) {
  2234. if (comparisonFn(min, item) === 1) {
  2235. min = item;
  2236. }
  2237. }
  2238. else {
  2239. if (item < min) {
  2240. min = item;
  2241. }
  2242. }
  2243. }
  2244. return min;
  2245. },
  2246. /**
  2247. * Returns the maximum value in the Array.
  2248. *
  2249. * @param {Array/NodeList} array The Array from which to select the maximum value.
  2250. * @param {Function} comparisonFn (optional) a function to perform the comparision which determines maximization.
  2251. * If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1
  2252. * @return {Object} maxValue The maximum value
  2253. */
  2254. max: function(array, comparisonFn) {
  2255. var max = array[0],
  2256. i, ln, item;
  2257. for (i = 0, ln = array.length; i < ln; i++) {
  2258. item = array[i];
  2259. if (comparisonFn) {
  2260. if (comparisonFn(max, item) === -1) {
  2261. max = item;
  2262. }
  2263. }
  2264. else {
  2265. if (item > max) {
  2266. max = item;
  2267. }
  2268. }
  2269. }
  2270. return max;
  2271. },
  2272. /**
  2273. * Calculates the mean of all items in the array.
  2274. *
  2275. * @param {Array} array The Array to calculate the mean value of.
  2276. * @return {Number} The mean.
  2277. */
  2278. mean: function(array) {
  2279. return array.length > 0 ? ExtArray.sum(array) / array.length : undefined;
  2280. },
  2281. /**
  2282. * Calculates the sum of all items in the given array.
  2283. *
  2284. * @param {Array} array The Array to calculate the sum value of.
  2285. * @return {Number} The sum.
  2286. */
  2287. sum: function(array) {
  2288. var sum = 0,
  2289. i, ln, item;
  2290. for (i = 0,ln = array.length; i < ln; i++) {
  2291. item = array[i];
  2292. sum += item;
  2293. }
  2294. return sum;
  2295. },
  2296. /**
  2297. * Creates a map (object) keyed by the elements of the given array. The values in
  2298. * the map are the index+1 of the array element. For example:
  2299. *
  2300. * var map = Ext.Array.toMap(['a','b','c']);
  2301. *
  2302. * // map = { a: 1, b: 2, c: 3 };
  2303. *
  2304. * Or a key property can be specified:
  2305. *
  2306. * var map = Ext.Array.toMap([
  2307. * { name: 'a' },
  2308. * { name: 'b' },
  2309. * { name: 'c' }
  2310. * ], 'name');
  2311. *
  2312. * // map = { a: 1, b: 2, c: 3 };
  2313. *
  2314. * Lastly, a key extractor can be provided:
  2315. *
  2316. * var map = Ext.Array.toMap([
  2317. * { name: 'a' },
  2318. * { name: 'b' },
  2319. * { name: 'c' }
  2320. * ], function (obj) { return obj.name.toUpperCase(); });
  2321. *
  2322. * // map = { A: 1, B: 2, C: 3 };
  2323. */
  2324. toMap: function(array, getKey, scope) {
  2325. var map = {},
  2326. i = array.length;
  2327. if (!getKey) {
  2328. while (i--) {
  2329. map[array[i]] = i+1;
  2330. }
  2331. } else if (typeof getKey == 'string') {
  2332. while (i--) {
  2333. map[array[i][getKey]] = i+1;
  2334. }
  2335. } else {
  2336. while (i--) {
  2337. map[getKey.call(scope, array[i])] = i+1;
  2338. }
  2339. }
  2340. return map;
  2341. },
  2342. _replaceSim: replaceSim, // for unit testing
  2343. _spliceSim: spliceSim,
  2344. /**
  2345. * Removes items from an array. This is functionally equivalent to the splice method
  2346. * of Array, but works around bugs in IE8's splice method and does not copy the
  2347. * removed elements in order to return them (because very often they are ignored).
  2348. *
  2349. * @param {Array} array The Array on which to replace.
  2350. * @param {Number} index The index in the array at which to operate.
  2351. * @param {Number} removeCount The number of items to remove at index.
  2352. * @return {Array} The array passed.
  2353. * @method
  2354. */
  2355. erase: erase,
  2356. /**
  2357. * Inserts items in to an array.
  2358. *
  2359. * @param {Array} array The Array in which to insert.
  2360. * @param {Number} index The index in the array at which to operate.
  2361. * @param {Array} items The array of items to insert at index.
  2362. * @return {Array} The array passed.
  2363. */
  2364. insert: function (array, index, items) {
  2365. return replace(array, index, 0, items);
  2366. },
  2367. /**
  2368. * Replaces items in an array. This is functionally equivalent to the splice method
  2369. * of Array, but works around bugs in IE8's splice method and is often more convenient
  2370. * to call because it accepts an array of items to insert rather than use a variadic
  2371. * argument list.
  2372. *
  2373. * @param {Array} array The Array on which to replace.
  2374. * @param {Number} index The index in the array at which to operate.
  2375. * @param {Number} removeCount The number of items to remove at index (can be 0).
  2376. * @param {Array} insert (optional) An array of items to insert at index.
  2377. * @return {Array} The array passed.
  2378. * @method
  2379. */
  2380. replace: replace,
  2381. /**
  2382. * Replaces items in an array. This is equivalent to the splice method of Array, but
  2383. * works around bugs in IE8's splice method. The signature is exactly the same as the
  2384. * splice method except that the array is the first argument. All arguments following
  2385. * removeCount are inserted in the array at index.
  2386. *
  2387. * @param {Array} array The Array on which to replace.
  2388. * @param {Number} index The index in the array at which to operate.
  2389. * @param {Number} removeCount The number of items to remove at index (can be 0).
  2390. * @param {Object...} elements The elements to add to the array. If you don't specify
  2391. * any elements, splice simply removes elements from the array.
  2392. * @return {Array} An array containing the removed items.
  2393. * @method
  2394. */
  2395. splice: splice,
  2396. /**
  2397. * Pushes new items onto the end of an Array.
  2398. *
  2399. * Passed parameters may be single items, or arrays of items. If an Array is found in the argument list, all its
  2400. * elements are pushed into the end of the target Array.
  2401. *
  2402. * @param {Array} target The Array onto which to push new items
  2403. * @param {Object...} elements The elements to add to the array. Each parameter may
  2404. * be an Array, in which case all the elements of that Array will be pushed into the end of the
  2405. * destination Array.
  2406. * @return {Array} An array containing all the new items push onto the end.
  2407. *
  2408. */
  2409. push: function(array) {
  2410. var len = arguments.length,
  2411. i = 1,
  2412. newItem;
  2413. if (array === undefined) {
  2414. array = [];
  2415. } else if (!Ext.isArray(array)) {
  2416. array = [array];
  2417. }
  2418. for (; i < len; i++) {
  2419. newItem = arguments[i];
  2420. Array.prototype.push[Ext.isArray(newItem) ? 'apply' : 'call'](array, newItem);
  2421. }
  2422. return array;
  2423. }
  2424. };
  2425. /**
  2426. * @method
  2427. * @member Ext
  2428. * @inheritdoc Ext.Array#each
  2429. */
  2430. Ext.each = ExtArray.each;
  2431. /**
  2432. * @method
  2433. * @member Ext.Array
  2434. * @inheritdoc Ext.Array#merge
  2435. */
  2436. ExtArray.union = ExtArray.merge;
  2437. /**
  2438. * Old alias to {@link Ext.Array#min}
  2439. * @deprecated 4.0.0 Use {@link Ext.Array#min} instead
  2440. * @method
  2441. * @member Ext
  2442. * @inheritdoc Ext.Array#min
  2443. */
  2444. Ext.min = ExtArray.min;
  2445. /**
  2446. * Old alias to {@link Ext.Array#max}
  2447. * @deprecated 4.0.0 Use {@link Ext.Array#max} instead
  2448. * @method
  2449. * @member Ext
  2450. * @inheritdoc Ext.Array#max
  2451. */
  2452. Ext.max = ExtArray.max;
  2453. /**
  2454. * Old alias to {@link Ext.Array#sum}
  2455. * @deprecated 4.0.0 Use {@link Ext.Array#sum} instead
  2456. * @method
  2457. * @member Ext
  2458. * @inheritdoc Ext.Array#sum
  2459. */
  2460. Ext.sum = ExtArray.sum;
  2461. /**
  2462. * Old alias to {@link Ext.Array#mean}
  2463. * @deprecated 4.0.0 Use {@link Ext.Array#mean} instead
  2464. * @method
  2465. * @member Ext
  2466. * @inheritdoc Ext.Array#mean
  2467. */
  2468. Ext.mean = ExtArray.mean;
  2469. /**
  2470. * Old alias to {@link Ext.Array#flatten}
  2471. * @deprecated 4.0.0 Use {@link Ext.Array#flatten} instead
  2472. * @method
  2473. * @member Ext
  2474. * @inheritdoc Ext.Array#flatten
  2475. */
  2476. Ext.flatten = ExtArray.flatten;
  2477. /**
  2478. * Old alias to {@link Ext.Array#clean}
  2479. * @deprecated 4.0.0 Use {@link Ext.Array#clean} instead
  2480. * @method
  2481. * @member Ext
  2482. * @inheritdoc Ext.Array#clean
  2483. */
  2484. Ext.clean = ExtArray.clean;
  2485. /**
  2486. * Old alias to {@link Ext.Array#unique}
  2487. * @deprecated 4.0.0 Use {@link Ext.Array#unique} instead
  2488. * @method
  2489. * @member Ext
  2490. * @inheritdoc Ext.Array#unique
  2491. */
  2492. Ext.unique = ExtArray.unique;
  2493. /**
  2494. * Old alias to {@link Ext.Array#pluck Ext.Array.pluck}
  2495. * @deprecated 4.0.0 Use {@link Ext.Array#pluck Ext.Array.pluck} instead
  2496. * @method
  2497. * @member Ext
  2498. * @inheritdoc Ext.Array#pluck
  2499. */
  2500. Ext.pluck = ExtArray.pluck;
  2501. /**
  2502. * @method
  2503. * @member Ext
  2504. * @inheritdoc Ext.Array#toArray
  2505. */
  2506. Ext.toArray = function() {
  2507. return ExtArray.toArray.apply(ExtArray, arguments);
  2508. };
  2509. }());
  2510. //@tag foundation,core
  2511. //@require Array.js
  2512. /**
  2513. * @class Ext.Function
  2514. *
  2515. * A collection of useful static methods to deal with function callbacks
  2516. * @singleton
  2517. * @alternateClassName Ext.util.Functions
  2518. */
  2519. Ext.Function = {
  2520. /**
  2521. * A very commonly used method throughout the framework. It acts as a wrapper around another method
  2522. * which originally accepts 2 arguments for `name` and `value`.
  2523. * The wrapped function then allows "flexible" value setting of either:
  2524. *
  2525. * - `name` and `value` as 2 arguments
  2526. * - one single object argument with multiple key - value pairs
  2527. *
  2528. * For example:
  2529. *
  2530. * var setValue = Ext.Function.flexSetter(function(name, value) {
  2531. * this[name] = value;
  2532. * });
  2533. *
  2534. * // Afterwards
  2535. * // Setting a single name - value
  2536. * setValue('name1', 'value1');
  2537. *
  2538. * // Settings multiple name - value pairs
  2539. * setValue({
  2540. * name1: 'value1',
  2541. * name2: 'value2',
  2542. * name3: 'value3'
  2543. * });
  2544. *
  2545. * @param {Function} setter
  2546. * @returns {Function} flexSetter
  2547. */
  2548. flexSetter: function(fn) {
  2549. return function(a, b) {
  2550. var k, i;
  2551. if (a === null) {
  2552. return this;
  2553. }
  2554. if (typeof a !== 'string') {
  2555. for (k in a) {
  2556. if (a.hasOwnProperty(k)) {
  2557. fn.call(this, k, a[k]);
  2558. }
  2559. }
  2560. if (Ext.enumerables) {
  2561. for (i = Ext.enumerables.length; i--;) {
  2562. k = Ext.enumerables[i];
  2563. if (a.hasOwnProperty(k)) {
  2564. fn.call(this, k, a[k]);
  2565. }
  2566. }
  2567. }
  2568. } else {
  2569. fn.call(this, a, b);
  2570. }
  2571. return this;
  2572. };
  2573. },
  2574. /**
  2575. * Create a new function from the provided `fn`, change `this` to the provided scope, optionally
  2576. * overrides arguments for the call. (Defaults to the arguments passed by the caller)
  2577. *
  2578. * {@link Ext#bind Ext.bind} is alias for {@link Ext.Function#bind Ext.Function.bind}
  2579. *
  2580. * @param {Function} fn The function to delegate.
  2581. * @param {Object} scope (optional) The scope (`this` reference) in which the function is executed.
  2582. * **If omitted, defaults to the default global environment object (usually the browser window).**
  2583. * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
  2584. * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
  2585. * if a number the args are inserted at the specified position
  2586. * @return {Function} The new function
  2587. */
  2588. bind: function(fn, scope, args, appendArgs) {
  2589. if (arguments.length === 2) {
  2590. return function() {
  2591. return fn.apply(scope, arguments);
  2592. };
  2593. }
  2594. var method = fn,
  2595. slice = Array.prototype.slice;
  2596. return function() {
  2597. var callArgs = args || arguments;
  2598. if (appendArgs === true) {
  2599. callArgs = slice.call(arguments, 0);
  2600. callArgs = callArgs.concat(args);
  2601. }
  2602. else if (typeof appendArgs == 'number') {
  2603. callArgs = slice.call(arguments, 0); // copy arguments first
  2604. Ext.Array.insert(callArgs, appendArgs, args);
  2605. }
  2606. return method.apply(scope || Ext.global, callArgs);
  2607. };
  2608. },
  2609. /**
  2610. * Create a new function from the provided `fn`, the arguments of which are pre-set to `args`.
  2611. * New arguments passed to the newly created callback when it's invoked are appended after the pre-set ones.
  2612. * This is especially useful when creating callbacks.
  2613. *
  2614. * For example:
  2615. *
  2616. * var originalFunction = function(){
  2617. * alert(Ext.Array.from(arguments).join(' '));
  2618. * };
  2619. *
  2620. * var callback = Ext.Function.pass(originalFunction, ['Hello', 'World']);
  2621. *
  2622. * callback(); // alerts 'Hello World'
  2623. * callback('by Me'); // alerts 'Hello World by Me'
  2624. *
  2625. * {@link Ext#pass Ext.pass} is alias for {@link Ext.Function#pass Ext.Function.pass}
  2626. *
  2627. * @param {Function} fn The original function
  2628. * @param {Array} args The arguments to pass to new callback
  2629. * @param {Object} scope (optional) The scope (`this` reference) in which the function is executed.
  2630. * @return {Function} The new callback function
  2631. */
  2632. pass: function(fn, args, scope) {
  2633. if (!Ext.isArray(args)) {
  2634. if (Ext.isIterable(args)) {
  2635. args = Ext.Array.clone(args);
  2636. } else {
  2637. args = args !== undefined ? [args] : [];
  2638. }
  2639. }
  2640. return function() {
  2641. var fnArgs = [].concat(args);
  2642. fnArgs.push.apply(fnArgs, arguments);
  2643. return fn.apply(scope || this, fnArgs);
  2644. };
  2645. },
  2646. /**
  2647. * Create an alias to the provided method property with name `methodName` of `object`.
  2648. * Note that the execution scope will still be bound to the provided `object` itself.
  2649. *
  2650. * @param {Object/Function} object
  2651. * @param {String} methodName
  2652. * @return {Function} aliasFn
  2653. */
  2654. alias: function(object, methodName) {
  2655. return function() {
  2656. return object[methodName].apply(object, arguments);
  2657. };
  2658. },
  2659. /**
  2660. * Create a "clone" of the provided method. The returned method will call the given
  2661. * method passing along all arguments and the "this" pointer and return its result.
  2662. *
  2663. * @param {Function} method
  2664. * @return {Function} cloneFn
  2665. */
  2666. clone: function(method) {
  2667. return function() {
  2668. return method.apply(this, arguments);
  2669. };
  2670. },
  2671. /**
  2672. * Creates an interceptor function. The passed function is called before the original one. If it returns false,
  2673. * the original one is not called. The resulting function returns the results of the original function.
  2674. * The passed function is called with the parameters of the original function. Example usage:
  2675. *
  2676. * var sayHi = function(name){
  2677. * alert('Hi, ' + name);
  2678. * }
  2679. *
  2680. * sayHi('Fred'); // alerts "Hi, Fred"
  2681. *
  2682. * // create a new function that validates input without
  2683. * // directly modifying the original function:
  2684. * var sayHiToFriend = Ext.Function.createInterceptor(sayHi, function(name){
  2685. * return name == 'Brian';
  2686. * });
  2687. *
  2688. * sayHiToFriend('Fred'); // no alert
  2689. * sayHiToFriend('Brian'); // alerts "Hi, Brian"
  2690. *
  2691. * @param {Function} origFn The original function.
  2692. * @param {Function} newFn The function to call before the original
  2693. * @param {Object} scope (optional) The scope (`this` reference) in which the passed function is executed.
  2694. * **If omitted, defaults to the scope in which the original function is called or the browser window.**
  2695. * @param {Object} returnValue (optional) The value to return if the passed function return false (defaults to null).
  2696. * @return {Function} The new function
  2697. */
  2698. createInterceptor: function(origFn, newFn, scope, returnValue) {
  2699. var method = origFn;
  2700. if (!Ext.isFunction(newFn)) {
  2701. return origFn;
  2702. }
  2703. else {
  2704. return function() {
  2705. var me = this,
  2706. args = arguments;
  2707. newFn.target = me;
  2708. newFn.method = origFn;
  2709. return (newFn.apply(scope || me || Ext.global, args) !== false) ? origFn.apply(me || Ext.global, args) : returnValue || null;
  2710. };
  2711. }
  2712. },
  2713. /**
  2714. * Creates a delegate (callback) which, when called, executes after a specific delay.
  2715. *
  2716. * @param {Function} fn The function which will be called on a delay when the returned function is called.
  2717. * Optionally, a replacement (or additional) argument list may be specified.
  2718. * @param {Number} delay The number of milliseconds to defer execution by whenever called.
  2719. * @param {Object} scope (optional) The scope (`this` reference) used by the function at execution time.
  2720. * @param {Array} args (optional) Override arguments for the call. (Defaults to the arguments passed by the caller)
  2721. * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
  2722. * if a number the args are inserted at the specified position.
  2723. * @return {Function} A function which, when called, executes the original function after the specified delay.
  2724. */
  2725. createDelayed: function(fn, delay, scope, args, appendArgs) {
  2726. if (scope || args) {
  2727. fn = Ext.Function.bind(fn, scope, args, appendArgs);
  2728. }
  2729. return function() {
  2730. var me = this,
  2731. args = Array.prototype.slice.call(arguments);
  2732. setTimeout(function() {
  2733. fn.apply(me, args);
  2734. }, delay);
  2735. };
  2736. },
  2737. /**
  2738. * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
  2739. *
  2740. * var sayHi = function(name){
  2741. * alert('Hi, ' + name);
  2742. * }
  2743. *
  2744. * // executes immediately:
  2745. * sayHi('Fred');
  2746. *
  2747. * // executes after 2 seconds:
  2748. * Ext.Function.defer(sayHi, 2000, this, ['Fred']);
  2749. *
  2750. * // this syntax is sometimes useful for deferring
  2751. * // execution of an anonymous function:
  2752. * Ext.Function.defer(function(){
  2753. * alert('Anonymous');
  2754. * }, 100);
  2755. *
  2756. * {@link Ext#defer Ext.defer} is alias for {@link Ext.Function#defer Ext.Function.defer}
  2757. *
  2758. * @param {Function} fn The function to defer.
  2759. * @param {Number} millis The number of milliseconds for the setTimeout call
  2760. * (if less than or equal to 0 the function is executed immediately)
  2761. * @param {Object} scope (optional) The scope (`this` reference) in which the function is executed.
  2762. * **If omitted, defaults to the browser window.**
  2763. * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
  2764. * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
  2765. * if a number the args are inserted at the specified position
  2766. * @return {Number} The timeout id that can be used with clearTimeout
  2767. */
  2768. defer: function(fn, millis, scope, args, appendArgs) {
  2769. fn = Ext.Function.bind(fn, scope, args, appendArgs);
  2770. if (millis > 0) {
  2771. return setTimeout(Ext.supports.TimeoutActualLateness ? function () {
  2772. fn();
  2773. } : fn, millis);
  2774. }
  2775. fn();
  2776. return 0;
  2777. },
  2778. /**
  2779. * Create a combined function call sequence of the original function + the passed function.
  2780. * The resulting function returns the results of the original function.
  2781. * The passed function is called with the parameters of the original function. Example usage:
  2782. *
  2783. * var sayHi = function(name){
  2784. * alert('Hi, ' + name);
  2785. * }
  2786. *
  2787. * sayHi('Fred'); // alerts "Hi, Fred"
  2788. *
  2789. * var sayGoodbye = Ext.Function.createSequence(sayHi, function(name){
  2790. * alert('Bye, ' + name);
  2791. * });
  2792. *
  2793. * sayGoodbye('Fred'); // both alerts show
  2794. *
  2795. * @param {Function} originalFn The original function.
  2796. * @param {Function} newFn The function to sequence
  2797. * @param {Object} scope (optional) The scope (`this` reference) in which the passed function is executed.
  2798. * If omitted, defaults to the scope in which the original function is called or the default global environment object (usually the browser window).
  2799. * @return {Function} The new function
  2800. */
  2801. createSequence: function(originalFn, newFn, scope) {
  2802. if (!newFn) {
  2803. return originalFn;
  2804. }
  2805. else {
  2806. return function() {
  2807. var result = originalFn.apply(this, arguments);
  2808. newFn.apply(scope || this, arguments);
  2809. return result;
  2810. };
  2811. }
  2812. },
  2813. /**
  2814. * Creates a delegate function, optionally with a bound scope which, when called, buffers
  2815. * the execution of the passed function for the configured number of milliseconds.
  2816. * If called again within that period, the impending invocation will be canceled, and the
  2817. * timeout period will begin again.
  2818. *
  2819. * @param {Function} fn The function to invoke on a buffered timer.
  2820. * @param {Number} buffer The number of milliseconds by which to buffer the invocation of the
  2821. * function.
  2822. * @param {Object} scope (optional) The scope (`this` reference) in which
  2823. * the passed function is executed. If omitted, defaults to the scope specified by the caller.
  2824. * @param {Array} args (optional) Override arguments for the call. Defaults to the arguments
  2825. * passed by the caller.
  2826. * @return {Function} A function which invokes the passed function after buffering for the specified time.
  2827. */
  2828. createBuffered: function(fn, buffer, scope, args) {
  2829. var timerId;
  2830. return function() {
  2831. var callArgs = args || Array.prototype.slice.call(arguments, 0),
  2832. me = scope || this;
  2833. if (timerId) {
  2834. clearTimeout(timerId);
  2835. }
  2836. timerId = setTimeout(function(){
  2837. fn.apply(me, callArgs);
  2838. }, buffer);
  2839. };
  2840. },
  2841. /**
  2842. * Creates a throttled version of the passed function which, when called repeatedly and
  2843. * rapidly, invokes the passed function only after a certain interval has elapsed since the
  2844. * previous invocation.
  2845. *
  2846. * This is useful for wrapping functions which may be called repeatedly, such as
  2847. * a handler of a mouse move event when the processing is expensive.
  2848. *
  2849. * @param {Function} fn The function to execute at a regular time interval.
  2850. * @param {Number} interval The interval **in milliseconds** on which the passed function is executed.
  2851. * @param {Object} scope (optional) The scope (`this` reference) in which
  2852. * the passed function is executed. If omitted, defaults to the scope specified by the caller.
  2853. * @returns {Function} A function which invokes the passed function at the specified interval.
  2854. */
  2855. createThrottled: function(fn, interval, scope) {
  2856. var lastCallTime, elapsed, lastArgs, timer, execute = function() {
  2857. fn.apply(scope || this, lastArgs);
  2858. lastCallTime = new Date().getTime();
  2859. };
  2860. return function() {
  2861. elapsed = new Date().getTime() - lastCallTime;
  2862. lastArgs = arguments;
  2863. clearTimeout(timer);
  2864. if (!lastCallTime || (elapsed >= interval)) {
  2865. execute();
  2866. } else {
  2867. timer = setTimeout(execute, interval - elapsed);
  2868. }
  2869. };
  2870. },
  2871. /**
  2872. * Adds behavior to an existing method that is executed before the
  2873. * original behavior of the function. For example:
  2874. *
  2875. * var soup = {
  2876. * contents: [],
  2877. * add: function(ingredient) {
  2878. * this.contents.push(ingredient);
  2879. * }
  2880. * };
  2881. * Ext.Function.interceptBefore(soup, "add", function(ingredient){
  2882. * if (!this.contents.length && ingredient !== "water") {
  2883. * // Always add water to start with
  2884. * this.contents.push("water");
  2885. * }
  2886. * });
  2887. * soup.add("onions");
  2888. * soup.add("salt");
  2889. * soup.contents; // will contain: water, onions, salt
  2890. *
  2891. * @param {Object} object The target object
  2892. * @param {String} methodName Name of the method to override
  2893. * @param {Function} fn Function with the new behavior. It will
  2894. * be called with the same arguments as the original method. The
  2895. * return value of this function will be the return value of the
  2896. * new method.
  2897. * @param {Object} [scope] The scope to execute the interceptor function. Defaults to the object.
  2898. * @return {Function} The new function just created.
  2899. */
  2900. interceptBefore: function(object, methodName, fn, scope) {
  2901. var method = object[methodName] || Ext.emptyFn;
  2902. return (object[methodName] = function() {
  2903. var ret = fn.apply(scope || this, arguments);
  2904. method.apply(this, arguments);
  2905. return ret;
  2906. });
  2907. },
  2908. /**
  2909. * Adds behavior to an existing method that is executed after the
  2910. * original behavior of the function. For example:
  2911. *
  2912. * var soup = {
  2913. * contents: [],
  2914. * add: function(ingredient) {
  2915. * this.contents.push(ingredient);
  2916. * }
  2917. * };
  2918. * Ext.Function.interceptAfter(soup, "add", function(ingredient){
  2919. * // Always add a bit of extra salt
  2920. * this.contents.push("salt");
  2921. * });
  2922. * soup.add("water");
  2923. * soup.add("onions");
  2924. * soup.contents; // will contain: water, salt, onions, salt
  2925. *
  2926. * @param {Object} object The target object
  2927. * @param {String} methodName Name of the method to override
  2928. * @param {Function} fn Function with the new behavior. It will
  2929. * be called with the same arguments as the original method. The
  2930. * return value of this function will be the return value of the
  2931. * new method.
  2932. * @param {Object} [scope] The scope to execute the interceptor function. Defaults to the object.
  2933. * @return {Function} The new function just created.
  2934. */
  2935. interceptAfter: function(object, methodName, fn, scope) {
  2936. var method = object[methodName] || Ext.emptyFn;
  2937. return (object[methodName] = function() {
  2938. method.apply(this, arguments);
  2939. return fn.apply(scope || this, arguments);
  2940. });
  2941. }
  2942. };
  2943. /**
  2944. * @method
  2945. * @member Ext
  2946. * @inheritdoc Ext.Function#defer
  2947. */
  2948. Ext.defer = Ext.Function.alias(Ext.Function, 'defer');
  2949. /**
  2950. * @method
  2951. * @member Ext
  2952. * @inheritdoc Ext.Function#pass
  2953. */
  2954. Ext.pass = Ext.Function.alias(Ext.Function, 'pass');
  2955. /**
  2956. * @method
  2957. * @member Ext
  2958. * @inheritdoc Ext.Function#bind
  2959. */
  2960. Ext.bind = Ext.Function.alias(Ext.Function, 'bind');
  2961. //@tag foundation,core
  2962. //@require Function.js
  2963. /**
  2964. * @author Jacky Nguyen <jacky@sencha.com>
  2965. * @docauthor Jacky Nguyen <jacky@sencha.com>
  2966. * @class Ext.Object
  2967. *
  2968. * A collection of useful static methods to deal with objects.
  2969. *
  2970. * @singleton
  2971. */
  2972. (function() {
  2973. // The "constructor" for chain:
  2974. var TemplateClass = function(){},
  2975. ExtObject = Ext.Object = {
  2976. /**
  2977. * Returns a new object with the given object as the prototype chain.
  2978. * @param {Object} object The prototype chain for the new object.
  2979. */
  2980. chain: function (object) {
  2981. TemplateClass.prototype = object;
  2982. var result = new TemplateClass();
  2983. TemplateClass.prototype = null;
  2984. return result;
  2985. },
  2986. /**
  2987. * Converts a `name` - `value` pair to an array of objects with support for nested structures. Useful to construct
  2988. * query strings. For example:
  2989. *
  2990. * var objects = Ext.Object.toQueryObjects('hobbies', ['reading', 'cooking', 'swimming']);
  2991. *
  2992. * // objects then equals:
  2993. * [
  2994. * { name: 'hobbies', value: 'reading' },
  2995. * { name: 'hobbies', value: 'cooking' },
  2996. * { name: 'hobbies', value: 'swimming' },
  2997. * ];
  2998. *
  2999. * var objects = Ext.Object.toQueryObjects('dateOfBirth', {
  3000. * day: 3,
  3001. * month: 8,
  3002. * year: 1987,
  3003. * extra: {
  3004. * hour: 4
  3005. * minute: 30
  3006. * }
  3007. * }, true); // Recursive
  3008. *
  3009. * // objects then equals:
  3010. * [
  3011. * { name: 'dateOfBirth[day]', value: 3 },
  3012. * { name: 'dateOfBirth[month]', value: 8 },
  3013. * { name: 'dateOfBirth[year]', value: 1987 },
  3014. * { name: 'dateOfBirth[extra][hour]', value: 4 },
  3015. * { name: 'dateOfBirth[extra][minute]', value: 30 },
  3016. * ];
  3017. *
  3018. * @param {String} name
  3019. * @param {Object/Array} value
  3020. * @param {Boolean} [recursive=false] True to traverse object recursively
  3021. * @return {Array}
  3022. */
  3023. toQueryObjects: function(name, value, recursive) {
  3024. var self = ExtObject.toQueryObjects,
  3025. objects = [],
  3026. i, ln;
  3027. if (Ext.isArray(value)) {
  3028. for (i = 0, ln = value.length; i < ln; i++) {
  3029. if (recursive) {
  3030. objects = objects.concat(self(name + '[' + i + ']', value[i], true));
  3031. }
  3032. else {
  3033. objects.push({
  3034. name: name,
  3035. value: value[i]
  3036. });
  3037. }
  3038. }
  3039. }
  3040. else if (Ext.isObject(value)) {
  3041. for (i in value) {
  3042. if (value.hasOwnProperty(i)) {
  3043. if (recursive) {
  3044. objects = objects.concat(self(name + '[' + i + ']', value[i], true));
  3045. }
  3046. else {
  3047. objects.push({
  3048. name: name,
  3049. value: value[i]
  3050. });
  3051. }
  3052. }
  3053. }
  3054. }
  3055. else {
  3056. objects.push({
  3057. name: name,
  3058. value: value
  3059. });
  3060. }
  3061. return objects;
  3062. },
  3063. /**
  3064. * Takes an object and converts it to an encoded query string.
  3065. *
  3066. * Non-recursive:
  3067. *
  3068. * Ext.Object.toQueryString({foo: 1, bar: 2}); // returns "foo=1&bar=2"
  3069. * Ext.Object.toQueryString({foo: null, bar: 2}); // returns "foo=&bar=2"
  3070. * Ext.Object.toQueryString({'some price': '$300'}); // returns "some%20price=%24300"
  3071. * Ext.Object.toQueryString({date: new Date(2011, 0, 1)}); // returns "date=%222011-01-01T00%3A00%3A00%22"
  3072. * Ext.Object.toQueryString({colors: ['red', 'green', 'blue']}); // returns "colors=red&colors=green&colors=blue"
  3073. *
  3074. * Recursive:
  3075. *
  3076. * Ext.Object.toQueryString({
  3077. * username: 'Jacky',
  3078. * dateOfBirth: {
  3079. * day: 1,
  3080. * month: 2,
  3081. * year: 1911
  3082. * },
  3083. * hobbies: ['coding', 'eating', 'sleeping', ['nested', 'stuff']]
  3084. * }, true); // returns the following string (broken down and url-decoded for ease of reading purpose):
  3085. * // username=Jacky
  3086. * // &dateOfBirth[day]=1&dateOfBirth[month]=2&dateOfBirth[year]=1911
  3087. * // &hobbies[0]=coding&hobbies[1]=eating&hobbies[2]=sleeping&hobbies[3][0]=nested&hobbies[3][1]=stuff
  3088. *
  3089. * @param {Object} object The object to encode
  3090. * @param {Boolean} [recursive=false] Whether or not to interpret the object in recursive format.
  3091. * (PHP / Ruby on Rails servers and similar).
  3092. * @return {String} queryString
  3093. */
  3094. toQueryString: function(object, recursive) {
  3095. var paramObjects = [],
  3096. params = [],
  3097. i, j, ln, paramObject, value;
  3098. for (i in object) {
  3099. if (object.hasOwnProperty(i)) {
  3100. paramObjects = paramObjects.concat(ExtObject.toQueryObjects(i, object[i], recursive));
  3101. }
  3102. }
  3103. for (j = 0, ln = paramObjects.length; j < ln; j++) {
  3104. paramObject = paramObjects[j];
  3105. value = paramObject.value;
  3106. if (Ext.isEmpty(value)) {
  3107. value = '';
  3108. }
  3109. else if (Ext.isDate(value)) {
  3110. value = Ext.Date.toString(value);
  3111. }
  3112. params.push(encodeURIComponent(paramObject.name) + '=' + encodeURIComponent(String(value)));
  3113. }
  3114. return params.join('&');
  3115. },
  3116. /**
  3117. * Converts a query string back into an object.
  3118. *
  3119. * Non-recursive:
  3120. *
  3121. * Ext.Object.fromQueryString("foo=1&bar=2"); // returns {foo: 1, bar: 2}
  3122. * Ext.Object.fromQueryString("foo=&bar=2"); // returns {foo: null, bar: 2}
  3123. * Ext.Object.fromQueryString("some%20price=%24300"); // returns {'some price': '$300'}
  3124. * Ext.Object.fromQueryString("colors=red&colors=green&colors=blue"); // returns {colors: ['red', 'green', 'blue']}
  3125. *
  3126. * Recursive:
  3127. *
  3128. * Ext.Object.fromQueryString(
  3129. * "username=Jacky&"+
  3130. * "dateOfBirth[day]=1&dateOfBirth[month]=2&dateOfBirth[year]=1911&"+
  3131. * "hobbies[0]=coding&hobbies[1]=eating&hobbies[2]=sleeping&"+
  3132. * "hobbies[3][0]=nested&hobbies[3][1]=stuff", true);
  3133. *
  3134. * // returns
  3135. * {
  3136. * username: 'Jacky',
  3137. * dateOfBirth: {
  3138. * day: '1',
  3139. * month: '2',
  3140. * year: '1911'
  3141. * },
  3142. * hobbies: ['coding', 'eating', 'sleeping', ['nested', 'stuff']]
  3143. * }
  3144. *
  3145. * @param {String} queryString The query string to decode
  3146. * @param {Boolean} [recursive=false] Whether or not to recursively decode the string. This format is supported by
  3147. * PHP / Ruby on Rails servers and similar.
  3148. * @return {Object}
  3149. */
  3150. fromQueryString: function(queryString, recursive) {
  3151. var parts = queryString.replace(/^\?/, '').split('&'),
  3152. object = {},
  3153. temp, components, name, value, i, ln,
  3154. part, j, subLn, matchedKeys, matchedName,
  3155. keys, key, nextKey;
  3156. for (i = 0, ln = parts.length; i < ln; i++) {
  3157. part = parts[i];
  3158. if (part.length > 0) {
  3159. components = part.split('=');
  3160. name = decodeURIComponent(components[0]);
  3161. value = (components[1] !== undefined) ? decodeURIComponent(components[1]) : '';
  3162. if (!recursive) {
  3163. if (object.hasOwnProperty(name)) {
  3164. if (!Ext.isArray(object[name])) {
  3165. object[name] = [object[name]];
  3166. }
  3167. object[name].push(value);
  3168. }
  3169. else {
  3170. object[name] = value;
  3171. }
  3172. }
  3173. else {
  3174. matchedKeys = name.match(/(\[):?([^\]]*)\]/g);
  3175. matchedName = name.match(/^([^\[]+)/);
  3176. if (!matchedName) {
  3177. throw new Error('[Ext.Object.fromQueryString] Malformed query string given, failed parsing name from "' + part + '"');
  3178. }
  3179. name = matchedName[0];
  3180. keys = [];
  3181. if (matchedKeys === null) {
  3182. object[name] = value;
  3183. continue;
  3184. }
  3185. for (j = 0, subLn = matchedKeys.length; j < subLn; j++) {
  3186. key = matchedKeys[j];
  3187. key = (key.length === 2) ? '' : key.substring(1, key.length - 1);
  3188. keys.push(key);
  3189. }
  3190. keys.unshift(name);
  3191. temp = object;
  3192. for (j = 0, subLn = keys.length; j < subLn; j++) {
  3193. key = keys[j];
  3194. if (j === subLn - 1) {
  3195. if (Ext.isArray(temp) && key === '') {
  3196. temp.push(value);
  3197. }
  3198. else {
  3199. temp[key] = value;
  3200. }
  3201. }
  3202. else {
  3203. if (temp[key] === undefined || typeof temp[key] === 'string') {
  3204. nextKey = keys[j+1];
  3205. temp[key] = (Ext.isNumeric(nextKey) || nextKey === '') ? [] : {};
  3206. }
  3207. temp = temp[key];
  3208. }
  3209. }
  3210. }
  3211. }
  3212. }
  3213. return object;
  3214. },
  3215. /**
  3216. * Iterates through an object and invokes the given callback function for each iteration.
  3217. * The iteration can be stopped by returning `false` in the callback function. For example:
  3218. *
  3219. * var person = {
  3220. * name: 'Jacky'
  3221. * hairColor: 'black'
  3222. * loves: ['food', 'sleeping', 'wife']
  3223. * };
  3224. *
  3225. * Ext.Object.each(person, function(key, value, myself) {
  3226. * console.log(key + ":" + value);
  3227. *
  3228. * if (key === 'hairColor') {
  3229. * return false; // stop the iteration
  3230. * }
  3231. * });
  3232. *
  3233. * @param {Object} object The object to iterate
  3234. * @param {Function} fn The callback function.
  3235. * @param {String} fn.key
  3236. * @param {Object} fn.value
  3237. * @param {Object} fn.object The object itself
  3238. * @param {Object} [scope] The execution scope (`this`) of the callback function
  3239. */
  3240. each: function(object, fn, scope) {
  3241. for (var property in object) {
  3242. if (object.hasOwnProperty(property)) {
  3243. if (fn.call(scope || object, property, object[property], object) === false) {
  3244. return;
  3245. }
  3246. }
  3247. }
  3248. },
  3249. /**
  3250. * Merges any number of objects recursively without referencing them or their children.
  3251. *
  3252. * var extjs = {
  3253. * companyName: 'Ext JS',
  3254. * products: ['Ext JS', 'Ext GWT', 'Ext Designer'],
  3255. * isSuperCool: true,
  3256. * office: {
  3257. * size: 2000,
  3258. * location: 'Palo Alto',
  3259. * isFun: true
  3260. * }
  3261. * };
  3262. *
  3263. * var newStuff = {
  3264. * companyName: 'Sencha Inc.',
  3265. * products: ['Ext JS', 'Ext GWT', 'Ext Designer', 'Sencha Touch', 'Sencha Animator'],
  3266. * office: {
  3267. * size: 40000,
  3268. * location: 'Redwood City'
  3269. * }
  3270. * };
  3271. *
  3272. * var sencha = Ext.Object.merge(extjs, newStuff);
  3273. *
  3274. * // extjs and sencha then equals to
  3275. * {
  3276. * companyName: 'Sencha Inc.',
  3277. * products: ['Ext JS', 'Ext GWT', 'Ext Designer', 'Sencha Touch', 'Sencha Animator'],
  3278. * isSuperCool: true,
  3279. * office: {
  3280. * size: 40000,
  3281. * location: 'Redwood City',
  3282. * isFun: true
  3283. * }
  3284. * }
  3285. *
  3286. * @param {Object} destination The object into which all subsequent objects are merged.
  3287. * @param {Object...} object Any number of objects to merge into the destination.
  3288. * @return {Object} merged The destination object with all passed objects merged in.
  3289. */
  3290. merge: function(destination) {
  3291. var i = 1,
  3292. ln = arguments.length,
  3293. mergeFn = ExtObject.merge,
  3294. cloneFn = Ext.clone,
  3295. object, key, value, sourceKey;
  3296. for (; i < ln; i++) {
  3297. object = arguments[i];
  3298. for (key in object) {
  3299. value = object[key];
  3300. if (value && value.constructor === Object) {
  3301. sourceKey = destination[key];
  3302. if (sourceKey && sourceKey.constructor === Object) {
  3303. mergeFn(sourceKey, value);
  3304. }
  3305. else {
  3306. destination[key] = cloneFn(value);
  3307. }
  3308. }
  3309. else {
  3310. destination[key] = value;
  3311. }
  3312. }
  3313. }
  3314. return destination;
  3315. },
  3316. /**
  3317. * @private
  3318. * @param destination
  3319. */
  3320. mergeIf: function(destination) {
  3321. var i = 1,
  3322. ln = arguments.length,
  3323. cloneFn = Ext.clone,
  3324. object, key, value;
  3325. for (; i < ln; i++) {
  3326. object = arguments[i];
  3327. for (key in object) {
  3328. if (!(key in destination)) {
  3329. value = object[key];
  3330. if (value && value.constructor === Object) {
  3331. destination[key] = cloneFn(value);
  3332. }
  3333. else {
  3334. destination[key] = value;
  3335. }
  3336. }
  3337. }
  3338. }
  3339. return destination;
  3340. },
  3341. /**
  3342. * Returns the first matching key corresponding to the given value.
  3343. * If no matching value is found, null is returned.
  3344. *
  3345. * var person = {
  3346. * name: 'Jacky',
  3347. * loves: 'food'
  3348. * };
  3349. *
  3350. * alert(Ext.Object.getKey(person, 'food')); // alerts 'loves'
  3351. *
  3352. * @param {Object} object
  3353. * @param {Object} value The value to find
  3354. */
  3355. getKey: function(object, value) {
  3356. for (var property in object) {
  3357. if (object.hasOwnProperty(property) && object[property] === value) {
  3358. return property;
  3359. }
  3360. }
  3361. return null;
  3362. },
  3363. /**
  3364. * Gets all values of the given object as an array.
  3365. *
  3366. * var values = Ext.Object.getValues({
  3367. * name: 'Jacky',
  3368. * loves: 'food'
  3369. * }); // ['Jacky', 'food']
  3370. *
  3371. * @param {Object} object
  3372. * @return {Array} An array of values from the object
  3373. */
  3374. getValues: function(object) {
  3375. var values = [],
  3376. property;
  3377. for (property in object) {
  3378. if (object.hasOwnProperty(property)) {
  3379. values.push(object[property]);
  3380. }
  3381. }
  3382. return values;
  3383. },
  3384. /**
  3385. * Gets all keys of the given object as an array.
  3386. *
  3387. * var values = Ext.Object.getKeys({
  3388. * name: 'Jacky',
  3389. * loves: 'food'
  3390. * }); // ['name', 'loves']
  3391. *
  3392. * @param {Object} object
  3393. * @return {String[]} An array of keys from the object
  3394. * @method
  3395. */
  3396. getKeys: (typeof Object.keys == 'function')
  3397. ? function(object){
  3398. if (!object) {
  3399. return [];
  3400. }
  3401. return Object.keys(object);
  3402. }
  3403. : function(object) {
  3404. var keys = [],
  3405. property;
  3406. for (property in object) {
  3407. if (object.hasOwnProperty(property)) {
  3408. keys.push(property);
  3409. }
  3410. }
  3411. return keys;
  3412. },
  3413. /**
  3414. * Gets the total number of this object's own properties
  3415. *
  3416. * var size = Ext.Object.getSize({
  3417. * name: 'Jacky',
  3418. * loves: 'food'
  3419. * }); // size equals 2
  3420. *
  3421. * @param {Object} object
  3422. * @return {Number} size
  3423. */
  3424. getSize: function(object) {
  3425. var size = 0,
  3426. property;
  3427. for (property in object) {
  3428. if (object.hasOwnProperty(property)) {
  3429. size++;
  3430. }
  3431. }
  3432. return size;
  3433. },
  3434. /**
  3435. * @private
  3436. */
  3437. classify: function(object) {
  3438. var prototype = object,
  3439. objectProperties = [],
  3440. propertyClassesMap = {},
  3441. objectClass = function() {
  3442. var i = 0,
  3443. ln = objectProperties.length,
  3444. property;
  3445. for (; i < ln; i++) {
  3446. property = objectProperties[i];
  3447. this[property] = new propertyClassesMap[property]();
  3448. }
  3449. },
  3450. key, value;
  3451. for (key in object) {
  3452. if (object.hasOwnProperty(key)) {
  3453. value = object[key];
  3454. if (value && value.constructor === Object) {
  3455. objectProperties.push(key);
  3456. propertyClassesMap[key] = ExtObject.classify(value);
  3457. }
  3458. }
  3459. }
  3460. objectClass.prototype = prototype;
  3461. return objectClass;
  3462. }
  3463. };
  3464. /**
  3465. * A convenient alias method for {@link Ext.Object#merge}.
  3466. *
  3467. * @member Ext
  3468. * @method merge
  3469. * @inheritdoc Ext.Object#merge
  3470. */
  3471. Ext.merge = Ext.Object.merge;
  3472. /**
  3473. * @private
  3474. * @member Ext
  3475. */
  3476. Ext.mergeIf = Ext.Object.mergeIf;
  3477. /**
  3478. *
  3479. * @member Ext
  3480. * @method urlEncode
  3481. * @inheritdoc Ext.Object#toQueryString
  3482. * @deprecated 4.0.0 Use {@link Ext.Object#toQueryString} instead
  3483. */
  3484. Ext.urlEncode = function() {
  3485. var args = Ext.Array.from(arguments),
  3486. prefix = '';
  3487. // Support for the old `pre` argument
  3488. if ((typeof args[1] === 'string')) {
  3489. prefix = args[1] + '&';
  3490. args[1] = false;
  3491. }
  3492. return prefix + ExtObject.toQueryString.apply(ExtObject, args);
  3493. };
  3494. /**
  3495. * Alias for {@link Ext.Object#fromQueryString}.
  3496. *
  3497. * @member Ext
  3498. * @method urlDecode
  3499. * @inheritdoc Ext.Object#fromQueryString
  3500. * @deprecated 4.0.0 Use {@link Ext.Object#fromQueryString} instead
  3501. */
  3502. Ext.urlDecode = function() {
  3503. return ExtObject.fromQueryString.apply(ExtObject, arguments);
  3504. };
  3505. }());
  3506. //@tag foundation,core
  3507. //@require Object.js
  3508. //@define Ext.Date
  3509. /**
  3510. * @class Ext.Date
  3511. * A set of useful static methods to deal with date
  3512. * Note that if Ext.Date is required and loaded, it will copy all methods / properties to
  3513. * this object for convenience
  3514. *
  3515. * The date parsing and formatting syntax contains a subset of
  3516. * <a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
  3517. * supported will provide results equivalent to their PHP versions.
  3518. *
  3519. * The following is a list of all currently supported formats:
  3520. * <pre class="">
  3521. Format Description Example returned values
  3522. ------ ----------------------------------------------------------------------- -----------------------
  3523. d Day of the month, 2 digits with leading zeros 01 to 31
  3524. D A short textual representation of the day of the week Mon to Sun
  3525. j Day of the month without leading zeros 1 to 31
  3526. l A full textual representation of the day of the week Sunday to Saturday
  3527. N ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)
  3528. S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
  3529. w Numeric representation of the day of the week 0 (for Sunday) to 6 (for Saturday)
  3530. z The day of the year (starting from 0) 0 to 364 (365 in leap years)
  3531. W ISO-8601 week number of year, weeks starting on Monday 01 to 53
  3532. F A full textual representation of a month, such as January or March January to December
  3533. m Numeric representation of a month, with leading zeros 01 to 12
  3534. M A short textual representation of a month Jan to Dec
  3535. n Numeric representation of a month, without leading zeros 1 to 12
  3536. t Number of days in the given month 28 to 31
  3537. L Whether it&#39;s a leap year 1 if it is a leap year, 0 otherwise.
  3538. o ISO-8601 year number (identical to (Y), but if the ISO week number (W) Examples: 1998 or 2004
  3539. belongs to the previous or next year, that year is used instead)
  3540. Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003
  3541. y A two digit representation of a year Examples: 99 or 03
  3542. a Lowercase Ante meridiem and Post meridiem am or pm
  3543. A Uppercase Ante meridiem and Post meridiem AM or PM
  3544. g 12-hour format of an hour without leading zeros 1 to 12
  3545. G 24-hour format of an hour without leading zeros 0 to 23
  3546. h 12-hour format of an hour with leading zeros 01 to 12
  3547. H 24-hour format of an hour with leading zeros 00 to 23
  3548. i Minutes, with leading zeros 00 to 59
  3549. s Seconds, with leading zeros 00 to 59
  3550. u Decimal fraction of a second Examples:
  3551. (minimum 1 digit, arbitrary number of digits allowed) 001 (i.e. 0.001s) or
  3552. 100 (i.e. 0.100s) or
  3553. 999 (i.e. 0.999s) or
  3554. 999876543210 (i.e. 0.999876543210s)
  3555. O Difference to Greenwich time (GMT) in hours and minutes Example: +1030
  3556. P Difference to Greenwich time (GMT) with colon between hours and minutes Example: -08:00
  3557. T Timezone abbreviation of the machine running the code Examples: EST, MDT, PDT ...
  3558. Z Timezone offset in seconds (negative if west of UTC, positive if east) -43200 to 50400
  3559. c ISO 8601 date
  3560. Notes: Examples:
  3561. 1) If unspecified, the month / day defaults to the current month / day, 1991 or
  3562. the time defaults to midnight, while the timezone defaults to the 1992-10 or
  3563. browser's timezone. If a time is specified, it must include both hours 1993-09-20 or
  3564. and minutes. The "T" delimiter, seconds, milliseconds and timezone 1994-08-19T16:20+01:00 or
  3565. are optional. 1995-07-18T17:21:28-02:00 or
  3566. 2) The decimal fraction of a second, if specified, must contain at 1996-06-17T18:22:29.98765+03:00 or
  3567. least 1 digit (there is no limit to the maximum number 1997-05-16T19:23:30,12345-0400 or
  3568. of digits allowed), and may be delimited by either a '.' or a ',' 1998-04-15T20:24:31.2468Z or
  3569. Refer to the examples on the right for the various levels of 1999-03-14T20:24:32Z or
  3570. date-time granularity which are supported, or see 2000-02-13T21:25:33
  3571. http://www.w3.org/TR/NOTE-datetime for more info. 2001-01-12 22:26:34
  3572. U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 1193432466 or -2138434463
  3573. MS Microsoft AJAX serialized dates \/Date(1238606590509)\/ (i.e. UTC milliseconds since epoch) or
  3574. \/Date(1238606590509+0800)\/
  3575. </pre>
  3576. *
  3577. * Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
  3578. * <pre><code>
  3579. // Sample date:
  3580. // 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
  3581. var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
  3582. console.log(Ext.Date.format(dt, 'Y-m-d')); // 2007-01-10
  3583. console.log(Ext.Date.format(dt, 'F j, Y, g:i a')); // January 10, 2007, 3:05 pm
  3584. console.log(Ext.Date.format(dt, 'l, \\t\\he jS \\of F Y h:i:s A')); // Wednesday, the 10th of January 2007 03:05:01 PM
  3585. </code></pre>
  3586. *
  3587. * Here are some standard date/time patterns that you might find helpful. They
  3588. * are not part of the source of Ext.Date, but to use them you can simply copy this
  3589. * block of code into any script that is included after Ext.Date and they will also become
  3590. * globally available on the Date object. Feel free to add or remove patterns as needed in your code.
  3591. * <pre><code>
  3592. Ext.Date.patterns = {
  3593. ISO8601Long:"Y-m-d H:i:s",
  3594. ISO8601Short:"Y-m-d",
  3595. ShortDate: "n/j/Y",
  3596. LongDate: "l, F d, Y",
  3597. FullDateTime: "l, F d, Y g:i:s A",
  3598. MonthDay: "F d",
  3599. ShortTime: "g:i A",
  3600. LongTime: "g:i:s A",
  3601. SortableDateTime: "Y-m-d\\TH:i:s",
  3602. UniversalSortableDateTime: "Y-m-d H:i:sO",
  3603. YearMonth: "F, Y"
  3604. };
  3605. </code></pre>
  3606. *
  3607. * Example usage:
  3608. * <pre><code>
  3609. var dt = new Date();
  3610. console.log(Ext.Date.format(dt, Ext.Date.patterns.ShortDate));
  3611. </code></pre>
  3612. * <p>Developer-written, custom formats may be used by supplying both a formatting and a parsing function
  3613. * which perform to specialized requirements. The functions are stored in {@link #parseFunctions} and {@link #formatFunctions}.</p>
  3614. * @singleton
  3615. */
  3616. /*
  3617. * Most of the date-formatting functions below are the excellent work of Baron Schwartz.
  3618. * (see http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/)
  3619. * They generate precompiled functions from format patterns instead of parsing and
  3620. * processing each pattern every time a date is formatted. These functions are available
  3621. * on every Date object.
  3622. */
  3623. (function() {
  3624. // create private copy of Ext's Ext.util.Format.format() method
  3625. // - to remove unnecessary dependency
  3626. // - to resolve namespace conflict with MS-Ajax's implementation
  3627. function xf(format) {
  3628. var args = Array.prototype.slice.call(arguments, 1);
  3629. return format.replace(/\{(\d+)\}/g, function(m, i) {
  3630. return args[i];
  3631. });
  3632. }
  3633. Ext.Date = {
  3634. /**
  3635. * Returns the current timestamp.
  3636. * @return {Number} Milliseconds since UNIX epoch.
  3637. * @method
  3638. */
  3639. now: Date.now || function() {
  3640. return +new Date();
  3641. },
  3642. /**
  3643. * @private
  3644. * Private for now
  3645. */
  3646. toString: function(date) {
  3647. var pad = Ext.String.leftPad;
  3648. return date.getFullYear() + "-"
  3649. + pad(date.getMonth() + 1, 2, '0') + "-"
  3650. + pad(date.getDate(), 2, '0') + "T"
  3651. + pad(date.getHours(), 2, '0') + ":"
  3652. + pad(date.getMinutes(), 2, '0') + ":"
  3653. + pad(date.getSeconds(), 2, '0');
  3654. },
  3655. /**
  3656. * Returns the number of milliseconds between two dates
  3657. * @param {Date} dateA The first date
  3658. * @param {Date} dateB (optional) The second date, defaults to now
  3659. * @return {Number} The difference in milliseconds
  3660. */
  3661. getElapsed: function(dateA, dateB) {
  3662. return Math.abs(dateA - (dateB || new Date()));
  3663. },
  3664. /**
  3665. * Global flag which determines if strict date parsing should be used.
  3666. * Strict date parsing will not roll-over invalid dates, which is the
  3667. * default behaviour of javascript Date objects.
  3668. * (see {@link #parse} for more information)
  3669. * Defaults to <tt>false</tt>.
  3670. * @type Boolean
  3671. */
  3672. useStrict: false,
  3673. // private
  3674. formatCodeToRegex: function(character, currentGroup) {
  3675. // Note: currentGroup - position in regex result array (see notes for Ext.Date.parseCodes below)
  3676. var p = utilDate.parseCodes[character];
  3677. if (p) {
  3678. p = typeof p == 'function'? p() : p;
  3679. utilDate.parseCodes[character] = p; // reassign function result to prevent repeated execution
  3680. }
  3681. return p ? Ext.applyIf({
  3682. c: p.c ? xf(p.c, currentGroup || "{0}") : p.c
  3683. }, p) : {
  3684. g: 0,
  3685. c: null,
  3686. s: Ext.String.escapeRegex(character) // treat unrecognised characters as literals
  3687. };
  3688. },
  3689. /**
  3690. * <p>An object hash in which each property is a date parsing function. The property name is the
  3691. * format string which that function parses.</p>
  3692. * <p>This object is automatically populated with date parsing functions as
  3693. * date formats are requested for Ext standard formatting strings.</p>
  3694. * <p>Custom parsing functions may be inserted into this object, keyed by a name which from then on
  3695. * may be used as a format string to {@link #parse}.<p>
  3696. * <p>Example:</p><pre><code>
  3697. Ext.Date.parseFunctions['x-date-format'] = myDateParser;
  3698. </code></pre>
  3699. * <p>A parsing function should return a Date object, and is passed the following parameters:<div class="mdetail-params"><ul>
  3700. * <li><code>date</code> : String<div class="sub-desc">The date string to parse.</div></li>
  3701. * <li><code>strict</code> : Boolean<div class="sub-desc">True to validate date strings while parsing
  3702. * (i.e. prevent javascript Date "rollover") (The default must be false).
  3703. * Invalid date strings should return null when parsed.</div></li>
  3704. * </ul></div></p>
  3705. * <p>To enable Dates to also be <i>formatted</i> according to that format, a corresponding
  3706. * formatting function must be placed into the {@link #formatFunctions} property.
  3707. * @property parseFunctions
  3708. * @type Object
  3709. */
  3710. parseFunctions: {
  3711. "MS": function(input, strict) {
  3712. // note: the timezone offset is ignored since the MS Ajax server sends
  3713. // a UTC milliseconds-since-Unix-epoch value (negative values are allowed)
  3714. var re = new RegExp('\\/Date\\(([-+])?(\\d+)(?:[+-]\\d{4})?\\)\\/'),
  3715. r = (input || '').match(re);
  3716. return r? new Date(((r[1] || '') + r[2]) * 1) : null;
  3717. }
  3718. },
  3719. parseRegexes: [],
  3720. /**
  3721. * <p>An object hash in which each property is a date formatting function. The property name is the
  3722. * format string which corresponds to the produced formatted date string.</p>
  3723. * <p>This object is automatically populated with date formatting functions as
  3724. * date formats are requested for Ext standard formatting strings.</p>
  3725. * <p>Custom formatting functions may be inserted into this object, keyed by a name which from then on
  3726. * may be used as a format string to {@link #format}. Example:</p><pre><code>
  3727. Ext.Date.formatFunctions['x-date-format'] = myDateFormatter;
  3728. </code></pre>
  3729. * <p>A formatting function should return a string representation of the passed Date object, and is passed the following parameters:<div class="mdetail-params"><ul>
  3730. * <li><code>date</code> : Date<div class="sub-desc">The Date to format.</div></li>
  3731. * </ul></div></p>
  3732. * <p>To enable date strings to also be <i>parsed</i> according to that format, a corresponding
  3733. * parsing function must be placed into the {@link #parseFunctions} property.
  3734. * @property formatFunctions
  3735. * @type Object
  3736. */
  3737. formatFunctions: {
  3738. "MS": function() {
  3739. // UTC milliseconds since Unix epoch (MS-AJAX serialized date format (MRSF))
  3740. return '\\/Date(' + this.getTime() + ')\\/';
  3741. }
  3742. },
  3743. y2kYear : 50,
  3744. /**
  3745. * Date interval constant
  3746. * @type String
  3747. */
  3748. MILLI : "ms",
  3749. /**
  3750. * Date interval constant
  3751. * @type String
  3752. */
  3753. SECOND : "s",
  3754. /**
  3755. * Date interval constant
  3756. * @type String
  3757. */
  3758. MINUTE : "mi",
  3759. /** Date interval constant
  3760. * @type String
  3761. */
  3762. HOUR : "h",
  3763. /**
  3764. * Date interval constant
  3765. * @type String
  3766. */
  3767. DAY : "d",
  3768. /**
  3769. * Date interval constant
  3770. * @type String
  3771. */
  3772. MONTH : "mo",
  3773. /**
  3774. * Date interval constant
  3775. * @type String
  3776. */
  3777. YEAR : "y",
  3778. /**
  3779. * <p>An object hash containing default date values used during date parsing.</p>
  3780. * <p>The following properties are available:<div class="mdetail-params"><ul>
  3781. * <li><code>y</code> : Number<div class="sub-desc">The default year value. (defaults to undefined)</div></li>
  3782. * <li><code>m</code> : Number<div class="sub-desc">The default 1-based month value. (defaults to undefined)</div></li>
  3783. * <li><code>d</code> : Number<div class="sub-desc">The default day value. (defaults to undefined)</div></li>
  3784. * <li><code>h</code> : Number<div class="sub-desc">The default hour value. (defaults to undefined)</div></li>
  3785. * <li><code>i</code> : Number<div class="sub-desc">The default minute value. (defaults to undefined)</div></li>
  3786. * <li><code>s</code> : Number<div class="sub-desc">The default second value. (defaults to undefined)</div></li>
  3787. * <li><code>ms</code> : Number<div class="sub-desc">The default millisecond value. (defaults to undefined)</div></li>
  3788. * </ul></div></p>
  3789. * <p>Override these properties to customize the default date values used by the {@link #parse} method.</p>
  3790. * <p><b>Note: In countries which experience Daylight Saving Time (i.e. DST), the <tt>h</tt>, <tt>i</tt>, <tt>s</tt>
  3791. * and <tt>ms</tt> properties may coincide with the exact time in which DST takes effect.
  3792. * It is the responsiblity of the developer to account for this.</b></p>
  3793. * Example Usage:
  3794. * <pre><code>
  3795. // set default day value to the first day of the month
  3796. Ext.Date.defaults.d = 1;
  3797. // parse a February date string containing only year and month values.
  3798. // setting the default day value to 1 prevents weird date rollover issues
  3799. // when attempting to parse the following date string on, for example, March 31st 2009.
  3800. Ext.Date.parse('2009-02', 'Y-m'); // returns a Date object representing February 1st 2009
  3801. </code></pre>
  3802. * @property defaults
  3803. * @type Object
  3804. */
  3805. defaults: {},
  3806. //<locale type="array">
  3807. /**
  3808. * @property {String[]} dayNames
  3809. * An array of textual day names.
  3810. * Override these values for international dates.
  3811. * Example:
  3812. * <pre><code>
  3813. Ext.Date.dayNames = [
  3814. 'SundayInYourLang',
  3815. 'MondayInYourLang',
  3816. ...
  3817. ];
  3818. </code></pre>
  3819. */
  3820. dayNames : [
  3821. "Sunday",
  3822. "Monday",
  3823. "Tuesday",
  3824. "Wednesday",
  3825. "Thursday",
  3826. "Friday",
  3827. "Saturday"
  3828. ],
  3829. //</locale>
  3830. //<locale type="array">
  3831. /**
  3832. * @property {String[]} monthNames
  3833. * An array of textual month names.
  3834. * Override these values for international dates.
  3835. * Example:
  3836. * <pre><code>
  3837. Ext.Date.monthNames = [
  3838. 'JanInYourLang',
  3839. 'FebInYourLang',
  3840. ...
  3841. ];
  3842. </code></pre>
  3843. */
  3844. monthNames : [
  3845. "January",
  3846. "February",
  3847. "March",
  3848. "April",
  3849. "May",
  3850. "June",
  3851. "July",
  3852. "August",
  3853. "September",
  3854. "October",
  3855. "November",
  3856. "December"
  3857. ],
  3858. //</locale>
  3859. //<locale type="object">
  3860. /**
  3861. * @property {Object} monthNumbers
  3862. * An object hash of zero-based javascript month numbers (with short month names as keys. note: keys are case-sensitive).
  3863. * Override these values for international dates.
  3864. * Example:
  3865. * <pre><code>
  3866. Ext.Date.monthNumbers = {
  3867. 'LongJanNameInYourLang': 0,
  3868. 'ShortJanNameInYourLang':0,
  3869. 'LongFebNameInYourLang':1,
  3870. 'ShortFebNameInYourLang':1,
  3871. ...
  3872. };
  3873. </code></pre>
  3874. */
  3875. monthNumbers : {
  3876. January: 0,
  3877. Jan: 0,
  3878. February: 1,
  3879. Feb: 1,
  3880. March: 2,
  3881. Mar: 2,
  3882. April: 3,
  3883. Apr: 3,
  3884. May: 4,
  3885. June: 5,
  3886. Jun: 5,
  3887. July: 6,
  3888. Jul: 6,
  3889. August: 7,
  3890. Aug: 7,
  3891. September: 8,
  3892. Sep: 8,
  3893. October: 9,
  3894. Oct: 9,
  3895. November: 10,
  3896. Nov: 10,
  3897. December: 11,
  3898. Dec: 11
  3899. },
  3900. //</locale>
  3901. //<locale>
  3902. /**
  3903. * @property {String} defaultFormat
  3904. * <p>The date format string that the {@link Ext.util.Format#dateRenderer}
  3905. * and {@link Ext.util.Format#date} functions use. See {@link Ext.Date} for details.</p>
  3906. * <p>This may be overridden in a locale file.</p>
  3907. */
  3908. defaultFormat : "m/d/Y",
  3909. //</locale>
  3910. //<locale type="function">
  3911. /**
  3912. * Get the short month name for the given month number.
  3913. * Override this function for international dates.
  3914. * @param {Number} month A zero-based javascript month number.
  3915. * @return {String} The short month name.
  3916. */
  3917. getShortMonthName : function(month) {
  3918. return Ext.Date.monthNames[month].substring(0, 3);
  3919. },
  3920. //</locale>
  3921. //<locale type="function">
  3922. /**
  3923. * Get the short day name for the given day number.
  3924. * Override this function for international dates.
  3925. * @param {Number} day A zero-based javascript day number.
  3926. * @return {String} The short day name.
  3927. */
  3928. getShortDayName : function(day) {
  3929. return Ext.Date.dayNames[day].substring(0, 3);
  3930. },
  3931. //</locale>
  3932. //<locale type="function">
  3933. /**
  3934. * Get the zero-based javascript month number for the given short/full month name.
  3935. * Override this function for international dates.
  3936. * @param {String} name The short/full month name.
  3937. * @return {Number} The zero-based javascript month number.
  3938. */
  3939. getMonthNumber : function(name) {
  3940. // handle camel casing for english month names (since the keys for the Ext.Date.monthNumbers hash are case sensitive)
  3941. return Ext.Date.monthNumbers[name.substring(0, 1).toUpperCase() + name.substring(1, 3).toLowerCase()];
  3942. },
  3943. //</locale>
  3944. /**
  3945. * Checks if the specified format contains hour information
  3946. * @param {String} format The format to check
  3947. * @return {Boolean} True if the format contains hour information
  3948. * @method
  3949. */
  3950. formatContainsHourInfo : (function(){
  3951. var stripEscapeRe = /(\\.)/g,
  3952. hourInfoRe = /([gGhHisucUOPZ]|MS)/;
  3953. return function(format){
  3954. return hourInfoRe.test(format.replace(stripEscapeRe, ''));
  3955. };
  3956. }()),
  3957. /**
  3958. * Checks if the specified format contains information about
  3959. * anything other than the time.
  3960. * @param {String} format The format to check
  3961. * @return {Boolean} True if the format contains information about
  3962. * date/day information.
  3963. * @method
  3964. */
  3965. formatContainsDateInfo : (function(){
  3966. var stripEscapeRe = /(\\.)/g,
  3967. dateInfoRe = /([djzmnYycU]|MS)/;
  3968. return function(format){
  3969. return dateInfoRe.test(format.replace(stripEscapeRe, ''));
  3970. };
  3971. }()),
  3972. /**
  3973. * Removes all escaping for a date format string. In date formats,
  3974. * using a '\' can be used to escape special characters.
  3975. * @param {String} format The format to unescape
  3976. * @return {String} The unescaped format
  3977. * @method
  3978. */
  3979. unescapeFormat: (function() {
  3980. var slashRe = /\\/gi;
  3981. return function(format) {
  3982. // Escape the format, since \ can be used to escape special
  3983. // characters in a date format. For example, in a spanish
  3984. // locale the format may be: 'd \\de F \\de Y'
  3985. return format.replace(slashRe, '');
  3986. }
  3987. }()),
  3988. /**
  3989. * The base format-code to formatting-function hashmap used by the {@link #format} method.
  3990. * Formatting functions are strings (or functions which return strings) which
  3991. * will return the appropriate value when evaluated in the context of the Date object
  3992. * from which the {@link #format} method is called.
  3993. * Add to / override these mappings for custom date formatting.
  3994. * Note: Ext.Date.format() treats characters as literals if an appropriate mapping cannot be found.
  3995. * Example:
  3996. * <pre><code>
  3997. Ext.Date.formatCodes.x = "Ext.util.Format.leftPad(this.getDate(), 2, '0')";
  3998. console.log(Ext.Date.format(new Date(), 'X'); // returns the current day of the month
  3999. </code></pre>
  4000. * @type Object
  4001. */
  4002. formatCodes : {
  4003. d: "Ext.String.leftPad(this.getDate(), 2, '0')",
  4004. D: "Ext.Date.getShortDayName(this.getDay())", // get localised short day name
  4005. j: "this.getDate()",
  4006. l: "Ext.Date.dayNames[this.getDay()]",
  4007. N: "(this.getDay() ? this.getDay() : 7)",
  4008. S: "Ext.Date.getSuffix(this)",
  4009. w: "this.getDay()",
  4010. z: "Ext.Date.getDayOfYear(this)",
  4011. W: "Ext.String.leftPad(Ext.Date.getWeekOfYear(this), 2, '0')",
  4012. F: "Ext.Date.monthNames[this.getMonth()]",
  4013. m: "Ext.String.leftPad(this.getMonth() + 1, 2, '0')",
  4014. M: "Ext.Date.getShortMonthName(this.getMonth())", // get localised short month name
  4015. n: "(this.getMonth() + 1)",
  4016. t: "Ext.Date.getDaysInMonth(this)",
  4017. L: "(Ext.Date.isLeapYear(this) ? 1 : 0)",
  4018. o: "(this.getFullYear() + (Ext.Date.getWeekOfYear(this) == 1 && this.getMonth() > 0 ? +1 : (Ext.Date.getWeekOfYear(this) >= 52 && this.getMonth() < 11 ? -1 : 0)))",
  4019. Y: "Ext.String.leftPad(this.getFullYear(), 4, '0')",
  4020. y: "('' + this.getFullYear()).substring(2, 4)",
  4021. a: "(this.getHours() < 12 ? 'am' : 'pm')",
  4022. A: "(this.getHours() < 12 ? 'AM' : 'PM')",
  4023. g: "((this.getHours() % 12) ? this.getHours() % 12 : 12)",
  4024. G: "this.getHours()",
  4025. h: "Ext.String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0')",
  4026. H: "Ext.String.leftPad(this.getHours(), 2, '0')",
  4027. i: "Ext.String.leftPad(this.getMinutes(), 2, '0')",
  4028. s: "Ext.String.leftPad(this.getSeconds(), 2, '0')",
  4029. u: "Ext.String.leftPad(this.getMilliseconds(), 3, '0')",
  4030. O: "Ext.Date.getGMTOffset(this)",
  4031. P: "Ext.Date.getGMTOffset(this, true)",
  4032. T: "Ext.Date.getTimezone(this)",
  4033. Z: "(this.getTimezoneOffset() * -60)",
  4034. c: function() { // ISO-8601 -- GMT format
  4035. var c, code, i, l, e;
  4036. for (c = "Y-m-dTH:i:sP", code = [], i = 0, l = c.length; i < l; ++i) {
  4037. e = c.charAt(i);
  4038. code.push(e == "T" ? "'T'" : utilDate.getFormatCode(e)); // treat T as a character literal
  4039. }
  4040. return code.join(" + ");
  4041. },
  4042. /*
  4043. c: function() { // ISO-8601 -- UTC format
  4044. return [
  4045. "this.getUTCFullYear()", "'-'",
  4046. "Ext.util.Format.leftPad(this.getUTCMonth() + 1, 2, '0')", "'-'",
  4047. "Ext.util.Format.leftPad(this.getUTCDate(), 2, '0')",
  4048. "'T'",
  4049. "Ext.util.Format.leftPad(this.getUTCHours(), 2, '0')", "':'",
  4050. "Ext.util.Format.leftPad(this.getUTCMinutes(), 2, '0')", "':'",
  4051. "Ext.util.Format.leftPad(this.getUTCSeconds(), 2, '0')",
  4052. "'Z'"
  4053. ].join(" + ");
  4054. },
  4055. */
  4056. U: "Math.round(this.getTime() / 1000)"
  4057. },
  4058. /**
  4059. * Checks if the passed Date parameters will cause a javascript Date "rollover".
  4060. * @param {Number} year 4-digit year
  4061. * @param {Number} month 1-based month-of-year
  4062. * @param {Number} day Day of month
  4063. * @param {Number} hour (optional) Hour
  4064. * @param {Number} minute (optional) Minute
  4065. * @param {Number} second (optional) Second
  4066. * @param {Number} millisecond (optional) Millisecond
  4067. * @return {Boolean} true if the passed parameters do not cause a Date "rollover", false otherwise.
  4068. */
  4069. isValid : function(y, m, d, h, i, s, ms) {
  4070. // setup defaults
  4071. h = h || 0;
  4072. i = i || 0;
  4073. s = s || 0;
  4074. ms = ms || 0;
  4075. // Special handling for year < 100
  4076. var dt = utilDate.add(new Date(y < 100 ? 100 : y, m - 1, d, h, i, s, ms), utilDate.YEAR, y < 100 ? y - 100 : 0);
  4077. return y == dt.getFullYear() &&
  4078. m == dt.getMonth() + 1 &&
  4079. d == dt.getDate() &&
  4080. h == dt.getHours() &&
  4081. i == dt.getMinutes() &&
  4082. s == dt.getSeconds() &&
  4083. ms == dt.getMilliseconds();
  4084. },
  4085. /**
  4086. * Parses the passed string using the specified date format.
  4087. * Note that this function expects normal calendar dates, meaning that months are 1-based (i.e. 1 = January).
  4088. * The {@link #defaults} hash will be used for any date value (i.e. year, month, day, hour, minute, second or millisecond)
  4089. * which cannot be found in the passed string. If a corresponding default date value has not been specified in the {@link #defaults} hash,
  4090. * the current date's year, month, day or DST-adjusted zero-hour time value will be used instead.
  4091. * Keep in mind that the input date string must precisely match the specified format string
  4092. * in order for the parse operation to be successful (failed parse operations return a null value).
  4093. * <p>Example:</p><pre><code>
  4094. //dt = Fri May 25 2007 (current date)
  4095. var dt = new Date();
  4096. //dt = Thu May 25 2006 (today&#39;s month/day in 2006)
  4097. dt = Ext.Date.parse("2006", "Y");
  4098. //dt = Sun Jan 15 2006 (all date parts specified)
  4099. dt = Ext.Date.parse("2006-01-15", "Y-m-d");
  4100. //dt = Sun Jan 15 2006 15:20:01
  4101. dt = Ext.Date.parse("2006-01-15 3:20:01 PM", "Y-m-d g:i:s A");
  4102. // attempt to parse Sun Feb 29 2006 03:20:01 in strict mode
  4103. dt = Ext.Date.parse("2006-02-29 03:20:01", "Y-m-d H:i:s", true); // returns null
  4104. </code></pre>
  4105. * @param {String} input The raw date string.
  4106. * @param {String} format The expected date string format.
  4107. * @param {Boolean} strict (optional) True to validate date strings while parsing (i.e. prevents javascript Date "rollover")
  4108. (defaults to false). Invalid date strings will return null when parsed.
  4109. * @return {Date} The parsed Date.
  4110. */
  4111. parse : function(input, format, strict) {
  4112. var p = utilDate.parseFunctions;
  4113. if (p[format] == null) {
  4114. utilDate.createParser(format);
  4115. }
  4116. return p[format](input, Ext.isDefined(strict) ? strict : utilDate.useStrict);
  4117. },
  4118. // Backwards compat
  4119. parseDate: function(input, format, strict){
  4120. return utilDate.parse(input, format, strict);
  4121. },
  4122. // private
  4123. getFormatCode : function(character) {
  4124. var f = utilDate.formatCodes[character];
  4125. if (f) {
  4126. f = typeof f == 'function'? f() : f;
  4127. utilDate.formatCodes[character] = f; // reassign function result to prevent repeated execution
  4128. }
  4129. // note: unknown characters are treated as literals
  4130. return f || ("'" + Ext.String.escape(character) + "'");
  4131. },
  4132. // private
  4133. createFormat : function(format) {
  4134. var code = [],
  4135. special = false,
  4136. ch = '',
  4137. i;
  4138. for (i = 0; i < format.length; ++i) {
  4139. ch = format.charAt(i);
  4140. if (!special && ch == "\\") {
  4141. special = true;
  4142. } else if (special) {
  4143. special = false;
  4144. code.push("'" + Ext.String.escape(ch) + "'");
  4145. } else {
  4146. code.push(utilDate.getFormatCode(ch));
  4147. }
  4148. }
  4149. utilDate.formatFunctions[format] = Ext.functionFactory("return " + code.join('+'));
  4150. },
  4151. // private
  4152. createParser : (function() {
  4153. var code = [
  4154. "var dt, y, m, d, h, i, s, ms, o, z, zz, u, v,",
  4155. "def = Ext.Date.defaults,",
  4156. "results = String(input).match(Ext.Date.parseRegexes[{0}]);", // either null, or an array of matched strings
  4157. "if(results){",
  4158. "{1}",
  4159. "if(u != null){", // i.e. unix time is defined
  4160. "v = new Date(u * 1000);", // give top priority to UNIX time
  4161. "}else{",
  4162. // create Date object representing midnight of the current day;
  4163. // this will provide us with our date defaults
  4164. // (note: clearTime() handles Daylight Saving Time automatically)
  4165. "dt = Ext.Date.clearTime(new Date);",
  4166. // date calculations (note: these calculations create a dependency on Ext.Number.from())
  4167. "y = Ext.Number.from(y, Ext.Number.from(def.y, dt.getFullYear()));",
  4168. "m = Ext.Number.from(m, Ext.Number.from(def.m - 1, dt.getMonth()));",
  4169. "d = Ext.Number.from(d, Ext.Number.from(def.d, dt.getDate()));",
  4170. // time calculations (note: these calculations create a dependency on Ext.Number.from())
  4171. "h = Ext.Number.from(h, Ext.Number.from(def.h, dt.getHours()));",
  4172. "i = Ext.Number.from(i, Ext.Number.from(def.i, dt.getMinutes()));",
  4173. "s = Ext.Number.from(s, Ext.Number.from(def.s, dt.getSeconds()));",
  4174. "ms = Ext.Number.from(ms, Ext.Number.from(def.ms, dt.getMilliseconds()));",
  4175. "if(z >= 0 && y >= 0){",
  4176. // both the year and zero-based day of year are defined and >= 0.
  4177. // these 2 values alone provide sufficient info to create a full date object
  4178. // create Date object representing January 1st for the given year
  4179. // handle years < 100 appropriately
  4180. "v = Ext.Date.add(new Date(y < 100 ? 100 : y, 0, 1, h, i, s, ms), Ext.Date.YEAR, y < 100 ? y - 100 : 0);",
  4181. // then add day of year, checking for Date "rollover" if necessary
  4182. "v = !strict? v : (strict === true && (z <= 364 || (Ext.Date.isLeapYear(v) && z <= 365))? Ext.Date.add(v, Ext.Date.DAY, z) : null);",
  4183. "}else if(strict === true && !Ext.Date.isValid(y, m + 1, d, h, i, s, ms)){", // check for Date "rollover"
  4184. "v = null;", // invalid date, so return null
  4185. "}else{",
  4186. // plain old Date object
  4187. // handle years < 100 properly
  4188. "v = Ext.Date.add(new Date(y < 100 ? 100 : y, m, d, h, i, s, ms), Ext.Date.YEAR, y < 100 ? y - 100 : 0);",
  4189. "}",
  4190. "}",
  4191. "}",
  4192. "if(v){",
  4193. // favour UTC offset over GMT offset
  4194. "if(zz != null){",
  4195. // reset to UTC, then add offset
  4196. "v = Ext.Date.add(v, Ext.Date.SECOND, -v.getTimezoneOffset() * 60 - zz);",
  4197. "}else if(o){",
  4198. // reset to GMT, then add offset
  4199. "v = Ext.Date.add(v, Ext.Date.MINUTE, -v.getTimezoneOffset() + (sn == '+'? -1 : 1) * (hr * 60 + mn));",
  4200. "}",
  4201. "}",
  4202. "return v;"
  4203. ].join('\n');
  4204. return function(format) {
  4205. var regexNum = utilDate.parseRegexes.length,
  4206. currentGroup = 1,
  4207. calc = [],
  4208. regex = [],
  4209. special = false,
  4210. ch = "",
  4211. i = 0,
  4212. len = format.length,
  4213. atEnd = [],
  4214. obj;
  4215. for (; i < len; ++i) {
  4216. ch = format.charAt(i);
  4217. if (!special && ch == "\\") {
  4218. special = true;
  4219. } else if (special) {
  4220. special = false;
  4221. regex.push(Ext.String.escape(ch));
  4222. } else {
  4223. obj = utilDate.formatCodeToRegex(ch, currentGroup);
  4224. currentGroup += obj.g;
  4225. regex.push(obj.s);
  4226. if (obj.g && obj.c) {
  4227. if (obj.calcAtEnd) {
  4228. atEnd.push(obj.c);
  4229. } else {
  4230. calc.push(obj.c);
  4231. }
  4232. }
  4233. }
  4234. }
  4235. calc = calc.concat(atEnd);
  4236. utilDate.parseRegexes[regexNum] = new RegExp("^" + regex.join('') + "$", 'i');
  4237. utilDate.parseFunctions[format] = Ext.functionFactory("input", "strict", xf(code, regexNum, calc.join('')));
  4238. };
  4239. }()),
  4240. // private
  4241. parseCodes : {
  4242. /*
  4243. * Notes:
  4244. * g = {Number} calculation group (0 or 1. only group 1 contributes to date calculations.)
  4245. * c = {String} calculation method (required for group 1. null for group 0. {0} = currentGroup - position in regex result array)
  4246. * s = {String} regex pattern. all matches are stored in results[], and are accessible by the calculation mapped to 'c'
  4247. */
  4248. d: {
  4249. g:1,
  4250. c:"d = parseInt(results[{0}], 10);\n",
  4251. s:"(3[0-1]|[1-2][0-9]|0[1-9])" // day of month with leading zeroes (01 - 31)
  4252. },
  4253. j: {
  4254. g:1,
  4255. c:"d = parseInt(results[{0}], 10);\n",
  4256. s:"(3[0-1]|[1-2][0-9]|[1-9])" // day of month without leading zeroes (1 - 31)
  4257. },
  4258. D: function() {
  4259. for (var a = [], i = 0; i < 7; a.push(utilDate.getShortDayName(i)), ++i); // get localised short day names
  4260. return {
  4261. g:0,
  4262. c:null,
  4263. s:"(?:" + a.join("|") +")"
  4264. };
  4265. },
  4266. l: function() {
  4267. return {
  4268. g:0,
  4269. c:null,
  4270. s:"(?:" + utilDate.dayNames.join("|") + ")"
  4271. };
  4272. },
  4273. N: {
  4274. g:0,
  4275. c:null,
  4276. s:"[1-7]" // ISO-8601 day number (1 (monday) - 7 (sunday))
  4277. },
  4278. //<locale type="object" property="parseCodes">
  4279. S: {
  4280. g:0,
  4281. c:null,
  4282. s:"(?:st|nd|rd|th)"
  4283. },
  4284. //</locale>
  4285. w: {
  4286. g:0,
  4287. c:null,
  4288. s:"[0-6]" // javascript day number (0 (sunday) - 6 (saturday))
  4289. },
  4290. z: {
  4291. g:1,
  4292. c:"z = parseInt(results[{0}], 10);\n",
  4293. s:"(\\d{1,3})" // day of the year (0 - 364 (365 in leap years))
  4294. },
  4295. W: {
  4296. g:0,
  4297. c:null,
  4298. s:"(?:\\d{2})" // ISO-8601 week number (with leading zero)
  4299. },
  4300. F: function() {
  4301. return {
  4302. g:1,
  4303. c:"m = parseInt(Ext.Date.getMonthNumber(results[{0}]), 10);\n", // get localised month number
  4304. s:"(" + utilDate.monthNames.join("|") + ")"
  4305. };
  4306. },
  4307. M: function() {
  4308. for (var a = [], i = 0; i < 12; a.push(utilDate.getShortMonthName(i)), ++i); // get localised short month names
  4309. return Ext.applyIf({
  4310. s:"(" + a.join("|") + ")"
  4311. }, utilDate.formatCodeToRegex("F"));
  4312. },
  4313. m: {
  4314. g:1,
  4315. c:"m = parseInt(results[{0}], 10) - 1;\n",
  4316. s:"(1[0-2]|0[1-9])" // month number with leading zeros (01 - 12)
  4317. },
  4318. n: {
  4319. g:1,
  4320. c:"m = parseInt(results[{0}], 10) - 1;\n",
  4321. s:"(1[0-2]|[1-9])" // month number without leading zeros (1 - 12)
  4322. },
  4323. t: {
  4324. g:0,
  4325. c:null,
  4326. s:"(?:\\d{2})" // no. of days in the month (28 - 31)
  4327. },
  4328. L: {
  4329. g:0,
  4330. c:null,
  4331. s:"(?:1|0)"
  4332. },
  4333. o: function() {
  4334. return utilDate.formatCodeToRegex("Y");
  4335. },
  4336. Y: {
  4337. g:1,
  4338. c:"y = parseInt(results[{0}], 10);\n",
  4339. s:"(\\d{4})" // 4-digit year
  4340. },
  4341. y: {
  4342. g:1,
  4343. c:"var ty = parseInt(results[{0}], 10);\n"
  4344. + "y = ty > Ext.Date.y2kYear ? 1900 + ty : 2000 + ty;\n", // 2-digit year
  4345. s:"(\\d{1,2})"
  4346. },
  4347. /*
  4348. * In the am/pm parsing routines, we allow both upper and lower case
  4349. * even though it doesn't exactly match the spec. It gives much more flexibility
  4350. * in being able to specify case insensitive regexes.
  4351. */
  4352. //<locale type="object" property="parseCodes">
  4353. a: {
  4354. g:1,
  4355. c:"if (/(am)/i.test(results[{0}])) {\n"
  4356. + "if (!h || h == 12) { h = 0; }\n"
  4357. + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
  4358. s:"(am|pm|AM|PM)",
  4359. calcAtEnd: true
  4360. },
  4361. //</locale>
  4362. //<locale type="object" property="parseCodes">
  4363. A: {
  4364. g:1,
  4365. c:"if (/(am)/i.test(results[{0}])) {\n"
  4366. + "if (!h || h == 12) { h = 0; }\n"
  4367. + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
  4368. s:"(AM|PM|am|pm)",
  4369. calcAtEnd: true
  4370. },
  4371. //</locale>
  4372. g: {
  4373. g:1,
  4374. c:"h = parseInt(results[{0}], 10);\n",
  4375. s:"(1[0-2]|[0-9])" // 12-hr format of an hour without leading zeroes (1 - 12)
  4376. },
  4377. G: {
  4378. g:1,
  4379. c:"h = parseInt(results[{0}], 10);\n",
  4380. s:"(2[0-3]|1[0-9]|[0-9])" // 24-hr format of an hour without leading zeroes (0 - 23)
  4381. },
  4382. h: {
  4383. g:1,
  4384. c:"h = parseInt(results[{0}], 10);\n",
  4385. s:"(1[0-2]|0[1-9])" // 12-hr format of an hour with leading zeroes (01 - 12)
  4386. },
  4387. H: {
  4388. g:1,
  4389. c:"h = parseInt(results[{0}], 10);\n",
  4390. s:"(2[0-3]|[0-1][0-9])" // 24-hr format of an hour with leading zeroes (00 - 23)
  4391. },
  4392. i: {
  4393. g:1,
  4394. c:"i = parseInt(results[{0}], 10);\n",
  4395. s:"([0-5][0-9])" // minutes with leading zeros (00 - 59)
  4396. },
  4397. s: {
  4398. g:1,
  4399. c:"s = parseInt(results[{0}], 10);\n",
  4400. s:"([0-5][0-9])" // seconds with leading zeros (00 - 59)
  4401. },
  4402. u: {
  4403. g:1,
  4404. c:"ms = results[{0}]; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n",
  4405. s:"(\\d+)" // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
  4406. },
  4407. O: {
  4408. g:1,
  4409. c:[
  4410. "o = results[{0}];",
  4411. "var sn = o.substring(0,1),", // get + / - sign
  4412. "hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
  4413. "mn = o.substring(3,5) % 60;", // get minutes
  4414. "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + Ext.String.leftPad(hr, 2, '0') + Ext.String.leftPad(mn, 2, '0')) : null;\n" // -12hrs <= GMT offset <= 14hrs
  4415. ].join("\n"),
  4416. s: "([+-]\\d{4})" // GMT offset in hrs and mins
  4417. },
  4418. P: {
  4419. g:1,
  4420. c:[
  4421. "o = results[{0}];",
  4422. "var sn = o.substring(0,1),", // get + / - sign
  4423. "hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
  4424. "mn = o.substring(4,6) % 60;", // get minutes
  4425. "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + Ext.String.leftPad(hr, 2, '0') + Ext.String.leftPad(mn, 2, '0')) : null;\n" // -12hrs <= GMT offset <= 14hrs
  4426. ].join("\n"),
  4427. s: "([+-]\\d{2}:\\d{2})" // GMT offset in hrs and mins (with colon separator)
  4428. },
  4429. T: {
  4430. g:0,
  4431. c:null,
  4432. s:"[A-Z]{1,4}" // timezone abbrev. may be between 1 - 4 chars
  4433. },
  4434. Z: {
  4435. g:1,
  4436. c:"zz = results[{0}] * 1;\n" // -43200 <= UTC offset <= 50400
  4437. + "zz = (-43200 <= zz && zz <= 50400)? zz : null;\n",
  4438. s:"([+-]?\\d{1,5})" // leading '+' sign is optional for UTC offset
  4439. },
  4440. c: function() {
  4441. var calc = [],
  4442. arr = [
  4443. utilDate.formatCodeToRegex("Y", 1), // year
  4444. utilDate.formatCodeToRegex("m", 2), // month
  4445. utilDate.formatCodeToRegex("d", 3), // day
  4446. utilDate.formatCodeToRegex("H", 4), // hour
  4447. utilDate.formatCodeToRegex("i", 5), // minute
  4448. utilDate.formatCodeToRegex("s", 6), // second
  4449. {c:"ms = results[7] || '0'; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n"}, // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
  4450. {c:[ // allow either "Z" (i.e. UTC) or "-0530" or "+08:00" (i.e. UTC offset) timezone delimiters. assumes local timezone if no timezone is specified
  4451. "if(results[8]) {", // timezone specified
  4452. "if(results[8] == 'Z'){",
  4453. "zz = 0;", // UTC
  4454. "}else if (results[8].indexOf(':') > -1){",
  4455. utilDate.formatCodeToRegex("P", 8).c, // timezone offset with colon separator
  4456. "}else{",
  4457. utilDate.formatCodeToRegex("O", 8).c, // timezone offset without colon separator
  4458. "}",
  4459. "}"
  4460. ].join('\n')}
  4461. ],
  4462. i,
  4463. l;
  4464. for (i = 0, l = arr.length; i < l; ++i) {
  4465. calc.push(arr[i].c);
  4466. }
  4467. return {
  4468. g:1,
  4469. c:calc.join(""),
  4470. s:[
  4471. arr[0].s, // year (required)
  4472. "(?:", "-", arr[1].s, // month (optional)
  4473. "(?:", "-", arr[2].s, // day (optional)
  4474. "(?:",
  4475. "(?:T| )?", // time delimiter -- either a "T" or a single blank space
  4476. arr[3].s, ":", arr[4].s, // hour AND minute, delimited by a single colon (optional). MUST be preceded by either a "T" or a single blank space
  4477. "(?::", arr[5].s, ")?", // seconds (optional)
  4478. "(?:(?:\\.|,)(\\d+))?", // decimal fraction of a second (e.g. ",12345" or ".98765") (optional)
  4479. "(Z|(?:[-+]\\d{2}(?::)?\\d{2}))?", // "Z" (UTC) or "-0530" (UTC offset without colon delimiter) or "+08:00" (UTC offset with colon delimiter) (optional)
  4480. ")?",
  4481. ")?",
  4482. ")?"
  4483. ].join("")
  4484. };
  4485. },
  4486. U: {
  4487. g:1,
  4488. c:"u = parseInt(results[{0}], 10);\n",
  4489. s:"(-?\\d+)" // leading minus sign indicates seconds before UNIX epoch
  4490. }
  4491. },
  4492. //Old Ext.Date prototype methods.
  4493. // private
  4494. dateFormat: function(date, format) {
  4495. return utilDate.format(date, format);
  4496. },
  4497. /**
  4498. * Compares if two dates are equal by comparing their values.
  4499. * @param {Date} date1
  4500. * @param {Date} date2
  4501. * @return {Boolean} True if the date values are equal
  4502. */
  4503. isEqual: function(date1, date2) {
  4504. // check we have 2 date objects
  4505. if (date1 && date2) {
  4506. return (date1.getTime() === date2.getTime());
  4507. }
  4508. // one or both isn't a date, only equal if both are falsey
  4509. return !(date1 || date2);
  4510. },
  4511. /**
  4512. * Formats a date given the supplied format string.
  4513. * @param {Date} date The date to format
  4514. * @param {String} format The format string
  4515. * @return {String} The formatted date or an empty string if date parameter is not a JavaScript Date object
  4516. */
  4517. format: function(date, format) {
  4518. var formatFunctions = utilDate.formatFunctions;
  4519. if (!Ext.isDate(date)) {
  4520. return '';
  4521. }
  4522. if (formatFunctions[format] == null) {
  4523. utilDate.createFormat(format);
  4524. }
  4525. return formatFunctions[format].call(date) + '';
  4526. },
  4527. /**
  4528. * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
  4529. *
  4530. * Note: The date string returned by the javascript Date object's toString() method varies
  4531. * between browsers (e.g. FF vs IE) and system region settings (e.g. IE in Asia vs IE in America).
  4532. * For a given date string e.g. "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)",
  4533. * getTimezone() first tries to get the timezone abbreviation from between a pair of parentheses
  4534. * (which may or may not be present), failing which it proceeds to get the timezone abbreviation
  4535. * from the GMT offset portion of the date string.
  4536. * @param {Date} date The date
  4537. * @return {String} The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).
  4538. */
  4539. getTimezone : function(date) {
  4540. // the following list shows the differences between date strings from different browsers on a WinXP SP2 machine from an Asian locale:
  4541. //
  4542. // Opera : "Thu, 25 Oct 2007 22:53:45 GMT+0800" -- shortest (weirdest) date string of the lot
  4543. // Safari : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone (same as FF)
  4544. // FF : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone
  4545. // IE : "Thu Oct 25 22:54:35 UTC+0800 2007" -- (Asian system setting) look for 3-4 letter timezone abbrev
  4546. // IE : "Thu Oct 25 17:06:37 PDT 2007" -- (American system setting) look for 3-4 letter timezone abbrev
  4547. //
  4548. // this crazy regex attempts to guess the correct timezone abbreviation despite these differences.
  4549. // step 1: (?:\((.*)\) -- find timezone in parentheses
  4550. // step 2: ([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?) -- if nothing was found in step 1, find timezone from timezone offset portion of date string
  4551. // step 3: remove all non uppercase characters found in step 1 and 2
  4552. return date.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, "$1$2").replace(/[^A-Z]/g, "");
  4553. },
  4554. /**
  4555. * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
  4556. * @param {Date} date The date
  4557. * @param {Boolean} colon (optional) true to separate the hours and minutes with a colon (defaults to false).
  4558. * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600').
  4559. */
  4560. getGMTOffset : function(date, colon) {
  4561. var offset = date.getTimezoneOffset();
  4562. return (offset > 0 ? "-" : "+")
  4563. + Ext.String.leftPad(Math.floor(Math.abs(offset) / 60), 2, "0")
  4564. + (colon ? ":" : "")
  4565. + Ext.String.leftPad(Math.abs(offset % 60), 2, "0");
  4566. },
  4567. /**
  4568. * Get the numeric day number of the year, adjusted for leap year.
  4569. * @param {Date} date The date
  4570. * @return {Number} 0 to 364 (365 in leap years).
  4571. */
  4572. getDayOfYear: function(date) {
  4573. var num = 0,
  4574. d = Ext.Date.clone(date),
  4575. m = date.getMonth(),
  4576. i;
  4577. for (i = 0, d.setDate(1), d.setMonth(0); i < m; d.setMonth(++i)) {
  4578. num += utilDate.getDaysInMonth(d);
  4579. }
  4580. return num + date.getDate() - 1;
  4581. },
  4582. /**
  4583. * Get the numeric ISO-8601 week number of the year.
  4584. * (equivalent to the format specifier 'W', but without a leading zero).
  4585. * @param {Date} date The date
  4586. * @return {Number} 1 to 53
  4587. * @method
  4588. */
  4589. getWeekOfYear : (function() {
  4590. // adapted from http://www.merlyn.demon.co.uk/weekcalc.htm
  4591. var ms1d = 864e5, // milliseconds in a day
  4592. ms7d = 7 * ms1d; // milliseconds in a week
  4593. return function(date) { // return a closure so constants get calculated only once
  4594. var DC3 = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate() + 3) / ms1d, // an Absolute Day Number
  4595. AWN = Math.floor(DC3 / 7), // an Absolute Week Number
  4596. Wyr = new Date(AWN * ms7d).getUTCFullYear();
  4597. return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1;
  4598. };
  4599. }()),
  4600. /**
  4601. * Checks if the current date falls within a leap year.
  4602. * @param {Date} date The date
  4603. * @return {Boolean} True if the current date falls within a leap year, false otherwise.
  4604. */
  4605. isLeapYear : function(date) {
  4606. var year = date.getFullYear();
  4607. return !!((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
  4608. },
  4609. /**
  4610. * Get the first day of the current month, adjusted for leap year. The returned value
  4611. * is the numeric day index within the week (0-6) which can be used in conjunction with
  4612. * the {@link #monthNames} array to retrieve the textual day name.
  4613. * Example:
  4614. * <pre><code>
  4615. var dt = new Date('1/10/2007'),
  4616. firstDay = Ext.Date.getFirstDayOfMonth(dt);
  4617. console.log(Ext.Date.dayNames[firstDay]); //output: 'Monday'
  4618. * </code></pre>
  4619. * @param {Date} date The date
  4620. * @return {Number} The day number (0-6).
  4621. */
  4622. getFirstDayOfMonth : function(date) {
  4623. var day = (date.getDay() - (date.getDate() - 1)) % 7;
  4624. return (day < 0) ? (day + 7) : day;
  4625. },
  4626. /**
  4627. * Get the last day of the current month, adjusted for leap year. The returned value
  4628. * is the numeric day index within the week (0-6) which can be used in conjunction with
  4629. * the {@link #monthNames} array to retrieve the textual day name.
  4630. * Example:
  4631. * <pre><code>
  4632. var dt = new Date('1/10/2007'),
  4633. lastDay = Ext.Date.getLastDayOfMonth(dt);
  4634. console.log(Ext.Date.dayNames[lastDay]); //output: 'Wednesday'
  4635. * </code></pre>
  4636. * @param {Date} date The date
  4637. * @return {Number} The day number (0-6).
  4638. */
  4639. getLastDayOfMonth : function(date) {
  4640. return utilDate.getLastDateOfMonth(date).getDay();
  4641. },
  4642. /**
  4643. * Get the date of the first day of the month in which this date resides.
  4644. * @param {Date} date The date
  4645. * @return {Date}
  4646. */
  4647. getFirstDateOfMonth : function(date) {
  4648. return new Date(date.getFullYear(), date.getMonth(), 1);
  4649. },
  4650. /**
  4651. * Get the date of the last day of the month in which this date resides.
  4652. * @param {Date} date The date
  4653. * @return {Date}
  4654. */
  4655. getLastDateOfMonth : function(date) {
  4656. return new Date(date.getFullYear(), date.getMonth(), utilDate.getDaysInMonth(date));
  4657. },
  4658. /**
  4659. * Get the number of days in the current month, adjusted for leap year.
  4660. * @param {Date} date The date
  4661. * @return {Number} The number of days in the month.
  4662. * @method
  4663. */
  4664. getDaysInMonth: (function() {
  4665. var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  4666. return function(date) { // return a closure for efficiency
  4667. var m = date.getMonth();
  4668. return m == 1 && utilDate.isLeapYear(date) ? 29 : daysInMonth[m];
  4669. };
  4670. }()),
  4671. //<locale type="function">
  4672. /**
  4673. * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
  4674. * @param {Date} date The date
  4675. * @return {String} 'st, 'nd', 'rd' or 'th'.
  4676. */
  4677. getSuffix : function(date) {
  4678. switch (date.getDate()) {
  4679. case 1:
  4680. case 21:
  4681. case 31:
  4682. return "st";
  4683. case 2:
  4684. case 22:
  4685. return "nd";
  4686. case 3:
  4687. case 23:
  4688. return "rd";
  4689. default:
  4690. return "th";
  4691. }
  4692. },
  4693. //</locale>
  4694. /**
  4695. * Creates and returns a new Date instance with the exact same date value as the called instance.
  4696. * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
  4697. * variable will also be changed. When the intention is to create a new variable that will not
  4698. * modify the original instance, you should create a clone.
  4699. *
  4700. * Example of correctly cloning a date:
  4701. * <pre><code>
  4702. //wrong way:
  4703. var orig = new Date('10/1/2006');
  4704. var copy = orig;
  4705. copy.setDate(5);
  4706. console.log(orig); //returns 'Thu Oct 05 2006'!
  4707. //correct way:
  4708. var orig = new Date('10/1/2006'),
  4709. copy = Ext.Date.clone(orig);
  4710. copy.setDate(5);
  4711. console.log(orig); //returns 'Thu Oct 01 2006'
  4712. * </code></pre>
  4713. * @param {Date} date The date
  4714. * @return {Date} The new Date instance.
  4715. */
  4716. clone : function(date) {
  4717. return new Date(date.getTime());
  4718. },
  4719. /**
  4720. * Checks if the current date is affected by Daylight Saving Time (DST).
  4721. * @param {Date} date The date
  4722. * @return {Boolean} True if the current date is affected by DST.
  4723. */
  4724. isDST : function(date) {
  4725. // adapted from http://sencha.com/forum/showthread.php?p=247172#post247172
  4726. // courtesy of @geoffrey.mcgill
  4727. return new Date(date.getFullYear(), 0, 1).getTimezoneOffset() != date.getTimezoneOffset();
  4728. },
  4729. /**
  4730. * Attempts to clear all time information from this Date by setting the time to midnight of the same day,
  4731. * automatically adjusting for Daylight Saving Time (DST) where applicable.
  4732. * (note: DST timezone information for the browser's host operating system is assumed to be up-to-date)
  4733. * @param {Date} date The date
  4734. * @param {Boolean} clone true to create a clone of this date, clear the time and return it (defaults to false).
  4735. * @return {Date} this or the clone.
  4736. */
  4737. clearTime : function(date, clone) {
  4738. if (clone) {
  4739. return Ext.Date.clearTime(Ext.Date.clone(date));
  4740. }
  4741. // get current date before clearing time
  4742. var d = date.getDate(),
  4743. hr,
  4744. c;
  4745. // clear time
  4746. date.setHours(0);
  4747. date.setMinutes(0);
  4748. date.setSeconds(0);
  4749. date.setMilliseconds(0);
  4750. if (date.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
  4751. // note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the case)
  4752. // refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule
  4753. // increment hour until cloned date == current date
  4754. for (hr = 1, c = utilDate.add(date, Ext.Date.HOUR, hr); c.getDate() != d; hr++, c = utilDate.add(date, Ext.Date.HOUR, hr));
  4755. date.setDate(d);
  4756. date.setHours(c.getHours());
  4757. }
  4758. return date;
  4759. },
  4760. /**
  4761. * Provides a convenient method for performing basic date arithmetic. This method
  4762. * does not modify the Date instance being called - it creates and returns
  4763. * a new Date instance containing the resulting date value.
  4764. *
  4765. * Examples:
  4766. * <pre><code>
  4767. // Basic usage:
  4768. var dt = Ext.Date.add(new Date('10/29/2006'), Ext.Date.DAY, 5);
  4769. console.log(dt); //returns 'Fri Nov 03 2006 00:00:00'
  4770. // Negative values will be subtracted:
  4771. var dt2 = Ext.Date.add(new Date('10/1/2006'), Ext.Date.DAY, -5);
  4772. console.log(dt2); //returns 'Tue Sep 26 2006 00:00:00'
  4773. * </code></pre>
  4774. *
  4775. * @param {Date} date The date to modify
  4776. * @param {String} interval A valid date interval enum value.
  4777. * @param {Number} value The amount to add to the current date.
  4778. * @return {Date} The new Date instance.
  4779. */
  4780. add : function(date, interval, value) {
  4781. var d = Ext.Date.clone(date),
  4782. Date = Ext.Date,
  4783. day;
  4784. if (!interval || value === 0) {
  4785. return d;
  4786. }
  4787. switch(interval.toLowerCase()) {
  4788. case Ext.Date.MILLI:
  4789. d.setMilliseconds(d.getMilliseconds() + value);
  4790. break;
  4791. case Ext.Date.SECOND:
  4792. d.setSeconds(d.getSeconds() + value);
  4793. break;
  4794. case Ext.Date.MINUTE:
  4795. d.setMinutes(d.getMinutes() + value);
  4796. break;
  4797. case Ext.Date.HOUR:
  4798. d.setHours(d.getHours() + value);
  4799. break;
  4800. case Ext.Date.DAY:
  4801. d.setDate(d.getDate() + value);
  4802. break;
  4803. case Ext.Date.MONTH:
  4804. day = date.getDate();
  4805. if (day > 28) {
  4806. day = Math.min(day, Ext.Date.getLastDateOfMonth(Ext.Date.add(Ext.Date.getFirstDateOfMonth(date), Ext.Date.MONTH, value)).getDate());
  4807. }
  4808. d.setDate(day);
  4809. d.setMonth(date.getMonth() + value);
  4810. break;
  4811. case Ext.Date.YEAR:
  4812. day = date.getDate();
  4813. if (day > 28) {
  4814. day = Math.min(day, Ext.Date.getLastDateOfMonth(Ext.Date.add(Ext.Date.getFirstDateOfMonth(date), Ext.Date.YEAR, value)).getDate());
  4815. }
  4816. d.setDate(day);
  4817. d.setFullYear(date.getFullYear() + value);
  4818. break;
  4819. }
  4820. return d;
  4821. },
  4822. /**
  4823. * Checks if a date falls on or between the given start and end dates.
  4824. * @param {Date} date The date to check
  4825. * @param {Date} start Start date
  4826. * @param {Date} end End date
  4827. * @return {Boolean} true if this date falls on or between the given start and end dates.
  4828. */
  4829. between : function(date, start, end) {
  4830. var t = date.getTime();
  4831. return start.getTime() <= t && t <= end.getTime();
  4832. },
  4833. //Maintains compatibility with old static and prototype window.Date methods.
  4834. compat: function() {
  4835. var nativeDate = window.Date,
  4836. p, u,
  4837. statics = ['useStrict', 'formatCodeToRegex', 'parseFunctions', 'parseRegexes', 'formatFunctions', 'y2kYear', 'MILLI', 'SECOND', 'MINUTE', 'HOUR', 'DAY', 'MONTH', 'YEAR', 'defaults', 'dayNames', 'monthNames', 'monthNumbers', 'getShortMonthName', 'getShortDayName', 'getMonthNumber', 'formatCodes', 'isValid', 'parseDate', 'getFormatCode', 'createFormat', 'createParser', 'parseCodes'],
  4838. proto = ['dateFormat', 'format', 'getTimezone', 'getGMTOffset', 'getDayOfYear', 'getWeekOfYear', 'isLeapYear', 'getFirstDayOfMonth', 'getLastDayOfMonth', 'getDaysInMonth', 'getSuffix', 'clone', 'isDST', 'clearTime', 'add', 'between'],
  4839. sLen = statics.length,
  4840. pLen = proto.length,
  4841. stat, prot, s;
  4842. //Append statics
  4843. for (s = 0; s < sLen; s++) {
  4844. stat = statics[s];
  4845. nativeDate[stat] = utilDate[stat];
  4846. }
  4847. //Append to prototype
  4848. for (p = 0; p < pLen; p++) {
  4849. prot = proto[p];
  4850. nativeDate.prototype[prot] = function() {
  4851. var args = Array.prototype.slice.call(arguments);
  4852. args.unshift(this);
  4853. return utilDate[prot].apply(utilDate, args);
  4854. };
  4855. }
  4856. }
  4857. };
  4858. var utilDate = Ext.Date;
  4859. }());
  4860. //@tag foundation,core
  4861. //@require ../lang/Date.js
  4862. /**
  4863. * @author Jacky Nguyen <jacky@sencha.com>
  4864. * @docauthor Jacky Nguyen <jacky@sencha.com>
  4865. * @class Ext.Base
  4866. *
  4867. * The root of all classes created with {@link Ext#define}.
  4868. *
  4869. * Ext.Base is the building block of all Ext classes. All classes in Ext inherit from Ext.Base.
  4870. * All prototype and static members of this class are inherited by all other classes.
  4871. */
  4872. (function(flexSetter) {
  4873. var noArgs = [],
  4874. Base = function(){};
  4875. // These static properties will be copied to every newly created class with {@link Ext#define}
  4876. Ext.apply(Base, {
  4877. $className: 'Ext.Base',
  4878. $isClass: true,
  4879. /**
  4880. * Create a new instance of this Class.
  4881. *
  4882. * Ext.define('My.cool.Class', {
  4883. * ...
  4884. * });
  4885. *
  4886. * My.cool.Class.create({
  4887. * someConfig: true
  4888. * });
  4889. *
  4890. * All parameters are passed to the constructor of the class.
  4891. *
  4892. * @return {Object} the created instance.
  4893. * @static
  4894. * @inheritable
  4895. */
  4896. create: function() {
  4897. return Ext.create.apply(Ext, [this].concat(Array.prototype.slice.call(arguments, 0)));
  4898. },
  4899. /**
  4900. * @private
  4901. * @static
  4902. * @inheritable
  4903. * @param config
  4904. */
  4905. extend: function(parent) {
  4906. var parentPrototype = parent.prototype,
  4907. basePrototype, prototype, i, ln, name, statics;
  4908. prototype = this.prototype = Ext.Object.chain(parentPrototype);
  4909. prototype.self = this;
  4910. this.superclass = prototype.superclass = parentPrototype;
  4911. if (!parent.$isClass) {
  4912. basePrototype = Ext.Base.prototype;
  4913. for (i in basePrototype) {
  4914. if (i in prototype) {
  4915. prototype[i] = basePrototype[i];
  4916. }
  4917. }
  4918. }
  4919. // Statics inheritance
  4920. statics = parentPrototype.$inheritableStatics;
  4921. if (statics) {
  4922. for (i = 0,ln = statics.length; i < ln; i++) {
  4923. name = statics[i];
  4924. if (!this.hasOwnProperty(name)) {
  4925. this[name] = parent[name];
  4926. }
  4927. }
  4928. }
  4929. if (parent.$onExtended) {
  4930. this.$onExtended = parent.$onExtended.slice();
  4931. }
  4932. prototype.config = new prototype.configClass();
  4933. prototype.initConfigList = prototype.initConfigList.slice();
  4934. prototype.initConfigMap = Ext.clone(prototype.initConfigMap);
  4935. prototype.configMap = Ext.Object.chain(prototype.configMap);
  4936. },
  4937. /**
  4938. * @private
  4939. * @static
  4940. * @inheritable
  4941. */
  4942. $onExtended: [],
  4943. /**
  4944. * @private
  4945. * @static
  4946. * @inheritable
  4947. */
  4948. triggerExtended: function() {
  4949. var callbacks = this.$onExtended,
  4950. ln = callbacks.length,
  4951. i, callback;
  4952. if (ln > 0) {
  4953. for (i = 0; i < ln; i++) {
  4954. callback = callbacks[i];
  4955. callback.fn.apply(callback.scope || this, arguments);
  4956. }
  4957. }
  4958. },
  4959. /**
  4960. * @private
  4961. * @static
  4962. * @inheritable
  4963. */
  4964. onExtended: function(fn, scope) {
  4965. this.$onExtended.push({
  4966. fn: fn,
  4967. scope: scope
  4968. });
  4969. return this;
  4970. },
  4971. /**
  4972. * @private
  4973. * @static
  4974. * @inheritable
  4975. * @param config
  4976. */
  4977. addConfig: function(config, fullMerge) {
  4978. var prototype = this.prototype,
  4979. configNameCache = Ext.Class.configNameCache,
  4980. hasConfig = prototype.configMap,
  4981. initConfigList = prototype.initConfigList,
  4982. initConfigMap = prototype.initConfigMap,
  4983. defaultConfig = prototype.config,
  4984. initializedName, name, value;
  4985. for (name in config) {
  4986. if (config.hasOwnProperty(name)) {
  4987. if (!hasConfig[name]) {
  4988. hasConfig[name] = true;
  4989. }
  4990. value = config[name];
  4991. initializedName = configNameCache[name].initialized;
  4992. if (!initConfigMap[name] && value !== null && !prototype[initializedName]) {
  4993. initConfigMap[name] = true;
  4994. initConfigList.push(name);
  4995. }
  4996. }
  4997. }
  4998. if (fullMerge) {
  4999. Ext.merge(defaultConfig, config);
  5000. }
  5001. else {
  5002. Ext.mergeIf(defaultConfig, config);
  5003. }
  5004. prototype.configClass = Ext.Object.classify(defaultConfig);
  5005. },
  5006. /**
  5007. * Add / override static properties of this class.
  5008. *
  5009. * Ext.define('My.cool.Class', {
  5010. * ...
  5011. * });
  5012. *
  5013. * My.cool.Class.addStatics({
  5014. * someProperty: 'someValue', // My.cool.Class.someProperty = 'someValue'
  5015. * method1: function() { ... }, // My.cool.Class.method1 = function() { ... };
  5016. * method2: function() { ... } // My.cool.Class.method2 = function() { ... };
  5017. * });
  5018. *
  5019. * @param {Object} members
  5020. * @return {Ext.Base} this
  5021. * @static
  5022. * @inheritable
  5023. */
  5024. addStatics: function(members) {
  5025. var member, name;
  5026. for (name in members) {
  5027. if (members.hasOwnProperty(name)) {
  5028. member = members[name];
  5029. if (typeof member == 'function' && !member.$isClass && member !== Ext.emptyFn && member !== Ext.identityFn) {
  5030. member.$owner = this;
  5031. member.$name = name;
  5032. member.displayName = Ext.getClassName(this) + '.' + name;
  5033. }
  5034. this[name] = member;
  5035. }
  5036. }
  5037. return this;
  5038. },
  5039. /**
  5040. * @private
  5041. * @static
  5042. * @inheritable
  5043. * @param {Object} members
  5044. */
  5045. addInheritableStatics: function(members) {
  5046. var inheritableStatics,
  5047. hasInheritableStatics,
  5048. prototype = this.prototype,
  5049. name, member;
  5050. inheritableStatics = prototype.$inheritableStatics;
  5051. hasInheritableStatics = prototype.$hasInheritableStatics;
  5052. if (!inheritableStatics) {
  5053. inheritableStatics = prototype.$inheritableStatics = [];
  5054. hasInheritableStatics = prototype.$hasInheritableStatics = {};
  5055. }
  5056. for (name in members) {
  5057. if (members.hasOwnProperty(name)) {
  5058. member = members[name];
  5059. if (typeof member == 'function') {
  5060. member.displayName = Ext.getClassName(this) + '.' + name;
  5061. }
  5062. this[name] = member;
  5063. if (!hasInheritableStatics[name]) {
  5064. hasInheritableStatics[name] = true;
  5065. inheritableStatics.push(name);
  5066. }
  5067. }
  5068. }
  5069. return this;
  5070. },
  5071. /**
  5072. * Add methods / properties to the prototype of this class.
  5073. *
  5074. * Ext.define('My.awesome.Cat', {
  5075. * constructor: function() {
  5076. * ...
  5077. * }
  5078. * });
  5079. *
  5080. * My.awesome.Cat.addMembers({
  5081. * meow: function() {
  5082. * alert('Meowww...');
  5083. * }
  5084. * });
  5085. *
  5086. * var kitty = new My.awesome.Cat;
  5087. * kitty.meow();
  5088. *
  5089. * @param {Object} members
  5090. * @static
  5091. * @inheritable
  5092. */
  5093. addMembers: function(members) {
  5094. var prototype = this.prototype,
  5095. enumerables = Ext.enumerables,
  5096. names = [],
  5097. i, ln, name, member;
  5098. for (name in members) {
  5099. names.push(name);
  5100. }
  5101. if (enumerables) {
  5102. names.push.apply(names, enumerables);
  5103. }
  5104. for (i = 0,ln = names.length; i < ln; i++) {
  5105. name = names[i];
  5106. if (members.hasOwnProperty(name)) {
  5107. member = members[name];
  5108. if (typeof member == 'function' && !member.$isClass && member !== Ext.emptyFn) {
  5109. member.$owner = this;
  5110. member.$name = name;
  5111. member.displayName = (this.$className || '') + '#' + name;
  5112. }
  5113. prototype[name] = member;
  5114. }
  5115. }
  5116. return this;
  5117. },
  5118. /**
  5119. * @private
  5120. * @static
  5121. * @inheritable
  5122. * @param name
  5123. * @param member
  5124. */
  5125. addMember: function(name, member) {
  5126. if (typeof member == 'function' && !member.$isClass && member !== Ext.emptyFn) {
  5127. member.$owner = this;
  5128. member.$name = name;
  5129. member.displayName = (this.$className || '') + '#' + name;
  5130. }
  5131. this.prototype[name] = member;
  5132. return this;
  5133. },
  5134. /**
  5135. * Adds members to class.
  5136. * @static
  5137. * @inheritable
  5138. * @deprecated 4.1 Use {@link #addMembers} instead.
  5139. */
  5140. implement: function() {
  5141. this.addMembers.apply(this, arguments);
  5142. },
  5143. /**
  5144. * Borrow another class' members to the prototype of this class.
  5145. *
  5146. * Ext.define('Bank', {
  5147. * money: '$$$',
  5148. * printMoney: function() {
  5149. * alert('$$$$$$$');
  5150. * }
  5151. * });
  5152. *
  5153. * Ext.define('Thief', {
  5154. * ...
  5155. * });
  5156. *
  5157. * Thief.borrow(Bank, ['money', 'printMoney']);
  5158. *
  5159. * var steve = new Thief();
  5160. *
  5161. * alert(steve.money); // alerts '$$$'
  5162. * steve.printMoney(); // alerts '$$$$$$$'
  5163. *
  5164. * @param {Ext.Base} fromClass The class to borrow members from
  5165. * @param {Array/String} members The names of the members to borrow
  5166. * @return {Ext.Base} this
  5167. * @static
  5168. * @inheritable
  5169. * @private
  5170. */
  5171. borrow: function(fromClass, members) {
  5172. var prototype = this.prototype,
  5173. fromPrototype = fromClass.prototype,
  5174. className = Ext.getClassName(this),
  5175. i, ln, name, fn, toBorrow;
  5176. members = Ext.Array.from(members);
  5177. for (i = 0,ln = members.length; i < ln; i++) {
  5178. name = members[i];
  5179. toBorrow = fromPrototype[name];
  5180. if (typeof toBorrow == 'function') {
  5181. fn = Ext.Function.clone(toBorrow);
  5182. if (className) {
  5183. fn.displayName = className + '#' + name;
  5184. }
  5185. fn.$owner = this;
  5186. fn.$name = name;
  5187. prototype[name] = fn;
  5188. }
  5189. else {
  5190. prototype[name] = toBorrow;
  5191. }
  5192. }
  5193. return this;
  5194. },
  5195. /**
  5196. * Override members of this class. Overridden methods can be invoked via
  5197. * {@link Ext.Base#callParent}.
  5198. *
  5199. * Ext.define('My.Cat', {
  5200. * constructor: function() {
  5201. * alert("I'm a cat!");
  5202. * }
  5203. * });
  5204. *
  5205. * My.Cat.override({
  5206. * constructor: function() {
  5207. * alert("I'm going to be a cat!");
  5208. *
  5209. * this.callParent(arguments);
  5210. *
  5211. * alert("Meeeeoooowwww");
  5212. * }
  5213. * });
  5214. *
  5215. * var kitty = new My.Cat(); // alerts "I'm going to be a cat!"
  5216. * // alerts "I'm a cat!"
  5217. * // alerts "Meeeeoooowwww"
  5218. *
  5219. * As of 4.1, direct use of this method is deprecated. Use {@link Ext#define Ext.define}
  5220. * instead:
  5221. *
  5222. * Ext.define('My.CatOverride', {
  5223. * override: 'My.Cat',
  5224. * constructor: function() {
  5225. * alert("I'm going to be a cat!");
  5226. *
  5227. * this.callParent(arguments);
  5228. *
  5229. * alert("Meeeeoooowwww");
  5230. * }
  5231. * });
  5232. *
  5233. * The above accomplishes the same result but can be managed by the {@link Ext.Loader}
  5234. * which can properly order the override and its target class and the build process
  5235. * can determine whether the override is needed based on the required state of the
  5236. * target class (My.Cat).
  5237. *
  5238. * @param {Object} members The properties to add to this class. This should be
  5239. * specified as an object literal containing one or more properties.
  5240. * @return {Ext.Base} this class
  5241. * @static
  5242. * @inheritable
  5243. * @markdown
  5244. * @deprecated 4.1.0 Use {@link Ext#define Ext.define} instead
  5245. */
  5246. override: function(members) {
  5247. var me = this,
  5248. enumerables = Ext.enumerables,
  5249. target = me.prototype,
  5250. cloneFunction = Ext.Function.clone,
  5251. name, index, member, statics, names, previous;
  5252. if (arguments.length === 2) {
  5253. name = members;
  5254. members = {};
  5255. members[name] = arguments[1];
  5256. enumerables = null;
  5257. }
  5258. do {
  5259. names = []; // clean slate for prototype (1st pass) and static (2nd pass)
  5260. statics = null; // not needed 1st pass, but needs to be cleared for 2nd pass
  5261. for (name in members) { // hasOwnProperty is checked in the next loop...
  5262. if (name == 'statics') {
  5263. statics = members[name];
  5264. } else if (name == 'config') {
  5265. me.addConfig(members[name], true);
  5266. } else {
  5267. names.push(name);
  5268. }
  5269. }
  5270. if (enumerables) {
  5271. names.push.apply(names, enumerables);
  5272. }
  5273. for (index = names.length; index--; ) {
  5274. name = names[index];
  5275. if (members.hasOwnProperty(name)) {
  5276. member = members[name];
  5277. if (typeof member == 'function' && !member.$className && member !== Ext.emptyFn) {
  5278. if (typeof member.$owner != 'undefined') {
  5279. member = cloneFunction(member);
  5280. }
  5281. if (me.$className) {
  5282. member.displayName = me.$className + '#' + name;
  5283. }
  5284. member.$owner = me;
  5285. member.$name = name;
  5286. previous = target[name];
  5287. if (previous) {
  5288. member.$previous = previous;
  5289. }
  5290. }
  5291. target[name] = member;
  5292. }
  5293. }
  5294. target = me; // 2nd pass is for statics
  5295. members = statics; // statics will be null on 2nd pass
  5296. } while (members);
  5297. return this;
  5298. },
  5299. // Documented downwards
  5300. callParent: function(args) {
  5301. var method;
  5302. // This code is intentionally inlined for the least number of debugger stepping
  5303. return (method = this.callParent.caller) && (method.$previous ||
  5304. ((method = method.$owner ? method : method.caller) &&
  5305. method.$owner.superclass.self[method.$name])).apply(this, args || noArgs);
  5306. },
  5307. // Documented downwards
  5308. callSuper: function(args) {
  5309. var method;
  5310. // This code is intentionally inlined for the least number of debugger stepping
  5311. return (method = this.callSuper.caller) &&
  5312. ((method = method.$owner ? method : method.caller) &&
  5313. method.$owner.superclass.self[method.$name]).apply(this, args || noArgs);
  5314. },
  5315. /**
  5316. * Used internally by the mixins pre-processor
  5317. * @private
  5318. * @static
  5319. * @inheritable
  5320. */
  5321. mixin: function(name, mixinClass) {
  5322. var mixin = mixinClass.prototype,
  5323. prototype = this.prototype,
  5324. key;
  5325. if (typeof mixin.onClassMixedIn != 'undefined') {
  5326. mixin.onClassMixedIn.call(mixinClass, this);
  5327. }
  5328. if (!prototype.hasOwnProperty('mixins')) {
  5329. if ('mixins' in prototype) {
  5330. prototype.mixins = Ext.Object.chain(prototype.mixins);
  5331. }
  5332. else {
  5333. prototype.mixins = {};
  5334. }
  5335. }
  5336. for (key in mixin) {
  5337. if (key === 'mixins') {
  5338. Ext.merge(prototype.mixins, mixin[key]);
  5339. }
  5340. else if (typeof prototype[key] == 'undefined' && key != 'mixinId' && key != 'config') {
  5341. prototype[key] = mixin[key];
  5342. }
  5343. }
  5344. if ('config' in mixin) {
  5345. this.addConfig(mixin.config, false);
  5346. }
  5347. prototype.mixins[name] = mixin;
  5348. },
  5349. /**
  5350. * Get the current class' name in string format.
  5351. *
  5352. * Ext.define('My.cool.Class', {
  5353. * constructor: function() {
  5354. * alert(this.self.getName()); // alerts 'My.cool.Class'
  5355. * }
  5356. * });
  5357. *
  5358. * My.cool.Class.getName(); // 'My.cool.Class'
  5359. *
  5360. * @return {String} className
  5361. * @static
  5362. * @inheritable
  5363. */
  5364. getName: function() {
  5365. return Ext.getClassName(this);
  5366. },
  5367. /**
  5368. * Create aliases for existing prototype methods. Example:
  5369. *
  5370. * Ext.define('My.cool.Class', {
  5371. * method1: function() { ... },
  5372. * method2: function() { ... }
  5373. * });
  5374. *
  5375. * var test = new My.cool.Class();
  5376. *
  5377. * My.cool.Class.createAlias({
  5378. * method3: 'method1',
  5379. * method4: 'method2'
  5380. * });
  5381. *
  5382. * test.method3(); // test.method1()
  5383. *
  5384. * My.cool.Class.createAlias('method5', 'method3');
  5385. *
  5386. * test.method5(); // test.method3() -> test.method1()
  5387. *
  5388. * @param {String/Object} alias The new method name, or an object to set multiple aliases. See
  5389. * {@link Ext.Function#flexSetter flexSetter}
  5390. * @param {String/Object} origin The original method name
  5391. * @static
  5392. * @inheritable
  5393. * @method
  5394. */
  5395. createAlias: flexSetter(function(alias, origin) {
  5396. this.override(alias, function() {
  5397. return this[origin].apply(this, arguments);
  5398. });
  5399. }),
  5400. /**
  5401. * @private
  5402. * @static
  5403. * @inheritable
  5404. */
  5405. addXtype: function(xtype) {
  5406. var prototype = this.prototype,
  5407. xtypesMap = prototype.xtypesMap,
  5408. xtypes = prototype.xtypes,
  5409. xtypesChain = prototype.xtypesChain;
  5410. if (!prototype.hasOwnProperty('xtypesMap')) {
  5411. xtypesMap = prototype.xtypesMap = Ext.merge({}, prototype.xtypesMap || {});
  5412. xtypes = prototype.xtypes = prototype.xtypes ? [].concat(prototype.xtypes) : [];
  5413. xtypesChain = prototype.xtypesChain = prototype.xtypesChain ? [].concat(prototype.xtypesChain) : [];
  5414. prototype.xtype = xtype;
  5415. }
  5416. if (!xtypesMap[xtype]) {
  5417. xtypesMap[xtype] = true;
  5418. xtypes.push(xtype);
  5419. xtypesChain.push(xtype);
  5420. Ext.ClassManager.setAlias(this, 'widget.' + xtype);
  5421. }
  5422. return this;
  5423. }
  5424. });
  5425. Base.implement({
  5426. /** @private */
  5427. isInstance: true,
  5428. /** @private */
  5429. $className: 'Ext.Base',
  5430. /** @private */
  5431. configClass: Ext.emptyFn,
  5432. /** @private */
  5433. initConfigList: [],
  5434. /** @private */
  5435. configMap: {},
  5436. /** @private */
  5437. initConfigMap: {},
  5438. /**
  5439. * Get the reference to the class from which this object was instantiated. Note that unlike {@link Ext.Base#self},
  5440. * `this.statics()` is scope-independent and it always returns the class from which it was called, regardless of what
  5441. * `this` points to during run-time
  5442. *
  5443. * Ext.define('My.Cat', {
  5444. * statics: {
  5445. * totalCreated: 0,
  5446. * speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
  5447. * },
  5448. *
  5449. * constructor: function() {
  5450. * var statics = this.statics();
  5451. *
  5452. * alert(statics.speciesName); // always equals to 'Cat' no matter what 'this' refers to
  5453. * // equivalent to: My.Cat.speciesName
  5454. *
  5455. * alert(this.self.speciesName); // dependent on 'this'
  5456. *
  5457. * statics.totalCreated++;
  5458. * },
  5459. *
  5460. * clone: function() {
  5461. * var cloned = new this.self; // dependent on 'this'
  5462. *
  5463. * cloned.groupName = this.statics().speciesName; // equivalent to: My.Cat.speciesName
  5464. *
  5465. * return cloned;
  5466. * }
  5467. * });
  5468. *
  5469. *
  5470. * Ext.define('My.SnowLeopard', {
  5471. * extend: 'My.Cat',
  5472. *
  5473. * statics: {
  5474. * speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'
  5475. * },
  5476. *
  5477. * constructor: function() {
  5478. * this.callParent();
  5479. * }
  5480. * });
  5481. *
  5482. * var cat = new My.Cat(); // alerts 'Cat', then alerts 'Cat'
  5483. *
  5484. * var snowLeopard = new My.SnowLeopard(); // alerts 'Cat', then alerts 'Snow Leopard'
  5485. *
  5486. * var clone = snowLeopard.clone();
  5487. * alert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'
  5488. * alert(clone.groupName); // alerts 'Cat'
  5489. *
  5490. * alert(My.Cat.totalCreated); // alerts 3
  5491. *
  5492. * @protected
  5493. * @return {Ext.Class}
  5494. */
  5495. statics: function() {
  5496. var method = this.statics.caller,
  5497. self = this.self;
  5498. if (!method) {
  5499. return self;
  5500. }
  5501. return method.$owner;
  5502. },
  5503. /**
  5504. * Call the "parent" method of the current method. That is the method previously
  5505. * overridden by derivation or by an override (see {@link Ext#define}).
  5506. *
  5507. * Ext.define('My.Base', {
  5508. * constructor: function (x) {
  5509. * this.x = x;
  5510. * },
  5511. *
  5512. * statics: {
  5513. * method: function (x) {
  5514. * return x;
  5515. * }
  5516. * }
  5517. * });
  5518. *
  5519. * Ext.define('My.Derived', {
  5520. * extend: 'My.Base',
  5521. *
  5522. * constructor: function () {
  5523. * this.callParent([21]);
  5524. * }
  5525. * });
  5526. *
  5527. * var obj = new My.Derived();
  5528. *
  5529. * alert(obj.x); // alerts 21
  5530. *
  5531. * This can be used with an override as follows:
  5532. *
  5533. * Ext.define('My.DerivedOverride', {
  5534. * override: 'My.Derived',
  5535. *
  5536. * constructor: function (x) {
  5537. * this.callParent([x*2]); // calls original My.Derived constructor
  5538. * }
  5539. * });
  5540. *
  5541. * var obj = new My.Derived();
  5542. *
  5543. * alert(obj.x); // now alerts 42
  5544. *
  5545. * This also works with static methods.
  5546. *
  5547. * Ext.define('My.Derived2', {
  5548. * extend: 'My.Base',
  5549. *
  5550. * statics: {
  5551. * method: function (x) {
  5552. * return this.callParent([x*2]); // calls My.Base.method
  5553. * }
  5554. * }
  5555. * });
  5556. *
  5557. * alert(My.Base.method(10); // alerts 10
  5558. * alert(My.Derived2.method(10); // alerts 20
  5559. *
  5560. * Lastly, it also works with overridden static methods.
  5561. *
  5562. * Ext.define('My.Derived2Override', {
  5563. * override: 'My.Derived2',
  5564. *
  5565. * statics: {
  5566. * method: function (x) {
  5567. * return this.callParent([x*2]); // calls My.Derived2.method
  5568. * }
  5569. * }
  5570. * });
  5571. *
  5572. * alert(My.Derived2.method(10); // now alerts 40
  5573. *
  5574. * To override a method and replace it and also call the superclass method, use
  5575. * {@link #callSuper}. This is often done to patch a method to fix a bug.
  5576. *
  5577. * @protected
  5578. * @param {Array/Arguments} args The arguments, either an array or the `arguments` object
  5579. * from the current method, for example: `this.callParent(arguments)`
  5580. * @return {Object} Returns the result of calling the parent method
  5581. */
  5582. callParent: function(args) {
  5583. // NOTE: this code is deliberately as few expressions (and no function calls)
  5584. // as possible so that a debugger can skip over this noise with the minimum number
  5585. // of steps. Basically, just hit Step Into until you are where you really wanted
  5586. // to be.
  5587. var method,
  5588. superMethod = (method = this.callParent.caller) && (method.$previous ||
  5589. ((method = method.$owner ? method : method.caller) &&
  5590. method.$owner.superclass[method.$name]));
  5591. if (!superMethod) {
  5592. method = this.callParent.caller;
  5593. var parentClass, methodName;
  5594. if (!method.$owner) {
  5595. if (!method.caller) {
  5596. throw new Error("Attempting to call a protected method from the public scope, which is not allowed");
  5597. }
  5598. method = method.caller;
  5599. }
  5600. parentClass = method.$owner.superclass;
  5601. methodName = method.$name;
  5602. if (!(methodName in parentClass)) {
  5603. throw new Error("this.callParent() was called but there's no such method (" + methodName +
  5604. ") found in the parent class (" + (Ext.getClassName(parentClass) || 'Object') + ")");
  5605. }
  5606. }
  5607. return superMethod.apply(this, args || noArgs);
  5608. },
  5609. /**
  5610. * This method is used by an override to call the superclass method but bypass any
  5611. * overridden method. This is often done to "patch" a method that contains a bug
  5612. * but for whatever reason cannot be fixed directly.
  5613. *
  5614. * Consider:
  5615. *
  5616. * Ext.define('Ext.some.Class', {
  5617. * method: function () {
  5618. * console.log('Good');
  5619. * }
  5620. * });
  5621. *
  5622. * Ext.define('Ext.some.DerivedClass', {
  5623. * method: function () {
  5624. * console.log('Bad');
  5625. *
  5626. * // ... logic but with a bug ...
  5627. *
  5628. * this.callParent();
  5629. * }
  5630. * });
  5631. *
  5632. * To patch the bug in `DerivedClass.method`, the typical solution is to create an
  5633. * override:
  5634. *
  5635. * Ext.define('App.paches.DerivedClass', {
  5636. * override: 'Ext.some.DerivedClass',
  5637. *
  5638. * method: function () {
  5639. * console.log('Fixed');
  5640. *
  5641. * // ... logic but with bug fixed ...
  5642. *
  5643. * this.callSuper();
  5644. * }
  5645. * });
  5646. *
  5647. * The patch method cannot use `callParent` to call the superclass `method` since
  5648. * that would call the overridden method containing the bug. In other words, the
  5649. * above patch would only produce "Fixed" then "Good" in the console log, whereas,
  5650. * using `callParent` would produce "Fixed" then "Bad" then "Good".
  5651. *
  5652. * @protected
  5653. * @param {Array/Arguments} args The arguments, either an array or the `arguments` object
  5654. * from the current method, for example: `this.callSuper(arguments)`
  5655. * @return {Object} Returns the result of calling the superclass method
  5656. */
  5657. callSuper: function(args) {
  5658. // NOTE: this code is deliberately as few expressions (and no function calls)
  5659. // as possible so that a debugger can skip over this noise with the minimum number
  5660. // of steps. Basically, just hit Step Into until you are where you really wanted
  5661. // to be.
  5662. var method,
  5663. superMethod = (method = this.callSuper.caller) &&
  5664. ((method = method.$owner ? method : method.caller) &&
  5665. method.$owner.superclass[method.$name]);
  5666. if (!superMethod) {
  5667. method = this.callSuper.caller;
  5668. var parentClass, methodName;
  5669. if (!method.$owner) {
  5670. if (!method.caller) {
  5671. throw new Error("Attempting to call a protected method from the public scope, which is not allowed");
  5672. }
  5673. method = method.caller;
  5674. }
  5675. parentClass = method.$owner.superclass;
  5676. methodName = method.$name;
  5677. if (!(methodName in parentClass)) {
  5678. throw new Error("this.callSuper() was called but there's no such method (" + methodName +
  5679. ") found in the parent class (" + (Ext.getClassName(parentClass) || 'Object') + ")");
  5680. }
  5681. }
  5682. return superMethod.apply(this, args || noArgs);
  5683. },
  5684. /**
  5685. * @property {Ext.Class} self
  5686. *
  5687. * Get the reference to the current class from which this object was instantiated. Unlike {@link Ext.Base#statics},
  5688. * `this.self` is scope-dependent and it's meant to be used for dynamic inheritance. See {@link Ext.Base#statics}
  5689. * for a detailed comparison
  5690. *
  5691. * Ext.define('My.Cat', {
  5692. * statics: {
  5693. * speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
  5694. * },
  5695. *
  5696. * constructor: function() {
  5697. * alert(this.self.speciesName); // dependent on 'this'
  5698. * },
  5699. *
  5700. * clone: function() {
  5701. * return new this.self();
  5702. * }
  5703. * });
  5704. *
  5705. *
  5706. * Ext.define('My.SnowLeopard', {
  5707. * extend: 'My.Cat',
  5708. * statics: {
  5709. * speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'
  5710. * }
  5711. * });
  5712. *
  5713. * var cat = new My.Cat(); // alerts 'Cat'
  5714. * var snowLeopard = new My.SnowLeopard(); // alerts 'Snow Leopard'
  5715. *
  5716. * var clone = snowLeopard.clone();
  5717. * alert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'
  5718. *
  5719. * @protected
  5720. */
  5721. self: Base,
  5722. // Default constructor, simply returns `this`
  5723. constructor: function() {
  5724. return this;
  5725. },
  5726. /**
  5727. * Initialize configuration for this class. a typical example:
  5728. *
  5729. * Ext.define('My.awesome.Class', {
  5730. * // The default config
  5731. * config: {
  5732. * name: 'Awesome',
  5733. * isAwesome: true
  5734. * },
  5735. *
  5736. * constructor: function(config) {
  5737. * this.initConfig(config);
  5738. * }
  5739. * });
  5740. *
  5741. * var awesome = new My.awesome.Class({
  5742. * name: 'Super Awesome'
  5743. * });
  5744. *
  5745. * alert(awesome.getName()); // 'Super Awesome'
  5746. *
  5747. * @protected
  5748. * @param {Object} config
  5749. * @return {Ext.Base} this
  5750. */
  5751. initConfig: function(config) {
  5752. var instanceConfig = config,
  5753. configNameCache = Ext.Class.configNameCache,
  5754. defaultConfig = new this.configClass(),
  5755. defaultConfigList = this.initConfigList,
  5756. hasConfig = this.configMap,
  5757. nameMap, i, ln, name, initializedName;
  5758. this.initConfig = Ext.emptyFn;
  5759. this.initialConfig = instanceConfig || {};
  5760. this.config = config = (instanceConfig) ? Ext.merge(defaultConfig, config) : defaultConfig;
  5761. if (instanceConfig) {
  5762. defaultConfigList = defaultConfigList.slice();
  5763. for (name in instanceConfig) {
  5764. if (hasConfig[name]) {
  5765. if (instanceConfig[name] !== null) {
  5766. defaultConfigList.push(name);
  5767. this[configNameCache[name].initialized] = false;
  5768. }
  5769. }
  5770. }
  5771. }
  5772. for (i = 0,ln = defaultConfigList.length; i < ln; i++) {
  5773. name = defaultConfigList[i];
  5774. nameMap = configNameCache[name];
  5775. initializedName = nameMap.initialized;
  5776. if (!this[initializedName]) {
  5777. this[initializedName] = true;
  5778. this[nameMap.set].call(this, config[name]);
  5779. }
  5780. }
  5781. return this;
  5782. },
  5783. /**
  5784. * @private
  5785. * @param config
  5786. */
  5787. hasConfig: function(name) {
  5788. return Boolean(this.configMap[name]);
  5789. },
  5790. /**
  5791. * @private
  5792. */
  5793. setConfig: function(config, applyIfNotSet) {
  5794. if (!config) {
  5795. return this;
  5796. }
  5797. var configNameCache = Ext.Class.configNameCache,
  5798. currentConfig = this.config,
  5799. hasConfig = this.configMap,
  5800. initialConfig = this.initialConfig,
  5801. name, value;
  5802. applyIfNotSet = Boolean(applyIfNotSet);
  5803. for (name in config) {
  5804. if (applyIfNotSet && initialConfig.hasOwnProperty(name)) {
  5805. continue;
  5806. }
  5807. value = config[name];
  5808. currentConfig[name] = value;
  5809. if (hasConfig[name]) {
  5810. this[configNameCache[name].set](value);
  5811. }
  5812. }
  5813. return this;
  5814. },
  5815. /**
  5816. * @private
  5817. * @param name
  5818. */
  5819. getConfig: function(name) {
  5820. var configNameCache = Ext.Class.configNameCache;
  5821. return this[configNameCache[name].get]();
  5822. },
  5823. /**
  5824. * Returns the initial configuration passed to constructor when instantiating
  5825. * this class.
  5826. * @param {String} [name] Name of the config option to return.
  5827. * @return {Object/Mixed} The full config object or a single config value
  5828. * when `name` parameter specified.
  5829. */
  5830. getInitialConfig: function(name) {
  5831. var config = this.config;
  5832. if (!name) {
  5833. return config;
  5834. }
  5835. else {
  5836. return config[name];
  5837. }
  5838. },
  5839. /**
  5840. * @private
  5841. * @param names
  5842. * @param callback
  5843. * @param scope
  5844. */
  5845. onConfigUpdate: function(names, callback, scope) {
  5846. var self = this.self,
  5847. className = self.$className,
  5848. i, ln, name,
  5849. updaterName, updater, newUpdater;
  5850. names = Ext.Array.from(names);
  5851. scope = scope || this;
  5852. for (i = 0,ln = names.length; i < ln; i++) {
  5853. name = names[i];
  5854. updaterName = 'update' + Ext.String.capitalize(name);
  5855. updater = this[updaterName] || Ext.emptyFn;
  5856. newUpdater = function() {
  5857. updater.apply(this, arguments);
  5858. scope[callback].apply(scope, arguments);
  5859. };
  5860. newUpdater.$name = updaterName;
  5861. newUpdater.$owner = self;
  5862. newUpdater.displayName = className + '#' + updaterName;
  5863. this[updaterName] = newUpdater;
  5864. }
  5865. },
  5866. /**
  5867. * @private
  5868. */
  5869. destroy: function() {
  5870. this.destroy = Ext.emptyFn;
  5871. }
  5872. });
  5873. /**
  5874. * Call the original method that was previously overridden with {@link Ext.Base#override}
  5875. *
  5876. * Ext.define('My.Cat', {
  5877. * constructor: function() {
  5878. * alert("I'm a cat!");
  5879. * }
  5880. * });
  5881. *
  5882. * My.Cat.override({
  5883. * constructor: function() {
  5884. * alert("I'm going to be a cat!");
  5885. *
  5886. * this.callOverridden();
  5887. *
  5888. * alert("Meeeeoooowwww");
  5889. * }
  5890. * });
  5891. *
  5892. * var kitty = new My.Cat(); // alerts "I'm going to be a cat!"
  5893. * // alerts "I'm a cat!"
  5894. * // alerts "Meeeeoooowwww"
  5895. *
  5896. * @param {Array/Arguments} args The arguments, either an array or the `arguments` object
  5897. * from the current method, for example: `this.callOverridden(arguments)`
  5898. * @return {Object} Returns the result of calling the overridden method
  5899. * @protected
  5900. * @deprecated as of 4.1. Use {@link #callParent} instead.
  5901. */
  5902. Base.prototype.callOverridden = Base.prototype.callParent;
  5903. Ext.Base = Base;
  5904. }(Ext.Function.flexSetter));
  5905. //@tag foundation,core
  5906. //@require Base.js
  5907. /**
  5908. * @author Jacky Nguyen <jacky@sencha.com>
  5909. * @docauthor Jacky Nguyen <jacky@sencha.com>
  5910. * @class Ext.Class
  5911. *
  5912. * Handles class creation throughout the framework. This is a low level factory that is used by Ext.ClassManager and generally
  5913. * should not be used directly. If you choose to use Ext.Class you will lose out on the namespace, aliasing and depency loading
  5914. * features made available by Ext.ClassManager. The only time you would use Ext.Class directly is to create an anonymous class.
  5915. *
  5916. * If you wish to create a class you should use {@link Ext#define Ext.define} which aliases
  5917. * {@link Ext.ClassManager#create Ext.ClassManager.create} to enable namespacing and dynamic dependency resolution.
  5918. *
  5919. * Ext.Class is the factory and **not** the superclass of everything. For the base class that **all** Ext classes inherit
  5920. * from, see {@link Ext.Base}.
  5921. */
  5922. (function() {
  5923. var ExtClass,
  5924. Base = Ext.Base,
  5925. baseStaticMembers = [],
  5926. baseStaticMember, baseStaticMemberLength;
  5927. for (baseStaticMember in Base) {
  5928. if (Base.hasOwnProperty(baseStaticMember)) {
  5929. baseStaticMembers.push(baseStaticMember);
  5930. }
  5931. }
  5932. baseStaticMemberLength = baseStaticMembers.length;
  5933. // Creates a constructor that has nothing extra in its scope chain.
  5934. function makeCtor (className) {
  5935. function constructor () {
  5936. // Opera has some problems returning from a constructor when Dragonfly isn't running. The || null seems to
  5937. // be sufficient to stop it misbehaving. Known to be required against 10.53, 11.51 and 11.61.
  5938. return this.constructor.apply(this, arguments) || null;
  5939. }
  5940. if (className) {
  5941. constructor.displayName = className;
  5942. }
  5943. return constructor;
  5944. }
  5945. /**
  5946. * @method constructor
  5947. * Create a new anonymous class.
  5948. *
  5949. * @param {Object} data An object represent the properties of this class
  5950. * @param {Function} onCreated Optional, the callback function to be executed when this class is fully created.
  5951. * Note that the creation process can be asynchronous depending on the pre-processors used.
  5952. *
  5953. * @return {Ext.Base} The newly created class
  5954. */
  5955. Ext.Class = ExtClass = function(Class, data, onCreated) {
  5956. if (typeof Class != 'function') {
  5957. onCreated = data;
  5958. data = Class;
  5959. Class = null;
  5960. }
  5961. if (!data) {
  5962. data = {};
  5963. }
  5964. Class = ExtClass.create(Class, data);
  5965. ExtClass.process(Class, data, onCreated);
  5966. return Class;
  5967. };
  5968. Ext.apply(ExtClass, {
  5969. /**
  5970. * @private
  5971. * @param Class
  5972. * @param data
  5973. * @param hooks
  5974. */
  5975. onBeforeCreated: function(Class, data, hooks) {
  5976. Class.addMembers(data);
  5977. hooks.onCreated.call(Class, Class);
  5978. },
  5979. /**
  5980. * @private
  5981. * @param Class
  5982. * @param classData
  5983. * @param onClassCreated
  5984. */
  5985. create: function(Class, data) {
  5986. var name, i;
  5987. if (!Class) {
  5988. Class = makeCtor(
  5989. data.$className
  5990. );
  5991. }
  5992. for (i = 0; i < baseStaticMemberLength; i++) {
  5993. name = baseStaticMembers[i];
  5994. Class[name] = Base[name];
  5995. }
  5996. return Class;
  5997. },
  5998. /**
  5999. * @private
  6000. * @param Class
  6001. * @param data
  6002. * @param onCreated
  6003. */
  6004. process: function(Class, data, onCreated) {
  6005. var preprocessorStack = data.preprocessors || ExtClass.defaultPreprocessors,
  6006. registeredPreprocessors = this.preprocessors,
  6007. hooks = {
  6008. onBeforeCreated: this.onBeforeCreated
  6009. },
  6010. preprocessors = [],
  6011. preprocessor, preprocessorsProperties,
  6012. i, ln, j, subLn, preprocessorProperty, process;
  6013. delete data.preprocessors;
  6014. for (i = 0,ln = preprocessorStack.length; i < ln; i++) {
  6015. preprocessor = preprocessorStack[i];
  6016. if (typeof preprocessor == 'string') {
  6017. preprocessor = registeredPreprocessors[preprocessor];
  6018. preprocessorsProperties = preprocessor.properties;
  6019. if (preprocessorsProperties === true) {
  6020. preprocessors.push(preprocessor.fn);
  6021. }
  6022. else if (preprocessorsProperties) {
  6023. for (j = 0,subLn = preprocessorsProperties.length; j < subLn; j++) {
  6024. preprocessorProperty = preprocessorsProperties[j];
  6025. if (data.hasOwnProperty(preprocessorProperty)) {
  6026. preprocessors.push(preprocessor.fn);
  6027. break;
  6028. }
  6029. }
  6030. }
  6031. }
  6032. else {
  6033. preprocessors.push(preprocessor);
  6034. }
  6035. }
  6036. hooks.onCreated = onCreated ? onCreated : Ext.emptyFn;
  6037. hooks.preprocessors = preprocessors;
  6038. this.doProcess(Class, data, hooks);
  6039. },
  6040. doProcess: function(Class, data, hooks){
  6041. var me = this,
  6042. preprocessor = hooks.preprocessors.shift();
  6043. if (!preprocessor) {
  6044. hooks.onBeforeCreated.apply(me, arguments);
  6045. return;
  6046. }
  6047. if (preprocessor.call(me, Class, data, hooks, me.doProcess) !== false) {
  6048. me.doProcess(Class, data, hooks);
  6049. }
  6050. },
  6051. /** @private */
  6052. preprocessors: {},
  6053. /**
  6054. * Register a new pre-processor to be used during the class creation process
  6055. *
  6056. * @param {String} name The pre-processor's name
  6057. * @param {Function} fn The callback function to be executed. Typical format:
  6058. *
  6059. * function(cls, data, fn) {
  6060. * // Your code here
  6061. *
  6062. * // Execute this when the processing is finished.
  6063. * // Asynchronous processing is perfectly ok
  6064. * if (fn) {
  6065. * fn.call(this, cls, data);
  6066. * }
  6067. * });
  6068. *
  6069. * @param {Function} fn.cls The created class
  6070. * @param {Object} fn.data The set of properties passed in {@link Ext.Class} constructor
  6071. * @param {Function} fn.fn The callback function that **must** to be executed when this
  6072. * pre-processor finishes, regardless of whether the processing is synchronous or aynchronous.
  6073. * @return {Ext.Class} this
  6074. * @private
  6075. * @static
  6076. */
  6077. registerPreprocessor: function(name, fn, properties, position, relativeTo) {
  6078. if (!position) {
  6079. position = 'last';
  6080. }
  6081. if (!properties) {
  6082. properties = [name];
  6083. }
  6084. this.preprocessors[name] = {
  6085. name: name,
  6086. properties: properties || false,
  6087. fn: fn
  6088. };
  6089. this.setDefaultPreprocessorPosition(name, position, relativeTo);
  6090. return this;
  6091. },
  6092. /**
  6093. * Retrieve a pre-processor callback function by its name, which has been registered before
  6094. *
  6095. * @param {String} name
  6096. * @return {Function} preprocessor
  6097. * @private
  6098. * @static
  6099. */
  6100. getPreprocessor: function(name) {
  6101. return this.preprocessors[name];
  6102. },
  6103. /**
  6104. * @private
  6105. */
  6106. getPreprocessors: function() {
  6107. return this.preprocessors;
  6108. },
  6109. /**
  6110. * @private
  6111. */
  6112. defaultPreprocessors: [],
  6113. /**
  6114. * Retrieve the array stack of default pre-processors
  6115. * @return {Function[]} defaultPreprocessors
  6116. * @private
  6117. * @static
  6118. */
  6119. getDefaultPreprocessors: function() {
  6120. return this.defaultPreprocessors;
  6121. },
  6122. /**
  6123. * Set the default array stack of default pre-processors
  6124. *
  6125. * @private
  6126. * @param {Array} preprocessors
  6127. * @return {Ext.Class} this
  6128. * @static
  6129. */
  6130. setDefaultPreprocessors: function(preprocessors) {
  6131. this.defaultPreprocessors = Ext.Array.from(preprocessors);
  6132. return this;
  6133. },
  6134. /**
  6135. * Insert this pre-processor at a specific position in the stack, optionally relative to
  6136. * any existing pre-processor. For example:
  6137. *
  6138. * Ext.Class.registerPreprocessor('debug', function(cls, data, fn) {
  6139. * // Your code here
  6140. *
  6141. * if (fn) {
  6142. * fn.call(this, cls, data);
  6143. * }
  6144. * }).setDefaultPreprocessorPosition('debug', 'last');
  6145. *
  6146. * @private
  6147. * @param {String} name The pre-processor name. Note that it needs to be registered with
  6148. * {@link Ext.Class#registerPreprocessor registerPreprocessor} before this
  6149. * @param {String} offset The insertion position. Four possible values are:
  6150. * 'first', 'last', or: 'before', 'after' (relative to the name provided in the third argument)
  6151. * @param {String} relativeName
  6152. * @return {Ext.Class} this
  6153. * @static
  6154. */
  6155. setDefaultPreprocessorPosition: function(name, offset, relativeName) {
  6156. var defaultPreprocessors = this.defaultPreprocessors,
  6157. index;
  6158. if (typeof offset == 'string') {
  6159. if (offset === 'first') {
  6160. defaultPreprocessors.unshift(name);
  6161. return this;
  6162. }
  6163. else if (offset === 'last') {
  6164. defaultPreprocessors.push(name);
  6165. return this;
  6166. }
  6167. offset = (offset === 'after') ? 1 : -1;
  6168. }
  6169. index = Ext.Array.indexOf(defaultPreprocessors, relativeName);
  6170. if (index !== -1) {
  6171. Ext.Array.splice(defaultPreprocessors, Math.max(0, index + offset), 0, name);
  6172. }
  6173. return this;
  6174. },
  6175. configNameCache: {},
  6176. getConfigNameMap: function(name) {
  6177. var cache = this.configNameCache,
  6178. map = cache[name],
  6179. capitalizedName;
  6180. if (!map) {
  6181. capitalizedName = name.charAt(0).toUpperCase() + name.substr(1);
  6182. map = cache[name] = {
  6183. internal: name,
  6184. initialized: '_is' + capitalizedName + 'Initialized',
  6185. apply: 'apply' + capitalizedName,
  6186. update: 'update' + capitalizedName,
  6187. 'set': 'set' + capitalizedName,
  6188. 'get': 'get' + capitalizedName,
  6189. doSet : 'doSet' + capitalizedName,
  6190. changeEvent: name.toLowerCase() + 'change'
  6191. };
  6192. }
  6193. return map;
  6194. }
  6195. });
  6196. /**
  6197. * @cfg {String} extend
  6198. * The parent class that this class extends. For example:
  6199. *
  6200. * Ext.define('Person', {
  6201. * say: function(text) { alert(text); }
  6202. * });
  6203. *
  6204. * Ext.define('Developer', {
  6205. * extend: 'Person',
  6206. * say: function(text) { this.callParent(["print "+text]); }
  6207. * });
  6208. */
  6209. ExtClass.registerPreprocessor('extend', function(Class, data) {
  6210. var Base = Ext.Base,
  6211. basePrototype = Base.prototype,
  6212. extend = data.extend,
  6213. Parent, parentPrototype, i;
  6214. delete data.extend;
  6215. if (extend && extend !== Object) {
  6216. Parent = extend;
  6217. }
  6218. else {
  6219. Parent = Base;
  6220. }
  6221. parentPrototype = Parent.prototype;
  6222. if (!Parent.$isClass) {
  6223. for (i in basePrototype) {
  6224. if (!parentPrototype[i]) {
  6225. parentPrototype[i] = basePrototype[i];
  6226. }
  6227. }
  6228. }
  6229. Class.extend(Parent);
  6230. Class.triggerExtended.apply(Class, arguments);
  6231. if (data.onClassExtended) {
  6232. Class.onExtended(data.onClassExtended, Class);
  6233. delete data.onClassExtended;
  6234. }
  6235. }, true);
  6236. /**
  6237. * @cfg {Object} statics
  6238. * List of static methods for this class. For example:
  6239. *
  6240. * Ext.define('Computer', {
  6241. * statics: {
  6242. * factory: function(brand) {
  6243. * // 'this' in static methods refer to the class itself
  6244. * return new this(brand);
  6245. * }
  6246. * },
  6247. *
  6248. * constructor: function() { ... }
  6249. * });
  6250. *
  6251. * var dellComputer = Computer.factory('Dell');
  6252. */
  6253. ExtClass.registerPreprocessor('statics', function(Class, data) {
  6254. Class.addStatics(data.statics);
  6255. delete data.statics;
  6256. });
  6257. /**
  6258. * @cfg {Object} inheritableStatics
  6259. * List of inheritable static methods for this class.
  6260. * Otherwise just like {@link #statics} but subclasses inherit these methods.
  6261. */
  6262. ExtClass.registerPreprocessor('inheritableStatics', function(Class, data) {
  6263. Class.addInheritableStatics(data.inheritableStatics);
  6264. delete data.inheritableStatics;
  6265. });
  6266. /**
  6267. * @cfg {Object} config
  6268. * List of configuration options with their default values, for which automatically
  6269. * accessor methods are generated. For example:
  6270. *
  6271. * Ext.define('SmartPhone', {
  6272. * config: {
  6273. * hasTouchScreen: false,
  6274. * operatingSystem: 'Other',
  6275. * price: 500
  6276. * },
  6277. * constructor: function(cfg) {
  6278. * this.initConfig(cfg);
  6279. * }
  6280. * });
  6281. *
  6282. * var iPhone = new SmartPhone({
  6283. * hasTouchScreen: true,
  6284. * operatingSystem: 'iOS'
  6285. * });
  6286. *
  6287. * iPhone.getPrice(); // 500;
  6288. * iPhone.getOperatingSystem(); // 'iOS'
  6289. * iPhone.getHasTouchScreen(); // true;
  6290. */
  6291. ExtClass.registerPreprocessor('config', function(Class, data) {
  6292. var config = data.config,
  6293. prototype = Class.prototype;
  6294. delete data.config;
  6295. Ext.Object.each(config, function(name, value) {
  6296. var nameMap = ExtClass.getConfigNameMap(name),
  6297. internalName = nameMap.internal,
  6298. initializedName = nameMap.initialized,
  6299. applyName = nameMap.apply,
  6300. updateName = nameMap.update,
  6301. setName = nameMap.set,
  6302. getName = nameMap.get,
  6303. hasOwnSetter = (setName in prototype) || data.hasOwnProperty(setName),
  6304. hasOwnApplier = (applyName in prototype) || data.hasOwnProperty(applyName),
  6305. hasOwnUpdater = (updateName in prototype) || data.hasOwnProperty(updateName),
  6306. optimizedGetter, customGetter;
  6307. if (value === null || (!hasOwnSetter && !hasOwnApplier && !hasOwnUpdater)) {
  6308. prototype[internalName] = value;
  6309. prototype[initializedName] = true;
  6310. }
  6311. else {
  6312. prototype[initializedName] = false;
  6313. }
  6314. if (!hasOwnSetter) {
  6315. data[setName] = function(value) {
  6316. var oldValue = this[internalName],
  6317. applier = this[applyName],
  6318. updater = this[updateName];
  6319. if (!this[initializedName]) {
  6320. this[initializedName] = true;
  6321. }
  6322. if (applier) {
  6323. value = applier.call(this, value, oldValue);
  6324. }
  6325. if (typeof value != 'undefined') {
  6326. this[internalName] = value;
  6327. if (updater && value !== oldValue) {
  6328. updater.call(this, value, oldValue);
  6329. }
  6330. }
  6331. return this;
  6332. };
  6333. }
  6334. if (!(getName in prototype) || data.hasOwnProperty(getName)) {
  6335. customGetter = data[getName] || false;
  6336. if (customGetter) {
  6337. optimizedGetter = function() {
  6338. return customGetter.apply(this, arguments);
  6339. };
  6340. }
  6341. else {
  6342. optimizedGetter = function() {
  6343. return this[internalName];
  6344. };
  6345. }
  6346. data[getName] = function() {
  6347. var currentGetter;
  6348. if (!this[initializedName]) {
  6349. this[initializedName] = true;
  6350. this[setName](this.config[name]);
  6351. }
  6352. currentGetter = this[getName];
  6353. if ('$previous' in currentGetter) {
  6354. currentGetter.$previous = optimizedGetter;
  6355. }
  6356. else {
  6357. this[getName] = optimizedGetter;
  6358. }
  6359. return optimizedGetter.apply(this, arguments);
  6360. };
  6361. }
  6362. });
  6363. Class.addConfig(config, true);
  6364. });
  6365. /**
  6366. * @cfg {String[]/Object} mixins
  6367. * List of classes to mix into this class. For example:
  6368. *
  6369. * Ext.define('CanSing', {
  6370. * sing: function() {
  6371. * alert("I'm on the highway to hell...")
  6372. * }
  6373. * });
  6374. *
  6375. * Ext.define('Musician', {
  6376. * mixins: ['CanSing']
  6377. * })
  6378. *
  6379. * In this case the Musician class will get a `sing` method from CanSing mixin.
  6380. *
  6381. * But what if the Musician already has a `sing` method? Or you want to mix
  6382. * in two classes, both of which define `sing`? In such a cases it's good
  6383. * to define mixins as an object, where you assign a name to each mixin:
  6384. *
  6385. * Ext.define('Musician', {
  6386. * mixins: {
  6387. * canSing: 'CanSing'
  6388. * },
  6389. *
  6390. * sing: function() {
  6391. * // delegate singing operation to mixin
  6392. * this.mixins.canSing.sing.call(this);
  6393. * }
  6394. * })
  6395. *
  6396. * In this case the `sing` method of Musician will overwrite the
  6397. * mixed in `sing` method. But you can access the original mixed in method
  6398. * through special `mixins` property.
  6399. */
  6400. ExtClass.registerPreprocessor('mixins', function(Class, data, hooks) {
  6401. var mixins = data.mixins,
  6402. name, mixin, i, ln;
  6403. delete data.mixins;
  6404. Ext.Function.interceptBefore(hooks, 'onCreated', function() {
  6405. if (mixins instanceof Array) {
  6406. for (i = 0,ln = mixins.length; i < ln; i++) {
  6407. mixin = mixins[i];
  6408. name = mixin.prototype.mixinId || mixin.$className;
  6409. Class.mixin(name, mixin);
  6410. }
  6411. }
  6412. else {
  6413. for (var mixinName in mixins) {
  6414. if (mixins.hasOwnProperty(mixinName)) {
  6415. Class.mixin(mixinName, mixins[mixinName]);
  6416. }
  6417. }
  6418. }
  6419. });
  6420. });
  6421. // Backwards compatible
  6422. Ext.extend = function(Class, Parent, members) {
  6423. if (arguments.length === 2 && Ext.isObject(Parent)) {
  6424. members = Parent;
  6425. Parent = Class;
  6426. Class = null;
  6427. }
  6428. var cls;
  6429. if (!Parent) {
  6430. throw new Error("[Ext.extend] Attempting to extend from a class which has not been loaded on the page.");
  6431. }
  6432. members.extend = Parent;
  6433. members.preprocessors = [
  6434. 'extend'
  6435. ,'statics'
  6436. ,'inheritableStatics'
  6437. ,'mixins'
  6438. ,'config'
  6439. ];
  6440. if (Class) {
  6441. cls = new ExtClass(Class, members);
  6442. // The 'constructor' is given as 'Class' but also needs to be on prototype
  6443. cls.prototype.constructor = Class;
  6444. } else {
  6445. cls = new ExtClass(members);
  6446. }
  6447. cls.prototype.override = function(o) {
  6448. for (var m in o) {
  6449. if (o.hasOwnProperty(m)) {
  6450. this[m] = o[m];
  6451. }
  6452. }
  6453. };
  6454. return cls;
  6455. };
  6456. }());
  6457. //@tag foundation,core
  6458. //@require Class.js
  6459. /**
  6460. * @author Jacky Nguyen <jacky@sencha.com>
  6461. * @docauthor Jacky Nguyen <jacky@sencha.com>
  6462. * @class Ext.ClassManager
  6463. *
  6464. * Ext.ClassManager manages all classes and handles mapping from string class name to
  6465. * actual class objects throughout the whole framework. It is not generally accessed directly, rather through
  6466. * these convenient shorthands:
  6467. *
  6468. * - {@link Ext#define Ext.define}
  6469. * - {@link Ext#create Ext.create}
  6470. * - {@link Ext#widget Ext.widget}
  6471. * - {@link Ext#getClass Ext.getClass}
  6472. * - {@link Ext#getClassName Ext.getClassName}
  6473. *
  6474. * # Basic syntax:
  6475. *
  6476. * Ext.define(className, properties);
  6477. *
  6478. * in which `properties` is an object represent a collection of properties that apply to the class. See
  6479. * {@link Ext.ClassManager#create} for more detailed instructions.
  6480. *
  6481. * Ext.define('Person', {
  6482. * name: 'Unknown',
  6483. *
  6484. * constructor: function(name) {
  6485. * if (name) {
  6486. * this.name = name;
  6487. * }
  6488. * },
  6489. *
  6490. * eat: function(foodType) {
  6491. * alert("I'm eating: " + foodType);
  6492. *
  6493. * return this;
  6494. * }
  6495. * });
  6496. *
  6497. * var aaron = new Person("Aaron");
  6498. * aaron.eat("Sandwich"); // alert("I'm eating: Sandwich");
  6499. *
  6500. * Ext.Class has a powerful set of extensible {@link Ext.Class#registerPreprocessor pre-processors} which takes care of
  6501. * everything related to class creation, including but not limited to inheritance, mixins, configuration, statics, etc.
  6502. *
  6503. * # Inheritance:
  6504. *
  6505. * Ext.define('Developer', {
  6506. * extend: 'Person',
  6507. *
  6508. * constructor: function(name, isGeek) {
  6509. * this.isGeek = isGeek;
  6510. *
  6511. * // Apply a method from the parent class' prototype
  6512. * this.callParent([name]);
  6513. * },
  6514. *
  6515. * code: function(language) {
  6516. * alert("I'm coding in: " + language);
  6517. *
  6518. * this.eat("Bugs");
  6519. *
  6520. * return this;
  6521. * }
  6522. * });
  6523. *
  6524. * var jacky = new Developer("Jacky", true);
  6525. * jacky.code("JavaScript"); // alert("I'm coding in: JavaScript");
  6526. * // alert("I'm eating: Bugs");
  6527. *
  6528. * See {@link Ext.Base#callParent} for more details on calling superclass' methods
  6529. *
  6530. * # Mixins:
  6531. *
  6532. * Ext.define('CanPlayGuitar', {
  6533. * playGuitar: function() {
  6534. * alert("F#...G...D...A");
  6535. * }
  6536. * });
  6537. *
  6538. * Ext.define('CanComposeSongs', {
  6539. * composeSongs: function() { ... }
  6540. * });
  6541. *
  6542. * Ext.define('CanSing', {
  6543. * sing: function() {
  6544. * alert("I'm on the highway to hell...")
  6545. * }
  6546. * });
  6547. *
  6548. * Ext.define('Musician', {
  6549. * extend: 'Person',
  6550. *
  6551. * mixins: {
  6552. * canPlayGuitar: 'CanPlayGuitar',
  6553. * canComposeSongs: 'CanComposeSongs',
  6554. * canSing: 'CanSing'
  6555. * }
  6556. * })
  6557. *
  6558. * Ext.define('CoolPerson', {
  6559. * extend: 'Person',
  6560. *
  6561. * mixins: {
  6562. * canPlayGuitar: 'CanPlayGuitar',
  6563. * canSing: 'CanSing'
  6564. * },
  6565. *
  6566. * sing: function() {
  6567. * alert("Ahem....");
  6568. *
  6569. * this.mixins.canSing.sing.call(this);
  6570. *
  6571. * alert("[Playing guitar at the same time...]");
  6572. *
  6573. * this.playGuitar();
  6574. * }
  6575. * });
  6576. *
  6577. * var me = new CoolPerson("Jacky");
  6578. *
  6579. * me.sing(); // alert("Ahem...");
  6580. * // alert("I'm on the highway to hell...");
  6581. * // alert("[Playing guitar at the same time...]");
  6582. * // alert("F#...G...D...A");
  6583. *
  6584. * # Config:
  6585. *
  6586. * Ext.define('SmartPhone', {
  6587. * config: {
  6588. * hasTouchScreen: false,
  6589. * operatingSystem: 'Other',
  6590. * price: 500
  6591. * },
  6592. *
  6593. * isExpensive: false,
  6594. *
  6595. * constructor: function(config) {
  6596. * this.initConfig(config);
  6597. * },
  6598. *
  6599. * applyPrice: function(price) {
  6600. * this.isExpensive = (price > 500);
  6601. *
  6602. * return price;
  6603. * },
  6604. *
  6605. * applyOperatingSystem: function(operatingSystem) {
  6606. * if (!(/^(iOS|Android|BlackBerry)$/i).test(operatingSystem)) {
  6607. * return 'Other';
  6608. * }
  6609. *
  6610. * return operatingSystem;
  6611. * }
  6612. * });
  6613. *
  6614. * var iPhone = new SmartPhone({
  6615. * hasTouchScreen: true,
  6616. * operatingSystem: 'iOS'
  6617. * });
  6618. *
  6619. * iPhone.getPrice(); // 500;
  6620. * iPhone.getOperatingSystem(); // 'iOS'
  6621. * iPhone.getHasTouchScreen(); // true;
  6622. * iPhone.hasTouchScreen(); // true
  6623. *
  6624. * iPhone.isExpensive; // false;
  6625. * iPhone.setPrice(600);
  6626. * iPhone.getPrice(); // 600
  6627. * iPhone.isExpensive; // true;
  6628. *
  6629. * iPhone.setOperatingSystem('AlienOS');
  6630. * iPhone.getOperatingSystem(); // 'Other'
  6631. *
  6632. * # Statics:
  6633. *
  6634. * Ext.define('Computer', {
  6635. * statics: {
  6636. * factory: function(brand) {
  6637. * // 'this' in static methods refer to the class itself
  6638. * return new this(brand);
  6639. * }
  6640. * },
  6641. *
  6642. * constructor: function() { ... }
  6643. * });
  6644. *
  6645. * var dellComputer = Computer.factory('Dell');
  6646. *
  6647. * Also see {@link Ext.Base#statics} and {@link Ext.Base#self} for more details on accessing
  6648. * static properties within class methods
  6649. *
  6650. * @singleton
  6651. */
  6652. (function(Class, alias, arraySlice, arrayFrom, global) {
  6653. // Creates a constructor that has nothing extra in its scope chain.
  6654. function makeCtor () {
  6655. function constructor () {
  6656. // Opera has some problems returning from a constructor when Dragonfly isn't running. The || null seems to
  6657. // be sufficient to stop it misbehaving. Known to be required against 10.53, 11.51 and 11.61.
  6658. return this.constructor.apply(this, arguments) || null;
  6659. }
  6660. return constructor;
  6661. }
  6662. var Manager = Ext.ClassManager = {
  6663. /**
  6664. * @property {Object} classes
  6665. * All classes which were defined through the ClassManager. Keys are the
  6666. * name of the classes and the values are references to the classes.
  6667. * @private
  6668. */
  6669. classes: {},
  6670. /**
  6671. * @private
  6672. */
  6673. existCache: {},
  6674. /**
  6675. * @private
  6676. */
  6677. namespaceRewrites: [{
  6678. from: 'Ext.',
  6679. to: Ext
  6680. }],
  6681. /**
  6682. * @private
  6683. */
  6684. maps: {
  6685. alternateToName: {},
  6686. aliasToName: {},
  6687. nameToAliases: {},
  6688. nameToAlternates: {}
  6689. },
  6690. /** @private */
  6691. enableNamespaceParseCache: true,
  6692. /** @private */
  6693. namespaceParseCache: {},
  6694. /** @private */
  6695. instantiators: [],
  6696. /**
  6697. * Checks if a class has already been created.
  6698. *
  6699. * @param {String} className
  6700. * @return {Boolean} exist
  6701. */
  6702. isCreated: function(className) {
  6703. var existCache = this.existCache,
  6704. i, ln, part, root, parts;
  6705. if (typeof className != 'string' || className.length < 1) {
  6706. throw new Error("[Ext.ClassManager] Invalid classname, must be a string and must not be empty");
  6707. }
  6708. if (this.classes[className] || existCache[className]) {
  6709. return true;
  6710. }
  6711. root = global;
  6712. parts = this.parseNamespace(className);
  6713. for (i = 0, ln = parts.length; i < ln; i++) {
  6714. part = parts[i];
  6715. if (typeof part != 'string') {
  6716. root = part;
  6717. } else {
  6718. if (!root || !root[part]) {
  6719. return false;
  6720. }
  6721. root = root[part];
  6722. }
  6723. }
  6724. existCache[className] = true;
  6725. this.triggerCreated(className);
  6726. return true;
  6727. },
  6728. /**
  6729. * @private
  6730. */
  6731. createdListeners: [],
  6732. /**
  6733. * @private
  6734. */
  6735. nameCreatedListeners: {},
  6736. /**
  6737. * @private
  6738. */
  6739. triggerCreated: function(className) {
  6740. var listeners = this.createdListeners,
  6741. nameListeners = this.nameCreatedListeners,
  6742. alternateNames = this.maps.nameToAlternates[className],
  6743. names = [className],
  6744. i, ln, j, subLn, listener, name;
  6745. for (i = 0,ln = listeners.length; i < ln; i++) {
  6746. listener = listeners[i];
  6747. listener.fn.call(listener.scope, className);
  6748. }
  6749. if (alternateNames) {
  6750. names.push.apply(names, alternateNames);
  6751. }
  6752. for (i = 0,ln = names.length; i < ln; i++) {
  6753. name = names[i];
  6754. listeners = nameListeners[name];
  6755. if (listeners) {
  6756. for (j = 0,subLn = listeners.length; j < subLn; j++) {
  6757. listener = listeners[j];
  6758. listener.fn.call(listener.scope, name);
  6759. }
  6760. delete nameListeners[name];
  6761. }
  6762. }
  6763. },
  6764. /**
  6765. * @private
  6766. */
  6767. onCreated: function(fn, scope, className) {
  6768. var listeners = this.createdListeners,
  6769. nameListeners = this.nameCreatedListeners,
  6770. listener = {
  6771. fn: fn,
  6772. scope: scope
  6773. };
  6774. if (className) {
  6775. if (this.isCreated(className)) {
  6776. fn.call(scope, className);
  6777. return;
  6778. }
  6779. if (!nameListeners[className]) {
  6780. nameListeners[className] = [];
  6781. }
  6782. nameListeners[className].push(listener);
  6783. }
  6784. else {
  6785. listeners.push(listener);
  6786. }
  6787. },
  6788. /**
  6789. * Supports namespace rewriting
  6790. * @private
  6791. */
  6792. parseNamespace: function(namespace) {
  6793. if (typeof namespace != 'string') {
  6794. throw new Error("[Ext.ClassManager] Invalid namespace, must be a string");
  6795. }
  6796. var cache = this.namespaceParseCache,
  6797. parts,
  6798. rewrites,
  6799. root,
  6800. name,
  6801. rewrite, from, to, i, ln;
  6802. if (this.enableNamespaceParseCache) {
  6803. if (cache.hasOwnProperty(namespace)) {
  6804. return cache[namespace];
  6805. }
  6806. }
  6807. parts = [];
  6808. rewrites = this.namespaceRewrites;
  6809. root = global;
  6810. name = namespace;
  6811. for (i = 0, ln = rewrites.length; i < ln; i++) {
  6812. rewrite = rewrites[i];
  6813. from = rewrite.from;
  6814. to = rewrite.to;
  6815. if (name === from || name.substring(0, from.length) === from) {
  6816. name = name.substring(from.length);
  6817. if (typeof to != 'string') {
  6818. root = to;
  6819. } else {
  6820. parts = parts.concat(to.split('.'));
  6821. }
  6822. break;
  6823. }
  6824. }
  6825. parts.push(root);
  6826. parts = parts.concat(name.split('.'));
  6827. if (this.enableNamespaceParseCache) {
  6828. cache[namespace] = parts;
  6829. }
  6830. return parts;
  6831. },
  6832. /**
  6833. * Creates a namespace and assign the `value` to the created object
  6834. *
  6835. * Ext.ClassManager.setNamespace('MyCompany.pkg.Example', someObject);
  6836. *
  6837. * alert(MyCompany.pkg.Example === someObject); // alerts true
  6838. *
  6839. * @param {String} name
  6840. * @param {Object} value
  6841. */
  6842. setNamespace: function(name, value) {
  6843. var root = global,
  6844. parts = this.parseNamespace(name),
  6845. ln = parts.length - 1,
  6846. leaf = parts[ln],
  6847. i, part;
  6848. for (i = 0; i < ln; i++) {
  6849. part = parts[i];
  6850. if (typeof part != 'string') {
  6851. root = part;
  6852. } else {
  6853. if (!root[part]) {
  6854. root[part] = {};
  6855. }
  6856. root = root[part];
  6857. }
  6858. }
  6859. root[leaf] = value;
  6860. return root[leaf];
  6861. },
  6862. /**
  6863. * The new Ext.ns, supports namespace rewriting
  6864. * @private
  6865. */
  6866. createNamespaces: function() {
  6867. var root = global,
  6868. parts, part, i, j, ln, subLn;
  6869. for (i = 0, ln = arguments.length; i < ln; i++) {
  6870. parts = this.parseNamespace(arguments[i]);
  6871. for (j = 0, subLn = parts.length; j < subLn; j++) {
  6872. part = parts[j];
  6873. if (typeof part != 'string') {
  6874. root = part;
  6875. } else {
  6876. if (!root[part]) {
  6877. root[part] = {};
  6878. }
  6879. root = root[part];
  6880. }
  6881. }
  6882. }
  6883. return root;
  6884. },
  6885. /**
  6886. * Sets a name reference to a class.
  6887. *
  6888. * @param {String} name
  6889. * @param {Object} value
  6890. * @return {Ext.ClassManager} this
  6891. */
  6892. set: function(name, value) {
  6893. var me = this,
  6894. maps = me.maps,
  6895. nameToAlternates = maps.nameToAlternates,
  6896. targetName = me.getName(value),
  6897. alternates;
  6898. me.classes[name] = me.setNamespace(name, value);
  6899. if (targetName && targetName !== name) {
  6900. maps.alternateToName[name] = targetName;
  6901. alternates = nameToAlternates[targetName] || (nameToAlternates[targetName] = []);
  6902. alternates.push(name);
  6903. }
  6904. return this;
  6905. },
  6906. /**
  6907. * Retrieve a class by its name.
  6908. *
  6909. * @param {String} name
  6910. * @return {Ext.Class} class
  6911. */
  6912. get: function(name) {
  6913. var classes = this.classes,
  6914. root,
  6915. parts,
  6916. part, i, ln;
  6917. if (classes[name]) {
  6918. return classes[name];
  6919. }
  6920. root = global;
  6921. parts = this.parseNamespace(name);
  6922. for (i = 0, ln = parts.length; i < ln; i++) {
  6923. part = parts[i];
  6924. if (typeof part != 'string') {
  6925. root = part;
  6926. } else {
  6927. if (!root || !root[part]) {
  6928. return null;
  6929. }
  6930. root = root[part];
  6931. }
  6932. }
  6933. return root;
  6934. },
  6935. /**
  6936. * Register the alias for a class.
  6937. *
  6938. * @param {Ext.Class/String} cls a reference to a class or a className
  6939. * @param {String} alias Alias to use when referring to this class
  6940. */
  6941. setAlias: function(cls, alias) {
  6942. var aliasToNameMap = this.maps.aliasToName,
  6943. nameToAliasesMap = this.maps.nameToAliases,
  6944. className;
  6945. if (typeof cls == 'string') {
  6946. className = cls;
  6947. } else {
  6948. className = this.getName(cls);
  6949. }
  6950. if (alias && aliasToNameMap[alias] !== className) {
  6951. if (aliasToNameMap[alias] && Ext.isDefined(global.console)) {
  6952. global.console.log("[Ext.ClassManager] Overriding existing alias: '" + alias + "' " +
  6953. "of: '" + aliasToNameMap[alias] + "' with: '" + className + "'. Be sure it's intentional.");
  6954. }
  6955. aliasToNameMap[alias] = className;
  6956. }
  6957. if (!nameToAliasesMap[className]) {
  6958. nameToAliasesMap[className] = [];
  6959. }
  6960. if (alias) {
  6961. Ext.Array.include(nameToAliasesMap[className], alias);
  6962. }
  6963. return this;
  6964. },
  6965. /**
  6966. * Adds a batch of class name to alias mappings
  6967. * @param {Object} aliases The set of mappings of the form
  6968. * className : [values...]
  6969. */
  6970. addNameAliasMappings: function(aliases){
  6971. var aliasToNameMap = this.maps.aliasToName,
  6972. nameToAliasesMap = this.maps.nameToAliases,
  6973. className, aliasList, alias, i;
  6974. for (className in aliases) {
  6975. aliasList = nameToAliasesMap[className] ||
  6976. (nameToAliasesMap[className] = []);
  6977. for (i = 0; i < aliases[className].length; i++) {
  6978. alias = aliases[className][i];
  6979. if (!aliasToNameMap[alias]) {
  6980. aliasToNameMap[alias] = className;
  6981. aliasList.push(alias);
  6982. }
  6983. }
  6984. }
  6985. return this;
  6986. },
  6987. /**
  6988. *
  6989. * @param {Object} alternates The set of mappings of the form
  6990. * className : [values...]
  6991. */
  6992. addNameAlternateMappings: function(alternates) {
  6993. var alternateToName = this.maps.alternateToName,
  6994. nameToAlternates = this.maps.nameToAlternates,
  6995. className, aliasList, alternate, i;
  6996. for (className in alternates) {
  6997. aliasList = nameToAlternates[className] ||
  6998. (nameToAlternates[className] = []);
  6999. for (i = 0; i < alternates[className].length; i++) {
  7000. alternate = alternates[className];
  7001. if (!alternateToName[alternate]) {
  7002. alternateToName[alternate] = className;
  7003. aliasList.push(alternate);
  7004. }
  7005. }
  7006. }
  7007. return this;
  7008. },
  7009. /**
  7010. * Get a reference to the class by its alias.
  7011. *
  7012. * @param {String} alias
  7013. * @return {Ext.Class} class
  7014. */
  7015. getByAlias: function(alias) {
  7016. return this.get(this.getNameByAlias(alias));
  7017. },
  7018. /**
  7019. * Get the name of a class by its alias.
  7020. *
  7021. * @param {String} alias
  7022. * @return {String} className
  7023. */
  7024. getNameByAlias: function(alias) {
  7025. return this.maps.aliasToName[alias] || '';
  7026. },
  7027. /**
  7028. * Get the name of a class by its alternate name.
  7029. *
  7030. * @param {String} alternate
  7031. * @return {String} className
  7032. */
  7033. getNameByAlternate: function(alternate) {
  7034. return this.maps.alternateToName[alternate] || '';
  7035. },
  7036. /**
  7037. * Get the aliases of a class by the class name
  7038. *
  7039. * @param {String} name
  7040. * @return {Array} aliases
  7041. */
  7042. getAliasesByName: function(name) {
  7043. return this.maps.nameToAliases[name] || [];
  7044. },
  7045. /**
  7046. * Get the name of the class by its reference or its instance;
  7047. * usually invoked by the shorthand {@link Ext#getClassName Ext.getClassName}
  7048. *
  7049. * Ext.ClassManager.getName(Ext.Action); // returns "Ext.Action"
  7050. *
  7051. * @param {Ext.Class/Object} object
  7052. * @return {String} className
  7053. */
  7054. getName: function(object) {
  7055. return object && object.$className || '';
  7056. },
  7057. /**
  7058. * Get the class of the provided object; returns null if it's not an instance
  7059. * of any class created with Ext.define. This is usually invoked by the shorthand {@link Ext#getClass Ext.getClass}
  7060. *
  7061. * var component = new Ext.Component();
  7062. *
  7063. * Ext.ClassManager.getClass(component); // returns Ext.Component
  7064. *
  7065. * @param {Object} object
  7066. * @return {Ext.Class} class
  7067. */
  7068. getClass: function(object) {
  7069. return object && object.self || null;
  7070. },
  7071. /**
  7072. * Defines a class.
  7073. * @deprecated 4.1.0 Use {@link Ext#define} instead, as that also supports creating overrides.
  7074. */
  7075. create: function(className, data, createdFn) {
  7076. if (className != null && typeof className != 'string') {
  7077. throw new Error("[Ext.define] Invalid class name '" + className + "' specified, must be a non-empty string");
  7078. }
  7079. var ctor = makeCtor();
  7080. if (typeof data == 'function') {
  7081. data = data(ctor);
  7082. }
  7083. if (className) {
  7084. ctor.displayName = className;
  7085. }
  7086. data.$className = className;
  7087. return new Class(ctor, data, function() {
  7088. var postprocessorStack = data.postprocessors || Manager.defaultPostprocessors,
  7089. registeredPostprocessors = Manager.postprocessors,
  7090. postprocessors = [],
  7091. postprocessor, i, ln, j, subLn, postprocessorProperties, postprocessorProperty;
  7092. delete data.postprocessors;
  7093. for (i = 0,ln = postprocessorStack.length; i < ln; i++) {
  7094. postprocessor = postprocessorStack[i];
  7095. if (typeof postprocessor == 'string') {
  7096. postprocessor = registeredPostprocessors[postprocessor];
  7097. postprocessorProperties = postprocessor.properties;
  7098. if (postprocessorProperties === true) {
  7099. postprocessors.push(postprocessor.fn);
  7100. }
  7101. else if (postprocessorProperties) {
  7102. for (j = 0,subLn = postprocessorProperties.length; j < subLn; j++) {
  7103. postprocessorProperty = postprocessorProperties[j];
  7104. if (data.hasOwnProperty(postprocessorProperty)) {
  7105. postprocessors.push(postprocessor.fn);
  7106. break;
  7107. }
  7108. }
  7109. }
  7110. }
  7111. else {
  7112. postprocessors.push(postprocessor);
  7113. }
  7114. }
  7115. data.postprocessors = postprocessors;
  7116. data.createdFn = createdFn;
  7117. Manager.processCreate(className, this, data);
  7118. });
  7119. },
  7120. processCreate: function(className, cls, clsData){
  7121. var me = this,
  7122. postprocessor = clsData.postprocessors.shift(),
  7123. createdFn = clsData.createdFn;
  7124. if (!postprocessor) {
  7125. if (className) {
  7126. me.set(className, cls);
  7127. }
  7128. if (createdFn) {
  7129. createdFn.call(cls, cls);
  7130. }
  7131. if (className) {
  7132. me.triggerCreated(className);
  7133. }
  7134. return;
  7135. }
  7136. if (postprocessor.call(me, className, cls, clsData, me.processCreate) !== false) {
  7137. me.processCreate(className, cls, clsData);
  7138. }
  7139. },
  7140. createOverride: function (className, data, createdFn) {
  7141. var me = this,
  7142. overriddenClassName = data.override,
  7143. requires = data.requires,
  7144. uses = data.uses,
  7145. classReady = function () {
  7146. var cls, temp;
  7147. if (requires) {
  7148. temp = requires;
  7149. requires = null; // do the real thing next time (which may be now)
  7150. // Since the override is going to be used (its target class is now
  7151. // created), we need to fetch the required classes for the override
  7152. // and call us back once they are loaded:
  7153. Ext.Loader.require(temp, classReady);
  7154. } else {
  7155. // The target class and the required classes for this override are
  7156. // ready, so we can apply the override now:
  7157. cls = me.get(overriddenClassName);
  7158. // We don't want to apply these:
  7159. delete data.override;
  7160. delete data.requires;
  7161. delete data.uses;
  7162. Ext.override(cls, data);
  7163. // This pushes the overridding file itself into Ext.Loader.history
  7164. // Hence if the target class never exists, the overriding file will
  7165. // never be included in the build.
  7166. me.triggerCreated(className);
  7167. if (uses) {
  7168. Ext.Loader.addUsedClasses(uses); // get these classes too!
  7169. }
  7170. if (createdFn) {
  7171. createdFn.call(cls); // last but not least!
  7172. }
  7173. }
  7174. };
  7175. me.existCache[className] = true;
  7176. // Override the target class right after it's created
  7177. me.onCreated(classReady, me, overriddenClassName);
  7178. return me;
  7179. },
  7180. /**
  7181. * Instantiate a class by its alias; usually invoked by the convenient shorthand {@link Ext#createByAlias Ext.createByAlias}
  7182. * If {@link Ext.Loader} is {@link Ext.Loader#setConfig enabled} and the class has not been defined yet, it will
  7183. * attempt to load the class via synchronous loading.
  7184. *
  7185. * var window = Ext.ClassManager.instantiateByAlias('widget.window', { width: 600, height: 800, ... });
  7186. *
  7187. * @param {String} alias
  7188. * @param {Object...} args Additional arguments after the alias will be passed to the
  7189. * class constructor.
  7190. * @return {Object} instance
  7191. */
  7192. instantiateByAlias: function() {
  7193. var alias = arguments[0],
  7194. args = arraySlice.call(arguments),
  7195. className = this.getNameByAlias(alias);
  7196. if (!className) {
  7197. className = this.maps.aliasToName[alias];
  7198. if (!className) {
  7199. throw new Error("[Ext.createByAlias] Cannot create an instance of unrecognized alias: " + alias);
  7200. }
  7201. if (global.console) {
  7202. global.console.warn("[Ext.Loader] Synchronously loading '" + className + "'; consider adding " +
  7203. "Ext.require('" + alias + "') above Ext.onReady");
  7204. }
  7205. Ext.syncRequire(className);
  7206. }
  7207. args[0] = className;
  7208. return this.instantiate.apply(this, args);
  7209. },
  7210. /**
  7211. * @private
  7212. */
  7213. instantiate: function() {
  7214. var name = arguments[0],
  7215. nameType = typeof name,
  7216. args = arraySlice.call(arguments, 1),
  7217. alias = name,
  7218. possibleName, cls;
  7219. if (nameType != 'function') {
  7220. if (nameType != 'string' && args.length === 0) {
  7221. args = [name];
  7222. name = name.xclass;
  7223. }
  7224. if (typeof name != 'string' || name.length < 1) {
  7225. throw new Error("[Ext.create] Invalid class name or alias '" + name + "' specified, must be a non-empty string");
  7226. }
  7227. cls = this.get(name);
  7228. }
  7229. else {
  7230. cls = name;
  7231. }
  7232. // No record of this class name, it's possibly an alias, so look it up
  7233. if (!cls) {
  7234. possibleName = this.getNameByAlias(name);
  7235. if (possibleName) {
  7236. name = possibleName;
  7237. cls = this.get(name);
  7238. }
  7239. }
  7240. // Still no record of this class name, it's possibly an alternate name, so look it up
  7241. if (!cls) {
  7242. possibleName = this.getNameByAlternate(name);
  7243. if (possibleName) {
  7244. name = possibleName;
  7245. cls = this.get(name);
  7246. }
  7247. }
  7248. // Still not existing at this point, try to load it via synchronous mode as the last resort
  7249. if (!cls) {
  7250. if (global.console) {
  7251. global.console.warn("[Ext.Loader] Synchronously loading '" + name + "'; consider adding " +
  7252. "Ext.require('" + ((possibleName) ? alias : name) + "') above Ext.onReady");
  7253. }
  7254. Ext.syncRequire(name);
  7255. cls = this.get(name);
  7256. }
  7257. if (!cls) {
  7258. throw new Error("[Ext.create] Cannot create an instance of unrecognized class name / alias: " + alias);
  7259. }
  7260. if (typeof cls != 'function') {
  7261. throw new Error("[Ext.create] '" + name + "' is a singleton and cannot be instantiated");
  7262. }
  7263. return this.getInstantiator(args.length)(cls, args);
  7264. },
  7265. /**
  7266. * @private
  7267. * @param name
  7268. * @param args
  7269. */
  7270. dynInstantiate: function(name, args) {
  7271. args = arrayFrom(args, true);
  7272. args.unshift(name);
  7273. return this.instantiate.apply(this, args);
  7274. },
  7275. /**
  7276. * @private
  7277. * @param length
  7278. */
  7279. getInstantiator: function(length) {
  7280. var instantiators = this.instantiators,
  7281. instantiator,
  7282. i,
  7283. args;
  7284. instantiator = instantiators[length];
  7285. if (!instantiator) {
  7286. i = length;
  7287. args = [];
  7288. for (i = 0; i < length; i++) {
  7289. args.push('a[' + i + ']');
  7290. }
  7291. instantiator = instantiators[length] = new Function('c', 'a', 'return new c(' + args.join(',') + ')');
  7292. instantiator.displayName = "Ext.ClassManager.instantiate" + length;
  7293. }
  7294. return instantiator;
  7295. },
  7296. /**
  7297. * @private
  7298. */
  7299. postprocessors: {},
  7300. /**
  7301. * @private
  7302. */
  7303. defaultPostprocessors: [],
  7304. /**
  7305. * Register a post-processor function.
  7306. *
  7307. * @private
  7308. * @param {String} name
  7309. * @param {Function} postprocessor
  7310. */
  7311. registerPostprocessor: function(name, fn, properties, position, relativeTo) {
  7312. if (!position) {
  7313. position = 'last';
  7314. }
  7315. if (!properties) {
  7316. properties = [name];
  7317. }
  7318. this.postprocessors[name] = {
  7319. name: name,
  7320. properties: properties || false,
  7321. fn: fn
  7322. };
  7323. this.setDefaultPostprocessorPosition(name, position, relativeTo);
  7324. return this;
  7325. },
  7326. /**
  7327. * Set the default post processors array stack which are applied to every class.
  7328. *
  7329. * @private
  7330. * @param {String/Array} The name of a registered post processor or an array of registered names.
  7331. * @return {Ext.ClassManager} this
  7332. */
  7333. setDefaultPostprocessors: function(postprocessors) {
  7334. this.defaultPostprocessors = arrayFrom(postprocessors);
  7335. return this;
  7336. },
  7337. /**
  7338. * Insert this post-processor at a specific position in the stack, optionally relative to
  7339. * any existing post-processor
  7340. *
  7341. * @private
  7342. * @param {String} name The post-processor name. Note that it needs to be registered with
  7343. * {@link Ext.ClassManager#registerPostprocessor} before this
  7344. * @param {String} offset The insertion position. Four possible values are:
  7345. * 'first', 'last', or: 'before', 'after' (relative to the name provided in the third argument)
  7346. * @param {String} relativeName
  7347. * @return {Ext.ClassManager} this
  7348. */
  7349. setDefaultPostprocessorPosition: function(name, offset, relativeName) {
  7350. var defaultPostprocessors = this.defaultPostprocessors,
  7351. index;
  7352. if (typeof offset == 'string') {
  7353. if (offset === 'first') {
  7354. defaultPostprocessors.unshift(name);
  7355. return this;
  7356. }
  7357. else if (offset === 'last') {
  7358. defaultPostprocessors.push(name);
  7359. return this;
  7360. }
  7361. offset = (offset === 'after') ? 1 : -1;
  7362. }
  7363. index = Ext.Array.indexOf(defaultPostprocessors, relativeName);
  7364. if (index !== -1) {
  7365. Ext.Array.splice(defaultPostprocessors, Math.max(0, index + offset), 0, name);
  7366. }
  7367. return this;
  7368. },
  7369. /**
  7370. * Converts a string expression to an array of matching class names. An expression can either refers to class aliases
  7371. * or class names. Expressions support wildcards:
  7372. *
  7373. * // returns ['Ext.window.Window']
  7374. * var window = Ext.ClassManager.getNamesByExpression('widget.window');
  7375. *
  7376. * // returns ['widget.panel', 'widget.window', ...]
  7377. * var allWidgets = Ext.ClassManager.getNamesByExpression('widget.*');
  7378. *
  7379. * // returns ['Ext.data.Store', 'Ext.data.ArrayProxy', ...]
  7380. * var allData = Ext.ClassManager.getNamesByExpression('Ext.data.*');
  7381. *
  7382. * @param {String} expression
  7383. * @return {String[]} classNames
  7384. */
  7385. getNamesByExpression: function(expression) {
  7386. var nameToAliasesMap = this.maps.nameToAliases,
  7387. names = [],
  7388. name, alias, aliases, possibleName, regex, i, ln;
  7389. if (typeof expression != 'string' || expression.length < 1) {
  7390. throw new Error("[Ext.ClassManager.getNamesByExpression] Expression " + expression + " is invalid, must be a non-empty string");
  7391. }
  7392. if (expression.indexOf('*') !== -1) {
  7393. expression = expression.replace(/\*/g, '(.*?)');
  7394. regex = new RegExp('^' + expression + '$');
  7395. for (name in nameToAliasesMap) {
  7396. if (nameToAliasesMap.hasOwnProperty(name)) {
  7397. aliases = nameToAliasesMap[name];
  7398. if (name.search(regex) !== -1) {
  7399. names.push(name);
  7400. }
  7401. else {
  7402. for (i = 0, ln = aliases.length; i < ln; i++) {
  7403. alias = aliases[i];
  7404. if (alias.search(regex) !== -1) {
  7405. names.push(name);
  7406. break;
  7407. }
  7408. }
  7409. }
  7410. }
  7411. }
  7412. } else {
  7413. possibleName = this.getNameByAlias(expression);
  7414. if (possibleName) {
  7415. names.push(possibleName);
  7416. } else {
  7417. possibleName = this.getNameByAlternate(expression);
  7418. if (possibleName) {
  7419. names.push(possibleName);
  7420. } else {
  7421. names.push(expression);
  7422. }
  7423. }
  7424. }
  7425. return names;
  7426. }
  7427. };
  7428. /**
  7429. * @cfg {String[]} alias
  7430. * @member Ext.Class
  7431. * List of short aliases for class names. Most useful for defining xtypes for widgets:
  7432. *
  7433. * Ext.define('MyApp.CoolPanel', {
  7434. * extend: 'Ext.panel.Panel',
  7435. * alias: ['widget.coolpanel'],
  7436. * title: 'Yeah!'
  7437. * });
  7438. *
  7439. * // Using Ext.create
  7440. * Ext.create('widget.coolpanel');
  7441. *
  7442. * // Using the shorthand for defining widgets by xtype
  7443. * Ext.widget('panel', {
  7444. * items: [
  7445. * {xtype: 'coolpanel', html: 'Foo'},
  7446. * {xtype: 'coolpanel', html: 'Bar'}
  7447. * ]
  7448. * });
  7449. *
  7450. * Besides "widget" for xtype there are alias namespaces like "feature" for ftype and "plugin" for ptype.
  7451. */
  7452. Manager.registerPostprocessor('alias', function(name, cls, data) {
  7453. var aliases = data.alias,
  7454. i, ln;
  7455. for (i = 0,ln = aliases.length; i < ln; i++) {
  7456. alias = aliases[i];
  7457. this.setAlias(cls, alias);
  7458. }
  7459. }, ['xtype', 'alias']);
  7460. /**
  7461. * @cfg {Boolean} singleton
  7462. * @member Ext.Class
  7463. * When set to true, the class will be instantiated as singleton. For example:
  7464. *
  7465. * Ext.define('Logger', {
  7466. * singleton: true,
  7467. * log: function(msg) {
  7468. * console.log(msg);
  7469. * }
  7470. * });
  7471. *
  7472. * Logger.log('Hello');
  7473. */
  7474. Manager.registerPostprocessor('singleton', function(name, cls, data, fn) {
  7475. fn.call(this, name, new cls(), data);
  7476. return false;
  7477. });
  7478. /**
  7479. * @cfg {String/String[]} alternateClassName
  7480. * @member Ext.Class
  7481. * Defines alternate names for this class. For example:
  7482. *
  7483. * Ext.define('Developer', {
  7484. * alternateClassName: ['Coder', 'Hacker'],
  7485. * code: function(msg) {
  7486. * alert('Typing... ' + msg);
  7487. * }
  7488. * });
  7489. *
  7490. * var joe = Ext.create('Developer');
  7491. * joe.code('stackoverflow');
  7492. *
  7493. * var rms = Ext.create('Hacker');
  7494. * rms.code('hack hack');
  7495. */
  7496. Manager.registerPostprocessor('alternateClassName', function(name, cls, data) {
  7497. var alternates = data.alternateClassName,
  7498. i, ln, alternate;
  7499. if (!(alternates instanceof Array)) {
  7500. alternates = [alternates];
  7501. }
  7502. for (i = 0, ln = alternates.length; i < ln; i++) {
  7503. alternate = alternates[i];
  7504. if (typeof alternate != 'string') {
  7505. throw new Error("[Ext.define] Invalid alternate of: '" + alternate + "' for class: '" + name + "'; must be a valid string");
  7506. }
  7507. this.set(alternate, cls);
  7508. }
  7509. });
  7510. Ext.apply(Ext, {
  7511. /**
  7512. * Instantiate a class by either full name, alias or alternate name.
  7513. *
  7514. * If {@link Ext.Loader} is {@link Ext.Loader#setConfig enabled} and the class has
  7515. * not been defined yet, it will attempt to load the class via synchronous loading.
  7516. *
  7517. * For example, all these three lines return the same result:
  7518. *
  7519. * // alias
  7520. * var window = Ext.create('widget.window', {
  7521. * width: 600,
  7522. * height: 800,
  7523. * ...
  7524. * });
  7525. *
  7526. * // alternate name
  7527. * var window = Ext.create('Ext.Window', {
  7528. * width: 600,
  7529. * height: 800,
  7530. * ...
  7531. * });
  7532. *
  7533. * // full class name
  7534. * var window = Ext.create('Ext.window.Window', {
  7535. * width: 600,
  7536. * height: 800,
  7537. * ...
  7538. * });
  7539. *
  7540. * // single object with xclass property:
  7541. * var window = Ext.create({
  7542. * xclass: 'Ext.window.Window', // any valid value for 'name' (above)
  7543. * width: 600,
  7544. * height: 800,
  7545. * ...
  7546. * });
  7547. *
  7548. * @param {String} [name] The class name or alias. Can be specified as `xclass`
  7549. * property if only one object parameter is specified.
  7550. * @param {Object...} [args] Additional arguments after the name will be passed to
  7551. * the class' constructor.
  7552. * @return {Object} instance
  7553. * @member Ext
  7554. * @method create
  7555. */
  7556. create: alias(Manager, 'instantiate'),
  7557. /**
  7558. * Convenient shorthand to create a widget by its xtype or a config object.
  7559. * See also {@link Ext.ClassManager#instantiateByAlias}.
  7560. *
  7561. * var button = Ext.widget('button'); // Equivalent to Ext.create('widget.button');
  7562. *
  7563. * var panel = Ext.widget('panel', { // Equivalent to Ext.create('widget.panel')
  7564. * title: 'Panel'
  7565. * });
  7566. *
  7567. * var grid = Ext.widget({
  7568. * xtype: 'grid',
  7569. * ...
  7570. * });
  7571. *
  7572. * If a {@link Ext.Component component} instance is passed, it is simply returned.
  7573. *
  7574. * @member Ext
  7575. * @param {String} [name] The xtype of the widget to create.
  7576. * @param {Object} [config] The configuration object for the widget constructor.
  7577. * @return {Object} The widget instance
  7578. */
  7579. widget: function(name, config) {
  7580. // forms:
  7581. // 1: (xtype)
  7582. // 2: (xtype, config)
  7583. // 3: (config)
  7584. // 4: (xtype, component)
  7585. // 5: (component)
  7586. //
  7587. var xtype = name,
  7588. alias, className, T, load;
  7589. if (typeof xtype != 'string') { // if (form 3 or 5)
  7590. // first arg is config or component
  7591. config = name; // arguments[0]
  7592. xtype = config.xtype;
  7593. } else {
  7594. config = config || {};
  7595. }
  7596. if (config.isComponent) {
  7597. return config;
  7598. }
  7599. alias = 'widget.' + xtype;
  7600. className = Manager.getNameByAlias(alias);
  7601. // this is needed to support demand loading of the class
  7602. if (!className) {
  7603. load = true;
  7604. }
  7605. T = Manager.get(className);
  7606. if (load || !T) {
  7607. return Manager.instantiateByAlias(alias, config);
  7608. }
  7609. return new T(config);
  7610. },
  7611. /**
  7612. * Convenient shorthand, see {@link Ext.ClassManager#instantiateByAlias}
  7613. * @member Ext
  7614. * @method createByAlias
  7615. */
  7616. createByAlias: alias(Manager, 'instantiateByAlias'),
  7617. /**
  7618. * @method
  7619. * Defines a class or override. A basic class is defined like this:
  7620. *
  7621. * Ext.define('My.awesome.Class', {
  7622. * someProperty: 'something',
  7623. *
  7624. * someMethod: function(s) {
  7625. * alert(s + this.someProperty);
  7626. * }
  7627. *
  7628. * ...
  7629. * });
  7630. *
  7631. * var obj = new My.awesome.Class();
  7632. *
  7633. * obj.someMethod('Say '); // alerts 'Say something'
  7634. *
  7635. * To create an anonymous class, pass `null` for the `className`:
  7636. *
  7637. * Ext.define(null, {
  7638. * constructor: function () {
  7639. * // ...
  7640. * }
  7641. * });
  7642. *
  7643. * In some cases, it is helpful to create a nested scope to contain some private
  7644. * properties. The best way to do this is to pass a function instead of an object
  7645. * as the second parameter. This function will be called to produce the class
  7646. * body:
  7647. *
  7648. * Ext.define('MyApp.foo.Bar', function () {
  7649. * var id = 0;
  7650. *
  7651. * return {
  7652. * nextId: function () {
  7653. * return ++id;
  7654. * }
  7655. * };
  7656. * });
  7657. *
  7658. * When using this form of `Ext.define`, the function is passed a reference to its
  7659. * class. This can be used as an efficient way to access any static properties you
  7660. * may have:
  7661. *
  7662. * Ext.define('MyApp.foo.Bar', function (Bar) {
  7663. * return {
  7664. * statics: {
  7665. * staticMethod: function () {
  7666. * // ...
  7667. * }
  7668. * },
  7669. *
  7670. * method: function () {
  7671. * return Bar.staticMethod();
  7672. * }
  7673. * };
  7674. * });
  7675. *
  7676. * To define an override, include the `override` property. The content of an
  7677. * override is aggregated with the specified class in order to extend or modify
  7678. * that class. This can be as simple as setting default property values or it can
  7679. * extend and/or replace methods. This can also extend the statics of the class.
  7680. *
  7681. * One use for an override is to break a large class into manageable pieces.
  7682. *
  7683. * // File: /src/app/Panel.js
  7684. *
  7685. * Ext.define('My.app.Panel', {
  7686. * extend: 'Ext.panel.Panel',
  7687. * requires: [
  7688. * 'My.app.PanelPart2',
  7689. * 'My.app.PanelPart3'
  7690. * ]
  7691. *
  7692. * constructor: function (config) {
  7693. * this.callParent(arguments); // calls Ext.panel.Panel's constructor
  7694. * //...
  7695. * },
  7696. *
  7697. * statics: {
  7698. * method: function () {
  7699. * return 'abc';
  7700. * }
  7701. * }
  7702. * });
  7703. *
  7704. * // File: /src/app/PanelPart2.js
  7705. * Ext.define('My.app.PanelPart2', {
  7706. * override: 'My.app.Panel',
  7707. *
  7708. * constructor: function (config) {
  7709. * this.callParent(arguments); // calls My.app.Panel's constructor
  7710. * //...
  7711. * }
  7712. * });
  7713. *
  7714. * Another use of overrides is to provide optional parts of classes that can be
  7715. * independently required. In this case, the class may even be unaware of the
  7716. * override altogether.
  7717. *
  7718. * Ext.define('My.ux.CoolTip', {
  7719. * override: 'Ext.tip.ToolTip',
  7720. *
  7721. * constructor: function (config) {
  7722. * this.callParent(arguments); // calls Ext.tip.ToolTip's constructor
  7723. * //...
  7724. * }
  7725. * });
  7726. *
  7727. * The above override can now be required as normal.
  7728. *
  7729. * Ext.define('My.app.App', {
  7730. * requires: [
  7731. * 'My.ux.CoolTip'
  7732. * ]
  7733. * });
  7734. *
  7735. * Overrides can also contain statics:
  7736. *
  7737. * Ext.define('My.app.BarMod', {
  7738. * override: 'Ext.foo.Bar',
  7739. *
  7740. * statics: {
  7741. * method: function (x) {
  7742. * return this.callParent([x * 2]); // call Ext.foo.Bar.method
  7743. * }
  7744. * }
  7745. * });
  7746. *
  7747. * IMPORTANT: An override is only included in a build if the class it overrides is
  7748. * required. Otherwise, the override, like the target class, is not included.
  7749. *
  7750. * @param {String} className The class name to create in string dot-namespaced format, for example:
  7751. * 'My.very.awesome.Class', 'FeedViewer.plugin.CoolPager'
  7752. * It is highly recommended to follow this simple convention:
  7753. * - The root and the class name are 'CamelCased'
  7754. * - Everything else is lower-cased
  7755. * Pass `null` to create an anonymous class.
  7756. * @param {Object} data The key - value pairs of properties to apply to this class. Property names can be of any valid
  7757. * strings, except those in the reserved listed below:
  7758. * - `mixins`
  7759. * - `statics`
  7760. * - `config`
  7761. * - `alias`
  7762. * - `self`
  7763. * - `singleton`
  7764. * - `alternateClassName`
  7765. * - `override`
  7766. *
  7767. * @param {Function} createdFn Optional callback to execute after the class is created, the execution scope of which
  7768. * (`this`) will be the newly created class itself.
  7769. * @return {Ext.Base}
  7770. * @markdown
  7771. * @member Ext
  7772. * @method define
  7773. */
  7774. define: function (className, data, createdFn) {
  7775. if (data.override) {
  7776. return Manager.createOverride.apply(Manager, arguments);
  7777. }
  7778. return Manager.create.apply(Manager, arguments);
  7779. },
  7780. /**
  7781. * Convenient shorthand, see {@link Ext.ClassManager#getName}
  7782. * @member Ext
  7783. * @method getClassName
  7784. */
  7785. getClassName: alias(Manager, 'getName'),
  7786. /**
  7787. * Returns the displayName property or className or object. When all else fails, returns "Anonymous".
  7788. * @param {Object} object
  7789. * @return {String}
  7790. */
  7791. getDisplayName: function(object) {
  7792. if (object) {
  7793. if (object.displayName) {
  7794. return object.displayName;
  7795. }
  7796. if (object.$name && object.$class) {
  7797. return Ext.getClassName(object.$class) + '#' + object.$name;
  7798. }
  7799. if (object.$className) {
  7800. return object.$className;
  7801. }
  7802. }
  7803. return 'Anonymous';
  7804. },
  7805. /**
  7806. * Convenient shorthand, see {@link Ext.ClassManager#getClass}
  7807. * @member Ext
  7808. * @method getClass
  7809. */
  7810. getClass: alias(Manager, 'getClass'),
  7811. /**
  7812. * Creates namespaces to be used for scoping variables and classes so that they are not global.
  7813. * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
  7814. *
  7815. * Ext.namespace('Company', 'Company.data');
  7816. *
  7817. * // equivalent and preferable to the above syntax
  7818. * Ext.ns('Company.data');
  7819. *
  7820. * Company.Widget = function() { ... };
  7821. *
  7822. * Company.data.CustomStore = function(config) { ... };
  7823. *
  7824. * @param {String...} namespaces
  7825. * @return {Object} The namespace object.
  7826. * (If multiple arguments are passed, this will be the last namespace created)
  7827. * @member Ext
  7828. * @method namespace
  7829. */
  7830. namespace: alias(Manager, 'createNamespaces')
  7831. });
  7832. /**
  7833. * Old name for {@link Ext#widget}.
  7834. * @deprecated 4.0.0 Use {@link Ext#widget} instead.
  7835. * @method createWidget
  7836. * @member Ext
  7837. */
  7838. Ext.createWidget = Ext.widget;
  7839. /**
  7840. * Convenient alias for {@link Ext#namespace Ext.namespace}.
  7841. * @inheritdoc Ext#namespace
  7842. * @member Ext
  7843. * @method ns
  7844. */
  7845. Ext.ns = Ext.namespace;
  7846. Class.registerPreprocessor('className', function(cls, data) {
  7847. if (data.$className) {
  7848. cls.$className = data.$className;
  7849. cls.displayName = cls.$className;
  7850. }
  7851. }, true, 'first');
  7852. Class.registerPreprocessor('alias', function(cls, data) {
  7853. var prototype = cls.prototype,
  7854. xtypes = arrayFrom(data.xtype),
  7855. aliases = arrayFrom(data.alias),
  7856. widgetPrefix = 'widget.',
  7857. widgetPrefixLength = widgetPrefix.length,
  7858. xtypesChain = Array.prototype.slice.call(prototype.xtypesChain || []),
  7859. xtypesMap = Ext.merge({}, prototype.xtypesMap || {}),
  7860. i, ln, alias, xtype;
  7861. for (i = 0,ln = aliases.length; i < ln; i++) {
  7862. alias = aliases[i];
  7863. if (typeof alias != 'string' || alias.length < 1) {
  7864. throw new Error("[Ext.define] Invalid alias of: '" + alias + "' for class: '" + name + "'; must be a valid string");
  7865. }
  7866. if (alias.substring(0, widgetPrefixLength) === widgetPrefix) {
  7867. xtype = alias.substring(widgetPrefixLength);
  7868. Ext.Array.include(xtypes, xtype);
  7869. }
  7870. }
  7871. cls.xtype = data.xtype = xtypes[0];
  7872. data.xtypes = xtypes;
  7873. for (i = 0,ln = xtypes.length; i < ln; i++) {
  7874. xtype = xtypes[i];
  7875. if (!xtypesMap[xtype]) {
  7876. xtypesMap[xtype] = true;
  7877. xtypesChain.push(xtype);
  7878. }
  7879. }
  7880. data.xtypesChain = xtypesChain;
  7881. data.xtypesMap = xtypesMap;
  7882. Ext.Function.interceptAfter(data, 'onClassCreated', function() {
  7883. var mixins = prototype.mixins,
  7884. key, mixin;
  7885. for (key in mixins) {
  7886. if (mixins.hasOwnProperty(key)) {
  7887. mixin = mixins[key];
  7888. xtypes = mixin.xtypes;
  7889. if (xtypes) {
  7890. for (i = 0,ln = xtypes.length; i < ln; i++) {
  7891. xtype = xtypes[i];
  7892. if (!xtypesMap[xtype]) {
  7893. xtypesMap[xtype] = true;
  7894. xtypesChain.push(xtype);
  7895. }
  7896. }
  7897. }
  7898. }
  7899. }
  7900. });
  7901. for (i = 0,ln = xtypes.length; i < ln; i++) {
  7902. xtype = xtypes[i];
  7903. if (typeof xtype != 'string' || xtype.length < 1) {
  7904. throw new Error("[Ext.define] Invalid xtype of: '" + xtype + "' for class: '" + name + "'; must be a valid non-empty string");
  7905. }
  7906. Ext.Array.include(aliases, widgetPrefix + xtype);
  7907. }
  7908. data.alias = aliases;
  7909. }, ['xtype', 'alias']);
  7910. }(Ext.Class, Ext.Function.alias, Array.prototype.slice, Ext.Array.from, Ext.global));
  7911. //@tag foundation,core
  7912. //@require ClassManager.js
  7913. //@define Ext.Loader
  7914. /**
  7915. * @author Jacky Nguyen <jacky@sencha.com>
  7916. * @docauthor Jacky Nguyen <jacky@sencha.com>
  7917. * @class Ext.Loader
  7918. *
  7919. * Ext.Loader is the heart of the new dynamic dependency loading capability in Ext JS 4+. It is most commonly used
  7920. * via the {@link Ext#require} shorthand. Ext.Loader supports both asynchronous and synchronous loading
  7921. * approaches, and leverage their advantages for the best development flow. We'll discuss about the pros and cons of each approach:
  7922. *
  7923. * # Asynchronous Loading #
  7924. *
  7925. * - Advantages:
  7926. * + Cross-domain
  7927. * + No web server needed: you can run the application via the file system protocol (i.e: `file://path/to/your/index
  7928. * .html`)
  7929. * + Best possible debugging experience: error messages come with the exact file name and line number
  7930. *
  7931. * - Disadvantages:
  7932. * + Dependencies need to be specified before-hand
  7933. *
  7934. * ### Method 1: Explicitly include what you need: ###
  7935. *
  7936. * // Syntax
  7937. * Ext.require({String/Array} expressions);
  7938. *
  7939. * // Example: Single alias
  7940. * Ext.require('widget.window');
  7941. *
  7942. * // Example: Single class name
  7943. * Ext.require('Ext.window.Window');
  7944. *
  7945. * // Example: Multiple aliases / class names mix
  7946. * Ext.require(['widget.window', 'layout.border', 'Ext.data.Connection']);
  7947. *
  7948. * // Wildcards
  7949. * Ext.require(['widget.*', 'layout.*', 'Ext.data.*']);
  7950. *
  7951. * ### Method 2: Explicitly exclude what you don't need: ###
  7952. *
  7953. * // Syntax: Note that it must be in this chaining format.
  7954. * Ext.exclude({String/Array} expressions)
  7955. * .require({String/Array} expressions);
  7956. *
  7957. * // Include everything except Ext.data.*
  7958. * Ext.exclude('Ext.data.*').require('*');
  7959. *
  7960. * // Include all widgets except widget.checkbox*,
  7961. * // which will match widget.checkbox, widget.checkboxfield, widget.checkboxgroup, etc.
  7962. * Ext.exclude('widget.checkbox*').require('widget.*');
  7963. *
  7964. * # Synchronous Loading on Demand #
  7965. *
  7966. * - Advantages:
  7967. * + There's no need to specify dependencies before-hand, which is always the convenience of including ext-all.js
  7968. * before
  7969. *
  7970. * - Disadvantages:
  7971. * + Not as good debugging experience since file name won't be shown (except in Firebug at the moment)
  7972. * + Must be from the same domain due to XHR restriction
  7973. * + Need a web server, same reason as above
  7974. *
  7975. * There's one simple rule to follow: Instantiate everything with Ext.create instead of the `new` keyword
  7976. *
  7977. * Ext.create('widget.window', { ... }); // Instead of new Ext.window.Window({...});
  7978. *
  7979. * Ext.create('Ext.window.Window', {}); // Same as above, using full class name instead of alias
  7980. *
  7981. * Ext.widget('window', {}); // Same as above, all you need is the traditional `xtype`
  7982. *
  7983. * Behind the scene, {@link Ext.ClassManager} will automatically check whether the given class name / alias has already
  7984. * existed on the page. If it's not, Ext.Loader will immediately switch itself to synchronous mode and automatic load the given
  7985. * class and all its dependencies.
  7986. *
  7987. * # Hybrid Loading - The Best of Both Worlds #
  7988. *
  7989. * It has all the advantages combined from asynchronous and synchronous loading. The development flow is simple:
  7990. *
  7991. * ### Step 1: Start writing your application using synchronous approach.
  7992. *
  7993. * Ext.Loader will automatically fetch all dependencies on demand as they're needed during run-time. For example:
  7994. *
  7995. * Ext.onReady(function(){
  7996. * var window = Ext.widget('window', {
  7997. * width: 500,
  7998. * height: 300,
  7999. * layout: {
  8000. * type: 'border',
  8001. * padding: 5
  8002. * },
  8003. * title: 'Hello Dialog',
  8004. * items: [{
  8005. * title: 'Navigation',
  8006. * collapsible: true,
  8007. * region: 'west',
  8008. * width: 200,
  8009. * html: 'Hello',
  8010. * split: true
  8011. * }, {
  8012. * title: 'TabPanel',
  8013. * region: 'center'
  8014. * }]
  8015. * });
  8016. *
  8017. * window.show();
  8018. * })
  8019. *
  8020. * ### Step 2: Along the way, when you need better debugging ability, watch the console for warnings like these: ###
  8021. *
  8022. * [Ext.Loader] Synchronously loading 'Ext.window.Window'; consider adding Ext.require('Ext.window.Window') before your application's code
  8023. * ClassManager.js:432
  8024. * [Ext.Loader] Synchronously loading 'Ext.layout.container.Border'; consider adding Ext.require('Ext.layout.container.Border') before your application's code
  8025. *
  8026. * Simply copy and paste the suggested code above `Ext.onReady`, i.e:
  8027. *
  8028. * Ext.require('Ext.window.Window');
  8029. * Ext.require('Ext.layout.container.Border');
  8030. *
  8031. * Ext.onReady(...);
  8032. *
  8033. * Everything should now load via asynchronous mode.
  8034. *
  8035. * # Deployment #
  8036. *
  8037. * It's important to note that dynamic loading should only be used during development on your local machines.
  8038. * During production, all dependencies should be combined into one single JavaScript file. Ext.Loader makes
  8039. * the whole process of transitioning from / to between development / maintenance and production as easy as
  8040. * possible. Internally {@link Ext.Loader#history Ext.Loader.history} maintains the list of all dependencies your application
  8041. * needs in the exact loading sequence. It's as simple as concatenating all files in this array into one,
  8042. * then include it on top of your application.
  8043. *
  8044. * This process will be automated with Sencha Command, to be released and documented towards Ext JS 4 Final.
  8045. *
  8046. * @singleton
  8047. */
  8048. Ext.Loader = new function() {
  8049. var Loader = this,
  8050. Manager = Ext.ClassManager,
  8051. Class = Ext.Class,
  8052. flexSetter = Ext.Function.flexSetter,
  8053. alias = Ext.Function.alias,
  8054. pass = Ext.Function.pass,
  8055. defer = Ext.Function.defer,
  8056. arrayErase = Ext.Array.erase,
  8057. dependencyProperties = ['extend', 'mixins', 'requires'],
  8058. isInHistory = {},
  8059. history = [],
  8060. slashDotSlashRe = /\/\.\//g,
  8061. dotRe = /\./g;
  8062. Ext.apply(Loader, {
  8063. /**
  8064. * @private
  8065. */
  8066. isInHistory: isInHistory,
  8067. /**
  8068. * An array of class names to keep track of the dependency loading order.
  8069. * This is not guaranteed to be the same everytime due to the asynchronous
  8070. * nature of the Loader.
  8071. *
  8072. * @property {Array} history
  8073. */
  8074. history: history,
  8075. /**
  8076. * Configuration
  8077. * @private
  8078. */
  8079. config: {
  8080. /**
  8081. * @cfg {Boolean} enabled
  8082. * Whether or not to enable the dynamic dependency loading feature.
  8083. */
  8084. enabled: false,
  8085. /**
  8086. * @cfg {Boolean} scriptChainDelay
  8087. * millisecond delay between asynchronous script injection (prevents stack overflow on some user agents)
  8088. * 'false' disables delay but potentially increases stack load.
  8089. */
  8090. scriptChainDelay : false,
  8091. /**
  8092. * @cfg {Boolean} disableCaching
  8093. * Appends current timestamp to script files to prevent caching.
  8094. */
  8095. disableCaching: true,
  8096. /**
  8097. * @cfg {String} disableCachingParam
  8098. * The get parameter name for the cache buster's timestamp.
  8099. */
  8100. disableCachingParam: '_dc',
  8101. /**
  8102. * @cfg {Boolean} garbageCollect
  8103. * True to prepare an asynchronous script tag for garbage collection (effective only
  8104. * if {@link #preserveScripts preserveScripts} is false)
  8105. */
  8106. garbageCollect : false,
  8107. /**
  8108. * @cfg {Object} paths
  8109. * The mapping from namespaces to file paths
  8110. *
  8111. * {
  8112. * 'Ext': '.', // This is set by default, Ext.layout.container.Container will be
  8113. * // loaded from ./layout/Container.js
  8114. *
  8115. * 'My': './src/my_own_folder' // My.layout.Container will be loaded from
  8116. * // ./src/my_own_folder/layout/Container.js
  8117. * }
  8118. *
  8119. * Note that all relative paths are relative to the current HTML document.
  8120. * If not being specified, for example, <code>Other.awesome.Class</code>
  8121. * will simply be loaded from <code>./Other/awesome/Class.js</code>
  8122. */
  8123. paths: {
  8124. 'Ext': '.'
  8125. },
  8126. /**
  8127. * @cfg {Boolean} preserveScripts
  8128. * False to remove and optionally {@link #garbageCollect garbage-collect} asynchronously loaded scripts,
  8129. * True to retain script element for browser debugger compatibility and improved load performance.
  8130. */
  8131. preserveScripts : true,
  8132. /**
  8133. * @cfg {String} scriptCharset
  8134. * Optional charset to specify encoding of dynamic script content.
  8135. */
  8136. scriptCharset : undefined
  8137. },
  8138. /**
  8139. * Set the configuration for the loader. This should be called right after ext-(debug).js
  8140. * is included in the page, and before Ext.onReady. i.e:
  8141. *
  8142. * <script type="text/javascript" src="ext-core-debug.js"></script>
  8143. * <script type="text/javascript">
  8144. * Ext.Loader.setConfig({
  8145. * enabled: true,
  8146. * paths: {
  8147. * 'My': 'my_own_path'
  8148. * }
  8149. * });
  8150. * </script>
  8151. * <script type="text/javascript">
  8152. * Ext.require(...);
  8153. *
  8154. * Ext.onReady(function() {
  8155. * // application code here
  8156. * });
  8157. * </script>
  8158. *
  8159. * Refer to config options of {@link Ext.Loader} for the list of possible properties
  8160. *
  8161. * @param {Object} config The config object to override the default values
  8162. * @return {Ext.Loader} this
  8163. */
  8164. setConfig: function(name, value) {
  8165. if (Ext.isObject(name) && arguments.length === 1) {
  8166. Ext.merge(Loader.config, name);
  8167. }
  8168. else {
  8169. Loader.config[name] = (Ext.isObject(value)) ? Ext.merge(Loader.config[name], value) : value;
  8170. }
  8171. return Loader;
  8172. },
  8173. /**
  8174. * Get the config value corresponding to the specified name. If no name is given, will return the config object
  8175. * @param {String} name The config property name
  8176. * @return {Object}
  8177. */
  8178. getConfig: function(name) {
  8179. if (name) {
  8180. return Loader.config[name];
  8181. }
  8182. return Loader.config;
  8183. },
  8184. /**
  8185. * Sets the path of a namespace.
  8186. * For Example:
  8187. *
  8188. * Ext.Loader.setPath('Ext', '.');
  8189. *
  8190. * @param {String/Object} name See {@link Ext.Function#flexSetter flexSetter}
  8191. * @param {String} path See {@link Ext.Function#flexSetter flexSetter}
  8192. * @return {Ext.Loader} this
  8193. * @method
  8194. */
  8195. setPath: flexSetter(function(name, path) {
  8196. Loader.config.paths[name] = path;
  8197. return Loader;
  8198. }),
  8199. /**
  8200. * Sets a batch of path entries
  8201. *
  8202. * @param {Object } paths a set of className: path mappings
  8203. * @return {Ext.Loader} this
  8204. */
  8205. addClassPathMappings: function(paths) {
  8206. var name;
  8207. for(name in paths){
  8208. Loader.config.paths[name] = paths[name];
  8209. }
  8210. return Loader;
  8211. },
  8212. /**
  8213. * Translates a className to a file path by adding the
  8214. * the proper prefix and converting the .'s to /'s. For example:
  8215. *
  8216. * Ext.Loader.setPath('My', '/path/to/My');
  8217. *
  8218. * alert(Ext.Loader.getPath('My.awesome.Class')); // alerts '/path/to/My/awesome/Class.js'
  8219. *
  8220. * Note that the deeper namespace levels, if explicitly set, are always resolved first. For example:
  8221. *
  8222. * Ext.Loader.setPath({
  8223. * 'My': '/path/to/lib',
  8224. * 'My.awesome': '/other/path/for/awesome/stuff',
  8225. * 'My.awesome.more': '/more/awesome/path'
  8226. * });
  8227. *
  8228. * alert(Ext.Loader.getPath('My.awesome.Class')); // alerts '/other/path/for/awesome/stuff/Class.js'
  8229. *
  8230. * alert(Ext.Loader.getPath('My.awesome.more.Class')); // alerts '/more/awesome/path/Class.js'
  8231. *
  8232. * alert(Ext.Loader.getPath('My.cool.Class')); // alerts '/path/to/lib/cool/Class.js'
  8233. *
  8234. * alert(Ext.Loader.getPath('Unknown.strange.Stuff')); // alerts 'Unknown/strange/Stuff.js'
  8235. *
  8236. * @param {String} className
  8237. * @return {String} path
  8238. */
  8239. getPath: function(className) {
  8240. var path = '',
  8241. paths = Loader.config.paths,
  8242. prefix = Loader.getPrefix(className);
  8243. if (prefix.length > 0) {
  8244. if (prefix === className) {
  8245. return paths[prefix];
  8246. }
  8247. path = paths[prefix];
  8248. className = className.substring(prefix.length + 1);
  8249. }
  8250. if (path.length > 0) {
  8251. path += '/';
  8252. }
  8253. return path.replace(slashDotSlashRe, '/') + className.replace(dotRe, "/") + '.js';
  8254. },
  8255. /**
  8256. * @private
  8257. * @param {String} className
  8258. */
  8259. getPrefix: function(className) {
  8260. var paths = Loader.config.paths,
  8261. prefix, deepestPrefix = '';
  8262. if (paths.hasOwnProperty(className)) {
  8263. return className;
  8264. }
  8265. for (prefix in paths) {
  8266. if (paths.hasOwnProperty(prefix) && prefix + '.' === className.substring(0, prefix.length + 1)) {
  8267. if (prefix.length > deepestPrefix.length) {
  8268. deepestPrefix = prefix;
  8269. }
  8270. }
  8271. }
  8272. return deepestPrefix;
  8273. },
  8274. /**
  8275. * @private
  8276. * @param {String} className
  8277. */
  8278. isAClassNameWithAKnownPrefix: function(className) {
  8279. var prefix = Loader.getPrefix(className);
  8280. // we can only say it's really a class if className is not equal to any known namespace
  8281. return prefix !== '' && prefix !== className;
  8282. },
  8283. /**
  8284. * Loads all classes by the given names and all their direct dependencies; optionally executes the given callback function when
  8285. * finishes, within the optional scope. This method is aliased by {@link Ext#require Ext.require} for convenience
  8286. * @param {String/Array} expressions Can either be a string or an array of string
  8287. * @param {Function} fn (Optional) The callback function
  8288. * @param {Object} scope (Optional) The execution scope (`this`) of the callback function
  8289. * @param {String/Array} excludes (Optional) Classes to be excluded, useful when being used with expressions
  8290. */
  8291. require: function(expressions, fn, scope, excludes) {
  8292. if (fn) {
  8293. fn.call(scope);
  8294. }
  8295. },
  8296. /**
  8297. * Synchronously loads all classes by the given names and all their direct dependencies; optionally executes the given callback function when finishes, within the optional scope. This method is aliased by {@link Ext#syncRequire} for convenience
  8298. * @param {String/Array} expressions Can either be a string or an array of string
  8299. * @param {Function} fn (Optional) The callback function
  8300. * @param {Object} scope (Optional) The execution scope (`this`) of the callback function
  8301. * @param {String/Array} excludes (Optional) Classes to be excluded, useful when being used with expressions
  8302. */
  8303. syncRequire: function() {},
  8304. /**
  8305. * Explicitly exclude files from being loaded. Useful when used in conjunction with a broad include expression.
  8306. * Can be chained with more `require` and `exclude` methods, eg:
  8307. *
  8308. * Ext.exclude('Ext.data.*').require('*');
  8309. *
  8310. * Ext.exclude('widget.button*').require('widget.*');
  8311. *
  8312. * @param {Array} excludes
  8313. * @return {Object} object contains `require` method for chaining
  8314. */
  8315. exclude: function(excludes) {
  8316. return {
  8317. require: function(expressions, fn, scope) {
  8318. return Loader.require(expressions, fn, scope, excludes);
  8319. },
  8320. syncRequire: function(expressions, fn, scope) {
  8321. return Loader.syncRequire(expressions, fn, scope, excludes);
  8322. }
  8323. };
  8324. },
  8325. /**
  8326. * Add a new listener to be executed when all required scripts are fully loaded
  8327. *
  8328. * @param {Function} fn The function callback to be executed
  8329. * @param {Object} scope The execution scope (<code>this</code>) of the callback function
  8330. * @param {Boolean} withDomReady Whether or not to wait for document dom ready as well
  8331. */
  8332. onReady: function(fn, scope, withDomReady, options) {
  8333. var oldFn;
  8334. if (withDomReady !== false && Ext.onDocumentReady) {
  8335. oldFn = fn;
  8336. fn = function() {
  8337. Ext.onDocumentReady(oldFn, scope, options);
  8338. };
  8339. }
  8340. fn.call(scope);
  8341. }
  8342. });
  8343. var queue = [],
  8344. isClassFileLoaded = {},
  8345. isFileLoaded = {},
  8346. classNameToFilePathMap = {},
  8347. scriptElements = {},
  8348. readyListeners = [],
  8349. usedClasses = [],
  8350. requiresMap = {};
  8351. Ext.apply(Loader, {
  8352. /**
  8353. * @private
  8354. */
  8355. documentHead: typeof document != 'undefined' && (document.head || document.getElementsByTagName('head')[0]),
  8356. /**
  8357. * Flag indicating whether there are still files being loaded
  8358. * @private
  8359. */
  8360. isLoading: false,
  8361. /**
  8362. * Maintain the queue for all dependencies. Each item in the array is an object of the format:
  8363. *
  8364. * {
  8365. * requires: [...], // The required classes for this queue item
  8366. * callback: function() { ... } // The function to execute when all classes specified in requires exist
  8367. * }
  8368. *
  8369. * @private
  8370. */
  8371. queue: queue,
  8372. /**
  8373. * Maintain the list of files that have already been handled so that they never get double-loaded
  8374. * @private
  8375. */
  8376. isClassFileLoaded: isClassFileLoaded,
  8377. /**
  8378. * @private
  8379. */
  8380. isFileLoaded: isFileLoaded,
  8381. /**
  8382. * Maintain the list of listeners to execute when all required scripts are fully loaded
  8383. * @private
  8384. */
  8385. readyListeners: readyListeners,
  8386. /**
  8387. * Contains classes referenced in `uses` properties.
  8388. * @private
  8389. */
  8390. optionalRequires: usedClasses,
  8391. /**
  8392. * Map of fully qualified class names to an array of dependent classes.
  8393. * @private
  8394. */
  8395. requiresMap: requiresMap,
  8396. /**
  8397. * @private
  8398. */
  8399. numPendingFiles: 0,
  8400. /**
  8401. * @private
  8402. */
  8403. numLoadedFiles: 0,
  8404. /** @private */
  8405. hasFileLoadError: false,
  8406. /**
  8407. * @private
  8408. */
  8409. classNameToFilePathMap: classNameToFilePathMap,
  8410. /**
  8411. * The number of scripts loading via loadScript.
  8412. * @private
  8413. */
  8414. scriptsLoading: 0,
  8415. /**
  8416. * @private
  8417. */
  8418. syncModeEnabled: false,
  8419. scriptElements: scriptElements,
  8420. /**
  8421. * Refresh all items in the queue. If all dependencies for an item exist during looping,
  8422. * it will execute the callback and call refreshQueue again. Triggers onReady when the queue is
  8423. * empty
  8424. * @private
  8425. */
  8426. refreshQueue: function() {
  8427. var ln = queue.length,
  8428. i, item, j, requires;
  8429. // When the queue of loading classes reaches zero, trigger readiness
  8430. if (!ln && !Loader.scriptsLoading) {
  8431. return Loader.triggerReady();
  8432. }
  8433. for (i = 0; i < ln; i++) {
  8434. item = queue[i];
  8435. if (item) {
  8436. requires = item.requires;
  8437. // Don't bother checking when the number of files loaded
  8438. // is still less than the array length
  8439. if (requires.length > Loader.numLoadedFiles) {
  8440. continue;
  8441. }
  8442. // Remove any required classes that are loaded
  8443. for (j = 0; j < requires.length; ) {
  8444. if (Manager.isCreated(requires[j])) {
  8445. // Take out from the queue
  8446. arrayErase(requires, j, 1);
  8447. }
  8448. else {
  8449. j++;
  8450. }
  8451. }
  8452. // If we've ended up with no required classes, call the callback
  8453. if (item.requires.length === 0) {
  8454. arrayErase(queue, i, 1);
  8455. item.callback.call(item.scope);
  8456. Loader.refreshQueue();
  8457. break;
  8458. }
  8459. }
  8460. }
  8461. return Loader;
  8462. },
  8463. /**
  8464. * Inject a script element to document's head, call onLoad and onError accordingly
  8465. * @private
  8466. */
  8467. injectScriptElement: function(url, onLoad, onError, scope, charset) {
  8468. var script = document.createElement('script'),
  8469. dispatched = false,
  8470. config = Loader.config,
  8471. onLoadFn = function() {
  8472. if(!dispatched) {
  8473. dispatched = true;
  8474. script.onload = script.onreadystatechange = script.onerror = null;
  8475. if (typeof config.scriptChainDelay == 'number') {
  8476. //free the stack (and defer the next script)
  8477. defer(onLoad, config.scriptChainDelay, scope);
  8478. } else {
  8479. onLoad.call(scope);
  8480. }
  8481. Loader.cleanupScriptElement(script, config.preserveScripts === false, config.garbageCollect);
  8482. }
  8483. },
  8484. onErrorFn = function(arg) {
  8485. defer(onError, 1, scope); //free the stack
  8486. Loader.cleanupScriptElement(script, config.preserveScripts === false, config.garbageCollect);
  8487. };
  8488. script.type = 'text/javascript';
  8489. script.onerror = onErrorFn;
  8490. charset = charset || config.scriptCharset;
  8491. if (charset) {
  8492. script.charset = charset;
  8493. }
  8494. /*
  8495. * IE9 Standards mode (and others) SHOULD follow the load event only
  8496. * (Note: IE9 supports both onload AND readystatechange events)
  8497. */
  8498. if ('addEventListener' in script ) {
  8499. script.onload = onLoadFn;
  8500. } else if ('readyState' in script) { // for <IE9 Compatability
  8501. script.onreadystatechange = function() {
  8502. if ( this.readyState == 'loaded' || this.readyState == 'complete' ) {
  8503. onLoadFn();
  8504. }
  8505. };
  8506. } else {
  8507. script.onload = onLoadFn;
  8508. }
  8509. script.src = url;
  8510. (Loader.documentHead || document.getElementsByTagName('head')[0]).appendChild(script);
  8511. return script;
  8512. },
  8513. /**
  8514. * @private
  8515. */
  8516. removeScriptElement: function(url) {
  8517. if (scriptElements[url]) {
  8518. Loader.cleanupScriptElement(scriptElements[url], true, !!Loader.getConfig('garbageCollect'));
  8519. delete scriptElements[url];
  8520. }
  8521. return Loader;
  8522. },
  8523. /**
  8524. * @private
  8525. */
  8526. cleanupScriptElement: function(script, remove, collect) {
  8527. var prop;
  8528. script.onload = script.onreadystatechange = script.onerror = null;
  8529. if (remove) {
  8530. Ext.removeNode(script); // Remove, since its useless now
  8531. if (collect) {
  8532. for (prop in script) {
  8533. try {
  8534. script[prop] = null;
  8535. delete script[prop]; // and prepare for GC
  8536. } catch (cleanEx) {
  8537. //ignore
  8538. }
  8539. }
  8540. }
  8541. }
  8542. return Loader;
  8543. },
  8544. /**
  8545. * Loads the specified script URL and calls the supplied callbacks. If this method
  8546. * is called before {@link Ext#isReady}, the script's load will delay the transition
  8547. * to ready. This can be used to load arbitrary scripts that may contain further
  8548. * {@link Ext#require Ext.require} calls.
  8549. *
  8550. * @param {Object/String} options The options object or simply the URL to load.
  8551. * @param {String} options.url The URL from which to load the script.
  8552. * @param {Function} [options.onLoad] The callback to call on successful load.
  8553. * @param {Function} [options.onError] The callback to call on failure to load.
  8554. * @param {Object} [options.scope] The scope (`this`) for the supplied callbacks.
  8555. */
  8556. loadScript: function (options) {
  8557. var config = Loader.getConfig(),
  8558. isString = typeof options == 'string',
  8559. url = isString ? options : options.url,
  8560. onError = !isString && options.onError,
  8561. onLoad = !isString && options.onLoad,
  8562. scope = !isString && options.scope,
  8563. onScriptError = function() {
  8564. Loader.numPendingFiles--;
  8565. Loader.scriptsLoading--;
  8566. if (onError) {
  8567. onError.call(scope, "Failed loading '" + url + "', please verify that the file exists");
  8568. }
  8569. if (Loader.numPendingFiles + Loader.scriptsLoading === 0) {
  8570. Loader.refreshQueue();
  8571. }
  8572. },
  8573. onScriptLoad = function () {
  8574. Loader.numPendingFiles--;
  8575. Loader.scriptsLoading--;
  8576. if (onLoad) {
  8577. onLoad.call(scope);
  8578. }
  8579. if (Loader.numPendingFiles + Loader.scriptsLoading === 0) {
  8580. Loader.refreshQueue();
  8581. }
  8582. },
  8583. src;
  8584. Loader.isLoading = true;
  8585. Loader.numPendingFiles++;
  8586. Loader.scriptsLoading++;
  8587. src = config.disableCaching ?
  8588. (url + '?' + config.disableCachingParam + '=' + Ext.Date.now()) : url;
  8589. scriptElements[url] = Loader.injectScriptElement(src, onScriptLoad, onScriptError);
  8590. },
  8591. /**
  8592. * Load a script file, supports both asynchronous and synchronous approaches
  8593. * @private
  8594. */
  8595. loadScriptFile: function(url, onLoad, onError, scope, synchronous) {
  8596. if (isFileLoaded[url]) {
  8597. return Loader;
  8598. }
  8599. var config = Loader.getConfig(),
  8600. noCacheUrl = url + (config.disableCaching ? ('?' + config.disableCachingParam + '=' + Ext.Date.now()) : ''),
  8601. isCrossOriginRestricted = false,
  8602. xhr, status, onScriptError,
  8603. debugSourceURL = "";
  8604. scope = scope || Loader;
  8605. Loader.isLoading = true;
  8606. if (!synchronous) {
  8607. onScriptError = function() {
  8608. onError.call(scope, "Failed loading '" + url + "', please verify that the file exists", synchronous);
  8609. };
  8610. scriptElements[url] = Loader.injectScriptElement(noCacheUrl, onLoad, onScriptError, scope);
  8611. } else {
  8612. if (typeof XMLHttpRequest != 'undefined') {
  8613. xhr = new XMLHttpRequest();
  8614. } else {
  8615. xhr = new ActiveXObject('Microsoft.XMLHTTP');
  8616. }
  8617. try {
  8618. xhr.open('GET', noCacheUrl, false);
  8619. xhr.send(null);
  8620. } catch (e) {
  8621. isCrossOriginRestricted = true;
  8622. }
  8623. status = (xhr.status === 1223) ? 204 :
  8624. (xhr.status === 0 && (self.location || {}).protocol == 'file:') ? 200 : xhr.status;
  8625. isCrossOriginRestricted = isCrossOriginRestricted || (status === 0);
  8626. if (isCrossOriginRestricted
  8627. ) {
  8628. onError.call(Loader, "Failed loading synchronously via XHR: '" + url + "'; It's likely that the file is either " +
  8629. "being loaded from a different domain or from the local file system whereby cross origin " +
  8630. "requests are not allowed due to security reasons. Use asynchronous loading with " +
  8631. "Ext.require instead.", synchronous);
  8632. }
  8633. else if ((status >= 200 && status < 300) || (status === 304)
  8634. ) {
  8635. // Debugger friendly, file names are still shown even though they're eval'ed code
  8636. // Breakpoints work on both Firebug and Chrome's Web Inspector
  8637. if (!Ext.isIE) {
  8638. debugSourceURL = "\n//@ sourceURL=" + url;
  8639. }
  8640. Ext.globalEval(xhr.responseText + debugSourceURL);
  8641. onLoad.call(scope);
  8642. }
  8643. else {
  8644. onError.call(Loader, "Failed loading synchronously via XHR: '" + url + "'; please " +
  8645. "verify that the file exists. " +
  8646. "XHR status code: " + status, synchronous);
  8647. }
  8648. // Prevent potential IE memory leak
  8649. xhr = null;
  8650. }
  8651. },
  8652. // documented above
  8653. syncRequire: function() {
  8654. var syncModeEnabled = Loader.syncModeEnabled;
  8655. if (!syncModeEnabled) {
  8656. Loader.syncModeEnabled = true;
  8657. }
  8658. Loader.require.apply(Loader, arguments);
  8659. if (!syncModeEnabled) {
  8660. Loader.syncModeEnabled = false;
  8661. }
  8662. Loader.refreshQueue();
  8663. },
  8664. // documented above
  8665. require: function(expressions, fn, scope, excludes) {
  8666. var excluded = {},
  8667. included = {},
  8668. excludedClassNames = [],
  8669. possibleClassNames = [],
  8670. classNames = [],
  8671. references = [],
  8672. callback,
  8673. syncModeEnabled,
  8674. filePath, expression, exclude, className,
  8675. possibleClassName, i, j, ln, subLn;
  8676. if (excludes) {
  8677. // Convert possible single string to an array.
  8678. excludes = (typeof excludes === 'string') ? [ excludes ] : excludes;
  8679. for (i = 0,ln = excludes.length; i < ln; i++) {
  8680. exclude = excludes[i];
  8681. if (typeof exclude == 'string' && exclude.length > 0) {
  8682. excludedClassNames = Manager.getNamesByExpression(exclude);
  8683. for (j = 0,subLn = excludedClassNames.length; j < subLn; j++) {
  8684. excluded[excludedClassNames[j]] = true;
  8685. }
  8686. }
  8687. }
  8688. }
  8689. // Convert possible single string to an array.
  8690. expressions = (typeof expressions === 'string') ? [ expressions ] : (expressions ? expressions : []);
  8691. if (fn) {
  8692. if (fn.length > 0) {
  8693. callback = function() {
  8694. var classes = [],
  8695. i, ln;
  8696. for (i = 0,ln = references.length; i < ln; i++) {
  8697. classes.push(Manager.get(references[i]));
  8698. }
  8699. return fn.apply(this, classes);
  8700. };
  8701. }
  8702. else {
  8703. callback = fn;
  8704. }
  8705. }
  8706. else {
  8707. callback = Ext.emptyFn;
  8708. }
  8709. scope = scope || Ext.global;
  8710. for (i = 0,ln = expressions.length; i < ln; i++) {
  8711. expression = expressions[i];
  8712. if (typeof expression == 'string' && expression.length > 0) {
  8713. possibleClassNames = Manager.getNamesByExpression(expression);
  8714. subLn = possibleClassNames.length;
  8715. for (j = 0; j < subLn; j++) {
  8716. possibleClassName = possibleClassNames[j];
  8717. if (excluded[possibleClassName] !== true) {
  8718. references.push(possibleClassName);
  8719. if (!Manager.isCreated(possibleClassName) && !included[possibleClassName]) {
  8720. included[possibleClassName] = true;
  8721. classNames.push(possibleClassName);
  8722. }
  8723. }
  8724. }
  8725. }
  8726. }
  8727. // If the dynamic dependency feature is not being used, throw an error
  8728. // if the dependencies are not defined
  8729. if (classNames.length > 0) {
  8730. if (!Loader.config.enabled) {
  8731. throw new Error("Ext.Loader is not enabled, so dependencies cannot be resolved dynamically. " +
  8732. "Missing required class" + ((classNames.length > 1) ? "es" : "") + ": " + classNames.join(', '));
  8733. }
  8734. }
  8735. else {
  8736. callback.call(scope);
  8737. return Loader;
  8738. }
  8739. syncModeEnabled = Loader.syncModeEnabled;
  8740. if (!syncModeEnabled) {
  8741. queue.push({
  8742. requires: classNames.slice(), // this array will be modified as the queue is processed,
  8743. // so we need a copy of it
  8744. callback: callback,
  8745. scope: scope
  8746. });
  8747. }
  8748. ln = classNames.length;
  8749. for (i = 0; i < ln; i++) {
  8750. className = classNames[i];
  8751. filePath = Loader.getPath(className);
  8752. // If we are synchronously loading a file that has already been asychronously loaded before
  8753. // we need to destroy the script tag and revert the count
  8754. // This file will then be forced loaded in synchronous
  8755. if (syncModeEnabled && isClassFileLoaded.hasOwnProperty(className)) {
  8756. Loader.numPendingFiles--;
  8757. Loader.removeScriptElement(filePath);
  8758. delete isClassFileLoaded[className];
  8759. }
  8760. if (!isClassFileLoaded.hasOwnProperty(className)) {
  8761. isClassFileLoaded[className] = false;
  8762. classNameToFilePathMap[className] = filePath;
  8763. Loader.numPendingFiles++;
  8764. Loader.loadScriptFile(
  8765. filePath,
  8766. pass(Loader.onFileLoaded, [className, filePath], Loader),
  8767. pass(Loader.onFileLoadError, [className, filePath], Loader),
  8768. Loader,
  8769. syncModeEnabled
  8770. );
  8771. }
  8772. }
  8773. if (syncModeEnabled) {
  8774. callback.call(scope);
  8775. if (ln === 1) {
  8776. return Manager.get(className);
  8777. }
  8778. }
  8779. return Loader;
  8780. },
  8781. /**
  8782. * @private
  8783. * @param {String} className
  8784. * @param {String} filePath
  8785. */
  8786. onFileLoaded: function(className, filePath) {
  8787. Loader.numLoadedFiles++;
  8788. isClassFileLoaded[className] = true;
  8789. isFileLoaded[filePath] = true;
  8790. Loader.numPendingFiles--;
  8791. if (Loader.numPendingFiles === 0) {
  8792. Loader.refreshQueue();
  8793. }
  8794. if (!Loader.syncModeEnabled && Loader.numPendingFiles === 0 && Loader.isLoading && !Loader.hasFileLoadError) {
  8795. var missingClasses = [],
  8796. missingPaths = [],
  8797. requires,
  8798. i, ln, j, subLn;
  8799. for (i = 0,ln = queue.length; i < ln; i++) {
  8800. requires = queue[i].requires;
  8801. for (j = 0,subLn = requires.length; j < subLn; j++) {
  8802. if (isClassFileLoaded[requires[j]]) {
  8803. missingClasses.push(requires[j]);
  8804. }
  8805. }
  8806. }
  8807. if (missingClasses.length < 1) {
  8808. return;
  8809. }
  8810. missingClasses = Ext.Array.filter(Ext.Array.unique(missingClasses), function(item) {
  8811. return !requiresMap.hasOwnProperty(item);
  8812. }, Loader);
  8813. for (i = 0,ln = missingClasses.length; i < ln; i++) {
  8814. missingPaths.push(classNameToFilePathMap[missingClasses[i]]);
  8815. }
  8816. throw new Error("The following classes are not declared even if their files have been " +
  8817. "loaded: '" + missingClasses.join("', '") + "'. Please check the source code of their " +
  8818. "corresponding files for possible typos: '" + missingPaths.join("', '"));
  8819. }
  8820. },
  8821. /**
  8822. * @private
  8823. */
  8824. onFileLoadError: function(className, filePath, errorMessage, isSynchronous) {
  8825. Loader.numPendingFiles--;
  8826. Loader.hasFileLoadError = true;
  8827. throw new Error("[Ext.Loader] " + errorMessage);
  8828. },
  8829. /**
  8830. * @private
  8831. * Ensure that any classes referenced in the `uses` property are loaded.
  8832. */
  8833. addUsedClasses: function (classes) {
  8834. var cls, i, ln;
  8835. if (classes) {
  8836. classes = (typeof classes == 'string') ? [classes] : classes;
  8837. for (i = 0, ln = classes.length; i < ln; i++) {
  8838. cls = classes[i];
  8839. if (typeof cls == 'string' && !Ext.Array.contains(usedClasses, cls)) {
  8840. usedClasses.push(cls);
  8841. }
  8842. }
  8843. }
  8844. return Loader;
  8845. },
  8846. /**
  8847. * @private
  8848. */
  8849. triggerReady: function() {
  8850. var listener,
  8851. i, refClasses = usedClasses;
  8852. if (Loader.isLoading) {
  8853. Loader.isLoading = false;
  8854. if (refClasses.length !== 0) {
  8855. // Clone then empty the array to eliminate potential recursive loop issue
  8856. refClasses = refClasses.slice();
  8857. usedClasses.length = 0;
  8858. // this may immediately call us back if all 'uses' classes
  8859. // have been loaded
  8860. Loader.require(refClasses, Loader.triggerReady, Loader);
  8861. return Loader;
  8862. }
  8863. }
  8864. // this method can be called with Loader.isLoading either true or false
  8865. // (can be called with false when all 'uses' classes are already loaded)
  8866. // this may bypass the above if condition
  8867. while (readyListeners.length && !Loader.isLoading) {
  8868. // calls to refreshQueue may re-enter triggerReady
  8869. // so we cannot necessarily iterate the readyListeners array
  8870. listener = readyListeners.shift();
  8871. listener.fn.call(listener.scope);
  8872. }
  8873. return Loader;
  8874. },
  8875. // Documented above already
  8876. onReady: function(fn, scope, withDomReady, options) {
  8877. var oldFn;
  8878. if (withDomReady !== false && Ext.onDocumentReady) {
  8879. oldFn = fn;
  8880. fn = function() {
  8881. Ext.onDocumentReady(oldFn, scope, options);
  8882. };
  8883. }
  8884. if (!Loader.isLoading) {
  8885. fn.call(scope);
  8886. }
  8887. else {
  8888. readyListeners.push({
  8889. fn: fn,
  8890. scope: scope
  8891. });
  8892. }
  8893. },
  8894. /**
  8895. * @private
  8896. * @param {String} className
  8897. */
  8898. historyPush: function(className) {
  8899. if (className && isClassFileLoaded.hasOwnProperty(className) && !isInHistory[className]) {
  8900. isInHistory[className] = true;
  8901. history.push(className);
  8902. }
  8903. return Loader;
  8904. }
  8905. });
  8906. /**
  8907. * Turns on or off the "cache buster" applied to dynamically loaded scripts. Normally
  8908. * dynamically loaded scripts have an extra query parameter appended to avoid stale
  8909. * cached scripts. This method can be used to disable this mechanism, and is primarily
  8910. * useful for testing. This is done using a cookie.
  8911. * @param {Boolean} disable True to disable the cache buster.
  8912. * @param {String} [path="/"] An optional path to scope the cookie.
  8913. * @private
  8914. */
  8915. Ext.disableCacheBuster = function (disable, path) {
  8916. var date = new Date();
  8917. date.setTime(date.getTime() + (disable ? 10*365 : -1) * 24*60*60*1000);
  8918. date = date.toGMTString();
  8919. document.cookie = 'ext-cache=1; expires=' + date + '; path='+(path || '/');
  8920. };
  8921. /**
  8922. * Convenient alias of {@link Ext.Loader#require}. Please see the introduction documentation of
  8923. * {@link Ext.Loader} for examples.
  8924. * @member Ext
  8925. * @method require
  8926. */
  8927. Ext.require = alias(Loader, 'require');
  8928. /**
  8929. * Synchronous version of {@link Ext#require}, convenient alias of {@link Ext.Loader#syncRequire}.
  8930. *
  8931. * @member Ext
  8932. * @method syncRequire
  8933. */
  8934. Ext.syncRequire = alias(Loader, 'syncRequire');
  8935. /**
  8936. * Convenient shortcut to {@link Ext.Loader#exclude}
  8937. * @member Ext
  8938. * @method exclude
  8939. */
  8940. Ext.exclude = alias(Loader, 'exclude');
  8941. /**
  8942. * @member Ext
  8943. * @method onReady
  8944. * @ignore
  8945. */
  8946. Ext.onReady = function(fn, scope, options) {
  8947. Loader.onReady(fn, scope, true, options);
  8948. };
  8949. /**
  8950. * @cfg {String[]} requires
  8951. * @member Ext.Class
  8952. * List of classes that have to be loaded before instantiating this class.
  8953. * For example:
  8954. *
  8955. * Ext.define('Mother', {
  8956. * requires: ['Child'],
  8957. * giveBirth: function() {
  8958. * // we can be sure that child class is available.
  8959. * return new Child();
  8960. * }
  8961. * });
  8962. */
  8963. Class.registerPreprocessor('loader', function(cls, data, hooks, continueFn) {
  8964. var me = this,
  8965. dependencies = [],
  8966. dependency,
  8967. className = Manager.getName(cls),
  8968. i, j, ln, subLn, value, propertyName, propertyValue,
  8969. requiredMap, requiredDep;
  8970. /*
  8971. Loop through the dependencyProperties, look for string class names and push
  8972. them into a stack, regardless of whether the property's value is a string, array or object. For example:
  8973. {
  8974. extend: 'Ext.MyClass',
  8975. requires: ['Ext.some.OtherClass'],
  8976. mixins: {
  8977. observable: 'Ext.util.Observable';
  8978. }
  8979. }
  8980. which will later be transformed into:
  8981. {
  8982. extend: Ext.MyClass,
  8983. requires: [Ext.some.OtherClass],
  8984. mixins: {
  8985. observable: Ext.util.Observable;
  8986. }
  8987. }
  8988. */
  8989. for (i = 0,ln = dependencyProperties.length; i < ln; i++) {
  8990. propertyName = dependencyProperties[i];
  8991. if (data.hasOwnProperty(propertyName)) {
  8992. propertyValue = data[propertyName];
  8993. if (typeof propertyValue == 'string') {
  8994. dependencies.push(propertyValue);
  8995. }
  8996. else if (propertyValue instanceof Array) {
  8997. for (j = 0, subLn = propertyValue.length; j < subLn; j++) {
  8998. value = propertyValue[j];
  8999. if (typeof value == 'string') {
  9000. dependencies.push(value);
  9001. }
  9002. }
  9003. }
  9004. else if (typeof propertyValue != 'function') {
  9005. for (j in propertyValue) {
  9006. if (propertyValue.hasOwnProperty(j)) {
  9007. value = propertyValue[j];
  9008. if (typeof value == 'string') {
  9009. dependencies.push(value);
  9010. }
  9011. }
  9012. }
  9013. }
  9014. }
  9015. }
  9016. if (dependencies.length === 0) {
  9017. return;
  9018. }
  9019. var deadlockPath = [],
  9020. detectDeadlock;
  9021. /*
  9022. Automatically detect deadlocks before-hand,
  9023. will throw an error with detailed path for ease of debugging. Examples of deadlock cases:
  9024. - A extends B, then B extends A
  9025. - A requires B, B requires C, then C requires A
  9026. The detectDeadlock function will recursively transverse till the leaf, hence it can detect deadlocks
  9027. no matter how deep the path is.
  9028. */
  9029. if (className) {
  9030. requiresMap[className] = dependencies;
  9031. requiredMap = Loader.requiredByMap || (Loader.requiredByMap = {});
  9032. for (i = 0,ln = dependencies.length; i < ln; i++) {
  9033. dependency = dependencies[i];
  9034. (requiredMap[dependency] || (requiredMap[dependency] = [])).push(className);
  9035. }
  9036. detectDeadlock = function(cls) {
  9037. deadlockPath.push(cls);
  9038. if (requiresMap[cls]) {
  9039. if (Ext.Array.contains(requiresMap[cls], className)) {
  9040. throw new Error("Deadlock detected while loading dependencies! '" + className + "' and '" +
  9041. deadlockPath[1] + "' " + "mutually require each other. Path: " +
  9042. deadlockPath.join(' -> ') + " -> " + deadlockPath[0]);
  9043. }
  9044. for (i = 0,ln = requiresMap[cls].length; i < ln; i++) {
  9045. detectDeadlock(requiresMap[cls][i]);
  9046. }
  9047. }
  9048. };
  9049. detectDeadlock(className);
  9050. }
  9051. Loader.require(dependencies, function() {
  9052. for (i = 0,ln = dependencyProperties.length; i < ln; i++) {
  9053. propertyName = dependencyProperties[i];
  9054. if (data.hasOwnProperty(propertyName)) {
  9055. propertyValue = data[propertyName];
  9056. if (typeof propertyValue == 'string') {
  9057. data[propertyName] = Manager.get(propertyValue);
  9058. }
  9059. else if (propertyValue instanceof Array) {
  9060. for (j = 0, subLn = propertyValue.length; j < subLn; j++) {
  9061. value = propertyValue[j];
  9062. if (typeof value == 'string') {
  9063. data[propertyName][j] = Manager.get(value);
  9064. }
  9065. }
  9066. }
  9067. else if (typeof propertyValue != 'function') {
  9068. for (var k in propertyValue) {
  9069. if (propertyValue.hasOwnProperty(k)) {
  9070. value = propertyValue[k];
  9071. if (typeof value == 'string') {
  9072. data[propertyName][k] = Manager.get(value);
  9073. }
  9074. }
  9075. }
  9076. }
  9077. }
  9078. }
  9079. continueFn.call(me, cls, data, hooks);
  9080. });
  9081. return false;
  9082. }, true, 'after', 'className');
  9083. /**
  9084. * @cfg {String[]} uses
  9085. * @member Ext.Class
  9086. * List of optional classes to load together with this class. These aren't neccessarily loaded before
  9087. * this class is created, but are guaranteed to be available before Ext.onReady listeners are
  9088. * invoked. For example:
  9089. *
  9090. * Ext.define('Mother', {
  9091. * uses: ['Child'],
  9092. * giveBirth: function() {
  9093. * // This code might, or might not work:
  9094. * // return new Child();
  9095. *
  9096. * // Instead use Ext.create() to load the class at the spot if not loaded already:
  9097. * return Ext.create('Child');
  9098. * }
  9099. * });
  9100. */
  9101. Manager.registerPostprocessor('uses', function(name, cls, data) {
  9102. var uses = data.uses;
  9103. if (uses) {
  9104. Loader.addUsedClasses(uses);
  9105. }
  9106. });
  9107. Manager.onCreated(Loader.historyPush);
  9108. };
  9109. // simple mechanism for automated means of injecting large amounts of dependency info
  9110. // at the appropriate time in the load cycle
  9111. if (Ext._classPathMetadata) {
  9112. Ext.Loader.addClassPathMappings(Ext._classPathMetadata);
  9113. Ext._classPathMetadata = null;
  9114. }
  9115. // initalize the default path of the framework
  9116. (function() {
  9117. var scripts = document.getElementsByTagName('script'),
  9118. currentScript = scripts[scripts.length - 1],
  9119. src = currentScript.src,
  9120. path = src.substring(0, src.lastIndexOf('/') + 1),
  9121. Loader = Ext.Loader;
  9122. if(src.indexOf("/platform/core/src/class/") != -1) {
  9123. path = path + "../../../../extjs/";
  9124. } else if(src.indexOf("/core/src/class/") != -1) {
  9125. path = path + "../../../";
  9126. }
  9127. Loader.setConfig({
  9128. enabled: true,
  9129. disableCaching: true,
  9130. paths: {
  9131. 'Ext': path + 'src'
  9132. }
  9133. });
  9134. })();
  9135. // allows a tools like dynatrace to deterministically detect onReady state by invoking
  9136. // a callback (intended for external consumption)
  9137. Ext._endTime = new Date().getTime();
  9138. if (Ext._beforereadyhandler){
  9139. Ext._beforereadyhandler();
  9140. }
  9141. //@tag foundation,core
  9142. //@require ../class/Loader.js
  9143. /**
  9144. * @author Brian Moeskau <brian@sencha.com>
  9145. * @docauthor Brian Moeskau <brian@sencha.com>
  9146. *
  9147. * A wrapper class for the native JavaScript Error object that adds a few useful capabilities for handling
  9148. * errors in an Ext application. When you use Ext.Error to {@link #raise} an error from within any class that
  9149. * uses the Ext 4 class system, the Error class can automatically add the source class and method from which
  9150. * the error was raised. It also includes logic to automatically log the eroor to the console, if available,
  9151. * with additional metadata about the error. In all cases, the error will always be thrown at the end so that
  9152. * execution will halt.
  9153. *
  9154. * Ext.Error also offers a global error {@link #handle handling} method that can be overridden in order to
  9155. * handle application-wide errors in a single spot. You can optionally {@link #ignore} errors altogether,
  9156. * although in a real application it's usually a better idea to override the handling function and perform
  9157. * logging or some other method of reporting the errors in a way that is meaningful to the application.
  9158. *
  9159. * At its simplest you can simply raise an error as a simple string from within any code:
  9160. *
  9161. * Example usage:
  9162. *
  9163. * Ext.Error.raise('Something bad happened!');
  9164. *
  9165. * If raised from plain JavaScript code, the error will be logged to the console (if available) and the message
  9166. * displayed. In most cases however you'll be raising errors from within a class, and it may often be useful to add
  9167. * additional metadata about the error being raised. The {@link #raise} method can also take a config object.
  9168. * In this form the `msg` attribute becomes the error description, and any other data added to the config gets
  9169. * added to the error object and, if the console is available, logged to the console for inspection.
  9170. *
  9171. * Example usage:
  9172. *
  9173. * Ext.define('Ext.Foo', {
  9174. * doSomething: function(option){
  9175. * if (someCondition === false) {
  9176. * Ext.Error.raise({
  9177. * msg: 'You cannot do that!',
  9178. * option: option, // whatever was passed into the method
  9179. * 'error code': 100 // other arbitrary info
  9180. * });
  9181. * }
  9182. * }
  9183. * });
  9184. *
  9185. * If a console is available (that supports the `console.dir` function) you'll see console output like:
  9186. *
  9187. * An error was raised with the following data:
  9188. * option: Object { foo: "bar"}
  9189. * foo: "bar"
  9190. * error code: 100
  9191. * msg: "You cannot do that!"
  9192. * sourceClass: "Ext.Foo"
  9193. * sourceMethod: "doSomething"
  9194. *
  9195. * uncaught exception: You cannot do that!
  9196. *
  9197. * As you can see, the error will report exactly where it was raised and will include as much information as the
  9198. * raising code can usefully provide.
  9199. *
  9200. * If you want to handle all application errors globally you can simply override the static {@link #handle} method
  9201. * and provide whatever handling logic you need. If the method returns true then the error is considered handled
  9202. * and will not be thrown to the browser. If anything but true is returned then the error will be thrown normally.
  9203. *
  9204. * Example usage:
  9205. *
  9206. * Ext.Error.handle = function(err) {
  9207. * if (err.someProperty == 'NotReallyAnError') {
  9208. * // maybe log something to the application here if applicable
  9209. * return true;
  9210. * }
  9211. * // any non-true return value (including none) will cause the error to be thrown
  9212. * }
  9213. *
  9214. */
  9215. Ext.Error = Ext.extend(Error, {
  9216. statics: {
  9217. /**
  9218. * @property {Boolean} ignore
  9219. * Static flag that can be used to globally disable error reporting to the browser if set to true
  9220. * (defaults to false). Note that if you ignore Ext errors it's likely that some other code may fail
  9221. * and throw a native JavaScript error thereafter, so use with caution. In most cases it will probably
  9222. * be preferable to supply a custom error {@link #handle handling} function instead.
  9223. *
  9224. * Example usage:
  9225. *
  9226. * Ext.Error.ignore = true;
  9227. *
  9228. * @static
  9229. */
  9230. ignore: false,
  9231. /**
  9232. * @property {Boolean} notify
  9233. * Static flag that can be used to globally control error notification to the user. Unlike
  9234. * Ex.Error.ignore, this does not effect exceptions. They are still thrown. This value can be
  9235. * set to false to disable the alert notification (default is true for IE6 and IE7).
  9236. *
  9237. * Only the first error will generate an alert. Internally this flag is set to false when the
  9238. * first error occurs prior to displaying the alert.
  9239. *
  9240. * This flag is not used in a release build.
  9241. *
  9242. * Example usage:
  9243. *
  9244. * Ext.Error.notify = false;
  9245. *
  9246. * @static
  9247. */
  9248. //notify: Ext.isIE6 || Ext.isIE7,
  9249. /**
  9250. * Raise an error that can include additional data and supports automatic console logging if available.
  9251. * You can pass a string error message or an object with the `msg` attribute which will be used as the
  9252. * error message. The object can contain any other name-value attributes (or objects) to be logged
  9253. * along with the error.
  9254. *
  9255. * Note that after displaying the error message a JavaScript error will ultimately be thrown so that
  9256. * execution will halt.
  9257. *
  9258. * Example usage:
  9259. *
  9260. * Ext.Error.raise('A simple string error message');
  9261. *
  9262. * // or...
  9263. *
  9264. * Ext.define('Ext.Foo', {
  9265. * doSomething: function(option){
  9266. * if (someCondition === false) {
  9267. * Ext.Error.raise({
  9268. * msg: 'You cannot do that!',
  9269. * option: option, // whatever was passed into the method
  9270. * 'error code': 100 // other arbitrary info
  9271. * });
  9272. * }
  9273. * }
  9274. * });
  9275. *
  9276. * @param {String/Object} err The error message string, or an object containing the attribute "msg" that will be
  9277. * used as the error message. Any other data included in the object will also be logged to the browser console,
  9278. * if available.
  9279. * @static
  9280. */
  9281. raise: function(err){
  9282. err = err || {};
  9283. if (Ext.isString(err)) {
  9284. err = { msg: err };
  9285. }
  9286. var method = this.raise.caller,
  9287. msg;
  9288. if (method) {
  9289. if (method.$name) {
  9290. err.sourceMethod = method.$name;
  9291. }
  9292. if (method.$owner) {
  9293. err.sourceClass = method.$owner.$className;
  9294. }
  9295. }
  9296. if (Ext.Error.handle(err) !== true) {
  9297. msg = Ext.Error.prototype.toString.call(err);
  9298. Ext.log({
  9299. msg: msg,
  9300. level: 'error',
  9301. dump: err,
  9302. stack: true
  9303. });
  9304. throw new Ext.Error(err);
  9305. }
  9306. },
  9307. /**
  9308. * Globally handle any Ext errors that may be raised, optionally providing custom logic to
  9309. * handle different errors individually. Return true from the function to bypass throwing the
  9310. * error to the browser, otherwise the error will be thrown and execution will halt.
  9311. *
  9312. * Example usage:
  9313. *
  9314. * Ext.Error.handle = function(err) {
  9315. * if (err.someProperty == 'NotReallyAnError') {
  9316. * // maybe log something to the application here if applicable
  9317. * return true;
  9318. * }
  9319. * // any non-true return value (including none) will cause the error to be thrown
  9320. * }
  9321. *
  9322. * @param {Ext.Error} err The Ext.Error object being raised. It will contain any attributes that were originally
  9323. * raised with it, plus properties about the method and class from which the error originated (if raised from a
  9324. * class that uses the Ext 4 class system).
  9325. * @static
  9326. */
  9327. handle: function(){
  9328. return Ext.Error.ignore;
  9329. }
  9330. },
  9331. // This is the standard property that is the name of the constructor.
  9332. name: 'Ext.Error',
  9333. /**
  9334. * Creates new Error object.
  9335. * @param {String/Object} config The error message string, or an object containing the
  9336. * attribute "msg" that will be used as the error message. Any other data included in
  9337. * the object will be applied to the error instance and logged to the browser console, if available.
  9338. */
  9339. constructor: function(config){
  9340. if (Ext.isString(config)) {
  9341. config = { msg: config };
  9342. }
  9343. var me = this;
  9344. Ext.apply(me, config);
  9345. me.message = me.message || me.msg; // 'message' is standard ('msg' is non-standard)
  9346. // note: the above does not work in old WebKit (me.message is readonly) (Safari 4)
  9347. },
  9348. /**
  9349. * Provides a custom string representation of the error object. This is an override of the base JavaScript
  9350. * `Object.toString` method, which is useful so that when logged to the browser console, an error object will
  9351. * be displayed with a useful message instead of `[object Object]`, the default `toString` result.
  9352. *
  9353. * The default implementation will include the error message along with the raising class and method, if available,
  9354. * but this can be overridden with a custom implementation either at the prototype level (for all errors) or on
  9355. * a particular error instance, if you want to provide a custom description that will show up in the console.
  9356. * @return {String} The error message. If raised from within the Ext 4 class system, the error message will also
  9357. * include the raising class and method names, if available.
  9358. */
  9359. toString: function(){
  9360. var me = this,
  9361. className = me.sourceClass ? me.sourceClass : '',
  9362. methodName = me.sourceMethod ? '.' + me.sourceMethod + '(): ' : '',
  9363. msg = me.msg || '(No description provided)';
  9364. return className + methodName + msg;
  9365. }
  9366. });
  9367. /*
  9368. * Create a function that will throw an error if called (in debug mode) with a message that
  9369. * indicates the method has been removed.
  9370. * @param {String} suggestion Optional text to include in the message (a workaround perhaps).
  9371. * @return {Function} The generated function.
  9372. * @private
  9373. */
  9374. Ext.deprecated = function (suggestion) {
  9375. if (!suggestion) {
  9376. suggestion = '';
  9377. }
  9378. function fail () {
  9379. Ext.Error.raise('The method "' + fail.$owner.$className + '.' + fail.$name +
  9380. '" has been removed. ' + suggestion);
  9381. }
  9382. return fail;
  9383. return Ext.emptyFn;
  9384. };
  9385. /*
  9386. * This mechanism is used to notify the user of the first error encountered on the page. This
  9387. * was previously internal to Ext.Error.raise and is a desirable feature since errors often
  9388. * slip silently under the radar. It cannot live in Ext.Error.raise since there are times
  9389. * where exceptions are handled in a try/catch.
  9390. */
  9391. (function () {
  9392. var timer, errors = 0,
  9393. win = Ext.global,
  9394. msg;
  9395. if (typeof window === 'undefined') {
  9396. return; // build system or some such environment...
  9397. }
  9398. // This method is called to notify the user of the current error status.
  9399. function notify () {
  9400. var counters = Ext.log.counters,
  9401. supports = Ext.supports,
  9402. hasOnError = supports && supports.WindowOnError; // TODO - timing
  9403. // Put log counters to the status bar (for most browsers):
  9404. if (counters && (counters.error + counters.warn + counters.info + counters.log)) {
  9405. msg = [ 'Logged Errors:',counters.error, 'Warnings:',counters.warn,
  9406. 'Info:',counters.info, 'Log:',counters.log].join(' ');
  9407. if (errors) {
  9408. msg = '*** Errors: ' + errors + ' - ' + msg;
  9409. } else if (counters.error) {
  9410. msg = '*** ' + msg;
  9411. }
  9412. win.status = msg;
  9413. }
  9414. // Display an alert on the first error:
  9415. if (!Ext.isDefined(Ext.Error.notify)) {
  9416. Ext.Error.notify = Ext.isIE6 || Ext.isIE7; // TODO - timing
  9417. }
  9418. if (Ext.Error.notify && (hasOnError ? errors : (counters && counters.error))) {
  9419. Ext.Error.notify = false;
  9420. if (timer) {
  9421. win.clearInterval(timer); // ticks can queue up so stop...
  9422. timer = null;
  9423. }
  9424. alert('Unhandled error on page: See console or log');
  9425. poll();
  9426. }
  9427. }
  9428. // Sets up polling loop. This is the only way to know about errors in some browsers
  9429. // (Opera/Safari) and is the only way to update the status bar for warnings and other
  9430. // non-errors.
  9431. function poll () {
  9432. timer = win.setInterval(notify, 1000);
  9433. }
  9434. // window.onerror sounds ideal but it prevents the built-in error dialog from doing
  9435. // its (better) thing.
  9436. poll();
  9437. }());
  9438. //@tag extras,core
  9439. //@require ../lang/Error.js
  9440. /**
  9441. * Modified version of [Douglas Crockford's JSON.js][dc] that doesn't
  9442. * mess with the Object prototype.
  9443. *
  9444. * [dc]: http://www.json.org/js.html
  9445. *
  9446. * @singleton
  9447. */
  9448. Ext.JSON = (new(function() {
  9449. var me = this,
  9450. encodingFunction,
  9451. decodingFunction,
  9452. useNative = null,
  9453. useHasOwn = !! {}.hasOwnProperty,
  9454. isNative = function() {
  9455. if (useNative === null) {
  9456. useNative = Ext.USE_NATIVE_JSON && window.JSON && JSON.toString() == '[object JSON]';
  9457. }
  9458. return useNative;
  9459. },
  9460. pad = function(n) {
  9461. return n < 10 ? "0" + n : n;
  9462. },
  9463. doDecode = function(json) {
  9464. return eval("(" + json + ')');
  9465. },
  9466. doEncode = function(o, newline) {
  9467. // http://jsperf.com/is-undefined
  9468. if (o === null || o === undefined) {
  9469. return "null";
  9470. } else if (Ext.isDate(o)) {
  9471. return Ext.JSON.encodeDate(o);
  9472. } else if (Ext.isString(o)) {
  9473. return Ext.JSON.encodeString(o);
  9474. } else if (typeof o == "number") {
  9475. //don't use isNumber here, since finite checks happen inside isNumber
  9476. return isFinite(o) ? String(o) : "null";
  9477. } else if (Ext.isBoolean(o)) {
  9478. return String(o);
  9479. }
  9480. // Allow custom zerialization by adding a toJSON method to any object type.
  9481. // Date/String have a toJSON in some environments, so check these first.
  9482. else if (o.toJSON) {
  9483. return o.toJSON();
  9484. } else if (Ext.isArray(o)) {
  9485. return encodeArray(o, newline);
  9486. } else if (Ext.isObject(o)) {
  9487. return encodeObject(o, newline);
  9488. } else if (typeof o === "function") {
  9489. return "null";
  9490. }
  9491. return 'undefined';
  9492. },
  9493. m = {
  9494. "\b": '\\b',
  9495. "\t": '\\t',
  9496. "\n": '\\n',
  9497. "\f": '\\f',
  9498. "\r": '\\r',
  9499. '"': '\\"',
  9500. "\\": '\\\\',
  9501. '\x0b': '\\u000b' //ie doesn't handle \v
  9502. },
  9503. charToReplace = /[\\\"\x00-\x1f\x7f-\uffff]/g,
  9504. encodeString = function(s) {
  9505. return '"' + s.replace(charToReplace, function(a) {
  9506. var c = m[a];
  9507. return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  9508. }) + '"';
  9509. },
  9510. encodeArrayPretty = function(o, newline) {
  9511. var len = o.length,
  9512. cnewline = newline + ' ',
  9513. sep = ',' + cnewline,
  9514. a = ["[", cnewline], // Note newline in case there are no members
  9515. i;
  9516. for (i = 0; i < len; i += 1) {
  9517. a.push(Ext.JSON.encodeValue(o[i], cnewline), sep);
  9518. }
  9519. // Overwrite trailing comma (or empty string)
  9520. a[a.length - 1] = newline + ']';
  9521. return a.join('');
  9522. },
  9523. encodeObjectPretty = function(o, newline) {
  9524. var cnewline = newline + ' ',
  9525. sep = ',' + cnewline,
  9526. a = ["{", cnewline], // Note newline in case there are no members
  9527. i;
  9528. for (i in o) {
  9529. if (!useHasOwn || o.hasOwnProperty(i)) {
  9530. a.push(Ext.JSON.encodeValue(i) + ': ' + Ext.JSON.encodeValue(o[i], cnewline), sep);
  9531. }
  9532. }
  9533. // Overwrite trailing comma (or empty string)
  9534. a[a.length - 1] = newline + '}';
  9535. return a.join('');
  9536. },
  9537. encodeArray = function(o, newline) {
  9538. if (newline) {
  9539. return encodeArrayPretty(o, newline);
  9540. }
  9541. var a = ["[", ""], // Note empty string in case there are no serializable members.
  9542. len = o.length,
  9543. i;
  9544. for (i = 0; i < len; i += 1) {
  9545. a.push(Ext.JSON.encodeValue(o[i]), ',');
  9546. }
  9547. // Overwrite trailing comma (or empty string)
  9548. a[a.length - 1] = ']';
  9549. return a.join("");
  9550. },
  9551. encodeObject = function(o, newline) {
  9552. if (newline) {
  9553. return encodeObjectPretty(o, newline);
  9554. }
  9555. var a = ["{", ""], // Note empty string in case there are no serializable members.
  9556. i;
  9557. for (i in o) {
  9558. if (!useHasOwn || o.hasOwnProperty(i)) {
  9559. a.push(Ext.JSON.encodeValue(i), ":", Ext.JSON.encodeValue(o[i]), ',');
  9560. }
  9561. }
  9562. // Overwrite trailing comma (or empty string)
  9563. a[a.length - 1] = '}';
  9564. return a.join("");
  9565. };
  9566. /**
  9567. * Encodes a String. This returns the actual string which is inserted into the JSON string as the literal
  9568. * expression. **The returned value includes enclosing double quotation marks.**
  9569. *
  9570. * To override this:
  9571. *
  9572. * Ext.JSON.encodeString = function(s) {
  9573. * return 'Foo' + s;
  9574. * };
  9575. *
  9576. * @param {String} s The String to encode
  9577. * @return {String} The string literal to use in a JSON string.
  9578. * @method
  9579. */
  9580. me.encodeString = encodeString;
  9581. /**
  9582. * The function which {@link #encode} uses to encode all javascript values to their JSON representations
  9583. * when {@link Ext#USE_NATIVE_JSON} is `false`.
  9584. *
  9585. * This is made public so that it can be replaced with a custom implementation.
  9586. *
  9587. * @param {Object} o Any javascript value to be converted to its JSON representation
  9588. * @return {String} The JSON representation of the passed value.
  9589. * @method
  9590. */
  9591. me.encodeValue = doEncode;
  9592. /**
  9593. * Encodes a Date. This returns the actual string which is inserted into the JSON string as the literal
  9594. * expression. **The returned value includes enclosing double quotation marks.**
  9595. *
  9596. * The default return format is `"yyyy-mm-ddThh:mm:ss"`.
  9597. *
  9598. * To override this:
  9599. *
  9600. * Ext.JSON.encodeDate = function(d) {
  9601. * return Ext.Date.format(d, '"Y-m-d"');
  9602. * };
  9603. *
  9604. * @param {Date} d The Date to encode
  9605. * @return {String} The string literal to use in a JSON string.
  9606. */
  9607. me.encodeDate = function(o) {
  9608. return '"' + o.getFullYear() + "-"
  9609. + pad(o.getMonth() + 1) + "-"
  9610. + pad(o.getDate()) + "T"
  9611. + pad(o.getHours()) + ":"
  9612. + pad(o.getMinutes()) + ":"
  9613. + pad(o.getSeconds()) + '"';
  9614. };
  9615. /**
  9616. * Encodes an Object, Array or other value.
  9617. *
  9618. * If the environment's native JSON encoding is not being used ({@link Ext#USE_NATIVE_JSON} is not set,
  9619. * or the environment does not support it), then ExtJS's encoding will be used. This allows the developer
  9620. * to add a `toJSON` method to their classes which need serializing to return a valid JSON representation
  9621. * of the object.
  9622. *
  9623. * @param {Object} o The variable to encode
  9624. * @return {String} The JSON string
  9625. */
  9626. me.encode = function(o) {
  9627. if (!encodingFunction) {
  9628. // setup encoding function on first access
  9629. encodingFunction = isNative() ? JSON.stringify : me.encodeValue;
  9630. }
  9631. return encodingFunction(o);
  9632. };
  9633. /**
  9634. * Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws
  9635. * a SyntaxError unless the safe option is set.
  9636. *
  9637. * @param {String} json The JSON string
  9638. * @param {Boolean} [safe=false] True to return null, false to throw an exception if the JSON is invalid.
  9639. * @return {Object} The resulting object
  9640. */
  9641. me.decode = function(json, safe) {
  9642. if (!decodingFunction) {
  9643. // setup decoding function on first access
  9644. decodingFunction = isNative() ? JSON.parse : doDecode;
  9645. }
  9646. try {
  9647. return decodingFunction(json);
  9648. } catch (e) {
  9649. if (safe === true) {
  9650. return null;
  9651. }
  9652. Ext.Error.raise({
  9653. sourceClass: "Ext.JSON",
  9654. sourceMethod: "decode",
  9655. msg: "You're trying to decode an invalid JSON String: " + json
  9656. });
  9657. }
  9658. };
  9659. })());
  9660. /**
  9661. * Shorthand for {@link Ext.JSON#encode}
  9662. * @member Ext
  9663. * @method encode
  9664. * @inheritdoc Ext.JSON#encode
  9665. */
  9666. Ext.encode = Ext.JSON.encode;
  9667. /**
  9668. * Shorthand for {@link Ext.JSON#decode}
  9669. * @member Ext
  9670. * @method decode
  9671. * @inheritdoc Ext.JSON#decode
  9672. */
  9673. Ext.decode = Ext.JSON.decode;
  9674. //@tag extras,core
  9675. //@require misc/JSON.js
  9676. /**
  9677. * @class Ext
  9678. *
  9679. * The Ext namespace (global object) encapsulates all classes, singletons, and
  9680. * utility methods provided by Sencha's libraries.
  9681. *
  9682. * Most user interface Components are at a lower level of nesting in the namespace,
  9683. * but many common utility functions are provided as direct properties of the Ext namespace.
  9684. *
  9685. * Also many frequently used methods from other classes are provided as shortcuts
  9686. * within the Ext namespace. For example {@link Ext#getCmp Ext.getCmp} aliases
  9687. * {@link Ext.ComponentManager#get Ext.ComponentManager.get}.
  9688. *
  9689. * Many applications are initiated with {@link Ext#onReady Ext.onReady} which is
  9690. * called once the DOM is ready. This ensures all scripts have been loaded,
  9691. * preventing dependency issues. For example:
  9692. *
  9693. * Ext.onReady(function(){
  9694. * new Ext.Component({
  9695. * renderTo: document.body,
  9696. * html: 'DOM ready!'
  9697. * });
  9698. * });
  9699. *
  9700. * For more information about how to use the Ext classes, see:
  9701. *
  9702. * - <a href="http://www.sencha.com/learn/">The Learning Center</a>
  9703. * - <a href="http://www.sencha.com/learn/Ext_FAQ">The FAQ</a>
  9704. * - <a href="http://www.sencha.com/forum/">The forums</a>
  9705. *
  9706. * @singleton
  9707. */
  9708. Ext.apply(Ext, {
  9709. userAgent: navigator.userAgent.toLowerCase(),
  9710. cache: {},
  9711. idSeed: 1000,
  9712. windowId: 'ext-window',
  9713. documentId: 'ext-document',
  9714. /**
  9715. * True when the document is fully initialized and ready for action
  9716. */
  9717. isReady: false,
  9718. /**
  9719. * True to automatically uncache orphaned Ext.Elements periodically
  9720. */
  9721. enableGarbageCollector: true,
  9722. /**
  9723. * True to automatically purge event listeners during garbageCollection.
  9724. */
  9725. enableListenerCollection: true,
  9726. addCacheEntry: function(id, el, dom) {
  9727. dom = dom || el.dom;
  9728. if (!dom) {
  9729. // Without the DOM node we can't GC the entry
  9730. Ext.Error.raise('Cannot add an entry to the element cache without the DOM node');
  9731. }
  9732. var key = id || (el && el.id) || dom.id,
  9733. entry = Ext.cache[key] || (Ext.cache[key] = {
  9734. data: {},
  9735. events: {},
  9736. dom: dom,
  9737. // Skip garbage collection for special elements (window, document, iframes)
  9738. skipGarbageCollection: !!(dom.getElementById || dom.navigator)
  9739. });
  9740. if (el) {
  9741. el.$cache = entry;
  9742. // Inject the back link from the cache in case the cache entry
  9743. // had already been created by Ext.fly. Ext.fly creates a cache entry with no el link.
  9744. entry.el = el;
  9745. }
  9746. return entry;
  9747. },
  9748. updateCacheEntry: function(cacheItem, dom){
  9749. cacheItem.dom = dom;
  9750. if (cacheItem.el) {
  9751. cacheItem.el.dom = dom;
  9752. }
  9753. return cacheItem;
  9754. },
  9755. /**
  9756. * Generates unique ids. If the element already has an id, it is unchanged
  9757. * @param {HTMLElement/Ext.Element} [el] The element to generate an id for
  9758. * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
  9759. * @return {String} The generated Id.
  9760. */
  9761. id: function(el, prefix) {
  9762. var me = this,
  9763. sandboxPrefix = '';
  9764. el = Ext.getDom(el, true) || {};
  9765. if (el === document) {
  9766. el.id = me.documentId;
  9767. }
  9768. else if (el === window) {
  9769. el.id = me.windowId;
  9770. }
  9771. if (!el.id) {
  9772. if (me.isSandboxed) {
  9773. sandboxPrefix = Ext.sandboxName.toLowerCase() + '-';
  9774. }
  9775. el.id = sandboxPrefix + (prefix || "ext-gen") + (++Ext.idSeed);
  9776. }
  9777. return el.id;
  9778. },
  9779. escapeId: (function(){
  9780. var validIdRe = /^[a-zA-Z_][a-zA-Z0-9_\-]*$/i,
  9781. escapeRx = /([\W]{1})/g,
  9782. leadingNumRx = /^(\d)/g,
  9783. escapeFn = function(match, capture){
  9784. return "\\" + capture;
  9785. },
  9786. numEscapeFn = function(match, capture){
  9787. return '\\00' + capture.charCodeAt(0).toString(16) + ' ';
  9788. };
  9789. return function(id) {
  9790. return validIdRe.test(id)
  9791. ? id
  9792. // replace the number portion last to keep the trailing ' '
  9793. // from being escaped
  9794. : id.replace(escapeRx, escapeFn)
  9795. .replace(leadingNumRx, numEscapeFn);
  9796. };
  9797. }()),
  9798. /**
  9799. * Returns the current document body as an {@link Ext.Element}.
  9800. * @return Ext.Element The document body
  9801. */
  9802. getBody: (function() {
  9803. var body;
  9804. return function() {
  9805. return body || (body = Ext.get(document.body));
  9806. };
  9807. }()),
  9808. /**
  9809. * Returns the current document head as an {@link Ext.Element}.
  9810. * @return Ext.Element The document head
  9811. * @method
  9812. */
  9813. getHead: (function() {
  9814. var head;
  9815. return function() {
  9816. return head || (head = Ext.get(document.getElementsByTagName("head")[0]));
  9817. };
  9818. }()),
  9819. /**
  9820. * Returns the current HTML document object as an {@link Ext.Element}.
  9821. * @return Ext.Element The document
  9822. */
  9823. getDoc: (function() {
  9824. var doc;
  9825. return function() {
  9826. return doc || (doc = Ext.get(document));
  9827. };
  9828. }()),
  9829. /**
  9830. * This is shorthand reference to {@link Ext.ComponentManager#get}.
  9831. * Looks up an existing {@link Ext.Component Component} by {@link Ext.Component#id id}
  9832. *
  9833. * @param {String} id The component {@link Ext.Component#id id}
  9834. * @return Ext.Component The Component, `undefined` if not found, or `null` if a
  9835. * Class was found.
  9836. */
  9837. getCmp: function(id) {
  9838. return Ext.ComponentManager.get(id);
  9839. },
  9840. /**
  9841. * Returns the current orientation of the mobile device
  9842. * @return {String} Either 'portrait' or 'landscape'
  9843. */
  9844. getOrientation: function() {
  9845. return window.innerHeight > window.innerWidth ? 'portrait' : 'landscape';
  9846. },
  9847. /**
  9848. * Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
  9849. * DOM (if applicable) and calling their destroy functions (if available). This method is primarily
  9850. * intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of
  9851. * {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
  9852. * passed into this function in a single call as separate arguments.
  9853. *
  9854. * @param {Ext.Element/Ext.Component/Ext.Element[]/Ext.Component[]...} args
  9855. * An {@link Ext.Element}, {@link Ext.Component}, or an Array of either of these to destroy
  9856. */
  9857. destroy: function() {
  9858. var ln = arguments.length,
  9859. i, arg;
  9860. for (i = 0; i < ln; i++) {
  9861. arg = arguments[i];
  9862. if (arg) {
  9863. if (Ext.isArray(arg)) {
  9864. this.destroy.apply(this, arg);
  9865. }
  9866. else if (Ext.isFunction(arg.destroy)) {
  9867. arg.destroy();
  9868. }
  9869. else if (arg.dom) {
  9870. arg.remove();
  9871. }
  9872. }
  9873. }
  9874. },
  9875. /**
  9876. * Execute a callback function in a particular scope. If no function is passed the call is ignored.
  9877. *
  9878. * For example, these lines are equivalent:
  9879. *
  9880. * Ext.callback(myFunc, this, [arg1, arg2]);
  9881. * Ext.isFunction(myFunc) && myFunc.apply(this, [arg1, arg2]);
  9882. *
  9883. * @param {Function} callback The callback to execute
  9884. * @param {Object} [scope] The scope to execute in
  9885. * @param {Array} [args] The arguments to pass to the function
  9886. * @param {Number} [delay] Pass a number to delay the call by a number of milliseconds.
  9887. */
  9888. callback: function(callback, scope, args, delay){
  9889. if(Ext.isFunction(callback)){
  9890. args = args || [];
  9891. scope = scope || window;
  9892. if (delay) {
  9893. Ext.defer(callback, delay, scope, args);
  9894. } else {
  9895. callback.apply(scope, args);
  9896. }
  9897. }
  9898. },
  9899. /**
  9900. * Alias for {@link Ext.String#htmlEncode}.
  9901. * @inheritdoc Ext.String#htmlEncode
  9902. * @ignore
  9903. */
  9904. htmlEncode : function(value) {
  9905. return Ext.String.htmlEncode(value);
  9906. },
  9907. /**
  9908. * Alias for {@link Ext.String#htmlDecode}.
  9909. * @inheritdoc Ext.String#htmlDecode
  9910. * @ignore
  9911. */
  9912. htmlDecode : function(value) {
  9913. return Ext.String.htmlDecode(value);
  9914. },
  9915. /**
  9916. * Alias for {@link Ext.String#urlAppend}.
  9917. * @inheritdoc Ext.String#urlAppend
  9918. * @ignore
  9919. */
  9920. urlAppend : function(url, s) {
  9921. return Ext.String.urlAppend(url, s);
  9922. }
  9923. });
  9924. Ext.ns = Ext.namespace;
  9925. // for old browsers
  9926. window.undefined = window.undefined;
  9927. /**
  9928. * @class Ext
  9929. */
  9930. (function(){
  9931. /*
  9932. FF 3.6 - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17
  9933. FF 4.0.1 - Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
  9934. FF 5.0 - Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0
  9935. IE6 - Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;)
  9936. IE7 - Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1;)
  9937. IE8 - Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
  9938. IE9 - Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
  9939. Chrome 11 - Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.60 Safari/534.24
  9940. Safari 5 - Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1
  9941. Opera 11.11 - Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
  9942. */
  9943. var check = function(regex){
  9944. return regex.test(Ext.userAgent);
  9945. },
  9946. isStrict = document.compatMode == "CSS1Compat",
  9947. version = function (is, regex) {
  9948. var m;
  9949. return (is && (m = regex.exec(Ext.userAgent))) ? parseFloat(m[1]) : 0;
  9950. },
  9951. docMode = document.documentMode,
  9952. isOpera = check(/opera/),
  9953. isOpera10_5 = isOpera && check(/version\/10\.5/),
  9954. isChrome = check(/\bchrome\b/),
  9955. isWebKit = check(/webkit/),
  9956. isSafari = !isChrome && check(/safari/),
  9957. isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
  9958. isSafari3 = isSafari && check(/version\/3/),
  9959. isSafari4 = isSafari && check(/version\/4/),
  9960. isSafari5_0 = isSafari && check(/version\/5\.0/),
  9961. isSafari5 = isSafari && check(/version\/5/),
  9962. isIE = !isOpera && check(/msie/),
  9963. isIE7 = isIE && ((check(/msie 7/) && docMode != 8 && docMode != 9) || docMode == 7),
  9964. isIE8 = isIE && ((check(/msie 8/) && docMode != 7 && docMode != 9) || docMode == 8),
  9965. isIE9 = isIE && ((check(/msie 9/) && docMode != 7 && docMode != 8) || docMode == 9),
  9966. isIE6 = isIE && check(/msie 6/),
  9967. isGecko = !isWebKit && check(/gecko/),
  9968. isGecko3 = isGecko && check(/rv:1\.9/),
  9969. isGecko4 = isGecko && check(/rv:2\.0/),
  9970. isGecko5 = isGecko && check(/rv:5\./),
  9971. isGecko10 = isGecko && check(/rv:10\./),
  9972. isFF3_0 = isGecko3 && check(/rv:1\.9\.0/),
  9973. isFF3_5 = isGecko3 && check(/rv:1\.9\.1/),
  9974. isFF3_6 = isGecko3 && check(/rv:1\.9\.2/),
  9975. isWindows = check(/windows|win32/),
  9976. isMac = check(/macintosh|mac os x/),
  9977. isLinux = check(/linux/),
  9978. scrollbarSize = null,
  9979. chromeVersion = version(true, /\bchrome\/(\d+\.\d+)/),
  9980. firefoxVersion = version(true, /\bfirefox\/(\d+\.\d+)/),
  9981. ieVersion = version(isIE, /msie (\d+\.\d+)/),
  9982. operaVersion = version(isOpera, /version\/(\d+\.\d+)/),
  9983. safariVersion = version(isSafari, /version\/(\d+\.\d+)/),
  9984. webKitVersion = version(isWebKit, /webkit\/(\d+\.\d+)/),
  9985. isSecure = /^https/i.test(window.location.protocol),
  9986. nullLog;
  9987. // remove css image flicker
  9988. try {
  9989. document.execCommand("BackgroundImageCache", false, true);
  9990. } catch(e) {}
  9991. var primitiveRe = /string|number|boolean/;
  9992. function dumpObject (object) {
  9993. var member, type, value, name,
  9994. members = [];
  9995. // Cannot use Ext.encode since it can recurse endlessly (if we're lucky)
  9996. // ...and the data could be prettier!
  9997. for (name in object) {
  9998. if (object.hasOwnProperty(name)) {
  9999. value = object[name];
  10000. type = typeof value;
  10001. if (type == "function") {
  10002. continue;
  10003. }
  10004. if (type == 'undefined') {
  10005. member = type;
  10006. } else if (value === null || primitiveRe.test(type) || Ext.isDate(value)) {
  10007. member = Ext.encode(value);
  10008. } else if (Ext.isArray(value)) {
  10009. member = '[ ]';
  10010. } else if (Ext.isObject(value)) {
  10011. member = '{ }';
  10012. } else {
  10013. member = type;
  10014. }
  10015. members.push(Ext.encode(name) + ': ' + member);
  10016. }
  10017. }
  10018. if (members.length) {
  10019. return ' \nData: {\n ' + members.join(',\n ') + '\n}';
  10020. }
  10021. return '';
  10022. }
  10023. function log (message) {
  10024. var options, dump,
  10025. con = Ext.global.console,
  10026. level = 'log',
  10027. indent = log.indent || 0,
  10028. stack,
  10029. out,
  10030. max;
  10031. log.indent = indent;
  10032. if (typeof message != 'string') {
  10033. options = message;
  10034. message = options.msg || '';
  10035. level = options.level || level;
  10036. dump = options.dump;
  10037. stack = options.stack;
  10038. if (options.indent) {
  10039. ++log.indent;
  10040. } else if (options.outdent) {
  10041. log.indent = indent = Math.max(indent - 1, 0);
  10042. }
  10043. if (dump && !(con && con.dir)) {
  10044. message += dumpObject(dump);
  10045. dump = null;
  10046. }
  10047. }
  10048. if (arguments.length > 1) {
  10049. message += Array.prototype.slice.call(arguments, 1).join('');
  10050. }
  10051. message = indent ? Ext.String.repeat(' ', log.indentSize * indent) + message : message;
  10052. // w/o console, all messages are equal, so munge the level into the message:
  10053. if (level != 'log') {
  10054. message = '[' + level.charAt(0).toUpperCase() + '] ' + message;
  10055. }
  10056. // Not obvious, but 'console' comes and goes when Firebug is turned on/off, so
  10057. // an early test may fail either direction if Firebug is toggled.
  10058. //
  10059. if (con) { // if (Firebug-like console)
  10060. if (con[level]) {
  10061. con[level](message);
  10062. } else {
  10063. con.log(message);
  10064. }
  10065. if (dump) {
  10066. con.dir(dump);
  10067. }
  10068. if (stack && con.trace) {
  10069. // Firebug's console.error() includes a trace already...
  10070. if (!con.firebug || level != 'error') {
  10071. con.trace();
  10072. }
  10073. }
  10074. } else {
  10075. if (Ext.isOpera) {
  10076. opera.postError(message);
  10077. } else {
  10078. out = log.out;
  10079. max = log.max;
  10080. if (out.length >= max) {
  10081. // this formula allows out.max to change (via debugger), where the
  10082. // more obvious "max/4" would not quite be the same
  10083. Ext.Array.erase(out, 0, out.length - 3 * Math.floor(max / 4)); // keep newest 75%
  10084. }
  10085. out.push(message);
  10086. }
  10087. }
  10088. // Mostly informational, but the Ext.Error notifier uses them:
  10089. ++log.count;
  10090. ++log.counters[level];
  10091. }
  10092. function logx (level, args) {
  10093. if (typeof args[0] == 'string') {
  10094. args.unshift({});
  10095. }
  10096. args[0].level = level;
  10097. log.apply(this, args);
  10098. }
  10099. log.error = function () {
  10100. logx('error', Array.prototype.slice.call(arguments));
  10101. };
  10102. log.info = function () {
  10103. logx('info', Array.prototype.slice.call(arguments));
  10104. };
  10105. log.warn = function () {
  10106. logx('warn', Array.prototype.slice.call(arguments));
  10107. };
  10108. log.count = 0;
  10109. log.counters = { error: 0, warn: 0, info: 0, log: 0 };
  10110. log.indentSize = 2;
  10111. log.out = [];
  10112. log.max = 750;
  10113. log.show = function () {
  10114. window.open('','extlog').document.write([
  10115. '<html><head><script type="text/javascript">',
  10116. 'var lastCount = 0;',
  10117. 'function update () {',
  10118. 'var ext = window.opener.Ext,',
  10119. 'extlog = ext && ext.log;',
  10120. 'if (extlog && extlog.out && lastCount != extlog.count) {',
  10121. 'lastCount = extlog.count;',
  10122. 'var s = "<tt>" + extlog.out.join("~~~").replace(/[&]/g, "&amp;").replace(/[<]/g, "&lt;").replace(/[ ]/g, "&#160;").replace(/\\~\\~\\~/g, "<br/>") + "</tt>";',
  10123. 'document.body.innerHTML = s;',
  10124. '}',
  10125. 'setTimeout(update, 1000);',
  10126. '}',
  10127. 'setTimeout(update, 1000);',
  10128. '</script></head><body></body></html>'].join(''));
  10129. };
  10130. nullLog = function () {};
  10131. nullLog.info = nullLog.warn = nullLog.error = Ext.emptyFn;
  10132. Ext.setVersion('extjs', '4.1.1.1');
  10133. Ext.apply(Ext, {
  10134. /**
  10135. * @property {String} SSL_SECURE_URL
  10136. * URL to a blank file used by Ext when in secure mode for iframe src and onReady src
  10137. * to prevent the IE insecure content warning (`'about:blank'`, except for IE
  10138. * in secure mode, which is `'javascript:""'`).
  10139. */
  10140. SSL_SECURE_URL : isSecure && isIE ? 'javascript:\'\'' : 'about:blank',
  10141. /**
  10142. * @property {Boolean} enableFx
  10143. * True if the {@link Ext.fx.Anim} Class is available.
  10144. */
  10145. /**
  10146. * @property {Boolean} scopeResetCSS
  10147. * True to scope the reset CSS to be just applied to Ext components. Note that this
  10148. * wraps root containers with an additional element. Also remember that when you turn
  10149. * on this option, you have to use ext-all-scoped (unless you use the bootstrap.js to
  10150. * load your javascript, in which case it will be handled for you).
  10151. */
  10152. scopeResetCSS : Ext.buildSettings.scopeResetCSS,
  10153. /**
  10154. * @property {String} resetCls
  10155. * The css class used to wrap Ext components when the {@link #scopeResetCSS} option
  10156. * is used.
  10157. */
  10158. resetCls: Ext.buildSettings.baseCSSPrefix + 'reset',
  10159. /**
  10160. * @property {Boolean} enableNestedListenerRemoval
  10161. * **Experimental.** True to cascade listener removal to child elements when an element
  10162. * is removed. Currently not optimized for performance.
  10163. */
  10164. enableNestedListenerRemoval : false,
  10165. /**
  10166. * @property {Boolean} USE_NATIVE_JSON
  10167. * Indicates whether to use native browser parsing for JSON methods.
  10168. * This option is ignored if the browser does not support native JSON methods.
  10169. *
  10170. * **Note:** Native JSON methods will not work with objects that have functions.
  10171. * Also, property names must be quoted, otherwise the data will not parse.
  10172. */
  10173. USE_NATIVE_JSON : false,
  10174. /**
  10175. * Returns the dom node for the passed String (id), dom node, or Ext.Element.
  10176. * Optional 'strict' flag is needed for IE since it can return 'name' and
  10177. * 'id' elements by using getElementById.
  10178. *
  10179. * Here are some examples:
  10180. *
  10181. * // gets dom node based on id
  10182. * var elDom = Ext.getDom('elId');
  10183. * // gets dom node based on the dom node
  10184. * var elDom1 = Ext.getDom(elDom);
  10185. *
  10186. * // If we don&#39;t know if we are working with an
  10187. * // Ext.Element or a dom node use Ext.getDom
  10188. * function(el){
  10189. * var dom = Ext.getDom(el);
  10190. * // do something with the dom node
  10191. * }
  10192. *
  10193. * **Note:** the dom node to be found actually needs to exist (be rendered, etc)
  10194. * when this method is called to be successful.
  10195. *
  10196. * @param {String/HTMLElement/Ext.Element} el
  10197. * @return HTMLElement
  10198. */
  10199. getDom : function(el, strict) {
  10200. if (!el || !document) {
  10201. return null;
  10202. }
  10203. if (el.dom) {
  10204. return el.dom;
  10205. } else {
  10206. if (typeof el == 'string') {
  10207. var e = Ext.getElementById(el);
  10208. // IE returns elements with the 'name' and 'id' attribute.
  10209. // we do a strict check to return the element with only the id attribute
  10210. if (e && isIE && strict) {
  10211. if (el == e.getAttribute('id')) {
  10212. return e;
  10213. } else {
  10214. return null;
  10215. }
  10216. }
  10217. return e;
  10218. } else {
  10219. return el;
  10220. }
  10221. }
  10222. },
  10223. /**
  10224. * Removes a DOM node from the document.
  10225. *
  10226. * Removes this element from the document, removes all DOM event listeners, and
  10227. * deletes the cache reference. All DOM event listeners are removed from this element.
  10228. * If {@link Ext#enableNestedListenerRemoval Ext.enableNestedListenerRemoval} is
  10229. * `true`, then DOM event listeners are also removed from all child nodes.
  10230. * The body node will be ignored if passed in.
  10231. *
  10232. * @param {HTMLElement} node The node to remove
  10233. * @method
  10234. */
  10235. removeNode : isIE6 || isIE7 || isIE8
  10236. ? (function() {
  10237. var d;
  10238. return function(n){
  10239. if(n && n.tagName.toUpperCase() != 'BODY'){
  10240. (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n) : Ext.EventManager.removeAll(n);
  10241. var cache = Ext.cache,
  10242. id = n.id;
  10243. if (cache[id]) {
  10244. delete cache[id].dom;
  10245. delete cache[id];
  10246. }
  10247. if (isIE8 && n.parentNode) {
  10248. n.parentNode.removeChild(n);
  10249. }
  10250. d = d || document.createElement('div');
  10251. d.appendChild(n);
  10252. d.innerHTML = '';
  10253. }
  10254. };
  10255. }())
  10256. : function(n) {
  10257. if (n && n.parentNode && n.tagName.toUpperCase() != 'BODY') {
  10258. (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n) : Ext.EventManager.removeAll(n);
  10259. var cache = Ext.cache,
  10260. id = n.id;
  10261. if (cache[id]) {
  10262. delete cache[id].dom;
  10263. delete cache[id];
  10264. }
  10265. n.parentNode.removeChild(n);
  10266. }
  10267. },
  10268. isStrict: isStrict,
  10269. isIEQuirks: isIE && !isStrict,
  10270. /**
  10271. * True if the detected browser is Opera.
  10272. * @type Boolean
  10273. */
  10274. isOpera : isOpera,
  10275. /**
  10276. * True if the detected browser is Opera 10.5x.
  10277. * @type Boolean
  10278. */
  10279. isOpera10_5 : isOpera10_5,
  10280. /**
  10281. * True if the detected browser uses WebKit.
  10282. * @type Boolean
  10283. */
  10284. isWebKit : isWebKit,
  10285. /**
  10286. * True if the detected browser is Chrome.
  10287. * @type Boolean
  10288. */
  10289. isChrome : isChrome,
  10290. /**
  10291. * True if the detected browser is Safari.
  10292. * @type Boolean
  10293. */
  10294. isSafari : isSafari,
  10295. /**
  10296. * True if the detected browser is Safari 3.x.
  10297. * @type Boolean
  10298. */
  10299. isSafari3 : isSafari3,
  10300. /**
  10301. * True if the detected browser is Safari 4.x.
  10302. * @type Boolean
  10303. */
  10304. isSafari4 : isSafari4,
  10305. /**
  10306. * True if the detected browser is Safari 5.x.
  10307. * @type Boolean
  10308. */
  10309. isSafari5 : isSafari5,
  10310. /**
  10311. * True if the detected browser is Safari 5.0.x.
  10312. * @type Boolean
  10313. */
  10314. isSafari5_0 : isSafari5_0,
  10315. /**
  10316. * True if the detected browser is Safari 2.x.
  10317. * @type Boolean
  10318. */
  10319. isSafari2 : isSafari2,
  10320. /**
  10321. * True if the detected browser is Internet Explorer.
  10322. * @type Boolean
  10323. */
  10324. isIE : isIE,
  10325. /**
  10326. * True if the detected browser is Internet Explorer 6.x.
  10327. * @type Boolean
  10328. */
  10329. isIE6 : isIE6,
  10330. /**
  10331. * True if the detected browser is Internet Explorer 7.x.
  10332. * @type Boolean
  10333. */
  10334. isIE7 : isIE7,
  10335. /**
  10336. * True if the detected browser is Internet Explorer 8.x.
  10337. * @type Boolean
  10338. */
  10339. isIE8 : isIE8,
  10340. /**
  10341. * True if the detected browser is Internet Explorer 9.x.
  10342. * @type Boolean
  10343. */
  10344. isIE9 : isIE9,
  10345. /**
  10346. * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
  10347. * @type Boolean
  10348. */
  10349. isGecko : isGecko,
  10350. /**
  10351. * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
  10352. * @type Boolean
  10353. */
  10354. isGecko3 : isGecko3,
  10355. /**
  10356. * True if the detected browser uses a Gecko 2.0+ layout engine (e.g. Firefox 4.x).
  10357. * @type Boolean
  10358. */
  10359. isGecko4 : isGecko4,
  10360. /**
  10361. * True if the detected browser uses a Gecko 5.0+ layout engine (e.g. Firefox 5.x).
  10362. * @type Boolean
  10363. */
  10364. isGecko5 : isGecko5,
  10365. /**
  10366. * True if the detected browser uses a Gecko 5.0+ layout engine (e.g. Firefox 5.x).
  10367. * @type Boolean
  10368. */
  10369. isGecko10 : isGecko10,
  10370. /**
  10371. * True if the detected browser uses FireFox 3.0
  10372. * @type Boolean
  10373. */
  10374. isFF3_0 : isFF3_0,
  10375. /**
  10376. * True if the detected browser uses FireFox 3.5
  10377. * @type Boolean
  10378. */
  10379. isFF3_5 : isFF3_5,
  10380. /**
  10381. * True if the detected browser uses FireFox 3.6
  10382. * @type Boolean
  10383. */
  10384. isFF3_6 : isFF3_6,
  10385. /**
  10386. * True if the detected browser uses FireFox 4
  10387. * @type Boolean
  10388. */
  10389. isFF4 : 4 <= firefoxVersion && firefoxVersion < 5,
  10390. /**
  10391. * True if the detected browser uses FireFox 5
  10392. * @type Boolean
  10393. */
  10394. isFF5 : 5 <= firefoxVersion && firefoxVersion < 6,
  10395. /**
  10396. * True if the detected browser uses FireFox 10
  10397. * @type Boolean
  10398. */
  10399. isFF10 : 10 <= firefoxVersion && firefoxVersion < 11,
  10400. /**
  10401. * True if the detected platform is Linux.
  10402. * @type Boolean
  10403. */
  10404. isLinux : isLinux,
  10405. /**
  10406. * True if the detected platform is Windows.
  10407. * @type Boolean
  10408. */
  10409. isWindows : isWindows,
  10410. /**
  10411. * True if the detected platform is Mac OS.
  10412. * @type Boolean
  10413. */
  10414. isMac : isMac,
  10415. /**
  10416. * The current version of Chrome (0 if the browser is not Chrome).
  10417. * @type Number
  10418. */
  10419. chromeVersion: chromeVersion,
  10420. /**
  10421. * The current version of Firefox (0 if the browser is not Firefox).
  10422. * @type Number
  10423. */
  10424. firefoxVersion: firefoxVersion,
  10425. /**
  10426. * The current version of IE (0 if the browser is not IE). This does not account
  10427. * for the documentMode of the current page, which is factored into {@link #isIE7},
  10428. * {@link #isIE8} and {@link #isIE9}. Thus this is not always true:
  10429. *
  10430. * Ext.isIE8 == (Ext.ieVersion == 8)
  10431. *
  10432. * @type Number
  10433. */
  10434. ieVersion: ieVersion,
  10435. /**
  10436. * The current version of Opera (0 if the browser is not Opera).
  10437. * @type Number
  10438. */
  10439. operaVersion: operaVersion,
  10440. /**
  10441. * The current version of Safari (0 if the browser is not Safari).
  10442. * @type Number
  10443. */
  10444. safariVersion: safariVersion,
  10445. /**
  10446. * The current version of WebKit (0 if the browser does not use WebKit).
  10447. * @type Number
  10448. */
  10449. webKitVersion: webKitVersion,
  10450. /**
  10451. * True if the page is running over SSL
  10452. * @type Boolean
  10453. */
  10454. isSecure: isSecure,
  10455. /**
  10456. * URL to a 1x1 transparent gif image used by Ext to create inline icons with
  10457. * CSS background images. In older versions of IE, this defaults to
  10458. * "http://sencha.com/s.gif" and you should change this to a URL on your server.
  10459. * For other browsers it uses an inline data URL.
  10460. * @type String
  10461. */
  10462. BLANK_IMAGE_URL : (isIE6 || isIE7) ? '/' + '/www.sencha.com/s.gif' : 'data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
  10463. /**
  10464. * Utility method for returning a default value if the passed value is empty.
  10465. *
  10466. * The value is deemed to be empty if it is:
  10467. *
  10468. * - null
  10469. * - undefined
  10470. * - an empty array
  10471. * - a zero length string (Unless the `allowBlank` parameter is `true`)
  10472. *
  10473. * @param {Object} value The value to test
  10474. * @param {Object} defaultValue The value to return if the original value is empty
  10475. * @param {Boolean} [allowBlank=false] true to allow zero length strings to qualify as non-empty.
  10476. * @return {Object} value, if non-empty, else defaultValue
  10477. * @deprecated 4.0.0 Use {@link Ext#valueFrom} instead
  10478. */
  10479. value : function(v, defaultValue, allowBlank){
  10480. return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
  10481. },
  10482. /**
  10483. * Escapes the passed string for use in a regular expression.
  10484. * @param {String} str
  10485. * @return {String}
  10486. * @deprecated 4.0.0 Use {@link Ext.String#escapeRegex} instead
  10487. */
  10488. escapeRe : function(s) {
  10489. return s.replace(/([-.*+?\^${}()|\[\]\/\\])/g, "\\$1");
  10490. },
  10491. /**
  10492. * Applies event listeners to elements by selectors when the document is ready.
  10493. * The event name is specified with an `@` suffix.
  10494. *
  10495. * Ext.addBehaviors({
  10496. * // add a listener for click on all anchors in element with id foo
  10497. * '#foo a@click' : function(e, t){
  10498. * // do something
  10499. * },
  10500. *
  10501. * // add the same listener to multiple selectors (separated by comma BEFORE the @)
  10502. * '#foo a, #bar span.some-class@mouseover' : function(){
  10503. * // do something
  10504. * }
  10505. * });
  10506. *
  10507. * @param {Object} obj The list of behaviors to apply
  10508. */
  10509. addBehaviors : function(o){
  10510. if(!Ext.isReady){
  10511. Ext.onReady(function(){
  10512. Ext.addBehaviors(o);
  10513. });
  10514. } else {
  10515. var cache = {}, // simple cache for applying multiple behaviors to same selector does query multiple times
  10516. parts,
  10517. b,
  10518. s;
  10519. for (b in o) {
  10520. if ((parts = b.split('@'))[1]) { // for Object prototype breakers
  10521. s = parts[0];
  10522. if(!cache[s]){
  10523. cache[s] = Ext.select(s);
  10524. }
  10525. cache[s].on(parts[1], o[b]);
  10526. }
  10527. }
  10528. cache = null;
  10529. }
  10530. },
  10531. /**
  10532. * Returns the size of the browser scrollbars. This can differ depending on
  10533. * operating system settings, such as the theme or font size.
  10534. * @param {Boolean} [force] true to force a recalculation of the value.
  10535. * @return {Object} An object containing scrollbar sizes.
  10536. * @return.width {Number} The width of the vertical scrollbar.
  10537. * @return.height {Number} The height of the horizontal scrollbar.
  10538. */
  10539. getScrollbarSize: function (force) {
  10540. if (!Ext.isReady) {
  10541. return {};
  10542. }
  10543. if (force || !scrollbarSize) {
  10544. var db = document.body,
  10545. div = document.createElement('div');
  10546. div.style.width = div.style.height = '100px';
  10547. div.style.overflow = 'scroll';
  10548. div.style.position = 'absolute';
  10549. db.appendChild(div); // now we can measure the div...
  10550. // at least in iE9 the div is not 100px - the scrollbar size is removed!
  10551. scrollbarSize = {
  10552. width: div.offsetWidth - div.clientWidth,
  10553. height: div.offsetHeight - div.clientHeight
  10554. };
  10555. db.removeChild(div);
  10556. }
  10557. return scrollbarSize;
  10558. },
  10559. /**
  10560. * Utility method for getting the width of the browser's vertical scrollbar. This
  10561. * can differ depending on operating system settings, such as the theme or font size.
  10562. *
  10563. * This method is deprected in favor of {@link #getScrollbarSize}.
  10564. *
  10565. * @param {Boolean} [force] true to force a recalculation of the value.
  10566. * @return {Number} The width of a vertical scrollbar.
  10567. * @deprecated
  10568. */
  10569. getScrollBarWidth: function(force){
  10570. var size = Ext.getScrollbarSize(force);
  10571. return size.width + 2; // legacy fudge factor
  10572. },
  10573. /**
  10574. * Copies a set of named properties fom the source object to the destination object.
  10575. *
  10576. * Example:
  10577. *
  10578. * ImageComponent = Ext.extend(Ext.Component, {
  10579. * initComponent: function() {
  10580. * this.autoEl = { tag: 'img' };
  10581. * MyComponent.superclass.initComponent.apply(this, arguments);
  10582. * this.initialBox = Ext.copyTo({}, this.initialConfig, 'x,y,width,height');
  10583. * }
  10584. * });
  10585. *
  10586. * Important note: To borrow class prototype methods, use {@link Ext.Base#borrow} instead.
  10587. *
  10588. * @param {Object} dest The destination object.
  10589. * @param {Object} source The source object.
  10590. * @param {String/String[]} names Either an Array of property names, or a comma-delimited list
  10591. * of property names to copy.
  10592. * @param {Boolean} [usePrototypeKeys] Defaults to false. Pass true to copy keys off of the
  10593. * prototype as well as the instance.
  10594. * @return {Object} The modified object.
  10595. */
  10596. copyTo : function(dest, source, names, usePrototypeKeys){
  10597. if(typeof names == 'string'){
  10598. names = names.split(/[,;\s]/);
  10599. }
  10600. var n,
  10601. nLen = names.length,
  10602. name;
  10603. for(n = 0; n < nLen; n++) {
  10604. name = names[n];
  10605. if(usePrototypeKeys || source.hasOwnProperty(name)){
  10606. dest[name] = source[name];
  10607. }
  10608. }
  10609. return dest;
  10610. },
  10611. /**
  10612. * Attempts to destroy and then remove a set of named properties of the passed object.
  10613. * @param {Object} o The object (most likely a Component) who's properties you wish to destroy.
  10614. * @param {String...} args One or more names of the properties to destroy and remove from the object.
  10615. */
  10616. destroyMembers : function(o){
  10617. for (var i = 1, a = arguments, len = a.length; i < len; i++) {
  10618. Ext.destroy(o[a[i]]);
  10619. delete o[a[i]];
  10620. }
  10621. },
  10622. /**
  10623. * Logs a message. If a console is present it will be used. On Opera, the method
  10624. * "opera.postError" is called. In other cases, the message is logged to an array
  10625. * "Ext.log.out". An attached debugger can watch this array and view the log. The
  10626. * log buffer is limited to a maximum of "Ext.log.max" entries (defaults to 250).
  10627. * The `Ext.log.out` array can also be written to a popup window by entering the
  10628. * following in the URL bar (a "bookmarklet"):
  10629. *
  10630. * javascript:void(Ext.log.show());
  10631. *
  10632. * If additional parameters are passed, they are joined and appended to the message.
  10633. * A technique for tracing entry and exit of a function is this:
  10634. *
  10635. * function foo () {
  10636. * Ext.log({ indent: 1 }, '>> foo');
  10637. *
  10638. * // log statements in here or methods called from here will be indented
  10639. * // by one step
  10640. *
  10641. * Ext.log({ outdent: 1 }, '<< foo');
  10642. * }
  10643. *
  10644. * This method does nothing in a release build.
  10645. *
  10646. * @param {String/Object} [options] The message to log or an options object with any
  10647. * of the following properties:
  10648. *
  10649. * - `msg`: The message to log (required).
  10650. * - `level`: One of: "error", "warn", "info" or "log" (the default is "log").
  10651. * - `dump`: An object to dump to the log as part of the message.
  10652. * - `stack`: True to include a stack trace in the log.
  10653. * - `indent`: Cause subsequent log statements to be indented one step.
  10654. * - `outdent`: Cause this and following statements to be one step less indented.
  10655. *
  10656. * @param {String...} [message] The message to log (required unless specified in
  10657. * options object).
  10658. *
  10659. * @method
  10660. */
  10661. log :
  10662. log ||
  10663. nullLog,
  10664. /**
  10665. * Partitions the set into two sets: a true set and a false set.
  10666. *
  10667. * Example 1:
  10668. *
  10669. * Ext.partition([true, false, true, true, false]);
  10670. * // returns [[true, true, true], [false, false]]
  10671. *
  10672. * Example 2:
  10673. *
  10674. * Ext.partition(
  10675. * Ext.query("p"),
  10676. * function(val){
  10677. * return val.className == "class1"
  10678. * }
  10679. * );
  10680. * // true are those paragraph elements with a className of "class1",
  10681. * // false set are those that do not have that className.
  10682. *
  10683. * @param {Array/NodeList} arr The array to partition
  10684. * @param {Function} truth (optional) a function to determine truth.
  10685. * If this is omitted the element itself must be able to be evaluated for its truthfulness.
  10686. * @return {Array} [array of truish values, array of falsy values]
  10687. * @deprecated 4.0.0 Will be removed in the next major version
  10688. */
  10689. partition : function(arr, truth){
  10690. var ret = [[],[]],
  10691. a, v,
  10692. aLen = arr.length;
  10693. for (a = 0; a < aLen; a++) {
  10694. v = arr[a];
  10695. ret[ (truth && truth(v, a, arr)) || (!truth && v) ? 0 : 1].push(v);
  10696. }
  10697. return ret;
  10698. },
  10699. /**
  10700. * Invokes a method on each item in an Array.
  10701. *
  10702. * Example:
  10703. *
  10704. * Ext.invoke(Ext.query("p"), "getAttribute", "id");
  10705. * // [el1.getAttribute("id"), el2.getAttribute("id"), ..., elN.getAttribute("id")]
  10706. *
  10707. * @param {Array/NodeList} arr The Array of items to invoke the method on.
  10708. * @param {String} methodName The method name to invoke.
  10709. * @param {Object...} args Arguments to send into the method invocation.
  10710. * @return {Array} The results of invoking the method on each item in the array.
  10711. * @deprecated 4.0.0 Will be removed in the next major version
  10712. */
  10713. invoke : function(arr, methodName){
  10714. var ret = [],
  10715. args = Array.prototype.slice.call(arguments, 2),
  10716. a, v,
  10717. aLen = arr.length;
  10718. for (a = 0; a < aLen; a++) {
  10719. v = arr[a];
  10720. if (v && typeof v[methodName] == 'function') {
  10721. ret.push(v[methodName].apply(v, args));
  10722. } else {
  10723. ret.push(undefined);
  10724. }
  10725. }
  10726. return ret;
  10727. },
  10728. /**
  10729. * Zips N sets together.
  10730. *
  10731. * Example 1:
  10732. *
  10733. * Ext.zip([1,2,3],[4,5,6]); // [[1,4],[2,5],[3,6]]
  10734. *
  10735. * Example 2:
  10736. *
  10737. * Ext.zip(
  10738. * [ "+", "-", "+"],
  10739. * [ 12, 10, 22],
  10740. * [ 43, 15, 96],
  10741. * function(a, b, c){
  10742. * return "$" + a + "" + b + "." + c
  10743. * }
  10744. * ); // ["$+12.43", "$-10.15", "$+22.96"]
  10745. *
  10746. * @param {Array/NodeList...} arr This argument may be repeated. Array(s)
  10747. * to contribute values.
  10748. * @param {Function} zipper (optional) The last item in the argument list.
  10749. * This will drive how the items are zipped together.
  10750. * @return {Array} The zipped set.
  10751. * @deprecated 4.0.0 Will be removed in the next major version
  10752. */
  10753. zip : function(){
  10754. var parts = Ext.partition(arguments, function( val ){ return typeof val != 'function'; }),
  10755. arrs = parts[0],
  10756. fn = parts[1][0],
  10757. len = Ext.max(Ext.pluck(arrs, "length")),
  10758. ret = [],
  10759. i,
  10760. j,
  10761. aLen;
  10762. for (i = 0; i < len; i++) {
  10763. ret[i] = [];
  10764. if(fn){
  10765. ret[i] = fn.apply(fn, Ext.pluck(arrs, i));
  10766. }else{
  10767. for (j = 0, aLen = arrs.length; j < aLen; j++){
  10768. ret[i].push( arrs[j][i] );
  10769. }
  10770. }
  10771. }
  10772. return ret;
  10773. },
  10774. /**
  10775. * Turns an array into a sentence, joined by a specified connector - e.g.:
  10776. *
  10777. * Ext.toSentence(['Adama', 'Tigh', 'Roslin']); //'Adama, Tigh and Roslin'
  10778. * Ext.toSentence(['Adama', 'Tigh', 'Roslin'], 'or'); //'Adama, Tigh or Roslin'
  10779. *
  10780. * @param {String[]} items The array to create a sentence from
  10781. * @param {String} connector The string to use to connect the last two words.
  10782. * Usually 'and' or 'or' - defaults to 'and'.
  10783. * @return {String} The sentence string
  10784. * @deprecated 4.0.0 Will be removed in the next major version
  10785. */
  10786. toSentence: function(items, connector) {
  10787. var length = items.length,
  10788. head,
  10789. tail;
  10790. if (length <= 1) {
  10791. return items[0];
  10792. } else {
  10793. head = items.slice(0, length - 1);
  10794. tail = items[length - 1];
  10795. return Ext.util.Format.format("{0} {1} {2}", head.join(", "), connector || 'and', tail);
  10796. }
  10797. },
  10798. /**
  10799. * @property {Boolean} useShims
  10800. * By default, Ext intelligently decides whether floating elements should be shimmed.
  10801. * If you are using flash, you may want to set this to true.
  10802. */
  10803. useShims: isIE6
  10804. });
  10805. }());
  10806. /**
  10807. * Loads Ext.app.Application class and starts it up with given configuration after the page is ready.
  10808. *
  10809. * See Ext.app.Application for details.
  10810. *
  10811. * @param {Object} config
  10812. */
  10813. Ext.application = function(config) {
  10814. Ext.require('Ext.app.Application');
  10815. Ext.onReady(function() {
  10816. new Ext.app.Application(config);
  10817. });
  10818. };
  10819. //@tag extras,core
  10820. //@require ../Ext-more.js
  10821. //@define Ext.util.Format
  10822. /**
  10823. * @class Ext.util.Format
  10824. *
  10825. * This class is a centralized place for formatting functions. It includes
  10826. * functions to format various different types of data, such as text, dates and numeric values.
  10827. *
  10828. * ## Localization
  10829. *
  10830. * This class contains several options for localization. These can be set once the library has loaded,
  10831. * all calls to the functions from that point will use the locale settings that were specified.
  10832. *
  10833. * Options include:
  10834. *
  10835. * - thousandSeparator
  10836. * - decimalSeparator
  10837. * - currenyPrecision
  10838. * - currencySign
  10839. * - currencyAtEnd
  10840. *
  10841. * This class also uses the default date format defined here: {@link Ext.Date#defaultFormat}.
  10842. *
  10843. * ## Using with renderers
  10844. *
  10845. * There are two helper functions that return a new function that can be used in conjunction with
  10846. * grid renderers:
  10847. *
  10848. * columns: [{
  10849. * dataIndex: 'date',
  10850. * renderer: Ext.util.Format.dateRenderer('Y-m-d')
  10851. * }, {
  10852. * dataIndex: 'time',
  10853. * renderer: Ext.util.Format.numberRenderer('0.000')
  10854. * }]
  10855. *
  10856. * Functions that only take a single argument can also be passed directly:
  10857. *
  10858. * columns: [{
  10859. * dataIndex: 'cost',
  10860. * renderer: Ext.util.Format.usMoney
  10861. * }, {
  10862. * dataIndex: 'productCode',
  10863. * renderer: Ext.util.Format.uppercase
  10864. * }]
  10865. *
  10866. * ## Using with XTemplates
  10867. *
  10868. * XTemplates can also directly use Ext.util.Format functions:
  10869. *
  10870. * new Ext.XTemplate([
  10871. * 'Date: {startDate:date("Y-m-d")}',
  10872. * 'Cost: {cost:usMoney}'
  10873. * ]);
  10874. *
  10875. * @singleton
  10876. */
  10877. (function() {
  10878. Ext.ns('Ext.util');
  10879. Ext.util.Format = {};
  10880. var UtilFormat = Ext.util.Format,
  10881. stripTagsRE = /<\/?[^>]+>/gi,
  10882. stripScriptsRe = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig,
  10883. nl2brRe = /\r?\n/g,
  10884. // A RegExp to remove from a number format string, all characters except digits and '.'
  10885. formatCleanRe = /[^\d\.]/g,
  10886. // A RegExp to remove from a number format string, all characters except digits and the local decimal separator.
  10887. // Created on first use. The local decimal separator character must be initialized for this to be created.
  10888. I18NFormatCleanRe;
  10889. Ext.apply(UtilFormat, {
  10890. //<locale>
  10891. /**
  10892. * @property {String} thousandSeparator
  10893. * The character that the {@link #number} function uses as a thousand separator.
  10894. *
  10895. * This may be overridden in a locale file.
  10896. */
  10897. thousandSeparator: ',',
  10898. //</locale>
  10899. //<locale>
  10900. /**
  10901. * @property {String} decimalSeparator
  10902. * The character that the {@link #number} function uses as a decimal point.
  10903. *
  10904. * This may be overridden in a locale file.
  10905. */
  10906. decimalSeparator: '.',
  10907. //</locale>
  10908. //<locale>
  10909. /**
  10910. * @property {Number} currencyPrecision
  10911. * The number of decimal places that the {@link #currency} function displays.
  10912. *
  10913. * This may be overridden in a locale file.
  10914. */
  10915. currencyPrecision: 2,
  10916. //</locale>
  10917. //<locale>
  10918. /**
  10919. * @property {String} currencySign
  10920. * The currency sign that the {@link #currency} function displays.
  10921. *
  10922. * This may be overridden in a locale file.
  10923. */
  10924. currencySign: '$',
  10925. //</locale>
  10926. //<locale>
  10927. /**
  10928. * @property {Boolean} currencyAtEnd
  10929. * This may be set to <code>true</code> to make the {@link #currency} function
  10930. * append the currency sign to the formatted value.
  10931. *
  10932. * This may be overridden in a locale file.
  10933. */
  10934. currencyAtEnd: false,
  10935. //</locale>
  10936. /**
  10937. * Checks a reference and converts it to empty string if it is undefined.
  10938. * @param {Object} value Reference to check
  10939. * @return {Object} Empty string if converted, otherwise the original value
  10940. */
  10941. undef : function(value) {
  10942. return value !== undefined ? value : "";
  10943. },
  10944. /**
  10945. * Checks a reference and converts it to the default value if it's empty.
  10946. * @param {Object} value Reference to check
  10947. * @param {String} [defaultValue=""] The value to insert of it's undefined.
  10948. * @return {String}
  10949. */
  10950. defaultValue : function(value, defaultValue) {
  10951. return value !== undefined && value !== '' ? value : defaultValue;
  10952. },
  10953. /**
  10954. * Returns a substring from within an original string.
  10955. * @param {String} value The original text
  10956. * @param {Number} start The start index of the substring
  10957. * @param {Number} length The length of the substring
  10958. * @return {String} The substring
  10959. * @method
  10960. */
  10961. substr : 'ab'.substr(-1) != 'b'
  10962. ? function (value, start, length) {
  10963. var str = String(value);
  10964. return (start < 0)
  10965. ? str.substr(Math.max(str.length + start, 0), length)
  10966. : str.substr(start, length);
  10967. }
  10968. : function(value, start, length) {
  10969. return String(value).substr(start, length);
  10970. },
  10971. /**
  10972. * Converts a string to all lower case letters.
  10973. * @param {String} value The text to convert
  10974. * @return {String} The converted text
  10975. */
  10976. lowercase : function(value) {
  10977. return String(value).toLowerCase();
  10978. },
  10979. /**
  10980. * Converts a string to all upper case letters.
  10981. * @param {String} value The text to convert
  10982. * @return {String} The converted text
  10983. */
  10984. uppercase : function(value) {
  10985. return String(value).toUpperCase();
  10986. },
  10987. /**
  10988. * Format a number as US currency.
  10989. * @param {Number/String} value The numeric value to format
  10990. * @return {String} The formatted currency string
  10991. */
  10992. usMoney : function(v) {
  10993. return UtilFormat.currency(v, '$', 2);
  10994. },
  10995. /**
  10996. * Format a number as a currency.
  10997. * @param {Number/String} value The numeric value to format
  10998. * @param {String} [sign] The currency sign to use (defaults to {@link #currencySign})
  10999. * @param {Number} [decimals] The number of decimals to use for the currency
  11000. * (defaults to {@link #currencyPrecision})
  11001. * @param {Boolean} [end] True if the currency sign should be at the end of the string
  11002. * (defaults to {@link #currencyAtEnd})
  11003. * @return {String} The formatted currency string
  11004. */
  11005. currency: function(v, currencySign, decimals, end) {
  11006. var negativeSign = '',
  11007. format = ",0",
  11008. i = 0;
  11009. v = v - 0;
  11010. if (v < 0) {
  11011. v = -v;
  11012. negativeSign = '-';
  11013. }
  11014. decimals = Ext.isDefined(decimals) ? decimals : UtilFormat.currencyPrecision;
  11015. format += format + (decimals > 0 ? '.' : '');
  11016. for (; i < decimals; i++) {
  11017. format += '0';
  11018. }
  11019. v = UtilFormat.number(v, format);
  11020. if ((end || UtilFormat.currencyAtEnd) === true) {
  11021. return Ext.String.format("{0}{1}{2}", negativeSign, v, currencySign || UtilFormat.currencySign);
  11022. } else {
  11023. return Ext.String.format("{0}{1}{2}", negativeSign, currencySign || UtilFormat.currencySign, v);
  11024. }
  11025. },
  11026. /**
  11027. * Formats the passed date using the specified format pattern.
  11028. * @param {String/Date} value The value to format. If a string is passed, it is converted to a Date
  11029. * by the Javascript's built-in Date#parse method.
  11030. * @param {String} [format] Any valid date format string. Defaults to {@link Ext.Date#defaultFormat}.
  11031. * @return {String} The formatted date string.
  11032. */
  11033. date: function(v, format) {
  11034. if (!v) {
  11035. return "";
  11036. }
  11037. if (!Ext.isDate(v)) {
  11038. v = new Date(Date.parse(v));
  11039. }
  11040. return Ext.Date.dateFormat(v, format || Ext.Date.defaultFormat);
  11041. },
  11042. /**
  11043. * Returns a date rendering function that can be reused to apply a date format multiple times efficiently.
  11044. * @param {String} format Any valid date format string. Defaults to {@link Ext.Date#defaultFormat}.
  11045. * @return {Function} The date formatting function
  11046. */
  11047. dateRenderer : function(format) {
  11048. return function(v) {
  11049. return UtilFormat.date(v, format);
  11050. };
  11051. },
  11052. /**
  11053. * Strips all HTML tags.
  11054. * @param {Object} value The text from which to strip tags
  11055. * @return {String} The stripped text
  11056. */
  11057. stripTags : function(v) {
  11058. return !v ? v : String(v).replace(stripTagsRE, "");
  11059. },
  11060. /**
  11061. * Strips all script tags.
  11062. * @param {Object} value The text from which to strip script tags
  11063. * @return {String} The stripped text
  11064. */
  11065. stripScripts : function(v) {
  11066. return !v ? v : String(v).replace(stripScriptsRe, "");
  11067. },
  11068. /**
  11069. * Simple format for a file size (xxx bytes, xxx KB, xxx MB).
  11070. * @param {Number/String} size The numeric value to format
  11071. * @return {String} The formatted file size
  11072. */
  11073. fileSize : function(size) {
  11074. if (size < 1024) {
  11075. return size + " bytes";
  11076. } else if (size < 1048576) {
  11077. return (Math.round(((size*10) / 1024))/10) + " KB";
  11078. } else {
  11079. return (Math.round(((size*10) / 1048576))/10) + " MB";
  11080. }
  11081. },
  11082. /**
  11083. * It does simple math for use in a template, for example:
  11084. *
  11085. * var tpl = new Ext.Template('{value} * 10 = {value:math("* 10")}');
  11086. *
  11087. * @return {Function} A function that operates on the passed value.
  11088. * @method
  11089. */
  11090. math : (function(){
  11091. var fns = {};
  11092. return function(v, a){
  11093. if (!fns[a]) {
  11094. fns[a] = Ext.functionFactory('v', 'return v ' + a + ';');
  11095. }
  11096. return fns[a](v);
  11097. };
  11098. }()),
  11099. /**
  11100. * Rounds the passed number to the required decimal precision.
  11101. * @param {Number/String} value The numeric value to round.
  11102. * @param {Number} precision The number of decimal places to which to round the first parameter's value.
  11103. * @return {Number} The rounded value.
  11104. */
  11105. round : function(value, precision) {
  11106. var result = Number(value);
  11107. if (typeof precision == 'number') {
  11108. precision = Math.pow(10, precision);
  11109. result = Math.round(value * precision) / precision;
  11110. }
  11111. return result;
  11112. },
  11113. /**
  11114. * Formats the passed number according to the passed format string.
  11115. *
  11116. * The number of digits after the decimal separator character specifies the number of
  11117. * decimal places in the resulting string. The *local-specific* decimal character is
  11118. * used in the result.
  11119. *
  11120. * The *presence* of a thousand separator character in the format string specifies that
  11121. * the *locale-specific* thousand separator (if any) is inserted separating thousand groups.
  11122. *
  11123. * By default, "," is expected as the thousand separator, and "." is expected as the decimal separator.
  11124. *
  11125. * ## New to Ext JS 4
  11126. *
  11127. * Locale-specific characters are always used in the formatted output when inserting
  11128. * thousand and decimal separators.
  11129. *
  11130. * The format string must specify separator characters according to US/UK conventions ("," as the
  11131. * thousand separator, and "." as the decimal separator)
  11132. *
  11133. * To allow specification of format strings according to local conventions for separator characters, add
  11134. * the string `/i` to the end of the format string.
  11135. *
  11136. * examples (123456.789):
  11137. *
  11138. * - `0` - (123456) show only digits, no precision
  11139. * - `0.00` - (123456.78) show only digits, 2 precision
  11140. * - `0.0000` - (123456.7890) show only digits, 4 precision
  11141. * - `0,000` - (123,456) show comma and digits, no precision
  11142. * - `0,000.00` - (123,456.78) show comma and digits, 2 precision
  11143. * - `0,0.00` - (123,456.78) shortcut method, show comma and digits, 2 precision
  11144. *
  11145. * To allow specification of the formatting string using UK/US grouping characters (,) and
  11146. * decimal (.) for international numbers, add /i to the end. For example: 0.000,00/i
  11147. *
  11148. * @param {Number} v The number to format.
  11149. * @param {String} format The way you would like to format this text.
  11150. * @return {String} The formatted number.
  11151. */
  11152. number : function(v, formatString) {
  11153. if (!formatString) {
  11154. return v;
  11155. }
  11156. v = Ext.Number.from(v, NaN);
  11157. if (isNaN(v)) {
  11158. return '';
  11159. }
  11160. var comma = UtilFormat.thousandSeparator,
  11161. dec = UtilFormat.decimalSeparator,
  11162. i18n = false,
  11163. neg = v < 0,
  11164. hasComma,
  11165. psplit,
  11166. fnum,
  11167. cnum,
  11168. parr,
  11169. j,
  11170. m,
  11171. n,
  11172. i;
  11173. v = Math.abs(v);
  11174. // The "/i" suffix allows caller to use a locale-specific formatting string.
  11175. // Clean the format string by removing all but numerals and the decimal separator.
  11176. // Then split the format string into pre and post decimal segments according to *what* the
  11177. // decimal separator is. If they are specifying "/i", they are using the local convention in the format string.
  11178. if (formatString.substr(formatString.length - 2) == '/i') {
  11179. if (!I18NFormatCleanRe) {
  11180. I18NFormatCleanRe = new RegExp('[^\\d\\' + UtilFormat.decimalSeparator + ']','g');
  11181. }
  11182. formatString = formatString.substr(0, formatString.length - 2);
  11183. i18n = true;
  11184. hasComma = formatString.indexOf(comma) != -1;
  11185. psplit = formatString.replace(I18NFormatCleanRe, '').split(dec);
  11186. } else {
  11187. hasComma = formatString.indexOf(',') != -1;
  11188. psplit = formatString.replace(formatCleanRe, '').split('.');
  11189. }
  11190. if (psplit.length > 2) {
  11191. Ext.Error.raise({
  11192. sourceClass: "Ext.util.Format",
  11193. sourceMethod: "number",
  11194. value: v,
  11195. formatString: formatString,
  11196. msg: "Invalid number format, should have no more than 1 decimal"
  11197. });
  11198. } else if (psplit.length > 1) {
  11199. v = Ext.Number.toFixed(v, psplit[1].length);
  11200. } else {
  11201. v = Ext.Number.toFixed(v, 0);
  11202. }
  11203. fnum = v.toString();
  11204. psplit = fnum.split('.');
  11205. if (hasComma) {
  11206. cnum = psplit[0];
  11207. parr = [];
  11208. j = cnum.length;
  11209. m = Math.floor(j / 3);
  11210. n = cnum.length % 3 || 3;
  11211. for (i = 0; i < j; i += n) {
  11212. if (i !== 0) {
  11213. n = 3;
  11214. }
  11215. parr[parr.length] = cnum.substr(i, n);
  11216. m -= 1;
  11217. }
  11218. fnum = parr.join(comma);
  11219. if (psplit[1]) {
  11220. fnum += dec + psplit[1];
  11221. }
  11222. } else {
  11223. if (psplit[1]) {
  11224. fnum = psplit[0] + dec + psplit[1];
  11225. }
  11226. }
  11227. if (neg) {
  11228. /*
  11229. * Edge case. If we have a very small negative number it will get rounded to 0,
  11230. * however the initial check at the top will still report as negative. Replace
  11231. * everything but 1-9 and check if the string is empty to determine a 0 value.
  11232. */
  11233. neg = fnum.replace(/[^1-9]/g, '') !== '';
  11234. }
  11235. return (neg ? '-' : '') + formatString.replace(/[\d,?\.?]+/, fnum);
  11236. },
  11237. /**
  11238. * Returns a number rendering function that can be reused to apply a number format multiple
  11239. * times efficiently.
  11240. *
  11241. * @param {String} format Any valid number format string for {@link #number}
  11242. * @return {Function} The number formatting function
  11243. */
  11244. numberRenderer : function(format) {
  11245. return function(v) {
  11246. return UtilFormat.number(v, format);
  11247. };
  11248. },
  11249. /**
  11250. * Selectively do a plural form of a word based on a numeric value. For example, in a template,
  11251. * `{commentCount:plural("Comment")}` would result in `"1 Comment"` if commentCount was 1 or
  11252. * would be `"x Comments"` if the value is 0 or greater than 1.
  11253. *
  11254. * @param {Number} value The value to compare against
  11255. * @param {String} singular The singular form of the word
  11256. * @param {String} [plural] The plural form of the word (defaults to the singular with an "s")
  11257. */
  11258. plural : function(v, s, p) {
  11259. return v +' ' + (v == 1 ? s : (p ? p : s+'s'));
  11260. },
  11261. /**
  11262. * Converts newline characters to the HTML tag `<br/>`
  11263. *
  11264. * @param {String} The string value to format.
  11265. * @return {String} The string with embedded `<br/>` tags in place of newlines.
  11266. */
  11267. nl2br : function(v) {
  11268. return Ext.isEmpty(v) ? '' : v.replace(nl2brRe, '<br/>');
  11269. },
  11270. /**
  11271. * Alias for {@link Ext.String#capitalize}.
  11272. * @method
  11273. * @inheritdoc Ext.String#capitalize
  11274. */
  11275. capitalize: Ext.String.capitalize,
  11276. /**
  11277. * Alias for {@link Ext.String#ellipsis}.
  11278. * @method
  11279. * @inheritdoc Ext.String#ellipsis
  11280. */
  11281. ellipsis: Ext.String.ellipsis,
  11282. /**
  11283. * Alias for {@link Ext.String#format}.
  11284. * @method
  11285. * @inheritdoc Ext.String#format
  11286. */
  11287. format: Ext.String.format,
  11288. /**
  11289. * Alias for {@link Ext.String#htmlDecode}.
  11290. * @method
  11291. * @inheritdoc Ext.String#htmlDecode
  11292. */
  11293. htmlDecode: Ext.String.htmlDecode,
  11294. /**
  11295. * Alias for {@link Ext.String#htmlEncode}.
  11296. * @method
  11297. * @inheritdoc Ext.String#htmlEncode
  11298. */
  11299. htmlEncode: Ext.String.htmlEncode,
  11300. /**
  11301. * Alias for {@link Ext.String#leftPad}.
  11302. * @method
  11303. * @inheritdoc Ext.String#leftPad
  11304. */
  11305. leftPad: Ext.String.leftPad,
  11306. /**
  11307. * Alias for {@link Ext.String#trim}.
  11308. * @method
  11309. * @inheritdoc Ext.String#trim
  11310. */
  11311. trim : Ext.String.trim,
  11312. /**
  11313. * Parses a number or string representing margin sizes into an object.
  11314. * Supports CSS-style margin declarations (e.g. 10, "10", "10 10", "10 10 10" and
  11315. * "10 10 10 10" are all valid options and would return the same result).
  11316. *
  11317. * @param {Number/String} v The encoded margins
  11318. * @return {Object} An object with margin sizes for top, right, bottom and left
  11319. */
  11320. parseBox : function(box) {
  11321. box = Ext.isEmpty(box) ? '' : box;
  11322. if (Ext.isNumber(box)) {
  11323. box = box.toString();
  11324. }
  11325. var parts = box.split(' '),
  11326. ln = parts.length;
  11327. if (ln == 1) {
  11328. parts[1] = parts[2] = parts[3] = parts[0];
  11329. }
  11330. else if (ln == 2) {
  11331. parts[2] = parts[0];
  11332. parts[3] = parts[1];
  11333. }
  11334. else if (ln == 3) {
  11335. parts[3] = parts[1];
  11336. }
  11337. return {
  11338. top :parseInt(parts[0], 10) || 0,
  11339. right :parseInt(parts[1], 10) || 0,
  11340. bottom:parseInt(parts[2], 10) || 0,
  11341. left :parseInt(parts[3], 10) || 0
  11342. };
  11343. },
  11344. /**
  11345. * Escapes the passed string for use in a regular expression.
  11346. * @param {String} str
  11347. * @return {String}
  11348. */
  11349. escapeRegex : function(s) {
  11350. return s.replace(/([\-.*+?\^${}()|\[\]\/\\])/g, "\\$1");
  11351. }
  11352. });
  11353. }());
  11354. //@tag extras,core
  11355. //@require Format.js
  11356. //@define Ext.util.TaskManager
  11357. //@define Ext.TaskManager
  11358. /**
  11359. * Provides the ability to execute one or more arbitrary tasks in a asynchronous manner.
  11360. * Generally, you can use the singleton {@link Ext.TaskManager} instead, but if needed,
  11361. * you can create separate instances of TaskRunner. Any number of separate tasks can be
  11362. * started at any time and will run independently of each other.
  11363. *
  11364. * Example usage:
  11365. *
  11366. * // Start a simple clock task that updates a div once per second
  11367. * var updateClock = function () {
  11368. * Ext.fly('clock').update(new Date().format('g:i:s A'));
  11369. * }
  11370. *
  11371. * var runner = new Ext.util.TaskRunner();
  11372. * var task = runner.start({
  11373. * run: updateClock,
  11374. * interval: 1000
  11375. * }
  11376. *
  11377. * The equivalent using TaskManager:
  11378. *
  11379. * var task = Ext.TaskManager.start({
  11380. * run: updateClock,
  11381. * interval: 1000
  11382. * });
  11383. *
  11384. * To end a running task:
  11385. *
  11386. * Ext.TaskManager.stop(task);
  11387. *
  11388. * If a task needs to be started and stopped repeated over time, you can create a
  11389. * {@link Ext.util.TaskRunner.Task Task} instance.
  11390. *
  11391. * var task = runner.newTask({
  11392. * run: function () {
  11393. * // useful code
  11394. * },
  11395. * interval: 1000
  11396. * });
  11397. *
  11398. * task.start();
  11399. *
  11400. * // ...
  11401. *
  11402. * task.stop();
  11403. *
  11404. * // ...
  11405. *
  11406. * task.start();
  11407. *
  11408. * A re-usable, one-shot task can be managed similar to the above:
  11409. *
  11410. * var task = runner.newTask({
  11411. * run: function () {
  11412. * // useful code to run once
  11413. * },
  11414. * repeat: 1
  11415. * });
  11416. *
  11417. * task.start();
  11418. *
  11419. * // ...
  11420. *
  11421. * task.start();
  11422. *
  11423. * See the {@link #start} method for details about how to configure a task object.
  11424. *
  11425. * Also see {@link Ext.util.DelayedTask}.
  11426. *
  11427. * @constructor
  11428. * @param {Number/Object} [interval=10] The minimum precision in milliseconds supported by this
  11429. * TaskRunner instance. Alternatively, a config object to apply to the new instance.
  11430. */
  11431. Ext.define('Ext.util.TaskRunner', {
  11432. /**
  11433. * @cfg interval
  11434. * The timer resolution.
  11435. */
  11436. interval: 10,
  11437. /**
  11438. * @property timerId
  11439. * The id of the current timer.
  11440. * @private
  11441. */
  11442. timerId: null,
  11443. constructor: function (interval) {
  11444. var me = this;
  11445. if (typeof interval == 'number') {
  11446. me.interval = interval;
  11447. } else if (interval) {
  11448. Ext.apply(me, interval);
  11449. }
  11450. me.tasks = [];
  11451. me.timerFn = Ext.Function.bind(me.onTick, me);
  11452. },
  11453. /**
  11454. * Creates a new {@link Ext.util.TaskRunner.Task Task} instance. These instances can
  11455. * be easily started and stopped.
  11456. * @param {Object} config The config object. For details on the supported properties,
  11457. * see {@link #start}.
  11458. */
  11459. newTask: function (config) {
  11460. var task = new Ext.util.TaskRunner.Task(config);
  11461. task.manager = this;
  11462. return task;
  11463. },
  11464. /**
  11465. * Starts a new task.
  11466. *
  11467. * Before each invocation, Ext injects the property `taskRunCount` into the task object
  11468. * so that calculations based on the repeat count can be performed.
  11469. *
  11470. * The returned task will contain a `destroy` method that can be used to destroy the
  11471. * task and cancel further calls. This is equivalent to the {@link #stop} method.
  11472. *
  11473. * @param {Object} task A config object that supports the following properties:
  11474. * @param {Function} task.run The function to execute each time the task is invoked. The
  11475. * function will be called at each interval and passed the `args` argument if specified,
  11476. * and the current invocation count if not.
  11477. *
  11478. * If a particular scope (`this` reference) is required, be sure to specify it using
  11479. * the `scope` argument.
  11480. *
  11481. * @param {Function} task.onError The function to execute in case of unhandled
  11482. * error on task.run.
  11483. *
  11484. * @param {Boolean} task.run.return `false` from this function to terminate the task.
  11485. *
  11486. * @param {Number} task.interval The frequency in milliseconds with which the task
  11487. * should be invoked.
  11488. *
  11489. * @param {Object[]} task.args An array of arguments to be passed to the function
  11490. * specified by `run`. If not specified, the current invocation count is passed.
  11491. *
  11492. * @param {Object} task.scope The scope (`this` reference) in which to execute the
  11493. * `run` function. Defaults to the task config object.
  11494. *
  11495. * @param {Number} task.duration The length of time in milliseconds to invoke the task
  11496. * before stopping automatically (defaults to indefinite).
  11497. *
  11498. * @param {Number} task.repeat The number of times to invoke the task before stopping
  11499. * automatically (defaults to indefinite).
  11500. * @return {Object} The task
  11501. */
  11502. start: function(task) {
  11503. var me = this,
  11504. now = new Date().getTime();
  11505. if (!task.pending) {
  11506. me.tasks.push(task);
  11507. task.pending = true; // don't allow the task to be added to me.tasks again
  11508. }
  11509. task.stopped = false; // might have been previously stopped...
  11510. task.taskStartTime = now;
  11511. task.taskRunTime = task.fireOnStart !== false ? 0 : task.taskStartTime;
  11512. task.taskRunCount = 0;
  11513. if (!me.firing) {
  11514. if (task.fireOnStart !== false) {
  11515. me.startTimer(0, now);
  11516. } else {
  11517. me.startTimer(task.interval, now);
  11518. }
  11519. }
  11520. return task;
  11521. },
  11522. /**
  11523. * Stops an existing running task.
  11524. * @param {Object} task The task to stop
  11525. * @return {Object} The task
  11526. */
  11527. stop: function(task) {
  11528. // NOTE: we don't attempt to remove the task from me.tasks at this point because
  11529. // this could be called from inside a task which would then corrupt the state of
  11530. // the loop in onTick
  11531. if (!task.stopped) {
  11532. task.stopped = true;
  11533. if (task.onStop) {
  11534. task.onStop.call(task.scope || task, task);
  11535. }
  11536. }
  11537. return task;
  11538. },
  11539. /**
  11540. * Stops all tasks that are currently running.
  11541. */
  11542. stopAll: function() {
  11543. // onTick will take care of cleaning up the mess after this point...
  11544. Ext.each(this.tasks, this.stop, this);
  11545. },
  11546. //-------------------------------------------------------------------------
  11547. firing: false,
  11548. nextExpires: 1e99,
  11549. // private
  11550. onTick: function () {
  11551. var me = this,
  11552. tasks = me.tasks,
  11553. now = new Date().getTime(),
  11554. nextExpires = 1e99,
  11555. len = tasks.length,
  11556. expires, newTasks, i, task, rt, remove;
  11557. me.timerId = null;
  11558. me.firing = true; // ensure we don't startTimer during this loop...
  11559. // tasks.length can be > len if start is called during a task.run call... so we
  11560. // first check len to avoid tasks.length reference but eventually we need to also
  11561. // check tasks.length. we avoid repeating use of tasks.length by setting len at
  11562. // that time (to help the next loop)
  11563. for (i = 0; i < len || i < (len = tasks.length); ++i) {
  11564. task = tasks[i];
  11565. if (!(remove = task.stopped)) {
  11566. expires = task.taskRunTime + task.interval;
  11567. if (expires <= now) {
  11568. rt = 1; // otherwise we have a stale "rt"
  11569. try {
  11570. rt = task.run.apply(task.scope || task, task.args || [++task.taskRunCount]);
  11571. } catch (taskError) {
  11572. try {
  11573. if (task.onError) {
  11574. rt = task.onError.call(task.scope || task, task, taskError);
  11575. }
  11576. } catch (ignore) { }
  11577. }
  11578. task.taskRunTime = now;
  11579. if (rt === false || task.taskRunCount === task.repeat) {
  11580. me.stop(task);
  11581. remove = true;
  11582. } else {
  11583. remove = task.stopped; // in case stop was called by run
  11584. expires = now + task.interval;
  11585. }
  11586. }
  11587. if (!remove && task.duration && task.duration <= (now - task.taskStartTime)) {
  11588. me.stop(task);
  11589. remove = true;
  11590. }
  11591. }
  11592. if (remove) {
  11593. task.pending = false; // allow the task to be added to me.tasks again
  11594. // once we detect that a task needs to be removed, we copy the tasks that
  11595. // will carry forward into newTasks... this way we avoid O(N*N) to remove
  11596. // each task from the tasks array (and ripple the array down) and also the
  11597. // potentially wasted effort of making a new tasks[] even if all tasks are
  11598. // going into the next wave.
  11599. if (!newTasks) {
  11600. newTasks = tasks.slice(0, i);
  11601. // we don't set me.tasks here because callbacks can also start tasks,
  11602. // which get added to me.tasks... so we will visit them in this loop
  11603. // and account for their expirations in nextExpires...
  11604. }
  11605. } else {
  11606. if (newTasks) {
  11607. newTasks.push(task); // we've cloned the tasks[], so keep this one...
  11608. }
  11609. if (nextExpires > expires) {
  11610. nextExpires = expires; // track the nearest expiration time
  11611. }
  11612. }
  11613. }
  11614. if (newTasks) {
  11615. // only now can we copy the newTasks to me.tasks since no user callbacks can
  11616. // take place
  11617. me.tasks = newTasks;
  11618. }
  11619. me.firing = false; // we're done, so allow startTimer afterwards
  11620. if (me.tasks.length) {
  11621. // we create a new Date here because all the callbacks could have taken a long
  11622. // time... we want to base the next timeout on the current time (after the
  11623. // callback storm):
  11624. me.startTimer(nextExpires - now, new Date().getTime());
  11625. }
  11626. },
  11627. // private
  11628. startTimer: function (timeout, now) {
  11629. var me = this,
  11630. expires = now + timeout,
  11631. timerId = me.timerId;
  11632. // Check to see if this request is enough in advance of the current timer. If so,
  11633. // we reschedule the timer based on this new expiration.
  11634. if (timerId && me.nextExpires - expires > me.interval) {
  11635. clearTimeout(timerId);
  11636. timerId = null;
  11637. }
  11638. if (!timerId) {
  11639. if (timeout < me.interval) {
  11640. timeout = me.interval;
  11641. }
  11642. me.timerId = setTimeout(me.timerFn, timeout);
  11643. me.nextExpires = expires;
  11644. }
  11645. }
  11646. },
  11647. function () {
  11648. var me = this,
  11649. proto = me.prototype;
  11650. /**
  11651. * Destroys this instance, stopping all tasks that are currently running.
  11652. * @method destroy
  11653. */
  11654. proto.destroy = proto.stopAll;
  11655. /**
  11656. * @class Ext.TaskManager
  11657. * @extends Ext.util.TaskRunner
  11658. * @singleton
  11659. *
  11660. * A static {@link Ext.util.TaskRunner} instance that can be used to start and stop
  11661. * arbitrary tasks. See {@link Ext.util.TaskRunner} for supported methods and task
  11662. * config properties.
  11663. *
  11664. * // Start a simple clock task that updates a div once per second
  11665. * var task = {
  11666. * run: function(){
  11667. * Ext.fly('clock').update(new Date().format('g:i:s A'));
  11668. * },
  11669. * interval: 1000 //1 second
  11670. * }
  11671. *
  11672. * Ext.TaskManager.start(task);
  11673. *
  11674. * See the {@link #start} method for details about how to configure a task object.
  11675. */
  11676. Ext.util.TaskManager = Ext.TaskManager = new me();
  11677. /**
  11678. * Instances of this class are created by {@link Ext.util.TaskRunner#newTask} method.
  11679. *
  11680. * For details on config properties, see {@link Ext.util.TaskRunner#start}.
  11681. * @class Ext.util.TaskRunner.Task
  11682. */
  11683. me.Task = new Ext.Class({
  11684. isTask: true,
  11685. /**
  11686. * This flag is set to `true` by {@link #stop}.
  11687. * @private
  11688. */
  11689. stopped: true, // this avoids the odd combination of !stopped && !pending
  11690. /**
  11691. * Override default behavior
  11692. */
  11693. fireOnStart: false,
  11694. constructor: function (config) {
  11695. Ext.apply(this, config);
  11696. },
  11697. /**
  11698. * Restarts this task, clearing it duration, expiration and run count.
  11699. * @param {Number} [interval] Optionally reset this task's interval.
  11700. */
  11701. restart: function (interval) {
  11702. if (interval !== undefined) {
  11703. this.interval = interval;
  11704. }
  11705. this.manager.start(this);
  11706. },
  11707. /**
  11708. * Starts this task if it is not already started.
  11709. * @param {Number} [interval] Optionally reset this task's interval.
  11710. */
  11711. start: function (interval) {
  11712. if (this.stopped) {
  11713. this.restart(interval);
  11714. }
  11715. },
  11716. /**
  11717. * Stops this task.
  11718. */
  11719. stop: function () {
  11720. this.manager.stop(this);
  11721. }
  11722. });
  11723. proto = me.Task.prototype;
  11724. /**
  11725. * Destroys this instance, stopping this task's execution.
  11726. * @method destroy
  11727. */
  11728. proto.destroy = proto.stop;
  11729. });
  11730. //@tag extras,core
  11731. //@require ../util/TaskManager.js
  11732. /**
  11733. * @class Ext.perf.Accumulator
  11734. * @private
  11735. */
  11736. Ext.define('Ext.perf.Accumulator', (function () {
  11737. var currentFrame = null,
  11738. khrome = Ext.global['chrome'],
  11739. formatTpl,
  11740. // lazy init on first request for timestamp (avoids infobar in IE until needed)
  11741. // Also avoids kicking off Chrome's microsecond timer until first needed
  11742. getTimestamp = function () {
  11743. getTimestamp = function () {
  11744. return new Date().getTime();
  11745. };
  11746. var interval, toolbox;
  11747. // If Chrome is started with the --enable-benchmarking switch
  11748. if (Ext.isChrome && khrome && khrome.Interval) {
  11749. interval = new khrome.Interval();
  11750. interval.start();
  11751. getTimestamp = function () {
  11752. return interval.microseconds() / 1000;
  11753. };
  11754. } else if (window.ActiveXObject) {
  11755. try {
  11756. // the above technique is not very accurate for small intervals...
  11757. toolbox = new ActiveXObject('SenchaToolbox.Toolbox');
  11758. Ext.senchaToolbox = toolbox; // export for other uses
  11759. getTimestamp = function () {
  11760. return toolbox.milliseconds;
  11761. };
  11762. } catch (e) {
  11763. // ignore
  11764. }
  11765. } else if (Date.now) {
  11766. getTimestamp = Date.now;
  11767. }
  11768. Ext.perf.getTimestamp = Ext.perf.Accumulator.getTimestamp = getTimestamp;
  11769. return getTimestamp();
  11770. };
  11771. function adjustSet (set, time) {
  11772. set.sum += time;
  11773. set.min = Math.min(set.min, time);
  11774. set.max = Math.max(set.max, time);
  11775. }
  11776. function leaveFrame (time) {
  11777. var totalTime = time ? time : (getTimestamp() - this.time), // do this first
  11778. me = this, // me = frame
  11779. accum = me.accum;
  11780. ++accum.count;
  11781. if (! --accum.depth) {
  11782. adjustSet(accum.total, totalTime);
  11783. }
  11784. adjustSet(accum.pure, totalTime - me.childTime);
  11785. currentFrame = me.parent;
  11786. if (currentFrame) {
  11787. ++currentFrame.accum.childCount;
  11788. currentFrame.childTime += totalTime;
  11789. }
  11790. }
  11791. function makeSet () {
  11792. return {
  11793. min: Number.MAX_VALUE,
  11794. max: 0,
  11795. sum: 0
  11796. };
  11797. }
  11798. function makeTap (me, fn) {
  11799. return function () {
  11800. var frame = me.enter(),
  11801. ret = fn.apply(this, arguments);
  11802. frame.leave();
  11803. return ret;
  11804. };
  11805. }
  11806. function round (x) {
  11807. return Math.round(x * 100) / 100;
  11808. }
  11809. function setToJSON (count, childCount, calibration, set) {
  11810. var data = {
  11811. avg: 0,
  11812. min: set.min,
  11813. max: set.max,
  11814. sum: 0
  11815. };
  11816. if (count) {
  11817. calibration = calibration || 0;
  11818. data.sum = set.sum - childCount * calibration;
  11819. data.avg = data.sum / count;
  11820. // min and max cannot be easily corrected since we don't know the number of
  11821. // child calls for them.
  11822. }
  11823. return data;
  11824. }
  11825. return {
  11826. constructor: function (name) {
  11827. var me = this;
  11828. me.count = me.childCount = me.depth = me.maxDepth = 0;
  11829. me.pure = makeSet();
  11830. me.total = makeSet();
  11831. me.name = name;
  11832. },
  11833. statics: {
  11834. getTimestamp: getTimestamp
  11835. },
  11836. format: function (calibration) {
  11837. if (!formatTpl) {
  11838. formatTpl = new Ext.XTemplate([
  11839. '{name} - {count} call(s)',
  11840. '<tpl if="count">',
  11841. '<tpl if="childCount">',
  11842. ' ({childCount} children)',
  11843. '</tpl>',
  11844. '<tpl if="depth - 1">',
  11845. ' ({depth} deep)',
  11846. '</tpl>',
  11847. '<tpl for="times">',
  11848. ', {type}: {[this.time(values.sum)]} msec (',
  11849. //'min={[this.time(values.min)]}, ',
  11850. 'avg={[this.time(values.sum / parent.count)]}',
  11851. //', max={[this.time(values.max)]}',
  11852. ')',
  11853. '</tpl>',
  11854. '</tpl>'
  11855. ].join(''), {
  11856. time: function (t) {
  11857. return Math.round(t * 100) / 100;
  11858. }
  11859. });
  11860. }
  11861. var data = this.getData(calibration);
  11862. data.name = this.name;
  11863. data.pure.type = 'Pure';
  11864. data.total.type = 'Total';
  11865. data.times = [data.pure, data.total];
  11866. return formatTpl.apply(data);
  11867. },
  11868. getData: function (calibration) {
  11869. var me = this;
  11870. return {
  11871. count: me.count,
  11872. childCount: me.childCount,
  11873. depth: me.maxDepth,
  11874. pure: setToJSON(me.count, me.childCount, calibration, me.pure),
  11875. total: setToJSON(me.count, me.childCount, calibration, me.total)
  11876. };
  11877. },
  11878. enter: function () {
  11879. var me = this,
  11880. frame = {
  11881. accum: me,
  11882. leave: leaveFrame,
  11883. childTime: 0,
  11884. parent: currentFrame
  11885. };
  11886. ++me.depth;
  11887. if (me.maxDepth < me.depth) {
  11888. me.maxDepth = me.depth;
  11889. }
  11890. currentFrame = frame;
  11891. frame.time = getTimestamp(); // do this last
  11892. return frame;
  11893. },
  11894. monitor: function (fn, scope, args) {
  11895. var frame = this.enter();
  11896. if (args) {
  11897. fn.apply(scope, args);
  11898. } else {
  11899. fn.call(scope);
  11900. }
  11901. frame.leave();
  11902. },
  11903. report: function () {
  11904. Ext.log(this.format());
  11905. },
  11906. tap: function (className, methodName) {
  11907. var me = this,
  11908. methods = typeof methodName == 'string' ? [methodName] : methodName,
  11909. klass, statik, i, parts, length, name, src,
  11910. tapFunc;
  11911. tapFunc = function(){
  11912. if (typeof className == 'string') {
  11913. klass = Ext.global;
  11914. parts = className.split('.');
  11915. for (i = 0, length = parts.length; i < length; ++i) {
  11916. klass = klass[parts[i]];
  11917. }
  11918. } else {
  11919. klass = className;
  11920. }
  11921. for (i = 0, length = methods.length; i < length; ++i) {
  11922. name = methods[i];
  11923. statik = name.charAt(0) == '!';
  11924. if (statik) {
  11925. name = name.substring(1);
  11926. } else {
  11927. statik = !(name in klass.prototype);
  11928. }
  11929. src = statik ? klass : klass.prototype;
  11930. src[name] = makeTap(me, src[name]);
  11931. }
  11932. };
  11933. Ext.ClassManager.onCreated(tapFunc, me, className);
  11934. return me;
  11935. }
  11936. };
  11937. }()),
  11938. function () {
  11939. Ext.perf.getTimestamp = this.getTimestamp;
  11940. });
  11941. //@tag extras,core
  11942. //@require Accumulator.js
  11943. /**
  11944. * @class Ext.perf.Monitor
  11945. * @singleton
  11946. * @private
  11947. */
  11948. Ext.define('Ext.perf.Monitor', {
  11949. singleton: true,
  11950. alternateClassName: 'Ext.Perf',
  11951. requires: [
  11952. 'Ext.perf.Accumulator'
  11953. ],
  11954. constructor: function () {
  11955. this.accumulators = [];
  11956. this.accumulatorsByName = {};
  11957. },
  11958. calibrate: function () {
  11959. var accum = new Ext.perf.Accumulator('$'),
  11960. total = accum.total,
  11961. getTimestamp = Ext.perf.Accumulator.getTimestamp,
  11962. count = 0,
  11963. frame,
  11964. endTime,
  11965. startTime;
  11966. startTime = getTimestamp();
  11967. do {
  11968. frame = accum.enter();
  11969. frame.leave();
  11970. ++count;
  11971. } while (total.sum < 100);
  11972. endTime = getTimestamp();
  11973. return (endTime - startTime) / count;
  11974. },
  11975. get: function (name) {
  11976. var me = this,
  11977. accum = me.accumulatorsByName[name];
  11978. if (!accum) {
  11979. me.accumulatorsByName[name] = accum = new Ext.perf.Accumulator(name);
  11980. me.accumulators.push(accum);
  11981. }
  11982. return accum;
  11983. },
  11984. enter: function (name) {
  11985. return this.get(name).enter();
  11986. },
  11987. monitor: function (name, fn, scope) {
  11988. this.get(name).monitor(fn, scope);
  11989. },
  11990. report: function () {
  11991. var me = this,
  11992. accumulators = me.accumulators,
  11993. calibration = me.calibrate();
  11994. accumulators.sort(function (a, b) {
  11995. return (a.name < b.name) ? -1 : ((b.name < a.name) ? 1 : 0);
  11996. });
  11997. me.updateGC();
  11998. Ext.log('Calibration: ' + Math.round(calibration * 100) / 100 + ' msec/sample');
  11999. Ext.each(accumulators, function (accum) {
  12000. Ext.log(accum.format(calibration));
  12001. });
  12002. },
  12003. getData: function (all) {
  12004. var ret = {},
  12005. accumulators = this.accumulators;
  12006. Ext.each(accumulators, function (accum) {
  12007. if (all || accum.count) {
  12008. ret[accum.name] = accum.getData();
  12009. }
  12010. });
  12011. return ret;
  12012. },
  12013. reset: function(){
  12014. Ext.each(this.accumulators, function(accum){
  12015. var me = accum;
  12016. me.count = me.childCount = me.depth = me.maxDepth = 0;
  12017. me.pure = {
  12018. min: Number.MAX_VALUE,
  12019. max: 0,
  12020. sum: 0
  12021. };
  12022. me.total = {
  12023. min: Number.MAX_VALUE,
  12024. max: 0,
  12025. sum: 0
  12026. };
  12027. });
  12028. },
  12029. updateGC: function () {
  12030. var accumGC = this.accumulatorsByName.GC,
  12031. toolbox = Ext.senchaToolbox,
  12032. bucket;
  12033. if (accumGC) {
  12034. accumGC.count = toolbox.garbageCollectionCounter || 0;
  12035. if (accumGC.count) {
  12036. bucket = accumGC.pure;
  12037. accumGC.total.sum = bucket.sum = toolbox.garbageCollectionMilliseconds;
  12038. bucket.min = bucket.max = bucket.sum / accumGC.count;
  12039. bucket = accumGC.total;
  12040. bucket.min = bucket.max = bucket.sum / accumGC.count;
  12041. }
  12042. }
  12043. },
  12044. watchGC: function () {
  12045. Ext.perf.getTimestamp(); // initializes SenchaToolbox (if available)
  12046. var toolbox = Ext.senchaToolbox;
  12047. if (toolbox) {
  12048. this.get("GC");
  12049. toolbox.watchGarbageCollector(false); // no logging, just totals
  12050. }
  12051. },
  12052. setup: function (config) {
  12053. if (!config) {
  12054. config = {
  12055. /*insertHtml: {
  12056. 'Ext.dom.Helper': 'insertHtml'
  12057. },*/
  12058. /*xtplCompile: {
  12059. 'Ext.XTemplateCompiler': 'compile'
  12060. },*/
  12061. // doInsert: {
  12062. // 'Ext.Template': 'doInsert'
  12063. // },
  12064. // applyOut: {
  12065. // 'Ext.XTemplate': 'applyOut'
  12066. // },
  12067. render: {
  12068. 'Ext.AbstractComponent': 'render'
  12069. },
  12070. // fnishRender: {
  12071. // 'Ext.AbstractComponent': 'finishRender'
  12072. // },
  12073. // renderSelectors: {
  12074. // 'Ext.AbstractComponent': 'applyRenderSelectors'
  12075. // },
  12076. // compAddCls: {
  12077. // 'Ext.AbstractComponent': 'addCls'
  12078. // },
  12079. // compRemoveCls: {
  12080. // 'Ext.AbstractComponent': 'removeCls'
  12081. // },
  12082. // getStyle: {
  12083. // 'Ext.core.Element': 'getStyle'
  12084. // },
  12085. // setStyle: {
  12086. // 'Ext.core.Element': 'setStyle'
  12087. // },
  12088. // addCls: {
  12089. // 'Ext.core.Element': 'addCls'
  12090. // },
  12091. // removeCls: {
  12092. // 'Ext.core.Element': 'removeCls'
  12093. // },
  12094. // measure: {
  12095. // 'Ext.layout.component.Component': 'measureAutoDimensions'
  12096. // },
  12097. // moveItem: {
  12098. // 'Ext.layout.Layout': 'moveItem'
  12099. // },
  12100. // layoutFlush: {
  12101. // 'Ext.layout.Context': 'flush'
  12102. // },
  12103. layout: {
  12104. 'Ext.layout.Context': 'run'
  12105. }
  12106. };
  12107. }
  12108. this.currentConfig = config;
  12109. var key, prop,
  12110. accum, className, methods;
  12111. for (key in config) {
  12112. if (config.hasOwnProperty(key)) {
  12113. prop = config[key];
  12114. accum = Ext.Perf.get(key);
  12115. for (className in prop) {
  12116. if (prop.hasOwnProperty(className)) {
  12117. methods = prop[className];
  12118. accum.tap(className, methods);
  12119. }
  12120. }
  12121. }
  12122. }
  12123. this.watchGC();
  12124. }
  12125. });
  12126. //@tag extras,core
  12127. //@require perf/Monitor.js
  12128. //@define Ext.Supports
  12129. /**
  12130. * @class Ext.is
  12131. *
  12132. * Determines information about the current platform the application is running on.
  12133. *
  12134. * @singleton
  12135. */
  12136. Ext.is = {
  12137. init : function(navigator) {
  12138. var platforms = this.platforms,
  12139. ln = platforms.length,
  12140. i, platform;
  12141. navigator = navigator || window.navigator;
  12142. for (i = 0; i < ln; i++) {
  12143. platform = platforms[i];
  12144. this[platform.identity] = platform.regex.test(navigator[platform.property]);
  12145. }
  12146. /**
  12147. * @property Desktop True if the browser is running on a desktop machine
  12148. * @type {Boolean}
  12149. */
  12150. this.Desktop = this.Mac || this.Windows || (this.Linux && !this.Android);
  12151. /**
  12152. * @property Tablet True if the browser is running on a tablet (iPad)
  12153. */
  12154. this.Tablet = this.iPad;
  12155. /**
  12156. * @property Phone True if the browser is running on a phone.
  12157. * @type {Boolean}
  12158. */
  12159. this.Phone = !this.Desktop && !this.Tablet;
  12160. /**
  12161. * @property iOS True if the browser is running on iOS
  12162. * @type {Boolean}
  12163. */
  12164. this.iOS = this.iPhone || this.iPad || this.iPod;
  12165. /**
  12166. * @property Standalone Detects when application has been saved to homescreen.
  12167. * @type {Boolean}
  12168. */
  12169. this.Standalone = !!window.navigator.standalone;
  12170. },
  12171. /**
  12172. * @property iPhone True when the browser is running on a iPhone
  12173. * @type {Boolean}
  12174. */
  12175. platforms: [{
  12176. property: 'platform',
  12177. regex: /iPhone/i,
  12178. identity: 'iPhone'
  12179. },
  12180. /**
  12181. * @property iPod True when the browser is running on a iPod
  12182. * @type {Boolean}
  12183. */
  12184. {
  12185. property: 'platform',
  12186. regex: /iPod/i,
  12187. identity: 'iPod'
  12188. },
  12189. /**
  12190. * @property iPad True when the browser is running on a iPad
  12191. * @type {Boolean}
  12192. */
  12193. {
  12194. property: 'userAgent',
  12195. regex: /iPad/i,
  12196. identity: 'iPad'
  12197. },
  12198. /**
  12199. * @property Blackberry True when the browser is running on a Blackberry
  12200. * @type {Boolean}
  12201. */
  12202. {
  12203. property: 'userAgent',
  12204. regex: /Blackberry/i,
  12205. identity: 'Blackberry'
  12206. },
  12207. /**
  12208. * @property Android True when the browser is running on an Android device
  12209. * @type {Boolean}
  12210. */
  12211. {
  12212. property: 'userAgent',
  12213. regex: /Android/i,
  12214. identity: 'Android'
  12215. },
  12216. /**
  12217. * @property Mac True when the browser is running on a Mac
  12218. * @type {Boolean}
  12219. */
  12220. {
  12221. property: 'platform',
  12222. regex: /Mac/i,
  12223. identity: 'Mac'
  12224. },
  12225. /**
  12226. * @property Windows True when the browser is running on Windows
  12227. * @type {Boolean}
  12228. */
  12229. {
  12230. property: 'platform',
  12231. regex: /Win/i,
  12232. identity: 'Windows'
  12233. },
  12234. /**
  12235. * @property Linux True when the browser is running on Linux
  12236. * @type {Boolean}
  12237. */
  12238. {
  12239. property: 'platform',
  12240. regex: /Linux/i,
  12241. identity: 'Linux'
  12242. }]
  12243. };
  12244. Ext.is.init();
  12245. /**
  12246. * @class Ext.supports
  12247. *
  12248. * Determines information about features are supported in the current environment
  12249. *
  12250. * @singleton
  12251. */
  12252. (function(){
  12253. // this is a local copy of certain logic from (Abstract)Element.getStyle
  12254. // to break a dependancy between the supports mechanism and Element
  12255. // use this instead of element references to check for styling info
  12256. var getStyle = function(element, styleName){
  12257. var view = element.ownerDocument.defaultView,
  12258. style = (view ? view.getComputedStyle(element, null) : element.currentStyle) || element.style;
  12259. return style[styleName];
  12260. };
  12261. Ext.supports = {
  12262. /**
  12263. * Runs feature detection routines and sets the various flags. This is called when
  12264. * the scripts loads (very early) and again at {@link Ext#onReady}. Some detections
  12265. * are flagged as `early` and run immediately. Others that require the document body
  12266. * will not run until ready.
  12267. *
  12268. * Each test is run only once, so calling this method from an onReady function is safe
  12269. * and ensures that all flags have been set.
  12270. * @markdown
  12271. * @private
  12272. */
  12273. init : function() {
  12274. var me = this,
  12275. doc = document,
  12276. tests = me.tests,
  12277. n = tests.length,
  12278. div = n && Ext.isReady && doc.createElement('div'),
  12279. test, notRun = [];
  12280. if (div) {
  12281. div.innerHTML = [
  12282. '<div style="height:30px;width:50px;">',
  12283. '<div style="height:20px;width:20px;"></div>',
  12284. '</div>',
  12285. '<div style="width: 200px; height: 200px; position: relative; padding: 5px;">',
  12286. '<div style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></div>',
  12287. '</div>',
  12288. '<div style="position: absolute; left: 10%; top: 10%;"></div>',
  12289. '<div style="float:left; background-color:transparent;"></div>'
  12290. ].join('');
  12291. doc.body.appendChild(div);
  12292. }
  12293. while (n--) {
  12294. test = tests[n];
  12295. if (div || test.early) {
  12296. me[test.identity] = test.fn.call(me, doc, div);
  12297. } else {
  12298. notRun.push(test);
  12299. }
  12300. }
  12301. if (div) {
  12302. doc.body.removeChild(div);
  12303. }
  12304. me.tests = notRun;
  12305. },
  12306. /**
  12307. * @property PointerEvents True if document environment supports the CSS3 pointer-events style.
  12308. * @type {Boolean}
  12309. */
  12310. PointerEvents: 'pointerEvents' in document.documentElement.style,
  12311. /**
  12312. * @property CSS3BoxShadow True if document environment supports the CSS3 box-shadow style.
  12313. * @type {Boolean}
  12314. */
  12315. CSS3BoxShadow: 'boxShadow' in document.documentElement.style || 'WebkitBoxShadow' in document.documentElement.style || 'MozBoxShadow' in document.documentElement.style,
  12316. /**
  12317. * @property ClassList True if document environment supports the HTML5 classList API.
  12318. * @type {Boolean}
  12319. */
  12320. ClassList: !!document.documentElement.classList,
  12321. /**
  12322. * @property OrientationChange True if the device supports orientation change
  12323. * @type {Boolean}
  12324. */
  12325. OrientationChange: ((typeof window.orientation != 'undefined') && ('onorientationchange' in window)),
  12326. /**
  12327. * @property DeviceMotion True if the device supports device motion (acceleration and rotation rate)
  12328. * @type {Boolean}
  12329. */
  12330. DeviceMotion: ('ondevicemotion' in window),
  12331. /**
  12332. * @property Touch True if the device supports touch
  12333. * @type {Boolean}
  12334. */
  12335. // is.Desktop is needed due to the bug in Chrome 5.0.375, Safari 3.1.2
  12336. // and Safari 4.0 (they all have 'ontouchstart' in the window object).
  12337. Touch: ('ontouchstart' in window) && (!Ext.is.Desktop),
  12338. /**
  12339. * @property TimeoutActualLateness True if the browser passes the "actualLateness" parameter to
  12340. * setTimeout. See: https://developer.mozilla.org/en/DOM/window.setTimeout
  12341. * @type {Boolean}
  12342. */
  12343. TimeoutActualLateness: (function(){
  12344. setTimeout(function(){
  12345. Ext.supports.TimeoutActualLateness = arguments.length !== 0;
  12346. }, 0);
  12347. }()),
  12348. tests: [
  12349. /**
  12350. * @property Transitions True if the device supports CSS3 Transitions
  12351. * @type {Boolean}
  12352. */
  12353. {
  12354. identity: 'Transitions',
  12355. fn: function(doc, div) {
  12356. var prefix = [
  12357. 'webkit',
  12358. 'Moz',
  12359. 'o',
  12360. 'ms',
  12361. 'khtml'
  12362. ],
  12363. TE = 'TransitionEnd',
  12364. transitionEndName = [
  12365. prefix[0] + TE,
  12366. 'transitionend', //Moz bucks the prefixing convention
  12367. prefix[2] + TE,
  12368. prefix[3] + TE,
  12369. prefix[4] + TE
  12370. ],
  12371. ln = prefix.length,
  12372. i = 0,
  12373. out = false;
  12374. for (; i < ln; i++) {
  12375. if (getStyle(div, prefix[i] + "TransitionProperty")) {
  12376. Ext.supports.CSS3Prefix = prefix[i];
  12377. Ext.supports.CSS3TransitionEnd = transitionEndName[i];
  12378. out = true;
  12379. break;
  12380. }
  12381. }
  12382. return out;
  12383. }
  12384. },
  12385. /**
  12386. * @property RightMargin True if the device supports right margin.
  12387. * See https://bugs.webkit.org/show_bug.cgi?id=13343 for why this is needed.
  12388. * @type {Boolean}
  12389. */
  12390. {
  12391. identity: 'RightMargin',
  12392. fn: function(doc, div) {
  12393. var view = doc.defaultView;
  12394. return !(view && view.getComputedStyle(div.firstChild.firstChild, null).marginRight != '0px');
  12395. }
  12396. },
  12397. /**
  12398. * @property DisplayChangeInputSelectionBug True if INPUT elements lose their
  12399. * selection when their display style is changed. Essentially, if a text input
  12400. * has focus and its display style is changed, the I-beam disappears.
  12401. *
  12402. * This bug is encountered due to the work around in place for the {@link #RightMargin}
  12403. * bug. This has been observed in Safari 4.0.4 and older, and appears to be fixed
  12404. * in Safari 5. It's not clear if Safari 4.1 has the bug, but it has the same WebKit
  12405. * version number as Safari 5 (according to http://unixpapa.com/js/gecko.html).
  12406. */
  12407. {
  12408. identity: 'DisplayChangeInputSelectionBug',
  12409. early: true,
  12410. fn: function() {
  12411. var webKitVersion = Ext.webKitVersion;
  12412. // WebKit but older than Safari 5 or Chrome 6:
  12413. return 0 < webKitVersion && webKitVersion < 533;
  12414. }
  12415. },
  12416. /**
  12417. * @property DisplayChangeTextAreaSelectionBug True if TEXTAREA elements lose their
  12418. * selection when their display style is changed. Essentially, if a text area has
  12419. * focus and its display style is changed, the I-beam disappears.
  12420. *
  12421. * This bug is encountered due to the work around in place for the {@link #RightMargin}
  12422. * bug. This has been observed in Chrome 10 and Safari 5 and older, and appears to
  12423. * be fixed in Chrome 11.
  12424. */
  12425. {
  12426. identity: 'DisplayChangeTextAreaSelectionBug',
  12427. early: true,
  12428. fn: function() {
  12429. var webKitVersion = Ext.webKitVersion;
  12430. /*
  12431. Has bug w/textarea:
  12432. (Chrome) Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US)
  12433. AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.127
  12434. Safari/534.16
  12435. (Safari) Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us)
  12436. AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5
  12437. Safari/533.21.1
  12438. No bug:
  12439. (Chrome) Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7)
  12440. AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.57
  12441. Safari/534.24
  12442. */
  12443. return 0 < webKitVersion && webKitVersion < 534.24;
  12444. }
  12445. },
  12446. /**
  12447. * @property TransparentColor True if the device supports transparent color
  12448. * @type {Boolean}
  12449. */
  12450. {
  12451. identity: 'TransparentColor',
  12452. fn: function(doc, div, view) {
  12453. view = doc.defaultView;
  12454. return !(view && view.getComputedStyle(div.lastChild, null).backgroundColor != 'transparent');
  12455. }
  12456. },
  12457. /**
  12458. * @property ComputedStyle True if the browser supports document.defaultView.getComputedStyle()
  12459. * @type {Boolean}
  12460. */
  12461. {
  12462. identity: 'ComputedStyle',
  12463. fn: function(doc, div, view) {
  12464. view = doc.defaultView;
  12465. return view && view.getComputedStyle;
  12466. }
  12467. },
  12468. /**
  12469. * @property Svg True if the device supports SVG
  12470. * @type {Boolean}
  12471. */
  12472. {
  12473. identity: 'Svg',
  12474. fn: function(doc) {
  12475. return !!doc.createElementNS && !!doc.createElementNS( "http:/" + "/www.w3.org/2000/svg", "svg").createSVGRect;
  12476. }
  12477. },
  12478. /**
  12479. * @property Canvas True if the device supports Canvas
  12480. * @type {Boolean}
  12481. */
  12482. {
  12483. identity: 'Canvas',
  12484. fn: function(doc) {
  12485. return !!doc.createElement('canvas').getContext;
  12486. }
  12487. },
  12488. /**
  12489. * @property Vml True if the device supports VML
  12490. * @type {Boolean}
  12491. */
  12492. {
  12493. identity: 'Vml',
  12494. fn: function(doc) {
  12495. var d = doc.createElement("div");
  12496. d.innerHTML = "<!--[if vml]><br/><br/><![endif]-->";
  12497. return (d.childNodes.length == 2);
  12498. }
  12499. },
  12500. /**
  12501. * @property Float True if the device supports CSS float
  12502. * @type {Boolean}
  12503. */
  12504. {
  12505. identity: 'Float',
  12506. fn: function(doc, div) {
  12507. return !!div.lastChild.style.cssFloat;
  12508. }
  12509. },
  12510. /**
  12511. * @property AudioTag True if the device supports the HTML5 audio tag
  12512. * @type {Boolean}
  12513. */
  12514. {
  12515. identity: 'AudioTag',
  12516. fn: function(doc) {
  12517. return !!doc.createElement('audio').canPlayType;
  12518. }
  12519. },
  12520. /**
  12521. * @property History True if the device supports HTML5 history
  12522. * @type {Boolean}
  12523. */
  12524. {
  12525. identity: 'History',
  12526. fn: function() {
  12527. var history = window.history;
  12528. return !!(history && history.pushState);
  12529. }
  12530. },
  12531. /**
  12532. * @property CSS3DTransform True if the device supports CSS3DTransform
  12533. * @type {Boolean}
  12534. */
  12535. {
  12536. identity: 'CSS3DTransform',
  12537. fn: function() {
  12538. return (typeof WebKitCSSMatrix != 'undefined' && new WebKitCSSMatrix().hasOwnProperty('m41'));
  12539. }
  12540. },
  12541. /**
  12542. * @property CSS3LinearGradient True if the device supports CSS3 linear gradients
  12543. * @type {Boolean}
  12544. */
  12545. {
  12546. identity: 'CSS3LinearGradient',
  12547. fn: function(doc, div) {
  12548. var property = 'background-image:',
  12549. webkit = '-webkit-gradient(linear, left top, right bottom, from(black), to(white))',
  12550. w3c = 'linear-gradient(left top, black, white)',
  12551. moz = '-moz-' + w3c,
  12552. opera = '-o-' + w3c,
  12553. options = [property + webkit, property + w3c, property + moz, property + opera];
  12554. div.style.cssText = options.join(';');
  12555. return ("" + div.style.backgroundImage).indexOf('gradient') !== -1;
  12556. }
  12557. },
  12558. /**
  12559. * @property CSS3BorderRadius True if the device supports CSS3 border radius
  12560. * @type {Boolean}
  12561. */
  12562. {
  12563. identity: 'CSS3BorderRadius',
  12564. fn: function(doc, div) {
  12565. var domPrefixes = ['borderRadius', 'BorderRadius', 'MozBorderRadius', 'WebkitBorderRadius', 'OBorderRadius', 'KhtmlBorderRadius'],
  12566. pass = false,
  12567. i;
  12568. for (i = 0; i < domPrefixes.length; i++) {
  12569. if (document.body.style[domPrefixes[i]] !== undefined) {
  12570. return true;
  12571. }
  12572. }
  12573. return pass;
  12574. }
  12575. },
  12576. /**
  12577. * @property GeoLocation True if the device supports GeoLocation
  12578. * @type {Boolean}
  12579. */
  12580. {
  12581. identity: 'GeoLocation',
  12582. fn: function() {
  12583. return (typeof navigator != 'undefined' && typeof navigator.geolocation != 'undefined') || (typeof google != 'undefined' && typeof google.gears != 'undefined');
  12584. }
  12585. },
  12586. /**
  12587. * @property MouseEnterLeave True if the browser supports mouseenter and mouseleave events
  12588. * @type {Boolean}
  12589. */
  12590. {
  12591. identity: 'MouseEnterLeave',
  12592. fn: function(doc, div){
  12593. return ('onmouseenter' in div && 'onmouseleave' in div);
  12594. }
  12595. },
  12596. /**
  12597. * @property MouseWheel True if the browser supports the mousewheel event
  12598. * @type {Boolean}
  12599. */
  12600. {
  12601. identity: 'MouseWheel',
  12602. fn: function(doc, div) {
  12603. return ('onmousewheel' in div);
  12604. }
  12605. },
  12606. /**
  12607. * @property Opacity True if the browser supports normal css opacity
  12608. * @type {Boolean}
  12609. */
  12610. {
  12611. identity: 'Opacity',
  12612. fn: function(doc, div){
  12613. // Not a strict equal comparison in case opacity can be converted to a number.
  12614. if (Ext.isIE6 || Ext.isIE7 || Ext.isIE8) {
  12615. return false;
  12616. }
  12617. div.firstChild.style.cssText = 'opacity:0.73';
  12618. return div.firstChild.style.opacity == '0.73';
  12619. }
  12620. },
  12621. /**
  12622. * @property Placeholder True if the browser supports the HTML5 placeholder attribute on inputs
  12623. * @type {Boolean}
  12624. */
  12625. {
  12626. identity: 'Placeholder',
  12627. fn: function(doc) {
  12628. return 'placeholder' in doc.createElement('input');
  12629. }
  12630. },
  12631. /**
  12632. * @property Direct2DBug True if when asking for an element's dimension via offsetWidth or offsetHeight,
  12633. * getBoundingClientRect, etc. the browser returns the subpixel width rounded to the nearest pixel.
  12634. * @type {Boolean}
  12635. */
  12636. {
  12637. identity: 'Direct2DBug',
  12638. fn: function() {
  12639. return Ext.isString(document.body.style.msTransformOrigin);
  12640. }
  12641. },
  12642. /**
  12643. * @property BoundingClientRect True if the browser supports the getBoundingClientRect method on elements
  12644. * @type {Boolean}
  12645. */
  12646. {
  12647. identity: 'BoundingClientRect',
  12648. fn: function(doc, div) {
  12649. return Ext.isFunction(div.getBoundingClientRect);
  12650. }
  12651. },
  12652. {
  12653. identity: 'IncludePaddingInWidthCalculation',
  12654. fn: function(doc, div){
  12655. return div.childNodes[1].firstChild.offsetWidth == 210;
  12656. }
  12657. },
  12658. {
  12659. identity: 'IncludePaddingInHeightCalculation',
  12660. fn: function(doc, div){
  12661. return div.childNodes[1].firstChild.offsetHeight == 210;
  12662. }
  12663. },
  12664. /**
  12665. * @property ArraySort True if the Array sort native method isn't bugged.
  12666. * @type {Boolean}
  12667. */
  12668. {
  12669. identity: 'ArraySort',
  12670. fn: function() {
  12671. var a = [1,2,3,4,5].sort(function(){ return 0; });
  12672. return a[0] === 1 && a[1] === 2 && a[2] === 3 && a[3] === 4 && a[4] === 5;
  12673. }
  12674. },
  12675. /**
  12676. * @property Range True if browser support document.createRange native method.
  12677. * @type {Boolean}
  12678. */
  12679. {
  12680. identity: 'Range',
  12681. fn: function() {
  12682. return !!document.createRange;
  12683. }
  12684. },
  12685. /**
  12686. * @property CreateContextualFragment True if browser support CreateContextualFragment range native methods.
  12687. * @type {Boolean}
  12688. */
  12689. {
  12690. identity: 'CreateContextualFragment',
  12691. fn: function() {
  12692. var range = Ext.supports.Range ? document.createRange() : false;
  12693. return range && !!range.createContextualFragment;
  12694. }
  12695. },
  12696. /**
  12697. * @property WindowOnError True if browser supports window.onerror.
  12698. * @type {Boolean}
  12699. */
  12700. {
  12701. identity: 'WindowOnError',
  12702. fn: function () {
  12703. // sadly, we cannot feature detect this...
  12704. return Ext.isIE || Ext.isGecko || Ext.webKitVersion >= 534.16; // Chrome 10+
  12705. }
  12706. },
  12707. /**
  12708. * @property TextAreaMaxLength True if the browser supports maxlength on textareas.
  12709. * @type {Boolean}
  12710. */
  12711. {
  12712. identity: 'TextAreaMaxLength',
  12713. fn: function(){
  12714. var el = document.createElement('textarea');
  12715. return ('maxlength' in el);
  12716. }
  12717. },
  12718. /**
  12719. * @property GetPositionPercentage True if the browser will return the left/top/right/bottom
  12720. * position as a percentage when explicitly set as a percentage value.
  12721. * @type {Boolean}
  12722. */
  12723. // Related bug: https://bugzilla.mozilla.org/show_bug.cgi?id=707691#c7
  12724. {
  12725. identity: 'GetPositionPercentage',
  12726. fn: function(doc, div){
  12727. return getStyle(div.childNodes[2], 'left') == '10%';
  12728. }
  12729. }
  12730. ]
  12731. };
  12732. }());
  12733. Ext.supports.init(); // run the "early" detections now
  12734. //@tag dom,core
  12735. //@require ../Support.js
  12736. //@define Ext.util.DelayedTask
  12737. /**
  12738. * @class Ext.util.DelayedTask
  12739. *
  12740. * The DelayedTask class provides a convenient way to "buffer" the execution of a method,
  12741. * performing setTimeout where a new timeout cancels the old timeout. When called, the
  12742. * task will wait the specified time period before executing. If durng that time period,
  12743. * the task is called again, the original call will be cancelled. This continues so that
  12744. * the function is only called a single time for each iteration.
  12745. *
  12746. * This method is especially useful for things like detecting whether a user has finished
  12747. * typing in a text field. An example would be performing validation on a keypress. You can
  12748. * use this class to buffer the keypress events for a certain number of milliseconds, and
  12749. * perform only if they stop for that amount of time.
  12750. *
  12751. * ## Usage
  12752. *
  12753. * var task = new Ext.util.DelayedTask(function(){
  12754. * alert(Ext.getDom('myInputField').value.length);
  12755. * });
  12756. *
  12757. * // Wait 500ms before calling our function. If the user presses another key
  12758. * // during that 500ms, it will be cancelled and we'll wait another 500ms.
  12759. * Ext.get('myInputField').on('keypress', function(){
  12760. * task.{@link #delay}(500);
  12761. * });
  12762. *
  12763. * Note that we are using a DelayedTask here to illustrate a point. The configuration
  12764. * option `buffer` for {@link Ext.util.Observable#addListener addListener/on} will
  12765. * also setup a delayed task for you to buffer events.
  12766. *
  12767. * @constructor The parameters to this constructor serve as defaults and are not required.
  12768. * @param {Function} fn (optional) The default function to call. If not specified here, it must be specified during the {@link #delay} call.
  12769. * @param {Object} scope (optional) The default scope (The <code><b>this</b></code> reference) in which the
  12770. * function is called. If not specified, <code>this</code> will refer to the browser window.
  12771. * @param {Array} args (optional) The default Array of arguments.
  12772. */
  12773. Ext.util.DelayedTask = function(fn, scope, args) {
  12774. var me = this,
  12775. id,
  12776. call = function() {
  12777. clearInterval(id);
  12778. id = null;
  12779. fn.apply(scope, args || []);
  12780. };
  12781. /**
  12782. * Cancels any pending timeout and queues a new one
  12783. * @param {Number} delay The milliseconds to delay
  12784. * @param {Function} newFn (optional) Overrides function passed to constructor
  12785. * @param {Object} newScope (optional) Overrides scope passed to constructor. Remember that if no scope
  12786. * is specified, <code>this</code> will refer to the browser window.
  12787. * @param {Array} newArgs (optional) Overrides args passed to constructor
  12788. */
  12789. this.delay = function(delay, newFn, newScope, newArgs) {
  12790. me.cancel();
  12791. fn = newFn || fn;
  12792. scope = newScope || scope;
  12793. args = newArgs || args;
  12794. id = setInterval(call, delay);
  12795. };
  12796. /**
  12797. * Cancel the last queued timeout
  12798. */
  12799. this.cancel = function(){
  12800. if (id) {
  12801. clearInterval(id);
  12802. id = null;
  12803. }
  12804. };
  12805. };
  12806. //@tag dom,core
  12807. //@define Ext.util.Event
  12808. //@require Ext.util.DelayedTask
  12809. Ext.require('Ext.util.DelayedTask', function() {
  12810. /**
  12811. * Represents single event type that an Observable object listens to.
  12812. * All actual listeners are tracked inside here. When the event fires,
  12813. * it calls all the registered listener functions.
  12814. *
  12815. * @private
  12816. */
  12817. Ext.util.Event = Ext.extend(Object, (function() {
  12818. var noOptions = {};
  12819. function createTargeted(handler, listener, o, scope){
  12820. return function(){
  12821. if (o.target === arguments[0]){
  12822. handler.apply(scope, arguments);
  12823. }
  12824. };
  12825. }
  12826. function createBuffered(handler, listener, o, scope) {
  12827. listener.task = new Ext.util.DelayedTask();
  12828. return function() {
  12829. listener.task.delay(o.buffer, handler, scope, Ext.Array.toArray(arguments));
  12830. };
  12831. }
  12832. function createDelayed(handler, listener, o, scope) {
  12833. return function() {
  12834. var task = new Ext.util.DelayedTask();
  12835. if (!listener.tasks) {
  12836. listener.tasks = [];
  12837. }
  12838. listener.tasks.push(task);
  12839. task.delay(o.delay || 10, handler, scope, Ext.Array.toArray(arguments));
  12840. };
  12841. }
  12842. function createSingle(handler, listener, o, scope) {
  12843. return function() {
  12844. var event = listener.ev;
  12845. if (event.removeListener(listener.fn, scope) && event.observable) {
  12846. // Removing from a regular Observable-owned, named event (not an anonymous
  12847. // event such as Ext's readyEvent): Decrement the listeners count
  12848. event.observable.hasListeners[event.name]--;
  12849. }
  12850. return handler.apply(scope, arguments);
  12851. };
  12852. }
  12853. return {
  12854. /**
  12855. * @property {Boolean} isEvent
  12856. * `true` in this class to identify an object as an instantiated Event, or subclass thereof.
  12857. */
  12858. isEvent: true,
  12859. constructor: function(observable, name) {
  12860. this.name = name;
  12861. this.observable = observable;
  12862. this.listeners = [];
  12863. },
  12864. addListener: function(fn, scope, options) {
  12865. var me = this,
  12866. listener;
  12867. scope = scope || me.observable;
  12868. if (!fn) {
  12869. Ext.Error.raise({
  12870. sourceClass: Ext.getClassName(this.observable),
  12871. sourceMethod: "addListener",
  12872. msg: "The specified callback function is undefined"
  12873. });
  12874. }
  12875. if (!me.isListening(fn, scope)) {
  12876. listener = me.createListener(fn, scope, options);
  12877. if (me.firing) {
  12878. // if we are currently firing this event, don't disturb the listener loop
  12879. me.listeners = me.listeners.slice(0);
  12880. }
  12881. me.listeners.push(listener);
  12882. }
  12883. },
  12884. createListener: function(fn, scope, options) {
  12885. options = options || noOptions;
  12886. scope = scope || this.observable;
  12887. var listener = {
  12888. fn: fn,
  12889. scope: scope,
  12890. o: options,
  12891. ev: this
  12892. },
  12893. handler = fn;
  12894. // The order is important. The 'single' wrapper must be wrapped by the 'buffer' and 'delayed' wrapper
  12895. // because the event removal that the single listener does destroys the listener's DelayedTask(s)
  12896. if (options.single) {
  12897. handler = createSingle(handler, listener, options, scope);
  12898. }
  12899. if (options.target) {
  12900. handler = createTargeted(handler, listener, options, scope);
  12901. }
  12902. if (options.delay) {
  12903. handler = createDelayed(handler, listener, options, scope);
  12904. }
  12905. if (options.buffer) {
  12906. handler = createBuffered(handler, listener, options, scope);
  12907. }
  12908. listener.fireFn = handler;
  12909. return listener;
  12910. },
  12911. findListener: function(fn, scope) {
  12912. var listeners = this.listeners,
  12913. i = listeners.length,
  12914. listener,
  12915. s;
  12916. while (i--) {
  12917. listener = listeners[i];
  12918. if (listener) {
  12919. s = listener.scope;
  12920. // Compare the listener's scope with *JUST THE PASSED SCOPE* if one is passed, and only fall back to the owning Observable if none is passed.
  12921. // We cannot use the test (s == scope || s == this.observable)
  12922. // Otherwise, if the Observable itself adds Ext.emptyFn as a listener, and then Ext.emptyFn is added under another scope, there will be a false match.
  12923. if (listener.fn == fn && (s == (scope || this.observable))) {
  12924. return i;
  12925. }
  12926. }
  12927. }
  12928. return - 1;
  12929. },
  12930. isListening: function(fn, scope) {
  12931. return this.findListener(fn, scope) !== -1;
  12932. },
  12933. removeListener: function(fn, scope) {
  12934. var me = this,
  12935. index,
  12936. listener,
  12937. k;
  12938. index = me.findListener(fn, scope);
  12939. if (index != -1) {
  12940. listener = me.listeners[index];
  12941. if (me.firing) {
  12942. me.listeners = me.listeners.slice(0);
  12943. }
  12944. // cancel and remove a buffered handler that hasn't fired yet
  12945. if (listener.task) {
  12946. listener.task.cancel();
  12947. delete listener.task;
  12948. }
  12949. // cancel and remove all delayed handlers that haven't fired yet
  12950. k = listener.tasks && listener.tasks.length;
  12951. if (k) {
  12952. while (k--) {
  12953. listener.tasks[k].cancel();
  12954. }
  12955. delete listener.tasks;
  12956. }
  12957. // remove this listener from the listeners array
  12958. Ext.Array.erase(me.listeners, index, 1);
  12959. return true;
  12960. }
  12961. return false;
  12962. },
  12963. // Iterate to stop any buffered/delayed events
  12964. clearListeners: function() {
  12965. var listeners = this.listeners,
  12966. i = listeners.length;
  12967. while (i--) {
  12968. this.removeListener(listeners[i].fn, listeners[i].scope);
  12969. }
  12970. },
  12971. fire: function() {
  12972. var me = this,
  12973. listeners = me.listeners,
  12974. count = listeners.length,
  12975. i,
  12976. args,
  12977. listener;
  12978. if (count > 0) {
  12979. me.firing = true;
  12980. for (i = 0; i < count; i++) {
  12981. listener = listeners[i];
  12982. args = arguments.length ? Array.prototype.slice.call(arguments, 0) : [];
  12983. if (listener.o) {
  12984. args.push(listener.o);
  12985. }
  12986. if (listener && listener.fireFn.apply(listener.scope || me.observable, args) === false) {
  12987. return (me.firing = false);
  12988. }
  12989. }
  12990. }
  12991. me.firing = false;
  12992. return true;
  12993. }
  12994. };
  12995. }()));
  12996. });
  12997. //@tag dom,core
  12998. //@require util/Event.js
  12999. //@define Ext.EventManager
  13000. /**
  13001. * @class Ext.EventManager
  13002. * Registers event handlers that want to receive a normalized EventObject instead of the standard browser event and provides
  13003. * several useful events directly.
  13004. * See {@link Ext.EventObject} for more details on normalized event objects.
  13005. * @singleton
  13006. */
  13007. Ext.EventManager = new function() {
  13008. var EventManager = this,
  13009. doc = document,
  13010. win = window,
  13011. initExtCss = function() {
  13012. // find the body element
  13013. var bd = doc.body || doc.getElementsByTagName('body')[0],
  13014. baseCSSPrefix = Ext.baseCSSPrefix,
  13015. cls = [baseCSSPrefix + 'body'],
  13016. htmlCls = [],
  13017. supportsLG = Ext.supports.CSS3LinearGradient,
  13018. supportsBR = Ext.supports.CSS3BorderRadius,
  13019. resetCls = [],
  13020. html,
  13021. resetElementSpec;
  13022. if (!bd) {
  13023. return false;
  13024. }
  13025. html = bd.parentNode;
  13026. function add (c) {
  13027. cls.push(baseCSSPrefix + c);
  13028. }
  13029. //Let's keep this human readable!
  13030. if (Ext.isIE) {
  13031. add('ie');
  13032. // very often CSS needs to do checks like "IE7+" or "IE6 or 7". To help
  13033. // reduce the clutter (since CSS/SCSS cannot do these tests), we add some
  13034. // additional classes:
  13035. //
  13036. // x-ie7p : IE7+ : 7 <= ieVer
  13037. // x-ie7m : IE7- : ieVer <= 7
  13038. // x-ie8p : IE8+ : 8 <= ieVer
  13039. // x-ie8m : IE8- : ieVer <= 8
  13040. // x-ie9p : IE9+ : 9 <= ieVer
  13041. // x-ie78 : IE7 or 8 : 7 <= ieVer <= 8
  13042. //
  13043. if (Ext.isIE6) {
  13044. add('ie6');
  13045. } else { // ignore pre-IE6 :)
  13046. add('ie7p');
  13047. if (Ext.isIE7) {
  13048. add('ie7');
  13049. } else {
  13050. add('ie8p');
  13051. if (Ext.isIE8) {
  13052. add('ie8');
  13053. } else {
  13054. add('ie9p');
  13055. if (Ext.isIE9) {
  13056. add('ie9');
  13057. }
  13058. }
  13059. }
  13060. }
  13061. if (Ext.isIE6 || Ext.isIE7) {
  13062. add('ie7m');
  13063. }
  13064. if (Ext.isIE6 || Ext.isIE7 || Ext.isIE8) {
  13065. add('ie8m');
  13066. }
  13067. if (Ext.isIE7 || Ext.isIE8) {
  13068. add('ie78');
  13069. }
  13070. }
  13071. if (Ext.isGecko) {
  13072. add('gecko');
  13073. if (Ext.isGecko3) {
  13074. add('gecko3');
  13075. }
  13076. if (Ext.isGecko4) {
  13077. add('gecko4');
  13078. }
  13079. if (Ext.isGecko5) {
  13080. add('gecko5');
  13081. }
  13082. }
  13083. if (Ext.isOpera) {
  13084. add('opera');
  13085. }
  13086. if (Ext.isWebKit) {
  13087. add('webkit');
  13088. }
  13089. if (Ext.isSafari) {
  13090. add('safari');
  13091. if (Ext.isSafari2) {
  13092. add('safari2');
  13093. }
  13094. if (Ext.isSafari3) {
  13095. add('safari3');
  13096. }
  13097. if (Ext.isSafari4) {
  13098. add('safari4');
  13099. }
  13100. if (Ext.isSafari5) {
  13101. add('safari5');
  13102. }
  13103. if (Ext.isSafari5_0) {
  13104. add('safari5_0')
  13105. }
  13106. }
  13107. if (Ext.isChrome) {
  13108. add('chrome');
  13109. }
  13110. if (Ext.isMac) {
  13111. add('mac');
  13112. }
  13113. if (Ext.isLinux) {
  13114. add('linux');
  13115. }
  13116. if (!supportsBR) {
  13117. add('nbr');
  13118. }
  13119. if (!supportsLG) {
  13120. add('nlg');
  13121. }
  13122. // If we are not globally resetting scope, but just resetting it in a wrapper around
  13123. // serarately rendered widgets, then create a common reset element for use when creating
  13124. // measurable elements. Using a common DomHelper spec.
  13125. if (Ext.scopeResetCSS) {
  13126. // Create Ext.resetElementSpec for use in Renderable when wrapping top level Components.
  13127. resetElementSpec = Ext.resetElementSpec = {
  13128. cls: baseCSSPrefix + 'reset'
  13129. };
  13130. if (!supportsLG) {
  13131. resetCls.push(baseCSSPrefix + 'nlg');
  13132. }
  13133. if (!supportsBR) {
  13134. resetCls.push(baseCSSPrefix + 'nbr');
  13135. }
  13136. if (resetCls.length) {
  13137. resetElementSpec.cn = {
  13138. cls: resetCls.join(' ')
  13139. };
  13140. }
  13141. Ext.resetElement = Ext.getBody().createChild(resetElementSpec);
  13142. if (resetCls.length) {
  13143. Ext.resetElement = Ext.get(Ext.resetElement.dom.firstChild);
  13144. }
  13145. }
  13146. // Otherwise, the common reset element is the document body
  13147. else {
  13148. Ext.resetElement = Ext.getBody();
  13149. add('reset');
  13150. }
  13151. // add to the parent to allow for selectors x-strict x-border-box, also set the isBorderBox property correctly
  13152. if (html) {
  13153. if (Ext.isStrict && (Ext.isIE6 || Ext.isIE7)) {
  13154. Ext.isBorderBox = false;
  13155. }
  13156. else {
  13157. Ext.isBorderBox = true;
  13158. }
  13159. if(Ext.isBorderBox) {
  13160. htmlCls.push(baseCSSPrefix + 'border-box');
  13161. }
  13162. if (Ext.isStrict) {
  13163. htmlCls.push(baseCSSPrefix + 'strict');
  13164. } else {
  13165. htmlCls.push(baseCSSPrefix + 'quirks');
  13166. }
  13167. Ext.fly(html, '_internal').addCls(htmlCls);
  13168. }
  13169. Ext.fly(bd, '_internal').addCls(cls);
  13170. return true;
  13171. };
  13172. Ext.apply(EventManager, {
  13173. /**
  13174. * Check if we have bound our global onReady listener
  13175. * @private
  13176. */
  13177. hasBoundOnReady: false,
  13178. /**
  13179. * Check if fireDocReady has been called
  13180. * @private
  13181. */
  13182. hasFiredReady: false,
  13183. /**
  13184. * Additionally, allow the 'DOM' listener thread to complete (usually desirable with mobWebkit, Gecko)
  13185. * before firing the entire onReady chain (high stack load on Loader) by specifying a delay value
  13186. * @default 1ms
  13187. * @private
  13188. */
  13189. deferReadyEvent : 1,
  13190. /*
  13191. * diags: a list of event names passed to onReadyEvent (in chron order)
  13192. * @private
  13193. */
  13194. onReadyChain : [],
  13195. /**
  13196. * Holds references to any onReady functions
  13197. * @private
  13198. */
  13199. readyEvent:
  13200. (function () {
  13201. var event = new Ext.util.Event();
  13202. event.fire = function () {
  13203. Ext._beforeReadyTime = Ext._beforeReadyTime || new Date().getTime();
  13204. event.self.prototype.fire.apply(event, arguments);
  13205. Ext._afterReadytime = new Date().getTime();
  13206. };
  13207. return event;
  13208. }()),
  13209. /**
  13210. * Fires when a DOM event handler finishes its run, just before returning to browser control.
  13211. * This can be useful for performing cleanup, or upfdate tasks which need to happen only
  13212. * after all code in an event handler has been run, but which should not be executed in a timer
  13213. * due to the intervening browser reflow/repaint which would take place.
  13214. *
  13215. */
  13216. idleEvent: new Ext.util.Event(),
  13217. /**
  13218. * detects whether the EventManager has been placed in a paused state for synchronization
  13219. * with external debugging / perf tools (PageAnalyzer)
  13220. * @private
  13221. */
  13222. isReadyPaused: function(){
  13223. return (/[?&]ext-pauseReadyFire\b/i.test(location.search) && !Ext._continueFireReady);
  13224. },
  13225. /**
  13226. * Binds the appropriate browser event for checking if the DOM has loaded.
  13227. * @private
  13228. */
  13229. bindReadyEvent: function() {
  13230. if (EventManager.hasBoundOnReady) {
  13231. return;
  13232. }
  13233. // Test scenario where Core is dynamically loaded AFTER window.load
  13234. if ( doc.readyState == 'complete' ) { // Firefox4+ got support for this state, others already do.
  13235. EventManager.onReadyEvent({
  13236. type: doc.readyState || 'body'
  13237. });
  13238. } else {
  13239. document.addEventListener('DOMContentLoaded', EventManager.onReadyEvent, false);
  13240. window.addEventListener('load', EventManager.onReadyEvent, false);
  13241. EventManager.hasBoundOnReady = true;
  13242. }
  13243. },
  13244. onReadyEvent : function(e) {
  13245. if (e && e.type) {
  13246. EventManager.onReadyChain.push(e.type);
  13247. }
  13248. if (EventManager.hasBoundOnReady) {
  13249. document.removeEventListener('DOMContentLoaded', EventManager.onReadyEvent, false);
  13250. window.removeEventListener('load', EventManager.onReadyEvent, false);
  13251. }
  13252. if (!Ext.isReady) {
  13253. EventManager.fireDocReady();
  13254. }
  13255. },
  13256. /**
  13257. * We know the document is loaded, so trigger any onReady events.
  13258. * @private
  13259. */
  13260. fireDocReady: function() {
  13261. if (!Ext.isReady) {
  13262. Ext._readyTime = new Date().getTime();
  13263. Ext.isReady = true;
  13264. Ext.supports.init();
  13265. EventManager.onWindowUnload();
  13266. EventManager.readyEvent.onReadyChain = EventManager.onReadyChain; //diags report
  13267. if (Ext.isNumber(EventManager.deferReadyEvent)) {
  13268. Ext.Function.defer(EventManager.fireReadyEvent, EventManager.deferReadyEvent);
  13269. EventManager.hasDocReadyTimer = true;
  13270. } else {
  13271. EventManager.fireReadyEvent();
  13272. }
  13273. }
  13274. },
  13275. /**
  13276. * Fires the ready event
  13277. * @private
  13278. */
  13279. fireReadyEvent: function(){
  13280. var readyEvent = EventManager.readyEvent;
  13281. // Unset the timer flag here since other onReady events may be
  13282. // added during the fire() call and we don't want to block them
  13283. EventManager.hasDocReadyTimer = false;
  13284. EventManager.isFiring = true;
  13285. // Ready events are all single: true, if we get to the end
  13286. // & there are more listeners, it means they were added
  13287. // inside some other ready event
  13288. while (readyEvent.listeners.length && !EventManager.isReadyPaused()) {
  13289. readyEvent.fire();
  13290. }
  13291. EventManager.isFiring = false;
  13292. EventManager.hasFiredReady = true;
  13293. },
  13294. /**
  13295. * Adds a listener to be notified when the document is ready (before onload and before images are loaded).
  13296. *
  13297. * @param {Function} fn The method the event invokes.
  13298. * @param {Object} [scope] The scope (`this` reference) in which the handler function executes.
  13299. * Defaults to the browser window.
  13300. * @param {Object} [options] Options object as passed to {@link Ext.Element#addListener}.
  13301. */
  13302. onDocumentReady: function(fn, scope, options) {
  13303. options = options || {};
  13304. // force single, only ever fire it once
  13305. options.single = true;
  13306. EventManager.readyEvent.addListener(fn, scope, options);
  13307. // If we're in the middle of firing, or we have a deferred timer
  13308. // pending, drop out since the event will be fired later
  13309. if (!(EventManager.isFiring || EventManager.hasDocReadyTimer)) {
  13310. if (Ext.isReady) {
  13311. EventManager.fireReadyEvent();
  13312. } else {
  13313. EventManager.bindReadyEvent();
  13314. }
  13315. }
  13316. },
  13317. // --------------------- event binding ---------------------
  13318. /**
  13319. * Contains a list of all document mouse downs, so we can ensure they fire even when stopEvent is called.
  13320. * @private
  13321. */
  13322. stoppedMouseDownEvent: new Ext.util.Event(),
  13323. /**
  13324. * Options to parse for the 4th argument to addListener.
  13325. * @private
  13326. */
  13327. propRe: /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate|freezeEvent)$/,
  13328. /**
  13329. * Get the id of the element. If one has not been assigned, automatically assign it.
  13330. * @param {HTMLElement/Ext.Element} element The element to get the id for.
  13331. * @return {String} id
  13332. */
  13333. getId : function(element) {
  13334. var id;
  13335. element = Ext.getDom(element);
  13336. if (element === doc || element === win) {
  13337. id = element === doc ? Ext.documentId : Ext.windowId;
  13338. }
  13339. else {
  13340. id = Ext.id(element);
  13341. }
  13342. if (!Ext.cache[id]) {
  13343. Ext.addCacheEntry(id, null, element);
  13344. }
  13345. return id;
  13346. },
  13347. /**
  13348. * Convert a "config style" listener into a set of flat arguments so they can be passed to addListener
  13349. * @private
  13350. * @param {Object} element The element the event is for
  13351. * @param {Object} event The event configuration
  13352. * @param {Object} isRemove True if a removal should be performed, otherwise an add will be done.
  13353. */
  13354. prepareListenerConfig: function(element, config, isRemove) {
  13355. var propRe = EventManager.propRe,
  13356. key, value, args;
  13357. // loop over all the keys in the object
  13358. for (key in config) {
  13359. if (config.hasOwnProperty(key)) {
  13360. // if the key is something else then an event option
  13361. if (!propRe.test(key)) {
  13362. value = config[key];
  13363. // if the value is a function it must be something like click: function() {}, scope: this
  13364. // which means that there might be multiple event listeners with shared options
  13365. if (typeof value == 'function') {
  13366. // shared options
  13367. args = [element, key, value, config.scope, config];
  13368. } else {
  13369. // if its not a function, it must be an object like click: {fn: function() {}, scope: this}
  13370. args = [element, key, value.fn, value.scope, value];
  13371. }
  13372. if (isRemove) {
  13373. EventManager.removeListener.apply(EventManager, args);
  13374. } else {
  13375. EventManager.addListener.apply(EventManager, args);
  13376. }
  13377. }
  13378. }
  13379. }
  13380. },
  13381. mouseEnterLeaveRe: /mouseenter|mouseleave/,
  13382. /**
  13383. * Normalize cross browser event differences
  13384. * @private
  13385. * @param {Object} eventName The event name
  13386. * @param {Object} fn The function to execute
  13387. * @return {Object} The new event name/function
  13388. */
  13389. normalizeEvent: function(eventName, fn) {
  13390. if (EventManager.mouseEnterLeaveRe.test(eventName) && !Ext.supports.MouseEnterLeave) {
  13391. if (fn) {
  13392. fn = Ext.Function.createInterceptor(fn, EventManager.contains);
  13393. }
  13394. eventName = eventName == 'mouseenter' ? 'mouseover' : 'mouseout';
  13395. } else if (eventName == 'mousewheel' && !Ext.supports.MouseWheel && !Ext.isOpera) {
  13396. eventName = 'DOMMouseScroll';
  13397. }
  13398. return {
  13399. eventName: eventName,
  13400. fn: fn
  13401. };
  13402. },
  13403. /**
  13404. * Checks whether the event's relatedTarget is contained inside (or <b>is</b>) the element.
  13405. * @private
  13406. * @param {Object} event
  13407. */
  13408. contains: function(event) {
  13409. var parent = event.browserEvent.currentTarget,
  13410. child = EventManager.getRelatedTarget(event);
  13411. if (parent && parent.firstChild) {
  13412. while (child) {
  13413. if (child === parent) {
  13414. return false;
  13415. }
  13416. child = child.parentNode;
  13417. if (child && (child.nodeType != 1)) {
  13418. child = null;
  13419. }
  13420. }
  13421. }
  13422. return true;
  13423. },
  13424. /**
  13425. * Appends an event handler to an element. The shorthand version {@link #on} is equivalent. Typically you will
  13426. * use {@link Ext.Element#addListener} directly on an Element in favor of calling this version.
  13427. * @param {String/HTMLElement} el The html element or id to assign the event handler to.
  13428. * @param {String} eventName The name of the event to listen for.
  13429. * @param {Function} handler The handler function the event invokes. This function is passed
  13430. * the following parameters:<ul>
  13431. * <li>evt : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li>
  13432. * <li>t : Element<div class="sub-desc">The {@link Ext.Element Element} which was the target of the event.
  13433. * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li>
  13434. * <li>o : Object<div class="sub-desc">The options object from the addListener call.</div></li>
  13435. * </ul>
  13436. * @param {Object} scope (optional) The scope (<b><code>this</code></b> reference) in which the handler function is executed. <b>Defaults to the Element</b>.
  13437. * @param {Object} options (optional) An object containing handler configuration properties.
  13438. * This may contain any of the following properties:<ul>
  13439. * <li>scope : Object<div class="sub-desc">The scope (<b><code>this</code></b> reference) in which the handler function is executed. <b>Defaults to the Element</b>.</div></li>
  13440. * <li>delegate : String<div class="sub-desc">A simple selector to filter the target or look for a descendant of the target</div></li>
  13441. * <li>stopEvent : Boolean<div class="sub-desc">True to stop the event. That is stop propagation, and prevent the default action.</div></li>
  13442. * <li>preventDefault : Boolean<div class="sub-desc">True to prevent the default action</div></li>
  13443. * <li>stopPropagation : Boolean<div class="sub-desc">True to prevent event propagation</div></li>
  13444. * <li>normalized : Boolean<div class="sub-desc">False to pass a browser event to the handler function instead of an Ext.EventObject</div></li>
  13445. * <li>delay : Number<div class="sub-desc">The number of milliseconds to delay the invocation of the handler after te event fires.</div></li>
  13446. * <li>single : Boolean<div class="sub-desc">True to add a handler to handle just the next firing of the event, and then remove itself.</div></li>
  13447. * <li>buffer : Number<div class="sub-desc">Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
  13448. * by the specified number of milliseconds. If the event fires again within that time, the original
  13449. * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li>
  13450. * <li>target : Element<div class="sub-desc">Only call the handler if the event was fired on the target Element, <i>not</i> if the event was bubbled up from a child node.</div></li>
  13451. * </ul><br>
  13452. * <p>See {@link Ext.Element#addListener} for examples of how to use these options.</p>
  13453. */
  13454. addListener: function(element, eventName, fn, scope, options) {
  13455. // Check if we've been passed a "config style" event.
  13456. if (typeof eventName !== 'string') {
  13457. EventManager.prepareListenerConfig(element, eventName);
  13458. return;
  13459. }
  13460. var dom = element.dom || Ext.getDom(element),
  13461. bind, wrap;
  13462. if (!fn) {
  13463. Ext.Error.raise({
  13464. sourceClass: 'Ext.EventManager',
  13465. sourceMethod: 'addListener',
  13466. targetElement: element,
  13467. eventName: eventName,
  13468. msg: 'Error adding "' + eventName + '\" listener. The handler function is undefined.'
  13469. });
  13470. }
  13471. // create the wrapper function
  13472. options = options || {};
  13473. bind = EventManager.normalizeEvent(eventName, fn);
  13474. wrap = EventManager.createListenerWrap(dom, eventName, bind.fn, scope, options);
  13475. if (dom.attachEvent) {
  13476. dom.attachEvent('on' + bind.eventName, wrap);
  13477. } else {
  13478. dom.addEventListener(bind.eventName, wrap, options.capture || false);
  13479. }
  13480. if (dom == doc && eventName == 'mousedown') {
  13481. EventManager.stoppedMouseDownEvent.addListener(wrap);
  13482. }
  13483. // add all required data into the event cache
  13484. EventManager.getEventListenerCache(element.dom ? element : dom, eventName).push({
  13485. fn: fn,
  13486. wrap: wrap,
  13487. scope: scope
  13488. });
  13489. },
  13490. /**
  13491. * Removes an event handler from an element. The shorthand version {@link #un} is equivalent. Typically
  13492. * you will use {@link Ext.Element#removeListener} directly on an Element in favor of calling this version.
  13493. * @param {String/HTMLElement} el The id or html element from which to remove the listener.
  13494. * @param {String} eventName The name of the event.
  13495. * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
  13496. * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
  13497. * then this must refer to the same object.
  13498. */
  13499. removeListener : function(element, eventName, fn, scope) {
  13500. // handle our listener config object syntax
  13501. if (typeof eventName !== 'string') {
  13502. EventManager.prepareListenerConfig(element, eventName, true);
  13503. return;
  13504. }
  13505. var dom = Ext.getDom(element),
  13506. el = element.dom ? element : Ext.get(dom),
  13507. cache = EventManager.getEventListenerCache(el, eventName),
  13508. bindName = EventManager.normalizeEvent(eventName).eventName,
  13509. i = cache.length, j,
  13510. listener, wrap, tasks;
  13511. while (i--) {
  13512. listener = cache[i];
  13513. if (listener && (!fn || listener.fn == fn) && (!scope || listener.scope === scope)) {
  13514. wrap = listener.wrap;
  13515. // clear buffered calls
  13516. if (wrap.task) {
  13517. clearTimeout(wrap.task);
  13518. delete wrap.task;
  13519. }
  13520. // clear delayed calls
  13521. j = wrap.tasks && wrap.tasks.length;
  13522. if (j) {
  13523. while (j--) {
  13524. clearTimeout(wrap.tasks[j]);
  13525. }
  13526. delete wrap.tasks;
  13527. }
  13528. if (dom.detachEvent) {
  13529. dom.detachEvent('on' + bindName, wrap);
  13530. } else {
  13531. dom.removeEventListener(bindName, wrap, false);
  13532. }
  13533. if (wrap && dom == doc && eventName == 'mousedown') {
  13534. EventManager.stoppedMouseDownEvent.removeListener(wrap);
  13535. }
  13536. // remove listener from cache
  13537. Ext.Array.erase(cache, i, 1);
  13538. }
  13539. }
  13540. },
  13541. /**
  13542. * Removes all event handers from an element. Typically you will use {@link Ext.Element#removeAllListeners}
  13543. * directly on an Element in favor of calling this version.
  13544. * @param {String/HTMLElement} el The id or html element from which to remove all event handlers.
  13545. */
  13546. removeAll : function(element) {
  13547. var el = element.dom ? element : Ext.get(element),
  13548. cache, events, eventName;
  13549. if (!el) {
  13550. return;
  13551. }
  13552. cache = (el.$cache || el.getCache());
  13553. events = cache.events;
  13554. for (eventName in events) {
  13555. if (events.hasOwnProperty(eventName)) {
  13556. EventManager.removeListener(el, eventName);
  13557. }
  13558. }
  13559. cache.events = {};
  13560. },
  13561. /**
  13562. * Recursively removes all previous added listeners from an element and its children. Typically you will use {@link Ext.Element#purgeAllListeners}
  13563. * directly on an Element in favor of calling this version.
  13564. * @param {String/HTMLElement} el The id or html element from which to remove all event handlers.
  13565. * @param {String} eventName (optional) The name of the event.
  13566. */
  13567. purgeElement : function(element, eventName) {
  13568. var dom = Ext.getDom(element),
  13569. i = 0, len;
  13570. if (eventName) {
  13571. EventManager.removeListener(element, eventName);
  13572. }
  13573. else {
  13574. EventManager.removeAll(element);
  13575. }
  13576. if (dom && dom.childNodes) {
  13577. for (len = element.childNodes.length; i < len; i++) {
  13578. EventManager.purgeElement(element.childNodes[i], eventName);
  13579. }
  13580. }
  13581. },
  13582. /**
  13583. * Create the wrapper function for the event
  13584. * @private
  13585. * @param {HTMLElement} dom The dom element
  13586. * @param {String} ename The event name
  13587. * @param {Function} fn The function to execute
  13588. * @param {Object} scope The scope to execute callback in
  13589. * @param {Object} options The options
  13590. * @return {Function} the wrapper function
  13591. */
  13592. createListenerWrap : function(dom, ename, fn, scope, options) {
  13593. options = options || {};
  13594. var f, gen, escapeRx = /\\/g, wrap = function(e, args) {
  13595. // Compile the implementation upon first firing
  13596. if (!gen) {
  13597. f = ['if(!' + Ext.name + ') {return;}'];
  13598. if(options.buffer || options.delay || options.freezeEvent) {
  13599. f.push('e = new X.EventObjectImpl(e, ' + (options.freezeEvent ? 'true' : 'false' ) + ');');
  13600. } else {
  13601. f.push('e = X.EventObject.setEvent(e);');
  13602. }
  13603. if (options.delegate) {
  13604. // double up '\' characters so escape sequences survive the
  13605. // string-literal translation
  13606. f.push('var result, t = e.getTarget("' + (options.delegate + '').replace(escapeRx, '\\\\') + '", this);');
  13607. f.push('if(!t) {return;}');
  13608. } else {
  13609. f.push('var t = e.target, result;');
  13610. }
  13611. if (options.target) {
  13612. f.push('if(e.target !== options.target) {return;}');
  13613. }
  13614. if(options.stopEvent) {
  13615. f.push('e.stopEvent();');
  13616. } else {
  13617. if(options.preventDefault) {
  13618. f.push('e.preventDefault();');
  13619. }
  13620. if(options.stopPropagation) {
  13621. f.push('e.stopPropagation();');
  13622. }
  13623. }
  13624. if(options.normalized === false) {
  13625. f.push('e = e.browserEvent;');
  13626. }
  13627. if(options.buffer) {
  13628. f.push('(wrap.task && clearTimeout(wrap.task));');
  13629. f.push('wrap.task = setTimeout(function() {');
  13630. }
  13631. if(options.delay) {
  13632. f.push('wrap.tasks = wrap.tasks || [];');
  13633. f.push('wrap.tasks.push(setTimeout(function() {');
  13634. }
  13635. // finally call the actual handler fn
  13636. f.push('result = fn.call(scope || dom, e, t, options);');
  13637. if(options.single) {
  13638. f.push('evtMgr.removeListener(dom, ename, fn, scope);');
  13639. }
  13640. // Fire the global idle event for all events except mousemove which is too common, and
  13641. // fires too frequently and fast to be use in tiggering onIdle processing.
  13642. if (ename !== 'mousemove') {
  13643. f.push('if (evtMgr.idleEvent.listeners.length) {');
  13644. f.push('evtMgr.idleEvent.fire();');
  13645. f.push('}');
  13646. }
  13647. if(options.delay) {
  13648. f.push('}, ' + options.delay + '));');
  13649. }
  13650. if(options.buffer) {
  13651. f.push('}, ' + options.buffer + ');');
  13652. }
  13653. f.push('return result;')
  13654. gen = Ext.cacheableFunctionFactory('e', 'options', 'fn', 'scope', 'ename', 'dom', 'wrap', 'args', 'X', 'evtMgr', f.join('\n'));
  13655. }
  13656. return gen.call(dom, e, options, fn, scope, ename, dom, wrap, args, Ext, EventManager);
  13657. };
  13658. return wrap;
  13659. },
  13660. /**
  13661. * Get the event cache for a particular element for a particular event
  13662. * @private
  13663. * @param {HTMLElement} element The element
  13664. * @param {Object} eventName The event name
  13665. * @return {Array} The events for the element
  13666. */
  13667. getEventListenerCache : function(element, eventName) {
  13668. var elementCache, eventCache;
  13669. if (!element) {
  13670. return [];
  13671. }
  13672. if (element.$cache) {
  13673. elementCache = element.$cache;
  13674. } else {
  13675. // getId will populate the cache for this element if it isn't already present
  13676. elementCache = Ext.cache[EventManager.getId(element)];
  13677. }
  13678. eventCache = elementCache.events || (elementCache.events = {});
  13679. return eventCache[eventName] || (eventCache[eventName] = []);
  13680. },
  13681. // --------------------- utility methods ---------------------
  13682. mouseLeaveRe: /(mouseout|mouseleave)/,
  13683. mouseEnterRe: /(mouseover|mouseenter)/,
  13684. /**
  13685. * Stop the event (preventDefault and stopPropagation)
  13686. * @param {Event} The event to stop
  13687. */
  13688. stopEvent: function(event) {
  13689. EventManager.stopPropagation(event);
  13690. EventManager.preventDefault(event);
  13691. },
  13692. /**
  13693. * Cancels bubbling of the event.
  13694. * @param {Event} The event to stop bubbling.
  13695. */
  13696. stopPropagation: function(event) {
  13697. event = event.browserEvent || event;
  13698. if (event.stopPropagation) {
  13699. event.stopPropagation();
  13700. } else {
  13701. event.cancelBubble = true;
  13702. }
  13703. },
  13704. /**
  13705. * Prevents the browsers default handling of the event.
  13706. * @param {Event} The event to prevent the default
  13707. */
  13708. preventDefault: function(event) {
  13709. event = event.browserEvent || event;
  13710. if (event.preventDefault) {
  13711. event.preventDefault();
  13712. } else {
  13713. event.returnValue = false;
  13714. // Some keys events require setting the keyCode to -1 to be prevented
  13715. try {
  13716. // all ctrl + X and F1 -> F12
  13717. if (event.ctrlKey || event.keyCode > 111 && event.keyCode < 124) {
  13718. event.keyCode = -1;
  13719. }
  13720. } catch (e) {
  13721. // see this outdated document http://support.microsoft.com/kb/934364/en-us for more info
  13722. }
  13723. }
  13724. },
  13725. /**
  13726. * Gets the related target from the event.
  13727. * @param {Object} event The event
  13728. * @return {HTMLElement} The related target.
  13729. */
  13730. getRelatedTarget: function(event) {
  13731. event = event.browserEvent || event;
  13732. var target = event.relatedTarget;
  13733. if (!target) {
  13734. if (EventManager.mouseLeaveRe.test(event.type)) {
  13735. target = event.toElement;
  13736. } else if (EventManager.mouseEnterRe.test(event.type)) {
  13737. target = event.fromElement;
  13738. }
  13739. }
  13740. return EventManager.resolveTextNode(target);
  13741. },
  13742. /**
  13743. * Gets the x coordinate from the event
  13744. * @param {Object} event The event
  13745. * @return {Number} The x coordinate
  13746. */
  13747. getPageX: function(event) {
  13748. return EventManager.getPageXY(event)[0];
  13749. },
  13750. /**
  13751. * Gets the y coordinate from the event
  13752. * @param {Object} event The event
  13753. * @return {Number} The y coordinate
  13754. */
  13755. getPageY: function(event) {
  13756. return EventManager.getPageXY(event)[1];
  13757. },
  13758. /**
  13759. * Gets the x & y coordinate from the event
  13760. * @param {Object} event The event
  13761. * @return {Number[]} The x/y coordinate
  13762. */
  13763. getPageXY: function(event) {
  13764. event = event.browserEvent || event;
  13765. var x = event.pageX,
  13766. y = event.pageY,
  13767. docEl = doc.documentElement,
  13768. body = doc.body;
  13769. // pageX/pageY not available (undefined, not null), use clientX/clientY instead
  13770. if (!x && x !== 0) {
  13771. x = event.clientX + (docEl && docEl.scrollLeft || body && body.scrollLeft || 0) - (docEl && docEl.clientLeft || body && body.clientLeft || 0);
  13772. y = event.clientY + (docEl && docEl.scrollTop || body && body.scrollTop || 0) - (docEl && docEl.clientTop || body && body.clientTop || 0);
  13773. }
  13774. return [x, y];
  13775. },
  13776. /**
  13777. * Gets the target of the event.
  13778. * @param {Object} event The event
  13779. * @return {HTMLElement} target
  13780. */
  13781. getTarget: function(event) {
  13782. event = event.browserEvent || event;
  13783. return EventManager.resolveTextNode(event.target || event.srcElement);
  13784. },
  13785. // technically no need to browser sniff this, however it makes
  13786. // no sense to check this every time, for every event, whether
  13787. // the string is equal.
  13788. /**
  13789. * Resolve any text nodes accounting for browser differences.
  13790. * @private
  13791. * @param {HTMLElement} node The node
  13792. * @return {HTMLElement} The resolved node
  13793. */
  13794. resolveTextNode: Ext.isGecko ?
  13795. function(node) {
  13796. if (!node) {
  13797. return;
  13798. }
  13799. // work around firefox bug, https://bugzilla.mozilla.org/show_bug.cgi?id=101197
  13800. var s = HTMLElement.prototype.toString.call(node);
  13801. if (s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]') {
  13802. return;
  13803. }
  13804. return node.nodeType == 3 ? node.parentNode: node;
  13805. }: function(node) {
  13806. return node && node.nodeType == 3 ? node.parentNode: node;
  13807. },
  13808. // --------------------- custom event binding ---------------------
  13809. // Keep track of the current width/height
  13810. curWidth: 0,
  13811. curHeight: 0,
  13812. /**
  13813. * Adds a listener to be notified when the browser window is resized and provides resize event buffering (100 milliseconds),
  13814. * passes new viewport width and height to handlers.
  13815. * @param {Function} fn The handler function the window resize event invokes.
  13816. * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
  13817. * @param {Boolean} options Options object as passed to {@link Ext.Element#addListener}
  13818. */
  13819. onWindowResize: function(fn, scope, options) {
  13820. var resize = EventManager.resizeEvent;
  13821. if (!resize) {
  13822. EventManager.resizeEvent = resize = new Ext.util.Event();
  13823. EventManager.on(win, 'resize', EventManager.fireResize, null, {buffer: 100});
  13824. }
  13825. resize.addListener(fn, scope, options);
  13826. },
  13827. /**
  13828. * Fire the resize event.
  13829. * @private
  13830. */
  13831. fireResize: function() {
  13832. var w = Ext.Element.getViewWidth(),
  13833. h = Ext.Element.getViewHeight();
  13834. //whacky problem in IE where the resize event will sometimes fire even though the w/h are the same.
  13835. if (EventManager.curHeight != h || EventManager.curWidth != w) {
  13836. EventManager.curHeight = h;
  13837. EventManager.curWidth = w;
  13838. EventManager.resizeEvent.fire(w, h);
  13839. }
  13840. },
  13841. /**
  13842. * Removes the passed window resize listener.
  13843. * @param {Function} fn The method the event invokes
  13844. * @param {Object} scope The scope of handler
  13845. */
  13846. removeResizeListener: function(fn, scope) {
  13847. var resize = EventManager.resizeEvent;
  13848. if (resize) {
  13849. resize.removeListener(fn, scope);
  13850. }
  13851. },
  13852. /**
  13853. * Adds a listener to be notified when the browser window is unloaded.
  13854. * @param {Function} fn The handler function the window unload event invokes.
  13855. * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
  13856. * @param {Boolean} options Options object as passed to {@link Ext.Element#addListener}
  13857. */
  13858. onWindowUnload: function(fn, scope, options) {
  13859. var unload = EventManager.unloadEvent;
  13860. if (!unload) {
  13861. EventManager.unloadEvent = unload = new Ext.util.Event();
  13862. EventManager.addListener(win, 'unload', EventManager.fireUnload);
  13863. }
  13864. if (fn) {
  13865. unload.addListener(fn, scope, options);
  13866. }
  13867. },
  13868. /**
  13869. * Fires the unload event for items bound with onWindowUnload
  13870. * @private
  13871. */
  13872. fireUnload: function() {
  13873. // wrap in a try catch, could have some problems during unload
  13874. try {
  13875. // relinquish references.
  13876. doc = win = undefined;
  13877. var gridviews, i, ln,
  13878. el, cache;
  13879. EventManager.unloadEvent.fire();
  13880. // Work around FF3 remembering the last scroll position when refreshing the grid and then losing grid view
  13881. if (Ext.isGecko3) {
  13882. gridviews = Ext.ComponentQuery.query('gridview');
  13883. i = 0;
  13884. ln = gridviews.length;
  13885. for (; i < ln; i++) {
  13886. gridviews[i].scrollToTop();
  13887. }
  13888. }
  13889. // Purge all elements in the cache
  13890. cache = Ext.cache;
  13891. for (el in cache) {
  13892. if (cache.hasOwnProperty(el)) {
  13893. EventManager.removeAll(el);
  13894. }
  13895. }
  13896. } catch(e) {
  13897. }
  13898. },
  13899. /**
  13900. * Removes the passed window unload listener.
  13901. * @param {Function} fn The method the event invokes
  13902. * @param {Object} scope The scope of handler
  13903. */
  13904. removeUnloadListener: function(fn, scope) {
  13905. var unload = EventManager.unloadEvent;
  13906. if (unload) {
  13907. unload.removeListener(fn, scope);
  13908. }
  13909. },
  13910. /**
  13911. * note 1: IE fires ONLY the keydown event on specialkey autorepeat
  13912. * note 2: Safari < 3.1, Gecko (Mac/Linux) & Opera fire only the keypress event on specialkey autorepeat
  13913. * (research done by Jan Wolter at http://unixpapa.com/js/key.html)
  13914. * @private
  13915. */
  13916. useKeyDown: Ext.isWebKit ?
  13917. parseInt(navigator.userAgent.match(/AppleWebKit\/(\d+)/)[1], 10) >= 525 :
  13918. !((Ext.isGecko && !Ext.isWindows) || Ext.isOpera),
  13919. /**
  13920. * Indicates which event to use for getting key presses.
  13921. * @return {String} The appropriate event name.
  13922. */
  13923. getKeyEvent: function() {
  13924. return EventManager.useKeyDown ? 'keydown' : 'keypress';
  13925. }
  13926. });
  13927. // route "< ie9-Standards" to a legacy IE onReady implementation
  13928. if(!('addEventListener' in document) && document.attachEvent) {
  13929. Ext.apply( EventManager, {
  13930. /* Customized implementation for Legacy IE. The default implementation is configured for use
  13931. * with all other 'standards compliant' agents.
  13932. * References: http://javascript.nwbox.com/IEContentLoaded/
  13933. * licensed courtesy of http://developer.yahoo.com/yui/license.html
  13934. */
  13935. /**
  13936. * This strategy has minimal benefits for Sencha solutions that build themselves (ie. minimal initial page markup).
  13937. * However, progressively-enhanced pages (with image content and/or embedded frames) will benefit the most from it.
  13938. * Browser timer resolution is too poor to ensure a doScroll check more than once on a page loaded with minimal
  13939. * assets (the readystatechange event 'complete' usually beats the doScroll timer on a 'lightly-loaded' initial document).
  13940. */
  13941. pollScroll : function() {
  13942. var scrollable = true;
  13943. try {
  13944. document.documentElement.doScroll('left');
  13945. } catch(e) {
  13946. scrollable = false;
  13947. }
  13948. // on IE8, when running within an iFrame, document.body is not immediately available
  13949. if (scrollable && document.body) {
  13950. EventManager.onReadyEvent({
  13951. type:'doScroll'
  13952. });
  13953. } else {
  13954. /*
  13955. * minimize thrashing --
  13956. * adjusted for setTimeout's close-to-minimums (not too low),
  13957. * as this method SHOULD always be called once initially
  13958. */
  13959. EventManager.scrollTimeout = setTimeout(EventManager.pollScroll, 20);
  13960. }
  13961. return scrollable;
  13962. },
  13963. /**
  13964. * Timer for doScroll polling
  13965. * @private
  13966. */
  13967. scrollTimeout: null,
  13968. /* @private
  13969. */
  13970. readyStatesRe : /complete/i,
  13971. /* @private
  13972. */
  13973. checkReadyState: function() {
  13974. var state = document.readyState;
  13975. if (EventManager.readyStatesRe.test(state)) {
  13976. EventManager.onReadyEvent({
  13977. type: state
  13978. });
  13979. }
  13980. },
  13981. bindReadyEvent: function() {
  13982. var topContext = true;
  13983. if (EventManager.hasBoundOnReady) {
  13984. return;
  13985. }
  13986. //are we in an IFRAME? (doScroll ineffective here)
  13987. try {
  13988. topContext = window.frameElement === undefined;
  13989. } catch(e) {
  13990. // If we throw an exception, it means we're probably getting access denied,
  13991. // which means we're in an iframe cross domain.
  13992. topContext = false;
  13993. }
  13994. if (!topContext || !doc.documentElement.doScroll) {
  13995. EventManager.pollScroll = Ext.emptyFn; //then noop this test altogether
  13996. }
  13997. // starts doScroll polling if necessary
  13998. if (EventManager.pollScroll() === true) {
  13999. return;
  14000. }
  14001. // Core is loaded AFTER initial document write/load ?
  14002. if (doc.readyState == 'complete' ) {
  14003. EventManager.onReadyEvent({type: 'already ' + (doc.readyState || 'body') });
  14004. } else {
  14005. doc.attachEvent('onreadystatechange', EventManager.checkReadyState);
  14006. window.attachEvent('onload', EventManager.onReadyEvent);
  14007. EventManager.hasBoundOnReady = true;
  14008. }
  14009. },
  14010. onReadyEvent : function(e) {
  14011. if (e && e.type) {
  14012. EventManager.onReadyChain.push(e.type);
  14013. }
  14014. if (EventManager.hasBoundOnReady) {
  14015. document.detachEvent('onreadystatechange', EventManager.checkReadyState);
  14016. window.detachEvent('onload', EventManager.onReadyEvent);
  14017. }
  14018. if (Ext.isNumber(EventManager.scrollTimeout)) {
  14019. clearTimeout(EventManager.scrollTimeout);
  14020. delete EventManager.scrollTimeout;
  14021. }
  14022. if (!Ext.isReady) {
  14023. EventManager.fireDocReady();
  14024. }
  14025. },
  14026. //diags: a list of event types passed to onReadyEvent (in chron order)
  14027. onReadyChain : []
  14028. });
  14029. }
  14030. /**
  14031. * Alias for {@link Ext.Loader#onReady Ext.Loader.onReady} with withDomReady set to true
  14032. * @member Ext
  14033. * @method onReady
  14034. */
  14035. Ext.onReady = function(fn, scope, options) {
  14036. Ext.Loader.onReady(fn, scope, true, options);
  14037. };
  14038. /**
  14039. * Alias for {@link Ext.EventManager#onDocumentReady Ext.EventManager.onDocumentReady}
  14040. * @member Ext
  14041. * @method onDocumentReady
  14042. */
  14043. Ext.onDocumentReady = EventManager.onDocumentReady;
  14044. /**
  14045. * Alias for {@link Ext.EventManager#addListener Ext.EventManager.addListener}
  14046. * @member Ext.EventManager
  14047. * @method on
  14048. */
  14049. EventManager.on = EventManager.addListener;
  14050. /**
  14051. * Alias for {@link Ext.EventManager#removeListener Ext.EventManager.removeListener}
  14052. * @member Ext.EventManager
  14053. * @method un
  14054. */
  14055. EventManager.un = EventManager.removeListener;
  14056. Ext.onReady(initExtCss);
  14057. };
  14058. //@tag dom,core
  14059. //@require EventManager.js
  14060. //@define Ext.EventObject
  14061. /**
  14062. * @class Ext.EventObject
  14063. Just as {@link Ext.Element} wraps around a native DOM node, Ext.EventObject
  14064. wraps the browser's native event-object normalizing cross-browser differences,
  14065. such as which mouse button is clicked, keys pressed, mechanisms to stop
  14066. event-propagation along with a method to prevent default actions from taking place.
  14067. For example:
  14068. function handleClick(e, t){ // e is not a standard event object, it is a Ext.EventObject
  14069. e.preventDefault();
  14070. var target = e.getTarget(); // same as t (the target HTMLElement)
  14071. ...
  14072. }
  14073. var myDiv = {@link Ext#get Ext.get}("myDiv"); // get reference to an {@link Ext.Element}
  14074. myDiv.on( // 'on' is shorthand for addListener
  14075. "click", // perform an action on click of myDiv
  14076. handleClick // reference to the action handler
  14077. );
  14078. // other methods to do the same:
  14079. Ext.EventManager.on("myDiv", 'click', handleClick);
  14080. Ext.EventManager.addListener("myDiv", 'click', handleClick);
  14081. * @singleton
  14082. * @markdown
  14083. */
  14084. Ext.define('Ext.EventObjectImpl', {
  14085. uses: ['Ext.util.Point'],
  14086. /** Key constant @type Number */
  14087. BACKSPACE: 8,
  14088. /** Key constant @type Number */
  14089. TAB: 9,
  14090. /** Key constant @type Number */
  14091. NUM_CENTER: 12,
  14092. /** Key constant @type Number */
  14093. ENTER: 13,
  14094. /** Key constant @type Number */
  14095. RETURN: 13,
  14096. /** Key constant @type Number */
  14097. SHIFT: 16,
  14098. /** Key constant @type Number */
  14099. CTRL: 17,
  14100. /** Key constant @type Number */
  14101. ALT: 18,
  14102. /** Key constant @type Number */
  14103. PAUSE: 19,
  14104. /** Key constant @type Number */
  14105. CAPS_LOCK: 20,
  14106. /** Key constant @type Number */
  14107. ESC: 27,
  14108. /** Key constant @type Number */
  14109. SPACE: 32,
  14110. /** Key constant @type Number */
  14111. PAGE_UP: 33,
  14112. /** Key constant @type Number */
  14113. PAGE_DOWN: 34,
  14114. /** Key constant @type Number */
  14115. END: 35,
  14116. /** Key constant @type Number */
  14117. HOME: 36,
  14118. /** Key constant @type Number */
  14119. LEFT: 37,
  14120. /** Key constant @type Number */
  14121. UP: 38,
  14122. /** Key constant @type Number */
  14123. RIGHT: 39,
  14124. /** Key constant @type Number */
  14125. DOWN: 40,
  14126. /** Key constant @type Number */
  14127. PRINT_SCREEN: 44,
  14128. /** Key constant @type Number */
  14129. INSERT: 45,
  14130. /** Key constant @type Number */
  14131. DELETE: 46,
  14132. /** Key constant @type Number */
  14133. ZERO: 48,
  14134. /** Key constant @type Number */
  14135. ONE: 49,
  14136. /** Key constant @type Number */
  14137. TWO: 50,
  14138. /** Key constant @type Number */
  14139. THREE: 51,
  14140. /** Key constant @type Number */
  14141. FOUR: 52,
  14142. /** Key constant @type Number */
  14143. FIVE: 53,
  14144. /** Key constant @type Number */
  14145. SIX: 54,
  14146. /** Key constant @type Number */
  14147. SEVEN: 55,
  14148. /** Key constant @type Number */
  14149. EIGHT: 56,
  14150. /** Key constant @type Number */
  14151. NINE: 57,
  14152. /** Key constant @type Number */
  14153. A: 65,
  14154. /** Key constant @type Number */
  14155. B: 66,
  14156. /** Key constant @type Number */
  14157. C: 67,
  14158. /** Key constant @type Number */
  14159. D: 68,
  14160. /** Key constant @type Number */
  14161. E: 69,
  14162. /** Key constant @type Number */
  14163. F: 70,
  14164. /** Key constant @type Number */
  14165. G: 71,
  14166. /** Key constant @type Number */
  14167. H: 72,
  14168. /** Key constant @type Number */
  14169. I: 73,
  14170. /** Key constant @type Number */
  14171. J: 74,
  14172. /** Key constant @type Number */
  14173. K: 75,
  14174. /** Key constant @type Number */
  14175. L: 76,
  14176. /** Key constant @type Number */
  14177. M: 77,
  14178. /** Key constant @type Number */
  14179. N: 78,
  14180. /** Key constant @type Number */
  14181. O: 79,
  14182. /** Key constant @type Number */
  14183. P: 80,
  14184. /** Key constant @type Number */
  14185. Q: 81,
  14186. /** Key constant @type Number */
  14187. R: 82,
  14188. /** Key constant @type Number */
  14189. S: 83,
  14190. /** Key constant @type Number */
  14191. T: 84,
  14192. /** Key constant @type Number */
  14193. U: 85,
  14194. /** Key constant @type Number */
  14195. V: 86,
  14196. /** Key constant @type Number */
  14197. W: 87,
  14198. /** Key constant @type Number */
  14199. X: 88,
  14200. /** Key constant @type Number */
  14201. Y: 89,
  14202. /** Key constant @type Number */
  14203. Z: 90,
  14204. /** Key constant @type Number */
  14205. CONTEXT_MENU: 93,
  14206. /** Key constant @type Number */
  14207. NUM_ZERO: 96,
  14208. /** Key constant @type Number */
  14209. NUM_ONE: 97,
  14210. /** Key constant @type Number */
  14211. NUM_TWO: 98,
  14212. /** Key constant @type Number */
  14213. NUM_THREE: 99,
  14214. /** Key constant @type Number */
  14215. NUM_FOUR: 100,
  14216. /** Key constant @type Number */
  14217. NUM_FIVE: 101,
  14218. /** Key constant @type Number */
  14219. NUM_SIX: 102,
  14220. /** Key constant @type Number */
  14221. NUM_SEVEN: 103,
  14222. /** Key constant @type Number */
  14223. NUM_EIGHT: 104,
  14224. /** Key constant @type Number */
  14225. NUM_NINE: 105,
  14226. /** Key constant @type Number */
  14227. NUM_MULTIPLY: 106,
  14228. /** Key constant @type Number */
  14229. NUM_PLUS: 107,
  14230. /** Key constant @type Number */
  14231. NUM_MINUS: 109,
  14232. /** Key constant @type Number */
  14233. NUM_PERIOD: 110,
  14234. /** Key constant @type Number */
  14235. NUM_DIVISION: 111,
  14236. /** Key constant @type Number */
  14237. F1: 112,
  14238. /** Key constant @type Number */
  14239. F2: 113,
  14240. /** Key constant @type Number */
  14241. F3: 114,
  14242. /** Key constant @type Number */
  14243. F4: 115,
  14244. /** Key constant @type Number */
  14245. F5: 116,
  14246. /** Key constant @type Number */
  14247. F6: 117,
  14248. /** Key constant @type Number */
  14249. F7: 118,
  14250. /** Key constant @type Number */
  14251. F8: 119,
  14252. /** Key constant @type Number */
  14253. F9: 120,
  14254. /** Key constant @type Number */
  14255. F10: 121,
  14256. /** Key constant @type Number */
  14257. F11: 122,
  14258. /** Key constant @type Number */
  14259. F12: 123,
  14260. /**
  14261. * The mouse wheel delta scaling factor. This value depends on browser version and OS and
  14262. * attempts to produce a similar scrolling experience across all platforms and browsers.
  14263. *
  14264. * To change this value:
  14265. *
  14266. * Ext.EventObjectImpl.prototype.WHEEL_SCALE = 72;
  14267. *
  14268. * @type Number
  14269. * @markdown
  14270. */
  14271. WHEEL_SCALE: (function () {
  14272. var scale;
  14273. if (Ext.isGecko) {
  14274. // Firefox uses 3 on all platforms
  14275. scale = 3;
  14276. } else if (Ext.isMac) {
  14277. // Continuous scrolling devices have momentum and produce much more scroll than
  14278. // discrete devices on the same OS and browser. To make things exciting, Safari
  14279. // (and not Chrome) changed from small values to 120 (like IE).
  14280. if (Ext.isSafari && Ext.webKitVersion >= 532.0) {
  14281. // Safari changed the scrolling factor to match IE (for details see
  14282. // https://bugs.webkit.org/show_bug.cgi?id=24368). The WebKit version where this
  14283. // change was introduced was 532.0
  14284. // Detailed discussion:
  14285. // https://bugs.webkit.org/show_bug.cgi?id=29601
  14286. // http://trac.webkit.org/browser/trunk/WebKit/chromium/src/mac/WebInputEventFactory.mm#L1063
  14287. scale = 120;
  14288. } else {
  14289. // MS optical wheel mouse produces multiples of 12 which is close enough
  14290. // to help tame the speed of the continuous mice...
  14291. scale = 12;
  14292. }
  14293. // Momentum scrolling produces very fast scrolling, so increase the scale factor
  14294. // to help produce similar results cross platform. This could be even larger and
  14295. // it would help those mice, but other mice would become almost unusable as a
  14296. // result (since we cannot tell which device type is in use).
  14297. scale *= 3;
  14298. } else {
  14299. // IE, Opera and other Windows browsers use 120.
  14300. scale = 120;
  14301. }
  14302. return scale;
  14303. }()),
  14304. /**
  14305. * Simple click regex
  14306. * @private
  14307. */
  14308. clickRe: /(dbl)?click/,
  14309. // safari keypress events for special keys return bad keycodes
  14310. safariKeys: {
  14311. 3: 13, // enter
  14312. 63234: 37, // left
  14313. 63235: 39, // right
  14314. 63232: 38, // up
  14315. 63233: 40, // down
  14316. 63276: 33, // page up
  14317. 63277: 34, // page down
  14318. 63272: 46, // delete
  14319. 63273: 36, // home
  14320. 63275: 35 // end
  14321. },
  14322. // normalize button clicks, don't see any way to feature detect this.
  14323. btnMap: Ext.isIE ? {
  14324. 1: 0,
  14325. 4: 1,
  14326. 2: 2
  14327. } : {
  14328. 0: 0,
  14329. 1: 1,
  14330. 2: 2
  14331. },
  14332. /**
  14333. * @property {Boolean} ctrlKey
  14334. * True if the control key was down during the event.
  14335. * In Mac this will also be true when meta key was down.
  14336. */
  14337. /**
  14338. * @property {Boolean} altKey
  14339. * True if the alt key was down during the event.
  14340. */
  14341. /**
  14342. * @property {Boolean} shiftKey
  14343. * True if the shift key was down during the event.
  14344. */
  14345. constructor: function(event, freezeEvent){
  14346. if (event) {
  14347. this.setEvent(event.browserEvent || event, freezeEvent);
  14348. }
  14349. },
  14350. setEvent: function(event, freezeEvent){
  14351. var me = this, button, options;
  14352. if (event == me || (event && event.browserEvent)) { // already wrapped
  14353. return event;
  14354. }
  14355. me.browserEvent = event;
  14356. if (event) {
  14357. // normalize buttons
  14358. button = event.button ? me.btnMap[event.button] : (event.which ? event.which - 1 : -1);
  14359. if (me.clickRe.test(event.type) && button == -1) {
  14360. button = 0;
  14361. }
  14362. options = {
  14363. type: event.type,
  14364. button: button,
  14365. shiftKey: event.shiftKey,
  14366. // mac metaKey behaves like ctrlKey
  14367. ctrlKey: event.ctrlKey || event.metaKey || false,
  14368. altKey: event.altKey,
  14369. // in getKey these will be normalized for the mac
  14370. keyCode: event.keyCode,
  14371. charCode: event.charCode,
  14372. // cache the targets for the delayed and or buffered events
  14373. target: Ext.EventManager.getTarget(event),
  14374. relatedTarget: Ext.EventManager.getRelatedTarget(event),
  14375. currentTarget: event.currentTarget,
  14376. xy: (freezeEvent ? me.getXY() : null)
  14377. };
  14378. } else {
  14379. options = {
  14380. button: -1,
  14381. shiftKey: false,
  14382. ctrlKey: false,
  14383. altKey: false,
  14384. keyCode: 0,
  14385. charCode: 0,
  14386. target: null,
  14387. xy: [0, 0]
  14388. };
  14389. }
  14390. Ext.apply(me, options);
  14391. return me;
  14392. },
  14393. /**
  14394. * Stop the event (preventDefault and stopPropagation)
  14395. */
  14396. stopEvent: function(){
  14397. this.stopPropagation();
  14398. this.preventDefault();
  14399. },
  14400. /**
  14401. * Prevents the browsers default handling of the event.
  14402. */
  14403. preventDefault: function(){
  14404. if (this.browserEvent) {
  14405. Ext.EventManager.preventDefault(this.browserEvent);
  14406. }
  14407. },
  14408. /**
  14409. * Cancels bubbling of the event.
  14410. */
  14411. stopPropagation: function(){
  14412. var browserEvent = this.browserEvent;
  14413. if (browserEvent) {
  14414. if (browserEvent.type == 'mousedown') {
  14415. Ext.EventManager.stoppedMouseDownEvent.fire(this);
  14416. }
  14417. Ext.EventManager.stopPropagation(browserEvent);
  14418. }
  14419. },
  14420. /**
  14421. * Gets the character code for the event.
  14422. * @return {Number}
  14423. */
  14424. getCharCode: function(){
  14425. return this.charCode || this.keyCode;
  14426. },
  14427. /**
  14428. * Returns a normalized keyCode for the event.
  14429. * @return {Number} The key code
  14430. */
  14431. getKey: function(){
  14432. return this.normalizeKey(this.keyCode || this.charCode);
  14433. },
  14434. /**
  14435. * Normalize key codes across browsers
  14436. * @private
  14437. * @param {Number} key The key code
  14438. * @return {Number} The normalized code
  14439. */
  14440. normalizeKey: function(key){
  14441. // can't feature detect this
  14442. return Ext.isWebKit ? (this.safariKeys[key] || key) : key;
  14443. },
  14444. /**
  14445. * Gets the x coordinate of the event.
  14446. * @return {Number}
  14447. * @deprecated 4.0 Replaced by {@link #getX}
  14448. */
  14449. getPageX: function(){
  14450. return this.getX();
  14451. },
  14452. /**
  14453. * Gets the y coordinate of the event.
  14454. * @return {Number}
  14455. * @deprecated 4.0 Replaced by {@link #getY}
  14456. */
  14457. getPageY: function(){
  14458. return this.getY();
  14459. },
  14460. /**
  14461. * Gets the x coordinate of the event.
  14462. * @return {Number}
  14463. */
  14464. getX: function() {
  14465. return this.getXY()[0];
  14466. },
  14467. /**
  14468. * Gets the y coordinate of the event.
  14469. * @return {Number}
  14470. */
  14471. getY: function() {
  14472. return this.getXY()[1];
  14473. },
  14474. /**
  14475. * Gets the page coordinates of the event.
  14476. * @return {Number[]} The xy values like [x, y]
  14477. */
  14478. getXY: function() {
  14479. if (!this.xy) {
  14480. // same for XY
  14481. this.xy = Ext.EventManager.getPageXY(this.browserEvent);
  14482. }
  14483. return this.xy;
  14484. },
  14485. /**
  14486. * Gets the target for the event.
  14487. * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
  14488. * @param {Number/HTMLElement} maxDepth (optional) The max depth to search as a number or element (defaults to 10 || document.body)
  14489. * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
  14490. * @return {HTMLElement}
  14491. */
  14492. getTarget : function(selector, maxDepth, returnEl){
  14493. if (selector) {
  14494. return Ext.fly(this.target).findParent(selector, maxDepth, returnEl);
  14495. }
  14496. return returnEl ? Ext.get(this.target) : this.target;
  14497. },
  14498. /**
  14499. * Gets the related target.
  14500. * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
  14501. * @param {Number/HTMLElement} maxDepth (optional) The max depth to search as a number or element (defaults to 10 || document.body)
  14502. * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
  14503. * @return {HTMLElement}
  14504. */
  14505. getRelatedTarget : function(selector, maxDepth, returnEl){
  14506. if (selector) {
  14507. return Ext.fly(this.relatedTarget).findParent(selector, maxDepth, returnEl);
  14508. }
  14509. return returnEl ? Ext.get(this.relatedTarget) : this.relatedTarget;
  14510. },
  14511. /**
  14512. * Correctly scales a given wheel delta.
  14513. * @param {Number} delta The delta value.
  14514. */
  14515. correctWheelDelta : function (delta) {
  14516. var scale = this.WHEEL_SCALE,
  14517. ret = Math.round(delta / scale);
  14518. if (!ret && delta) {
  14519. ret = (delta < 0) ? -1 : 1; // don't allow non-zero deltas to go to zero!
  14520. }
  14521. return ret;
  14522. },
  14523. /**
  14524. * Returns the mouse wheel deltas for this event.
  14525. * @return {Object} An object with "x" and "y" properties holding the mouse wheel deltas.
  14526. */
  14527. getWheelDeltas : function () {
  14528. var me = this,
  14529. event = me.browserEvent,
  14530. dx = 0, dy = 0; // the deltas
  14531. if (Ext.isDefined(event.wheelDeltaX)) { // WebKit has both dimensions
  14532. dx = event.wheelDeltaX;
  14533. dy = event.wheelDeltaY;
  14534. } else if (event.wheelDelta) { // old WebKit and IE
  14535. dy = event.wheelDelta;
  14536. } else if (event.detail) { // Gecko
  14537. dy = -event.detail; // gecko is backwards
  14538. // Gecko sometimes returns really big values if the user changes settings to
  14539. // scroll a whole page per scroll
  14540. if (dy > 100) {
  14541. dy = 3;
  14542. } else if (dy < -100) {
  14543. dy = -3;
  14544. }
  14545. // Firefox 3.1 adds an axis field to the event to indicate direction of
  14546. // scroll. See https://developer.mozilla.org/en/Gecko-Specific_DOM_Events
  14547. if (Ext.isDefined(event.axis) && event.axis === event.HORIZONTAL_AXIS) {
  14548. dx = dy;
  14549. dy = 0;
  14550. }
  14551. }
  14552. return {
  14553. x: me.correctWheelDelta(dx),
  14554. y: me.correctWheelDelta(dy)
  14555. };
  14556. },
  14557. /**
  14558. * Normalizes mouse wheel y-delta across browsers. To get x-delta information, use
  14559. * {@link #getWheelDeltas} instead.
  14560. * @return {Number} The mouse wheel y-delta
  14561. */
  14562. getWheelDelta : function(){
  14563. var deltas = this.getWheelDeltas();
  14564. return deltas.y;
  14565. },
  14566. /**
  14567. * Returns true if the target of this event is a child of el. Unless the allowEl parameter is set, it will return false if if the target is el.
  14568. * Example usage:<pre><code>
  14569. // Handle click on any child of an element
  14570. Ext.getBody().on('click', function(e){
  14571. if(e.within('some-el')){
  14572. alert('Clicked on a child of some-el!');
  14573. }
  14574. });
  14575. // Handle click directly on an element, ignoring clicks on child nodes
  14576. Ext.getBody().on('click', function(e,t){
  14577. if((t.id == 'some-el') && !e.within(t, true)){
  14578. alert('Clicked directly on some-el!');
  14579. }
  14580. });
  14581. </code></pre>
  14582. * @param {String/HTMLElement/Ext.Element} el The id, DOM element or Ext.Element to check
  14583. * @param {Boolean} related (optional) true to test if the related target is within el instead of the target
  14584. * @param {Boolean} allowEl (optional) true to also check if the passed element is the target or related target
  14585. * @return {Boolean}
  14586. */
  14587. within : function(el, related, allowEl){
  14588. if(el){
  14589. var t = related ? this.getRelatedTarget() : this.getTarget(),
  14590. result;
  14591. if (t) {
  14592. result = Ext.fly(el).contains(t);
  14593. if (!result && allowEl) {
  14594. result = t == Ext.getDom(el);
  14595. }
  14596. return result;
  14597. }
  14598. }
  14599. return false;
  14600. },
  14601. /**
  14602. * Checks if the key pressed was a "navigation" key
  14603. * @return {Boolean} True if the press is a navigation keypress
  14604. */
  14605. isNavKeyPress : function(){
  14606. var me = this,
  14607. k = this.normalizeKey(me.keyCode);
  14608. return (k >= 33 && k <= 40) || // Page Up/Down, End, Home, Left, Up, Right, Down
  14609. k == me.RETURN ||
  14610. k == me.TAB ||
  14611. k == me.ESC;
  14612. },
  14613. /**
  14614. * Checks if the key pressed was a "special" key
  14615. * @return {Boolean} True if the press is a special keypress
  14616. */
  14617. isSpecialKey : function(){
  14618. var k = this.normalizeKey(this.keyCode);
  14619. return (this.type == 'keypress' && this.ctrlKey) ||
  14620. this.isNavKeyPress() ||
  14621. (k == this.BACKSPACE) || // Backspace
  14622. (k >= 16 && k <= 20) || // Shift, Ctrl, Alt, Pause, Caps Lock
  14623. (k >= 44 && k <= 46); // Print Screen, Insert, Delete
  14624. },
  14625. /**
  14626. * Returns a point object that consists of the object coordinates.
  14627. * @return {Ext.util.Point} point
  14628. */
  14629. getPoint : function(){
  14630. var xy = this.getXY();
  14631. return new Ext.util.Point(xy[0], xy[1]);
  14632. },
  14633. /**
  14634. * Returns true if the control, meta, shift or alt key was pressed during this event.
  14635. * @return {Boolean}
  14636. */
  14637. hasModifier : function(){
  14638. return this.ctrlKey || this.altKey || this.shiftKey || this.metaKey;
  14639. },
  14640. /**
  14641. * Injects a DOM event using the data in this object and (optionally) a new target.
  14642. * This is a low-level technique and not likely to be used by application code. The
  14643. * currently supported event types are:
  14644. * <p><b>HTMLEvents</b></p>
  14645. * <ul>
  14646. * <li>load</li>
  14647. * <li>unload</li>
  14648. * <li>select</li>
  14649. * <li>change</li>
  14650. * <li>submit</li>
  14651. * <li>reset</li>
  14652. * <li>resize</li>
  14653. * <li>scroll</li>
  14654. * </ul>
  14655. * <p><b>MouseEvents</b></p>
  14656. * <ul>
  14657. * <li>click</li>
  14658. * <li>dblclick</li>
  14659. * <li>mousedown</li>
  14660. * <li>mouseup</li>
  14661. * <li>mouseover</li>
  14662. * <li>mousemove</li>
  14663. * <li>mouseout</li>
  14664. * </ul>
  14665. * <p><b>UIEvents</b></p>
  14666. * <ul>
  14667. * <li>focusin</li>
  14668. * <li>focusout</li>
  14669. * <li>activate</li>
  14670. * <li>focus</li>
  14671. * <li>blur</li>
  14672. * </ul>
  14673. * @param {Ext.Element/HTMLElement} target (optional) If specified, the target for the event. This
  14674. * is likely to be used when relaying a DOM event. If not specified, {@link #getTarget}
  14675. * is used to determine the target.
  14676. */
  14677. injectEvent: (function () {
  14678. var API,
  14679. dispatchers = {}, // keyed by event type (e.g., 'mousedown')
  14680. crazyIEButtons;
  14681. // Good reference: http://developer.yahoo.com/yui/docs/UserAction.js.html
  14682. // IE9 has createEvent, but this code causes major problems with htmleditor (it
  14683. // blocks all mouse events and maybe more). TODO
  14684. if (!Ext.isIE && document.createEvent) { // if (DOM compliant)
  14685. API = {
  14686. createHtmlEvent: function (doc, type, bubbles, cancelable) {
  14687. var event = doc.createEvent('HTMLEvents');
  14688. event.initEvent(type, bubbles, cancelable);
  14689. return event;
  14690. },
  14691. createMouseEvent: function (doc, type, bubbles, cancelable, detail,
  14692. clientX, clientY, ctrlKey, altKey, shiftKey, metaKey,
  14693. button, relatedTarget) {
  14694. var event = doc.createEvent('MouseEvents'),
  14695. view = doc.defaultView || window;
  14696. if (event.initMouseEvent) {
  14697. event.initMouseEvent(type, bubbles, cancelable, view, detail,
  14698. clientX, clientY, clientX, clientY, ctrlKey, altKey,
  14699. shiftKey, metaKey, button, relatedTarget);
  14700. } else { // old Safari
  14701. event = doc.createEvent('UIEvents');
  14702. event.initEvent(type, bubbles, cancelable);
  14703. event.view = view;
  14704. event.detail = detail;
  14705. event.screenX = clientX;
  14706. event.screenY = clientY;
  14707. event.clientX = clientX;
  14708. event.clientY = clientY;
  14709. event.ctrlKey = ctrlKey;
  14710. event.altKey = altKey;
  14711. event.metaKey = metaKey;
  14712. event.shiftKey = shiftKey;
  14713. event.button = button;
  14714. event.relatedTarget = relatedTarget;
  14715. }
  14716. return event;
  14717. },
  14718. createUIEvent: function (doc, type, bubbles, cancelable, detail) {
  14719. var event = doc.createEvent('UIEvents'),
  14720. view = doc.defaultView || window;
  14721. event.initUIEvent(type, bubbles, cancelable, view, detail);
  14722. return event;
  14723. },
  14724. fireEvent: function (target, type, event) {
  14725. target.dispatchEvent(event);
  14726. },
  14727. fixTarget: function (target) {
  14728. // Safari3 doesn't have window.dispatchEvent()
  14729. if (target == window && !target.dispatchEvent) {
  14730. return document;
  14731. }
  14732. return target;
  14733. }
  14734. };
  14735. } else if (document.createEventObject) { // else if (IE)
  14736. crazyIEButtons = { 0: 1, 1: 4, 2: 2 };
  14737. API = {
  14738. createHtmlEvent: function (doc, type, bubbles, cancelable) {
  14739. var event = doc.createEventObject();
  14740. event.bubbles = bubbles;
  14741. event.cancelable = cancelable;
  14742. return event;
  14743. },
  14744. createMouseEvent: function (doc, type, bubbles, cancelable, detail,
  14745. clientX, clientY, ctrlKey, altKey, shiftKey, metaKey,
  14746. button, relatedTarget) {
  14747. var event = doc.createEventObject();
  14748. event.bubbles = bubbles;
  14749. event.cancelable = cancelable;
  14750. event.detail = detail;
  14751. event.screenX = clientX;
  14752. event.screenY = clientY;
  14753. event.clientX = clientX;
  14754. event.clientY = clientY;
  14755. event.ctrlKey = ctrlKey;
  14756. event.altKey = altKey;
  14757. event.shiftKey = shiftKey;
  14758. event.metaKey = metaKey;
  14759. event.button = crazyIEButtons[button] || button;
  14760. event.relatedTarget = relatedTarget; // cannot assign to/fromElement
  14761. return event;
  14762. },
  14763. createUIEvent: function (doc, type, bubbles, cancelable, detail) {
  14764. var event = doc.createEventObject();
  14765. event.bubbles = bubbles;
  14766. event.cancelable = cancelable;
  14767. return event;
  14768. },
  14769. fireEvent: function (target, type, event) {
  14770. target.fireEvent('on' + type, event);
  14771. },
  14772. fixTarget: function (target) {
  14773. if (target == document) {
  14774. // IE6,IE7 thinks window==document and doesn't have window.fireEvent()
  14775. // IE6,IE7 cannot properly call document.fireEvent()
  14776. return document.documentElement;
  14777. }
  14778. return target;
  14779. }
  14780. };
  14781. }
  14782. //----------------
  14783. // HTMLEvents
  14784. Ext.Object.each({
  14785. load: [false, false],
  14786. unload: [false, false],
  14787. select: [true, false],
  14788. change: [true, false],
  14789. submit: [true, true],
  14790. reset: [true, false],
  14791. resize: [true, false],
  14792. scroll: [true, false]
  14793. },
  14794. function (name, value) {
  14795. var bubbles = value[0], cancelable = value[1];
  14796. dispatchers[name] = function (targetEl, srcEvent) {
  14797. var e = API.createHtmlEvent(name, bubbles, cancelable);
  14798. API.fireEvent(targetEl, name, e);
  14799. };
  14800. });
  14801. //----------------
  14802. // MouseEvents
  14803. function createMouseEventDispatcher (type, detail) {
  14804. var cancelable = (type != 'mousemove');
  14805. return function (targetEl, srcEvent) {
  14806. var xy = srcEvent.getXY(),
  14807. e = API.createMouseEvent(targetEl.ownerDocument, type, true, cancelable,
  14808. detail, xy[0], xy[1], srcEvent.ctrlKey, srcEvent.altKey,
  14809. srcEvent.shiftKey, srcEvent.metaKey, srcEvent.button,
  14810. srcEvent.relatedTarget);
  14811. API.fireEvent(targetEl, type, e);
  14812. };
  14813. }
  14814. Ext.each(['click', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mousemove', 'mouseout'],
  14815. function (eventName) {
  14816. dispatchers[eventName] = createMouseEventDispatcher(eventName, 1);
  14817. });
  14818. //----------------
  14819. // UIEvents
  14820. Ext.Object.each({
  14821. focusin: [true, false],
  14822. focusout: [true, false],
  14823. activate: [true, true],
  14824. focus: [false, false],
  14825. blur: [false, false]
  14826. },
  14827. function (name, value) {
  14828. var bubbles = value[0], cancelable = value[1];
  14829. dispatchers[name] = function (targetEl, srcEvent) {
  14830. var e = API.createUIEvent(targetEl.ownerDocument, name, bubbles, cancelable, 1);
  14831. API.fireEvent(targetEl, name, e);
  14832. };
  14833. });
  14834. //---------
  14835. if (!API) {
  14836. // not even sure what ancient browsers fall into this category...
  14837. dispatchers = {}; // never mind all those we just built :P
  14838. API = {
  14839. fixTarget: function (t) {
  14840. return t;
  14841. }
  14842. };
  14843. }
  14844. function cannotInject (target, srcEvent) {
  14845. // TODO log something
  14846. }
  14847. return function (target) {
  14848. var me = this,
  14849. dispatcher = dispatchers[me.type] || cannotInject,
  14850. t = target ? (target.dom || target) : me.getTarget();
  14851. t = API.fixTarget(t);
  14852. dispatcher(t, me);
  14853. };
  14854. }()) // call to produce method
  14855. }, function() {
  14856. Ext.EventObject = new Ext.EventObjectImpl();
  14857. });
  14858. //@tag dom,core
  14859. //@require ../EventObject.js
  14860. /**
  14861. * @class Ext.dom.AbstractQuery
  14862. * @private
  14863. */
  14864. Ext.define('Ext.dom.AbstractQuery', {
  14865. /**
  14866. * Selects a group of elements.
  14867. * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
  14868. * @param {HTMLElement/String} [root] The start of the query (defaults to document).
  14869. * @return {HTMLElement[]} An Array of DOM elements which match the selector. If there are
  14870. * no matches, and empty Array is returned.
  14871. */
  14872. select: function(q, root) {
  14873. var results = [],
  14874. nodes,
  14875. i,
  14876. j,
  14877. qlen,
  14878. nlen;
  14879. root = root || document;
  14880. if (typeof root == 'string') {
  14881. root = document.getElementById(root);
  14882. }
  14883. q = q.split(",");
  14884. for (i = 0,qlen = q.length; i < qlen; i++) {
  14885. if (typeof q[i] == 'string') {
  14886. //support for node attribute selection
  14887. if (typeof q[i][0] == '@') {
  14888. nodes = root.getAttributeNode(q[i].substring(1));
  14889. results.push(nodes);
  14890. } else {
  14891. nodes = root.querySelectorAll(q[i]);
  14892. for (j = 0,nlen = nodes.length; j < nlen; j++) {
  14893. results.push(nodes[j]);
  14894. }
  14895. }
  14896. }
  14897. }
  14898. return results;
  14899. },
  14900. /**
  14901. * Selects a single element.
  14902. * @param {String} selector The selector/xpath query
  14903. * @param {HTMLElement/String} [root] The start of the query (defaults to document).
  14904. * @return {HTMLElement} The DOM element which matched the selector.
  14905. */
  14906. selectNode: function(q, root) {
  14907. return this.select(q, root)[0];
  14908. },
  14909. /**
  14910. * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
  14911. * @param {String/HTMLElement/Array} el An element id, element or array of elements
  14912. * @param {String} selector The simple selector to test
  14913. * @return {Boolean}
  14914. */
  14915. is: function(el, q) {
  14916. if (typeof el == "string") {
  14917. el = document.getElementById(el);
  14918. }
  14919. return this.select(q).indexOf(el) !== -1;
  14920. }
  14921. });
  14922. //@tag dom,core
  14923. //@require AbstractQuery.js
  14924. /**
  14925. * Abstract base class for {@link Ext.dom.Helper}.
  14926. * @private
  14927. */
  14928. Ext.define('Ext.dom.AbstractHelper', {
  14929. emptyTags : /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i,
  14930. confRe : /(?:tag|children|cn|html|tpl|tplData)$/i,
  14931. endRe : /end/i,
  14932. // Since cls & for are reserved words, we need to transform them
  14933. attributeTransform: { cls : 'class', htmlFor : 'for' },
  14934. closeTags: {},
  14935. decamelizeName : (function () {
  14936. var camelCaseRe = /([a-z])([A-Z])/g,
  14937. cache = {};
  14938. function decamel (match, p1, p2) {
  14939. return p1 + '-' + p2.toLowerCase();
  14940. }
  14941. return function (s) {
  14942. return cache[s] || (cache[s] = s.replace(camelCaseRe, decamel));
  14943. };
  14944. }()),
  14945. generateMarkup: function(spec, buffer) {
  14946. var me = this,
  14947. attr, val, tag, i, closeTags;
  14948. if (typeof spec == "string") {
  14949. buffer.push(spec);
  14950. } else if (Ext.isArray(spec)) {
  14951. for (i = 0; i < spec.length; i++) {
  14952. if (spec[i]) {
  14953. me.generateMarkup(spec[i], buffer);
  14954. }
  14955. }
  14956. } else {
  14957. tag = spec.tag || 'div';
  14958. buffer.push('<', tag);
  14959. for (attr in spec) {
  14960. if (spec.hasOwnProperty(attr)) {
  14961. val = spec[attr];
  14962. if (!me.confRe.test(attr)) {
  14963. if (typeof val == "object") {
  14964. buffer.push(' ', attr, '="');
  14965. me.generateStyles(val, buffer).push('"');
  14966. } else {
  14967. buffer.push(' ', me.attributeTransform[attr] || attr, '="', val, '"');
  14968. }
  14969. }
  14970. }
  14971. }
  14972. // Now either just close the tag or try to add children and close the tag.
  14973. if (me.emptyTags.test(tag)) {
  14974. buffer.push('/>');
  14975. } else {
  14976. buffer.push('>');
  14977. // Apply the tpl html, and cn specifications
  14978. if ((val = spec.tpl)) {
  14979. val.applyOut(spec.tplData, buffer);
  14980. }
  14981. if ((val = spec.html)) {
  14982. buffer.push(val);
  14983. }
  14984. if ((val = spec.cn || spec.children)) {
  14985. me.generateMarkup(val, buffer);
  14986. }
  14987. // we generate a lot of close tags, so cache them rather than push 3 parts
  14988. closeTags = me.closeTags;
  14989. buffer.push(closeTags[tag] || (closeTags[tag] = '</' + tag + '>'));
  14990. }
  14991. }
  14992. return buffer;
  14993. },
  14994. /**
  14995. * Converts the styles from the given object to text. The styles are CSS style names
  14996. * with their associated value.
  14997. *
  14998. * The basic form of this method returns a string:
  14999. *
  15000. * var s = Ext.DomHelper.generateStyles({
  15001. * backgroundColor: 'red'
  15002. * });
  15003. *
  15004. * // s = 'background-color:red;'
  15005. *
  15006. * Alternatively, this method can append to an output array.
  15007. *
  15008. * var buf = [];
  15009. *
  15010. * ...
  15011. *
  15012. * Ext.DomHelper.generateStyles({
  15013. * backgroundColor: 'red'
  15014. * }, buf);
  15015. *
  15016. * In this case, the style text is pushed on to the array and the array is returned.
  15017. *
  15018. * @param {Object} styles The object describing the styles.
  15019. * @param {String[]} [buffer] The output buffer.
  15020. * @return {String/String[]} If buffer is passed, it is returned. Otherwise the style
  15021. * string is returned.
  15022. */
  15023. generateStyles: function (styles, buffer) {
  15024. var a = buffer || [],
  15025. name;
  15026. for (name in styles) {
  15027. if (styles.hasOwnProperty(name)) {
  15028. a.push(this.decamelizeName(name), ':', styles[name], ';');
  15029. }
  15030. }
  15031. return buffer || a.join('');
  15032. },
  15033. /**
  15034. * Returns the markup for the passed Element(s) config.
  15035. * @param {Object} spec The DOM object spec (and children)
  15036. * @return {String}
  15037. */
  15038. markup: function(spec) {
  15039. if (typeof spec == "string") {
  15040. return spec;
  15041. }
  15042. var buf = this.generateMarkup(spec, []);
  15043. return buf.join('');
  15044. },
  15045. /**
  15046. * Applies a style specification to an element.
  15047. * @param {String/HTMLElement} el The element to apply styles to
  15048. * @param {String/Object/Function} styles A style specification string e.g. 'width:100px', or object in the form {width:'100px'}, or
  15049. * a function which returns such a specification.
  15050. */
  15051. applyStyles: function(el, styles) {
  15052. if (styles) {
  15053. var i = 0,
  15054. len,
  15055. style;
  15056. el = Ext.fly(el);
  15057. if (typeof styles == 'function') {
  15058. styles = styles.call();
  15059. }
  15060. if (typeof styles == 'string'){
  15061. styles = Ext.util.Format.trim(styles).split(/\s*(?::|;)\s*/);
  15062. for(len = styles.length; i < len;){
  15063. el.setStyle(styles[i++], styles[i++]);
  15064. }
  15065. } else if (Ext.isObject(styles)) {
  15066. el.setStyle(styles);
  15067. }
  15068. }
  15069. },
  15070. /**
  15071. * Inserts an HTML fragment into the DOM.
  15072. * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.
  15073. *
  15074. * For example take the following HTML: `<div>Contents</div>`
  15075. *
  15076. * Using different `where` values inserts element to the following places:
  15077. *
  15078. * - beforeBegin: `<HERE><div>Contents</div>`
  15079. * - afterBegin: `<div><HERE>Contents</div>`
  15080. * - beforeEnd: `<div>Contents<HERE></div>`
  15081. * - afterEnd: `<div>Contents</div><HERE>`
  15082. *
  15083. * @param {HTMLElement/TextNode} el The context element
  15084. * @param {String} html The HTML fragment
  15085. * @return {HTMLElement} The new node
  15086. */
  15087. insertHtml: function(where, el, html) {
  15088. var hash = {},
  15089. hashVal,
  15090. setStart,
  15091. range,
  15092. frag,
  15093. rangeEl,
  15094. rs;
  15095. where = where.toLowerCase();
  15096. // add these here because they are used in both branches of the condition.
  15097. hash['beforebegin'] = ['BeforeBegin', 'previousSibling'];
  15098. hash['afterend'] = ['AfterEnd', 'nextSibling'];
  15099. range = el.ownerDocument.createRange();
  15100. setStart = 'setStart' + (this.endRe.test(where) ? 'After' : 'Before');
  15101. if (hash[where]) {
  15102. range[setStart](el);
  15103. frag = range.createContextualFragment(html);
  15104. el.parentNode.insertBefore(frag, where == 'beforebegin' ? el : el.nextSibling);
  15105. return el[(where == 'beforebegin' ? 'previous' : 'next') + 'Sibling'];
  15106. }
  15107. else {
  15108. rangeEl = (where == 'afterbegin' ? 'first' : 'last') + 'Child';
  15109. if (el.firstChild) {
  15110. range[setStart](el[rangeEl]);
  15111. frag = range.createContextualFragment(html);
  15112. if (where == 'afterbegin') {
  15113. el.insertBefore(frag, el.firstChild);
  15114. }
  15115. else {
  15116. el.appendChild(frag);
  15117. }
  15118. }
  15119. else {
  15120. el.innerHTML = html;
  15121. }
  15122. return el[rangeEl];
  15123. }
  15124. throw 'Illegal insertion point -> "' + where + '"';
  15125. },
  15126. /**
  15127. * Creates new DOM element(s) and inserts them before el.
  15128. * @param {String/HTMLElement/Ext.Element} el The context element
  15129. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  15130. * @param {Boolean} [returnElement] true to return a Ext.Element
  15131. * @return {HTMLElement/Ext.Element} The new node
  15132. */
  15133. insertBefore: function(el, o, returnElement) {
  15134. return this.doInsert(el, o, returnElement, 'beforebegin');
  15135. },
  15136. /**
  15137. * Creates new DOM element(s) and inserts them after el.
  15138. * @param {String/HTMLElement/Ext.Element} el The context element
  15139. * @param {Object} o The DOM object spec (and children)
  15140. * @param {Boolean} [returnElement] true to return a Ext.Element
  15141. * @return {HTMLElement/Ext.Element} The new node
  15142. */
  15143. insertAfter: function(el, o, returnElement) {
  15144. return this.doInsert(el, o, returnElement, 'afterend', 'nextSibling');
  15145. },
  15146. /**
  15147. * Creates new DOM element(s) and inserts them as the first child of el.
  15148. * @param {String/HTMLElement/Ext.Element} el The context element
  15149. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  15150. * @param {Boolean} [returnElement] true to return a Ext.Element
  15151. * @return {HTMLElement/Ext.Element} The new node
  15152. */
  15153. insertFirst: function(el, o, returnElement) {
  15154. return this.doInsert(el, o, returnElement, 'afterbegin', 'firstChild');
  15155. },
  15156. /**
  15157. * Creates new DOM element(s) and appends them to el.
  15158. * @param {String/HTMLElement/Ext.Element} el The context element
  15159. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  15160. * @param {Boolean} [returnElement] true to return a Ext.Element
  15161. * @return {HTMLElement/Ext.Element} The new node
  15162. */
  15163. append: function(el, o, returnElement) {
  15164. return this.doInsert(el, o, returnElement, 'beforeend', '', true);
  15165. },
  15166. /**
  15167. * Creates new DOM element(s) and overwrites the contents of el with them.
  15168. * @param {String/HTMLElement/Ext.Element} el The context element
  15169. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  15170. * @param {Boolean} [returnElement] true to return a Ext.Element
  15171. * @return {HTMLElement/Ext.Element} The new node
  15172. */
  15173. overwrite: function(el, o, returnElement) {
  15174. el = Ext.getDom(el);
  15175. el.innerHTML = this.markup(o);
  15176. return returnElement ? Ext.get(el.firstChild) : el.firstChild;
  15177. },
  15178. doInsert: function(el, o, returnElement, pos, sibling, append) {
  15179. var newNode = this.insertHtml(pos, Ext.getDom(el), this.markup(o));
  15180. return returnElement ? Ext.get(newNode, true) : newNode;
  15181. }
  15182. });
  15183. //@tag dom,core
  15184. //@require AbstractHelper.js
  15185. //@require Ext.Supports
  15186. //@require Ext.EventManager
  15187. //@define Ext.dom.AbstractElement
  15188. /**
  15189. * @class Ext.dom.AbstractElement
  15190. * @extend Ext.Base
  15191. * @private
  15192. */
  15193. (function() {
  15194. var document = window.document,
  15195. trimRe = /^\s+|\s+$/g,
  15196. whitespaceRe = /\s/;
  15197. if (!Ext.cache){
  15198. Ext.cache = {};
  15199. }
  15200. Ext.define('Ext.dom.AbstractElement', {
  15201. inheritableStatics: {
  15202. /**
  15203. * Retrieves Ext.dom.Element objects. {@link Ext#get} is alias for {@link Ext.dom.Element#get}.
  15204. *
  15205. * **This method does not retrieve {@link Ext.Component Component}s.** This method retrieves Ext.dom.Element
  15206. * objects which encapsulate DOM elements. To retrieve a Component by its ID, use {@link Ext.ComponentManager#get}.
  15207. *
  15208. * Uses simple caching to consistently return the same object. Automatically fixes if an object was recreated with
  15209. * the same id via AJAX or DOM.
  15210. *
  15211. * @param {String/HTMLElement/Ext.Element} el The id of the node, a DOM Node or an existing Element.
  15212. * @return {Ext.dom.Element} The Element object (or null if no matching element was found)
  15213. * @static
  15214. * @inheritable
  15215. */
  15216. get: function(el) {
  15217. var me = this,
  15218. El = Ext.dom.Element,
  15219. cacheItem,
  15220. extEl,
  15221. dom,
  15222. id;
  15223. if (!el) {
  15224. return null;
  15225. }
  15226. if (typeof el == "string") { // element id
  15227. if (el == Ext.windowId) {
  15228. return El.get(window);
  15229. } else if (el == Ext.documentId) {
  15230. return El.get(document);
  15231. }
  15232. cacheItem = Ext.cache[el];
  15233. // This code is here to catch the case where we've got a reference to a document of an iframe
  15234. // It getElementById will fail because it's not part of the document, so if we're skipping
  15235. // GC it means it's a window/document object that isn't the default window/document, which we have
  15236. // already handled above
  15237. if (cacheItem && cacheItem.skipGarbageCollection) {
  15238. extEl = cacheItem.el;
  15239. return extEl;
  15240. }
  15241. if (!(dom = document.getElementById(el))) {
  15242. return null;
  15243. }
  15244. if (cacheItem && cacheItem.el) {
  15245. extEl = Ext.updateCacheEntry(cacheItem, dom).el;
  15246. } else {
  15247. // Force new element if there's a cache but no el attached
  15248. extEl = new El(dom, !!cacheItem);
  15249. }
  15250. return extEl;
  15251. } else if (el.tagName) { // dom element
  15252. if (!(id = el.id)) {
  15253. id = Ext.id(el);
  15254. }
  15255. cacheItem = Ext.cache[id];
  15256. if (cacheItem && cacheItem.el) {
  15257. extEl = Ext.updateCacheEntry(cacheItem, el).el;
  15258. } else {
  15259. // Force new element if there's a cache but no el attached
  15260. extEl = new El(el, !!cacheItem);
  15261. }
  15262. return extEl;
  15263. } else if (el instanceof me) {
  15264. if (el != me.docEl && el != me.winEl) {
  15265. id = el.id;
  15266. // refresh dom element in case no longer valid,
  15267. // catch case where it hasn't been appended
  15268. cacheItem = Ext.cache[id];
  15269. if (cacheItem) {
  15270. Ext.updateCacheEntry(cacheItem, document.getElementById(id) || el.dom);
  15271. }
  15272. }
  15273. return el;
  15274. } else if (el.isComposite) {
  15275. return el;
  15276. } else if (Ext.isArray(el)) {
  15277. return me.select(el);
  15278. } else if (el === document) {
  15279. // create a bogus element object representing the document object
  15280. if (!me.docEl) {
  15281. me.docEl = Ext.Object.chain(El.prototype);
  15282. me.docEl.dom = document;
  15283. me.docEl.id = Ext.id(document);
  15284. me.addToCache(me.docEl);
  15285. }
  15286. return me.docEl;
  15287. } else if (el === window) {
  15288. if (!me.winEl) {
  15289. me.winEl = Ext.Object.chain(El.prototype);
  15290. me.winEl.dom = window;
  15291. me.winEl.id = Ext.id(window);
  15292. me.addToCache(me.winEl);
  15293. }
  15294. return me.winEl;
  15295. }
  15296. return null;
  15297. },
  15298. addToCache: function(el, id) {
  15299. if (el) {
  15300. Ext.addCacheEntry(id, el);
  15301. }
  15302. return el;
  15303. },
  15304. addMethods: function() {
  15305. this.override.apply(this, arguments);
  15306. },
  15307. /**
  15308. * <p>Returns an array of unique class names based upon the input strings, or string arrays.</p>
  15309. * <p>The number of parameters is unlimited.</p>
  15310. * <p>Example</p><code><pre>
  15311. // Add x-invalid and x-mandatory classes, do not duplicate
  15312. myElement.dom.className = Ext.core.Element.mergeClsList(this.initialClasses, 'x-invalid x-mandatory');
  15313. </pre></code>
  15314. * @param {Mixed} clsList1 A string of class names, or an array of class names.
  15315. * @param {Mixed} clsList2 A string of class names, or an array of class names.
  15316. * @return {Array} An array of strings representing remaining unique, merged class names. If class names were added to the first list, the <code>changed</code> property will be <code>true</code>.
  15317. * @static
  15318. * @inheritable
  15319. */
  15320. mergeClsList: function() {
  15321. var clsList, clsHash = {},
  15322. i, length, j, listLength, clsName, result = [],
  15323. changed = false;
  15324. for (i = 0, length = arguments.length; i < length; i++) {
  15325. clsList = arguments[i];
  15326. if (Ext.isString(clsList)) {
  15327. clsList = clsList.replace(trimRe, '').split(whitespaceRe);
  15328. }
  15329. if (clsList) {
  15330. for (j = 0, listLength = clsList.length; j < listLength; j++) {
  15331. clsName = clsList[j];
  15332. if (!clsHash[clsName]) {
  15333. if (i) {
  15334. changed = true;
  15335. }
  15336. clsHash[clsName] = true;
  15337. }
  15338. }
  15339. }
  15340. }
  15341. for (clsName in clsHash) {
  15342. result.push(clsName);
  15343. }
  15344. result.changed = changed;
  15345. return result;
  15346. },
  15347. /**
  15348. * <p>Returns an array of unique class names deom the first parameter with all class names
  15349. * from the second parameter removed.</p>
  15350. * <p>Example</p><code><pre>
  15351. // Remove x-invalid and x-mandatory classes if present.
  15352. myElement.dom.className = Ext.core.Element.removeCls(this.initialClasses, 'x-invalid x-mandatory');
  15353. </pre></code>
  15354. * @param {Mixed} existingClsList A string of class names, or an array of class names.
  15355. * @param {Mixed} removeClsList A string of class names, or an array of class names to remove from <code>existingClsList</code>.
  15356. * @return {Array} An array of strings representing remaining class names. If class names were removed, the <code>changed</code> property will be <code>true</code>.
  15357. * @static
  15358. * @inheritable
  15359. */
  15360. removeCls: function(existingClsList, removeClsList) {
  15361. var clsHash = {},
  15362. i, length, clsName, result = [],
  15363. changed = false;
  15364. if (existingClsList) {
  15365. if (Ext.isString(existingClsList)) {
  15366. existingClsList = existingClsList.replace(trimRe, '').split(whitespaceRe);
  15367. }
  15368. for (i = 0, length = existingClsList.length; i < length; i++) {
  15369. clsHash[existingClsList[i]] = true;
  15370. }
  15371. }
  15372. if (removeClsList) {
  15373. if (Ext.isString(removeClsList)) {
  15374. removeClsList = removeClsList.split(whitespaceRe);
  15375. }
  15376. for (i = 0, length = removeClsList.length; i < length; i++) {
  15377. clsName = removeClsList[i];
  15378. if (clsHash[clsName]) {
  15379. changed = true;
  15380. delete clsHash[clsName];
  15381. }
  15382. }
  15383. }
  15384. for (clsName in clsHash) {
  15385. result.push(clsName);
  15386. }
  15387. result.changed = changed;
  15388. return result;
  15389. },
  15390. /**
  15391. * @property
  15392. * Visibility mode constant for use with {@link Ext.dom.Element#setVisibilityMode}.
  15393. * Use the CSS 'visibility' property to hide the element.
  15394. *
  15395. * Note that in this mode, {@link Ext.dom.Element#isVisible isVisible} may return true
  15396. * for an element even though it actually has a parent element that is hidden. For this
  15397. * reason, and in most cases, using the {@link #OFFSETS} mode is a better choice.
  15398. * @static
  15399. * @inheritable
  15400. */
  15401. VISIBILITY: 1,
  15402. /**
  15403. * @property
  15404. * Visibility mode constant for use with {@link Ext.dom.Element#setVisibilityMode}.
  15405. * Use the CSS 'display' property to hide the element.
  15406. * @static
  15407. * @inheritable
  15408. */
  15409. DISPLAY: 2,
  15410. /**
  15411. * @property
  15412. * Visibility mode constant for use with {@link Ext.dom.Element#setVisibilityMode}.
  15413. * Use CSS absolute positioning and top/left offsets to hide the element.
  15414. * @static
  15415. * @inheritable
  15416. */
  15417. OFFSETS: 3,
  15418. /**
  15419. * @property
  15420. * Visibility mode constant for use with {@link Ext.dom.Element#setVisibilityMode}.
  15421. * Add or remove the {@link Ext.Layer#visibilityCls} class to hide the element.
  15422. * @static
  15423. * @inheritable
  15424. */
  15425. ASCLASS: 4
  15426. },
  15427. constructor: function(element, forceNew) {
  15428. var me = this,
  15429. dom = typeof element == 'string'
  15430. ? document.getElementById(element)
  15431. : element,
  15432. id;
  15433. if (!dom) {
  15434. return null;
  15435. }
  15436. id = dom.id;
  15437. if (!forceNew && id && Ext.cache[id]) {
  15438. // element object already exists
  15439. return Ext.cache[id].el;
  15440. }
  15441. /**
  15442. * @property {HTMLElement} dom
  15443. * The DOM element
  15444. */
  15445. me.dom = dom;
  15446. /**
  15447. * @property {String} id
  15448. * The DOM element ID
  15449. */
  15450. me.id = id || Ext.id(dom);
  15451. me.self.addToCache(me);
  15452. },
  15453. /**
  15454. * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
  15455. * @param {Object} o The object with the attributes
  15456. * @param {Boolean} [useSet=true] false to override the default setAttribute to use expandos.
  15457. * @return {Ext.dom.Element} this
  15458. */
  15459. set: function(o, useSet) {
  15460. var el = this.dom,
  15461. attr,
  15462. value;
  15463. for (attr in o) {
  15464. if (o.hasOwnProperty(attr)) {
  15465. value = o[attr];
  15466. if (attr == 'style') {
  15467. this.applyStyles(value);
  15468. }
  15469. else if (attr == 'cls') {
  15470. el.className = value;
  15471. }
  15472. else if (useSet !== false) {
  15473. if (value === undefined) {
  15474. el.removeAttribute(attr);
  15475. } else {
  15476. el.setAttribute(attr, value);
  15477. }
  15478. }
  15479. else {
  15480. el[attr] = value;
  15481. }
  15482. }
  15483. }
  15484. return this;
  15485. },
  15486. /**
  15487. * @property {String} defaultUnit
  15488. * The default unit to append to CSS values where a unit isn't provided.
  15489. */
  15490. defaultUnit: "px",
  15491. /**
  15492. * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
  15493. * @param {String} selector The simple selector to test
  15494. * @return {Boolean} True if this element matches the selector, else false
  15495. */
  15496. is: function(simpleSelector) {
  15497. return Ext.DomQuery.is(this.dom, simpleSelector);
  15498. },
  15499. /**
  15500. * Returns the value of the "value" attribute
  15501. * @param {Boolean} asNumber true to parse the value as a number
  15502. * @return {String/Number}
  15503. */
  15504. getValue: function(asNumber) {
  15505. var val = this.dom.value;
  15506. return asNumber ? parseInt(val, 10) : val;
  15507. },
  15508. /**
  15509. * Removes this element's dom reference. Note that event and cache removal is handled at {@link Ext#removeNode
  15510. * Ext.removeNode}
  15511. */
  15512. remove: function() {
  15513. var me = this,
  15514. dom = me.dom;
  15515. if (dom) {
  15516. Ext.removeNode(dom);
  15517. delete me.dom;
  15518. }
  15519. },
  15520. /**
  15521. * Returns true if this element is an ancestor of the passed element
  15522. * @param {HTMLElement/String} el The element to check
  15523. * @return {Boolean} True if this element is an ancestor of el, else false
  15524. */
  15525. contains: function(el) {
  15526. if (!el) {
  15527. return false;
  15528. }
  15529. var me = this,
  15530. dom = el.dom || el;
  15531. // we need el-contains-itself logic here because isAncestor does not do that:
  15532. return (dom === me.dom) || Ext.dom.AbstractElement.isAncestor(me.dom, dom);
  15533. },
  15534. /**
  15535. * Returns the value of an attribute from the element's underlying DOM node.
  15536. * @param {String} name The attribute name
  15537. * @param {String} [namespace] The namespace in which to look for the attribute
  15538. * @return {String} The attribute value
  15539. */
  15540. getAttribute: function(name, ns) {
  15541. var dom = this.dom;
  15542. return dom.getAttributeNS(ns, name) || dom.getAttribute(ns + ":" + name) || dom.getAttribute(name) || dom[name];
  15543. },
  15544. /**
  15545. * Update the innerHTML of this element
  15546. * @param {String} html The new HTML
  15547. * @return {Ext.dom.Element} this
  15548. */
  15549. update: function(html) {
  15550. if (this.dom) {
  15551. this.dom.innerHTML = html;
  15552. }
  15553. return this;
  15554. },
  15555. /**
  15556. * Set the innerHTML of this element
  15557. * @param {String} html The new HTML
  15558. * @return {Ext.Element} this
  15559. */
  15560. setHTML: function(html) {
  15561. if(this.dom) {
  15562. this.dom.innerHTML = html;
  15563. }
  15564. return this;
  15565. },
  15566. /**
  15567. * Returns the innerHTML of an Element or an empty string if the element's
  15568. * dom no longer exists.
  15569. */
  15570. getHTML: function() {
  15571. return this.dom ? this.dom.innerHTML : '';
  15572. },
  15573. /**
  15574. * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
  15575. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  15576. * @return {Ext.Element} this
  15577. */
  15578. hide: function() {
  15579. this.setVisible(false);
  15580. return this;
  15581. },
  15582. /**
  15583. * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
  15584. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  15585. * @return {Ext.Element} this
  15586. */
  15587. show: function() {
  15588. this.setVisible(true);
  15589. return this;
  15590. },
  15591. /**
  15592. * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
  15593. * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
  15594. * @param {Boolean} visible Whether the element is visible
  15595. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  15596. * @return {Ext.Element} this
  15597. */
  15598. setVisible: function(visible, animate) {
  15599. var me = this,
  15600. statics = me.self,
  15601. mode = me.getVisibilityMode(),
  15602. prefix = Ext.baseCSSPrefix;
  15603. switch (mode) {
  15604. case statics.VISIBILITY:
  15605. me.removeCls([prefix + 'hidden-display', prefix + 'hidden-offsets']);
  15606. me[visible ? 'removeCls' : 'addCls'](prefix + 'hidden-visibility');
  15607. break;
  15608. case statics.DISPLAY:
  15609. me.removeCls([prefix + 'hidden-visibility', prefix + 'hidden-offsets']);
  15610. me[visible ? 'removeCls' : 'addCls'](prefix + 'hidden-display');
  15611. break;
  15612. case statics.OFFSETS:
  15613. me.removeCls([prefix + 'hidden-visibility', prefix + 'hidden-display']);
  15614. me[visible ? 'removeCls' : 'addCls'](prefix + 'hidden-offsets');
  15615. break;
  15616. }
  15617. return me;
  15618. },
  15619. getVisibilityMode: function() {
  15620. // Only flyweights won't have a $cache object, by calling getCache the cache
  15621. // will be created for future accesses. As such, we're eliminating the method
  15622. // call since it's mostly redundant
  15623. var data = (this.$cache || this.getCache()).data,
  15624. visMode = data.visibilityMode;
  15625. if (visMode === undefined) {
  15626. data.visibilityMode = visMode = this.self.DISPLAY;
  15627. }
  15628. return visMode;
  15629. },
  15630. /**
  15631. * Use this to change the visibility mode between {@link #VISIBILITY}, {@link #DISPLAY}, {@link #OFFSETS} or {@link #ASCLASS}.
  15632. */
  15633. setVisibilityMode: function(mode) {
  15634. (this.$cache || this.getCache()).data.visibilityMode = mode;
  15635. return this;
  15636. },
  15637. getCache: function() {
  15638. var me = this,
  15639. id = me.dom.id || Ext.id(me.dom);
  15640. // Note that we do not assign an ID to the calling object here.
  15641. // An Ext.dom.Element will have one assigned at construction, and an Ext.dom.AbstractElement.Fly must not have one.
  15642. // We assign an ID to the DOM element if it does not have one.
  15643. me.$cache = Ext.cache[id] || Ext.addCacheEntry(id, null, me.dom);
  15644. return me.$cache;
  15645. }
  15646. }, function() {
  15647. var AbstractElement = this;
  15648. /**
  15649. * @private
  15650. * @member Ext
  15651. */
  15652. Ext.getDetachedBody = function () {
  15653. var detachedEl = AbstractElement.detachedBodyEl;
  15654. if (!detachedEl) {
  15655. detachedEl = document.createElement('div');
  15656. AbstractElement.detachedBodyEl = detachedEl = new AbstractElement.Fly(detachedEl);
  15657. detachedEl.isDetachedBody = true;
  15658. }
  15659. return detachedEl;
  15660. };
  15661. /**
  15662. * @private
  15663. * @member Ext
  15664. */
  15665. Ext.getElementById = function (id) {
  15666. var el = document.getElementById(id),
  15667. detachedBodyEl;
  15668. if (!el && (detachedBodyEl = AbstractElement.detachedBodyEl)) {
  15669. el = detachedBodyEl.dom.querySelector('#' + Ext.escapeId(id));
  15670. }
  15671. return el;
  15672. };
  15673. /**
  15674. * @member Ext
  15675. * @method get
  15676. * @inheritdoc Ext.dom.Element#get
  15677. */
  15678. Ext.get = function(el) {
  15679. return Ext.dom.Element.get(el);
  15680. };
  15681. this.addStatics({
  15682. /**
  15683. * @class Ext.dom.AbstractElement.Fly
  15684. * @extends Ext.dom.AbstractElement
  15685. *
  15686. * A non-persistent wrapper for a DOM element which may be used to execute methods of {@link Ext.dom.Element}
  15687. * upon a DOM element without creating an instance of {@link Ext.dom.Element}.
  15688. *
  15689. * A **singleton** instance of this class is returned when you use {@link Ext#fly}
  15690. *
  15691. * Because it is a singleton, this Flyweight does not have an ID, and must be used and discarded in a single line.
  15692. * You should not keep and use the reference to this singleton over multiple lines because methods that you call
  15693. * may themselves make use of {@link Ext#fly} and may change the DOM element to which the instance refers.
  15694. */
  15695. Fly: new Ext.Class({
  15696. extend: AbstractElement,
  15697. /**
  15698. * @property {Boolean} isFly
  15699. * This is `true` to identify Element flyweights
  15700. */
  15701. isFly: true,
  15702. constructor: function(dom) {
  15703. this.dom = dom;
  15704. },
  15705. /**
  15706. * @private
  15707. * Attach this fliyweight instance to the passed DOM element.
  15708. *
  15709. * Note that a flightweight does **not** have an ID, and does not acquire the ID of the DOM element.
  15710. */
  15711. attach: function (dom) {
  15712. // Attach to the passed DOM element. The same code as in Ext.Fly
  15713. this.dom = dom;
  15714. // Use cached data if there is existing cached data for the referenced DOM element,
  15715. // otherwise it will be created when needed by getCache.
  15716. this.$cache = dom.id ? Ext.cache[dom.id] : null;
  15717. return this;
  15718. }
  15719. }),
  15720. _flyweights: {},
  15721. /**
  15722. * Gets the singleton {@link Ext.dom.AbstractElement.Fly flyweight} element, with the passed node as the active element.
  15723. *
  15724. * Because it is a singleton, this Flyweight does not have an ID, and must be used and discarded in a single line.
  15725. * You may not keep and use the reference to this singleton over multiple lines because methods that you call
  15726. * may themselves make use of {@link Ext#fly} and may change the DOM element to which the instance refers.
  15727. *
  15728. * {@link Ext#fly} is alias for {@link Ext.dom.AbstractElement#fly}.
  15729. *
  15730. * Use this to make one-time references to DOM elements which are not going to be accessed again either by
  15731. * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link
  15732. * Ext#get Ext.get} will be more appropriate to take advantage of the caching provided by the Ext.dom.Element
  15733. * class.
  15734. *
  15735. * @param {String/HTMLElement} dom The dom node or id
  15736. * @param {String} [named] Allows for creation of named reusable flyweights to prevent conflicts (e.g.
  15737. * internally Ext uses "_global")
  15738. * @return {Ext.dom.AbstractElement.Fly} The singleton flyweight object (or null if no matching element was found)
  15739. * @static
  15740. * @member Ext.dom.AbstractElement
  15741. */
  15742. fly: function(dom, named) {
  15743. var fly = null,
  15744. _flyweights = AbstractElement._flyweights;
  15745. named = named || '_global';
  15746. dom = Ext.getDom(dom);
  15747. if (dom) {
  15748. fly = _flyweights[named] || (_flyweights[named] = new AbstractElement.Fly());
  15749. // Attach to the passed DOM element.
  15750. // This code performs the same function as Fly.attach, but inline it for efficiency
  15751. fly.dom = dom;
  15752. // Use cached data if there is existing cached data for the referenced DOM element,
  15753. // otherwise it will be created when needed by getCache.
  15754. fly.$cache = dom.id ? Ext.cache[dom.id] : null;
  15755. }
  15756. return fly;
  15757. }
  15758. });
  15759. /**
  15760. * @member Ext
  15761. * @method fly
  15762. * @inheritdoc Ext.dom.AbstractElement#fly
  15763. */
  15764. Ext.fly = function() {
  15765. return AbstractElement.fly.apply(AbstractElement, arguments);
  15766. };
  15767. (function (proto) {
  15768. /**
  15769. * @method destroy
  15770. * @member Ext.dom.AbstractElement
  15771. * @inheritdoc Ext.dom.AbstractElement#remove
  15772. * Alias to {@link #remove}.
  15773. */
  15774. proto.destroy = proto.remove;
  15775. /**
  15776. * Returns a child element of this element given its `id`.
  15777. * @method getById
  15778. * @member Ext.dom.AbstractElement
  15779. * @param {String} id The id of the desired child element.
  15780. * @param {Boolean} [asDom=false] True to return the DOM element, false to return a
  15781. * wrapped Element object.
  15782. */
  15783. if (document.querySelector) {
  15784. proto.getById = function (id, asDom) {
  15785. // for normal elements getElementById is the best solution, but if the el is
  15786. // not part of the document.body, we have to resort to querySelector
  15787. var dom = document.getElementById(id) ||
  15788. this.dom.querySelector('#'+Ext.escapeId(id));
  15789. return asDom ? dom : (dom ? Ext.get(dom) : null);
  15790. };
  15791. } else {
  15792. proto.getById = function (id, asDom) {
  15793. var dom = document.getElementById(id);
  15794. return asDom ? dom : (dom ? Ext.get(dom) : null);
  15795. };
  15796. }
  15797. }(this.prototype));
  15798. });
  15799. }());
  15800. //@tag dom,core
  15801. //@require AbstractElement.js
  15802. //@define Ext.dom.AbstractElement-static
  15803. //@define Ext.dom.AbstractElement
  15804. /**
  15805. * @class Ext.dom.AbstractElement
  15806. */
  15807. Ext.dom.AbstractElement.addInheritableStatics({
  15808. unitRe: /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i,
  15809. camelRe: /(-[a-z])/gi,
  15810. cssRe: /([a-z0-9\-]+)\s*:\s*([^;\s]+(?:\s*[^;\s]+)*);?/gi,
  15811. opacityRe: /alpha\(opacity=(.*)\)/i,
  15812. propertyCache: {},
  15813. defaultUnit : "px",
  15814. borders: {l: 'border-left-width', r: 'border-right-width', t: 'border-top-width', b: 'border-bottom-width'},
  15815. paddings: {l: 'padding-left', r: 'padding-right', t: 'padding-top', b: 'padding-bottom'},
  15816. margins: {l: 'margin-left', r: 'margin-right', t: 'margin-top', b: 'margin-bottom'},
  15817. /**
  15818. * Test if size has a unit, otherwise appends the passed unit string, or the default for this Element.
  15819. * @param size {Object} The size to set
  15820. * @param units {String} The units to append to a numeric size value
  15821. * @private
  15822. * @static
  15823. */
  15824. addUnits: function(size, units) {
  15825. // Most common case first: Size is set to a number
  15826. if (typeof size == 'number') {
  15827. return size + (units || this.defaultUnit || 'px');
  15828. }
  15829. // Size set to a value which means "auto"
  15830. if (size === "" || size == "auto" || size === undefined || size === null) {
  15831. return size || '';
  15832. }
  15833. // Otherwise, warn if it's not a valid CSS measurement
  15834. if (!this.unitRe.test(size)) {
  15835. if (Ext.isDefined(Ext.global.console)) {
  15836. Ext.global.console.warn("Warning, size detected as NaN on Element.addUnits.");
  15837. }
  15838. return size || '';
  15839. }
  15840. return size;
  15841. },
  15842. /**
  15843. * @static
  15844. * @private
  15845. */
  15846. isAncestor: function(p, c) {
  15847. var ret = false;
  15848. p = Ext.getDom(p);
  15849. c = Ext.getDom(c);
  15850. if (p && c) {
  15851. if (p.contains) {
  15852. return p.contains(c);
  15853. } else if (p.compareDocumentPosition) {
  15854. return !!(p.compareDocumentPosition(c) & 16);
  15855. } else {
  15856. while ((c = c.parentNode)) {
  15857. ret = c == p || ret;
  15858. }
  15859. }
  15860. }
  15861. return ret;
  15862. },
  15863. /**
  15864. * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations
  15865. * (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result)
  15866. * @static
  15867. * @param {Number/String} box The encoded margins
  15868. * @return {Object} An object with margin sizes for top, right, bottom and left
  15869. */
  15870. parseBox: function(box) {
  15871. if (typeof box != 'string') {
  15872. box = box.toString();
  15873. }
  15874. var parts = box.split(' '),
  15875. ln = parts.length;
  15876. if (ln == 1) {
  15877. parts[1] = parts[2] = parts[3] = parts[0];
  15878. }
  15879. else if (ln == 2) {
  15880. parts[2] = parts[0];
  15881. parts[3] = parts[1];
  15882. }
  15883. else if (ln == 3) {
  15884. parts[3] = parts[1];
  15885. }
  15886. return {
  15887. top :parseFloat(parts[0]) || 0,
  15888. right :parseFloat(parts[1]) || 0,
  15889. bottom:parseFloat(parts[2]) || 0,
  15890. left :parseFloat(parts[3]) || 0
  15891. };
  15892. },
  15893. /**
  15894. * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations
  15895. * (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result)
  15896. * @static
  15897. * @param {Number/String} box The encoded margins
  15898. * @param {String} units The type of units to add
  15899. * @return {String} An string with unitized (px if units is not specified) metrics for top, right, bottom and left
  15900. */
  15901. unitizeBox: function(box, units) {
  15902. var a = this.addUnits,
  15903. b = this.parseBox(box);
  15904. return a(b.top, units) + ' ' +
  15905. a(b.right, units) + ' ' +
  15906. a(b.bottom, units) + ' ' +
  15907. a(b.left, units);
  15908. },
  15909. // private
  15910. camelReplaceFn: function(m, a) {
  15911. return a.charAt(1).toUpperCase();
  15912. },
  15913. /**
  15914. * Normalizes CSS property keys from dash delimited to camel case JavaScript Syntax.
  15915. * For example:
  15916. *
  15917. * - border-width -> borderWidth
  15918. * - padding-top -> paddingTop
  15919. *
  15920. * @static
  15921. * @param {String} prop The property to normalize
  15922. * @return {String} The normalized string
  15923. */
  15924. normalize: function(prop) {
  15925. // TODO: Mobile optimization?
  15926. if (prop == 'float') {
  15927. prop = Ext.supports.Float ? 'cssFloat' : 'styleFloat';
  15928. }
  15929. return this.propertyCache[prop] || (this.propertyCache[prop] = prop.replace(this.camelRe, this.camelReplaceFn));
  15930. },
  15931. /**
  15932. * Retrieves the document height
  15933. * @static
  15934. * @return {Number} documentHeight
  15935. */
  15936. getDocumentHeight: function() {
  15937. return Math.max(!Ext.isStrict ? document.body.scrollHeight : document.documentElement.scrollHeight, this.getViewportHeight());
  15938. },
  15939. /**
  15940. * Retrieves the document width
  15941. * @static
  15942. * @return {Number} documentWidth
  15943. */
  15944. getDocumentWidth: function() {
  15945. return Math.max(!Ext.isStrict ? document.body.scrollWidth : document.documentElement.scrollWidth, this.getViewportWidth());
  15946. },
  15947. /**
  15948. * Retrieves the viewport height of the window.
  15949. * @static
  15950. * @return {Number} viewportHeight
  15951. */
  15952. getViewportHeight: function(){
  15953. return window.innerHeight;
  15954. },
  15955. /**
  15956. * Retrieves the viewport width of the window.
  15957. * @static
  15958. * @return {Number} viewportWidth
  15959. */
  15960. getViewportWidth: function() {
  15961. return window.innerWidth;
  15962. },
  15963. /**
  15964. * Retrieves the viewport size of the window.
  15965. * @static
  15966. * @return {Object} object containing width and height properties
  15967. */
  15968. getViewSize: function() {
  15969. return {
  15970. width: window.innerWidth,
  15971. height: window.innerHeight
  15972. };
  15973. },
  15974. /**
  15975. * Retrieves the current orientation of the window. This is calculated by
  15976. * determing if the height is greater than the width.
  15977. * @static
  15978. * @return {String} Orientation of window: 'portrait' or 'landscape'
  15979. */
  15980. getOrientation: function() {
  15981. if (Ext.supports.OrientationChange) {
  15982. return (window.orientation == 0) ? 'portrait' : 'landscape';
  15983. }
  15984. return (window.innerHeight > window.innerWidth) ? 'portrait' : 'landscape';
  15985. },
  15986. /**
  15987. * Returns the top Element that is located at the passed coordinates
  15988. * @static
  15989. * @param {Number} x The x coordinate
  15990. * @param {Number} y The y coordinate
  15991. * @return {String} The found Element
  15992. */
  15993. fromPoint: function(x, y) {
  15994. return Ext.get(document.elementFromPoint(x, y));
  15995. },
  15996. /**
  15997. * Converts a CSS string into an object with a property for each style.
  15998. *
  15999. * The sample code below would return an object with 2 properties, one
  16000. * for background-color and one for color.
  16001. *
  16002. * var css = 'background-color: red;color: blue; ';
  16003. * console.log(Ext.dom.Element.parseStyles(css));
  16004. *
  16005. * @static
  16006. * @param {String} styles A CSS string
  16007. * @return {Object} styles
  16008. */
  16009. parseStyles: function(styles){
  16010. var out = {},
  16011. cssRe = this.cssRe,
  16012. matches;
  16013. if (styles) {
  16014. // Since we're using the g flag on the regex, we need to set the lastIndex.
  16015. // This automatically happens on some implementations, but not others, see:
  16016. // http://stackoverflow.com/questions/2645273/javascript-regular-expression-literal-persists-between-function-calls
  16017. // http://blog.stevenlevithan.com/archives/fixing-javascript-regexp
  16018. cssRe.lastIndex = 0;
  16019. while ((matches = cssRe.exec(styles))) {
  16020. out[matches[1]] = matches[2];
  16021. }
  16022. }
  16023. return out;
  16024. }
  16025. });
  16026. //TODO Need serious cleanups
  16027. (function(){
  16028. var doc = document,
  16029. AbstractElement = Ext.dom.AbstractElement,
  16030. activeElement = null,
  16031. isCSS1 = doc.compatMode == "CSS1Compat",
  16032. flyInstance,
  16033. fly = function (el) {
  16034. if (!flyInstance) {
  16035. flyInstance = new AbstractElement.Fly();
  16036. }
  16037. flyInstance.attach(el);
  16038. return flyInstance;
  16039. };
  16040. // If the browser does not support document.activeElement we need some assistance.
  16041. // This covers old Safari 3.2 (4.0 added activeElement along with just about all
  16042. // other browsers). We need this support to handle issues with old Safari.
  16043. if (!('activeElement' in doc) && doc.addEventListener) {
  16044. doc.addEventListener('focus',
  16045. function (ev) {
  16046. if (ev && ev.target) {
  16047. activeElement = (ev.target == doc) ? null : ev.target;
  16048. }
  16049. }, true);
  16050. }
  16051. /*
  16052. * Helper function to create the function that will restore the selection.
  16053. */
  16054. function makeSelectionRestoreFn (activeEl, start, end) {
  16055. return function () {
  16056. activeEl.selectionStart = start;
  16057. activeEl.selectionEnd = end;
  16058. };
  16059. }
  16060. AbstractElement.addInheritableStatics({
  16061. /**
  16062. * Returns the active element in the DOM. If the browser supports activeElement
  16063. * on the document, this is returned. If not, the focus is tracked and the active
  16064. * element is maintained internally.
  16065. * @return {HTMLElement} The active (focused) element in the document.
  16066. */
  16067. getActiveElement: function () {
  16068. return doc.activeElement || activeElement;
  16069. },
  16070. /**
  16071. * Creates a function to call to clean up problems with the work-around for the
  16072. * WebKit RightMargin bug. The work-around is to add "display: 'inline-block'" to
  16073. * the element before calling getComputedStyle and then to restore its original
  16074. * display value. The problem with this is that it corrupts the selection of an
  16075. * INPUT or TEXTAREA element (as in the "I-beam" goes away but ths focus remains).
  16076. * To cleanup after this, we need to capture the selection of any such element and
  16077. * then restore it after we have restored the display style.
  16078. *
  16079. * @param {Ext.dom.Element} target The top-most element being adjusted.
  16080. * @private
  16081. */
  16082. getRightMarginFixCleaner: function (target) {
  16083. var supports = Ext.supports,
  16084. hasInputBug = supports.DisplayChangeInputSelectionBug,
  16085. hasTextAreaBug = supports.DisplayChangeTextAreaSelectionBug,
  16086. activeEl,
  16087. tag,
  16088. start,
  16089. end;
  16090. if (hasInputBug || hasTextAreaBug) {
  16091. activeEl = doc.activeElement || activeElement; // save a call
  16092. tag = activeEl && activeEl.tagName;
  16093. if ((hasTextAreaBug && tag == 'TEXTAREA') ||
  16094. (hasInputBug && tag == 'INPUT' && activeEl.type == 'text')) {
  16095. if (Ext.dom.Element.isAncestor(target, activeEl)) {
  16096. start = activeEl.selectionStart;
  16097. end = activeEl.selectionEnd;
  16098. if (Ext.isNumber(start) && Ext.isNumber(end)) { // to be safe...
  16099. // We don't create the raw closure here inline because that
  16100. // will be costly even if we don't want to return it (nested
  16101. // function decls and exprs are often instantiated on entry
  16102. // regardless of whether execution ever reaches them):
  16103. return makeSelectionRestoreFn(activeEl, start, end);
  16104. }
  16105. }
  16106. }
  16107. }
  16108. return Ext.emptyFn; // avoid special cases, just return a nop
  16109. },
  16110. getViewWidth: function(full) {
  16111. return full ? Ext.dom.Element.getDocumentWidth() : Ext.dom.Element.getViewportWidth();
  16112. },
  16113. getViewHeight: function(full) {
  16114. return full ? Ext.dom.Element.getDocumentHeight() : Ext.dom.Element.getViewportHeight();
  16115. },
  16116. getDocumentHeight: function() {
  16117. return Math.max(!isCSS1 ? doc.body.scrollHeight : doc.documentElement.scrollHeight, Ext.dom.Element.getViewportHeight());
  16118. },
  16119. getDocumentWidth: function() {
  16120. return Math.max(!isCSS1 ? doc.body.scrollWidth : doc.documentElement.scrollWidth, Ext.dom.Element.getViewportWidth());
  16121. },
  16122. getViewportHeight: function(){
  16123. return Ext.isIE ?
  16124. (Ext.isStrict ? doc.documentElement.clientHeight : doc.body.clientHeight) :
  16125. self.innerHeight;
  16126. },
  16127. getViewportWidth: function() {
  16128. return (!Ext.isStrict && !Ext.isOpera) ? doc.body.clientWidth :
  16129. Ext.isIE ? doc.documentElement.clientWidth : self.innerWidth;
  16130. },
  16131. getY: function(el) {
  16132. return Ext.dom.Element.getXY(el)[1];
  16133. },
  16134. getX: function(el) {
  16135. return Ext.dom.Element.getXY(el)[0];
  16136. },
  16137. getXY: function(el) {
  16138. var bd = doc.body,
  16139. docEl = doc.documentElement,
  16140. leftBorder = 0,
  16141. topBorder = 0,
  16142. ret = [0,0],
  16143. round = Math.round,
  16144. box,
  16145. scroll;
  16146. el = Ext.getDom(el);
  16147. if(el != doc && el != bd){
  16148. // IE has the potential to throw when getBoundingClientRect called
  16149. // on element not attached to dom
  16150. if (Ext.isIE) {
  16151. try {
  16152. box = el.getBoundingClientRect();
  16153. // In some versions of IE, the documentElement (HTML element) will have a 2px border that gets included, so subtract it off
  16154. topBorder = docEl.clientTop || bd.clientTop;
  16155. leftBorder = docEl.clientLeft || bd.clientLeft;
  16156. } catch (ex) {
  16157. box = { left: 0, top: 0 };
  16158. }
  16159. } else {
  16160. box = el.getBoundingClientRect();
  16161. }
  16162. scroll = fly(document).getScroll();
  16163. ret = [round(box.left + scroll.left - leftBorder), round(box.top + scroll.top - topBorder)];
  16164. }
  16165. return ret;
  16166. },
  16167. setXY: function(el, xy) {
  16168. (el = Ext.fly(el, '_setXY')).position();
  16169. var pts = el.translatePoints(xy),
  16170. style = el.dom.style,
  16171. pos;
  16172. for (pos in pts) {
  16173. if (!isNaN(pts[pos])) {
  16174. style[pos] = pts[pos] + "px";
  16175. }
  16176. }
  16177. },
  16178. setX: function(el, x) {
  16179. Ext.dom.Element.setXY(el, [x, false]);
  16180. },
  16181. setY: function(el, y) {
  16182. Ext.dom.Element.setXY(el, [false, y]);
  16183. },
  16184. /**
  16185. * Serializes a DOM form into a url encoded string
  16186. * @param {Object} form The form
  16187. * @return {String} The url encoded form
  16188. */
  16189. serializeForm: function(form) {
  16190. var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements,
  16191. hasSubmit = false,
  16192. encoder = encodeURIComponent,
  16193. data = '',
  16194. eLen = fElements.length,
  16195. element, name, type, options, hasValue, e,
  16196. o, oLen, opt;
  16197. for (e = 0; e < eLen; e++) {
  16198. element = fElements[e];
  16199. name = element.name;
  16200. type = element.type;
  16201. options = element.options;
  16202. if (!element.disabled && name) {
  16203. if (/select-(one|multiple)/i.test(type)) {
  16204. oLen = options.length;
  16205. for (o = 0; o < oLen; o++) {
  16206. opt = options[o];
  16207. if (opt.selected) {
  16208. hasValue = opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttributeNode('value').specified;
  16209. data += Ext.String.format("{0}={1}&", encoder(name), encoder(hasValue ? opt.value : opt.text));
  16210. }
  16211. }
  16212. } else if (!(/file|undefined|reset|button/i.test(type))) {
  16213. if (!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)) {
  16214. data += encoder(name) + '=' + encoder(element.value) + '&';
  16215. hasSubmit = /submit/i.test(type);
  16216. }
  16217. }
  16218. }
  16219. }
  16220. return data.substr(0, data.length - 1);
  16221. }
  16222. });
  16223. }());
  16224. //@tag dom,core
  16225. //@require Ext.dom.AbstractElement-static
  16226. //@define Ext.dom.AbstractElement-alignment
  16227. /**
  16228. * @class Ext.dom.AbstractElement
  16229. */
  16230. Ext.dom.AbstractElement.override({
  16231. /**
  16232. * Gets the x,y coordinates specified by the anchor position on the element.
  16233. * @param {String} [anchor] The specified anchor position (defaults to "c"). See {@link Ext.dom.Element#alignTo}
  16234. * for details on supported anchor positions.
  16235. * @param {Boolean} [local] True to get the local (element top/left-relative) anchor position instead
  16236. * of page coordinates
  16237. * @param {Object} [size] An object containing the size to use for calculating anchor position
  16238. * {width: (target width), height: (target height)} (defaults to the element's current size)
  16239. * @return {Array} [x, y] An array containing the element's x and y coordinates
  16240. */
  16241. getAnchorXY: function(anchor, local, size) {
  16242. //Passing a different size is useful for pre-calculating anchors,
  16243. //especially for anchored animations that change the el size.
  16244. anchor = (anchor || "tl").toLowerCase();
  16245. size = size || {};
  16246. var me = this,
  16247. vp = me.dom == document.body || me.dom == document,
  16248. width = size.width || vp ? window.innerWidth: me.getWidth(),
  16249. height = size.height || vp ? window.innerHeight: me.getHeight(),
  16250. xy,
  16251. rnd = Math.round,
  16252. myXY = me.getXY(),
  16253. extraX = vp ? 0: !local ? myXY[0] : 0,
  16254. extraY = vp ? 0: !local ? myXY[1] : 0,
  16255. hash = {
  16256. c: [rnd(width * 0.5), rnd(height * 0.5)],
  16257. t: [rnd(width * 0.5), 0],
  16258. l: [0, rnd(height * 0.5)],
  16259. r: [width, rnd(height * 0.5)],
  16260. b: [rnd(width * 0.5), height],
  16261. tl: [0, 0],
  16262. bl: [0, height],
  16263. br: [width, height],
  16264. tr: [width, 0]
  16265. };
  16266. xy = hash[anchor];
  16267. return [xy[0] + extraX, xy[1] + extraY];
  16268. },
  16269. alignToRe: /^([a-z]+)-([a-z]+)(\?)?$/,
  16270. /**
  16271. * Gets the x,y coordinates to align this element with another element. See {@link Ext.dom.Element#alignTo} for more info on the
  16272. * supported position values.
  16273. * @param {Ext.Element/HTMLElement/String} element The element to align to.
  16274. * @param {String} [position="tl-bl?"] The position to align to.
  16275. * @param {Array} [offsets=[0,0]] Offset the positioning by [x, y]
  16276. * @return {Array} [x, y]
  16277. */
  16278. getAlignToXY: function(el, position, offsets, local) {
  16279. local = !!local;
  16280. el = Ext.get(el);
  16281. if (!el || !el.dom) {
  16282. throw new Error("Element.alignToXY with an element that doesn't exist");
  16283. }
  16284. offsets = offsets || [0, 0];
  16285. if (!position || position == '?') {
  16286. position = 'tl-bl?';
  16287. }
  16288. else if (! (/-/).test(position) && position !== "") {
  16289. position = 'tl-' + position;
  16290. }
  16291. position = position.toLowerCase();
  16292. var me = this,
  16293. matches = position.match(this.alignToRe),
  16294. dw = window.innerWidth,
  16295. dh = window.innerHeight,
  16296. p1 = "",
  16297. p2 = "",
  16298. a1,
  16299. a2,
  16300. x,
  16301. y,
  16302. swapX,
  16303. swapY,
  16304. p1x,
  16305. p1y,
  16306. p2x,
  16307. p2y,
  16308. width,
  16309. height,
  16310. region,
  16311. constrain;
  16312. if (!matches) {
  16313. throw "Element.alignTo with an invalid alignment " + position;
  16314. }
  16315. p1 = matches[1];
  16316. p2 = matches[2];
  16317. constrain = !!matches[3];
  16318. //Subtract the aligned el's internal xy from the target's offset xy
  16319. //plus custom offset to get the aligned el's new offset xy
  16320. a1 = me.getAnchorXY(p1, true);
  16321. a2 = el.getAnchorXY(p2, local);
  16322. x = a2[0] - a1[0] + offsets[0];
  16323. y = a2[1] - a1[1] + offsets[1];
  16324. if (constrain) {
  16325. width = me.getWidth();
  16326. height = me.getHeight();
  16327. region = el.getPageBox();
  16328. //If we are at a viewport boundary and the aligned el is anchored on a target border that is
  16329. //perpendicular to the vp border, allow the aligned el to slide on that border,
  16330. //otherwise swap the aligned el to the opposite border of the target.
  16331. p1y = p1.charAt(0);
  16332. p1x = p1.charAt(p1.length - 1);
  16333. p2y = p2.charAt(0);
  16334. p2x = p2.charAt(p2.length - 1);
  16335. swapY = ((p1y == "t" && p2y == "b") || (p1y == "b" && p2y == "t"));
  16336. swapX = ((p1x == "r" && p2x == "l") || (p1x == "l" && p2x == "r"));
  16337. if (x + width > dw) {
  16338. x = swapX ? region.left - width: dw - width;
  16339. }
  16340. if (x < 0) {
  16341. x = swapX ? region.right: 0;
  16342. }
  16343. if (y + height > dh) {
  16344. y = swapY ? region.top - height: dh - height;
  16345. }
  16346. if (y < 0) {
  16347. y = swapY ? region.bottom: 0;
  16348. }
  16349. }
  16350. return [x, y];
  16351. },
  16352. // private
  16353. getAnchor: function(){
  16354. var data = (this.$cache || this.getCache()).data,
  16355. anchor;
  16356. if (!this.dom) {
  16357. return;
  16358. }
  16359. anchor = data._anchor;
  16360. if(!anchor){
  16361. anchor = data._anchor = {};
  16362. }
  16363. return anchor;
  16364. },
  16365. // private ==> used outside of core
  16366. adjustForConstraints: function(xy, parent) {
  16367. var vector = this.getConstrainVector(parent, xy);
  16368. if (vector) {
  16369. xy[0] += vector[0];
  16370. xy[1] += vector[1];
  16371. }
  16372. return xy;
  16373. }
  16374. });
  16375. //@tag dom,core
  16376. //@require Ext.dom.AbstractElement-alignment
  16377. //@define Ext.dom.AbstractElement-insertion
  16378. //@define Ext.dom.AbstractElement
  16379. /**
  16380. * @class Ext.dom.AbstractElement
  16381. */
  16382. Ext.dom.AbstractElement.addMethods({
  16383. /**
  16384. * Appends the passed element(s) to this element
  16385. * @param {String/HTMLElement/Ext.dom.AbstractElement} el
  16386. * The id of the node, a DOM Node or an existing Element.
  16387. * @return {Ext.dom.AbstractElement} This element
  16388. */
  16389. appendChild: function(el) {
  16390. return Ext.get(el).appendTo(this);
  16391. },
  16392. /**
  16393. * Appends this element to the passed element
  16394. * @param {String/HTMLElement/Ext.dom.AbstractElement} el The new parent element.
  16395. * The id of the node, a DOM Node or an existing Element.
  16396. * @return {Ext.dom.AbstractElement} This element
  16397. */
  16398. appendTo: function(el) {
  16399. Ext.getDom(el).appendChild(this.dom);
  16400. return this;
  16401. },
  16402. /**
  16403. * Inserts this element before the passed element in the DOM
  16404. * @param {String/HTMLElement/Ext.dom.AbstractElement} el The element before which this element will be inserted.
  16405. * The id of the node, a DOM Node or an existing Element.
  16406. * @return {Ext.dom.AbstractElement} This element
  16407. */
  16408. insertBefore: function(el) {
  16409. el = Ext.getDom(el);
  16410. el.parentNode.insertBefore(this.dom, el);
  16411. return this;
  16412. },
  16413. /**
  16414. * Inserts this element after the passed element in the DOM
  16415. * @param {String/HTMLElement/Ext.dom.AbstractElement} el The element to insert after.
  16416. * The id of the node, a DOM Node or an existing Element.
  16417. * @return {Ext.dom.AbstractElement} This element
  16418. */
  16419. insertAfter: function(el) {
  16420. el = Ext.getDom(el);
  16421. el.parentNode.insertBefore(this.dom, el.nextSibling);
  16422. return this;
  16423. },
  16424. /**
  16425. * Inserts (or creates) an element (or DomHelper config) as the first child of this element
  16426. * @param {String/HTMLElement/Ext.dom.AbstractElement/Object} el The id or element to insert or a DomHelper config
  16427. * to create and insert
  16428. * @return {Ext.dom.AbstractElement} The new child
  16429. */
  16430. insertFirst: function(el, returnDom) {
  16431. el = el || {};
  16432. if (el.nodeType || el.dom || typeof el == 'string') { // element
  16433. el = Ext.getDom(el);
  16434. this.dom.insertBefore(el, this.dom.firstChild);
  16435. return !returnDom ? Ext.get(el) : el;
  16436. }
  16437. else { // dh config
  16438. return this.createChild(el, this.dom.firstChild, returnDom);
  16439. }
  16440. },
  16441. /**
  16442. * Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element
  16443. * @param {String/HTMLElement/Ext.dom.AbstractElement/Object/Array} el The id, element to insert or a DomHelper config
  16444. * to create and insert *or* an array of any of those.
  16445. * @param {String} [where='before'] 'before' or 'after'
  16446. * @param {Boolean} [returnDom=false] True to return the .;ll;l,raw DOM element instead of Ext.dom.AbstractElement
  16447. * @return {Ext.dom.AbstractElement} The inserted Element. If an array is passed, the last inserted element is returned.
  16448. */
  16449. insertSibling: function(el, where, returnDom){
  16450. var me = this,
  16451. isAfter = (where || 'before').toLowerCase() == 'after',
  16452. rt, insertEl, eLen, e;
  16453. if (Ext.isArray(el)) {
  16454. insertEl = me;
  16455. eLen = el.length;
  16456. for (e = 0; e < eLen; e++) {
  16457. rt = Ext.fly(insertEl, '_internal').insertSibling(el[e], where, returnDom);
  16458. if (isAfter) {
  16459. insertEl = rt;
  16460. }
  16461. }
  16462. return rt;
  16463. }
  16464. el = el || {};
  16465. if(el.nodeType || el.dom){
  16466. rt = me.dom.parentNode.insertBefore(Ext.getDom(el), isAfter ? me.dom.nextSibling : me.dom);
  16467. if (!returnDom) {
  16468. rt = Ext.get(rt);
  16469. }
  16470. }else{
  16471. if (isAfter && !me.dom.nextSibling) {
  16472. rt = Ext.core.DomHelper.append(me.dom.parentNode, el, !returnDom);
  16473. } else {
  16474. rt = Ext.core.DomHelper[isAfter ? 'insertAfter' : 'insertBefore'](me.dom, el, !returnDom);
  16475. }
  16476. }
  16477. return rt;
  16478. },
  16479. /**
  16480. * Replaces the passed element with this element
  16481. * @param {String/HTMLElement/Ext.dom.AbstractElement} el The element to replace.
  16482. * The id of the node, a DOM Node or an existing Element.
  16483. * @return {Ext.dom.AbstractElement} This element
  16484. */
  16485. replace: function(el) {
  16486. el = Ext.get(el);
  16487. this.insertBefore(el);
  16488. el.remove();
  16489. return this;
  16490. },
  16491. /**
  16492. * Replaces this element with the passed element
  16493. * @param {String/HTMLElement/Ext.dom.AbstractElement/Object} el The new element (id of the node, a DOM Node
  16494. * or an existing Element) or a DomHelper config of an element to create
  16495. * @return {Ext.dom.AbstractElement} This element
  16496. */
  16497. replaceWith: function(el){
  16498. var me = this;
  16499. if(el.nodeType || el.dom || typeof el == 'string'){
  16500. el = Ext.get(el);
  16501. me.dom.parentNode.insertBefore(el, me.dom);
  16502. }else{
  16503. el = Ext.core.DomHelper.insertBefore(me.dom, el);
  16504. }
  16505. delete Ext.cache[me.id];
  16506. Ext.removeNode(me.dom);
  16507. me.id = Ext.id(me.dom = el);
  16508. Ext.dom.AbstractElement.addToCache(me.isFlyweight ? new Ext.dom.AbstractElement(me.dom) : me);
  16509. return me;
  16510. },
  16511. /**
  16512. * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
  16513. * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
  16514. * automatically generated with the specified attributes.
  16515. * @param {HTMLElement} [insertBefore] a child element of this element
  16516. * @param {Boolean} [returnDom=false] true to return the dom node instead of creating an Element
  16517. * @return {Ext.dom.AbstractElement} The new child element
  16518. */
  16519. createChild: function(config, insertBefore, returnDom) {
  16520. config = config || {tag:'div'};
  16521. if (insertBefore) {
  16522. return Ext.core.DomHelper.insertBefore(insertBefore, config, returnDom !== true);
  16523. }
  16524. else {
  16525. return Ext.core.DomHelper[!this.dom.firstChild ? 'insertFirst' : 'append'](this.dom, config, returnDom !== true);
  16526. }
  16527. },
  16528. /**
  16529. * Creates and wraps this element with another element
  16530. * @param {Object} [config] DomHelper element config object for the wrapper element or null for an empty div
  16531. * @param {Boolean} [returnDom=false] True to return the raw DOM element instead of Ext.dom.AbstractElement
  16532. * @param {String} [selector] A {@link Ext.dom.Query DomQuery} selector to select a descendant node within the created element to use as the wrapping element.
  16533. * @return {HTMLElement/Ext.dom.AbstractElement} The newly created wrapper element
  16534. */
  16535. wrap: function(config, returnDom, selector) {
  16536. var newEl = Ext.core.DomHelper.insertBefore(this.dom, config || {tag: "div"}, true),
  16537. target = newEl;
  16538. if (selector) {
  16539. target = Ext.DomQuery.selectNode(selector, newEl.dom);
  16540. }
  16541. target.appendChild(this.dom);
  16542. return returnDom ? newEl.dom : newEl;
  16543. },
  16544. /**
  16545. * Inserts an html fragment into this element
  16546. * @param {String} where Where to insert the html in relation to this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
  16547. * See {@link Ext.dom.Helper#insertHtml} for details.
  16548. * @param {String} html The HTML fragment
  16549. * @param {Boolean} [returnEl=false] True to return an Ext.dom.AbstractElement
  16550. * @return {HTMLElement/Ext.dom.AbstractElement} The inserted node (or nearest related if more than 1 inserted)
  16551. */
  16552. insertHtml: function(where, html, returnEl) {
  16553. var el = Ext.core.DomHelper.insertHtml(where, this.dom, html);
  16554. return returnEl ? Ext.get(el) : el;
  16555. }
  16556. });
  16557. //@tag dom,core
  16558. //@require Ext.dom.AbstractElement-insertion
  16559. //@define Ext.dom.AbstractElement-position
  16560. //@define Ext.dom.AbstractElement
  16561. /**
  16562. * @class Ext.dom.AbstractElement
  16563. */
  16564. (function(){
  16565. var Element = Ext.dom.AbstractElement;
  16566. Element.override({
  16567. /**
  16568. * Gets the current X position of the element based on page coordinates. Element must be part of the DOM
  16569. * tree to have page coordinates (display:none or elements not appended return false).
  16570. * @return {Number} The X position of the element
  16571. */
  16572. getX: function(el) {
  16573. return this.getXY(el)[0];
  16574. },
  16575. /**
  16576. * Gets the current Y position of the element based on page coordinates. Element must be part of the DOM
  16577. * tree to have page coordinates (display:none or elements not appended return false).
  16578. * @return {Number} The Y position of the element
  16579. */
  16580. getY: function(el) {
  16581. return this.getXY(el)[1];
  16582. },
  16583. /**
  16584. * Gets the current position of the element based on page coordinates. Element must be part of the DOM
  16585. * tree to have page coordinates (display:none or elements not appended return false).
  16586. * @return {Array} The XY position of the element
  16587. */
  16588. getXY: function() {
  16589. // @FEATUREDETECT
  16590. var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0));
  16591. return [point.x, point.y];
  16592. },
  16593. /**
  16594. * Returns the offsets of this element from the passed element. Both element must be part of the DOM
  16595. * tree and not have display:none to have page coordinates.
  16596. * @param {Ext.Element/HTMLElement/String} element The element to get the offsets from.
  16597. * @return {Array} The XY page offsets (e.g. [100, -200])
  16598. */
  16599. getOffsetsTo: function(el){
  16600. var o = this.getXY(),
  16601. e = Ext.fly(el, '_internal').getXY();
  16602. return [o[0]-e[0],o[1]-e[1]];
  16603. },
  16604. /**
  16605. * Sets the X position of the element based on page coordinates. Element must be part of the DOM tree
  16606. * to have page coordinates (display:none or elements not appended return false).
  16607. * @param {Number} The X position of the element
  16608. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element
  16609. * animation config object
  16610. * @return {Ext.dom.AbstractElement} this
  16611. */
  16612. setX: function(x){
  16613. return this.setXY([x, this.getY()]);
  16614. },
  16615. /**
  16616. * Sets the Y position of the element based on page coordinates. Element must be part of the DOM tree
  16617. * to have page coordinates (display:none or elements not appended return false).
  16618. * @param {Number} The Y position of the element
  16619. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element
  16620. * animation config object
  16621. * @return {Ext.dom.AbstractElement} this
  16622. */
  16623. setY: function(y) {
  16624. return this.setXY([this.getX(), y]);
  16625. },
  16626. /**
  16627. * Sets the element's left position directly using CSS style (instead of {@link #setX}).
  16628. * @param {String} left The left CSS property value
  16629. * @return {Ext.dom.AbstractElement} this
  16630. */
  16631. setLeft: function(left) {
  16632. this.setStyle('left', Element.addUnits(left));
  16633. return this;
  16634. },
  16635. /**
  16636. * Sets the element's top position directly using CSS style (instead of {@link #setY}).
  16637. * @param {String} top The top CSS property value
  16638. * @return {Ext.dom.AbstractElement} this
  16639. */
  16640. setTop: function(top) {
  16641. this.setStyle('top', Element.addUnits(top));
  16642. return this;
  16643. },
  16644. /**
  16645. * Sets the element's CSS right style.
  16646. * @param {String} right The right CSS property value
  16647. * @return {Ext.dom.AbstractElement} this
  16648. */
  16649. setRight: function(right) {
  16650. this.setStyle('right', Element.addUnits(right));
  16651. return this;
  16652. },
  16653. /**
  16654. * Sets the element's CSS bottom style.
  16655. * @param {String} bottom The bottom CSS property value
  16656. * @return {Ext.dom.AbstractElement} this
  16657. */
  16658. setBottom: function(bottom) {
  16659. this.setStyle('bottom', Element.addUnits(bottom));
  16660. return this;
  16661. },
  16662. /**
  16663. * Sets the position of the element in page coordinates, regardless of how the element is positioned.
  16664. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  16665. * @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
  16666. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element animation config object
  16667. * @return {Ext.dom.AbstractElement} this
  16668. */
  16669. setXY: function(pos) {
  16670. var me = this,
  16671. pts,
  16672. style,
  16673. pt;
  16674. if (arguments.length > 1) {
  16675. pos = [pos, arguments[1]];
  16676. }
  16677. // me.position();
  16678. pts = me.translatePoints(pos);
  16679. style = me.dom.style;
  16680. for (pt in pts) {
  16681. if (!pts.hasOwnProperty(pt)) {
  16682. continue;
  16683. }
  16684. if (!isNaN(pts[pt])) {
  16685. style[pt] = pts[pt] + "px";
  16686. }
  16687. }
  16688. return me;
  16689. },
  16690. /**
  16691. * Gets the left X coordinate
  16692. * @param {Boolean} local True to get the local css position instead of page coordinate
  16693. * @return {Number}
  16694. */
  16695. getLeft: function(local) {
  16696. return parseInt(this.getStyle('left'), 10) || 0;
  16697. },
  16698. /**
  16699. * Gets the right X coordinate of the element (element X position + element width)
  16700. * @param {Boolean} local True to get the local css position instead of page coordinate
  16701. * @return {Number}
  16702. */
  16703. getRight: function(local) {
  16704. return parseInt(this.getStyle('right'), 10) || 0;
  16705. },
  16706. /**
  16707. * Gets the top Y coordinate
  16708. * @param {Boolean} local True to get the local css position instead of page coordinate
  16709. * @return {Number}
  16710. */
  16711. getTop: function(local) {
  16712. return parseInt(this.getStyle('top'), 10) || 0;
  16713. },
  16714. /**
  16715. * Gets the bottom Y coordinate of the element (element Y position + element height)
  16716. * @param {Boolean} local True to get the local css position instead of page coordinate
  16717. * @return {Number}
  16718. */
  16719. getBottom: function(local) {
  16720. return parseInt(this.getStyle('bottom'), 10) || 0;
  16721. },
  16722. /**
  16723. * Translates the passed page coordinates into left/top css values for this element
  16724. * @param {Number/Array} x The page x or an array containing [x, y]
  16725. * @param {Number} [y] The page y, required if x is not an array
  16726. * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
  16727. */
  16728. translatePoints: function(x, y) {
  16729. y = isNaN(x[1]) ? y : x[1];
  16730. x = isNaN(x[0]) ? x : x[0];
  16731. var me = this,
  16732. relative = me.isStyle('position', 'relative'),
  16733. o = me.getXY(),
  16734. l = parseInt(me.getStyle('left'), 10),
  16735. t = parseInt(me.getStyle('top'), 10);
  16736. l = !isNaN(l) ? l : (relative ? 0 : me.dom.offsetLeft);
  16737. t = !isNaN(t) ? t : (relative ? 0 : me.dom.offsetTop);
  16738. return {left: (x - o[0] + l), top: (y - o[1] + t)};
  16739. },
  16740. /**
  16741. * Sets the element's box. Use getBox() on another element to get a box obj.
  16742. * If animate is true then width, height, x and y will be animated concurrently.
  16743. * @param {Object} box The box to fill {x, y, width, height}
  16744. * @param {Boolean} [adjust] Whether to adjust for box-model issues automatically
  16745. * @param {Boolean/Object} [animate] true for the default animation or a standard
  16746. * Element animation config object
  16747. * @return {Ext.dom.AbstractElement} this
  16748. */
  16749. setBox: function(box) {
  16750. var me = this,
  16751. width = box.width,
  16752. height = box.height,
  16753. top = box.top,
  16754. left = box.left;
  16755. if (left !== undefined) {
  16756. me.setLeft(left);
  16757. }
  16758. if (top !== undefined) {
  16759. me.setTop(top);
  16760. }
  16761. if (width !== undefined) {
  16762. me.setWidth(width);
  16763. }
  16764. if (height !== undefined) {
  16765. me.setHeight(height);
  16766. }
  16767. return this;
  16768. },
  16769. /**
  16770. * Return an object defining the area of this Element which can be passed to {@link #setBox} to
  16771. * set another Element's size/location to match this element.
  16772. *
  16773. * @param {Boolean} [contentBox] If true a box for the content of the element is returned.
  16774. * @param {Boolean} [local] If true the element's left and top are returned instead of page x/y.
  16775. * @return {Object} box An object in the format:
  16776. *
  16777. * {
  16778. * x: <Element's X position>,
  16779. * y: <Element's Y position>,
  16780. * width: <Element's width>,
  16781. * height: <Element's height>,
  16782. * bottom: <Element's lower bound>,
  16783. * right: <Element's rightmost bound>
  16784. * }
  16785. *
  16786. * The returned object may also be addressed as an Array where index 0 contains the X position
  16787. * and index 1 contains the Y position. So the result may also be used for {@link #setXY}
  16788. */
  16789. getBox: function(contentBox, local) {
  16790. var me = this,
  16791. dom = me.dom,
  16792. width = dom.offsetWidth,
  16793. height = dom.offsetHeight,
  16794. xy, box, l, r, t, b;
  16795. if (!local) {
  16796. xy = me.getXY();
  16797. }
  16798. else if (contentBox) {
  16799. xy = [0,0];
  16800. }
  16801. else {
  16802. xy = [parseInt(me.getStyle("left"), 10) || 0, parseInt(me.getStyle("top"), 10) || 0];
  16803. }
  16804. if (!contentBox) {
  16805. box = {
  16806. x: xy[0],
  16807. y: xy[1],
  16808. 0: xy[0],
  16809. 1: xy[1],
  16810. width: width,
  16811. height: height
  16812. };
  16813. }
  16814. else {
  16815. l = me.getBorderWidth.call(me, "l") + me.getPadding.call(me, "l");
  16816. r = me.getBorderWidth.call(me, "r") + me.getPadding.call(me, "r");
  16817. t = me.getBorderWidth.call(me, "t") + me.getPadding.call(me, "t");
  16818. b = me.getBorderWidth.call(me, "b") + me.getPadding.call(me, "b");
  16819. box = {
  16820. x: xy[0] + l,
  16821. y: xy[1] + t,
  16822. 0: xy[0] + l,
  16823. 1: xy[1] + t,
  16824. width: width - (l + r),
  16825. height: height - (t + b)
  16826. };
  16827. }
  16828. box.left = box.x;
  16829. box.top = box.y;
  16830. box.right = box.x + box.width;
  16831. box.bottom = box.y + box.height;
  16832. return box;
  16833. },
  16834. /**
  16835. * Return an object defining the area of this Element which can be passed to {@link #setBox} to
  16836. * set another Element's size/location to match this element.
  16837. *
  16838. * @param {Boolean} [asRegion] If true an Ext.util.Region will be returned
  16839. * @return {Object} box An object in the format
  16840. *
  16841. * {
  16842. * left: <Element's X position>,
  16843. * top: <Element's Y position>,
  16844. * width: <Element's width>,
  16845. * height: <Element's height>,
  16846. * bottom: <Element's lower bound>,
  16847. * right: <Element's rightmost bound>
  16848. * }
  16849. *
  16850. * The returned object may also be addressed as an Array where index 0 contains the X position
  16851. * and index 1 contains the Y position. So the result may also be used for {@link #setXY}
  16852. */
  16853. getPageBox: function(getRegion) {
  16854. var me = this,
  16855. el = me.dom,
  16856. w = el.offsetWidth,
  16857. h = el.offsetHeight,
  16858. xy = me.getXY(),
  16859. t = xy[1],
  16860. r = xy[0] + w,
  16861. b = xy[1] + h,
  16862. l = xy[0];
  16863. if (!el) {
  16864. return new Ext.util.Region();
  16865. }
  16866. if (getRegion) {
  16867. return new Ext.util.Region(t, r, b, l);
  16868. }
  16869. else {
  16870. return {
  16871. left: l,
  16872. top: t,
  16873. width: w,
  16874. height: h,
  16875. right: r,
  16876. bottom: b
  16877. };
  16878. }
  16879. }
  16880. });
  16881. }());
  16882. //@tag dom,core
  16883. //@require Ext.dom.AbstractElement-position
  16884. //@define Ext.dom.AbstractElement-style
  16885. //@define Ext.dom.AbstractElement
  16886. /**
  16887. * @class Ext.dom.AbstractElement
  16888. */
  16889. (function(){
  16890. // local style camelizing for speed
  16891. var Element = Ext.dom.AbstractElement,
  16892. view = document.defaultView,
  16893. array = Ext.Array,
  16894. trimRe = /^\s+|\s+$/g,
  16895. wordsRe = /\w/g,
  16896. spacesRe = /\s+/,
  16897. transparentRe = /^(?:transparent|(?:rgba[(](?:\s*\d+\s*[,]){3}\s*0\s*[)]))$/i,
  16898. hasClassList = Ext.supports.ClassList,
  16899. PADDING = 'padding',
  16900. MARGIN = 'margin',
  16901. BORDER = 'border',
  16902. LEFT_SUFFIX = '-left',
  16903. RIGHT_SUFFIX = '-right',
  16904. TOP_SUFFIX = '-top',
  16905. BOTTOM_SUFFIX = '-bottom',
  16906. WIDTH = '-width',
  16907. // special markup used throughout Ext when box wrapping elements
  16908. borders = {l: BORDER + LEFT_SUFFIX + WIDTH, r: BORDER + RIGHT_SUFFIX + WIDTH, t: BORDER + TOP_SUFFIX + WIDTH, b: BORDER + BOTTOM_SUFFIX + WIDTH},
  16909. paddings = {l: PADDING + LEFT_SUFFIX, r: PADDING + RIGHT_SUFFIX, t: PADDING + TOP_SUFFIX, b: PADDING + BOTTOM_SUFFIX},
  16910. margins = {l: MARGIN + LEFT_SUFFIX, r: MARGIN + RIGHT_SUFFIX, t: MARGIN + TOP_SUFFIX, b: MARGIN + BOTTOM_SUFFIX};
  16911. Element.override({
  16912. /**
  16913. * This shared object is keyed by style name (e.g., 'margin-left' or 'marginLeft'). The
  16914. * values are objects with the following properties:
  16915. *
  16916. * * `name` (String) : The actual name to be presented to the DOM. This is typically the value
  16917. * returned by {@link #normalize}.
  16918. * * `get` (Function) : A hook function that will perform the get on this style. These
  16919. * functions receive "(dom, el)" arguments. The `dom` parameter is the DOM Element
  16920. * from which to get ths tyle. The `el` argument (may be null) is the Ext.Element.
  16921. * * `set` (Function) : A hook function that will perform the set on this style. These
  16922. * functions receive "(dom, value, el)" arguments. The `dom` parameter is the DOM Element
  16923. * from which to get ths tyle. The `value` parameter is the new value for the style. The
  16924. * `el` argument (may be null) is the Ext.Element.
  16925. *
  16926. * The `this` pointer is the object that contains `get` or `set`, which means that
  16927. * `this.name` can be accessed if needed. The hook functions are both optional.
  16928. * @private
  16929. */
  16930. styleHooks: {},
  16931. // private
  16932. addStyles : function(sides, styles){
  16933. var totalSize = 0,
  16934. sidesArr = (sides || '').match(wordsRe),
  16935. i,
  16936. len = sidesArr.length,
  16937. side,
  16938. styleSides = [];
  16939. if (len == 1) {
  16940. totalSize = Math.abs(parseFloat(this.getStyle(styles[sidesArr[0]])) || 0);
  16941. } else if (len) {
  16942. for (i = 0; i < len; i++) {
  16943. side = sidesArr[i];
  16944. styleSides.push(styles[side]);
  16945. }
  16946. //Gather all at once, returning a hash
  16947. styleSides = this.getStyle(styleSides);
  16948. for (i=0; i < len; i++) {
  16949. side = sidesArr[i];
  16950. totalSize += Math.abs(parseFloat(styleSides[styles[side]]) || 0);
  16951. }
  16952. }
  16953. return totalSize;
  16954. },
  16955. /**
  16956. * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
  16957. * @param {String/String[]} className The CSS classes to add separated by space, or an array of classes
  16958. * @return {Ext.dom.Element} this
  16959. * @method
  16960. */
  16961. addCls: hasClassList ?
  16962. function (className) {
  16963. if (String(className).indexOf('undefined') > -1) {
  16964. Ext.Logger.warn("called with an undefined className: " + className);
  16965. }
  16966. var me = this,
  16967. dom = me.dom,
  16968. classList,
  16969. newCls,
  16970. i,
  16971. len,
  16972. cls;
  16973. if (typeof(className) == 'string') {
  16974. // split string on spaces to make an array of className
  16975. className = className.replace(trimRe, '').split(spacesRe);
  16976. }
  16977. // the gain we have here is that we can skip parsing className and use the
  16978. // classList.contains method, so now O(M) not O(M+N)
  16979. if (dom && className && !!(len = className.length)) {
  16980. if (!dom.className) {
  16981. dom.className = className.join(' ');
  16982. } else {
  16983. classList = dom.classList;
  16984. for (i = 0; i < len; ++i) {
  16985. cls = className[i];
  16986. if (cls) {
  16987. if (!classList.contains(cls)) {
  16988. if (newCls) {
  16989. newCls.push(cls);
  16990. } else {
  16991. newCls = dom.className.replace(trimRe, '');
  16992. newCls = newCls ? [newCls, cls] : [cls];
  16993. }
  16994. }
  16995. }
  16996. }
  16997. if (newCls) {
  16998. dom.className = newCls.join(' '); // write to DOM once
  16999. }
  17000. }
  17001. }
  17002. return me;
  17003. } :
  17004. function(className) {
  17005. if (String(className).indexOf('undefined') > -1) {
  17006. Ext.Logger.warn("called with an undefined className: '" + className + "'");
  17007. }
  17008. var me = this,
  17009. dom = me.dom,
  17010. changed,
  17011. elClasses;
  17012. if (dom && className && className.length) {
  17013. elClasses = Ext.Element.mergeClsList(dom.className, className);
  17014. if (elClasses.changed) {
  17015. dom.className = elClasses.join(' '); // write to DOM once
  17016. }
  17017. }
  17018. return me;
  17019. },
  17020. /**
  17021. * Removes one or more CSS classes from the element.
  17022. * @param {String/String[]} className The CSS classes to remove separated by space, or an array of classes
  17023. * @return {Ext.dom.Element} this
  17024. */
  17025. removeCls: function(className) {
  17026. var me = this,
  17027. dom = me.dom,
  17028. len,
  17029. elClasses;
  17030. if (typeof(className) == 'string') {
  17031. // split string on spaces to make an array of className
  17032. className = className.replace(trimRe, '').split(spacesRe);
  17033. }
  17034. if (dom && dom.className && className && !!(len = className.length)) {
  17035. if (len == 1 && hasClassList) {
  17036. if (className[0]) {
  17037. dom.classList.remove(className[0]); // one DOM write
  17038. }
  17039. } else {
  17040. elClasses = Ext.Element.removeCls(dom.className, className);
  17041. if (elClasses.changed) {
  17042. dom.className = elClasses.join(' ');
  17043. }
  17044. }
  17045. }
  17046. return me;
  17047. },
  17048. /**
  17049. * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
  17050. * @param {String/String[]} className The CSS class to add, or an array of classes
  17051. * @return {Ext.dom.Element} this
  17052. */
  17053. radioCls: function(className) {
  17054. var cn = this.dom.parentNode.childNodes,
  17055. v,
  17056. i, len;
  17057. className = Ext.isArray(className) ? className: [className];
  17058. for (i = 0, len = cn.length; i < len; i++) {
  17059. v = cn[i];
  17060. if (v && v.nodeType == 1) {
  17061. Ext.fly(v, '_internal').removeCls(className);
  17062. }
  17063. }
  17064. return this.addCls(className);
  17065. },
  17066. /**
  17067. * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
  17068. * @param {String} className The CSS class to toggle
  17069. * @return {Ext.dom.Element} this
  17070. * @method
  17071. */
  17072. toggleCls: hasClassList ?
  17073. function (className) {
  17074. var me = this,
  17075. dom = me.dom;
  17076. if (dom) {
  17077. className = className.replace(trimRe, '');
  17078. if (className) {
  17079. dom.classList.toggle(className);
  17080. }
  17081. }
  17082. return me;
  17083. } :
  17084. function(className) {
  17085. var me = this;
  17086. return me.hasCls(className) ? me.removeCls(className) : me.addCls(className);
  17087. },
  17088. /**
  17089. * Checks if the specified CSS class exists on this element's DOM node.
  17090. * @param {String} className The CSS class to check for
  17091. * @return {Boolean} True if the class exists, else false
  17092. * @method
  17093. */
  17094. hasCls: hasClassList ?
  17095. function (className) {
  17096. var dom = this.dom;
  17097. return (dom && className) ? dom.classList.contains(className) : false;
  17098. } :
  17099. function(className) {
  17100. var dom = this.dom;
  17101. return dom ? className && (' '+dom.className+' ').indexOf(' '+className+' ') != -1 : false;
  17102. },
  17103. /**
  17104. * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
  17105. * @param {String} oldClassName The CSS class to replace
  17106. * @param {String} newClassName The replacement CSS class
  17107. * @return {Ext.dom.Element} this
  17108. */
  17109. replaceCls: function(oldClassName, newClassName){
  17110. return this.removeCls(oldClassName).addCls(newClassName);
  17111. },
  17112. /**
  17113. * Checks if the current value of a style is equal to a given value.
  17114. * @param {String} style property whose value is returned.
  17115. * @param {String} value to check against.
  17116. * @return {Boolean} true for when the current value equals the given value.
  17117. */
  17118. isStyle: function(style, val) {
  17119. return this.getStyle(style) == val;
  17120. },
  17121. /**
  17122. * Returns a named style property based on computed/currentStyle (primary) and
  17123. * inline-style if primary is not available.
  17124. *
  17125. * @param {String/String[]} property The style property (or multiple property names
  17126. * in an array) whose value is returned.
  17127. * @param {Boolean} [inline=false] if `true` only inline styles will be returned.
  17128. * @return {String/Object} The current value of the style property for this element
  17129. * (or a hash of named style values if multiple property arguments are requested).
  17130. * @method
  17131. */
  17132. getStyle: function (property, inline) {
  17133. var me = this,
  17134. dom = me.dom,
  17135. multiple = typeof property != 'string',
  17136. hooks = me.styleHooks,
  17137. prop = property,
  17138. props = prop,
  17139. len = 1,
  17140. domStyle, camel, values, hook, out, style, i;
  17141. if (multiple) {
  17142. values = {};
  17143. prop = props[0];
  17144. i = 0;
  17145. if (!(len = props.length)) {
  17146. return values;
  17147. }
  17148. }
  17149. if (!dom || dom.documentElement) {
  17150. return values || '';
  17151. }
  17152. domStyle = dom.style;
  17153. if (inline) {
  17154. style = domStyle;
  17155. } else {
  17156. // Caution: Firefox will not render "presentation" (ie. computed styles) in
  17157. // iframes that are display:none or those inheriting display:none. Similar
  17158. // issues with legacy Safari.
  17159. //
  17160. style = dom.ownerDocument.defaultView.getComputedStyle(dom, null);
  17161. // fallback to inline style if rendering context not available
  17162. if (!style) {
  17163. inline = true;
  17164. style = domStyle;
  17165. }
  17166. }
  17167. do {
  17168. hook = hooks[prop];
  17169. if (!hook) {
  17170. hooks[prop] = hook = { name: Element.normalize(prop) };
  17171. }
  17172. if (hook.get) {
  17173. out = hook.get(dom, me, inline, style);
  17174. } else {
  17175. camel = hook.name;
  17176. out = style[camel];
  17177. }
  17178. if (!multiple) {
  17179. return out;
  17180. }
  17181. values[prop] = out;
  17182. prop = props[++i];
  17183. } while (i < len);
  17184. return values;
  17185. },
  17186. getStyles: function () {
  17187. var props = Ext.Array.slice(arguments),
  17188. len = props.length,
  17189. inline;
  17190. if (len && typeof props[len-1] == 'boolean') {
  17191. inline = props.pop();
  17192. }
  17193. return this.getStyle(props, inline);
  17194. },
  17195. /**
  17196. * Returns true if the value of the given property is visually transparent. This
  17197. * may be due to a 'transparent' style value or an rgba value with 0 in the alpha
  17198. * component.
  17199. * @param {String} prop The style property whose value is to be tested.
  17200. * @return {Boolean} True if the style property is visually transparent.
  17201. */
  17202. isTransparent: function (prop) {
  17203. var value = this.getStyle(prop);
  17204. return value ? transparentRe.test(value) : false;
  17205. },
  17206. /**
  17207. * Wrapper for setting style properties, also takes single object parameter of multiple styles.
  17208. * @param {String/Object} property The style property to be set, or an object of multiple styles.
  17209. * @param {String} [value] The value to apply to the given property, or null if an object was passed.
  17210. * @return {Ext.dom.Element} this
  17211. */
  17212. setStyle: function(prop, value) {
  17213. var me = this,
  17214. dom = me.dom,
  17215. hooks = me.styleHooks,
  17216. style = dom.style,
  17217. name = prop,
  17218. hook;
  17219. // we don't promote the 2-arg form to object-form to avoid the overhead...
  17220. if (typeof name == 'string') {
  17221. hook = hooks[name];
  17222. if (!hook) {
  17223. hooks[name] = hook = { name: Element.normalize(name) };
  17224. }
  17225. value = (value == null) ? '' : value;
  17226. if (hook.set) {
  17227. hook.set(dom, value, me);
  17228. } else {
  17229. style[hook.name] = value;
  17230. }
  17231. if (hook.afterSet) {
  17232. hook.afterSet(dom, value, me);
  17233. }
  17234. } else {
  17235. for (name in prop) {
  17236. if (prop.hasOwnProperty(name)) {
  17237. hook = hooks[name];
  17238. if (!hook) {
  17239. hooks[name] = hook = { name: Element.normalize(name) };
  17240. }
  17241. value = prop[name];
  17242. value = (value == null) ? '' : value;
  17243. if (hook.set) {
  17244. hook.set(dom, value, me);
  17245. } else {
  17246. style[hook.name] = value;
  17247. }
  17248. if (hook.afterSet) {
  17249. hook.afterSet(dom, value, me);
  17250. }
  17251. }
  17252. }
  17253. }
  17254. return me;
  17255. },
  17256. /**
  17257. * Returns the offset height of the element
  17258. * @param {Boolean} [contentHeight] true to get the height minus borders and padding
  17259. * @return {Number} The element's height
  17260. */
  17261. getHeight: function(contentHeight) {
  17262. var dom = this.dom,
  17263. height = contentHeight ? (dom.clientHeight - this.getPadding("tb")) : dom.offsetHeight;
  17264. return height > 0 ? height: 0;
  17265. },
  17266. /**
  17267. * Returns the offset width of the element
  17268. * @param {Boolean} [contentWidth] true to get the width minus borders and padding
  17269. * @return {Number} The element's width
  17270. */
  17271. getWidth: function(contentWidth) {
  17272. var dom = this.dom,
  17273. width = contentWidth ? (dom.clientWidth - this.getPadding("lr")) : dom.offsetWidth;
  17274. return width > 0 ? width: 0;
  17275. },
  17276. /**
  17277. * Set the width of this Element.
  17278. * @param {Number/String} width The new width. This may be one of:
  17279. *
  17280. * - A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).
  17281. * - A String used to set the CSS width style. Animation may **not** be used.
  17282. *
  17283. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  17284. * @return {Ext.dom.Element} this
  17285. */
  17286. setWidth: function(width) {
  17287. var me = this;
  17288. me.dom.style.width = Element.addUnits(width);
  17289. return me;
  17290. },
  17291. /**
  17292. * Set the height of this Element.
  17293. *
  17294. * // change the height to 200px and animate with default configuration
  17295. * Ext.fly('elementId').setHeight(200, true);
  17296. *
  17297. * // change the height to 150px and animate with a custom configuration
  17298. * Ext.fly('elId').setHeight(150, {
  17299. * duration : 500, // animation will have a duration of .5 seconds
  17300. * // will change the content to "finished"
  17301. * callback: function(){ this.{@link #update}("finished"); }
  17302. * });
  17303. *
  17304. * @param {Number/String} height The new height. This may be one of:
  17305. *
  17306. * - A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels.)
  17307. * - A String used to set the CSS height style. Animation may **not** be used.
  17308. *
  17309. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  17310. * @return {Ext.dom.Element} this
  17311. */
  17312. setHeight: function(height) {
  17313. var me = this;
  17314. me.dom.style.height = Element.addUnits(height);
  17315. return me;
  17316. },
  17317. /**
  17318. * Gets the width of the border(s) for the specified side(s)
  17319. * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
  17320. * passing `'lr'` would get the border **l**eft width + the border **r**ight width.
  17321. * @return {Number} The width of the sides passed added together
  17322. */
  17323. getBorderWidth: function(side){
  17324. return this.addStyles(side, borders);
  17325. },
  17326. /**
  17327. * Gets the width of the padding(s) for the specified side(s)
  17328. * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
  17329. * passing `'lr'` would get the padding **l**eft + the padding **r**ight.
  17330. * @return {Number} The padding of the sides passed added together
  17331. */
  17332. getPadding: function(side){
  17333. return this.addStyles(side, paddings);
  17334. },
  17335. margins : margins,
  17336. /**
  17337. * More flexible version of {@link #setStyle} for setting style properties.
  17338. * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
  17339. * a function which returns such a specification.
  17340. * @return {Ext.dom.Element} this
  17341. */
  17342. applyStyles: function(styles) {
  17343. if (styles) {
  17344. var i,
  17345. len,
  17346. dom = this.dom;
  17347. if (typeof styles == 'function') {
  17348. styles = styles.call();
  17349. }
  17350. if (typeof styles == 'string') {
  17351. styles = Ext.util.Format.trim(styles).split(/\s*(?::|;)\s*/);
  17352. for (i = 0, len = styles.length; i < len;) {
  17353. dom.style[Element.normalize(styles[i++])] = styles[i++];
  17354. }
  17355. }
  17356. else if (typeof styles == 'object') {
  17357. this.setStyle(styles);
  17358. }
  17359. }
  17360. },
  17361. /**
  17362. * Set the size of this Element. If animation is true, both width and height will be animated concurrently.
  17363. * @param {Number/String} width The new width. This may be one of:
  17364. *
  17365. * - A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).
  17366. * - A String used to set the CSS width style. Animation may **not** be used.
  17367. * - A size object in the format `{width: widthValue, height: heightValue}`.
  17368. *
  17369. * @param {Number/String} height The new height. This may be one of:
  17370. *
  17371. * - A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels).
  17372. * - A String used to set the CSS height style. Animation may **not** be used.
  17373. *
  17374. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  17375. * @return {Ext.dom.Element} this
  17376. */
  17377. setSize: function(width, height) {
  17378. var me = this,
  17379. style = me.dom.style;
  17380. if (Ext.isObject(width)) {
  17381. // in case of object from getSize()
  17382. height = width.height;
  17383. width = width.width;
  17384. }
  17385. style.width = Element.addUnits(width);
  17386. style.height = Element.addUnits(height);
  17387. return me;
  17388. },
  17389. /**
  17390. * Returns the dimensions of the element available to lay content out in.
  17391. *
  17392. * If the element (or any ancestor element) has CSS style `display: none`, the dimensions will be zero.
  17393. *
  17394. * Example:
  17395. *
  17396. * var vpSize = Ext.getBody().getViewSize();
  17397. *
  17398. * // all Windows created afterwards will have a default value of 90% height and 95% width
  17399. * Ext.Window.override({
  17400. * width: vpSize.width * 0.9,
  17401. * height: vpSize.height * 0.95
  17402. * });
  17403. * // To handle window resizing you would have to hook onto onWindowResize.
  17404. *
  17405. * getViewSize utilizes clientHeight/clientWidth which excludes sizing of scrollbars.
  17406. * To obtain the size including scrollbars, use getStyleSize
  17407. *
  17408. * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
  17409. *
  17410. * @return {Object} Object describing width and height.
  17411. * @return {Number} return.width
  17412. * @return {Number} return.height
  17413. */
  17414. getViewSize: function() {
  17415. var doc = document,
  17416. dom = this.dom;
  17417. if (dom == doc || dom == doc.body) {
  17418. return {
  17419. width: Element.getViewportWidth(),
  17420. height: Element.getViewportHeight()
  17421. };
  17422. }
  17423. else {
  17424. return {
  17425. width: dom.clientWidth,
  17426. height: dom.clientHeight
  17427. };
  17428. }
  17429. },
  17430. /**
  17431. * Returns the size of the element.
  17432. * @param {Boolean} [contentSize] true to get the width/size minus borders and padding
  17433. * @return {Object} An object containing the element's size:
  17434. * @return {Number} return.width
  17435. * @return {Number} return.height
  17436. */
  17437. getSize: function(contentSize) {
  17438. var dom = this.dom;
  17439. return {
  17440. width: Math.max(0, contentSize ? (dom.clientWidth - this.getPadding("lr")) : dom.offsetWidth),
  17441. height: Math.max(0, contentSize ? (dom.clientHeight - this.getPadding("tb")) : dom.offsetHeight)
  17442. };
  17443. },
  17444. /**
  17445. * Forces the browser to repaint this element
  17446. * @return {Ext.dom.Element} this
  17447. */
  17448. repaint: function(){
  17449. var dom = this.dom;
  17450. this.addCls(Ext.baseCSSPrefix + 'repaint');
  17451. setTimeout(function(){
  17452. Ext.fly(dom).removeCls(Ext.baseCSSPrefix + 'repaint');
  17453. }, 1);
  17454. return this;
  17455. },
  17456. /**
  17457. * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
  17458. * then it returns the calculated width of the sides (see getPadding)
  17459. * @param {String} [sides] Any combination of l, r, t, b to get the sum of those sides
  17460. * @return {Object/Number}
  17461. */
  17462. getMargin: function(side){
  17463. var me = this,
  17464. hash = {t:"top", l:"left", r:"right", b: "bottom"},
  17465. key,
  17466. o,
  17467. margins;
  17468. if (!side) {
  17469. margins = [];
  17470. for (key in me.margins) {
  17471. if(me.margins.hasOwnProperty(key)) {
  17472. margins.push(me.margins[key]);
  17473. }
  17474. }
  17475. o = me.getStyle(margins);
  17476. if(o && typeof o == 'object') {
  17477. //now mixin nomalized values (from hash table)
  17478. for (key in me.margins) {
  17479. if(me.margins.hasOwnProperty(key)) {
  17480. o[hash[key]] = parseFloat(o[me.margins[key]]) || 0;
  17481. }
  17482. }
  17483. }
  17484. return o;
  17485. } else {
  17486. return me.addStyles.call(me, side, me.margins);
  17487. }
  17488. },
  17489. /**
  17490. * Puts a mask over this element to disable user interaction. Requires core.css.
  17491. * This method can only be applied to elements which accept child nodes.
  17492. * @param {String} [msg] A message to display in the mask
  17493. * @param {String} [msgCls] A css class to apply to the msg element
  17494. */
  17495. mask: function(msg, msgCls, transparent) {
  17496. var me = this,
  17497. dom = me.dom,
  17498. data = (me.$cache || me.getCache()).data,
  17499. el = data.mask,
  17500. mask,
  17501. size,
  17502. cls = '',
  17503. prefix = Ext.baseCSSPrefix;
  17504. me.addCls(prefix + 'masked');
  17505. if (me.getStyle("position") == "static") {
  17506. me.addCls(prefix + 'masked-relative');
  17507. }
  17508. if (el) {
  17509. el.remove();
  17510. }
  17511. if (msgCls && typeof msgCls == 'string' ) {
  17512. cls = ' ' + msgCls;
  17513. }
  17514. else {
  17515. cls = ' ' + prefix + 'mask-gray';
  17516. }
  17517. mask = me.createChild({
  17518. cls: prefix + 'mask' + ((transparent !== false) ? '' : (' ' + prefix + 'mask-gray')),
  17519. html: msg ? ('<div class="' + (msgCls || (prefix + 'mask-message')) + '">' + msg + '</div>') : ''
  17520. });
  17521. size = me.getSize();
  17522. data.mask = mask;
  17523. if (dom === document.body) {
  17524. size.height = window.innerHeight;
  17525. if (me.orientationHandler) {
  17526. Ext.EventManager.unOrientationChange(me.orientationHandler, me);
  17527. }
  17528. me.orientationHandler = function() {
  17529. size = me.getSize();
  17530. size.height = window.innerHeight;
  17531. mask.setSize(size);
  17532. };
  17533. Ext.EventManager.onOrientationChange(me.orientationHandler, me);
  17534. }
  17535. mask.setSize(size);
  17536. if (Ext.is.iPad) {
  17537. Ext.repaint();
  17538. }
  17539. },
  17540. /**
  17541. * Removes a previously applied mask.
  17542. */
  17543. unmask: function() {
  17544. var me = this,
  17545. data = (me.$cache || me.getCache()).data,
  17546. mask = data.mask,
  17547. prefix = Ext.baseCSSPrefix;
  17548. if (mask) {
  17549. mask.remove();
  17550. delete data.mask;
  17551. }
  17552. me.removeCls([prefix + 'masked', prefix + 'masked-relative']);
  17553. if (me.dom === document.body) {
  17554. Ext.EventManager.unOrientationChange(me.orientationHandler, me);
  17555. delete me.orientationHandler;
  17556. }
  17557. }
  17558. });
  17559. /**
  17560. * Creates mappings for 'margin-before' to 'marginLeft' (etc.) given the output
  17561. * map and an ordering pair (e.g., ['left', 'right']). The ordering pair is in
  17562. * before/after order.
  17563. */
  17564. Element.populateStyleMap = function (map, order) {
  17565. var baseStyles = ['margin-', 'padding-', 'border-width-'],
  17566. beforeAfter = ['before', 'after'],
  17567. index, style, name, i;
  17568. for (index = baseStyles.length; index--; ) {
  17569. for (i = 2; i--; ) {
  17570. style = baseStyles[index] + beforeAfter[i]; // margin-before
  17571. // ex: maps margin-before and marginBefore to marginLeft
  17572. map[Element.normalize(style)] = map[style] = {
  17573. name: Element.normalize(baseStyles[index] + order[i])
  17574. };
  17575. }
  17576. }
  17577. };
  17578. Ext.onReady(function () {
  17579. var supports = Ext.supports,
  17580. styleHooks,
  17581. colorStyles, i, name, camel;
  17582. function fixTransparent (dom, el, inline, style) {
  17583. var value = style[this.name] || '';
  17584. return transparentRe.test(value) ? 'transparent' : value;
  17585. }
  17586. function fixRightMargin (dom, el, inline, style) {
  17587. var result = style.marginRight,
  17588. domStyle, display;
  17589. // Ignore cases when the margin is correctly reported as 0, the bug only shows
  17590. // numbers larger.
  17591. if (result != '0px') {
  17592. domStyle = dom.style;
  17593. display = domStyle.display;
  17594. domStyle.display = 'inline-block';
  17595. result = (inline ? style : dom.ownerDocument.defaultView.getComputedStyle(dom, null)).marginRight;
  17596. domStyle.display = display;
  17597. }
  17598. return result;
  17599. }
  17600. function fixRightMarginAndInputFocus (dom, el, inline, style) {
  17601. var result = style.marginRight,
  17602. domStyle, cleaner, display;
  17603. if (result != '0px') {
  17604. domStyle = dom.style;
  17605. cleaner = Element.getRightMarginFixCleaner(dom);
  17606. display = domStyle.display;
  17607. domStyle.display = 'inline-block';
  17608. result = (inline ? style : dom.ownerDocument.defaultView.getComputedStyle(dom, '')).marginRight;
  17609. domStyle.display = display;
  17610. cleaner();
  17611. }
  17612. return result;
  17613. }
  17614. styleHooks = Element.prototype.styleHooks;
  17615. // Populate the LTR flavors of margin-before et.al. (see Ext.rtl.AbstractElement):
  17616. Element.populateStyleMap(styleHooks, ['left', 'right']);
  17617. // Ext.supports needs to be initialized (we run very early in the onready sequence),
  17618. // but it is OK to call Ext.supports.init() more times than necessary...
  17619. if (supports.init) {
  17620. supports.init();
  17621. }
  17622. // Fix bug caused by this: https://bugs.webkit.org/show_bug.cgi?id=13343
  17623. if (!supports.RightMargin) {
  17624. styleHooks.marginRight = styleHooks['margin-right'] = {
  17625. name: 'marginRight',
  17626. // TODO - Touch should use conditional compilation here or ensure that the
  17627. // underlying Ext.supports flags are set correctly...
  17628. get: (supports.DisplayChangeInputSelectionBug || supports.DisplayChangeTextAreaSelectionBug) ?
  17629. fixRightMarginAndInputFocus : fixRightMargin
  17630. };
  17631. }
  17632. if (!supports.TransparentColor) {
  17633. colorStyles = ['background-color', 'border-color', 'color', 'outline-color'];
  17634. for (i = colorStyles.length; i--; ) {
  17635. name = colorStyles[i];
  17636. camel = Element.normalize(name);
  17637. styleHooks[name] = styleHooks[camel] = {
  17638. name: camel,
  17639. get: fixTransparent
  17640. };
  17641. }
  17642. }
  17643. });
  17644. }());
  17645. //@tag dom,core
  17646. //@require Ext.dom.AbstractElement-style
  17647. //@define Ext.dom.AbstractElement-traversal
  17648. //@define Ext.dom.AbstractElement
  17649. /**
  17650. * @class Ext.dom.AbstractElement
  17651. */
  17652. Ext.dom.AbstractElement.override({
  17653. /**
  17654. * Looks at this node and then at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
  17655. * @param {String} selector The simple selector to test
  17656. * @param {Number/String/HTMLElement/Ext.Element} [limit]
  17657. * The max depth to search as a number or an element which causes the upward traversal to stop
  17658. * and is <b>not</b> considered for inclusion as the result. (defaults to 50 || document.documentElement)
  17659. * @param {Boolean} [returnEl=false] True to return a Ext.Element object instead of DOM node
  17660. * @return {HTMLElement} The matching DOM node (or null if no match was found)
  17661. */
  17662. findParent: function(simpleSelector, limit, returnEl) {
  17663. var target = this.dom,
  17664. topmost = document.documentElement,
  17665. depth = 0,
  17666. stopEl;
  17667. limit = limit || 50;
  17668. if (isNaN(limit)) {
  17669. stopEl = Ext.getDom(limit);
  17670. limit = Number.MAX_VALUE;
  17671. }
  17672. while (target && target.nodeType == 1 && depth < limit && target != topmost && target != stopEl) {
  17673. if (Ext.DomQuery.is(target, simpleSelector)) {
  17674. return returnEl ? Ext.get(target) : target;
  17675. }
  17676. depth++;
  17677. target = target.parentNode;
  17678. }
  17679. return null;
  17680. },
  17681. /**
  17682. * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
  17683. * @param {String} selector The simple selector to test
  17684. * @param {Number/String/HTMLElement/Ext.Element} [limit]
  17685. * The max depth to search as a number or an element which causes the upward traversal to stop
  17686. * and is <b>not</b> considered for inclusion as the result. (defaults to 50 || document.documentElement)
  17687. * @param {Boolean} [returnEl=false] True to return a Ext.Element object instead of DOM node
  17688. * @return {HTMLElement} The matching DOM node (or null if no match was found)
  17689. */
  17690. findParentNode: function(simpleSelector, limit, returnEl) {
  17691. var p = Ext.fly(this.dom.parentNode, '_internal');
  17692. return p ? p.findParent(simpleSelector, limit, returnEl) : null;
  17693. },
  17694. /**
  17695. * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child).
  17696. * This is a shortcut for findParentNode() that always returns an Ext.dom.Element.
  17697. * @param {String} selector The simple selector to test
  17698. * @param {Number/String/HTMLElement/Ext.Element} [limit]
  17699. * The max depth to search as a number or an element which causes the upward traversal to stop
  17700. * and is <b>not</b> considered for inclusion as the result. (defaults to 50 || document.documentElement)
  17701. * @return {Ext.Element} The matching DOM node (or null if no match was found)
  17702. */
  17703. up: function(simpleSelector, limit) {
  17704. return this.findParentNode(simpleSelector, limit, true);
  17705. },
  17706. /**
  17707. * Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
  17708. * @param {String} selector The CSS selector
  17709. * @param {Boolean} [unique] True to create a unique Ext.Element for each element. Defaults to a shared flyweight object.
  17710. * @return {Ext.CompositeElement} The composite element
  17711. */
  17712. select: function(selector, composite) {
  17713. return Ext.dom.Element.select(selector, this.dom, composite);
  17714. },
  17715. /**
  17716. * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
  17717. * @param {String} selector The CSS selector
  17718. * @return {HTMLElement[]} An array of the matched nodes
  17719. */
  17720. query: function(selector) {
  17721. return Ext.DomQuery.select(selector, this.dom);
  17722. },
  17723. /**
  17724. * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
  17725. * @param {String} selector The CSS selector
  17726. * @param {Boolean} [returnDom=false] True to return the DOM node instead of Ext.dom.Element
  17727. * @return {HTMLElement/Ext.dom.Element} The child Ext.dom.Element (or DOM node if returnDom = true)
  17728. */
  17729. down: function(selector, returnDom) {
  17730. var n = Ext.DomQuery.selectNode(selector, this.dom);
  17731. return returnDom ? n : Ext.get(n);
  17732. },
  17733. /**
  17734. * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
  17735. * @param {String} selector The CSS selector
  17736. * @param {Boolean} [returnDom=false] True to return the DOM node instead of Ext.dom.Element.
  17737. * @return {HTMLElement/Ext.dom.Element} The child Ext.dom.Element (or DOM node if returnDom = true)
  17738. */
  17739. child: function(selector, returnDom) {
  17740. var node,
  17741. me = this,
  17742. id;
  17743. // Pull the ID from the DOM (Ext.id also ensures that there *is* an ID).
  17744. // If this object is a Flyweight, it will not have an ID
  17745. id = Ext.id(me.dom);
  17746. // Escape "invalid" chars
  17747. id = Ext.escapeId(id);
  17748. node = Ext.DomQuery.selectNode('#' + id + " > " + selector, me.dom);
  17749. return returnDom ? node : Ext.get(node);
  17750. },
  17751. /**
  17752. * Gets the parent node for this element, optionally chaining up trying to match a selector
  17753. * @param {String} [selector] Find a parent node that matches the passed simple selector
  17754. * @param {Boolean} [returnDom=false] True to return a raw dom node instead of an Ext.dom.Element
  17755. * @return {Ext.dom.Element/HTMLElement} The parent node or null
  17756. */
  17757. parent: function(selector, returnDom) {
  17758. return this.matchNode('parentNode', 'parentNode', selector, returnDom);
  17759. },
  17760. /**
  17761. * Gets the next sibling, skipping text nodes
  17762. * @param {String} [selector] Find the next sibling that matches the passed simple selector
  17763. * @param {Boolean} [returnDom=false] True to return a raw dom node instead of an Ext.dom.Element
  17764. * @return {Ext.dom.Element/HTMLElement} The next sibling or null
  17765. */
  17766. next: function(selector, returnDom) {
  17767. return this.matchNode('nextSibling', 'nextSibling', selector, returnDom);
  17768. },
  17769. /**
  17770. * Gets the previous sibling, skipping text nodes
  17771. * @param {String} [selector] Find the previous sibling that matches the passed simple selector
  17772. * @param {Boolean} [returnDom=false] True to return a raw dom node instead of an Ext.dom.Element
  17773. * @return {Ext.dom.Element/HTMLElement} The previous sibling or null
  17774. */
  17775. prev: function(selector, returnDom) {
  17776. return this.matchNode('previousSibling', 'previousSibling', selector, returnDom);
  17777. },
  17778. /**
  17779. * Gets the first child, skipping text nodes
  17780. * @param {String} [selector] Find the next sibling that matches the passed simple selector
  17781. * @param {Boolean} [returnDom=false] True to return a raw dom node instead of an Ext.dom.Element
  17782. * @return {Ext.dom.Element/HTMLElement} The first child or null
  17783. */
  17784. first: function(selector, returnDom) {
  17785. return this.matchNode('nextSibling', 'firstChild', selector, returnDom);
  17786. },
  17787. /**
  17788. * Gets the last child, skipping text nodes
  17789. * @param {String} [selector] Find the previous sibling that matches the passed simple selector
  17790. * @param {Boolean} [returnDom=false] True to return a raw dom node instead of an Ext.dom.Element
  17791. * @return {Ext.dom.Element/HTMLElement} The last child or null
  17792. */
  17793. last: function(selector, returnDom) {
  17794. return this.matchNode('previousSibling', 'lastChild', selector, returnDom);
  17795. },
  17796. matchNode: function(dir, start, selector, returnDom) {
  17797. if (!this.dom) {
  17798. return null;
  17799. }
  17800. var n = this.dom[start];
  17801. while (n) {
  17802. if (n.nodeType == 1 && (!selector || Ext.DomQuery.is(n, selector))) {
  17803. return !returnDom ? Ext.get(n) : n;
  17804. }
  17805. n = n[dir];
  17806. }
  17807. return null;
  17808. },
  17809. isAncestor: function(element) {
  17810. return this.self.isAncestor.call(this.self, this.dom, element);
  17811. }
  17812. });
  17813. //@tag dom,core
  17814. //@define Ext.DomHelper
  17815. //@define Ext.core.DomHelper
  17816. //@require Ext.dom.AbstractElement-traversal
  17817. /**
  17818. * @class Ext.DomHelper
  17819. * @extends Ext.dom.Helper
  17820. * @alternateClassName Ext.core.DomHelper
  17821. * @singleton
  17822. *
  17823. * The DomHelper class provides a layer of abstraction from DOM and transparently supports creating elements via DOM or
  17824. * using HTML fragments. It also has the ability to create HTML fragment templates from your DOM building code.
  17825. *
  17826. * # DomHelper element specification object
  17827. *
  17828. * A specification object is used when creating elements. Attributes of this object are assumed to be element
  17829. * attributes, except for 4 special attributes:
  17830. *
  17831. * - **tag** - The tag name of the element.
  17832. * - **children** or **cn** - An array of the same kind of element definition objects to be created and appended.
  17833. * These can be nested as deep as you want.
  17834. * - **cls** - The class attribute of the element. This will end up being either the "class" attribute on a HTML
  17835. * fragment or className for a DOM node, depending on whether DomHelper is using fragments or DOM.
  17836. * - **html** - The innerHTML for the element.
  17837. *
  17838. * **NOTE:** For other arbitrary attributes, the value will currently **not** be automatically HTML-escaped prior to
  17839. * building the element's HTML string. This means that if your attribute value contains special characters that would
  17840. * not normally be allowed in a double-quoted attribute value, you **must** manually HTML-encode it beforehand (see
  17841. * {@link Ext.String#htmlEncode}) or risk malformed HTML being created. This behavior may change in a future release.
  17842. *
  17843. * # Insertion methods
  17844. *
  17845. * Commonly used insertion methods:
  17846. *
  17847. * - **{@link #append}**
  17848. * - **{@link #insertBefore}**
  17849. * - **{@link #insertAfter}**
  17850. * - **{@link #overwrite}**
  17851. * - **{@link #createTemplate}**
  17852. * - **{@link #insertHtml}**
  17853. *
  17854. * # Example
  17855. *
  17856. * This is an example, where an unordered list with 3 children items is appended to an existing element with
  17857. * id 'my-div':
  17858. *
  17859. * var dh = Ext.DomHelper; // create shorthand alias
  17860. * // specification object
  17861. * var spec = {
  17862. * id: 'my-ul',
  17863. * tag: 'ul',
  17864. * cls: 'my-list',
  17865. * // append children after creating
  17866. * children: [ // may also specify 'cn' instead of 'children'
  17867. * {tag: 'li', id: 'item0', html: 'List Item 0'},
  17868. * {tag: 'li', id: 'item1', html: 'List Item 1'},
  17869. * {tag: 'li', id: 'item2', html: 'List Item 2'}
  17870. * ]
  17871. * };
  17872. * var list = dh.append(
  17873. * 'my-div', // the context element 'my-div' can either be the id or the actual node
  17874. * spec // the specification object
  17875. * );
  17876. *
  17877. * Element creation specification parameters in this class may also be passed as an Array of specification objects. This
  17878. * can be used to insert multiple sibling nodes into an existing container very efficiently. For example, to add more
  17879. * list items to the example above:
  17880. *
  17881. * dh.append('my-ul', [
  17882. * {tag: 'li', id: 'item3', html: 'List Item 3'},
  17883. * {tag: 'li', id: 'item4', html: 'List Item 4'}
  17884. * ]);
  17885. *
  17886. * # Templating
  17887. *
  17888. * The real power is in the built-in templating. Instead of creating or appending any elements, {@link #createTemplate}
  17889. * returns a Template object which can be used over and over to insert new elements. Revisiting the example above, we
  17890. * could utilize templating this time:
  17891. *
  17892. * // create the node
  17893. * var list = dh.append('my-div', {tag: 'ul', cls: 'my-list'});
  17894. * // get template
  17895. * var tpl = dh.createTemplate({tag: 'li', id: 'item{0}', html: 'List Item {0}'});
  17896. *
  17897. * for(var i = 0; i < 5, i++){
  17898. * tpl.append(list, [i]); // use template to append to the actual node
  17899. * }
  17900. *
  17901. * An example using a template:
  17902. *
  17903. * var html = '<a id="{0}" href="{1}" class="nav">{2}</a>';
  17904. *
  17905. * var tpl = new Ext.DomHelper.createTemplate(html);
  17906. * tpl.append('blog-roll', ['link1', 'http://www.edspencer.net/', "Ed's Site"]);
  17907. * tpl.append('blog-roll', ['link2', 'http://www.dustindiaz.com/', "Dustin's Site"]);
  17908. *
  17909. * The same example using named parameters:
  17910. *
  17911. * var html = '<a id="{id}" href="{url}" class="nav">{text}</a>';
  17912. *
  17913. * var tpl = new Ext.DomHelper.createTemplate(html);
  17914. * tpl.append('blog-roll', {
  17915. * id: 'link1',
  17916. * url: 'http://www.edspencer.net/',
  17917. * text: "Ed's Site"
  17918. * });
  17919. * tpl.append('blog-roll', {
  17920. * id: 'link2',
  17921. * url: 'http://www.dustindiaz.com/',
  17922. * text: "Dustin's Site"
  17923. * });
  17924. *
  17925. * # Compiling Templates
  17926. *
  17927. * Templates are applied using regular expressions. The performance is great, but if you are adding a bunch of DOM
  17928. * elements using the same template, you can increase performance even further by {@link Ext.Template#compile
  17929. * "compiling"} the template. The way "{@link Ext.Template#compile compile()}" works is the template is parsed and
  17930. * broken up at the different variable points and a dynamic function is created and eval'ed. The generated function
  17931. * performs string concatenation of these parts and the passed variables instead of using regular expressions.
  17932. *
  17933. * var html = '<a id="{id}" href="{url}" class="nav">{text}</a>';
  17934. *
  17935. * var tpl = new Ext.DomHelper.createTemplate(html);
  17936. * tpl.compile();
  17937. *
  17938. * //... use template like normal
  17939. *
  17940. * # Performance Boost
  17941. *
  17942. * DomHelper will transparently create HTML fragments when it can. Using HTML fragments instead of DOM can significantly
  17943. * boost performance.
  17944. *
  17945. * Element creation specification parameters may also be strings. If {@link #useDom} is false, then the string is used
  17946. * as innerHTML. If {@link #useDom} is true, a string specification results in the creation of a text node. Usage:
  17947. *
  17948. * Ext.DomHelper.useDom = true; // force it to use DOM; reduces performance
  17949. *
  17950. */
  17951. (function() {
  17952. // kill repeat to save bytes
  17953. var afterbegin = 'afterbegin',
  17954. afterend = 'afterend',
  17955. beforebegin = 'beforebegin',
  17956. beforeend = 'beforeend',
  17957. ts = '<table>',
  17958. te = '</table>',
  17959. tbs = ts+'<tbody>',
  17960. tbe = '</tbody>'+te,
  17961. trs = tbs + '<tr>',
  17962. tre = '</tr>'+tbe,
  17963. detachedDiv = document.createElement('div'),
  17964. bbValues = ['BeforeBegin', 'previousSibling'],
  17965. aeValues = ['AfterEnd', 'nextSibling'],
  17966. bb_ae_PositionHash = {
  17967. beforebegin: bbValues,
  17968. afterend: aeValues
  17969. },
  17970. fullPositionHash = {
  17971. beforebegin: bbValues,
  17972. afterend: aeValues,
  17973. afterbegin: ['AfterBegin', 'firstChild'],
  17974. beforeend: ['BeforeEnd', 'lastChild']
  17975. };
  17976. /**
  17977. * The actual class of which {@link Ext.DomHelper} is instance of.
  17978. *
  17979. * Use singleton {@link Ext.DomHelper} instead.
  17980. *
  17981. * @private
  17982. */
  17983. Ext.define('Ext.dom.Helper', {
  17984. extend: 'Ext.dom.AbstractHelper',
  17985. requires:['Ext.dom.AbstractElement'],
  17986. tableRe: /^table|tbody|tr|td$/i,
  17987. tableElRe: /td|tr|tbody/i,
  17988. /**
  17989. * @property {Boolean} useDom
  17990. * True to force the use of DOM instead of html fragments.
  17991. */
  17992. useDom : false,
  17993. /**
  17994. * Creates new DOM element(s) without inserting them to the document.
  17995. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  17996. * @return {HTMLElement} The new uninserted node
  17997. */
  17998. createDom: function(o, parentNode){
  17999. var el,
  18000. doc = document,
  18001. useSet,
  18002. attr,
  18003. val,
  18004. cn,
  18005. i, l;
  18006. if (Ext.isArray(o)) { // Allow Arrays of siblings to be inserted
  18007. el = doc.createDocumentFragment(); // in one shot using a DocumentFragment
  18008. for (i = 0, l = o.length; i < l; i++) {
  18009. this.createDom(o[i], el);
  18010. }
  18011. } else if (typeof o == 'string') { // Allow a string as a child spec.
  18012. el = doc.createTextNode(o);
  18013. } else {
  18014. el = doc.createElement(o.tag || 'div');
  18015. useSet = !!el.setAttribute; // In IE some elements don't have setAttribute
  18016. for (attr in o) {
  18017. if (!this.confRe.test(attr)) {
  18018. val = o[attr];
  18019. if (attr == 'cls') {
  18020. el.className = val;
  18021. } else {
  18022. if (useSet) {
  18023. el.setAttribute(attr, val);
  18024. } else {
  18025. el[attr] = val;
  18026. }
  18027. }
  18028. }
  18029. }
  18030. Ext.DomHelper.applyStyles(el, o.style);
  18031. if ((cn = o.children || o.cn)) {
  18032. this.createDom(cn, el);
  18033. } else if (o.html) {
  18034. el.innerHTML = o.html;
  18035. }
  18036. }
  18037. if (parentNode) {
  18038. parentNode.appendChild(el);
  18039. }
  18040. return el;
  18041. },
  18042. ieTable: function(depth, openingTags, htmlContent, closingTags){
  18043. detachedDiv.innerHTML = [openingTags, htmlContent, closingTags].join('');
  18044. var i = -1,
  18045. el = detachedDiv,
  18046. ns;
  18047. while (++i < depth) {
  18048. el = el.firstChild;
  18049. }
  18050. // If the result is multiple siblings, then encapsulate them into one fragment.
  18051. ns = el.nextSibling;
  18052. if (ns) {
  18053. el = document.createDocumentFragment();
  18054. while (ns) {
  18055. el.appendChild(ns);
  18056. ns = ns.nextSibling;
  18057. }
  18058. }
  18059. return el;
  18060. },
  18061. /**
  18062. * @private
  18063. * Nasty code for IE's broken table implementation
  18064. */
  18065. insertIntoTable: function(tag, where, destinationEl, html) {
  18066. var node,
  18067. before,
  18068. bb = where == beforebegin,
  18069. ab = where == afterbegin,
  18070. be = where == beforeend,
  18071. ae = where == afterend;
  18072. if (tag == 'td' && (ab || be) || !this.tableElRe.test(tag) && (bb || ae)) {
  18073. return null;
  18074. }
  18075. before = bb ? destinationEl :
  18076. ae ? destinationEl.nextSibling :
  18077. ab ? destinationEl.firstChild : null;
  18078. if (bb || ae) {
  18079. destinationEl = destinationEl.parentNode;
  18080. }
  18081. if (tag == 'td' || (tag == 'tr' && (be || ab))) {
  18082. node = this.ieTable(4, trs, html, tre);
  18083. } else if ((tag == 'tbody' && (be || ab)) ||
  18084. (tag == 'tr' && (bb || ae))) {
  18085. node = this.ieTable(3, tbs, html, tbe);
  18086. } else {
  18087. node = this.ieTable(2, ts, html, te);
  18088. }
  18089. destinationEl.insertBefore(node, before);
  18090. return node;
  18091. },
  18092. /**
  18093. * @private
  18094. * Fix for IE9 createContextualFragment missing method
  18095. */
  18096. createContextualFragment: function(html) {
  18097. var fragment = document.createDocumentFragment(),
  18098. length, childNodes;
  18099. detachedDiv.innerHTML = html;
  18100. childNodes = detachedDiv.childNodes;
  18101. length = childNodes.length;
  18102. // Move nodes into fragment, don't clone: http://jsperf.com/create-fragment
  18103. while (length--) {
  18104. fragment.appendChild(childNodes[0]);
  18105. }
  18106. return fragment;
  18107. },
  18108. applyStyles: function(el, styles) {
  18109. if (styles) {
  18110. el = Ext.fly(el);
  18111. if (typeof styles == "function") {
  18112. styles = styles.call();
  18113. }
  18114. if (typeof styles == "string") {
  18115. styles = Ext.dom.Element.parseStyles(styles);
  18116. }
  18117. if (typeof styles == "object") {
  18118. el.setStyle(styles);
  18119. }
  18120. }
  18121. },
  18122. /**
  18123. * Alias for {@link #markup}.
  18124. * @inheritdoc Ext.dom.AbstractHelper#markup
  18125. */
  18126. createHtml: function(spec) {
  18127. return this.markup(spec);
  18128. },
  18129. doInsert: function(el, o, returnElement, pos, sibling, append) {
  18130. el = el.dom || Ext.getDom(el);
  18131. var newNode;
  18132. if (this.useDom) {
  18133. newNode = this.createDom(o, null);
  18134. if (append) {
  18135. el.appendChild(newNode);
  18136. }
  18137. else {
  18138. (sibling == 'firstChild' ? el : el.parentNode).insertBefore(newNode, el[sibling] || el);
  18139. }
  18140. } else {
  18141. newNode = this.insertHtml(pos, el, this.markup(o));
  18142. }
  18143. return returnElement ? Ext.get(newNode, true) : newNode;
  18144. },
  18145. /**
  18146. * Creates new DOM element(s) and overwrites the contents of el with them.
  18147. * @param {String/HTMLElement/Ext.Element} el The context element
  18148. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  18149. * @param {Boolean} [returnElement] true to return an Ext.Element
  18150. * @return {HTMLElement/Ext.Element} The new node
  18151. */
  18152. overwrite: function(el, html, returnElement) {
  18153. var newNode;
  18154. el = Ext.getDom(el);
  18155. html = this.markup(html);
  18156. // IE Inserting HTML into a table/tbody/tr requires extra processing: http://www.ericvasilik.com/2006/07/code-karma.html
  18157. if (Ext.isIE && this.tableRe.test(el.tagName)) {
  18158. // Clearing table elements requires removal of all elements.
  18159. while (el.firstChild) {
  18160. el.removeChild(el.firstChild);
  18161. }
  18162. if (html) {
  18163. newNode = this.insertHtml('afterbegin', el, html);
  18164. return returnElement ? Ext.get(newNode) : newNode;
  18165. }
  18166. return null;
  18167. }
  18168. el.innerHTML = html;
  18169. return returnElement ? Ext.get(el.firstChild) : el.firstChild;
  18170. },
  18171. insertHtml: function(where, el, html) {
  18172. var hashVal,
  18173. range,
  18174. rangeEl,
  18175. setStart,
  18176. frag;
  18177. where = where.toLowerCase();
  18178. // Has fast HTML insertion into existing DOM: http://www.w3.org/TR/html5/apis-in-html-documents.html#insertadjacenthtml
  18179. if (el.insertAdjacentHTML) {
  18180. // IE's incomplete table implementation: http://www.ericvasilik.com/2006/07/code-karma.html
  18181. if (Ext.isIE && this.tableRe.test(el.tagName) && (frag = this.insertIntoTable(el.tagName.toLowerCase(), where, el, html))) {
  18182. return frag;
  18183. }
  18184. if ((hashVal = fullPositionHash[where])) {
  18185. el.insertAdjacentHTML(hashVal[0], html);
  18186. return el[hashVal[1]];
  18187. }
  18188. // if (not IE and context element is an HTMLElement) or TextNode
  18189. } else {
  18190. // we cannot insert anything inside a textnode so...
  18191. if (el.nodeType === 3) {
  18192. where = where === 'afterbegin' ? 'beforebegin' : where;
  18193. where = where === 'beforeend' ? 'afterend' : where;
  18194. }
  18195. range = Ext.supports.CreateContextualFragment ? el.ownerDocument.createRange() : undefined;
  18196. setStart = 'setStart' + (this.endRe.test(where) ? 'After' : 'Before');
  18197. if (bb_ae_PositionHash[where]) {
  18198. if (range) {
  18199. range[setStart](el);
  18200. frag = range.createContextualFragment(html);
  18201. } else {
  18202. frag = this.createContextualFragment(html);
  18203. }
  18204. el.parentNode.insertBefore(frag, where == beforebegin ? el : el.nextSibling);
  18205. return el[(where == beforebegin ? 'previous' : 'next') + 'Sibling'];
  18206. } else {
  18207. rangeEl = (where == afterbegin ? 'first' : 'last') + 'Child';
  18208. if (el.firstChild) {
  18209. if (range) {
  18210. range[setStart](el[rangeEl]);
  18211. frag = range.createContextualFragment(html);
  18212. } else {
  18213. frag = this.createContextualFragment(html);
  18214. }
  18215. if (where == afterbegin) {
  18216. el.insertBefore(frag, el.firstChild);
  18217. } else {
  18218. el.appendChild(frag);
  18219. }
  18220. } else {
  18221. el.innerHTML = html;
  18222. }
  18223. return el[rangeEl];
  18224. }
  18225. }
  18226. Ext.Error.raise({
  18227. sourceClass: 'Ext.DomHelper',
  18228. sourceMethod: 'insertHtml',
  18229. htmlToInsert: html,
  18230. targetElement: el,
  18231. msg: 'Illegal insertion point reached: "' + where + '"'
  18232. });
  18233. },
  18234. /**
  18235. * Creates a new Ext.Template from the DOM object spec.
  18236. * @param {Object} o The DOM object spec (and children)
  18237. * @return {Ext.Template} The new template
  18238. */
  18239. createTemplate: function(o) {
  18240. var html = this.markup(o);
  18241. return new Ext.Template(html);
  18242. }
  18243. }, function() {
  18244. Ext.ns('Ext.core');
  18245. Ext.DomHelper = Ext.core.DomHelper = new this;
  18246. });
  18247. }());
  18248. //@tag dom,core
  18249. //@require Helper.js
  18250. //@define Ext.dom.Query
  18251. //@define Ext.core.Query
  18252. //@define Ext.DomQuery
  18253. /*
  18254. * This is code is also distributed under MIT license for use
  18255. * with jQuery and prototype JavaScript libraries.
  18256. */
  18257. /**
  18258. * @class Ext.dom.Query
  18259. * @alternateClassName Ext.DomQuery
  18260. * @alternateClassName Ext.core.DomQuery
  18261. * @singleton
  18262. *
  18263. * Provides high performance selector/xpath processing by compiling queries into reusable functions. New pseudo classes
  18264. * and matchers can be plugged. It works on HTML and XML documents (if a content node is passed in).
  18265. *
  18266. * DomQuery supports most of the [CSS3 selectors spec][1], along with some custom selectors and basic XPath.
  18267. *
  18268. * All selectors, attribute filters and pseudos below can be combined infinitely in any order. For example
  18269. * `div.foo:nth-child(odd)[@foo=bar].bar:first` would be a perfectly valid selector. Node filters are processed
  18270. * in the order in which they appear, which allows you to optimize your queries for your document structure.
  18271. *
  18272. * ## Element Selectors:
  18273. *
  18274. * - **`*`** any element
  18275. * - **`E`** an element with the tag E
  18276. * - **`E F`** All descendent elements of E that have the tag F
  18277. * - **`E > F`** or **E/F** all direct children elements of E that have the tag F
  18278. * - **`E + F`** all elements with the tag F that are immediately preceded by an element with the tag E
  18279. * - **`E ~ F`** all elements with the tag F that are preceded by a sibling element with the tag E
  18280. *
  18281. * ## Attribute Selectors:
  18282. *
  18283. * The use of `@` and quotes are optional. For example, `div[@foo='bar']` is also a valid attribute selector.
  18284. *
  18285. * - **`E[foo]`** has an attribute "foo"
  18286. * - **`E[foo=bar]`** has an attribute "foo" that equals "bar"
  18287. * - **`E[foo^=bar]`** has an attribute "foo" that starts with "bar"
  18288. * - **`E[foo$=bar]`** has an attribute "foo" that ends with "bar"
  18289. * - **`E[foo*=bar]`** has an attribute "foo" that contains the substring "bar"
  18290. * - **`E[foo%=2]`** has an attribute "foo" that is evenly divisible by 2
  18291. * - **`E[foo!=bar]`** attribute "foo" does not equal "bar"
  18292. *
  18293. * ## Pseudo Classes:
  18294. *
  18295. * - **`E:first-child`** E is the first child of its parent
  18296. * - **`E:last-child`** E is the last child of its parent
  18297. * - **`E:nth-child(_n_)`** E is the _n_th child of its parent (1 based as per the spec)
  18298. * - **`E:nth-child(odd)`** E is an odd child of its parent
  18299. * - **`E:nth-child(even)`** E is an even child of its parent
  18300. * - **`E:only-child`** E is the only child of its parent
  18301. * - **`E:checked`** E is an element that is has a checked attribute that is true (e.g. a radio or checkbox)
  18302. * - **`E:first`** the first E in the resultset
  18303. * - **`E:last`** the last E in the resultset
  18304. * - **`E:nth(_n_)`** the _n_th E in the resultset (1 based)
  18305. * - **`E:odd`** shortcut for :nth-child(odd)
  18306. * - **`E:even`** shortcut for :nth-child(even)
  18307. * - **`E:contains(foo)`** E's innerHTML contains the substring "foo"
  18308. * - **`E:nodeValue(foo)`** E contains a textNode with a nodeValue that equals "foo"
  18309. * - **`E:not(S)`** an E element that does not match simple selector S
  18310. * - **`E:has(S)`** an E element that has a descendent that matches simple selector S
  18311. * - **`E:next(S)`** an E element whose next sibling matches simple selector S
  18312. * - **`E:prev(S)`** an E element whose previous sibling matches simple selector S
  18313. * - **`E:any(S1|S2|S2)`** an E element which matches any of the simple selectors S1, S2 or S3
  18314. *
  18315. * ## CSS Value Selectors:
  18316. *
  18317. * - **`E{display=none}`** css value "display" that equals "none"
  18318. * - **`E{display^=none}`** css value "display" that starts with "none"
  18319. * - **`E{display$=none}`** css value "display" that ends with "none"
  18320. * - **`E{display*=none}`** css value "display" that contains the substring "none"
  18321. * - **`E{display%=2}`** css value "display" that is evenly divisible by 2
  18322. * - **`E{display!=none}`** css value "display" that does not equal "none"
  18323. *
  18324. * [1]: http://www.w3.org/TR/2005/WD-css3-selectors-20051215/#selectors
  18325. */
  18326. Ext.ns('Ext.core');
  18327. Ext.dom.Query = Ext.core.DomQuery = Ext.DomQuery = (function(){
  18328. var cache = {},
  18329. simpleCache = {},
  18330. valueCache = {},
  18331. nonSpace = /\S/,
  18332. trimRe = /^\s+|\s+$/g,
  18333. tplRe = /\{(\d+)\}/g,
  18334. modeRe = /^(\s?[\/>+~]\s?|\s|$)/,
  18335. tagTokenRe = /^(#)?([\w\-\*\\]+)/,
  18336. nthRe = /(\d*)n\+?(\d*)/,
  18337. nthRe2 = /\D/,
  18338. startIdRe = /^\s*\#/,
  18339. // This is for IE MSXML which does not support expandos.
  18340. // IE runs the same speed using setAttribute, however FF slows way down
  18341. // and Safari completely fails so they need to continue to use expandos.
  18342. isIE = window.ActiveXObject ? true : false,
  18343. key = 30803,
  18344. longHex = /\\([0-9a-fA-F]{6})/g,
  18345. shortHex = /\\([0-9a-fA-F]{1,6})\s{0,1}/g,
  18346. nonHex = /\\([^0-9a-fA-F]{1})/g,
  18347. escapes = /\\/g,
  18348. num, hasEscapes,
  18349. // replaces a long hex regex match group with the appropriate ascii value
  18350. // $args indicate regex match pos
  18351. longHexToChar = function($0, $1) {
  18352. return String.fromCharCode(parseInt($1, 16));
  18353. },
  18354. // converts a shortHex regex match to the long form
  18355. shortToLongHex = function($0, $1) {
  18356. while ($1.length < 6) {
  18357. $1 = '0' + $1;
  18358. }
  18359. return '\\' + $1;
  18360. },
  18361. // converts a single char escape to long escape form
  18362. charToLongHex = function($0, $1) {
  18363. num = $1.charCodeAt(0).toString(16);
  18364. if (num.length === 1) {
  18365. num = '0' + num;
  18366. }
  18367. return '\\0000' + num;
  18368. },
  18369. // Un-escapes an input selector string. Assumes all escape sequences have been
  18370. // normalized to the css '\\0000##' 6-hex-digit style escape sequence :
  18371. // will not handle any other escape formats
  18372. unescapeCssSelector = function (selector) {
  18373. return (hasEscapes)
  18374. ? selector.replace(longHex, longHexToChar)
  18375. : selector;
  18376. },
  18377. // checks if the path has escaping & does any appropriate replacements
  18378. setupEscapes = function(path){
  18379. hasEscapes = (path.indexOf('\\') > -1);
  18380. if (hasEscapes) {
  18381. path = path
  18382. .replace(shortHex, shortToLongHex)
  18383. .replace(nonHex, charToLongHex)
  18384. .replace(escapes, '\\\\'); // double the '\' for js compilation
  18385. }
  18386. return path;
  18387. };
  18388. // this eval is stop the compressor from
  18389. // renaming the variable to something shorter
  18390. eval("var batch = 30803;");
  18391. // Retrieve the child node from a particular
  18392. // parent at the specified index.
  18393. function child(parent, index){
  18394. var i = 0,
  18395. n = parent.firstChild;
  18396. while(n){
  18397. if(n.nodeType == 1){
  18398. if(++i == index){
  18399. return n;
  18400. }
  18401. }
  18402. n = n.nextSibling;
  18403. }
  18404. return null;
  18405. }
  18406. // retrieve the next element node
  18407. function next(n){
  18408. while((n = n.nextSibling) && n.nodeType != 1);
  18409. return n;
  18410. }
  18411. // retrieve the previous element node
  18412. function prev(n){
  18413. while((n = n.previousSibling) && n.nodeType != 1);
  18414. return n;
  18415. }
  18416. // Mark each child node with a nodeIndex skipping and
  18417. // removing empty text nodes.
  18418. function children(parent){
  18419. var n = parent.firstChild,
  18420. nodeIndex = -1,
  18421. nextNode;
  18422. while(n){
  18423. nextNode = n.nextSibling;
  18424. // clean worthless empty nodes.
  18425. if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
  18426. parent.removeChild(n);
  18427. }else{
  18428. // add an expando nodeIndex
  18429. n.nodeIndex = ++nodeIndex;
  18430. }
  18431. n = nextNode;
  18432. }
  18433. return this;
  18434. }
  18435. // nodeSet - array of nodes
  18436. // cls - CSS Class
  18437. function byClassName(nodeSet, cls){
  18438. cls = unescapeCssSelector(cls);
  18439. if(!cls){
  18440. return nodeSet;
  18441. }
  18442. var result = [], ri = -1,
  18443. i, ci;
  18444. for(i = 0, ci; ci = nodeSet[i]; i++){
  18445. if((' '+ci.className+' ').indexOf(cls) != -1){
  18446. result[++ri] = ci;
  18447. }
  18448. }
  18449. return result;
  18450. }
  18451. function attrValue(n, attr){
  18452. // if its an array, use the first node.
  18453. if(!n.tagName && typeof n.length != "undefined"){
  18454. n = n[0];
  18455. }
  18456. if(!n){
  18457. return null;
  18458. }
  18459. if(attr == "for"){
  18460. return n.htmlFor;
  18461. }
  18462. if(attr == "class" || attr == "className"){
  18463. return n.className;
  18464. }
  18465. return n.getAttribute(attr) || n[attr];
  18466. }
  18467. // ns - nodes
  18468. // mode - false, /, >, +, ~
  18469. // tagName - defaults to "*"
  18470. function getNodes(ns, mode, tagName){
  18471. var result = [], ri = -1, cs,
  18472. i, ni, j, ci, cn, utag, n, cj;
  18473. if(!ns){
  18474. return result;
  18475. }
  18476. tagName = tagName || "*";
  18477. // convert to array
  18478. if(typeof ns.getElementsByTagName != "undefined"){
  18479. ns = [ns];
  18480. }
  18481. // no mode specified, grab all elements by tagName
  18482. // at any depth
  18483. if(!mode){
  18484. for(i = 0, ni; ni = ns[i]; i++){
  18485. cs = ni.getElementsByTagName(tagName);
  18486. for(j = 0, ci; ci = cs[j]; j++){
  18487. result[++ri] = ci;
  18488. }
  18489. }
  18490. // Direct Child mode (/ or >)
  18491. // E > F or E/F all direct children elements of E that have the tag
  18492. } else if(mode == "/" || mode == ">"){
  18493. utag = tagName.toUpperCase();
  18494. for(i = 0, ni, cn; ni = ns[i]; i++){
  18495. cn = ni.childNodes;
  18496. for(j = 0, cj; cj = cn[j]; j++){
  18497. if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
  18498. result[++ri] = cj;
  18499. }
  18500. }
  18501. }
  18502. // Immediately Preceding mode (+)
  18503. // E + F all elements with the tag F that are immediately preceded by an element with the tag E
  18504. }else if(mode == "+"){
  18505. utag = tagName.toUpperCase();
  18506. for(i = 0, n; n = ns[i]; i++){
  18507. while((n = n.nextSibling) && n.nodeType != 1);
  18508. if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
  18509. result[++ri] = n;
  18510. }
  18511. }
  18512. // Sibling mode (~)
  18513. // E ~ F all elements with the tag F that are preceded by a sibling element with the tag E
  18514. }else if(mode == "~"){
  18515. utag = tagName.toUpperCase();
  18516. for(i = 0, n; n = ns[i]; i++){
  18517. while((n = n.nextSibling)){
  18518. if (n.nodeName == utag || n.nodeName == tagName || tagName == '*'){
  18519. result[++ri] = n;
  18520. }
  18521. }
  18522. }
  18523. }
  18524. return result;
  18525. }
  18526. function concat(a, b){
  18527. if(b.slice){
  18528. return a.concat(b);
  18529. }
  18530. for(var i = 0, l = b.length; i < l; i++){
  18531. a[a.length] = b[i];
  18532. }
  18533. return a;
  18534. }
  18535. function byTag(cs, tagName){
  18536. if(cs.tagName || cs == document){
  18537. cs = [cs];
  18538. }
  18539. if(!tagName){
  18540. return cs;
  18541. }
  18542. var result = [], ri = -1,
  18543. i, ci;
  18544. tagName = tagName.toLowerCase();
  18545. for(i = 0, ci; ci = cs[i]; i++){
  18546. if(ci.nodeType == 1 && ci.tagName.toLowerCase() == tagName){
  18547. result[++ri] = ci;
  18548. }
  18549. }
  18550. return result;
  18551. }
  18552. function byId(cs, id){
  18553. id = unescapeCssSelector(id);
  18554. if(cs.tagName || cs == document){
  18555. cs = [cs];
  18556. }
  18557. if(!id){
  18558. return cs;
  18559. }
  18560. var result = [], ri = -1,
  18561. i, ci;
  18562. for(i = 0, ci; ci = cs[i]; i++){
  18563. if(ci && ci.id == id){
  18564. result[++ri] = ci;
  18565. return result;
  18566. }
  18567. }
  18568. return result;
  18569. }
  18570. // operators are =, !=, ^=, $=, *=, %=, |= and ~=
  18571. // custom can be "{"
  18572. function byAttribute(cs, attr, value, op, custom){
  18573. var result = [],
  18574. ri = -1,
  18575. useGetStyle = custom == "{",
  18576. fn = Ext.DomQuery.operators[op],
  18577. a,
  18578. xml,
  18579. hasXml,
  18580. i, ci;
  18581. value = unescapeCssSelector(value);
  18582. for(i = 0, ci; ci = cs[i]; i++){
  18583. // skip non-element nodes.
  18584. if(ci.nodeType != 1){
  18585. continue;
  18586. }
  18587. // only need to do this for the first node
  18588. if(!hasXml){
  18589. xml = Ext.DomQuery.isXml(ci);
  18590. hasXml = true;
  18591. }
  18592. // we only need to change the property names if we're dealing with html nodes, not XML
  18593. if(!xml){
  18594. if(useGetStyle){
  18595. a = Ext.DomQuery.getStyle(ci, attr);
  18596. } else if (attr == "class" || attr == "className"){
  18597. a = ci.className;
  18598. } else if (attr == "for"){
  18599. a = ci.htmlFor;
  18600. } else if (attr == "href"){
  18601. // getAttribute href bug
  18602. // http://www.glennjones.net/Post/809/getAttributehrefbug.htm
  18603. a = ci.getAttribute("href", 2);
  18604. } else{
  18605. a = ci.getAttribute(attr);
  18606. }
  18607. }else{
  18608. a = ci.getAttribute(attr);
  18609. }
  18610. if((fn && fn(a, value)) || (!fn && a)){
  18611. result[++ri] = ci;
  18612. }
  18613. }
  18614. return result;
  18615. }
  18616. function byPseudo(cs, name, value){
  18617. value = unescapeCssSelector(value);
  18618. return Ext.DomQuery.pseudos[name](cs, value);
  18619. }
  18620. function nodupIEXml(cs){
  18621. var d = ++key,
  18622. r,
  18623. i, len, c;
  18624. cs[0].setAttribute("_nodup", d);
  18625. r = [cs[0]];
  18626. for(i = 1, len = cs.length; i < len; i++){
  18627. c = cs[i];
  18628. if(!c.getAttribute("_nodup") != d){
  18629. c.setAttribute("_nodup", d);
  18630. r[r.length] = c;
  18631. }
  18632. }
  18633. for(i = 0, len = cs.length; i < len; i++){
  18634. cs[i].removeAttribute("_nodup");
  18635. }
  18636. return r;
  18637. }
  18638. function nodup(cs){
  18639. if(!cs){
  18640. return [];
  18641. }
  18642. var len = cs.length, c, i, r = cs, cj, ri = -1, d, j;
  18643. if(!len || typeof cs.nodeType != "undefined" || len == 1){
  18644. return cs;
  18645. }
  18646. if(isIE && typeof cs[0].selectSingleNode != "undefined"){
  18647. return nodupIEXml(cs);
  18648. }
  18649. d = ++key;
  18650. cs[0]._nodup = d;
  18651. for(i = 1; c = cs[i]; i++){
  18652. if(c._nodup != d){
  18653. c._nodup = d;
  18654. }else{
  18655. r = [];
  18656. for(j = 0; j < i; j++){
  18657. r[++ri] = cs[j];
  18658. }
  18659. for(j = i+1; cj = cs[j]; j++){
  18660. if(cj._nodup != d){
  18661. cj._nodup = d;
  18662. r[++ri] = cj;
  18663. }
  18664. }
  18665. return r;
  18666. }
  18667. }
  18668. return r;
  18669. }
  18670. function quickDiffIEXml(c1, c2){
  18671. var d = ++key,
  18672. r = [],
  18673. i, len;
  18674. for(i = 0, len = c1.length; i < len; i++){
  18675. c1[i].setAttribute("_qdiff", d);
  18676. }
  18677. for(i = 0, len = c2.length; i < len; i++){
  18678. if(c2[i].getAttribute("_qdiff") != d){
  18679. r[r.length] = c2[i];
  18680. }
  18681. }
  18682. for(i = 0, len = c1.length; i < len; i++){
  18683. c1[i].removeAttribute("_qdiff");
  18684. }
  18685. return r;
  18686. }
  18687. function quickDiff(c1, c2){
  18688. var len1 = c1.length,
  18689. d = ++key,
  18690. r = [],
  18691. i, len;
  18692. if(!len1){
  18693. return c2;
  18694. }
  18695. if(isIE && typeof c1[0].selectSingleNode != "undefined"){
  18696. return quickDiffIEXml(c1, c2);
  18697. }
  18698. for(i = 0; i < len1; i++){
  18699. c1[i]._qdiff = d;
  18700. }
  18701. for(i = 0, len = c2.length; i < len; i++){
  18702. if(c2[i]._qdiff != d){
  18703. r[r.length] = c2[i];
  18704. }
  18705. }
  18706. return r;
  18707. }
  18708. function quickId(ns, mode, root, id){
  18709. if(ns == root){
  18710. id = unescapeCssSelector(id);
  18711. var d = root.ownerDocument || root;
  18712. return d.getElementById(id);
  18713. }
  18714. ns = getNodes(ns, mode, "*");
  18715. return byId(ns, id);
  18716. }
  18717. return {
  18718. getStyle : function(el, name){
  18719. return Ext.fly(el).getStyle(name);
  18720. },
  18721. /**
  18722. * Compiles a selector/xpath query into a reusable function. The returned function
  18723. * takes one parameter "root" (optional), which is the context node from where the query should start.
  18724. * @param {String} selector The selector/xpath query
  18725. * @param {String} [type="select"] Either "select" or "simple" for a simple selector match
  18726. * @return {Function}
  18727. */
  18728. compile : function(path, type){
  18729. type = type || "select";
  18730. // setup fn preamble
  18731. var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"],
  18732. mode,
  18733. lastPath,
  18734. matchers = Ext.DomQuery.matchers,
  18735. matchersLn = matchers.length,
  18736. modeMatch,
  18737. // accept leading mode switch
  18738. lmode = path.match(modeRe),
  18739. tokenMatch, matched, j, t, m;
  18740. path = setupEscapes(path);
  18741. if(lmode && lmode[1]){
  18742. fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";';
  18743. path = path.replace(lmode[1], "");
  18744. }
  18745. // strip leading slashes
  18746. while(path.substr(0, 1)=="/"){
  18747. path = path.substr(1);
  18748. }
  18749. while(path && lastPath != path){
  18750. lastPath = path;
  18751. tokenMatch = path.match(tagTokenRe);
  18752. if(type == "select"){
  18753. if(tokenMatch){
  18754. // ID Selector
  18755. if(tokenMatch[1] == "#"){
  18756. fn[fn.length] = 'n = quickId(n, mode, root, "'+tokenMatch[2]+'");';
  18757. }else{
  18758. fn[fn.length] = 'n = getNodes(n, mode, "'+tokenMatch[2]+'");';
  18759. }
  18760. path = path.replace(tokenMatch[0], "");
  18761. }else if(path.substr(0, 1) != '@'){
  18762. fn[fn.length] = 'n = getNodes(n, mode, "*");';
  18763. }
  18764. // type of "simple"
  18765. }else{
  18766. if(tokenMatch){
  18767. if(tokenMatch[1] == "#"){
  18768. fn[fn.length] = 'n = byId(n, "'+tokenMatch[2]+'");';
  18769. }else{
  18770. fn[fn.length] = 'n = byTag(n, "'+tokenMatch[2]+'");';
  18771. }
  18772. path = path.replace(tokenMatch[0], "");
  18773. }
  18774. }
  18775. while(!(modeMatch = path.match(modeRe))){
  18776. matched = false;
  18777. for(j = 0; j < matchersLn; j++){
  18778. t = matchers[j];
  18779. m = path.match(t.re);
  18780. if(m){
  18781. fn[fn.length] = t.select.replace(tplRe, function(x, i){
  18782. return m[i];
  18783. });
  18784. path = path.replace(m[0], "");
  18785. matched = true;
  18786. break;
  18787. }
  18788. }
  18789. // prevent infinite loop on bad selector
  18790. if(!matched){
  18791. Ext.Error.raise({
  18792. sourceClass: 'Ext.DomQuery',
  18793. sourceMethod: 'compile',
  18794. msg: 'Error parsing selector. Parsing failed at "' + path + '"'
  18795. });
  18796. }
  18797. }
  18798. if(modeMatch[1]){
  18799. fn[fn.length] = 'mode="'+modeMatch[1].replace(trimRe, "")+'";';
  18800. path = path.replace(modeMatch[1], "");
  18801. }
  18802. }
  18803. // close fn out
  18804. fn[fn.length] = "return nodup(n);\n}";
  18805. // eval fn and return it
  18806. eval(fn.join(""));
  18807. return f;
  18808. },
  18809. /**
  18810. * Selects an array of DOM nodes using JavaScript-only implementation.
  18811. *
  18812. * Use {@link #select} to take advantage of browsers built-in support for CSS selectors.
  18813. * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
  18814. * @param {HTMLElement/String} [root=document] The start of the query.
  18815. * @return {HTMLElement[]} An Array of DOM elements which match the selector. If there are
  18816. * no matches, and empty Array is returned.
  18817. */
  18818. jsSelect: function(path, root, type){
  18819. // set root to doc if not specified.
  18820. root = root || document;
  18821. if(typeof root == "string"){
  18822. root = document.getElementById(root);
  18823. }
  18824. var paths = path.split(","),
  18825. results = [],
  18826. i, len, subPath, result;
  18827. // loop over each selector
  18828. for(i = 0, len = paths.length; i < len; i++){
  18829. subPath = paths[i].replace(trimRe, "");
  18830. // compile and place in cache
  18831. if(!cache[subPath]){
  18832. // When we compile, escaping is handled inside the compile method
  18833. cache[subPath] = Ext.DomQuery.compile(subPath, type);
  18834. if(!cache[subPath]){
  18835. Ext.Error.raise({
  18836. sourceClass: 'Ext.DomQuery',
  18837. sourceMethod: 'jsSelect',
  18838. msg: subPath + ' is not a valid selector'
  18839. });
  18840. }
  18841. } else {
  18842. // If we've already compiled, we still need to check if the
  18843. // selector has escaping and setup the appropriate flags
  18844. setupEscapes(subPath);
  18845. }
  18846. result = cache[subPath](root);
  18847. if(result && result != document){
  18848. results = results.concat(result);
  18849. }
  18850. }
  18851. // if there were multiple selectors, make sure dups
  18852. // are eliminated
  18853. if(paths.length > 1){
  18854. return nodup(results);
  18855. }
  18856. return results;
  18857. },
  18858. isXml: function(el) {
  18859. var docEl = (el ? el.ownerDocument || el : 0).documentElement;
  18860. return docEl ? docEl.nodeName !== "HTML" : false;
  18861. },
  18862. /**
  18863. * Selects an array of DOM nodes by CSS/XPath selector.
  18864. *
  18865. * Uses [document.querySelectorAll][0] if browser supports that, otherwise falls back to
  18866. * {@link Ext.dom.Query#jsSelect} to do the work.
  18867. *
  18868. * Aliased as {@link Ext#query}.
  18869. *
  18870. * [0]: https://developer.mozilla.org/en/DOM/document.querySelectorAll
  18871. *
  18872. * @param {String} path The selector/xpath query
  18873. * @param {HTMLElement} [root=document] The start of the query.
  18874. * @return {HTMLElement[]} An array of DOM elements (not a NodeList as returned by `querySelectorAll`).
  18875. * @param {String} [type="select"] Either "select" or "simple" for a simple selector match (only valid when
  18876. * used when the call is deferred to the jsSelect method)
  18877. * @method
  18878. */
  18879. select : document.querySelectorAll ? function(path, root, type) {
  18880. root = root || document;
  18881. if (!Ext.DomQuery.isXml(root)) {
  18882. try {
  18883. /*
  18884. * This checking here is to "fix" the behaviour of querySelectorAll
  18885. * for non root document queries. The way qsa works is intentional,
  18886. * however it's definitely not the expected way it should work.
  18887. * When descendant selectors are used, only the lowest selector must be inside the root!
  18888. * More info: http://ejohn.org/blog/thoughts-on-queryselectorall/
  18889. * So we create a descendant selector by prepending the root's ID, and query the parent node.
  18890. * UNLESS the root has no parent in which qsa will work perfectly.
  18891. *
  18892. * We only modify the path for single selectors (ie, no multiples),
  18893. * without a full parser it makes it difficult to do this correctly.
  18894. */
  18895. if (root.parentNode && (root.nodeType !== 9) && path.indexOf(',') === -1 && !startIdRe.test(path)) {
  18896. path = '#' + Ext.escapeId(Ext.id(root)) + ' ' + path;
  18897. root = root.parentNode;
  18898. }
  18899. return Ext.Array.toArray(root.querySelectorAll(path));
  18900. }
  18901. catch (e) {
  18902. }
  18903. }
  18904. return Ext.DomQuery.jsSelect.call(this, path, root, type);
  18905. } : function(path, root, type) {
  18906. return Ext.DomQuery.jsSelect.call(this, path, root, type);
  18907. },
  18908. /**
  18909. * Selects a single element.
  18910. * @param {String} selector The selector/xpath query
  18911. * @param {HTMLElement} [root=document] The start of the query.
  18912. * @return {HTMLElement} The DOM element which matched the selector.
  18913. */
  18914. selectNode : function(path, root){
  18915. return Ext.DomQuery.select(path, root)[0];
  18916. },
  18917. /**
  18918. * Selects the value of a node, optionally replacing null with the defaultValue.
  18919. * @param {String} selector The selector/xpath query
  18920. * @param {HTMLElement} [root=document] The start of the query.
  18921. * @param {String} [defaultValue] When specified, this is return as empty value.
  18922. * @return {String}
  18923. */
  18924. selectValue : function(path, root, defaultValue){
  18925. path = path.replace(trimRe, "");
  18926. if (!valueCache[path]) {
  18927. valueCache[path] = Ext.DomQuery.compile(path, "select");
  18928. } else {
  18929. setupEscapes(path);
  18930. }
  18931. var n = valueCache[path](root),
  18932. v;
  18933. n = n[0] ? n[0] : n;
  18934. // overcome a limitation of maximum textnode size
  18935. // Rumored to potentially crash IE6 but has not been confirmed.
  18936. // http://reference.sitepoint.com/javascript/Node/normalize
  18937. // https://developer.mozilla.org/En/DOM/Node.normalize
  18938. if (typeof n.normalize == 'function') {
  18939. n.normalize();
  18940. }
  18941. v = (n && n.firstChild ? n.firstChild.nodeValue : null);
  18942. return ((v === null||v === undefined||v==='') ? defaultValue : v);
  18943. },
  18944. /**
  18945. * Selects the value of a node, parsing integers and floats.
  18946. * Returns the defaultValue, or 0 if none is specified.
  18947. * @param {String} selector The selector/xpath query
  18948. * @param {HTMLElement} [root=document] The start of the query.
  18949. * @param {Number} [defaultValue] When specified, this is return as empty value.
  18950. * @return {Number}
  18951. */
  18952. selectNumber : function(path, root, defaultValue){
  18953. var v = Ext.DomQuery.selectValue(path, root, defaultValue || 0);
  18954. return parseFloat(v);
  18955. },
  18956. /**
  18957. * Returns true if the passed element(s) match the passed simple selector
  18958. * (e.g. `div.some-class` or `span:first-child`)
  18959. * @param {String/HTMLElement/HTMLElement[]} el An element id, element or array of elements
  18960. * @param {String} selector The simple selector to test
  18961. * @return {Boolean}
  18962. */
  18963. is : function(el, ss){
  18964. if(typeof el == "string"){
  18965. el = document.getElementById(el);
  18966. }
  18967. var isArray = Ext.isArray(el),
  18968. result = Ext.DomQuery.filter(isArray ? el : [el], ss);
  18969. return isArray ? (result.length == el.length) : (result.length > 0);
  18970. },
  18971. /**
  18972. * Filters an array of elements to only include matches of a simple selector
  18973. * (e.g. `div.some-class` or `span:first-child`)
  18974. * @param {HTMLElement[]} el An array of elements to filter
  18975. * @param {String} selector The simple selector to test
  18976. * @param {Boolean} nonMatches If true, it returns the elements that DON'T match the selector instead of the
  18977. * ones that match
  18978. * @return {HTMLElement[]} An Array of DOM elements which match the selector. If there are no matches, and empty
  18979. * Array is returned.
  18980. */
  18981. filter : function(els, ss, nonMatches){
  18982. ss = ss.replace(trimRe, "");
  18983. if (!simpleCache[ss]) {
  18984. simpleCache[ss] = Ext.DomQuery.compile(ss, "simple");
  18985. } else {
  18986. setupEscapes(ss);
  18987. }
  18988. var result = simpleCache[ss](els);
  18989. return nonMatches ? quickDiff(result, els) : result;
  18990. },
  18991. /**
  18992. * Collection of matching regular expressions and code snippets.
  18993. * Each capture group within `()` will be replace the `{}` in the select
  18994. * statement as specified by their index.
  18995. */
  18996. matchers : [{
  18997. re: /^\.([\w\-\\]+)/,
  18998. select: 'n = byClassName(n, " {1} ");'
  18999. }, {
  19000. re: /^\:([\w\-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
  19001. select: 'n = byPseudo(n, "{1}", "{2}");'
  19002. },{
  19003. re: /^(?:([\[\{])(?:@)?([\w\-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
  19004. select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
  19005. }, {
  19006. re: /^#([\w\-\\]+)/,
  19007. select: 'n = byId(n, "{1}");'
  19008. },{
  19009. re: /^@([\w\-]+)/,
  19010. select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
  19011. }
  19012. ],
  19013. /**
  19014. * Collection of operator comparison functions.
  19015. * The default operators are `=`, `!=`, `^=`, `$=`, `*=`, `%=`, `|=` and `~=`.
  19016. * New operators can be added as long as the match the format *c*`=` where *c*
  19017. * is any character other than space, `>`, or `<`.
  19018. */
  19019. operators : {
  19020. "=" : function(a, v){
  19021. return a == v;
  19022. },
  19023. "!=" : function(a, v){
  19024. return a != v;
  19025. },
  19026. "^=" : function(a, v){
  19027. return a && a.substr(0, v.length) == v;
  19028. },
  19029. "$=" : function(a, v){
  19030. return a && a.substr(a.length-v.length) == v;
  19031. },
  19032. "*=" : function(a, v){
  19033. return a && a.indexOf(v) !== -1;
  19034. },
  19035. "%=" : function(a, v){
  19036. return (a % v) == 0;
  19037. },
  19038. "|=" : function(a, v){
  19039. return a && (a == v || a.substr(0, v.length+1) == v+'-');
  19040. },
  19041. "~=" : function(a, v){
  19042. return a && (' '+a+' ').indexOf(' '+v+' ') != -1;
  19043. }
  19044. },
  19045. /**
  19046. * Object hash of "pseudo class" filter functions which are used when filtering selections.
  19047. * Each function is passed two parameters:
  19048. *
  19049. * - **c** : Array
  19050. * An Array of DOM elements to filter.
  19051. *
  19052. * - **v** : String
  19053. * The argument (if any) supplied in the selector.
  19054. *
  19055. * A filter function returns an Array of DOM elements which conform to the pseudo class.
  19056. * In addition to the provided pseudo classes listed above such as `first-child` and `nth-child`,
  19057. * developers may add additional, custom psuedo class filters to select elements according to application-specific requirements.
  19058. *
  19059. * For example, to filter `a` elements to only return links to __external__ resources:
  19060. *
  19061. * Ext.DomQuery.pseudos.external = function(c, v){
  19062. * var r = [], ri = -1;
  19063. * for(var i = 0, ci; ci = c[i]; i++){
  19064. * // Include in result set only if it's a link to an external resource
  19065. * if(ci.hostname != location.hostname){
  19066. * r[++ri] = ci;
  19067. * }
  19068. * }
  19069. * return r;
  19070. * };
  19071. *
  19072. * Then external links could be gathered with the following statement:
  19073. *
  19074. * var externalLinks = Ext.select("a:external");
  19075. */
  19076. pseudos : {
  19077. "first-child" : function(c){
  19078. var r = [], ri = -1, n,
  19079. i, ci;
  19080. for(i = 0; (ci = n = c[i]); i++){
  19081. while((n = n.previousSibling) && n.nodeType != 1);
  19082. if(!n){
  19083. r[++ri] = ci;
  19084. }
  19085. }
  19086. return r;
  19087. },
  19088. "last-child" : function(c){
  19089. var r = [], ri = -1, n,
  19090. i, ci;
  19091. for(i = 0; (ci = n = c[i]); i++){
  19092. while((n = n.nextSibling) && n.nodeType != 1);
  19093. if(!n){
  19094. r[++ri] = ci;
  19095. }
  19096. }
  19097. return r;
  19098. },
  19099. "nth-child" : function(c, a) {
  19100. var r = [], ri = -1,
  19101. m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a),
  19102. f = (m[1] || 1) - 0, l = m[2] - 0,
  19103. i, n, j, cn, pn;
  19104. for(i = 0; n = c[i]; i++){
  19105. pn = n.parentNode;
  19106. if (batch != pn._batch) {
  19107. j = 0;
  19108. for(cn = pn.firstChild; cn; cn = cn.nextSibling){
  19109. if(cn.nodeType == 1){
  19110. cn.nodeIndex = ++j;
  19111. }
  19112. }
  19113. pn._batch = batch;
  19114. }
  19115. if (f == 1) {
  19116. if (l == 0 || n.nodeIndex == l){
  19117. r[++ri] = n;
  19118. }
  19119. } else if ((n.nodeIndex + l) % f == 0){
  19120. r[++ri] = n;
  19121. }
  19122. }
  19123. return r;
  19124. },
  19125. "only-child" : function(c){
  19126. var r = [], ri = -1,
  19127. i, ci;
  19128. for(i = 0; ci = c[i]; i++){
  19129. if(!prev(ci) && !next(ci)){
  19130. r[++ri] = ci;
  19131. }
  19132. }
  19133. return r;
  19134. },
  19135. "empty" : function(c){
  19136. var r = [], ri = -1,
  19137. i, ci, cns, j, cn, empty;
  19138. for(i = 0, ci; ci = c[i]; i++){
  19139. cns = ci.childNodes;
  19140. j = 0;
  19141. empty = true;
  19142. while(cn = cns[j]){
  19143. ++j;
  19144. if(cn.nodeType == 1 || cn.nodeType == 3){
  19145. empty = false;
  19146. break;
  19147. }
  19148. }
  19149. if(empty){
  19150. r[++ri] = ci;
  19151. }
  19152. }
  19153. return r;
  19154. },
  19155. "contains" : function(c, v){
  19156. var r = [], ri = -1,
  19157. i, ci;
  19158. for(i = 0; ci = c[i]; i++){
  19159. if((ci.textContent||ci.innerText||ci.text||'').indexOf(v) != -1){
  19160. r[++ri] = ci;
  19161. }
  19162. }
  19163. return r;
  19164. },
  19165. "nodeValue" : function(c, v){
  19166. var r = [], ri = -1,
  19167. i, ci;
  19168. for(i = 0; ci = c[i]; i++){
  19169. if(ci.firstChild && ci.firstChild.nodeValue == v){
  19170. r[++ri] = ci;
  19171. }
  19172. }
  19173. return r;
  19174. },
  19175. "checked" : function(c){
  19176. var r = [], ri = -1,
  19177. i, ci;
  19178. for(i = 0; ci = c[i]; i++){
  19179. if(ci.checked == true){
  19180. r[++ri] = ci;
  19181. }
  19182. }
  19183. return r;
  19184. },
  19185. "not" : function(c, ss){
  19186. return Ext.DomQuery.filter(c, ss, true);
  19187. },
  19188. "any" : function(c, selectors){
  19189. var ss = selectors.split('|'),
  19190. r = [], ri = -1, s,
  19191. i, ci, j;
  19192. for(i = 0; ci = c[i]; i++){
  19193. for(j = 0; s = ss[j]; j++){
  19194. if(Ext.DomQuery.is(ci, s)){
  19195. r[++ri] = ci;
  19196. break;
  19197. }
  19198. }
  19199. }
  19200. return r;
  19201. },
  19202. "odd" : function(c){
  19203. return this["nth-child"](c, "odd");
  19204. },
  19205. "even" : function(c){
  19206. return this["nth-child"](c, "even");
  19207. },
  19208. "nth" : function(c, a){
  19209. return c[a-1] || [];
  19210. },
  19211. "first" : function(c){
  19212. return c[0] || [];
  19213. },
  19214. "last" : function(c){
  19215. return c[c.length-1] || [];
  19216. },
  19217. "has" : function(c, ss){
  19218. var s = Ext.DomQuery.select,
  19219. r = [], ri = -1,
  19220. i, ci;
  19221. for(i = 0; ci = c[i]; i++){
  19222. if(s(ss, ci).length > 0){
  19223. r[++ri] = ci;
  19224. }
  19225. }
  19226. return r;
  19227. },
  19228. "next" : function(c, ss){
  19229. var is = Ext.DomQuery.is,
  19230. r = [], ri = -1,
  19231. i, ci, n;
  19232. for(i = 0; ci = c[i]; i++){
  19233. n = next(ci);
  19234. if(n && is(n, ss)){
  19235. r[++ri] = ci;
  19236. }
  19237. }
  19238. return r;
  19239. },
  19240. "prev" : function(c, ss){
  19241. var is = Ext.DomQuery.is,
  19242. r = [], ri = -1,
  19243. i, ci, n;
  19244. for(i = 0; ci = c[i]; i++){
  19245. n = prev(ci);
  19246. if(n && is(n, ss)){
  19247. r[++ri] = ci;
  19248. }
  19249. }
  19250. return r;
  19251. }
  19252. }
  19253. };
  19254. }());
  19255. /**
  19256. * Shorthand of {@link Ext.dom.Query#select}
  19257. * @member Ext
  19258. * @method query
  19259. * @inheritdoc Ext.dom.Query#select
  19260. */
  19261. Ext.query = Ext.DomQuery.select;
  19262. //@tag dom,core
  19263. //@require Query.js
  19264. //@define Ext.dom.Element
  19265. //@require Ext.dom.AbstractElement
  19266. /**
  19267. * @class Ext.dom.Element
  19268. * @alternateClassName Ext.Element
  19269. * @alternateClassName Ext.core.Element
  19270. * @extend Ext.dom.AbstractElement
  19271. *
  19272. * Encapsulates a DOM element, adding simple DOM manipulation facilities, normalizing for browser differences.
  19273. *
  19274. * All instances of this class inherit the methods of {@link Ext.fx.Anim} making visual effects easily available to all
  19275. * DOM elements.
  19276. *
  19277. * Note that the events documented in this class are not Ext events, they encapsulate browser events. Some older browsers
  19278. * may not support the full range of events. Which events are supported is beyond the control of Ext JS.
  19279. *
  19280. * Usage:
  19281. *
  19282. * // by id
  19283. * var el = Ext.get("my-div");
  19284. *
  19285. * // by DOM element reference
  19286. * var el = Ext.get(myDivElement);
  19287. *
  19288. * # Animations
  19289. *
  19290. * When an element is manipulated, by default there is no animation.
  19291. *
  19292. * var el = Ext.get("my-div");
  19293. *
  19294. * // no animation
  19295. * el.setWidth(100);
  19296. *
  19297. * Many of the functions for manipulating an element have an optional "animate" parameter. This parameter can be
  19298. * specified as boolean (true) for default animation effects.
  19299. *
  19300. * // default animation
  19301. * el.setWidth(100, true);
  19302. *
  19303. * To configure the effects, an object literal with animation options to use as the Element animation configuration
  19304. * object can also be specified. Note that the supported Element animation configuration options are a subset of the
  19305. * {@link Ext.fx.Anim} animation options specific to Fx effects. The supported Element animation configuration options
  19306. * are:
  19307. *
  19308. * Option Default Description
  19309. * --------- -------- ---------------------------------------------
  19310. * {@link Ext.fx.Anim#duration duration} 350 The duration of the animation in milliseconds
  19311. * {@link Ext.fx.Anim#easing easing} easeOut The easing method
  19312. * {@link Ext.fx.Anim#callback callback} none A function to execute when the anim completes
  19313. * {@link Ext.fx.Anim#scope scope} this The scope (this) of the callback function
  19314. *
  19315. * Usage:
  19316. *
  19317. * // Element animation options object
  19318. * var opt = {
  19319. * {@link Ext.fx.Anim#duration duration}: 1000,
  19320. * {@link Ext.fx.Anim#easing easing}: 'elasticIn',
  19321. * {@link Ext.fx.Anim#callback callback}: this.foo,
  19322. * {@link Ext.fx.Anim#scope scope}: this
  19323. * };
  19324. * // animation with some options set
  19325. * el.setWidth(100, opt);
  19326. *
  19327. * The Element animation object being used for the animation will be set on the options object as "anim", which allows
  19328. * you to stop or manipulate the animation. Here is an example:
  19329. *
  19330. * // using the "anim" property to get the Anim object
  19331. * if(opt.anim.isAnimated()){
  19332. * opt.anim.stop();
  19333. * }
  19334. *
  19335. * # Composite (Collections of) Elements
  19336. *
  19337. * For working with collections of Elements, see {@link Ext.CompositeElement}
  19338. *
  19339. * @constructor
  19340. * Creates new Element directly.
  19341. * @param {String/HTMLElement} element
  19342. * @param {Boolean} [forceNew] By default the constructor checks to see if there is already an instance of this
  19343. * element in the cache and if there is it returns the same instance. This will skip that check (useful for extending
  19344. * this class).
  19345. * @return {Object}
  19346. */
  19347. (function() {
  19348. var HIDDEN = 'hidden',
  19349. DOC = document,
  19350. VISIBILITY = "visibility",
  19351. DISPLAY = "display",
  19352. NONE = "none",
  19353. XMASKED = Ext.baseCSSPrefix + "masked",
  19354. XMASKEDRELATIVE = Ext.baseCSSPrefix + "masked-relative",
  19355. EXTELMASKMSG = Ext.baseCSSPrefix + "mask-msg",
  19356. bodyRe = /^body/i,
  19357. visFly,
  19358. // speedy lookup for elements never to box adjust
  19359. noBoxAdjust = Ext.isStrict ? {
  19360. select: 1
  19361. }: {
  19362. input: 1,
  19363. select: 1,
  19364. textarea: 1
  19365. },
  19366. // Pseudo for use by cacheScrollValues
  19367. isScrolled = function(c) {
  19368. var r = [], ri = -1,
  19369. i, ci;
  19370. for (i = 0; ci = c[i]; i++) {
  19371. if (ci.scrollTop > 0 || ci.scrollLeft > 0) {
  19372. r[++ri] = ci;
  19373. }
  19374. }
  19375. return r;
  19376. },
  19377. Element = Ext.define('Ext.dom.Element', {
  19378. extend: 'Ext.dom.AbstractElement',
  19379. alternateClassName: ['Ext.Element', 'Ext.core.Element'],
  19380. addUnits: function() {
  19381. return this.self.addUnits.apply(this.self, arguments);
  19382. },
  19383. /**
  19384. * Tries to focus the element. Any exceptions are caught and ignored.
  19385. * @param {Number} [defer] Milliseconds to defer the focus
  19386. * @return {Ext.dom.Element} this
  19387. */
  19388. focus: function(defer, /* private */ dom) {
  19389. var me = this,
  19390. scrollTop,
  19391. body;
  19392. dom = dom || me.dom;
  19393. body = (dom.ownerDocument || DOC).body || DOC.body;
  19394. try {
  19395. if (Number(defer)) {
  19396. Ext.defer(me.focus, defer, me, [null, dom]);
  19397. } else {
  19398. // Focusing a large element, the browser attempts to scroll as much of it into view
  19399. // as possible. We need to override this behaviour.
  19400. if (dom.offsetHeight > Element.getViewHeight()) {
  19401. scrollTop = body.scrollTop;
  19402. }
  19403. dom.focus();
  19404. if (scrollTop !== undefined) {
  19405. body.scrollTop = scrollTop;
  19406. }
  19407. }
  19408. } catch(e) {
  19409. }
  19410. return me;
  19411. },
  19412. /**
  19413. * Tries to blur the element. Any exceptions are caught and ignored.
  19414. * @return {Ext.dom.Element} this
  19415. */
  19416. blur: function() {
  19417. try {
  19418. this.dom.blur();
  19419. } catch(e) {
  19420. }
  19421. return this;
  19422. },
  19423. /**
  19424. * Tests various css rules/browsers to determine if this element uses a border box
  19425. * @return {Boolean}
  19426. */
  19427. isBorderBox: function() {
  19428. var box = Ext.isBorderBox;
  19429. if (box) {
  19430. box = !((this.dom.tagName || "").toLowerCase() in noBoxAdjust);
  19431. }
  19432. return box;
  19433. },
  19434. /**
  19435. * Sets up event handlers to call the passed functions when the mouse is moved into and out of the Element.
  19436. * @param {Function} overFn The function to call when the mouse enters the Element.
  19437. * @param {Function} outFn The function to call when the mouse leaves the Element.
  19438. * @param {Object} [scope] The scope (`this` reference) in which the functions are executed. Defaults
  19439. * to the Element's DOM element.
  19440. * @param {Object} [options] Options for the listener. See {@link Ext.util.Observable#addListener the
  19441. * options parameter}.
  19442. * @return {Ext.dom.Element} this
  19443. */
  19444. hover: function(overFn, outFn, scope, options) {
  19445. var me = this;
  19446. me.on('mouseenter', overFn, scope || me.dom, options);
  19447. me.on('mouseleave', outFn, scope || me.dom, options);
  19448. return me;
  19449. },
  19450. /**
  19451. * Returns the value of a namespaced attribute from the element's underlying DOM node.
  19452. * @param {String} namespace The namespace in which to look for the attribute
  19453. * @param {String} name The attribute name
  19454. * @return {String} The attribute value
  19455. */
  19456. getAttributeNS: function(ns, name) {
  19457. return this.getAttribute(name, ns);
  19458. },
  19459. getAttribute: (Ext.isIE && !(Ext.isIE9 && DOC.documentMode === 9)) ?
  19460. function(name, ns) {
  19461. var d = this.dom,
  19462. type;
  19463. if (ns) {
  19464. type = typeof d[ns + ":" + name];
  19465. if (type != 'undefined' && type != 'unknown') {
  19466. return d[ns + ":" + name] || null;
  19467. }
  19468. return null;
  19469. }
  19470. if (name === "for") {
  19471. name = "htmlFor";
  19472. }
  19473. return d[name] || null;
  19474. } : function(name, ns) {
  19475. var d = this.dom;
  19476. if (ns) {
  19477. return d.getAttributeNS(ns, name) || d.getAttribute(ns + ":" + name);
  19478. }
  19479. return d.getAttribute(name) || d[name] || null;
  19480. },
  19481. /**
  19482. * When an element is moved around in the DOM, or is hidden using `display:none`, it loses layout, and therefore
  19483. * all scroll positions of all descendant elements are lost.
  19484. *
  19485. * This function caches them, and returns a function, which when run will restore the cached positions.
  19486. * In the following example, the Panel is moved from one Container to another which will cause it to lose all scroll positions:
  19487. *
  19488. * var restoreScroll = myPanel.el.cacheScrollValues();
  19489. * myOtherContainer.add(myPanel);
  19490. * restoreScroll();
  19491. *
  19492. * @return {Function} A function which will restore all descentant elements of this Element to their scroll
  19493. * positions recorded when this function was executed. Be aware that the returned function is a closure which has
  19494. * captured the scope of `cacheScrollValues`, so take care to derefence it as soon as not needed - if is it is a `var`
  19495. * it will drop out of scope, and the reference will be freed.
  19496. */
  19497. cacheScrollValues: function() {
  19498. var me = this,
  19499. scrolledDescendants,
  19500. el, i,
  19501. scrollValues = [],
  19502. result = function() {
  19503. for (i = 0; i < scrolledDescendants.length; i++) {
  19504. el = scrolledDescendants[i];
  19505. el.scrollLeft = scrollValues[i][0];
  19506. el.scrollTop = scrollValues[i][1];
  19507. }
  19508. };
  19509. if (!Ext.DomQuery.pseudos.isScrolled) {
  19510. Ext.DomQuery.pseudos.isScrolled = isScrolled;
  19511. }
  19512. scrolledDescendants = me.query(':isScrolled');
  19513. for (i = 0; i < scrolledDescendants.length; i++) {
  19514. el = scrolledDescendants[i];
  19515. scrollValues[i] = [el.scrollLeft, el.scrollTop];
  19516. }
  19517. return result;
  19518. },
  19519. /**
  19520. * @property {Boolean} autoBoxAdjust
  19521. * True to automatically adjust width and height settings for box-model issues.
  19522. */
  19523. autoBoxAdjust: true,
  19524. /**
  19525. * Checks whether the element is currently visible using both visibility and display properties.
  19526. * @param {Boolean} [deep=false] True to walk the dom and see if parent elements are hidden.
  19527. * If false, the function only checks the visibility of the element itself and it may return
  19528. * `true` even though a parent is not visible.
  19529. * @return {Boolean} `true` if the element is currently visible, else `false`
  19530. */
  19531. isVisible : function(deep) {
  19532. var me = this,
  19533. dom = me.dom,
  19534. stopNode = dom.ownerDocument.documentElement;
  19535. if (!visFly) {
  19536. visFly = new Element.Fly();
  19537. }
  19538. while (dom !== stopNode) {
  19539. // We're invisible if we hit a nonexistent parentNode or a document
  19540. // fragment or computed style visibility:hidden or display:none
  19541. if (!dom || dom.nodeType === 11 || (visFly.attach(dom)).isStyle(VISIBILITY, HIDDEN) || visFly.isStyle(DISPLAY, NONE)) {
  19542. return false;
  19543. }
  19544. // Quit now unless we are being asked to check parent nodes.
  19545. if (!deep) {
  19546. break;
  19547. }
  19548. dom = dom.parentNode;
  19549. }
  19550. return true;
  19551. },
  19552. /**
  19553. * Returns true if display is not "none"
  19554. * @return {Boolean}
  19555. */
  19556. isDisplayed : function() {
  19557. return !this.isStyle(DISPLAY, NONE);
  19558. },
  19559. /**
  19560. * Convenience method for setVisibilityMode(Element.DISPLAY)
  19561. * @param {String} [display] What to set display to when visible
  19562. * @return {Ext.dom.Element} this
  19563. */
  19564. enableDisplayMode : function(display) {
  19565. var me = this;
  19566. me.setVisibilityMode(Element.DISPLAY);
  19567. if (!Ext.isEmpty(display)) {
  19568. (me.$cache || me.getCache()).data.originalDisplay = display;
  19569. }
  19570. return me;
  19571. },
  19572. /**
  19573. * Puts a mask over this element to disable user interaction. Requires core.css.
  19574. * This method can only be applied to elements which accept child nodes.
  19575. * @param {String} [msg] A message to display in the mask
  19576. * @param {String} [msgCls] A css class to apply to the msg element
  19577. * @return {Ext.dom.Element} The mask element
  19578. */
  19579. mask : function(msg, msgCls /* private - passed by AbstractComponent.mask to avoid the need to interrogate the DOM to get the height*/, elHeight) {
  19580. var me = this,
  19581. dom = me.dom,
  19582. // In some cases, setExpression will exist but not be of a function type,
  19583. // so we check it explicitly here to stop IE throwing errors
  19584. setExpression = dom.style.setExpression,
  19585. data = (me.$cache || me.getCache()).data,
  19586. maskEl = data.maskEl,
  19587. maskMsg = data.maskMsg;
  19588. if (!(bodyRe.test(dom.tagName) && me.getStyle('position') == 'static')) {
  19589. me.addCls(XMASKEDRELATIVE);
  19590. }
  19591. // We always needs to recreate the mask since the DOM element may have been re-created
  19592. if (maskEl) {
  19593. maskEl.remove();
  19594. }
  19595. if (maskMsg) {
  19596. maskMsg.remove();
  19597. }
  19598. Ext.DomHelper.append(dom, [{
  19599. cls : Ext.baseCSSPrefix + "mask"
  19600. }, {
  19601. cls : msgCls ? EXTELMASKMSG + " " + msgCls : EXTELMASKMSG,
  19602. cn : {
  19603. tag: 'div',
  19604. html: msg || ''
  19605. }
  19606. }]);
  19607. maskMsg = Ext.get(dom.lastChild);
  19608. maskEl = Ext.get(maskMsg.dom.previousSibling);
  19609. data.maskMsg = maskMsg;
  19610. data.maskEl = maskEl;
  19611. me.addCls(XMASKED);
  19612. maskEl.setDisplayed(true);
  19613. if (typeof msg == 'string') {
  19614. maskMsg.setDisplayed(true);
  19615. maskMsg.center(me);
  19616. } else {
  19617. maskMsg.setDisplayed(false);
  19618. }
  19619. // NOTE: CSS expressions are resource intensive and to be used only as a last resort
  19620. // These expressions are removed as soon as they are no longer necessary - in the unmask method.
  19621. // In normal use cases an element will be masked for a limited period of time.
  19622. // Fix for https://sencha.jira.com/browse/EXTJSIV-19.
  19623. // IE6 strict mode and IE6-9 quirks mode takes off left+right padding when calculating width!
  19624. if (!Ext.supports.IncludePaddingInWidthCalculation && setExpression) {
  19625. // In an occasional case setExpression will throw an exception
  19626. try {
  19627. maskEl.dom.style.setExpression('width', 'this.parentNode.clientWidth + "px"');
  19628. } catch (e) {}
  19629. }
  19630. // Some versions and modes of IE subtract top+bottom padding when calculating height.
  19631. // Different versions from those which make the same error for width!
  19632. if (!Ext.supports.IncludePaddingInHeightCalculation && setExpression) {
  19633. // In an occasional case setExpression will throw an exception
  19634. try {
  19635. maskEl.dom.style.setExpression('height', 'this.parentNode.' + (dom == DOC.body ? 'scrollHeight' : 'offsetHeight') + ' + "px"');
  19636. } catch (e) {}
  19637. }
  19638. // ie will not expand full height automatically
  19639. else if (Ext.isIE && !(Ext.isIE7 && Ext.isStrict) && me.getStyle('height') == 'auto') {
  19640. maskEl.setSize(undefined, elHeight || me.getHeight());
  19641. }
  19642. return maskEl;
  19643. },
  19644. /**
  19645. * Hides a previously applied mask.
  19646. */
  19647. unmask : function() {
  19648. var me = this,
  19649. data = (me.$cache || me.getCache()).data,
  19650. maskEl = data.maskEl,
  19651. maskMsg = data.maskMsg,
  19652. style;
  19653. if (maskEl) {
  19654. style = maskEl.dom.style;
  19655. // Remove resource-intensive CSS expressions as soon as they are not required.
  19656. if (style.clearExpression) {
  19657. style.clearExpression('width');
  19658. style.clearExpression('height');
  19659. }
  19660. if (maskEl) {
  19661. maskEl.remove();
  19662. delete data.maskEl;
  19663. }
  19664. if (maskMsg) {
  19665. maskMsg.remove();
  19666. delete data.maskMsg;
  19667. }
  19668. me.removeCls([XMASKED, XMASKEDRELATIVE]);
  19669. }
  19670. },
  19671. /**
  19672. * Returns true if this element is masked. Also re-centers any displayed message within the mask.
  19673. * @return {Boolean}
  19674. */
  19675. isMasked : function() {
  19676. var me = this,
  19677. data = (me.$cache || me.getCache()).data,
  19678. maskEl = data.maskEl,
  19679. maskMsg = data.maskMsg,
  19680. hasMask = false;
  19681. if (maskEl && maskEl.isVisible()) {
  19682. if (maskMsg) {
  19683. maskMsg.center(me);
  19684. }
  19685. hasMask = true;
  19686. }
  19687. return hasMask;
  19688. },
  19689. /**
  19690. * Creates an iframe shim for this element to keep selects and other windowed objects from
  19691. * showing through.
  19692. * @return {Ext.dom.Element} The new shim element
  19693. */
  19694. createShim : function() {
  19695. var el = DOC.createElement('iframe'),
  19696. shim;
  19697. el.frameBorder = '0';
  19698. el.className = Ext.baseCSSPrefix + 'shim';
  19699. el.src = Ext.SSL_SECURE_URL;
  19700. shim = Ext.get(this.dom.parentNode.insertBefore(el, this.dom));
  19701. shim.autoBoxAdjust = false;
  19702. return shim;
  19703. },
  19704. /**
  19705. * Convenience method for constructing a KeyMap
  19706. * @param {String/Number/Number[]/Object} key Either a string with the keys to listen for, the numeric key code,
  19707. * array of key codes or an object with the following options:
  19708. * @param {Number/Array} key.key
  19709. * @param {Boolean} key.shift
  19710. * @param {Boolean} key.ctrl
  19711. * @param {Boolean} key.alt
  19712. * @param {Function} fn The function to call
  19713. * @param {Object} [scope] The scope (`this` reference) in which the specified function is executed. Defaults to this Element.
  19714. * @return {Ext.util.KeyMap} The KeyMap created
  19715. */
  19716. addKeyListener : function(key, fn, scope){
  19717. var config;
  19718. if(typeof key != 'object' || Ext.isArray(key)){
  19719. config = {
  19720. target: this,
  19721. key: key,
  19722. fn: fn,
  19723. scope: scope
  19724. };
  19725. }else{
  19726. config = {
  19727. target: this,
  19728. key : key.key,
  19729. shift : key.shift,
  19730. ctrl : key.ctrl,
  19731. alt : key.alt,
  19732. fn: fn,
  19733. scope: scope
  19734. };
  19735. }
  19736. return new Ext.util.KeyMap(config);
  19737. },
  19738. /**
  19739. * Creates a KeyMap for this element
  19740. * @param {Object} config The KeyMap config. See {@link Ext.util.KeyMap} for more details
  19741. * @return {Ext.util.KeyMap} The KeyMap created
  19742. */
  19743. addKeyMap : function(config) {
  19744. return new Ext.util.KeyMap(Ext.apply({
  19745. target: this
  19746. }, config));
  19747. },
  19748. // Mouse events
  19749. /**
  19750. * @event click
  19751. * Fires when a mouse click is detected within the element.
  19752. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19753. * @param {HTMLElement} t The target of the event.
  19754. */
  19755. /**
  19756. * @event contextmenu
  19757. * Fires when a right click is detected within the element.
  19758. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19759. * @param {HTMLElement} t The target of the event.
  19760. */
  19761. /**
  19762. * @event dblclick
  19763. * Fires when a mouse double click is detected within the element.
  19764. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19765. * @param {HTMLElement} t The target of the event.
  19766. */
  19767. /**
  19768. * @event mousedown
  19769. * Fires when a mousedown is detected within the element.
  19770. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19771. * @param {HTMLElement} t The target of the event.
  19772. */
  19773. /**
  19774. * @event mouseup
  19775. * Fires when a mouseup is detected within the element.
  19776. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19777. * @param {HTMLElement} t The target of the event.
  19778. */
  19779. /**
  19780. * @event mouseover
  19781. * Fires when a mouseover is detected within the element.
  19782. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19783. * @param {HTMLElement} t The target of the event.
  19784. */
  19785. /**
  19786. * @event mousemove
  19787. * Fires when a mousemove is detected with the element.
  19788. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19789. * @param {HTMLElement} t The target of the event.
  19790. */
  19791. /**
  19792. * @event mouseout
  19793. * Fires when a mouseout is detected with the element.
  19794. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19795. * @param {HTMLElement} t The target of the event.
  19796. */
  19797. /**
  19798. * @event mouseenter
  19799. * Fires when the mouse enters the element.
  19800. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19801. * @param {HTMLElement} t The target of the event.
  19802. */
  19803. /**
  19804. * @event mouseleave
  19805. * Fires when the mouse leaves the element.
  19806. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19807. * @param {HTMLElement} t The target of the event.
  19808. */
  19809. // Keyboard events
  19810. /**
  19811. * @event keypress
  19812. * Fires when a keypress is detected within the element.
  19813. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19814. * @param {HTMLElement} t The target of the event.
  19815. */
  19816. /**
  19817. * @event keydown
  19818. * Fires when a keydown is detected within the element.
  19819. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19820. * @param {HTMLElement} t The target of the event.
  19821. */
  19822. /**
  19823. * @event keyup
  19824. * Fires when a keyup is detected within the element.
  19825. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19826. * @param {HTMLElement} t The target of the event.
  19827. */
  19828. // HTML frame/object events
  19829. /**
  19830. * @event load
  19831. * Fires when the user agent finishes loading all content within the element. Only supported by window, frames,
  19832. * objects and images.
  19833. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19834. * @param {HTMLElement} t The target of the event.
  19835. */
  19836. /**
  19837. * @event unload
  19838. * Fires when the user agent removes all content from a window or frame. For elements, it fires when the target
  19839. * element or any of its content has been removed.
  19840. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19841. * @param {HTMLElement} t The target of the event.
  19842. */
  19843. /**
  19844. * @event abort
  19845. * Fires when an object/image is stopped from loading before completely loaded.
  19846. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19847. * @param {HTMLElement} t The target of the event.
  19848. */
  19849. /**
  19850. * @event error
  19851. * Fires when an object/image/frame cannot be loaded properly.
  19852. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19853. * @param {HTMLElement} t The target of the event.
  19854. */
  19855. /**
  19856. * @event resize
  19857. * Fires when a document view is resized.
  19858. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19859. * @param {HTMLElement} t The target of the event.
  19860. */
  19861. /**
  19862. * @event scroll
  19863. * Fires when a document view is scrolled.
  19864. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19865. * @param {HTMLElement} t The target of the event.
  19866. */
  19867. // Form events
  19868. /**
  19869. * @event select
  19870. * Fires when a user selects some text in a text field, including input and textarea.
  19871. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19872. * @param {HTMLElement} t The target of the event.
  19873. */
  19874. /**
  19875. * @event change
  19876. * Fires when a control loses the input focus and its value has been modified since gaining focus.
  19877. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19878. * @param {HTMLElement} t The target of the event.
  19879. */
  19880. /**
  19881. * @event submit
  19882. * Fires when a form is submitted.
  19883. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19884. * @param {HTMLElement} t The target of the event.
  19885. */
  19886. /**
  19887. * @event reset
  19888. * Fires when a form is reset.
  19889. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19890. * @param {HTMLElement} t The target of the event.
  19891. */
  19892. /**
  19893. * @event focus
  19894. * Fires when an element receives focus either via the pointing device or by tab navigation.
  19895. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19896. * @param {HTMLElement} t The target of the event.
  19897. */
  19898. /**
  19899. * @event blur
  19900. * Fires when an element loses focus either via the pointing device or by tabbing navigation.
  19901. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19902. * @param {HTMLElement} t The target of the event.
  19903. */
  19904. // User Interface events
  19905. /**
  19906. * @event DOMFocusIn
  19907. * Where supported. Similar to HTML focus event, but can be applied to any focusable element.
  19908. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19909. * @param {HTMLElement} t The target of the event.
  19910. */
  19911. /**
  19912. * @event DOMFocusOut
  19913. * Where supported. Similar to HTML blur event, but can be applied to any focusable element.
  19914. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19915. * @param {HTMLElement} t The target of the event.
  19916. */
  19917. /**
  19918. * @event DOMActivate
  19919. * Where supported. Fires when an element is activated, for instance, through a mouse click or a keypress.
  19920. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19921. * @param {HTMLElement} t The target of the event.
  19922. */
  19923. // DOM Mutation events
  19924. /**
  19925. * @event DOMSubtreeModified
  19926. * Where supported. Fires when the subtree is modified.
  19927. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19928. * @param {HTMLElement} t The target of the event.
  19929. */
  19930. /**
  19931. * @event DOMNodeInserted
  19932. * Where supported. Fires when a node has been added as a child of another node.
  19933. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19934. * @param {HTMLElement} t The target of the event.
  19935. */
  19936. /**
  19937. * @event DOMNodeRemoved
  19938. * Where supported. Fires when a descendant node of the element is removed.
  19939. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19940. * @param {HTMLElement} t The target of the event.
  19941. */
  19942. /**
  19943. * @event DOMNodeRemovedFromDocument
  19944. * Where supported. Fires when a node is being removed from a document.
  19945. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19946. * @param {HTMLElement} t The target of the event.
  19947. */
  19948. /**
  19949. * @event DOMNodeInsertedIntoDocument
  19950. * Where supported. Fires when a node is being inserted into a document.
  19951. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19952. * @param {HTMLElement} t The target of the event.
  19953. */
  19954. /**
  19955. * @event DOMAttrModified
  19956. * Where supported. Fires when an attribute has been modified.
  19957. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19958. * @param {HTMLElement} t The target of the event.
  19959. */
  19960. /**
  19961. * @event DOMCharacterDataModified
  19962. * Where supported. Fires when the character data has been modified.
  19963. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  19964. * @param {HTMLElement} t The target of the event.
  19965. */
  19966. /**
  19967. * Appends an event handler to this element.
  19968. *
  19969. * @param {String} eventName The name of event to handle.
  19970. *
  19971. * @param {Function} fn The handler function the event invokes. This function is passed the following parameters:
  19972. *
  19973. * - **evt** : EventObject
  19974. *
  19975. * The {@link Ext.EventObject EventObject} describing the event.
  19976. *
  19977. * - **el** : HtmlElement
  19978. *
  19979. * The DOM element which was the target of the event. Note that this may be filtered by using the delegate option.
  19980. *
  19981. * - **o** : Object
  19982. *
  19983. * The options object from the call that setup the listener.
  19984. *
  19985. * @param {Object} scope (optional) The scope (**this** reference) in which the handler function is executed. **If
  19986. * omitted, defaults to this Element.**
  19987. *
  19988. * @param {Object} options (optional) An object containing handler configuration properties. This may contain any of
  19989. * the following properties:
  19990. *
  19991. * - **scope** Object :
  19992. *
  19993. * The scope (**this** reference) in which the handler function is executed. **If omitted, defaults to this
  19994. * Element.**
  19995. *
  19996. * - **delegate** String:
  19997. *
  19998. * A simple selector to filter the target or look for a descendant of the target. See below for additional details.
  19999. *
  20000. * - **stopEvent** Boolean:
  20001. *
  20002. * True to stop the event. That is stop propagation, and prevent the default action.
  20003. *
  20004. * - **preventDefault** Boolean:
  20005. *
  20006. * True to prevent the default action
  20007. *
  20008. * - **stopPropagation** Boolean:
  20009. *
  20010. * True to prevent event propagation
  20011. *
  20012. * - **normalized** Boolean:
  20013. *
  20014. * False to pass a browser event to the handler function instead of an Ext.EventObject
  20015. *
  20016. * - **target** Ext.dom.Element:
  20017. *
  20018. * Only call the handler if the event was fired on the target Element, _not_ if the event was bubbled up from a
  20019. * child node.
  20020. *
  20021. * - **delay** Number:
  20022. *
  20023. * The number of milliseconds to delay the invocation of the handler after the event fires.
  20024. *
  20025. * - **single** Boolean:
  20026. *
  20027. * True to add a handler to handle just the next firing of the event, and then remove itself.
  20028. *
  20029. * - **buffer** Number:
  20030. *
  20031. * Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed by the specified number of
  20032. * milliseconds. If the event fires again within that time, the original handler is _not_ invoked, but the new
  20033. * handler is scheduled in its place.
  20034. *
  20035. * **Combining Options**
  20036. *
  20037. * Using the options argument, it is possible to combine different types of listeners:
  20038. *
  20039. * A delayed, one-time listener that auto stops the event and adds a custom argument (forumId) to the options
  20040. * object. The options object is available as the third parameter in the handler function.
  20041. *
  20042. * Code:
  20043. *
  20044. * el.on('click', this.onClick, this, {
  20045. * single: true,
  20046. * delay: 100,
  20047. * stopEvent : true,
  20048. * forumId: 4
  20049. * });
  20050. *
  20051. * **Attaching multiple handlers in 1 call**
  20052. *
  20053. * The method also allows for a single argument to be passed which is a config object containing properties which
  20054. * specify multiple handlers.
  20055. *
  20056. * Code:
  20057. *
  20058. * el.on({
  20059. * 'click' : {
  20060. * fn: this.onClick,
  20061. * scope: this,
  20062. * delay: 100
  20063. * },
  20064. * 'mouseover' : {
  20065. * fn: this.onMouseOver,
  20066. * scope: this
  20067. * },
  20068. * 'mouseout' : {
  20069. * fn: this.onMouseOut,
  20070. * scope: this
  20071. * }
  20072. * });
  20073. *
  20074. * Or a shorthand syntax:
  20075. *
  20076. * Code:
  20077. *
  20078. * el.on({
  20079. * 'click' : this.onClick,
  20080. * 'mouseover' : this.onMouseOver,
  20081. * 'mouseout' : this.onMouseOut,
  20082. * scope: this
  20083. * });
  20084. *
  20085. * **delegate**
  20086. *
  20087. * This is a configuration option that you can pass along when registering a handler for an event to assist with
  20088. * event delegation. Event delegation is a technique that is used to reduce memory consumption and prevent exposure
  20089. * to memory-leaks. By registering an event for a container element as opposed to each element within a container.
  20090. * By setting this configuration option to a simple selector, the target element will be filtered to look for a
  20091. * descendant of the target. For example:
  20092. *
  20093. * // using this markup:
  20094. * <div id='elId'>
  20095. * <p id='p1'>paragraph one</p>
  20096. * <p id='p2' class='clickable'>paragraph two</p>
  20097. * <p id='p3'>paragraph three</p>
  20098. * </div>
  20099. *
  20100. * // utilize event delegation to registering just one handler on the container element:
  20101. * el = Ext.get('elId');
  20102. * el.on(
  20103. * 'click',
  20104. * function(e,t) {
  20105. * // handle click
  20106. * console.info(t.id); // 'p2'
  20107. * },
  20108. * this,
  20109. * {
  20110. * // filter the target element to be a descendant with the class 'clickable'
  20111. * delegate: '.clickable'
  20112. * }
  20113. * );
  20114. *
  20115. * @return {Ext.dom.Element} this
  20116. */
  20117. on: function(eventName, fn, scope, options) {
  20118. Ext.EventManager.on(this, eventName, fn, scope || this, options);
  20119. return this;
  20120. },
  20121. /**
  20122. * Removes an event handler from this element.
  20123. *
  20124. * **Note**: if a *scope* was explicitly specified when {@link #on adding} the listener,
  20125. * the same scope must be specified here.
  20126. *
  20127. * Example:
  20128. *
  20129. * el.un('click', this.handlerFn);
  20130. * // or
  20131. * el.removeListener('click', this.handlerFn);
  20132. *
  20133. * @param {String} eventName The name of the event from which to remove the handler.
  20134. * @param {Function} fn The handler function to remove. **This must be a reference to the function passed into the
  20135. * {@link #on} call.**
  20136. * @param {Object} scope If a scope (**this** reference) was specified when the listener was added, then this must
  20137. * refer to the same object.
  20138. * @return {Ext.dom.Element} this
  20139. */
  20140. un: function(eventName, fn, scope) {
  20141. Ext.EventManager.un(this, eventName, fn, scope || this);
  20142. return this;
  20143. },
  20144. /**
  20145. * Removes all previous added listeners from this element
  20146. * @return {Ext.dom.Element} this
  20147. */
  20148. removeAllListeners: function() {
  20149. Ext.EventManager.removeAll(this);
  20150. return this;
  20151. },
  20152. /**
  20153. * Recursively removes all previous added listeners from this element and its children
  20154. * @return {Ext.dom.Element} this
  20155. */
  20156. purgeAllListeners: function() {
  20157. Ext.EventManager.purgeElement(this);
  20158. return this;
  20159. }
  20160. }, function() {
  20161. var EC = Ext.cache,
  20162. El = this,
  20163. AbstractElement = Ext.dom.AbstractElement,
  20164. focusRe = /a|button|embed|iframe|img|input|object|select|textarea/i,
  20165. nonSpaceRe = /\S/,
  20166. scriptTagRe = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig,
  20167. replaceScriptTagRe = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig,
  20168. srcRe = /\ssrc=([\'\"])(.*?)\1/i,
  20169. typeRe = /\stype=([\'\"])(.*?)\1/i,
  20170. useDocForId = !(Ext.isIE6 || Ext.isIE7 || Ext.isIE8);
  20171. El.boxMarkup = '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div><div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div><div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
  20172. //</!if>
  20173. // private
  20174. // Garbage collection - uncache elements/purge listeners on orphaned elements
  20175. // so we don't hold a reference and cause the browser to retain them
  20176. function garbageCollect() {
  20177. if (!Ext.enableGarbageCollector) {
  20178. clearInterval(El.collectorThreadId);
  20179. } else {
  20180. var eid,
  20181. d,
  20182. o,
  20183. t;
  20184. for (eid in EC) {
  20185. if (!EC.hasOwnProperty(eid)) {
  20186. continue;
  20187. }
  20188. o = EC[eid];
  20189. // Skip document and window elements
  20190. if (o.skipGarbageCollection) {
  20191. continue;
  20192. }
  20193. d = o.dom;
  20194. // Should always have a DOM node
  20195. if (!d) {
  20196. Ext.Error.raise('Missing DOM node in element garbage collection: ' + eid);
  20197. }
  20198. // Check that document and window elements haven't got through
  20199. if (d && (d.getElementById || d.navigator)) {
  20200. Ext.Error.raise('Unexpected document or window element in element garbage collection');
  20201. }
  20202. // -------------------------------------------------------
  20203. // Determining what is garbage:
  20204. // -------------------------------------------------------
  20205. // !d.parentNode
  20206. // no parentNode == direct orphan, definitely garbage
  20207. // -------------------------------------------------------
  20208. // !d.offsetParent && !document.getElementById(eid)
  20209. // display none elements have no offsetParent so we will
  20210. // also try to look it up by it's id. However, check
  20211. // offsetParent first so we don't do unneeded lookups.
  20212. // This enables collection of elements that are not orphans
  20213. // directly, but somewhere up the line they have an orphan
  20214. // parent.
  20215. // -------------------------------------------------------
  20216. if (!d.parentNode || (!d.offsetParent && !Ext.getElementById(eid))) {
  20217. if (d && Ext.enableListenerCollection) {
  20218. Ext.EventManager.removeAll(d);
  20219. }
  20220. delete EC[eid];
  20221. }
  20222. }
  20223. // Cleanup IE Object leaks
  20224. if (Ext.isIE) {
  20225. t = {};
  20226. for (eid in EC) {
  20227. if (!EC.hasOwnProperty(eid)) {
  20228. continue;
  20229. }
  20230. t[eid] = EC[eid];
  20231. }
  20232. EC = Ext.cache = t;
  20233. }
  20234. }
  20235. }
  20236. El.collectorThreadId = setInterval(garbageCollect, 30000);
  20237. //Stuff from Element-more.js
  20238. El.addMethods({
  20239. /**
  20240. * Monitors this Element for the mouse leaving. Calls the function after the specified delay only if
  20241. * the mouse was not moved back into the Element within the delay. If the mouse *was* moved
  20242. * back in, the function is not called.
  20243. * @param {Number} delay The delay **in milliseconds** to wait for possible mouse re-entry before calling the handler function.
  20244. * @param {Function} handler The function to call if the mouse remains outside of this Element for the specified time.
  20245. * @param {Object} [scope] The scope (`this` reference) in which the handler function executes. Defaults to this Element.
  20246. * @return {Object} The listeners object which was added to this element so that monitoring can be stopped. Example usage:
  20247. *
  20248. * // Hide the menu if the mouse moves out for 250ms or more
  20249. * this.mouseLeaveMonitor = this.menuEl.monitorMouseLeave(250, this.hideMenu, this);
  20250. *
  20251. * ...
  20252. * // Remove mouseleave monitor on menu destroy
  20253. * this.menuEl.un(this.mouseLeaveMonitor);
  20254. *
  20255. */
  20256. monitorMouseLeave: function(delay, handler, scope) {
  20257. var me = this,
  20258. timer,
  20259. listeners = {
  20260. mouseleave: function(e) {
  20261. timer = setTimeout(Ext.Function.bind(handler, scope||me, [e]), delay);
  20262. },
  20263. mouseenter: function() {
  20264. clearTimeout(timer);
  20265. },
  20266. freezeEvent: true
  20267. };
  20268. me.on(listeners);
  20269. return listeners;
  20270. },
  20271. /**
  20272. * Stops the specified event(s) from bubbling and optionally prevents the default action
  20273. * @param {String/String[]} eventName an event / array of events to stop from bubbling
  20274. * @param {Boolean} [preventDefault] true to prevent the default action too
  20275. * @return {Ext.dom.Element} this
  20276. */
  20277. swallowEvent : function(eventName, preventDefault) {
  20278. var me = this,
  20279. e, eLen;
  20280. function fn(e) {
  20281. e.stopPropagation();
  20282. if (preventDefault) {
  20283. e.preventDefault();
  20284. }
  20285. }
  20286. if (Ext.isArray(eventName)) {
  20287. eLen = eventName.length;
  20288. for (e = 0; e < eLen; e++) {
  20289. me.on(eventName[e], fn);
  20290. }
  20291. return me;
  20292. }
  20293. me.on(eventName, fn);
  20294. return me;
  20295. },
  20296. /**
  20297. * Create an event handler on this element such that when the event fires and is handled by this element,
  20298. * it will be relayed to another object (i.e., fired again as if it originated from that object instead).
  20299. * @param {String} eventName The type of event to relay
  20300. * @param {Object} observable Any object that extends {@link Ext.util.Observable} that will provide the context
  20301. * for firing the relayed event
  20302. */
  20303. relayEvent : function(eventName, observable) {
  20304. this.on(eventName, function(e) {
  20305. observable.fireEvent(eventName, e);
  20306. });
  20307. },
  20308. /**
  20309. * Removes Empty, or whitespace filled text nodes. Combines adjacent text nodes.
  20310. * @param {Boolean} [forceReclean=false] By default the element keeps track if it has been cleaned already
  20311. * so you can call this over and over. However, if you update the element and need to force a reclean, you
  20312. * can pass true.
  20313. */
  20314. clean : function(forceReclean) {
  20315. var me = this,
  20316. dom = me.dom,
  20317. data = (me.$cache || me.getCache()).data,
  20318. n = dom.firstChild,
  20319. ni = -1,
  20320. nx;
  20321. if (data.isCleaned && forceReclean !== true) {
  20322. return me;
  20323. }
  20324. while (n) {
  20325. nx = n.nextSibling;
  20326. if (n.nodeType == 3) {
  20327. // Remove empty/whitespace text nodes
  20328. if (!(nonSpaceRe.test(n.nodeValue))) {
  20329. dom.removeChild(n);
  20330. // Combine adjacent text nodes
  20331. } else if (nx && nx.nodeType == 3) {
  20332. n.appendData(Ext.String.trim(nx.data));
  20333. dom.removeChild(nx);
  20334. nx = n.nextSibling;
  20335. n.nodeIndex = ++ni;
  20336. }
  20337. } else {
  20338. // Recursively clean
  20339. Ext.fly(n).clean();
  20340. n.nodeIndex = ++ni;
  20341. }
  20342. n = nx;
  20343. }
  20344. data.isCleaned = true;
  20345. return me;
  20346. },
  20347. /**
  20348. * Direct access to the Ext.ElementLoader {@link Ext.ElementLoader#method-load} method. The method takes the same object
  20349. * parameter as {@link Ext.ElementLoader#method-load}
  20350. * @return {Ext.dom.Element} this
  20351. */
  20352. load : function(options) {
  20353. this.getLoader().load(options);
  20354. return this;
  20355. },
  20356. /**
  20357. * Gets this element's {@link Ext.ElementLoader ElementLoader}
  20358. * @return {Ext.ElementLoader} The loader
  20359. */
  20360. getLoader : function() {
  20361. var me = this,
  20362. data = (me.$cache || me.getCache()).data,
  20363. loader = data.loader;
  20364. if (!loader) {
  20365. data.loader = loader = new Ext.ElementLoader({
  20366. target: me
  20367. });
  20368. }
  20369. return loader;
  20370. },
  20371. /**
  20372. * @private.
  20373. * Currently used for updating grid cells without modifying DOM structure
  20374. *
  20375. * Synchronizes content of this Element with the content of the passed element.
  20376. *
  20377. * Style and CSS class are copied from source into this Element, and contents are synched
  20378. * recursively. If a child node is a text node, the textual data is copied.
  20379. */
  20380. syncContent: function(source) {
  20381. source = Ext.getDom(source);
  20382. var me = this,
  20383. sourceNodes = source.childNodes,
  20384. sourceLen = sourceNodes.length,
  20385. dest = me.dom,
  20386. destNodes = dest.childNodes,
  20387. destLen = destNodes.length,
  20388. i, destNode, sourceNode,
  20389. nodeType;
  20390. // Copy top node's style and CSS class
  20391. dest.style.cssText = source.style.cssText;
  20392. dest.className = source.className;
  20393. // If the number of child nodes does not match, fall back to replacing innerHTML
  20394. if (sourceLen !== destLen) {
  20395. source.innerHTML = dest.innerHTML;
  20396. return;
  20397. }
  20398. // Loop through source nodes.
  20399. // If there are fewer, we must remove excess
  20400. for (i = 0; i < sourceLen; i++) {
  20401. sourceNode = sourceNodes[i];
  20402. destNode = destNodes[i];
  20403. nodeType = sourceNode.nodeType;
  20404. // If node structure is out of sync, just drop innerHTML in and return
  20405. if (nodeType !== destNode.nodeType || (nodeType === 1 && sourceNode.tagName !== destNode.tagName)) {
  20406. dest.innerHTML = source.innerHTML;
  20407. return;
  20408. }
  20409. // Update text node
  20410. if (nodeType === 3) {
  20411. destNode.data = sourceNode.data;
  20412. }
  20413. // Sync element content
  20414. else {
  20415. if (sourceNode.id && destNode.id !== sourceNode.id) {
  20416. destNode.id = sourceNode.id;
  20417. }
  20418. destNode.style.cssText = sourceNode.style.cssText;
  20419. destNode.className = sourceNode.className;
  20420. Ext.fly(destNode).syncContent(sourceNode);
  20421. }
  20422. }
  20423. },
  20424. /**
  20425. * Updates the innerHTML of this element, optionally searching for and processing scripts.
  20426. * @param {String} html The new HTML
  20427. * @param {Boolean} [loadScripts] True to look for and process scripts (defaults to false)
  20428. * @param {Function} [callback] For async script loading you can be notified when the update completes
  20429. * @return {Ext.dom.Element} this
  20430. */
  20431. update : function(html, loadScripts, callback) {
  20432. var me = this,
  20433. id,
  20434. dom,
  20435. interval;
  20436. if (!me.dom) {
  20437. return me;
  20438. }
  20439. html = html || '';
  20440. dom = me.dom;
  20441. if (loadScripts !== true) {
  20442. dom.innerHTML = html;
  20443. Ext.callback(callback, me);
  20444. return me;
  20445. }
  20446. id = Ext.id();
  20447. html += '<span id="' + id + '"></span>';
  20448. interval = setInterval(function() {
  20449. var hd,
  20450. match,
  20451. attrs,
  20452. srcMatch,
  20453. typeMatch,
  20454. el,
  20455. s;
  20456. if (!(el = DOC.getElementById(id))) {
  20457. return false;
  20458. }
  20459. clearInterval(interval);
  20460. Ext.removeNode(el);
  20461. hd = Ext.getHead().dom;
  20462. while ((match = scriptTagRe.exec(html))) {
  20463. attrs = match[1];
  20464. srcMatch = attrs ? attrs.match(srcRe) : false;
  20465. if (srcMatch && srcMatch[2]) {
  20466. s = DOC.createElement("script");
  20467. s.src = srcMatch[2];
  20468. typeMatch = attrs.match(typeRe);
  20469. if (typeMatch && typeMatch[2]) {
  20470. s.type = typeMatch[2];
  20471. }
  20472. hd.appendChild(s);
  20473. } else if (match[2] && match[2].length > 0) {
  20474. if (window.execScript) {
  20475. window.execScript(match[2]);
  20476. } else {
  20477. window.eval(match[2]);
  20478. }
  20479. }
  20480. }
  20481. Ext.callback(callback, me);
  20482. }, 20);
  20483. dom.innerHTML = html.replace(replaceScriptTagRe, '');
  20484. return me;
  20485. },
  20486. // inherit docs, overridden so we can add removeAnchor
  20487. removeAllListeners : function() {
  20488. this.removeAnchor();
  20489. Ext.EventManager.removeAll(this.dom);
  20490. return this;
  20491. },
  20492. /**
  20493. * Creates a proxy element of this element
  20494. * @param {String/Object} config The class name of the proxy element or a DomHelper config object
  20495. * @param {String/HTMLElement} [renderTo] The element or element id to render the proxy to. Defaults to: document.body.
  20496. * @param {Boolean} [matchBox=false] True to align and size the proxy to this element now.
  20497. * @return {Ext.dom.Element} The new proxy element
  20498. */
  20499. createProxy : function(config, renderTo, matchBox) {
  20500. config = (typeof config == 'object') ? config : {tag : "div", cls: config};
  20501. var me = this,
  20502. proxy = renderTo ? Ext.DomHelper.append(renderTo, config, true) :
  20503. Ext.DomHelper.insertBefore(me.dom, config, true);
  20504. proxy.setVisibilityMode(Element.DISPLAY);
  20505. proxy.hide();
  20506. if (matchBox && me.setBox && me.getBox) { // check to make sure Element.position.js is loaded
  20507. proxy.setBox(me.getBox());
  20508. }
  20509. return proxy;
  20510. },
  20511. /**
  20512. * Gets the parent node of the current element taking into account Ext.scopeResetCSS
  20513. * @protected
  20514. * @return {HTMLElement} The parent element
  20515. */
  20516. getScopeParent: function() {
  20517. var parent = this.dom.parentNode;
  20518. if (Ext.scopeResetCSS) {
  20519. // If it's a normal reset, we will be wrapped in a single x-reset element, so grab the parent
  20520. parent = parent.parentNode;
  20521. if (!Ext.supports.CSS3LinearGradient || !Ext.supports.CSS3BorderRadius) {
  20522. // In the cases where we have nbr or nlg, it will be wrapped in a second element,
  20523. // so we need to go and get the parent again.
  20524. parent = parent.parentNode;
  20525. }
  20526. }
  20527. return parent;
  20528. },
  20529. /**
  20530. * Returns true if this element needs an explicit tabIndex to make it focusable. Input fields, text areas, buttons
  20531. * anchors elements **with an href** etc do not need a tabIndex, but structural elements do.
  20532. */
  20533. needsTabIndex: function() {
  20534. if (this.dom) {
  20535. if ((this.dom.nodeName === 'a') && (!this.dom.href)) {
  20536. return true;
  20537. }
  20538. return !focusRe.test(this.dom.nodeName);
  20539. }
  20540. },
  20541. /**
  20542. * Checks whether this element can be focused.
  20543. * @return {Boolean} True if the element is focusable
  20544. */
  20545. focusable: function () {
  20546. var dom = this.dom,
  20547. nodeName = dom.nodeName,
  20548. canFocus = false;
  20549. if (!dom.disabled) {
  20550. if (focusRe.test(nodeName)) {
  20551. if ((nodeName !== 'a') || dom.href) {
  20552. canFocus = true;
  20553. }
  20554. } else {
  20555. canFocus = !isNaN(dom.tabIndex);
  20556. }
  20557. }
  20558. return canFocus && this.isVisible(true);
  20559. }
  20560. });
  20561. if (Ext.isIE) {
  20562. El.prototype.getById = function (id, asDom) {
  20563. var dom = this.dom,
  20564. cacheItem, el, ret;
  20565. if (dom) {
  20566. // for normal elements getElementById is the best solution, but if the el is
  20567. // not part of the document.body, we need to use all[]
  20568. el = (useDocForId && DOC.getElementById(id)) || dom.all[id];
  20569. if (el) {
  20570. if (asDom) {
  20571. ret = el;
  20572. } else {
  20573. // calling El.get here is a real hit (2x slower) because it has to
  20574. // redetermine that we are giving it a dom el.
  20575. cacheItem = EC[id];
  20576. if (cacheItem && cacheItem.el) {
  20577. ret = Ext.updateCacheEntry(cacheItem, el).el;
  20578. } else {
  20579. ret = new Element(el);
  20580. }
  20581. }
  20582. return ret;
  20583. }
  20584. }
  20585. return asDom ? Ext.getDom(id) : El.get(id);
  20586. };
  20587. }
  20588. El.createAlias({
  20589. /**
  20590. * @method
  20591. * @inheritdoc Ext.dom.Element#on
  20592. * Shorthand for {@link #on}.
  20593. */
  20594. addListener: 'on',
  20595. /**
  20596. * @method
  20597. * @inheritdoc Ext.dom.Element#un
  20598. * Shorthand for {@link #un}.
  20599. */
  20600. removeListener: 'un',
  20601. /**
  20602. * @method
  20603. * @inheritdoc Ext.dom.Element#removeAllListeners
  20604. * Alias for {@link #removeAllListeners}.
  20605. */
  20606. clearListeners: 'removeAllListeners'
  20607. });
  20608. El.Fly = AbstractElement.Fly = new Ext.Class({
  20609. extend: El,
  20610. constructor: function(dom) {
  20611. this.dom = dom;
  20612. },
  20613. attach: AbstractElement.Fly.prototype.attach
  20614. });
  20615. if (Ext.isIE) {
  20616. Ext.getElementById = function (id) {
  20617. var el = DOC.getElementById(id),
  20618. detachedBodyEl;
  20619. if (!el && (detachedBodyEl = AbstractElement.detachedBodyEl)) {
  20620. el = detachedBodyEl.dom.all[id];
  20621. }
  20622. return el;
  20623. };
  20624. } else if (!DOC.querySelector) {
  20625. Ext.getDetachedBody = Ext.getBody;
  20626. Ext.getElementById = function (id) {
  20627. return DOC.getElementById(id);
  20628. };
  20629. }
  20630. });
  20631. }());
  20632. //@tag dom,core
  20633. //@require Element.js
  20634. //@define Ext.dom.Element-alignment
  20635. //@define Ext.dom.Element
  20636. /**
  20637. * @class Ext.dom.Element
  20638. */
  20639. Ext.dom.Element.override((function() {
  20640. var doc = document,
  20641. win = window,
  20642. alignRe = /^([a-z]+)-([a-z]+)(\?)?$/,
  20643. round = Math.round;
  20644. return {
  20645. /**
  20646. * Gets the x,y coordinates specified by the anchor position on the element.
  20647. * @param {String} [anchor='c'] The specified anchor position. See {@link #alignTo}
  20648. * for details on supported anchor positions.
  20649. * @param {Boolean} [local] True to get the local (element top/left-relative) anchor position instead
  20650. * of page coordinates
  20651. * @param {Object} [size] An object containing the size to use for calculating anchor position
  20652. * {width: (target width), height: (target height)} (defaults to the element's current size)
  20653. * @return {Number[]} [x, y] An array containing the element's x and y coordinates
  20654. */
  20655. getAnchorXY: function(anchor, local, mySize) {
  20656. //Passing a different size is useful for pre-calculating anchors,
  20657. //especially for anchored animations that change the el size.
  20658. anchor = (anchor || "tl").toLowerCase();
  20659. mySize = mySize || {};
  20660. var me = this,
  20661. isViewport = me.dom == doc.body || me.dom == doc,
  20662. myWidth = mySize.width || isViewport ? Ext.dom.Element.getViewWidth() : me.getWidth(),
  20663. myHeight = mySize.height || isViewport ? Ext.dom.Element.getViewHeight() : me.getHeight(),
  20664. xy,
  20665. myPos = me.getXY(),
  20666. scroll = me.getScroll(),
  20667. extraX = isViewport ? scroll.left : !local ? myPos[0] : 0,
  20668. extraY = isViewport ? scroll.top : !local ? myPos[1] : 0;
  20669. // Calculate anchor position.
  20670. // Test most common cases for picker alignment first.
  20671. switch (anchor) {
  20672. case 'tl' : xy = [ 0, 0];
  20673. break;
  20674. case 'bl' : xy = [ 0, myHeight];
  20675. break;
  20676. case 'tr' : xy = [ myWidth, 0];
  20677. break;
  20678. case 'c' : xy = [ round(myWidth * 0.5), round(myHeight * 0.5)];
  20679. break;
  20680. case 't' : xy = [ round(myWidth * 0.5), 0];
  20681. break;
  20682. case 'l' : xy = [ 0, round(myHeight * 0.5)];
  20683. break;
  20684. case 'r' : xy = [ myWidth, round(myHeight * 0.5)];
  20685. break;
  20686. case 'b' : xy = [ round(myWidth * 0.5), myHeight];
  20687. break;
  20688. case 'br' : xy = [ myWidth, myHeight];
  20689. }
  20690. return [xy[0] + extraX, xy[1] + extraY];
  20691. },
  20692. /**
  20693. * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the
  20694. * supported position values.
  20695. * @param {String/HTMLElement/Ext.Element} element The element to align to.
  20696. * @param {String} [position="tl-bl?"] The position to align to (defaults to )
  20697. * @param {Number[]} [offsets] Offset the positioning by [x, y]
  20698. * @return {Number[]} [x, y]
  20699. */
  20700. getAlignToXY : function(alignToEl, posSpec, offset) {
  20701. alignToEl = Ext.get(alignToEl);
  20702. if (!alignToEl || !alignToEl.dom) {
  20703. Ext.Error.raise({
  20704. sourceClass: 'Ext.dom.Element',
  20705. sourceMethod: 'getAlignToXY',
  20706. msg: 'Attempted to align an element that doesn\'t exist'
  20707. });
  20708. }
  20709. offset = offset || [0,0];
  20710. posSpec = (!posSpec || posSpec == "?" ? "tl-bl?" : (!(/-/).test(posSpec) && posSpec !== "" ? "tl-" + posSpec : posSpec || "tl-bl")).toLowerCase();
  20711. var me = this,
  20712. myPosition,
  20713. alignToElPosition,
  20714. x,
  20715. y,
  20716. myWidth,
  20717. myHeight,
  20718. alignToElRegion,
  20719. viewportWidth = Ext.dom.Element.getViewWidth() - 10, // 10px of margin for ie
  20720. viewportHeight = Ext.dom.Element.getViewHeight() - 10, // 10px of margin for ie
  20721. p1y,
  20722. p1x,
  20723. p2y,
  20724. p2x,
  20725. swapY,
  20726. swapX,
  20727. docElement = doc.documentElement,
  20728. docBody = doc.body,
  20729. scrollX = (docElement.scrollLeft || docBody.scrollLeft || 0),// + 5, WHY was 5 ever added?
  20730. scrollY = (docElement.scrollTop || docBody.scrollTop || 0),// + 5, It means align will fail if the alignTo el was at less than 5,5
  20731. constrain, //constrain to viewport
  20732. align1,
  20733. align2,
  20734. alignMatch = posSpec.match(alignRe);
  20735. if (!alignMatch) {
  20736. Ext.Error.raise({
  20737. sourceClass: 'Ext.dom.Element',
  20738. sourceMethod: 'getAlignToXY',
  20739. el: alignToEl,
  20740. position: posSpec,
  20741. offset: offset,
  20742. msg: 'Attemmpted to align an element with an invalid position: "' + posSpec + '"'
  20743. });
  20744. }
  20745. align1 = alignMatch[1];
  20746. align2 = alignMatch[2];
  20747. constrain = !!alignMatch[3];
  20748. //Subtract the aligned el's internal xy from the target's offset xy
  20749. //plus custom offset to get this Element's new offset xy
  20750. myPosition = me.getAnchorXY(align1, true);
  20751. alignToElPosition = alignToEl.getAnchorXY(align2, false);
  20752. x = alignToElPosition[0] - myPosition[0] + offset[0];
  20753. y = alignToElPosition[1] - myPosition[1] + offset[1];
  20754. // If position spec ended with a "?", then constrain to viewport is necessary
  20755. if (constrain) {
  20756. myWidth = me.getWidth();
  20757. myHeight = me.getHeight();
  20758. alignToElRegion = alignToEl.getRegion();
  20759. //If we are at a viewport boundary and the aligned el is anchored on a target border that is
  20760. //perpendicular to the vp border, allow the aligned el to slide on that border,
  20761. //otherwise swap the aligned el to the opposite border of the target.
  20762. p1y = align1.charAt(0);
  20763. p1x = align1.charAt(align1.length - 1);
  20764. p2y = align2.charAt(0);
  20765. p2x = align2.charAt(align2.length - 1);
  20766. swapY = ((p1y == "t" && p2y == "b") || (p1y == "b" && p2y == "t"));
  20767. swapX = ((p1x == "r" && p2x == "l") || (p1x == "l" && p2x == "r"));
  20768. if (x + myWidth > viewportWidth + scrollX) {
  20769. x = swapX ? alignToElRegion.left - myWidth : viewportWidth + scrollX - myWidth;
  20770. }
  20771. if (x < scrollX) {
  20772. x = swapX ? alignToElRegion.right : scrollX;
  20773. }
  20774. if (y + myHeight > viewportHeight + scrollY) {
  20775. y = swapY ? alignToElRegion.top - myHeight : viewportHeight + scrollY - myHeight;
  20776. }
  20777. if (y < scrollY) {
  20778. y = swapY ? alignToElRegion.bottom : scrollY;
  20779. }
  20780. }
  20781. return [x,y];
  20782. },
  20783. /**
  20784. * Anchors an element to another element and realigns it when the window is resized.
  20785. * @param {String/HTMLElement/Ext.Element} element The element to align to.
  20786. * @param {String} position The position to align to.
  20787. * @param {Number[]} [offsets] Offset the positioning by [x, y]
  20788. * @param {Boolean/Object} [animate] True for the default animation or a standard Element animation config object
  20789. * @param {Boolean/Number} [monitorScroll] True to monitor body scroll and reposition. If this parameter
  20790. * is a number, it is used as the buffer delay (defaults to 50ms).
  20791. * @param {Function} [callback] The function to call after the animation finishes
  20792. * @return {Ext.Element} this
  20793. */
  20794. anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback) {
  20795. var me = this,
  20796. dom = me.dom,
  20797. scroll = !Ext.isEmpty(monitorScroll),
  20798. action = function() {
  20799. Ext.fly(dom).alignTo(el, alignment, offsets, animate);
  20800. Ext.callback(callback, Ext.fly(dom));
  20801. },
  20802. anchor = this.getAnchor();
  20803. // previous listener anchor, remove it
  20804. this.removeAnchor();
  20805. Ext.apply(anchor, {
  20806. fn: action,
  20807. scroll: scroll
  20808. });
  20809. Ext.EventManager.onWindowResize(action, null);
  20810. if (scroll) {
  20811. Ext.EventManager.on(win, 'scroll', action, null,
  20812. {buffer: !isNaN(monitorScroll) ? monitorScroll : 50});
  20813. }
  20814. action.call(me); // align immediately
  20815. return me;
  20816. },
  20817. /**
  20818. * Remove any anchor to this element. See {@link #anchorTo}.
  20819. * @return {Ext.dom.Element} this
  20820. */
  20821. removeAnchor : function() {
  20822. var me = this,
  20823. anchor = this.getAnchor();
  20824. if (anchor && anchor.fn) {
  20825. Ext.EventManager.removeResizeListener(anchor.fn);
  20826. if (anchor.scroll) {
  20827. Ext.EventManager.un(win, 'scroll', anchor.fn);
  20828. }
  20829. delete anchor.fn;
  20830. }
  20831. return me;
  20832. },
  20833. getAlignVector: function(el, spec, offset) {
  20834. var me = this,
  20835. myPos = me.getXY(),
  20836. alignedPos = me.getAlignToXY(el, spec, offset);
  20837. el = Ext.get(el);
  20838. if (!el || !el.dom) {
  20839. Ext.Error.raise({
  20840. sourceClass: 'Ext.dom.Element',
  20841. sourceMethod: 'getAlignVector',
  20842. msg: 'Attempted to align an element that doesn\'t exist'
  20843. });
  20844. }
  20845. alignedPos[0] -= myPos[0];
  20846. alignedPos[1] -= myPos[1];
  20847. return alignedPos;
  20848. },
  20849. /**
  20850. * Aligns this element with another element relative to the specified anchor points. If the other element is the
  20851. * document it aligns it to the viewport. The position parameter is optional, and can be specified in any one of
  20852. * the following formats:
  20853. *
  20854. * - **Blank**: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").
  20855. * - **One anchor (deprecated)**: The passed anchor position is used as the target element's anchor point.
  20856. * The element being aligned will position its top-left corner (tl) to that point. *This method has been
  20857. * deprecated in favor of the newer two anchor syntax below*.
  20858. * - **Two anchors**: If two values from the table below are passed separated by a dash, the first value is used as the
  20859. * element's anchor point, and the second value is used as the target's anchor point.
  20860. *
  20861. * In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of
  20862. * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to
  20863. * the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than
  20864. * that specified in order to enforce the viewport constraints.
  20865. * Following are all of the supported anchor positions:
  20866. *
  20867. * <pre>
  20868. * Value Description
  20869. * ----- -----------------------------
  20870. * tl The top left corner (default)
  20871. * t The center of the top edge
  20872. * tr The top right corner
  20873. * l The center of the left edge
  20874. * c In the center of the element
  20875. * r The center of the right edge
  20876. * bl The bottom left corner
  20877. * b The center of the bottom edge
  20878. * br The bottom right corner
  20879. * </pre>
  20880. *
  20881. * Example Usage:
  20882. *
  20883. * // align el to other-el using the default positioning ("tl-bl", non-constrained)
  20884. * el.alignTo("other-el");
  20885. *
  20886. * // align the top left corner of el with the top right corner of other-el (constrained to viewport)
  20887. * el.alignTo("other-el", "tr?");
  20888. *
  20889. * // align the bottom right corner of el with the center left edge of other-el
  20890. * el.alignTo("other-el", "br-l?");
  20891. *
  20892. * // align the center of el with the bottom left corner of other-el and
  20893. * // adjust the x position by -6 pixels (and the y position by 0)
  20894. * el.alignTo("other-el", "c-bl", [-6, 0]);
  20895. *
  20896. * @param {String/HTMLElement/Ext.Element} element The element to align to.
  20897. * @param {String} [position="tl-bl?"] The position to align to
  20898. * @param {Number[]} [offsets] Offset the positioning by [x, y]
  20899. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  20900. * @return {Ext.Element} this
  20901. */
  20902. alignTo: function(element, position, offsets, animate) {
  20903. var me = this;
  20904. return me.setXY(me.getAlignToXY(element, position, offsets),
  20905. me.anim && !!animate ? me.anim(animate) : false);
  20906. },
  20907. /**
  20908. * Returns the `[X, Y]` vector by which this element must be translated to make a best attempt
  20909. * to constrain within the passed constraint. Returns `false` is this element does not need to be moved.
  20910. *
  20911. * Priority is given to constraining the top and left within the constraint.
  20912. *
  20913. * The constraint may either be an existing element into which this element is to be constrained, or
  20914. * an {@link Ext.util.Region Region} into which this element is to be constrained.
  20915. *
  20916. * @param {Ext.Element/Ext.util.Region} constrainTo The Element or Region into which this element is to be constrained.
  20917. * @param {Number[]} proposedPosition A proposed `[X, Y]` position to test for validity and to produce a vector for instead
  20918. * of using this Element's current position;
  20919. * @returns {Number[]/Boolean} **If** this element *needs* to be translated, an `[X, Y]`
  20920. * vector by which this element must be translated. Otherwise, `false`.
  20921. */
  20922. getConstrainVector: function(constrainTo, proposedPosition) {
  20923. if (!(constrainTo instanceof Ext.util.Region)) {
  20924. constrainTo = Ext.get(constrainTo).getViewRegion();
  20925. }
  20926. var thisRegion = this.getRegion(),
  20927. vector = [0, 0],
  20928. shadowSize = (this.shadow && !this.shadowDisabled) ? this.shadow.getShadowSize() : undefined,
  20929. overflowed = false;
  20930. // Shift this region to occupy the proposed position
  20931. if (proposedPosition) {
  20932. thisRegion.translateBy(proposedPosition[0] - thisRegion.x, proposedPosition[1] - thisRegion.y);
  20933. }
  20934. // Reduce the constrain region to allow for shadow
  20935. if (shadowSize) {
  20936. constrainTo.adjust(shadowSize[0], -shadowSize[1], -shadowSize[2], shadowSize[3]);
  20937. }
  20938. // Constrain the X coordinate by however much this Element overflows
  20939. if (thisRegion.right > constrainTo.right) {
  20940. overflowed = true;
  20941. vector[0] = (constrainTo.right - thisRegion.right); // overflowed the right
  20942. }
  20943. if (thisRegion.left + vector[0] < constrainTo.left) {
  20944. overflowed = true;
  20945. vector[0] = (constrainTo.left - thisRegion.left); // overflowed the left
  20946. }
  20947. // Constrain the Y coordinate by however much this Element overflows
  20948. if (thisRegion.bottom > constrainTo.bottom) {
  20949. overflowed = true;
  20950. vector[1] = (constrainTo.bottom - thisRegion.bottom); // overflowed the bottom
  20951. }
  20952. if (thisRegion.top + vector[1] < constrainTo.top) {
  20953. overflowed = true;
  20954. vector[1] = (constrainTo.top - thisRegion.top); // overflowed the top
  20955. }
  20956. return overflowed ? vector : false;
  20957. },
  20958. /**
  20959. * Calculates the x, y to center this element on the screen
  20960. * @return {Number[]} The x, y values [x, y]
  20961. */
  20962. getCenterXY : function(){
  20963. return this.getAlignToXY(doc, 'c-c');
  20964. },
  20965. /**
  20966. * Centers the Element in either the viewport, or another Element.
  20967. * @param {String/HTMLElement/Ext.Element} [centerIn] The element in which to center the element.
  20968. */
  20969. center : function(centerIn){
  20970. return this.alignTo(centerIn || doc, 'c-c');
  20971. }
  20972. };
  20973. }()));
  20974. //@tag dom,core
  20975. //@require Ext.dom.Element-alignment
  20976. //@define Ext.dom.Element-anim
  20977. //@define Ext.dom.Element
  20978. /**
  20979. * @class Ext.dom.Element
  20980. */
  20981. /* ================================
  20982. * A Note About Wrapped Animations
  20983. * ================================
  20984. * A few of the effects below implement two different animations per effect, one wrapping
  20985. * animation that performs the visual effect and a "no-op" animation on this Element where
  20986. * no attributes of the element itself actually change. The purpose for this is that the
  20987. * wrapper is required for the effect to work and so it does the actual animation work, but
  20988. * we always animate `this` so that the element's events and callbacks work as expected to
  20989. * the callers of this API.
  20990. *
  20991. * Because of this, we always want each wrap animation to complete first (we don't want to
  20992. * cut off the visual effect early). To ensure that, we arbitrarily increase the duration of
  20993. * the element's no-op animation, also ensuring that it has a decent minimum value -- on slow
  20994. * systems, too-low durations can cause race conditions between the wrap animation and the
  20995. * element animation being removed out of order. Note that in each wrap's `afteranimate`
  20996. * callback it will explicitly terminate the element animation as soon as the wrap is complete,
  20997. * so there's no real danger in making the duration too long.
  20998. *
  20999. * This applies to all effects that get wrapped, including slideIn, slideOut, switchOff and frame.
  21000. */
  21001. Ext.dom.Element.override({
  21002. /**
  21003. * Performs custom animation on this Element.
  21004. *
  21005. * The following properties may be specified in `from`, `to`, and `keyframe` objects:
  21006. *
  21007. * - `x` - The page X position in pixels.
  21008. *
  21009. * - `y` - The page Y position in pixels
  21010. *
  21011. * - `left` - The element's CSS `left` value. Units must be supplied.
  21012. *
  21013. * - `top` - The element's CSS `top` value. Units must be supplied.
  21014. *
  21015. * - `width` - The element's CSS `width` value. Units must be supplied.
  21016. *
  21017. * - `height` - The element's CSS `height` value. Units must be supplied.
  21018. *
  21019. * - `scrollLeft` - The element's `scrollLeft` value.
  21020. *
  21021. * - `scrollTop` - The element's `scrollTop` value.
  21022. *
  21023. * - `opacity` - The element's `opacity` value. This must be a value between `0` and `1`.
  21024. *
  21025. * **Be aware** that animating an Element which is being used by an Ext Component without in some way informing the
  21026. * Component about the changed element state will result in incorrect Component behaviour. This is because the
  21027. * Component will be using the old state of the element. To avoid this problem, it is now possible to directly
  21028. * animate certain properties of Components.
  21029. *
  21030. * @param {Object} config Configuration for {@link Ext.fx.Anim}.
  21031. * Note that the {@link Ext.fx.Anim#to to} config is required.
  21032. * @return {Ext.dom.Element} this
  21033. */
  21034. animate: function(config) {
  21035. var me = this,
  21036. listeners,
  21037. anim,
  21038. animId = me.dom.id || Ext.id(me.dom);
  21039. if (!Ext.fx.Manager.hasFxBlock(animId)) {
  21040. // Bit of gymnastics here to ensure our internal listeners get bound first
  21041. if (config.listeners) {
  21042. listeners = config.listeners;
  21043. delete config.listeners;
  21044. }
  21045. if (config.internalListeners) {
  21046. config.listeners = config.internalListeners;
  21047. delete config.internalListeners;
  21048. }
  21049. anim = new Ext.fx.Anim(me.anim(config));
  21050. if (listeners) {
  21051. anim.on(listeners);
  21052. }
  21053. Ext.fx.Manager.queueFx(anim);
  21054. }
  21055. return me;
  21056. },
  21057. // @private - process the passed fx configuration.
  21058. anim: function(config) {
  21059. if (!Ext.isObject(config)) {
  21060. return (config) ? {} : false;
  21061. }
  21062. var me = this,
  21063. duration = config.duration || Ext.fx.Anim.prototype.duration,
  21064. easing = config.easing || 'ease',
  21065. animConfig;
  21066. if (config.stopAnimation) {
  21067. me.stopAnimation();
  21068. }
  21069. Ext.applyIf(config, Ext.fx.Manager.getFxDefaults(me.id));
  21070. // Clear any 'paused' defaults.
  21071. Ext.fx.Manager.setFxDefaults(me.id, {
  21072. delay: 0
  21073. });
  21074. animConfig = {
  21075. // Pass the DOM reference. That's tested first so will be converted to an Ext.fx.Target fastest.
  21076. target: me.dom,
  21077. remove: config.remove,
  21078. alternate: config.alternate || false,
  21079. duration: duration,
  21080. easing: easing,
  21081. callback: config.callback,
  21082. listeners: config.listeners,
  21083. iterations: config.iterations || 1,
  21084. scope: config.scope,
  21085. block: config.block,
  21086. concurrent: config.concurrent,
  21087. delay: config.delay || 0,
  21088. paused: true,
  21089. keyframes: config.keyframes,
  21090. from: config.from || {},
  21091. to: Ext.apply({}, config)
  21092. };
  21093. Ext.apply(animConfig.to, config.to);
  21094. // Anim API properties - backward compat
  21095. delete animConfig.to.to;
  21096. delete animConfig.to.from;
  21097. delete animConfig.to.remove;
  21098. delete animConfig.to.alternate;
  21099. delete animConfig.to.keyframes;
  21100. delete animConfig.to.iterations;
  21101. delete animConfig.to.listeners;
  21102. delete animConfig.to.target;
  21103. delete animConfig.to.paused;
  21104. delete animConfig.to.callback;
  21105. delete animConfig.to.scope;
  21106. delete animConfig.to.duration;
  21107. delete animConfig.to.easing;
  21108. delete animConfig.to.concurrent;
  21109. delete animConfig.to.block;
  21110. delete animConfig.to.stopAnimation;
  21111. delete animConfig.to.delay;
  21112. return animConfig;
  21113. },
  21114. /**
  21115. * Slides the element into view. An anchor point can be optionally passed to set the point of origin for the slide
  21116. * effect. This function automatically handles wrapping the element with a fixed-size container if needed. See the
  21117. * Fx class overview for valid anchor point options. Usage:
  21118. *
  21119. * // default: slide the element in from the top
  21120. * el.slideIn();
  21121. *
  21122. * // custom: slide the element in from the right with a 2-second duration
  21123. * el.slideIn('r', { duration: 2000 });
  21124. *
  21125. * // common config options shown with default values
  21126. * el.slideIn('t', {
  21127. * easing: 'easeOut',
  21128. * duration: 500
  21129. * });
  21130. *
  21131. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
  21132. * @param {Object} options (optional) Object literal with any of the Fx config options
  21133. * @param {Boolean} options.preserveScroll Set to true if preservation of any descendant elements'
  21134. * `scrollTop` values is required. By default the DOM wrapping operation performed by `slideIn` and
  21135. * `slideOut` causes the browser to lose all scroll positions.
  21136. * @return {Ext.dom.Element} The Element
  21137. */
  21138. slideIn: function(anchor, obj, slideOut) {
  21139. var me = this,
  21140. elStyle = me.dom.style,
  21141. beforeAnim,
  21142. wrapAnim,
  21143. restoreScroll,
  21144. wrapDomParentNode;
  21145. anchor = anchor || "t";
  21146. obj = obj || {};
  21147. beforeAnim = function() {
  21148. var animScope = this,
  21149. listeners = obj.listeners,
  21150. box, originalStyles, anim, wrap;
  21151. if (!slideOut) {
  21152. me.fixDisplay();
  21153. }
  21154. box = me.getBox();
  21155. if ((anchor == 't' || anchor == 'b') && box.height === 0) {
  21156. box.height = me.dom.scrollHeight;
  21157. }
  21158. else if ((anchor == 'l' || anchor == 'r') && box.width === 0) {
  21159. box.width = me.dom.scrollWidth;
  21160. }
  21161. originalStyles = me.getStyles('width', 'height', 'left', 'right', 'top', 'bottom', 'position', 'z-index', true);
  21162. me.setSize(box.width, box.height);
  21163. // Cache all descendants' scrollTop & scrollLeft values if configured to preserve scroll.
  21164. if (obj.preserveScroll) {
  21165. restoreScroll = me.cacheScrollValues();
  21166. }
  21167. wrap = me.wrap({
  21168. id: Ext.id() + '-anim-wrap-for-' + me.id,
  21169. style: {
  21170. visibility: slideOut ? 'visible' : 'hidden'
  21171. }
  21172. });
  21173. wrapDomParentNode = wrap.dom.parentNode;
  21174. wrap.setPositioning(me.getPositioning());
  21175. if (wrap.isStyle('position', 'static')) {
  21176. wrap.position('relative');
  21177. }
  21178. me.clearPositioning('auto');
  21179. wrap.clip();
  21180. // The wrap will have reset all descendant scrollTops. Restore them if we cached them.
  21181. if (restoreScroll) {
  21182. restoreScroll();
  21183. }
  21184. // This element is temporarily positioned absolute within its wrapper.
  21185. // Restore to its default, CSS-inherited visibility setting.
  21186. // We cannot explicitly poke visibility:visible into its style because that overrides the visibility of the wrap.
  21187. me.setStyle({
  21188. visibility: '',
  21189. position: 'absolute'
  21190. });
  21191. if (slideOut) {
  21192. wrap.setSize(box.width, box.height);
  21193. }
  21194. switch (anchor) {
  21195. case 't':
  21196. anim = {
  21197. from: {
  21198. width: box.width + 'px',
  21199. height: '0px'
  21200. },
  21201. to: {
  21202. width: box.width + 'px',
  21203. height: box.height + 'px'
  21204. }
  21205. };
  21206. elStyle.bottom = '0px';
  21207. break;
  21208. case 'l':
  21209. anim = {
  21210. from: {
  21211. width: '0px',
  21212. height: box.height + 'px'
  21213. },
  21214. to: {
  21215. width: box.width + 'px',
  21216. height: box.height + 'px'
  21217. }
  21218. };
  21219. elStyle.right = '0px';
  21220. break;
  21221. case 'r':
  21222. anim = {
  21223. from: {
  21224. x: box.x + box.width,
  21225. width: '0px',
  21226. height: box.height + 'px'
  21227. },
  21228. to: {
  21229. x: box.x,
  21230. width: box.width + 'px',
  21231. height: box.height + 'px'
  21232. }
  21233. };
  21234. break;
  21235. case 'b':
  21236. anim = {
  21237. from: {
  21238. y: box.y + box.height,
  21239. width: box.width + 'px',
  21240. height: '0px'
  21241. },
  21242. to: {
  21243. y: box.y,
  21244. width: box.width + 'px',
  21245. height: box.height + 'px'
  21246. }
  21247. };
  21248. break;
  21249. case 'tl':
  21250. anim = {
  21251. from: {
  21252. x: box.x,
  21253. y: box.y,
  21254. width: '0px',
  21255. height: '0px'
  21256. },
  21257. to: {
  21258. width: box.width + 'px',
  21259. height: box.height + 'px'
  21260. }
  21261. };
  21262. elStyle.bottom = '0px';
  21263. elStyle.right = '0px';
  21264. break;
  21265. case 'bl':
  21266. anim = {
  21267. from: {
  21268. y: box.y + box.height,
  21269. width: '0px',
  21270. height: '0px'
  21271. },
  21272. to: {
  21273. y: box.y,
  21274. width: box.width + 'px',
  21275. height: box.height + 'px'
  21276. }
  21277. };
  21278. elStyle.bottom = '0px';
  21279. break;
  21280. case 'br':
  21281. anim = {
  21282. from: {
  21283. x: box.x + box.width,
  21284. y: box.y + box.height,
  21285. width: '0px',
  21286. height: '0px'
  21287. },
  21288. to: {
  21289. x: box.x,
  21290. y: box.y,
  21291. width: box.width + 'px',
  21292. height: box.height + 'px'
  21293. }
  21294. };
  21295. break;
  21296. case 'tr':
  21297. anim = {
  21298. from: {
  21299. x: box.x + box.width,
  21300. width: '0px',
  21301. height: '0px'
  21302. },
  21303. to: {
  21304. x: box.x,
  21305. width: box.width + 'px',
  21306. height: box.height + 'px'
  21307. }
  21308. };
  21309. elStyle.right = '0px';
  21310. break;
  21311. }
  21312. wrap.show();
  21313. wrapAnim = Ext.apply({}, obj);
  21314. delete wrapAnim.listeners;
  21315. wrapAnim = new Ext.fx.Anim(Ext.applyIf(wrapAnim, {
  21316. target: wrap,
  21317. duration: 500,
  21318. easing: 'ease-out',
  21319. from: slideOut ? anim.to : anim.from,
  21320. to: slideOut ? anim.from : anim.to
  21321. }));
  21322. // In the absence of a callback, this listener MUST be added first
  21323. wrapAnim.on('afteranimate', function() {
  21324. me.setStyle(originalStyles);
  21325. if (slideOut) {
  21326. if (obj.useDisplay) {
  21327. me.setDisplayed(false);
  21328. } else {
  21329. me.hide();
  21330. }
  21331. }
  21332. if (wrap.dom) {
  21333. if (wrap.dom.parentNode) {
  21334. wrap.dom.parentNode.insertBefore(me.dom, wrap.dom);
  21335. } else {
  21336. wrapDomParentNode.appendChild(me.dom);
  21337. }
  21338. wrap.remove();
  21339. }
  21340. // The unwrap will have reset all descendant scrollTops. Restore them if we cached them.
  21341. if (restoreScroll) {
  21342. restoreScroll();
  21343. }
  21344. // kill the no-op element animation created below
  21345. animScope.end();
  21346. });
  21347. // Add configured listeners after
  21348. if (listeners) {
  21349. wrapAnim.on(listeners);
  21350. }
  21351. };
  21352. me.animate({
  21353. // See "A Note About Wrapped Animations" at the top of this class:
  21354. duration: obj.duration ? Math.max(obj.duration, 500) * 2 : 1000,
  21355. listeners: {
  21356. beforeanimate: beforeAnim // kick off the wrap animation
  21357. }
  21358. });
  21359. return me;
  21360. },
  21361. /**
  21362. * Slides the element out of view. An anchor point can be optionally passed to set the end point for the slide
  21363. * effect. When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will
  21364. * still take up space in the document. The element must be removed from the DOM using the 'remove' config option if
  21365. * desired. This function automatically handles wrapping the element with a fixed-size container if needed. See the
  21366. * Fx class overview for valid anchor point options. Usage:
  21367. *
  21368. * // default: slide the element out to the top
  21369. * el.slideOut();
  21370. *
  21371. * // custom: slide the element out to the right with a 2-second duration
  21372. * el.slideOut('r', { duration: 2000 });
  21373. *
  21374. * // common config options shown with default values
  21375. * el.slideOut('t', {
  21376. * easing: 'easeOut',
  21377. * duration: 500,
  21378. * remove: false,
  21379. * useDisplay: false
  21380. * });
  21381. *
  21382. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
  21383. * @param {Object} options (optional) Object literal with any of the Fx config options
  21384. * @return {Ext.dom.Element} The Element
  21385. */
  21386. slideOut: function(anchor, o) {
  21387. return this.slideIn(anchor, o, true);
  21388. },
  21389. /**
  21390. * Fades the element out while slowly expanding it in all directions. When the effect is completed, the element will
  21391. * be hidden (visibility = 'hidden') but block elements will still take up space in the document. Usage:
  21392. *
  21393. * // default
  21394. * el.puff();
  21395. *
  21396. * // common config options shown with default values
  21397. * el.puff({
  21398. * easing: 'easeOut',
  21399. * duration: 500,
  21400. * useDisplay: false
  21401. * });
  21402. *
  21403. * @param {Object} options (optional) Object literal with any of the Fx config options
  21404. * @return {Ext.dom.Element} The Element
  21405. */
  21406. puff: function(obj) {
  21407. var me = this,
  21408. beforeAnim,
  21409. box = me.getBox(),
  21410. originalStyles = me.getStyles('width', 'height', 'left', 'right', 'top', 'bottom', 'position', 'z-index', 'font-size', 'opacity', true);
  21411. obj = Ext.applyIf(obj || {}, {
  21412. easing: 'ease-out',
  21413. duration: 500,
  21414. useDisplay: false
  21415. });
  21416. beforeAnim = function() {
  21417. me.clearOpacity();
  21418. me.show();
  21419. this.to = {
  21420. width: box.width * 2,
  21421. height: box.height * 2,
  21422. x: box.x - (box.width / 2),
  21423. y: box.y - (box.height /2),
  21424. opacity: 0,
  21425. fontSize: '200%'
  21426. };
  21427. this.on('afteranimate',function() {
  21428. if (me.dom) {
  21429. if (obj.useDisplay) {
  21430. me.setDisplayed(false);
  21431. } else {
  21432. me.hide();
  21433. }
  21434. me.setStyle(originalStyles);
  21435. obj.callback.call(obj.scope);
  21436. }
  21437. });
  21438. };
  21439. me.animate({
  21440. duration: obj.duration,
  21441. easing: obj.easing,
  21442. listeners: {
  21443. beforeanimate: {
  21444. fn: beforeAnim
  21445. }
  21446. }
  21447. });
  21448. return me;
  21449. },
  21450. /**
  21451. * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).
  21452. * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still
  21453. * take up space in the document. The element must be removed from the DOM using the 'remove' config option if
  21454. * desired. Usage:
  21455. *
  21456. * // default
  21457. * el.switchOff();
  21458. *
  21459. * // all config options shown with default values
  21460. * el.switchOff({
  21461. * easing: 'easeIn',
  21462. * duration: .3,
  21463. * remove: false,
  21464. * useDisplay: false
  21465. * });
  21466. *
  21467. * @param {Object} options (optional) Object literal with any of the Fx config options
  21468. * @return {Ext.dom.Element} The Element
  21469. */
  21470. switchOff: function(obj) {
  21471. var me = this,
  21472. beforeAnim;
  21473. obj = Ext.applyIf(obj || {}, {
  21474. easing: 'ease-in',
  21475. duration: 500,
  21476. remove: false,
  21477. useDisplay: false
  21478. });
  21479. beforeAnim = function() {
  21480. var animScope = this,
  21481. size = me.getSize(),
  21482. xy = me.getXY(),
  21483. keyframe, position;
  21484. me.clearOpacity();
  21485. me.clip();
  21486. position = me.getPositioning();
  21487. keyframe = new Ext.fx.Animator({
  21488. target: me,
  21489. duration: obj.duration,
  21490. easing: obj.easing,
  21491. keyframes: {
  21492. 33: {
  21493. opacity: 0.3
  21494. },
  21495. 66: {
  21496. height: 1,
  21497. y: xy[1] + size.height / 2
  21498. },
  21499. 100: {
  21500. width: 1,
  21501. x: xy[0] + size.width / 2
  21502. }
  21503. }
  21504. });
  21505. keyframe.on('afteranimate', function() {
  21506. if (obj.useDisplay) {
  21507. me.setDisplayed(false);
  21508. } else {
  21509. me.hide();
  21510. }
  21511. me.clearOpacity();
  21512. me.setPositioning(position);
  21513. me.setSize(size);
  21514. // kill the no-op element animation created below
  21515. animScope.end();
  21516. });
  21517. };
  21518. me.animate({
  21519. // See "A Note About Wrapped Animations" at the top of this class:
  21520. duration: (Math.max(obj.duration, 500) * 2),
  21521. listeners: {
  21522. beforeanimate: {
  21523. fn: beforeAnim
  21524. }
  21525. }
  21526. });
  21527. return me;
  21528. },
  21529. /**
  21530. * Shows a ripple of exploding, attenuating borders to draw attention to an Element. Usage:
  21531. *
  21532. * // default: a single light blue ripple
  21533. * el.frame();
  21534. *
  21535. * // custom: 3 red ripples lasting 3 seconds total
  21536. * el.frame("#ff0000", 3, { duration: 3000 });
  21537. *
  21538. * // common config options shown with default values
  21539. * el.frame("#C3DAF9", 1, {
  21540. * duration: 1000 // duration of each individual ripple.
  21541. * // Note: Easing is not configurable and will be ignored if included
  21542. * });
  21543. *
  21544. * @param {String} [color='#C3DAF9'] The hex color value for the border.
  21545. * @param {Number} [count=1] The number of ripples to display.
  21546. * @param {Object} [options] Object literal with any of the Fx config options
  21547. * @return {Ext.dom.Element} The Element
  21548. */
  21549. frame : function(color, count, obj){
  21550. var me = this,
  21551. beforeAnim;
  21552. color = color || '#C3DAF9';
  21553. count = count || 1;
  21554. obj = obj || {};
  21555. beforeAnim = function() {
  21556. me.show();
  21557. var animScope = this,
  21558. box = me.getBox(),
  21559. proxy = Ext.getBody().createChild({
  21560. id: me.id + '-anim-proxy',
  21561. style: {
  21562. position : 'absolute',
  21563. 'pointer-events': 'none',
  21564. 'z-index': 35000,
  21565. border : '0px solid ' + color
  21566. }
  21567. }),
  21568. proxyAnim;
  21569. proxyAnim = new Ext.fx.Anim({
  21570. target: proxy,
  21571. duration: obj.duration || 1000,
  21572. iterations: count,
  21573. from: {
  21574. top: box.y,
  21575. left: box.x,
  21576. borderWidth: 0,
  21577. opacity: 1,
  21578. height: box.height,
  21579. width: box.width
  21580. },
  21581. to: {
  21582. top: box.y - 20,
  21583. left: box.x - 20,
  21584. borderWidth: 10,
  21585. opacity: 0,
  21586. height: box.height + 40,
  21587. width: box.width + 40
  21588. }
  21589. });
  21590. proxyAnim.on('afteranimate', function() {
  21591. proxy.remove();
  21592. // kill the no-op element animation created below
  21593. animScope.end();
  21594. });
  21595. };
  21596. me.animate({
  21597. // See "A Note About Wrapped Animations" at the top of this class:
  21598. duration: (Math.max(obj.duration, 500) * 2) || 2000,
  21599. listeners: {
  21600. beforeanimate: {
  21601. fn: beforeAnim
  21602. }
  21603. }
  21604. });
  21605. return me;
  21606. },
  21607. /**
  21608. * Slides the element while fading it out of view. An anchor point can be optionally passed to set the ending point
  21609. * of the effect. Usage:
  21610. *
  21611. * // default: slide the element downward while fading out
  21612. * el.ghost();
  21613. *
  21614. * // custom: slide the element out to the right with a 2-second duration
  21615. * el.ghost('r', { duration: 2000 });
  21616. *
  21617. * // common config options shown with default values
  21618. * el.ghost('b', {
  21619. * easing: 'easeOut',
  21620. * duration: 500
  21621. * });
  21622. *
  21623. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b')
  21624. * @param {Object} options (optional) Object literal with any of the Fx config options
  21625. * @return {Ext.dom.Element} The Element
  21626. */
  21627. ghost: function(anchor, obj) {
  21628. var me = this,
  21629. beforeAnim;
  21630. anchor = anchor || "b";
  21631. beforeAnim = function() {
  21632. var width = me.getWidth(),
  21633. height = me.getHeight(),
  21634. xy = me.getXY(),
  21635. position = me.getPositioning(),
  21636. to = {
  21637. opacity: 0
  21638. };
  21639. switch (anchor) {
  21640. case 't':
  21641. to.y = xy[1] - height;
  21642. break;
  21643. case 'l':
  21644. to.x = xy[0] - width;
  21645. break;
  21646. case 'r':
  21647. to.x = xy[0] + width;
  21648. break;
  21649. case 'b':
  21650. to.y = xy[1] + height;
  21651. break;
  21652. case 'tl':
  21653. to.x = xy[0] - width;
  21654. to.y = xy[1] - height;
  21655. break;
  21656. case 'bl':
  21657. to.x = xy[0] - width;
  21658. to.y = xy[1] + height;
  21659. break;
  21660. case 'br':
  21661. to.x = xy[0] + width;
  21662. to.y = xy[1] + height;
  21663. break;
  21664. case 'tr':
  21665. to.x = xy[0] + width;
  21666. to.y = xy[1] - height;
  21667. break;
  21668. }
  21669. this.to = to;
  21670. this.on('afteranimate', function () {
  21671. if (me.dom) {
  21672. me.hide();
  21673. me.clearOpacity();
  21674. me.setPositioning(position);
  21675. }
  21676. });
  21677. };
  21678. me.animate(Ext.applyIf(obj || {}, {
  21679. duration: 500,
  21680. easing: 'ease-out',
  21681. listeners: {
  21682. beforeanimate: {
  21683. fn: beforeAnim
  21684. }
  21685. }
  21686. }));
  21687. return me;
  21688. },
  21689. /**
  21690. * Highlights the Element by setting a color (applies to the background-color by default, but can be changed using
  21691. * the "attr" config option) and then fading back to the original color. If no original color is available, you
  21692. * should provide the "endColor" config option which will be cleared after the animation. Usage:
  21693. *
  21694. * // default: highlight background to yellow
  21695. * el.highlight();
  21696. *
  21697. * // custom: highlight foreground text to blue for 2 seconds
  21698. * el.highlight("0000ff", { attr: 'color', duration: 2000 });
  21699. *
  21700. * // common config options shown with default values
  21701. * el.highlight("ffff9c", {
  21702. * attr: "backgroundColor", //can be any valid CSS property (attribute) that supports a color value
  21703. * endColor: (current color) or "ffffff",
  21704. * easing: 'easeIn',
  21705. * duration: 1000
  21706. * });
  21707. *
  21708. * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading #
  21709. * (defaults to yellow: 'ffff9c')
  21710. * @param {Object} options (optional) Object literal with any of the Fx config options
  21711. * @return {Ext.dom.Element} The Element
  21712. */
  21713. highlight: function(color, o) {
  21714. var me = this,
  21715. dom = me.dom,
  21716. from = {},
  21717. restore, to, attr, lns, event, fn;
  21718. o = o || {};
  21719. lns = o.listeners || {};
  21720. attr = o.attr || 'backgroundColor';
  21721. from[attr] = color || 'ffff9c';
  21722. if (!o.to) {
  21723. to = {};
  21724. to[attr] = o.endColor || me.getColor(attr, 'ffffff', '');
  21725. }
  21726. else {
  21727. to = o.to;
  21728. }
  21729. // Don't apply directly on lns, since we reference it in our own callbacks below
  21730. o.listeners = Ext.apply(Ext.apply({}, lns), {
  21731. beforeanimate: function() {
  21732. restore = dom.style[attr];
  21733. me.clearOpacity();
  21734. me.show();
  21735. event = lns.beforeanimate;
  21736. if (event) {
  21737. fn = event.fn || event;
  21738. return fn.apply(event.scope || lns.scope || window, arguments);
  21739. }
  21740. },
  21741. afteranimate: function() {
  21742. if (dom) {
  21743. dom.style[attr] = restore;
  21744. }
  21745. event = lns.afteranimate;
  21746. if (event) {
  21747. fn = event.fn || event;
  21748. fn.apply(event.scope || lns.scope || window, arguments);
  21749. }
  21750. }
  21751. });
  21752. me.animate(Ext.apply({}, o, {
  21753. duration: 1000,
  21754. easing: 'ease-in',
  21755. from: from,
  21756. to: to
  21757. }));
  21758. return me;
  21759. },
  21760. /**
  21761. * Creates a pause before any subsequent queued effects begin. If there are no effects queued after the pause it will
  21762. * have no effect. Usage:
  21763. *
  21764. * el.pause(1);
  21765. *
  21766. * @deprecated 4.0 Use the `delay` config to {@link #animate} instead.
  21767. * @param {Number} seconds The length of time to pause (in seconds)
  21768. * @return {Ext.Element} The Element
  21769. */
  21770. pause: function(ms) {
  21771. var me = this;
  21772. Ext.fx.Manager.setFxDefaults(me.id, {
  21773. delay: ms
  21774. });
  21775. return me;
  21776. },
  21777. /**
  21778. * Fade an element in (from transparent to opaque). The ending opacity can be specified using the `opacity`
  21779. * config option. Usage:
  21780. *
  21781. * // default: fade in from opacity 0 to 100%
  21782. * el.fadeIn();
  21783. *
  21784. * // custom: fade in from opacity 0 to 75% over 2 seconds
  21785. * el.fadeIn({ opacity: .75, duration: 2000});
  21786. *
  21787. * // common config options shown with default values
  21788. * el.fadeIn({
  21789. * opacity: 1, //can be any value between 0 and 1 (e.g. .5)
  21790. * easing: 'easeOut',
  21791. * duration: 500
  21792. * });
  21793. *
  21794. * @param {Object} options (optional) Object literal with any of the Fx config options
  21795. * @return {Ext.Element} The Element
  21796. */
  21797. fadeIn: function(o) {
  21798. var me = this;
  21799. me.animate(Ext.apply({}, o, {
  21800. opacity: 1,
  21801. internalListeners: {
  21802. beforeanimate: function(anim){
  21803. // restore any visibility/display that may have
  21804. // been applied by a fadeout animation
  21805. if (me.isStyle('display', 'none')) {
  21806. me.setDisplayed('');
  21807. } else {
  21808. me.show();
  21809. }
  21810. }
  21811. }
  21812. }));
  21813. return this;
  21814. },
  21815. /**
  21816. * Fade an element out (from opaque to transparent). The ending opacity can be specified using the `opacity`
  21817. * config option. Note that IE may require `useDisplay:true` in order to redisplay correctly.
  21818. * Usage:
  21819. *
  21820. * // default: fade out from the element's current opacity to 0
  21821. * el.fadeOut();
  21822. *
  21823. * // custom: fade out from the element's current opacity to 25% over 2 seconds
  21824. * el.fadeOut({ opacity: .25, duration: 2000});
  21825. *
  21826. * // common config options shown with default values
  21827. * el.fadeOut({
  21828. * opacity: 0, //can be any value between 0 and 1 (e.g. .5)
  21829. * easing: 'easeOut',
  21830. * duration: 500,
  21831. * remove: false,
  21832. * useDisplay: false
  21833. * });
  21834. *
  21835. * @param {Object} options (optional) Object literal with any of the Fx config options
  21836. * @return {Ext.Element} The Element
  21837. */
  21838. fadeOut: function(o) {
  21839. var me = this;
  21840. o = Ext.apply({
  21841. opacity: 0,
  21842. internalListeners: {
  21843. afteranimate: function(anim){
  21844. var dom = me.dom;
  21845. if (dom && anim.to.opacity === 0) {
  21846. if (o.useDisplay) {
  21847. me.setDisplayed(false);
  21848. } else {
  21849. me.hide();
  21850. }
  21851. }
  21852. }
  21853. }
  21854. }, o);
  21855. me.animate(o);
  21856. return me;
  21857. },
  21858. /**
  21859. * Animates the transition of an element's dimensions from a starting height/width to an ending height/width. This
  21860. * method is a convenience implementation of {@link #shift}. Usage:
  21861. *
  21862. * // change height and width to 100x100 pixels
  21863. * el.scale(100, 100);
  21864. *
  21865. * // common config options shown with default values. The height and width will default to
  21866. * // the element's existing values if passed as null.
  21867. * el.scale(
  21868. * [element's width],
  21869. * [element's height], {
  21870. * easing: 'easeOut',
  21871. * duration: 350
  21872. * }
  21873. * );
  21874. *
  21875. * @deprecated 4.0 Just use {@link #animate} instead.
  21876. * @param {Number} width The new width (pass undefined to keep the original width)
  21877. * @param {Number} height The new height (pass undefined to keep the original height)
  21878. * @param {Object} options (optional) Object literal with any of the Fx config options
  21879. * @return {Ext.Element} The Element
  21880. */
  21881. scale: function(w, h, o) {
  21882. this.animate(Ext.apply({}, o, {
  21883. width: w,
  21884. height: h
  21885. }));
  21886. return this;
  21887. },
  21888. /**
  21889. * Animates the transition of any combination of an element's dimensions, xy position and/or opacity. Any of these
  21890. * properties not specified in the config object will not be changed. This effect requires that at least one new
  21891. * dimension, position or opacity setting must be passed in on the config object in order for the function to have
  21892. * any effect. Usage:
  21893. *
  21894. * // slide the element horizontally to x position 200 while changing the height and opacity
  21895. * el.shift({ x: 200, height: 50, opacity: .8 });
  21896. *
  21897. * // common config options shown with default values.
  21898. * el.shift({
  21899. * width: [element's width],
  21900. * height: [element's height],
  21901. * x: [element's x position],
  21902. * y: [element's y position],
  21903. * opacity: [element's opacity],
  21904. * easing: 'easeOut',
  21905. * duration: 350
  21906. * });
  21907. *
  21908. * @deprecated 4.0 Just use {@link #animate} instead.
  21909. * @param {Object} options Object literal with any of the Fx config options
  21910. * @return {Ext.Element} The Element
  21911. */
  21912. shift: function(config) {
  21913. this.animate(config);
  21914. return this;
  21915. }
  21916. });
  21917. //@tag dom,core
  21918. //@require Ext.dom.Element-anim
  21919. //@define Ext.dom.Element-dd
  21920. //@define Ext.dom.Element
  21921. /**
  21922. * @class Ext.dom.Element
  21923. */
  21924. Ext.dom.Element.override({
  21925. /**
  21926. * Initializes a {@link Ext.dd.DD} drag drop object for this element.
  21927. * @param {String} group The group the DD object is member of
  21928. * @param {Object} config The DD config object
  21929. * @param {Object} overrides An object containing methods to override/implement on the DD object
  21930. * @return {Ext.dd.DD} The DD object
  21931. */
  21932. initDD : function(group, config, overrides){
  21933. var dd = new Ext.dd.DD(Ext.id(this.dom), group, config);
  21934. return Ext.apply(dd, overrides);
  21935. },
  21936. /**
  21937. * Initializes a {@link Ext.dd.DDProxy} object for this element.
  21938. * @param {String} group The group the DDProxy object is member of
  21939. * @param {Object} config The DDProxy config object
  21940. * @param {Object} overrides An object containing methods to override/implement on the DDProxy object
  21941. * @return {Ext.dd.DDProxy} The DDProxy object
  21942. */
  21943. initDDProxy : function(group, config, overrides){
  21944. var dd = new Ext.dd.DDProxy(Ext.id(this.dom), group, config);
  21945. return Ext.apply(dd, overrides);
  21946. },
  21947. /**
  21948. * Initializes a {@link Ext.dd.DDTarget} object for this element.
  21949. * @param {String} group The group the DDTarget object is member of
  21950. * @param {Object} config The DDTarget config object
  21951. * @param {Object} overrides An object containing methods to override/implement on the DDTarget object
  21952. * @return {Ext.dd.DDTarget} The DDTarget object
  21953. */
  21954. initDDTarget : function(group, config, overrides){
  21955. var dd = new Ext.dd.DDTarget(Ext.id(this.dom), group, config);
  21956. return Ext.apply(dd, overrides);
  21957. }
  21958. });
  21959. //@tag dom,core
  21960. //@require Ext.dom.Element-dd
  21961. //@define Ext.dom.Element-fx
  21962. //@define Ext.dom.Element
  21963. /**
  21964. * @class Ext.dom.Element
  21965. */
  21966. (function() {
  21967. var Element = Ext.dom.Element,
  21968. VISIBILITY = "visibility",
  21969. DISPLAY = "display",
  21970. NONE = "none",
  21971. HIDDEN = 'hidden',
  21972. VISIBLE = 'visible',
  21973. OFFSETS = "offsets",
  21974. ASCLASS = "asclass",
  21975. NOSIZE = 'nosize',
  21976. ORIGINALDISPLAY = 'originalDisplay',
  21977. VISMODE = 'visibilityMode',
  21978. ISVISIBLE = 'isVisible',
  21979. OFFSETCLASS = Ext.baseCSSPrefix + 'hide-offsets',
  21980. getDisplay = function(el) {
  21981. var data = (el.$cache || el.getCache()).data,
  21982. display = data[ORIGINALDISPLAY];
  21983. if (display === undefined) {
  21984. data[ORIGINALDISPLAY] = display = '';
  21985. }
  21986. return display;
  21987. },
  21988. getVisMode = function(el){
  21989. var data = (el.$cache || el.getCache()).data,
  21990. visMode = data[VISMODE];
  21991. if (visMode === undefined) {
  21992. data[VISMODE] = visMode = Element.VISIBILITY;
  21993. }
  21994. return visMode;
  21995. };
  21996. Element.override({
  21997. /**
  21998. * The element's default display mode.
  21999. */
  22000. originalDisplay : "",
  22001. visibilityMode : 1,
  22002. /**
  22003. * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
  22004. * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
  22005. * @param {Boolean} visible Whether the element is visible
  22006. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element animation config object
  22007. * @return {Ext.dom.Element} this
  22008. */
  22009. setVisible : function(visible, animate) {
  22010. var me = this,
  22011. dom = me.dom,
  22012. visMode = getVisMode(me);
  22013. // hideMode string override
  22014. if (typeof animate == 'string') {
  22015. switch (animate) {
  22016. case DISPLAY:
  22017. visMode = Element.DISPLAY;
  22018. break;
  22019. case VISIBILITY:
  22020. visMode = Element.VISIBILITY;
  22021. break;
  22022. case OFFSETS:
  22023. visMode = Element.OFFSETS;
  22024. break;
  22025. case NOSIZE:
  22026. case ASCLASS:
  22027. visMode = Element.ASCLASS;
  22028. break;
  22029. }
  22030. me.setVisibilityMode(visMode);
  22031. animate = false;
  22032. }
  22033. if (!animate || !me.anim) {
  22034. if (visMode == Element.DISPLAY) {
  22035. return me.setDisplayed(visible);
  22036. } else if (visMode == Element.OFFSETS) {
  22037. me[visible?'removeCls':'addCls'](OFFSETCLASS);
  22038. } else if (visMode == Element.VISIBILITY) {
  22039. me.fixDisplay();
  22040. // Show by clearing visibility style. Explicitly setting to "visible" overrides parent visibility setting
  22041. dom.style.visibility = visible ? '' : HIDDEN;
  22042. } else if (visMode == Element.ASCLASS) {
  22043. me[visible?'removeCls':'addCls'](me.visibilityCls || Element.visibilityCls);
  22044. }
  22045. } else {
  22046. // closure for composites
  22047. if (visible) {
  22048. me.setOpacity(0.01);
  22049. me.setVisible(true);
  22050. }
  22051. if (!Ext.isObject(animate)) {
  22052. animate = {
  22053. duration: 350,
  22054. easing: 'ease-in'
  22055. };
  22056. }
  22057. me.animate(Ext.applyIf({
  22058. callback: function() {
  22059. if (!visible) {
  22060. me.setVisible(false).setOpacity(1);
  22061. }
  22062. },
  22063. to: {
  22064. opacity: (visible) ? 1 : 0
  22065. }
  22066. }, animate));
  22067. }
  22068. (me.$cache || me.getCache()).data[ISVISIBLE] = visible;
  22069. return me;
  22070. },
  22071. /**
  22072. * @private
  22073. * Determine if the Element has a relevant height and width available based
  22074. * upon current logical visibility state
  22075. */
  22076. hasMetrics : function(){
  22077. var visMode = getVisMode(this);
  22078. return this.isVisible() || (visMode == Element.OFFSETS) || (visMode == Element.VISIBILITY);
  22079. },
  22080. /**
  22081. * Toggles the element's visibility or display, depending on visibility mode.
  22082. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element animation config object
  22083. * @return {Ext.dom.Element} this
  22084. */
  22085. toggle : function(animate){
  22086. var me = this;
  22087. me.setVisible(!me.isVisible(), me.anim(animate));
  22088. return me;
  22089. },
  22090. /**
  22091. * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
  22092. * @param {Boolean/String} value Boolean value to display the element using its default display, or a string to set the display directly.
  22093. * @return {Ext.dom.Element} this
  22094. */
  22095. setDisplayed : function(value) {
  22096. if(typeof value == "boolean"){
  22097. value = value ? getDisplay(this) : NONE;
  22098. }
  22099. this.setStyle(DISPLAY, value);
  22100. return this;
  22101. },
  22102. // private
  22103. fixDisplay : function(){
  22104. var me = this;
  22105. if (me.isStyle(DISPLAY, NONE)) {
  22106. me.setStyle(VISIBILITY, HIDDEN);
  22107. me.setStyle(DISPLAY, getDisplay(me)); // first try reverting to default
  22108. if (me.isStyle(DISPLAY, NONE)) { // if that fails, default to block
  22109. me.setStyle(DISPLAY, "block");
  22110. }
  22111. }
  22112. },
  22113. /**
  22114. * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
  22115. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  22116. * @return {Ext.dom.Element} this
  22117. */
  22118. hide : function(animate){
  22119. // hideMode override
  22120. if (typeof animate == 'string'){
  22121. this.setVisible(false, animate);
  22122. return this;
  22123. }
  22124. this.setVisible(false, this.anim(animate));
  22125. return this;
  22126. },
  22127. /**
  22128. * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
  22129. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  22130. * @return {Ext.dom.Element} this
  22131. */
  22132. show : function(animate){
  22133. // hideMode override
  22134. if (typeof animate == 'string'){
  22135. this.setVisible(true, animate);
  22136. return this;
  22137. }
  22138. this.setVisible(true, this.anim(animate));
  22139. return this;
  22140. }
  22141. });
  22142. }());
  22143. //@tag dom,core
  22144. //@require Ext.dom.Element-fx
  22145. //@define Ext.dom.Element-position
  22146. //@define Ext.dom.Element
  22147. /**
  22148. * @class Ext.dom.Element
  22149. */
  22150. (function() {
  22151. var Element = Ext.dom.Element,
  22152. LEFT = "left",
  22153. RIGHT = "right",
  22154. TOP = "top",
  22155. BOTTOM = "bottom",
  22156. POSITION = "position",
  22157. STATIC = "static",
  22158. RELATIVE = "relative",
  22159. AUTO = "auto",
  22160. ZINDEX = "z-index",
  22161. BODY = 'BODY',
  22162. PADDING = 'padding',
  22163. BORDER = 'border',
  22164. SLEFT = '-left',
  22165. SRIGHT = '-right',
  22166. STOP = '-top',
  22167. SBOTTOM = '-bottom',
  22168. SWIDTH = '-width',
  22169. // special markup used throughout Ext when box wrapping elements
  22170. borders = {l: BORDER + SLEFT + SWIDTH, r: BORDER + SRIGHT + SWIDTH, t: BORDER + STOP + SWIDTH, b: BORDER + SBOTTOM + SWIDTH},
  22171. paddings = {l: PADDING + SLEFT, r: PADDING + SRIGHT, t: PADDING + STOP, b: PADDING + SBOTTOM},
  22172. paddingsTLRB = [paddings.l, paddings.r, paddings.t, paddings.b],
  22173. bordersTLRB = [borders.l, borders.r, borders.t, borders.b],
  22174. positionTopLeft = ['position', 'top', 'left'];
  22175. Element.override({
  22176. getX: function() {
  22177. return Element.getX(this.dom);
  22178. },
  22179. getY: function() {
  22180. return Element.getY(this.dom);
  22181. },
  22182. /**
  22183. * Gets the current position of the element based on page coordinates.
  22184. * Element must be part of the DOM tree to have page coordinates
  22185. * (display:none or elements not appended return false).
  22186. * @return {Number[]} The XY position of the element
  22187. */
  22188. getXY: function() {
  22189. return Element.getXY(this.dom);
  22190. },
  22191. /**
  22192. * Returns the offsets of this element from the passed element. Both element must be part
  22193. * of the DOM tree and not have display:none to have page coordinates.
  22194. * @param {String/HTMLElement/Ext.Element} element The element to get the offsets from.
  22195. * @return {Number[]} The XY page offsets (e.g. `[100, -200]`)
  22196. */
  22197. getOffsetsTo : function(el){
  22198. var o = this.getXY(),
  22199. e = Ext.fly(el, '_internal').getXY();
  22200. return [o[0] - e[0],o[1] - e[1]];
  22201. },
  22202. setX: function(x, animate) {
  22203. return this.setXY([x, this.getY()], animate);
  22204. },
  22205. setY: function(y, animate) {
  22206. return this.setXY([this.getX(), y], animate);
  22207. },
  22208. setLeft: function(left) {
  22209. this.setStyle(LEFT, this.addUnits(left));
  22210. return this;
  22211. },
  22212. setTop: function(top) {
  22213. this.setStyle(TOP, this.addUnits(top));
  22214. return this;
  22215. },
  22216. setRight: function(right) {
  22217. this.setStyle(RIGHT, this.addUnits(right));
  22218. return this;
  22219. },
  22220. setBottom: function(bottom) {
  22221. this.setStyle(BOTTOM, this.addUnits(bottom));
  22222. return this;
  22223. },
  22224. /**
  22225. * Sets the position of the element in page coordinates, regardless of how the element
  22226. * is positioned. The element must be part of the DOM tree to have page coordinates
  22227. * (`display:none` or elements not appended return false).
  22228. * @param {Number[]} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
  22229. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element
  22230. * animation config object
  22231. * @return {Ext.Element} this
  22232. */
  22233. setXY: function(pos, animate) {
  22234. var me = this;
  22235. if (!animate || !me.anim) {
  22236. Element.setXY(me.dom, pos);
  22237. }
  22238. else {
  22239. if (!Ext.isObject(animate)) {
  22240. animate = {};
  22241. }
  22242. me.animate(Ext.applyIf({ to: { x: pos[0], y: pos[1] } }, animate));
  22243. }
  22244. return me;
  22245. },
  22246. pxRe: /^\d+(?:\.\d*)?px$/i,
  22247. /**
  22248. * Returns the x-coordinate of this element reletive to its `offsetParent`.
  22249. * @return {Number} The local x-coordinate (relative to the `offsetParent`).
  22250. */
  22251. getLocalX: function() {
  22252. var me = this,
  22253. offsetParent,
  22254. x = me.getStyle(LEFT);
  22255. if (!x || x === AUTO) {
  22256. return 0;
  22257. }
  22258. if (x && me.pxRe.test(x)) {
  22259. return parseFloat(x);
  22260. }
  22261. x = me.getX();
  22262. offsetParent = me.dom.offsetParent;
  22263. if (offsetParent) {
  22264. x -= Ext.fly(offsetParent).getX();
  22265. }
  22266. return x;
  22267. },
  22268. /**
  22269. * Returns the y-coordinate of this element reletive to its `offsetParent`.
  22270. * @return {Number} The local y-coordinate (relative to the `offsetParent`).
  22271. */
  22272. getLocalY: function() {
  22273. var me = this,
  22274. offsetParent,
  22275. y = me.getStyle(TOP);
  22276. if (!y || y === AUTO) {
  22277. return 0;
  22278. }
  22279. if (y && me.pxRe.test(y)) {
  22280. return parseFloat(y);
  22281. }
  22282. y = me.getY();
  22283. offsetParent = me.dom.offsetParent;
  22284. if (offsetParent) {
  22285. y -= Ext.fly(offsetParent).getY();
  22286. }
  22287. return y;
  22288. },
  22289. getLeft: function(local) {
  22290. return local ? this.getLocalX() : this.getX();
  22291. },
  22292. getRight: function(local) {
  22293. return (local ? this.getLocalX() : this.getX()) + this.getWidth();
  22294. },
  22295. getTop: function(local) {
  22296. return local ? this.getLocalY() : this.getY();
  22297. },
  22298. getBottom: function(local) {
  22299. return (local ? this.getLocalY() : this.getY()) + this.getHeight();
  22300. },
  22301. translatePoints: function(x, y) {
  22302. var me = this,
  22303. styles = me.getStyle(positionTopLeft),
  22304. relative = styles.position == 'relative',
  22305. left = parseFloat(styles.left),
  22306. top = parseFloat(styles.top),
  22307. xy = me.getXY();
  22308. if (Ext.isArray(x)) {
  22309. y = x[1];
  22310. x = x[0];
  22311. }
  22312. if (isNaN(left)) {
  22313. left = relative ? 0 : me.dom.offsetLeft;
  22314. }
  22315. if (isNaN(top)) {
  22316. top = relative ? 0 : me.dom.offsetTop;
  22317. }
  22318. left = (typeof x == 'number') ? x - xy[0] + left : undefined;
  22319. top = (typeof y == 'number') ? y - xy[1] + top : undefined;
  22320. return {
  22321. left: left,
  22322. top: top
  22323. };
  22324. },
  22325. setBox: function(box, adjust, animate) {
  22326. var me = this,
  22327. w = box.width,
  22328. h = box.height;
  22329. if ((adjust && !me.autoBoxAdjust) && !me.isBorderBox()) {
  22330. w -= (me.getBorderWidth("lr") + me.getPadding("lr"));
  22331. h -= (me.getBorderWidth("tb") + me.getPadding("tb"));
  22332. }
  22333. me.setBounds(box.x, box.y, w, h, animate);
  22334. return me;
  22335. },
  22336. getBox: function(contentBox, local) {
  22337. var me = this,
  22338. xy,
  22339. left,
  22340. top,
  22341. paddingWidth,
  22342. bordersWidth,
  22343. l, r, t, b, w, h, bx;
  22344. if (!local) {
  22345. xy = me.getXY();
  22346. } else {
  22347. xy = me.getStyle([LEFT, TOP]);
  22348. xy = [ parseFloat(xy.left) || 0, parseFloat(xy.top) || 0];
  22349. }
  22350. w = me.getWidth();
  22351. h = me.getHeight();
  22352. if (!contentBox) {
  22353. bx = {
  22354. x: xy[0],
  22355. y: xy[1],
  22356. 0: xy[0],
  22357. 1: xy[1],
  22358. width: w,
  22359. height: h
  22360. };
  22361. } else {
  22362. paddingWidth = me.getStyle(paddingsTLRB);
  22363. bordersWidth = me.getStyle(bordersTLRB);
  22364. l = (parseFloat(bordersWidth[borders.l]) || 0) + (parseFloat(paddingWidth[paddings.l]) || 0);
  22365. r = (parseFloat(bordersWidth[borders.r]) || 0) + (parseFloat(paddingWidth[paddings.r]) || 0);
  22366. t = (parseFloat(bordersWidth[borders.t]) || 0) + (parseFloat(paddingWidth[paddings.t]) || 0);
  22367. b = (parseFloat(bordersWidth[borders.b]) || 0) + (parseFloat(paddingWidth[paddings.b]) || 0);
  22368. bx = {
  22369. x: xy[0] + l,
  22370. y: xy[1] + t,
  22371. 0: xy[0] + l,
  22372. 1: xy[1] + t,
  22373. width: w - (l + r),
  22374. height: h - (t + b)
  22375. };
  22376. }
  22377. bx.right = bx.x + bx.width;
  22378. bx.bottom = bx.y + bx.height;
  22379. return bx;
  22380. },
  22381. getPageBox: function(getRegion) {
  22382. var me = this,
  22383. el = me.dom,
  22384. isDoc = el.nodeName == BODY,
  22385. w = isDoc ? Ext.dom.AbstractElement.getViewWidth() : el.offsetWidth,
  22386. h = isDoc ? Ext.dom.AbstractElement.getViewHeight() : el.offsetHeight,
  22387. xy = me.getXY(),
  22388. t = xy[1],
  22389. r = xy[0] + w,
  22390. b = xy[1] + h,
  22391. l = xy[0];
  22392. if (getRegion) {
  22393. return new Ext.util.Region(t, r, b, l);
  22394. }
  22395. else {
  22396. return {
  22397. left: l,
  22398. top: t,
  22399. width: w,
  22400. height: h,
  22401. right: r,
  22402. bottom: b
  22403. };
  22404. }
  22405. },
  22406. /**
  22407. * Sets the position of the element in page coordinates, regardless of how the element
  22408. * is positioned. The element must be part of the DOM tree to have page coordinates
  22409. * (`display:none` or elements not appended return false).
  22410. * @param {Number} x X value for new position (coordinates are page-based)
  22411. * @param {Number} y Y value for new position (coordinates are page-based)
  22412. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element
  22413. * animation config object
  22414. * @return {Ext.dom.AbstractElement} this
  22415. */
  22416. setLocation : function(x, y, animate) {
  22417. return this.setXY([x, y], animate);
  22418. },
  22419. /**
  22420. * Sets the position of the element in page coordinates, regardless of how the element
  22421. * is positioned. The element must be part of the DOM tree to have page coordinates
  22422. * (`display:none` or elements not appended return false).
  22423. * @param {Number} x X value for new position (coordinates are page-based)
  22424. * @param {Number} y Y value for new position (coordinates are page-based)
  22425. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element
  22426. * animation config object
  22427. * @return {Ext.dom.AbstractElement} this
  22428. */
  22429. moveTo : function(x, y, animate) {
  22430. return this.setXY([x, y], animate);
  22431. },
  22432. /**
  22433. * Initializes positioning on this element. If a desired position is not passed, it will make the
  22434. * the element positioned relative IF it is not already positioned.
  22435. * @param {String} [pos] Positioning to use "relative", "absolute" or "fixed"
  22436. * @param {Number} [zIndex] The zIndex to apply
  22437. * @param {Number} [x] Set the page X position
  22438. * @param {Number} [y] Set the page Y position
  22439. */
  22440. position : function(pos, zIndex, x, y) {
  22441. var me = this;
  22442. if (!pos && me.isStyle(POSITION, STATIC)) {
  22443. me.setStyle(POSITION, RELATIVE);
  22444. } else if (pos) {
  22445. me.setStyle(POSITION, pos);
  22446. }
  22447. if (zIndex) {
  22448. me.setStyle(ZINDEX, zIndex);
  22449. }
  22450. if (x || y) {
  22451. me.setXY([x || false, y || false]);
  22452. }
  22453. },
  22454. /**
  22455. * Clears positioning back to the default when the document was loaded.
  22456. * @param {String} [value=''] The value to use for the left, right, top, bottom. You could use 'auto'.
  22457. * @return {Ext.dom.AbstractElement} this
  22458. */
  22459. clearPositioning : function(value) {
  22460. value = value || '';
  22461. this.setStyle({
  22462. left : value,
  22463. right : value,
  22464. top : value,
  22465. bottom : value,
  22466. "z-index" : "",
  22467. position : STATIC
  22468. });
  22469. return this;
  22470. },
  22471. /**
  22472. * Gets an object with all CSS positioning properties. Useful along with #setPostioning to get
  22473. * snapshot before performing an update and then restoring the element.
  22474. * @return {Object}
  22475. */
  22476. getPositioning : function(){
  22477. var styles = this.getStyle([LEFT, TOP, POSITION, RIGHT, BOTTOM, ZINDEX]);
  22478. styles[RIGHT] = styles[LEFT] ? '' : styles[RIGHT];
  22479. styles[BOTTOM] = styles[TOP] ? '' : styles[BOTTOM];
  22480. return styles;
  22481. },
  22482. /**
  22483. * Set positioning with an object returned by #getPositioning.
  22484. * @param {Object} posCfg
  22485. * @return {Ext.dom.AbstractElement} this
  22486. */
  22487. setPositioning : function(pc) {
  22488. var me = this,
  22489. style = me.dom.style;
  22490. me.setStyle(pc);
  22491. if (pc.right == AUTO) {
  22492. style.right = "";
  22493. }
  22494. if (pc.bottom == AUTO) {
  22495. style.bottom = "";
  22496. }
  22497. return me;
  22498. },
  22499. /**
  22500. * Move this element relative to its current position.
  22501. * @param {String} direction Possible values are:
  22502. *
  22503. * - `"l"` (or `"left"`)
  22504. * - `"r"` (or `"right"`)
  22505. * - `"t"` (or `"top"`, or `"up"`)
  22506. * - `"b"` (or `"bottom"`, or `"down"`)
  22507. *
  22508. * @param {Number} distance How far to move the element in pixels
  22509. * @param {Boolean/Object} [animate] true for the default animation or a standard Element
  22510. * animation config object
  22511. */
  22512. move: function(direction, distance, animate) {
  22513. var me = this,
  22514. xy = me.getXY(),
  22515. x = xy[0],
  22516. y = xy[1],
  22517. left = [x - distance, y],
  22518. right = [x + distance, y],
  22519. top = [x, y - distance],
  22520. bottom = [x, y + distance],
  22521. hash = {
  22522. l: left,
  22523. left: left,
  22524. r: right,
  22525. right: right,
  22526. t: top,
  22527. top: top,
  22528. up: top,
  22529. b: bottom,
  22530. bottom: bottom,
  22531. down: bottom
  22532. };
  22533. direction = direction.toLowerCase();
  22534. me.moveTo(hash[direction][0], hash[direction][1], animate);
  22535. },
  22536. /**
  22537. * Conveniently sets left and top adding default units.
  22538. * @param {String} left The left CSS property value
  22539. * @param {String} top The top CSS property value
  22540. * @return {Ext.dom.Element} this
  22541. */
  22542. setLeftTop: function(left, top) {
  22543. var style = this.dom.style;
  22544. style.left = Element.addUnits(left);
  22545. style.top = Element.addUnits(top);
  22546. return this;
  22547. },
  22548. /**
  22549. * Returns the region of this element.
  22550. * The element must be part of the DOM tree to have a region
  22551. * (display:none or elements not appended return false).
  22552. * @return {Ext.util.Region} A Region containing "top, left, bottom, right" member data.
  22553. */
  22554. getRegion: function() {
  22555. return this.getPageBox(true);
  22556. },
  22557. /**
  22558. * Returns the **content** region of this element. That is the region within the borders and padding.
  22559. * @return {Ext.util.Region} A Region containing "top, left, bottom, right" member data.
  22560. */
  22561. getViewRegion: function() {
  22562. var me = this,
  22563. isBody = me.dom.nodeName == BODY,
  22564. scroll, pos, top, left, width, height;
  22565. // For the body we want to do some special logic
  22566. if (isBody) {
  22567. scroll = me.getScroll();
  22568. left = scroll.left;
  22569. top = scroll.top;
  22570. width = Ext.dom.AbstractElement.getViewportWidth();
  22571. height = Ext.dom.AbstractElement.getViewportHeight();
  22572. }
  22573. else {
  22574. pos = me.getXY();
  22575. left = pos[0] + me.getBorderWidth('l') + me.getPadding('l');
  22576. top = pos[1] + me.getBorderWidth('t') + me.getPadding('t');
  22577. width = me.getWidth(true);
  22578. height = me.getHeight(true);
  22579. }
  22580. return new Ext.util.Region(top, left + width - 1, top + height - 1, left);
  22581. },
  22582. /**
  22583. * Sets the element's position and size in one shot. If animation is true then width, height,
  22584. * x and y will be animated concurrently.
  22585. *
  22586. * @param {Number} x X value for new position (coordinates are page-based)
  22587. * @param {Number} y Y value for new position (coordinates are page-based)
  22588. * @param {Number/String} width The new width. This may be one of:
  22589. *
  22590. * - A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels)
  22591. * - A String used to set the CSS width style. Animation may **not** be used.
  22592. *
  22593. * @param {Number/String} height The new height. This may be one of:
  22594. *
  22595. * - A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels)
  22596. * - A String used to set the CSS height style. Animation may **not** be used.
  22597. *
  22598. * @param {Boolean/Object} [animate] true for the default animation or a standard Element
  22599. * animation config object
  22600. *
  22601. * @return {Ext.dom.AbstractElement} this
  22602. */
  22603. setBounds: function(x, y, width, height, animate) {
  22604. var me = this;
  22605. if (!animate || !me.anim) {
  22606. me.setSize(width, height);
  22607. me.setLocation(x, y);
  22608. } else {
  22609. if (!Ext.isObject(animate)) {
  22610. animate = {};
  22611. }
  22612. me.animate(Ext.applyIf({
  22613. to: {
  22614. x: x,
  22615. y: y,
  22616. width: me.adjustWidth(width),
  22617. height: me.adjustHeight(height)
  22618. }
  22619. }, animate));
  22620. }
  22621. return me;
  22622. },
  22623. /**
  22624. * Sets the element's position and size the specified region. If animation is true then width, height,
  22625. * x and y will be animated concurrently.
  22626. *
  22627. * @param {Ext.util.Region} region The region to fill
  22628. * @param {Boolean/Object} [animate] true for the default animation or a standard Element
  22629. * animation config object
  22630. * @return {Ext.dom.AbstractElement} this
  22631. */
  22632. setRegion: function(region, animate) {
  22633. return this.setBounds(region.left, region.top, region.right - region.left, region.bottom - region.top, animate);
  22634. }
  22635. });
  22636. }());
  22637. //@tag dom,core
  22638. //@require Ext.dom.Element-position
  22639. //@define Ext.dom.Element-scroll
  22640. //@define Ext.dom.Element
  22641. /**
  22642. * @class Ext.dom.Element
  22643. */
  22644. Ext.dom.Element.override({
  22645. /**
  22646. * Returns true if this element is scrollable.
  22647. * @return {Boolean}
  22648. */
  22649. isScrollable: function() {
  22650. var dom = this.dom;
  22651. return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth;
  22652. },
  22653. /**
  22654. * Returns the current scroll position of the element.
  22655. * @return {Object} An object containing the scroll position in the format
  22656. * `{left: (scrollLeft), top: (scrollTop)}`
  22657. */
  22658. getScroll: function() {
  22659. var d = this.dom,
  22660. doc = document,
  22661. body = doc.body,
  22662. docElement = doc.documentElement,
  22663. l,
  22664. t,
  22665. ret;
  22666. if (d == doc || d == body) {
  22667. if (Ext.isIE && Ext.isStrict) {
  22668. l = docElement.scrollLeft;
  22669. t = docElement.scrollTop;
  22670. } else {
  22671. l = window.pageXOffset;
  22672. t = window.pageYOffset;
  22673. }
  22674. ret = {
  22675. left: l || (body ? body.scrollLeft : 0),
  22676. top : t || (body ? body.scrollTop : 0)
  22677. };
  22678. } else {
  22679. ret = {
  22680. left: d.scrollLeft,
  22681. top : d.scrollTop
  22682. };
  22683. }
  22684. return ret;
  22685. },
  22686. /**
  22687. * Scrolls this element by the passed delta values, optionally animating.
  22688. *
  22689. * All of the following are equivalent:
  22690. *
  22691. * el.scrollBy(10, 10, true);
  22692. * el.scrollBy([10, 10], true);
  22693. * el.scrollBy({ x: 10, y: 10 }, true);
  22694. *
  22695. * @param {Number/Number[]/Object} deltaX Either the x delta, an Array specifying x and y deltas or
  22696. * an object with "x" and "y" properties.
  22697. * @param {Number/Boolean/Object} deltaY Either the y delta, or an animate flag or config object.
  22698. * @param {Boolean/Object} animate Animate flag/config object if the delta values were passed separately.
  22699. * @return {Ext.Element} this
  22700. */
  22701. scrollBy: function(deltaX, deltaY, animate) {
  22702. var me = this,
  22703. dom = me.dom;
  22704. // Extract args if deltas were passed as an Array.
  22705. if (deltaX.length) {
  22706. animate = deltaY;
  22707. deltaY = deltaX[1];
  22708. deltaX = deltaX[0];
  22709. } else if (typeof deltaX != 'number') { // or an object
  22710. animate = deltaY;
  22711. deltaY = deltaX.y;
  22712. deltaX = deltaX.x;
  22713. }
  22714. if (deltaX) {
  22715. me.scrollTo('left', Math.max(Math.min(dom.scrollLeft + deltaX, dom.scrollWidth - dom.clientWidth), 0), animate);
  22716. }
  22717. if (deltaY) {
  22718. me.scrollTo('top', Math.max(Math.min(dom.scrollTop + deltaY, dom.scrollHeight - dom.clientHeight), 0), animate);
  22719. }
  22720. return me;
  22721. },
  22722. /**
  22723. * Scrolls this element the specified scroll point. It does NOT do bounds checking so
  22724. * if you scroll to a weird value it will try to do it. For auto bounds checking, use #scroll.
  22725. * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
  22726. * @param {Number} value The new scroll value
  22727. * @param {Boolean/Object} [animate] true for the default animation or a standard Element
  22728. * animation config object
  22729. * @return {Ext.Element} this
  22730. */
  22731. scrollTo: function(side, value, animate) {
  22732. //check if we're scrolling top or left
  22733. var top = /top/i.test(side),
  22734. me = this,
  22735. dom = me.dom,
  22736. animCfg,
  22737. prop;
  22738. if (!animate || !me.anim) {
  22739. // just setting the value, so grab the direction
  22740. prop = 'scroll' + (top ? 'Top' : 'Left');
  22741. dom[prop] = value;
  22742. // corrects IE, other browsers will ignore
  22743. dom[prop] = value;
  22744. }
  22745. else {
  22746. animCfg = {
  22747. to: {}
  22748. };
  22749. animCfg.to['scroll' + (top ? 'Top' : 'Left')] = value;
  22750. if (Ext.isObject(animate)) {
  22751. Ext.applyIf(animCfg, animate);
  22752. }
  22753. me.animate(animCfg);
  22754. }
  22755. return me;
  22756. },
  22757. /**
  22758. * Scrolls this element into view within the passed container.
  22759. * @param {String/HTMLElement/Ext.Element} [container=document.body] The container element
  22760. * to scroll. Should be a string (id), dom node, or Ext.Element.
  22761. * @param {Boolean} [hscroll=true] False to disable horizontal scroll.
  22762. * @param {Boolean/Object} [animate] true for the default animation or a standard Element
  22763. * animation config object
  22764. * @return {Ext.dom.Element} this
  22765. */
  22766. scrollIntoView: function(container, hscroll, animate) {
  22767. container = Ext.getDom(container) || Ext.getBody().dom;
  22768. var el = this.dom,
  22769. offsets = this.getOffsetsTo(container),
  22770. // el's box
  22771. left = offsets[0] + container.scrollLeft,
  22772. top = offsets[1] + container.scrollTop,
  22773. bottom = top + el.offsetHeight,
  22774. right = left + el.offsetWidth,
  22775. // ct's box
  22776. ctClientHeight = container.clientHeight,
  22777. ctScrollTop = parseInt(container.scrollTop, 10),
  22778. ctScrollLeft = parseInt(container.scrollLeft, 10),
  22779. ctBottom = ctScrollTop + ctClientHeight,
  22780. ctRight = ctScrollLeft + container.clientWidth,
  22781. newPos;
  22782. if (el.offsetHeight > ctClientHeight || top < ctScrollTop) {
  22783. newPos = top;
  22784. } else if (bottom > ctBottom) {
  22785. newPos = bottom - ctClientHeight;
  22786. }
  22787. if (newPos != null) {
  22788. Ext.get(container).scrollTo('top', newPos, animate);
  22789. }
  22790. if (hscroll !== false) {
  22791. newPos = null;
  22792. if (el.offsetWidth > container.clientWidth || left < ctScrollLeft) {
  22793. newPos = left;
  22794. } else if (right > ctRight) {
  22795. newPos = right - container.clientWidth;
  22796. }
  22797. if (newPos != null) {
  22798. Ext.get(container).scrollTo('left', newPos, animate);
  22799. }
  22800. }
  22801. return this;
  22802. },
  22803. // @private
  22804. scrollChildIntoView: function(child, hscroll) {
  22805. Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
  22806. },
  22807. /**
  22808. * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
  22809. * within this element's scrollable range.
  22810. * @param {String} direction Possible values are:
  22811. *
  22812. * - `"l"` (or `"left"`)
  22813. * - `"r"` (or `"right"`)
  22814. * - `"t"` (or `"top"`, or `"up"`)
  22815. * - `"b"` (or `"bottom"`, or `"down"`)
  22816. *
  22817. * @param {Number} distance How far to scroll the element in pixels
  22818. * @param {Boolean/Object} [animate] true for the default animation or a standard Element
  22819. * animation config object
  22820. * @return {Boolean} Returns true if a scroll was triggered or false if the element
  22821. * was scrolled as far as it could go.
  22822. */
  22823. scroll: function(direction, distance, animate) {
  22824. if (!this.isScrollable()) {
  22825. return false;
  22826. }
  22827. var el = this.dom,
  22828. l = el.scrollLeft, t = el.scrollTop,
  22829. w = el.scrollWidth, h = el.scrollHeight,
  22830. cw = el.clientWidth, ch = el.clientHeight,
  22831. scrolled = false, v,
  22832. hash = {
  22833. l: Math.min(l + distance, w - cw),
  22834. r: v = Math.max(l - distance, 0),
  22835. t: Math.max(t - distance, 0),
  22836. b: Math.min(t + distance, h - ch)
  22837. };
  22838. hash.d = hash.b;
  22839. hash.u = hash.t;
  22840. direction = direction.substr(0, 1);
  22841. if ((v = hash[direction]) > -1) {
  22842. scrolled = true;
  22843. this.scrollTo(direction == 'l' || direction == 'r' ? 'left' : 'top', v, this.anim(animate));
  22844. }
  22845. return scrolled;
  22846. }
  22847. });
  22848. //@tag dom,core
  22849. //@require Ext.dom.Element-scroll
  22850. //@define Ext.dom.Element-style
  22851. //@define Ext.dom.Element
  22852. /**
  22853. * @class Ext.dom.Element
  22854. */
  22855. (function() {
  22856. var Element = Ext.dom.Element,
  22857. view = document.defaultView,
  22858. adjustDirect2DTableRe = /table-row|table-.*-group/,
  22859. INTERNAL = '_internal',
  22860. HIDDEN = 'hidden',
  22861. HEIGHT = 'height',
  22862. WIDTH = 'width',
  22863. ISCLIPPED = 'isClipped',
  22864. OVERFLOW = 'overflow',
  22865. OVERFLOWX = 'overflow-x',
  22866. OVERFLOWY = 'overflow-y',
  22867. ORIGINALCLIP = 'originalClip',
  22868. DOCORBODYRE = /#document|body/i,
  22869. // This reduces the lookup of 'me.styleHooks' by one hop in the prototype chain. It is
  22870. // the same object.
  22871. styleHooks,
  22872. edges, k, edge, borderWidth;
  22873. if (!view || !view.getComputedStyle) {
  22874. Element.prototype.getStyle = function (property, inline) {
  22875. var me = this,
  22876. dom = me.dom,
  22877. multiple = typeof property != 'string',
  22878. hooks = me.styleHooks,
  22879. prop = property,
  22880. props = prop,
  22881. len = 1,
  22882. isInline = inline,
  22883. camel, domStyle, values, hook, out, style, i;
  22884. if (multiple) {
  22885. values = {};
  22886. prop = props[0];
  22887. i = 0;
  22888. if (!(len = props.length)) {
  22889. return values;
  22890. }
  22891. }
  22892. if (!dom || dom.documentElement) {
  22893. return values || '';
  22894. }
  22895. domStyle = dom.style;
  22896. if (inline) {
  22897. style = domStyle;
  22898. } else {
  22899. style = dom.currentStyle;
  22900. // fallback to inline style if rendering context not available
  22901. if (!style) {
  22902. isInline = true;
  22903. style = domStyle;
  22904. }
  22905. }
  22906. do {
  22907. hook = hooks[prop];
  22908. if (!hook) {
  22909. hooks[prop] = hook = { name: Element.normalize(prop) };
  22910. }
  22911. if (hook.get) {
  22912. out = hook.get(dom, me, isInline, style);
  22913. } else {
  22914. camel = hook.name;
  22915. // In some cases, IE6 will throw Invalid Argument exceptions for properties
  22916. // like fontSize (/examples/tabs/tabs.html in 4.0 used to exhibit this but
  22917. // no longer does due to font style changes). There is a real cost to a try
  22918. // block, so we avoid it where possible...
  22919. if (hook.canThrow) {
  22920. try {
  22921. out = style[camel];
  22922. } catch (e) {
  22923. out = '';
  22924. }
  22925. } else {
  22926. // EXTJSIV-5657 - In IE9 quirks mode there is a chance that VML root element
  22927. // has neither `currentStyle` nor `style`. Return '' this case.
  22928. out = style ? style[camel] : '';
  22929. }
  22930. }
  22931. if (!multiple) {
  22932. return out;
  22933. }
  22934. values[prop] = out;
  22935. prop = props[++i];
  22936. } while (i < len);
  22937. return values;
  22938. };
  22939. }
  22940. Element.override({
  22941. getHeight: function(contentHeight, preciseHeight) {
  22942. var me = this,
  22943. dom = me.dom,
  22944. hidden = me.isStyle('display', 'none'),
  22945. height,
  22946. floating;
  22947. if (hidden) {
  22948. return 0;
  22949. }
  22950. height = Math.max(dom.offsetHeight, dom.clientHeight) || 0;
  22951. // IE9 Direct2D dimension rounding bug
  22952. if (Ext.supports.Direct2DBug) {
  22953. floating = me.adjustDirect2DDimension(HEIGHT);
  22954. if (preciseHeight) {
  22955. height += floating;
  22956. }
  22957. else if (floating > 0 && floating < 0.5) {
  22958. height++;
  22959. }
  22960. }
  22961. if (contentHeight) {
  22962. height -= me.getBorderWidth("tb") + me.getPadding("tb");
  22963. }
  22964. return (height < 0) ? 0 : height;
  22965. },
  22966. getWidth: function(contentWidth, preciseWidth) {
  22967. var me = this,
  22968. dom = me.dom,
  22969. hidden = me.isStyle('display', 'none'),
  22970. rect, width, floating;
  22971. if (hidden) {
  22972. return 0;
  22973. }
  22974. // Gecko will in some cases report an offsetWidth that is actually less than the width of the
  22975. // text contents, because it measures fonts with sub-pixel precision but rounds the calculated
  22976. // value down. Using getBoundingClientRect instead of offsetWidth allows us to get the precise
  22977. // subpixel measurements so we can force them to always be rounded up. See
  22978. // https://bugzilla.mozilla.org/show_bug.cgi?id=458617
  22979. // Rounding up ensures that the width includes the full width of the text contents.
  22980. if (Ext.supports.BoundingClientRect) {
  22981. rect = dom.getBoundingClientRect();
  22982. width = rect.right - rect.left;
  22983. width = preciseWidth ? width : Math.ceil(width);
  22984. } else {
  22985. width = dom.offsetWidth;
  22986. }
  22987. width = Math.max(width, dom.clientWidth) || 0;
  22988. // IE9 Direct2D dimension rounding bug
  22989. if (Ext.supports.Direct2DBug) {
  22990. // get the fractional portion of the sub-pixel precision width of the element's text contents
  22991. floating = me.adjustDirect2DDimension(WIDTH);
  22992. if (preciseWidth) {
  22993. width += floating;
  22994. }
  22995. // IE9 also measures fonts with sub-pixel precision, but unlike Gecko, instead of rounding the offsetWidth down,
  22996. // it rounds to the nearest integer. This means that in order to ensure that the width includes the full
  22997. // width of the text contents we need to increment the width by 1 only if the fractional portion is less than 0.5
  22998. else if (floating > 0 && floating < 0.5) {
  22999. width++;
  23000. }
  23001. }
  23002. if (contentWidth) {
  23003. width -= me.getBorderWidth("lr") + me.getPadding("lr");
  23004. }
  23005. return (width < 0) ? 0 : width;
  23006. },
  23007. setWidth: function(width, animate) {
  23008. var me = this;
  23009. width = me.adjustWidth(width);
  23010. if (!animate || !me.anim) {
  23011. me.dom.style.width = me.addUnits(width);
  23012. }
  23013. else {
  23014. if (!Ext.isObject(animate)) {
  23015. animate = {};
  23016. }
  23017. me.animate(Ext.applyIf({
  23018. to: {
  23019. width: width
  23020. }
  23021. }, animate));
  23022. }
  23023. return me;
  23024. },
  23025. setHeight : function(height, animate) {
  23026. var me = this;
  23027. height = me.adjustHeight(height);
  23028. if (!animate || !me.anim) {
  23029. me.dom.style.height = me.addUnits(height);
  23030. }
  23031. else {
  23032. if (!Ext.isObject(animate)) {
  23033. animate = {};
  23034. }
  23035. me.animate(Ext.applyIf({
  23036. to: {
  23037. height: height
  23038. }
  23039. }, animate));
  23040. }
  23041. return me;
  23042. },
  23043. applyStyles: function(style) {
  23044. Ext.DomHelper.applyStyles(this.dom, style);
  23045. return this;
  23046. },
  23047. setSize: function(width, height, animate) {
  23048. var me = this;
  23049. if (Ext.isObject(width)) { // in case of object from getSize()
  23050. animate = height;
  23051. height = width.height;
  23052. width = width.width;
  23053. }
  23054. width = me.adjustWidth(width);
  23055. height = me.adjustHeight(height);
  23056. if (!animate || !me.anim) {
  23057. me.dom.style.width = me.addUnits(width);
  23058. me.dom.style.height = me.addUnits(height);
  23059. }
  23060. else {
  23061. if (animate === true) {
  23062. animate = {};
  23063. }
  23064. me.animate(Ext.applyIf({
  23065. to: {
  23066. width: width,
  23067. height: height
  23068. }
  23069. }, animate));
  23070. }
  23071. return me;
  23072. },
  23073. getViewSize : function() {
  23074. var me = this,
  23075. dom = me.dom,
  23076. isDoc = DOCORBODYRE.test(dom.nodeName),
  23077. ret;
  23078. // If the body, use static methods
  23079. if (isDoc) {
  23080. ret = {
  23081. width : Element.getViewWidth(),
  23082. height : Element.getViewHeight()
  23083. };
  23084. } else {
  23085. ret = {
  23086. width : dom.clientWidth,
  23087. height : dom.clientHeight
  23088. };
  23089. }
  23090. return ret;
  23091. },
  23092. getSize: function(contentSize) {
  23093. return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
  23094. },
  23095. // TODO: Look at this
  23096. // private ==> used by Fx
  23097. adjustWidth : function(width) {
  23098. var me = this,
  23099. isNum = (typeof width == 'number');
  23100. if (isNum && me.autoBoxAdjust && !me.isBorderBox()) {
  23101. width -= (me.getBorderWidth("lr") + me.getPadding("lr"));
  23102. }
  23103. return (isNum && width < 0) ? 0 : width;
  23104. },
  23105. // private ==> used by Fx
  23106. adjustHeight : function(height) {
  23107. var me = this,
  23108. isNum = (typeof height == "number");
  23109. if (isNum && me.autoBoxAdjust && !me.isBorderBox()) {
  23110. height -= (me.getBorderWidth("tb") + me.getPadding("tb"));
  23111. }
  23112. return (isNum && height < 0) ? 0 : height;
  23113. },
  23114. /**
  23115. * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like `#fff`) and valid values
  23116. * are convert to standard 6 digit hex color.
  23117. * @param {String} attr The css attribute
  23118. * @param {String} defaultValue The default value to use when a valid color isn't found
  23119. * @param {String} [prefix] defaults to #. Use an empty string when working with
  23120. * color anims.
  23121. */
  23122. getColor : function(attr, defaultValue, prefix) {
  23123. var v = this.getStyle(attr),
  23124. color = prefix || prefix === '' ? prefix : '#',
  23125. h, len, i=0;
  23126. if (!v || (/transparent|inherit/.test(v))) {
  23127. return defaultValue;
  23128. }
  23129. if (/^r/.test(v)) {
  23130. v = v.slice(4, v.length - 1).split(',');
  23131. len = v.length;
  23132. for (; i<len; i++) {
  23133. h = parseInt(v[i], 10);
  23134. color += (h < 16 ? '0' : '') + h.toString(16);
  23135. }
  23136. } else {
  23137. v = v.replace('#', '');
  23138. color += v.length == 3 ? v.replace(/^(\w)(\w)(\w)$/, '$1$1$2$2$3$3') : v;
  23139. }
  23140. return(color.length > 5 ? color.toLowerCase() : defaultValue);
  23141. },
  23142. /**
  23143. * Set the opacity of the element
  23144. * @param {Number} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
  23145. * @param {Boolean/Object} [animate] a standard Element animation config object or `true` for
  23146. * the default animation (`{duration: 350, easing: 'easeIn'}`)
  23147. * @return {Ext.dom.Element} this
  23148. */
  23149. setOpacity: function(opacity, animate) {
  23150. var me = this;
  23151. if (!me.dom) {
  23152. return me;
  23153. }
  23154. if (!animate || !me.anim) {
  23155. me.setStyle('opacity', opacity);
  23156. }
  23157. else {
  23158. if (typeof animate != 'object') {
  23159. animate = {
  23160. duration: 350,
  23161. easing: 'ease-in'
  23162. };
  23163. }
  23164. me.animate(Ext.applyIf({
  23165. to: {
  23166. opacity: opacity
  23167. }
  23168. }, animate));
  23169. }
  23170. return me;
  23171. },
  23172. /**
  23173. * Clears any opacity settings from this element. Required in some cases for IE.
  23174. * @return {Ext.dom.Element} this
  23175. */
  23176. clearOpacity : function() {
  23177. return this.setOpacity('');
  23178. },
  23179. /**
  23180. * @private
  23181. * Returns 1 if the browser returns the subpixel dimension rounded to the lowest pixel.
  23182. * @return {Number} 0 or 1
  23183. */
  23184. adjustDirect2DDimension: function(dimension) {
  23185. var me = this,
  23186. dom = me.dom,
  23187. display = me.getStyle('display'),
  23188. inlineDisplay = dom.style.display,
  23189. inlinePosition = dom.style.position,
  23190. originIndex = dimension === WIDTH ? 0 : 1,
  23191. currentStyle = dom.currentStyle,
  23192. floating;
  23193. if (display === 'inline') {
  23194. dom.style.display = 'inline-block';
  23195. }
  23196. dom.style.position = display.match(adjustDirect2DTableRe) ? 'absolute' : 'static';
  23197. // floating will contain digits that appears after the decimal point
  23198. // if height or width are set to auto we fallback to msTransformOrigin calculation
  23199. // Use currentStyle here instead of getStyle. In some difficult to reproduce
  23200. // instances it resets the scrollWidth of the element
  23201. floating = (parseFloat(currentStyle[dimension]) || parseFloat(currentStyle.msTransformOrigin.split(' ')[originIndex]) * 2) % 1;
  23202. dom.style.position = inlinePosition;
  23203. if (display === 'inline') {
  23204. dom.style.display = inlineDisplay;
  23205. }
  23206. return floating;
  23207. },
  23208. /**
  23209. * Store the current overflow setting and clip overflow on the element - use {@link #unclip} to remove
  23210. * @return {Ext.dom.Element} this
  23211. */
  23212. clip : function() {
  23213. var me = this,
  23214. data = (me.$cache || me.getCache()).data,
  23215. style;
  23216. if (!data[ISCLIPPED]) {
  23217. data[ISCLIPPED] = true;
  23218. style = me.getStyle([OVERFLOW, OVERFLOWX, OVERFLOWY]);
  23219. data[ORIGINALCLIP] = {
  23220. o: style[OVERFLOW],
  23221. x: style[OVERFLOWX],
  23222. y: style[OVERFLOWY]
  23223. };
  23224. me.setStyle(OVERFLOW, HIDDEN);
  23225. me.setStyle(OVERFLOWX, HIDDEN);
  23226. me.setStyle(OVERFLOWY, HIDDEN);
  23227. }
  23228. return me;
  23229. },
  23230. /**
  23231. * Return clipping (overflow) to original clipping before {@link #clip} was called
  23232. * @return {Ext.dom.Element} this
  23233. */
  23234. unclip : function() {
  23235. var me = this,
  23236. data = (me.$cache || me.getCache()).data,
  23237. clip;
  23238. if (data[ISCLIPPED]) {
  23239. data[ISCLIPPED] = false;
  23240. clip = data[ORIGINALCLIP];
  23241. if (clip.o) {
  23242. me.setStyle(OVERFLOW, clip.o);
  23243. }
  23244. if (clip.x) {
  23245. me.setStyle(OVERFLOWX, clip.x);
  23246. }
  23247. if (clip.y) {
  23248. me.setStyle(OVERFLOWY, clip.y);
  23249. }
  23250. }
  23251. return me;
  23252. },
  23253. /**
  23254. * Wraps the specified element with a special 9 element markup/CSS block that renders by default as
  23255. * a gray container with a gradient background, rounded corners and a 4-way shadow.
  23256. *
  23257. * This special markup is used throughout Ext when box wrapping elements ({@link Ext.button.Button},
  23258. * {@link Ext.panel.Panel} when {@link Ext.panel.Panel#frame frame=true}, {@link Ext.window.Window}).
  23259. * The markup is of this form:
  23260. *
  23261. * Ext.dom.Element.boxMarkup =
  23262. * '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div>
  23263. * <div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div>
  23264. * <div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
  23265. *
  23266. * Example usage:
  23267. *
  23268. * // Basic box wrap
  23269. * Ext.get("foo").boxWrap();
  23270. *
  23271. * // You can also add a custom class and use CSS inheritance rules to customize the box look.
  23272. * // 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example
  23273. * // for how to create a custom box wrap style.
  23274. * Ext.get("foo").boxWrap().addCls("x-box-blue");
  23275. *
  23276. * @param {String} [class='x-box'] A base CSS class to apply to the containing wrapper element.
  23277. * Note that there are a number of CSS rules that are dependent on this name to make the overall effect work,
  23278. * so if you supply an alternate base class, make sure you also supply all of the necessary rules.
  23279. * @return {Ext.dom.Element} The outermost wrapping element of the created box structure.
  23280. */
  23281. boxWrap : function(cls) {
  23282. cls = cls || Ext.baseCSSPrefix + 'box';
  23283. var el = Ext.get(this.insertHtml("beforeBegin", "<div class='" + cls + "'>" + Ext.String.format(Element.boxMarkup, cls) + "</div>"));
  23284. Ext.DomQuery.selectNode('.' + cls + '-mc', el.dom).appendChild(this.dom);
  23285. return el;
  23286. },
  23287. /**
  23288. * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
  23289. * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
  23290. * if a height has not been set using CSS.
  23291. * @return {Number}
  23292. */
  23293. getComputedHeight : function() {
  23294. var me = this,
  23295. h = Math.max(me.dom.offsetHeight, me.dom.clientHeight);
  23296. if (!h) {
  23297. h = parseFloat(me.getStyle(HEIGHT)) || 0;
  23298. if (!me.isBorderBox()) {
  23299. h += me.getFrameWidth('tb');
  23300. }
  23301. }
  23302. return h;
  23303. },
  23304. /**
  23305. * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
  23306. * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
  23307. * if a width has not been set using CSS.
  23308. * @return {Number}
  23309. */
  23310. getComputedWidth : function() {
  23311. var me = this,
  23312. w = Math.max(me.dom.offsetWidth, me.dom.clientWidth);
  23313. if (!w) {
  23314. w = parseFloat(me.getStyle(WIDTH)) || 0;
  23315. if (!me.isBorderBox()) {
  23316. w += me.getFrameWidth('lr');
  23317. }
  23318. }
  23319. return w;
  23320. },
  23321. /**
  23322. * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
  23323. * for more information about the sides.
  23324. * @param {String} sides
  23325. * @return {Number}
  23326. */
  23327. getFrameWidth : function(sides, onlyContentBox) {
  23328. return (onlyContentBox && this.isBorderBox()) ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
  23329. },
  23330. /**
  23331. * Sets up event handlers to add and remove a css class when the mouse is over this element
  23332. * @param {String} className The class to add
  23333. * @param {Function} [testFn] A test function to execute before adding the class. The passed parameter
  23334. * will be the Element instance. If this functions returns false, the class will not be added.
  23335. * @param {Object} [scope] The scope to execute the testFn in.
  23336. * @return {Ext.dom.Element} this
  23337. */
  23338. addClsOnOver : function(className, testFn, scope) {
  23339. var me = this,
  23340. dom = me.dom,
  23341. hasTest = Ext.isFunction(testFn);
  23342. me.hover(
  23343. function() {
  23344. if (hasTest && testFn.call(scope || me, me) === false) {
  23345. return;
  23346. }
  23347. Ext.fly(dom, INTERNAL).addCls(className);
  23348. },
  23349. function() {
  23350. Ext.fly(dom, INTERNAL).removeCls(className);
  23351. }
  23352. );
  23353. return me;
  23354. },
  23355. /**
  23356. * Sets up event handlers to add and remove a css class when this element has the focus
  23357. * @param {String} className The class to add
  23358. * @param {Function} [testFn] A test function to execute before adding the class. The passed parameter
  23359. * will be the Element instance. If this functions returns false, the class will not be added.
  23360. * @param {Object} [scope] The scope to execute the testFn in.
  23361. * @return {Ext.dom.Element} this
  23362. */
  23363. addClsOnFocus : function(className, testFn, scope) {
  23364. var me = this,
  23365. dom = me.dom,
  23366. hasTest = Ext.isFunction(testFn);
  23367. me.on("focus", function() {
  23368. if (hasTest && testFn.call(scope || me, me) === false) {
  23369. return false;
  23370. }
  23371. Ext.fly(dom, INTERNAL).addCls(className);
  23372. });
  23373. me.on("blur", function() {
  23374. Ext.fly(dom, INTERNAL).removeCls(className);
  23375. });
  23376. return me;
  23377. },
  23378. /**
  23379. * Sets up event handlers to add and remove a css class when the mouse is down and then up on this element (a click effect)
  23380. * @param {String} className The class to add
  23381. * @param {Function} [testFn] A test function to execute before adding the class. The passed parameter
  23382. * will be the Element instance. If this functions returns false, the class will not be added.
  23383. * @param {Object} [scope] The scope to execute the testFn in.
  23384. * @return {Ext.dom.Element} this
  23385. */
  23386. addClsOnClick : function(className, testFn, scope) {
  23387. var me = this,
  23388. dom = me.dom,
  23389. hasTest = Ext.isFunction(testFn);
  23390. me.on("mousedown", function() {
  23391. if (hasTest && testFn.call(scope || me, me) === false) {
  23392. return false;
  23393. }
  23394. Ext.fly(dom, INTERNAL).addCls(className);
  23395. var d = Ext.getDoc(),
  23396. fn = function() {
  23397. Ext.fly(dom, INTERNAL).removeCls(className);
  23398. d.removeListener("mouseup", fn);
  23399. };
  23400. d.on("mouseup", fn);
  23401. });
  23402. return me;
  23403. },
  23404. /**
  23405. * Returns the dimensions of the element available to lay content out in.
  23406. *
  23407. * getStyleSize utilizes prefers style sizing if present, otherwise it chooses the larger of offsetHeight/clientHeight and
  23408. * offsetWidth/clientWidth. To obtain the size excluding scrollbars, use getViewSize.
  23409. *
  23410. * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
  23411. *
  23412. * @return {Object} Object describing width and height.
  23413. * @return {Number} return.width
  23414. * @return {Number} return.height
  23415. */
  23416. getStyleSize : function() {
  23417. var me = this,
  23418. d = this.dom,
  23419. isDoc = DOCORBODYRE.test(d.nodeName),
  23420. s ,
  23421. w, h;
  23422. // If the body, use static methods
  23423. if (isDoc) {
  23424. return {
  23425. width : Element.getViewWidth(),
  23426. height : Element.getViewHeight()
  23427. };
  23428. }
  23429. s = me.getStyle([HEIGHT, WIDTH], true); //seek inline
  23430. // Use Styles if they are set
  23431. if (s.width && s.width != 'auto') {
  23432. w = parseFloat(s.width);
  23433. if (me.isBorderBox()) {
  23434. w -= me.getFrameWidth('lr');
  23435. }
  23436. }
  23437. // Use Styles if they are set
  23438. if (s.height && s.height != 'auto') {
  23439. h = parseFloat(s.height);
  23440. if (me.isBorderBox()) {
  23441. h -= me.getFrameWidth('tb');
  23442. }
  23443. }
  23444. // Use getWidth/getHeight if style not set.
  23445. return {width: w || me.getWidth(true), height: h || me.getHeight(true)};
  23446. },
  23447. /**
  23448. * Enable text selection for this element (normalized across browsers)
  23449. * @return {Ext.Element} this
  23450. */
  23451. selectable : function() {
  23452. var me = this;
  23453. me.dom.unselectable = "off";
  23454. // Prevent it from bubles up and enables it to be selectable
  23455. me.on('selectstart', function (e) {
  23456. e.stopPropagation();
  23457. return true;
  23458. });
  23459. me.applyStyles("-moz-user-select: text; -khtml-user-select: text;");
  23460. me.removeCls(Ext.baseCSSPrefix + 'unselectable');
  23461. return me;
  23462. },
  23463. /**
  23464. * Disables text selection for this element (normalized across browsers)
  23465. * @return {Ext.dom.Element} this
  23466. */
  23467. unselectable : function() {
  23468. var me = this;
  23469. me.dom.unselectable = "on";
  23470. me.swallowEvent("selectstart", true);
  23471. me.applyStyles("-moz-user-select:-moz-none;-khtml-user-select:none;");
  23472. me.addCls(Ext.baseCSSPrefix + 'unselectable');
  23473. return me;
  23474. }
  23475. });
  23476. Element.prototype.styleHooks = styleHooks = Ext.dom.AbstractElement.prototype.styleHooks;
  23477. if (Ext.isIE6 || Ext.isIE7) {
  23478. styleHooks.fontSize = styleHooks['font-size'] = {
  23479. name: 'fontSize',
  23480. canThrow: true
  23481. };
  23482. styleHooks.fontStyle = styleHooks['font-style'] = {
  23483. name: 'fontStyle',
  23484. canThrow: true
  23485. };
  23486. styleHooks.fontFamily = styleHooks['font-family'] = {
  23487. name: 'fontFamily',
  23488. canThrow: true
  23489. };
  23490. }
  23491. // override getStyle for border-*-width
  23492. if (Ext.isIEQuirks || Ext.isIE && Ext.ieVersion <= 8) {
  23493. function getBorderWidth (dom, el, inline, style) {
  23494. if (style[this.styleName] == 'none') {
  23495. return '0px';
  23496. }
  23497. return style[this.name];
  23498. }
  23499. edges = ['Top','Right','Bottom','Left'];
  23500. k = edges.length;
  23501. while (k--) {
  23502. edge = edges[k];
  23503. borderWidth = 'border' + edge + 'Width';
  23504. styleHooks['border-'+edge.toLowerCase()+'-width'] = styleHooks[borderWidth] = {
  23505. name: borderWidth,
  23506. styleName: 'border' + edge + 'Style',
  23507. get: getBorderWidth
  23508. };
  23509. }
  23510. }
  23511. }());
  23512. Ext.onReady(function () {
  23513. var opacityRe = /alpha\(opacity=(.*)\)/i,
  23514. trimRe = /^\s+|\s+$/g,
  23515. hooks = Ext.dom.Element.prototype.styleHooks;
  23516. // Ext.supports flags are not populated until onReady...
  23517. hooks.opacity = {
  23518. name: 'opacity',
  23519. afterSet: function(dom, value, el) {
  23520. if (el.isLayer) {
  23521. el.onOpacitySet(value);
  23522. }
  23523. }
  23524. };
  23525. if (!Ext.supports.Opacity && Ext.isIE) {
  23526. Ext.apply(hooks.opacity, {
  23527. get: function (dom) {
  23528. var filter = dom.style.filter,
  23529. match, opacity;
  23530. if (filter.match) {
  23531. match = filter.match(opacityRe);
  23532. if (match) {
  23533. opacity = parseFloat(match[1]);
  23534. if (!isNaN(opacity)) {
  23535. return opacity ? opacity / 100 : 0;
  23536. }
  23537. }
  23538. }
  23539. return 1;
  23540. },
  23541. set: function (dom, value) {
  23542. var style = dom.style,
  23543. val = style.filter.replace(opacityRe, '').replace(trimRe, '');
  23544. style.zoom = 1; // ensure dom.hasLayout
  23545. // value can be a number or '' or null... so treat falsey as no opacity
  23546. if (typeof(value) == 'number' && value >= 0 && value < 1) {
  23547. value *= 100;
  23548. style.filter = val + (val.length ? ' ' : '') + 'alpha(opacity='+value+')';
  23549. } else {
  23550. style.filter = val;
  23551. }
  23552. }
  23553. });
  23554. }
  23555. // else there is no work around for the lack of opacity support. Should not be a
  23556. // problem given that this has been supported for a long time now...
  23557. });
  23558. //@tag dom,core
  23559. //@require Ext.dom.Element-style
  23560. //@define Ext.dom.Element-traversal
  23561. //@define Ext.dom.Element
  23562. /**
  23563. * @class Ext.dom.Element
  23564. */
  23565. Ext.dom.Element.override({
  23566. select: function(selector) {
  23567. return Ext.dom.Element.select(selector, false, this.dom);
  23568. }
  23569. });
  23570. //@tag dom,core
  23571. //@require Ext.dom.Element-traversal
  23572. /**
  23573. * This class encapsulates a *collection* of DOM elements, providing methods to filter members, or to perform collective
  23574. * actions upon the whole set.
  23575. *
  23576. * Although they are not listed, this class supports all of the methods of {@link Ext.dom.Element} and
  23577. * {@link Ext.fx.Anim}. The methods from these classes will be performed on all the elements in this collection.
  23578. *
  23579. * Example:
  23580. *
  23581. * var els = Ext.select("#some-el div.some-class");
  23582. * // or select directly from an existing element
  23583. * var el = Ext.get('some-el');
  23584. * el.select('div.some-class');
  23585. *
  23586. * els.setWidth(100); // all elements become 100 width
  23587. * els.hide(true); // all elements fade out and hide
  23588. * // or
  23589. * els.setWidth(100).hide(true);
  23590. */
  23591. Ext.define('Ext.dom.CompositeElementLite', {
  23592. alternateClassName: 'Ext.CompositeElementLite',
  23593. requires: ['Ext.dom.Element', 'Ext.dom.Query'],
  23594. statics: {
  23595. /**
  23596. * @private
  23597. * Copies all of the functions from Ext.dom.Element's prototype onto CompositeElementLite's prototype.
  23598. * This is called twice - once immediately below, and once again after additional Ext.dom.Element
  23599. * are added in Ext JS
  23600. */
  23601. importElementMethods: function() {
  23602. var name,
  23603. elementPrototype = Ext.dom.Element.prototype,
  23604. prototype = this.prototype;
  23605. for (name in elementPrototype) {
  23606. if (typeof elementPrototype[name] == 'function'){
  23607. (function(key) {
  23608. prototype[key] = prototype[key] || function() {
  23609. return this.invoke(key, arguments);
  23610. };
  23611. }).call(prototype, name);
  23612. }
  23613. }
  23614. }
  23615. },
  23616. constructor: function(elements, root) {
  23617. /**
  23618. * @property {HTMLElement[]} elements
  23619. * The Array of DOM elements which this CompositeElement encapsulates.
  23620. *
  23621. * This will not *usually* be accessed in developers' code, but developers wishing to augment the capabilities
  23622. * of the CompositeElementLite class may use it when adding methods to the class.
  23623. *
  23624. * For example to add the `nextAll` method to the class to **add** all following siblings of selected elements,
  23625. * the code would be
  23626. *
  23627. * Ext.override(Ext.dom.CompositeElementLite, {
  23628. * nextAll: function() {
  23629. * var elements = this.elements, i, l = elements.length, n, r = [], ri = -1;
  23630. *
  23631. * // Loop through all elements in this Composite, accumulating
  23632. * // an Array of all siblings.
  23633. * for (i = 0; i < l; i++) {
  23634. * for (n = elements[i].nextSibling; n; n = n.nextSibling) {
  23635. * r[++ri] = n;
  23636. * }
  23637. * }
  23638. *
  23639. * // Add all found siblings to this Composite
  23640. * return this.add(r);
  23641. * }
  23642. * });
  23643. *
  23644. * @readonly
  23645. */
  23646. this.elements = [];
  23647. this.add(elements, root);
  23648. this.el = new Ext.dom.AbstractElement.Fly();
  23649. },
  23650. /**
  23651. * @property {Boolean} isComposite
  23652. * `true` in this class to identify an object as an instantiated CompositeElement, or subclass thereof.
  23653. */
  23654. isComposite: true,
  23655. // private
  23656. getElement: function(el) {
  23657. // Set the shared flyweight dom property to the current element
  23658. return this.el.attach(el);
  23659. },
  23660. // private
  23661. transformElement: function(el) {
  23662. return Ext.getDom(el);
  23663. },
  23664. /**
  23665. * Returns the number of elements in this Composite.
  23666. * @return {Number}
  23667. */
  23668. getCount: function() {
  23669. return this.elements.length;
  23670. },
  23671. /**
  23672. * Adds elements to this Composite object.
  23673. * @param {HTMLElement[]/Ext.dom.CompositeElement} els Either an Array of DOM elements to add, or another Composite
  23674. * object who's elements should be added.
  23675. * @return {Ext.dom.CompositeElement} This Composite object.
  23676. */
  23677. add: function(els, root) {
  23678. var elements = this.elements,
  23679. i, ln;
  23680. if (!els) {
  23681. return this;
  23682. }
  23683. if (typeof els == "string") {
  23684. els = Ext.dom.Element.selectorFunction(els, root);
  23685. }
  23686. else if (els.isComposite) {
  23687. els = els.elements;
  23688. }
  23689. else if (!Ext.isIterable(els)) {
  23690. els = [els];
  23691. }
  23692. for (i = 0, ln = els.length; i < ln; ++i) {
  23693. elements.push(this.transformElement(els[i]));
  23694. }
  23695. return this;
  23696. },
  23697. invoke: function(fn, args) {
  23698. var elements = this.elements,
  23699. ln = elements.length,
  23700. element,
  23701. i;
  23702. fn = Ext.dom.Element.prototype[fn];
  23703. for (i = 0; i < ln; i++) {
  23704. element = elements[i];
  23705. if (element) {
  23706. fn.apply(this.getElement(element), args);
  23707. }
  23708. }
  23709. return this;
  23710. },
  23711. /**
  23712. * Returns a flyweight Element of the dom element object at the specified index
  23713. * @param {Number} index
  23714. * @return {Ext.dom.Element}
  23715. */
  23716. item: function(index) {
  23717. var el = this.elements[index],
  23718. out = null;
  23719. if (el) {
  23720. out = this.getElement(el);
  23721. }
  23722. return out;
  23723. },
  23724. // fixes scope with flyweight
  23725. addListener: function(eventName, handler, scope, opt) {
  23726. var els = this.elements,
  23727. len = els.length,
  23728. i, e;
  23729. for (i = 0; i < len; i++) {
  23730. e = els[i];
  23731. if (e) {
  23732. Ext.EventManager.on(e, eventName, handler, scope || e, opt);
  23733. }
  23734. }
  23735. return this;
  23736. },
  23737. /**
  23738. * Calls the passed function for each element in this composite.
  23739. * @param {Function} fn The function to call.
  23740. * @param {Ext.dom.Element} fn.el The current Element in the iteration. **This is the flyweight
  23741. * (shared) Ext.dom.Element instance, so if you require a a reference to the dom node, use el.dom.**
  23742. * @param {Ext.dom.CompositeElement} fn.c This Composite object.
  23743. * @param {Number} fn.index The zero-based index in the iteration.
  23744. * @param {Object} [scope] The scope (this reference) in which the function is executed.
  23745. * Defaults to the Element.
  23746. * @return {Ext.dom.CompositeElement} this
  23747. */
  23748. each: function(fn, scope) {
  23749. var me = this,
  23750. els = me.elements,
  23751. len = els.length,
  23752. i, e;
  23753. for (i = 0; i < len; i++) {
  23754. e = els[i];
  23755. if (e) {
  23756. e = this.getElement(e);
  23757. if (fn.call(scope || e, e, me, i) === false) {
  23758. break;
  23759. }
  23760. }
  23761. }
  23762. return me;
  23763. },
  23764. /**
  23765. * Clears this Composite and adds the elements passed.
  23766. * @param {HTMLElement[]/Ext.dom.CompositeElement} els Either an array of DOM elements, or another Composite from which
  23767. * to fill this Composite.
  23768. * @return {Ext.dom.CompositeElement} this
  23769. */
  23770. fill: function(els) {
  23771. var me = this;
  23772. me.elements = [];
  23773. me.add(els);
  23774. return me;
  23775. },
  23776. /**
  23777. * Filters this composite to only elements that match the passed selector.
  23778. * @param {String/Function} selector A string CSS selector or a comparison function. The comparison function will be
  23779. * called with the following arguments:
  23780. * @param {Ext.dom.Element} selector.el The current DOM element.
  23781. * @param {Number} selector.index The current index within the collection.
  23782. * @return {Ext.dom.CompositeElement} this
  23783. */
  23784. filter: function(selector) {
  23785. var me = this,
  23786. els = me.elements,
  23787. len = els.length,
  23788. out = [],
  23789. i = 0,
  23790. isFunc = typeof selector == 'function',
  23791. add,
  23792. el;
  23793. for (; i < len; i++) {
  23794. el = els[i];
  23795. add = false;
  23796. if (el) {
  23797. el = me.getElement(el);
  23798. if (isFunc) {
  23799. add = selector.call(el, el, me, i) !== false;
  23800. } else {
  23801. add = el.is(selector);
  23802. }
  23803. if (add) {
  23804. out.push(me.transformElement(el));
  23805. }
  23806. }
  23807. }
  23808. me.elements = out;
  23809. return me;
  23810. },
  23811. /**
  23812. * Find the index of the passed element within the composite collection.
  23813. * @param {String/HTMLElement/Ext.Element/Number} el The id of an element, or an Ext.dom.Element, or an HtmlElement
  23814. * to find within the composite collection.
  23815. * @return {Number} The index of the passed Ext.dom.Element in the composite collection, or -1 if not found.
  23816. */
  23817. indexOf: function(el) {
  23818. return Ext.Array.indexOf(this.elements, this.transformElement(el));
  23819. },
  23820. /**
  23821. * Replaces the specified element with the passed element.
  23822. * @param {String/HTMLElement/Ext.Element/Number} el The id of an element, the Element itself, the index of the
  23823. * element in this composite to replace.
  23824. * @param {String/Ext.Element} replacement The id of an element or the Element itself.
  23825. * @param {Boolean} [domReplace] True to remove and replace the element in the document too.
  23826. * @return {Ext.dom.CompositeElement} this
  23827. */
  23828. replaceElement: function(el, replacement, domReplace) {
  23829. var index = !isNaN(el) ? el : this.indexOf(el),
  23830. d;
  23831. if (index > -1) {
  23832. replacement = Ext.getDom(replacement);
  23833. if (domReplace) {
  23834. d = this.elements[index];
  23835. d.parentNode.insertBefore(replacement, d);
  23836. Ext.removeNode(d);
  23837. }
  23838. Ext.Array.splice(this.elements, index, 1, replacement);
  23839. }
  23840. return this;
  23841. },
  23842. /**
  23843. * Removes all elements.
  23844. */
  23845. clear: function() {
  23846. this.elements = [];
  23847. },
  23848. addElements: function(els, root) {
  23849. if (!els) {
  23850. return this;
  23851. }
  23852. if (typeof els == "string") {
  23853. els = Ext.dom.Element.selectorFunction(els, root);
  23854. }
  23855. var yels = this.elements,
  23856. eLen = els.length,
  23857. e;
  23858. for (e = 0; e < eLen; e++) {
  23859. yels.push(Ext.get(els[e]));
  23860. }
  23861. return this;
  23862. },
  23863. /**
  23864. * Returns the first Element
  23865. * @return {Ext.dom.Element}
  23866. */
  23867. first: function() {
  23868. return this.item(0);
  23869. },
  23870. /**
  23871. * Returns the last Element
  23872. * @return {Ext.dom.Element}
  23873. */
  23874. last: function() {
  23875. return this.item(this.getCount() - 1);
  23876. },
  23877. /**
  23878. * Returns true if this composite contains the passed element
  23879. * @param {String/HTMLElement/Ext.Element/Number} el The id of an element, or an Ext.Element, or an HtmlElement to
  23880. * find within the composite collection.
  23881. * @return {Boolean}
  23882. */
  23883. contains: function(el) {
  23884. return this.indexOf(el) != -1;
  23885. },
  23886. /**
  23887. * Removes the specified element(s).
  23888. * @param {String/HTMLElement/Ext.Element/Number} el The id of an element, the Element itself, the index of the
  23889. * element in this composite or an array of any of those.
  23890. * @param {Boolean} [removeDom] True to also remove the element from the document
  23891. * @return {Ext.dom.CompositeElement} this
  23892. */
  23893. removeElement: function(keys, removeDom) {
  23894. keys = [].concat(keys);
  23895. var me = this,
  23896. elements = me.elements,
  23897. kLen = keys.length,
  23898. val, el, k;
  23899. for (k = 0; k < kLen; k++) {
  23900. val = keys[k];
  23901. if ((el = (elements[val] || elements[val = me.indexOf(val)]))) {
  23902. if (removeDom) {
  23903. if (el.dom) {
  23904. el.remove();
  23905. } else {
  23906. Ext.removeNode(el);
  23907. }
  23908. }
  23909. Ext.Array.erase(elements, val, 1);
  23910. }
  23911. }
  23912. return me;
  23913. }
  23914. }, function() {
  23915. this.importElementMethods();
  23916. this.prototype.on = this.prototype.addListener;
  23917. if (Ext.DomQuery){
  23918. Ext.dom.Element.selectorFunction = Ext.DomQuery.select;
  23919. }
  23920. /**
  23921. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  23922. * to be applied to many related elements in one statement through the returned
  23923. * {@link Ext.dom.CompositeElement CompositeElement} or
  23924. * {@link Ext.dom.CompositeElementLite CompositeElementLite} object.
  23925. * @param {String/HTMLElement[]} selector The CSS selector or an array of elements
  23926. * @param {HTMLElement/String} [root] The root element of the query or id of the root
  23927. * @return {Ext.dom.CompositeElementLite/Ext.dom.CompositeElement}
  23928. * @member Ext.dom.Element
  23929. * @method select
  23930. * @static
  23931. * @ignore
  23932. */
  23933. Ext.dom.Element.select = function(selector, root) {
  23934. var elements;
  23935. if (typeof selector == "string") {
  23936. elements = Ext.dom.Element.selectorFunction(selector, root);
  23937. }
  23938. else if (selector.length !== undefined) {
  23939. elements = selector;
  23940. }
  23941. else {
  23942. throw new Error("[Ext.select] Invalid selector specified: " + selector);
  23943. }
  23944. return new Ext.CompositeElementLite(elements);
  23945. };
  23946. /**
  23947. * @member Ext
  23948. * @method select
  23949. * @inheritdoc Ext.dom.Element#select
  23950. * @ignore
  23951. */
  23952. Ext.select = function() {
  23953. return Ext.dom.Element.select.apply(Ext.dom.Element, arguments);
  23954. };
  23955. });
  23956. //@tag dom,core
  23957. /**
  23958. * @class Ext.dom.CompositeElement
  23959. * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter
  23960. * members, or to perform collective actions upon the whole set.</p>
  23961. * <p>Although they are not listed, this class supports all of the methods of {@link Ext.dom.Element} and
  23962. * {@link Ext.fx.Anim}. The methods from these classes will be performed on all the elements in this collection.</p>
  23963. * <p>All methods return <i>this</i> and can be chained.</p>
  23964. * Usage:
  23965. <pre><code>
  23966. var els = Ext.select("#some-el div.some-class", true);
  23967. // or select directly from an existing element
  23968. var el = Ext.get('some-el');
  23969. el.select('div.some-class', true);
  23970. els.setWidth(100); // all elements become 100 width
  23971. els.hide(true); // all elements fade out and hide
  23972. // or
  23973. els.setWidth(100).hide(true);
  23974. </code></pre>
  23975. */
  23976. Ext.define('Ext.dom.CompositeElement', {
  23977. alternateClassName: 'Ext.CompositeElement',
  23978. extend: 'Ext.dom.CompositeElementLite',
  23979. // private
  23980. getElement: function(el) {
  23981. // In this case just return it, since we already have a reference to it
  23982. return el;
  23983. },
  23984. // private
  23985. transformElement: function(el) {
  23986. return Ext.get(el);
  23987. }
  23988. }, function() {
  23989. /**
  23990. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  23991. * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
  23992. * {@link Ext.CompositeElementLite CompositeElementLite} object.
  23993. * @param {String/HTMLElement[]} selector The CSS selector or an array of elements
  23994. * @param {Boolean} [unique] true to create a unique Ext.Element for each element (defaults to a shared flyweight object)
  23995. * @param {HTMLElement/String} [root] The root element of the query or id of the root
  23996. * @return {Ext.CompositeElementLite/Ext.CompositeElement}
  23997. * @member Ext.dom.Element
  23998. * @method select
  23999. * @static
  24000. */
  24001. Ext.dom.Element.select = function(selector, unique, root) {
  24002. var elements;
  24003. if (typeof selector == "string") {
  24004. elements = Ext.dom.Element.selectorFunction(selector, root);
  24005. }
  24006. else if (selector.length !== undefined) {
  24007. elements = selector;
  24008. }
  24009. else {
  24010. throw new Error("[Ext.select] Invalid selector specified: " + selector);
  24011. }
  24012. return (unique === true) ? new Ext.CompositeElement(elements) : new Ext.CompositeElementLite(elements);
  24013. };
  24014. });
  24015. /**
  24016. * Shorthand of {@link Ext.Element#method-select}.
  24017. * @member Ext
  24018. * @method select
  24019. * @inheritdoc Ext.Element#select
  24020. */
  24021. Ext.select = Ext.Element.select;
  24022. Ext.ClassManager.addNameAlternateMappings({
  24023. "Ext.draw.engine.ImageExporter": [],
  24024. "Ext.layout.component.Auto": [],
  24025. "Ext.grid.property.Store": [
  24026. "Ext.grid.PropertyStore"
  24027. ],
  24028. "Ext.layout.container.Box": [
  24029. "Ext.layout.BoxLayout"
  24030. ],
  24031. "Ext.direct.JsonProvider": [],
  24032. "Ext.tree.Panel": [
  24033. "Ext.tree.TreePanel",
  24034. "Ext.TreePanel"
  24035. ],
  24036. "Ext.data.Model": [
  24037. "Ext.data.Record"
  24038. ],
  24039. "Ext.data.reader.Reader": [
  24040. "Ext.data.Reader",
  24041. "Ext.data.DataReader"
  24042. ],
  24043. "Ext.tab.Tab": [],
  24044. "Ext.button.Button": [
  24045. "Ext.Button"
  24046. ],
  24047. "Ext.util.Grouper": [],
  24048. "Ext.util.TaskRunner": [],
  24049. "Ext.direct.RemotingProvider": [],
  24050. "Ext.data.NodeInterface": [],
  24051. "Ext.grid.column.Date": [
  24052. "Ext.grid.DateColumn"
  24053. ],
  24054. "Ext.form.field.Trigger": [
  24055. "Ext.form.TriggerField",
  24056. "Ext.form.TwinTriggerField",
  24057. "Ext.form.Trigger"
  24058. ],
  24059. "Ext.grid.plugin.RowEditing": [],
  24060. "Ext.tip.QuickTip": [
  24061. "Ext.QuickTip"
  24062. ],
  24063. "Ext.form.action.Load": [
  24064. "Ext.form.Action.Load"
  24065. ],
  24066. "Ext.form.field.ComboBox": [
  24067. "Ext.form.ComboBox"
  24068. ],
  24069. "Ext.layout.container.Border": [
  24070. "Ext.layout.BorderLayout"
  24071. ],
  24072. "Ext.data.JsonPStore": [],
  24073. "Ext.layout.component.field.TextArea": [],
  24074. "Ext.dom.AbstractHelper": [],
  24075. "Ext.layout.container.Container": [
  24076. "Ext.layout.ContainerLayout"
  24077. ],
  24078. "Ext.util.Sortable": [],
  24079. "Ext.selection.Model": [
  24080. "Ext.AbstractSelectionModel"
  24081. ],
  24082. "Ext.draw.CompositeSprite": [],
  24083. "Ext.fx.Queue": [],
  24084. "Ext.dd.StatusProxy": [],
  24085. "Ext.form.field.Checkbox": [
  24086. "Ext.form.Checkbox"
  24087. ],
  24088. "Ext.XTemplateCompiler": [],
  24089. "Ext.direct.Transaction": [
  24090. "Ext.Direct.Transaction"
  24091. ],
  24092. "Ext.util.Offset": [],
  24093. "Ext.dom.Element": [
  24094. "Ext.Element",
  24095. "Ext.core.Element"
  24096. ],
  24097. "Ext.view.DragZone": [],
  24098. "Ext.util.KeyNav": [
  24099. "Ext.KeyNav"
  24100. ],
  24101. "Ext.form.field.File": [
  24102. "Ext.form.FileUploadField",
  24103. "Ext.ux.form.FileUploadField",
  24104. "Ext.form.File"
  24105. ],
  24106. "Ext.slider.Single": [
  24107. "Ext.Slider",
  24108. "Ext.form.SliderField",
  24109. "Ext.slider.SingleSlider",
  24110. "Ext.slider.Slider"
  24111. ],
  24112. "Ext.panel.Proxy": [
  24113. "Ext.dd.PanelProxy"
  24114. ],
  24115. "Ext.fx.target.Target": [],
  24116. "Ext.ComponentManager": [
  24117. "Ext.ComponentMgr"
  24118. ],
  24119. "Ext.grid.feature.GroupingSummary": [],
  24120. "Ext.grid.property.HeaderContainer": [
  24121. "Ext.grid.PropertyColumnModel"
  24122. ],
  24123. "Ext.layout.component.BoundList": [],
  24124. "Ext.tab.Bar": [],
  24125. "Ext.app.Application": [],
  24126. "Ext.ShadowPool": [],
  24127. "Ext.layout.container.Accordion": [
  24128. "Ext.layout.AccordionLayout"
  24129. ],
  24130. "Ext.resizer.ResizeTracker": [],
  24131. "Ext.layout.container.boxOverflow.None": [
  24132. "Ext.layout.boxOverflow.None"
  24133. ],
  24134. "Ext.panel.Tool": [],
  24135. "Ext.tree.View": [],
  24136. "Ext.ElementLoader": [],
  24137. "Ext.grid.ColumnComponentLayout": [],
  24138. "Ext.toolbar.Separator": [
  24139. "Ext.Toolbar.Separator"
  24140. ],
  24141. "Ext.dd.DragZone": [],
  24142. "Ext.util.Renderable": [],
  24143. "Ext.layout.component.FieldSet": [],
  24144. "Ext.util.Bindable": [],
  24145. "Ext.data.SortTypes": [],
  24146. "Ext.util.Animate": [],
  24147. "Ext.form.field.Date": [
  24148. "Ext.form.DateField",
  24149. "Ext.form.Date"
  24150. ],
  24151. "Ext.Component": [],
  24152. "Ext.chart.axis.Axis": [
  24153. "Ext.chart.Axis"
  24154. ],
  24155. "Ext.fx.target.CompositeSprite": [],
  24156. "Ext.menu.DatePicker": [],
  24157. "Ext.form.field.Picker": [
  24158. "Ext.form.Picker"
  24159. ],
  24160. "Ext.fx.Animator": [],
  24161. "Ext.Ajax": [],
  24162. "Ext.layout.component.Dock": [
  24163. "Ext.layout.component.AbstractDock"
  24164. ],
  24165. "Ext.util.Filter": [],
  24166. "Ext.dd.DragDrop": [],
  24167. "Ext.grid.Scroller": [],
  24168. "Ext.view.View": [
  24169. "Ext.DataView"
  24170. ],
  24171. "Ext.data.association.BelongsTo": [
  24172. "Ext.data.BelongsToAssociation"
  24173. ],
  24174. "Ext.fx.target.Element": [],
  24175. "Ext.draw.Surface": [],
  24176. "Ext.dd.DDProxy": [],
  24177. "Ext.data.AbstractStore": [],
  24178. "Ext.form.action.StandardSubmit": [],
  24179. "Ext.grid.Lockable": [],
  24180. "Ext.dd.Registry": [],
  24181. "Ext.picker.Month": [
  24182. "Ext.MonthPicker"
  24183. ],
  24184. "Ext.container.Container": [
  24185. "Ext.Container"
  24186. ],
  24187. "Ext.menu.Manager": [
  24188. "Ext.menu.MenuMgr"
  24189. ],
  24190. "Ext.util.KeyMap": [
  24191. "Ext.KeyMap"
  24192. ],
  24193. "Ext.data.Batch": [],
  24194. "Ext.resizer.Handle": [],
  24195. "Ext.util.ElementContainer": [],
  24196. "Ext.grid.feature.Grouping": [],
  24197. "Ext.tab.Panel": [
  24198. "Ext.TabPanel"
  24199. ],
  24200. "Ext.layout.component.Body": [],
  24201. "Ext.layout.Context": [],
  24202. "Ext.layout.component.field.ComboBox": [],
  24203. "Ext.dd.DDTarget": [],
  24204. "Ext.chart.Chart": [],
  24205. "Ext.data.Field": [],
  24206. "Ext.chart.series.Gauge": [],
  24207. "Ext.data.StoreManager": [
  24208. "Ext.StoreMgr",
  24209. "Ext.data.StoreMgr",
  24210. "Ext.StoreManager"
  24211. ],
  24212. "Ext.tip.QuickTipManager": [
  24213. "Ext.QuickTips"
  24214. ],
  24215. "Ext.data.IdGenerator": [],
  24216. "Ext.grid.plugin.Editing": [],
  24217. "Ext.grid.RowEditor": [],
  24218. "Ext.state.LocalStorageProvider": [],
  24219. "Ext.form.action.Action": [
  24220. "Ext.form.Action"
  24221. ],
  24222. "Ext.ProgressBar": [],
  24223. "Ext.tree.ViewDragZone": [],
  24224. "Ext.data.reader.Array": [
  24225. "Ext.data.ArrayReader"
  24226. ],
  24227. "Ext.picker.Date": [
  24228. "Ext.DatePicker"
  24229. ],
  24230. "Ext.data.proxy.JsonP": [
  24231. "Ext.data.ScriptTagProxy"
  24232. ],
  24233. "Ext.chart.series.Area": [],
  24234. "Ext.fx.Anim": [],
  24235. "Ext.menu.Item": [
  24236. "Ext.menu.TextItem"
  24237. ],
  24238. "Ext.chart.Legend": [],
  24239. "Ext.grid.plugin.HeaderReorderer": [],
  24240. "Ext.layout.container.VBox": [
  24241. "Ext.layout.VBoxLayout"
  24242. ],
  24243. "Ext.view.DropZone": [],
  24244. "Ext.layout.component.Button": [],
  24245. "Ext.form.field.Hidden": [
  24246. "Ext.form.Hidden"
  24247. ],
  24248. "Ext.form.FieldContainer": [],
  24249. "Ext.data.proxy.Server": [
  24250. "Ext.data.ServerProxy"
  24251. ],
  24252. "Ext.chart.series.Cartesian": [
  24253. "Ext.chart.CartesianSeries",
  24254. "Ext.chart.CartesianChart"
  24255. ],
  24256. "Ext.grid.column.Column": [
  24257. "Ext.grid.Column"
  24258. ],
  24259. "Ext.data.ResultSet": [],
  24260. "Ext.data.association.HasMany": [
  24261. "Ext.data.HasManyAssociation"
  24262. ],
  24263. "Ext.layout.container.Fit": [
  24264. "Ext.layout.FitLayout"
  24265. ],
  24266. "Ext.util.CSS": [],
  24267. "Ext.layout.component.field.Field": [],
  24268. "Ext.data.proxy.Ajax": [
  24269. "Ext.data.HttpProxy",
  24270. "Ext.data.AjaxProxy"
  24271. ],
  24272. "Ext.form.Label": [],
  24273. "Ext.data.writer.Writer": [
  24274. "Ext.data.DataWriter",
  24275. "Ext.data.Writer"
  24276. ],
  24277. "Ext.view.BoundListKeyNav": [],
  24278. "Ext.form.FieldSet": [],
  24279. "Ext.XTemplateParser": [],
  24280. "Ext.form.field.VTypes": [
  24281. "Ext.form.VTypes"
  24282. ],
  24283. "Ext.fx.PropertyHandler": [],
  24284. "Ext.form.CheckboxGroup": [],
  24285. "Ext.data.JsonP": [],
  24286. "Ext.draw.engine.Vml": [],
  24287. "Ext.layout.container.CheckboxGroup": [],
  24288. "Ext.panel.Header": [],
  24289. "Ext.app.Controller": [],
  24290. "Ext.grid.plugin.CellEditing": [],
  24291. "Ext.form.field.Time": [
  24292. "Ext.form.TimeField",
  24293. "Ext.form.Time"
  24294. ],
  24295. "Ext.fx.CubicBezier": [],
  24296. "Ext.button.Cycle": [
  24297. "Ext.CycleButton"
  24298. ],
  24299. "Ext.data.Tree": [],
  24300. "Ext.ModelManager": [
  24301. "Ext.ModelMgr"
  24302. ],
  24303. "Ext.data.XmlStore": [],
  24304. "Ext.grid.ViewDropZone": [],
  24305. "Ext.grid.header.DropZone": [],
  24306. "Ext.Layer": [],
  24307. "Ext.util.HashMap": [],
  24308. "Ext.grid.column.Template": [
  24309. "Ext.grid.TemplateColumn"
  24310. ],
  24311. "Ext.ComponentLoader": [],
  24312. "Ext.EventObjectImpl": [],
  24313. "Ext.form.FieldAncestor": [],
  24314. "Ext.chart.axis.Gauge": [],
  24315. "Ext.data.validations": [],
  24316. "Ext.data.Connection": [],
  24317. "Ext.dd.DropZone": [],
  24318. "Ext.direct.ExceptionEvent": [],
  24319. "Ext.resizer.Splitter": [],
  24320. "Ext.form.RadioManager": [],
  24321. "Ext.data.association.HasOne": [
  24322. "Ext.data.HasOneAssociation"
  24323. ],
  24324. "Ext.draw.Text": [],
  24325. "Ext.window.MessageBox": [],
  24326. "Ext.fx.target.CompositeElementCSS": [],
  24327. "Ext.chart.series.Line": [
  24328. "Ext.chart.LineSeries",
  24329. "Ext.chart.LineChart"
  24330. ],
  24331. "Ext.view.Table": [],
  24332. "Ext.data.writer.Json": [
  24333. "Ext.data.JsonWriter"
  24334. ],
  24335. "Ext.fx.Manager": [],
  24336. "Ext.fx.target.CompositeElement": [],
  24337. "Ext.chart.Label": [],
  24338. "Ext.grid.View": [],
  24339. "Ext.Action": [],
  24340. "Ext.form.Basic": [
  24341. "Ext.form.BasicForm"
  24342. ],
  24343. "Ext.container.Viewport": [
  24344. "Ext.Viewport"
  24345. ],
  24346. "Ext.state.Stateful": [],
  24347. "Ext.grid.feature.RowBody": [],
  24348. "Ext.form.field.Text": [
  24349. "Ext.form.TextField",
  24350. "Ext.form.Text"
  24351. ],
  24352. "Ext.data.reader.Xml": [
  24353. "Ext.data.XmlReader"
  24354. ],
  24355. "Ext.grid.feature.AbstractSummary": [],
  24356. "Ext.chart.axis.Category": [
  24357. "Ext.chart.CategoryAxis"
  24358. ],
  24359. "Ext.layout.container.Absolute": [
  24360. "Ext.layout.AbsoluteLayout"
  24361. ],
  24362. "Ext.data.reader.Json": [
  24363. "Ext.data.JsonReader"
  24364. ],
  24365. "Ext.util.TextMetrics": [],
  24366. "Ext.data.TreeStore": [],
  24367. "Ext.view.BoundList": [
  24368. "Ext.BoundList"
  24369. ],
  24370. "Ext.form.field.HtmlEditor": [
  24371. "Ext.form.HtmlEditor"
  24372. ],
  24373. "Ext.layout.container.Form": [
  24374. "Ext.layout.FormLayout"
  24375. ],
  24376. "Ext.chart.MaskLayer": [],
  24377. "Ext.util.Observable": [],
  24378. "Ext.resizer.BorderSplitterTracker": [],
  24379. "Ext.util.LruCache": [],
  24380. "Ext.tip.Tip": [
  24381. "Ext.Tip"
  24382. ],
  24383. "Ext.dom.CompositeElement": [
  24384. "Ext.CompositeElement"
  24385. ],
  24386. "Ext.grid.feature.RowWrap": [],
  24387. "Ext.data.proxy.Client": [
  24388. "Ext.data.ClientProxy"
  24389. ],
  24390. "Ext.data.Types": [],
  24391. "Ext.draw.SpriteDD": [],
  24392. "Ext.layout.container.boxOverflow.Menu": [
  24393. "Ext.layout.boxOverflow.Menu"
  24394. ],
  24395. "Ext.LoadMask": [],
  24396. "Ext.toolbar.Paging": [
  24397. "Ext.PagingToolbar"
  24398. ],
  24399. "Ext.data.association.Association": [
  24400. "Ext.data.Association"
  24401. ],
  24402. "Ext.tree.ViewDropZone": [],
  24403. "Ext.grid.LockingView": [],
  24404. "Ext.toolbar.Toolbar": [
  24405. "Ext.Toolbar"
  24406. ],
  24407. "Ext.tip.ToolTip": [
  24408. "Ext.ToolTip"
  24409. ],
  24410. "Ext.chart.Highlight": [],
  24411. "Ext.state.Manager": [],
  24412. "Ext.util.Inflector": [],
  24413. "Ext.grid.Panel": [
  24414. "Ext.list.ListView",
  24415. "Ext.ListView",
  24416. "Ext.grid.GridPanel"
  24417. ],
  24418. "Ext.XTemplate": [],
  24419. "Ext.data.NodeStore": [],
  24420. "Ext.Shadow": [],
  24421. "Ext.form.action.Submit": [
  24422. "Ext.form.Action.Submit"
  24423. ],
  24424. "Ext.form.Panel": [
  24425. "Ext.FormPanel",
  24426. "Ext.form.FormPanel"
  24427. ],
  24428. "Ext.chart.series.Series": [],
  24429. "Ext.perf.Accumulator": [],
  24430. "Ext.data.Request": [],
  24431. "Ext.dd.DD": [],
  24432. "Ext.dom.CompositeElementLite": [
  24433. "Ext.CompositeElementLite"
  24434. ],
  24435. "Ext.toolbar.Fill": [
  24436. "Ext.Toolbar.Fill"
  24437. ],
  24438. "Ext.grid.RowNumberer": [],
  24439. "Ext.data.proxy.WebStorage": [
  24440. "Ext.data.WebStorageProxy"
  24441. ],
  24442. "Ext.util.Floating": [],
  24443. "Ext.form.action.DirectSubmit": [
  24444. "Ext.form.Action.DirectSubmit"
  24445. ],
  24446. "Ext.util.Cookies": [],
  24447. "Ext.data.UuidGenerator": [],
  24448. "Ext.util.Point": [],
  24449. "Ext.fx.target.Component": [],
  24450. "Ext.form.CheckboxManager": [],
  24451. "Ext.form.field.Field": [],
  24452. "Ext.form.field.Display": [
  24453. "Ext.form.DisplayField",
  24454. "Ext.form.Display"
  24455. ],
  24456. "Ext.layout.container.Anchor": [
  24457. "Ext.layout.AnchorLayout"
  24458. ],
  24459. "Ext.layout.component.field.Text": [],
  24460. "Ext.data.DirectStore": [],
  24461. "Ext.data.BufferStore": [],
  24462. "Ext.grid.ColumnLayout": [],
  24463. "Ext.chart.series.Column": [
  24464. "Ext.chart.ColumnSeries",
  24465. "Ext.chart.ColumnChart",
  24466. "Ext.chart.StackedColumnChart"
  24467. ],
  24468. "Ext.Template": [],
  24469. "Ext.AbstractComponent": [],
  24470. "Ext.flash.Component": [
  24471. "Ext.FlashComponent"
  24472. ],
  24473. "Ext.form.field.Base": [
  24474. "Ext.form.Field",
  24475. "Ext.form.BaseField"
  24476. ],
  24477. "Ext.data.SequentialIdGenerator": [],
  24478. "Ext.grid.header.Container": [],
  24479. "Ext.container.ButtonGroup": [
  24480. "Ext.ButtonGroup"
  24481. ],
  24482. "Ext.grid.column.Action": [
  24483. "Ext.grid.ActionColumn"
  24484. ],
  24485. "Ext.layout.component.field.Trigger": [],
  24486. "Ext.layout.component.field.FieldContainer": [],
  24487. "Ext.chart.Shape": [],
  24488. "Ext.panel.DD": [],
  24489. "Ext.container.AbstractContainer": [],
  24490. "Ext.data.ArrayStore": [],
  24491. "Ext.window.Window": [
  24492. "Ext.Window"
  24493. ],
  24494. "Ext.picker.Color": [
  24495. "Ext.ColorPalette"
  24496. ],
  24497. "Ext.grid.feature.Feature": [],
  24498. "Ext.chart.theme.Theme": [],
  24499. "Ext.util.ClickRepeater": [],
  24500. "Ext.form.field.Spinner": [
  24501. "Ext.form.Spinner"
  24502. ],
  24503. "Ext.container.DockingContainer": [],
  24504. "Ext.selection.DataViewModel": [],
  24505. "Ext.dd.DragTracker": [],
  24506. "Ext.dd.DragDropManager": [
  24507. "Ext.dd.DragDropMgr",
  24508. "Ext.dd.DDM"
  24509. ],
  24510. "Ext.selection.CheckboxModel": [],
  24511. "Ext.layout.container.Column": [
  24512. "Ext.layout.ColumnLayout"
  24513. ],
  24514. "Ext.menu.KeyNav": [],
  24515. "Ext.draw.Matrix": [],
  24516. "Ext.form.field.Number": [
  24517. "Ext.form.NumberField",
  24518. "Ext.form.Number"
  24519. ],
  24520. "Ext.data.proxy.Direct": [
  24521. "Ext.data.DirectProxy"
  24522. ],
  24523. "Ext.chart.Navigation": [],
  24524. "Ext.slider.Tip": [],
  24525. "Ext.chart.theme.Base": [],
  24526. "Ext.form.field.TextArea": [
  24527. "Ext.form.TextArea"
  24528. ],
  24529. "Ext.form.field.Radio": [
  24530. "Ext.form.Radio"
  24531. ],
  24532. "Ext.layout.component.ProgressBar": [],
  24533. "Ext.chart.series.Pie": [
  24534. "Ext.chart.PieSeries",
  24535. "Ext.chart.PieChart"
  24536. ],
  24537. "Ext.view.TableChunker": [],
  24538. "Ext.tree.plugin.TreeViewDragDrop": [],
  24539. "Ext.direct.Provider": [],
  24540. "Ext.layout.Layout": [],
  24541. "Ext.toolbar.TextItem": [
  24542. "Ext.Toolbar.TextItem"
  24543. ],
  24544. "Ext.dom.Helper": [],
  24545. "Ext.util.AbstractMixedCollection": [],
  24546. "Ext.data.JsonStore": [],
  24547. "Ext.button.Split": [
  24548. "Ext.SplitButton"
  24549. ],
  24550. "Ext.dd.DropTarget": [],
  24551. "Ext.direct.RemotingEvent": [],
  24552. "Ext.draw.Sprite": [],
  24553. "Ext.fx.target.Sprite": [],
  24554. "Ext.data.proxy.LocalStorage": [
  24555. "Ext.data.LocalStorageProxy"
  24556. ],
  24557. "Ext.layout.component.Draw": [],
  24558. "Ext.AbstractPlugin": [],
  24559. "Ext.Editor": [],
  24560. "Ext.chart.axis.Radial": [],
  24561. "Ext.chart.Tip": [],
  24562. "Ext.layout.container.Table": [
  24563. "Ext.layout.TableLayout"
  24564. ],
  24565. "Ext.chart.axis.Abstract": [],
  24566. "Ext.data.proxy.Rest": [
  24567. "Ext.data.RestProxy"
  24568. ],
  24569. "Ext.util.Queue": [],
  24570. "Ext.state.CookieProvider": [],
  24571. "Ext.Img": [],
  24572. "Ext.dd.DragSource": [],
  24573. "Ext.grid.CellEditor": [],
  24574. "Ext.layout.ClassList": [],
  24575. "Ext.util.Sorter": [],
  24576. "Ext.resizer.SplitterTracker": [],
  24577. "Ext.panel.Table": [],
  24578. "Ext.draw.Color": [],
  24579. "Ext.chart.series.Bar": [
  24580. "Ext.chart.BarSeries",
  24581. "Ext.chart.BarChart",
  24582. "Ext.chart.StackedBarChart"
  24583. ],
  24584. "Ext.PluginManager": [
  24585. "Ext.PluginMgr"
  24586. ],
  24587. "Ext.util.ComponentDragger": [],
  24588. "Ext.chart.series.Scatter": [],
  24589. "Ext.chart.Callout": [],
  24590. "Ext.data.Store": [],
  24591. "Ext.grid.feature.Summary": [],
  24592. "Ext.layout.component.Component": [],
  24593. "Ext.util.ProtoElement": [],
  24594. "Ext.direct.Manager": [],
  24595. "Ext.data.proxy.Proxy": [
  24596. "Ext.data.DataProxy",
  24597. "Ext.data.Proxy"
  24598. ],
  24599. "Ext.menu.CheckItem": [],
  24600. "Ext.dom.AbstractElement": [],
  24601. "Ext.layout.container.Card": [
  24602. "Ext.layout.CardLayout"
  24603. ],
  24604. "Ext.draw.Component": [],
  24605. "Ext.toolbar.Item": [
  24606. "Ext.Toolbar.Item"
  24607. ],
  24608. "Ext.form.RadioGroup": [],
  24609. "Ext.slider.Thumb": [],
  24610. "Ext.grid.header.DragZone": [],
  24611. "Ext.form.action.DirectLoad": [
  24612. "Ext.form.Action.DirectLoad"
  24613. ],
  24614. "Ext.picker.Time": [],
  24615. "Ext.resizer.BorderSplitter": [],
  24616. "Ext.ZIndexManager": [
  24617. "Ext.WindowGroup"
  24618. ],
  24619. "Ext.menu.ColorPicker": [],
  24620. "Ext.menu.Menu": [],
  24621. "Ext.chart.LegendItem": [],
  24622. "Ext.toolbar.Spacer": [
  24623. "Ext.Toolbar.Spacer"
  24624. ],
  24625. "Ext.panel.Panel": [
  24626. "Ext.Panel"
  24627. ],
  24628. "Ext.util.Memento": [],
  24629. "Ext.data.proxy.Memory": [
  24630. "Ext.data.MemoryProxy"
  24631. ],
  24632. "Ext.chart.axis.Time": [
  24633. "Ext.chart.TimeAxis"
  24634. ],
  24635. "Ext.grid.plugin.DragDrop": [],
  24636. "Ext.layout.component.Tab": [],
  24637. "Ext.ComponentQuery": [],
  24638. "Ext.draw.engine.SvgExporter": [],
  24639. "Ext.grid.feature.Chunking": [],
  24640. "Ext.layout.container.Auto": [],
  24641. "Ext.view.AbstractView": [],
  24642. "Ext.util.Region": [],
  24643. "Ext.draw.Draw": [],
  24644. "Ext.fx.target.ElementCSS": [],
  24645. "Ext.grid.PagingScroller": [],
  24646. "Ext.layout.component.field.HtmlEditor": [],
  24647. "Ext.data.proxy.SessionStorage": [
  24648. "Ext.data.SessionStorageProxy"
  24649. ],
  24650. "Ext.app.EventBus": [],
  24651. "Ext.menu.Separator": [],
  24652. "Ext.util.History": [
  24653. "Ext.History"
  24654. ],
  24655. "Ext.direct.Event": [],
  24656. "Ext.direct.RemotingMethod": [],
  24657. "Ext.dd.ScrollManager": [],
  24658. "Ext.chart.Mask": [],
  24659. "Ext.selection.CellModel": [],
  24660. "Ext.view.TableLayout": [],
  24661. "Ext.state.Provider": [],
  24662. "Ext.layout.container.Editor": [],
  24663. "Ext.data.Errors": [],
  24664. "Ext.dom.AbstractQuery": [],
  24665. "Ext.selection.TreeModel": [],
  24666. "Ext.form.Labelable": [],
  24667. "Ext.grid.column.Number": [
  24668. "Ext.grid.NumberColumn"
  24669. ],
  24670. "Ext.draw.engine.Svg": [],
  24671. "Ext.grid.property.Grid": [
  24672. "Ext.grid.PropertyGrid"
  24673. ],
  24674. "Ext.FocusManager": [
  24675. "Ext.FocusMgr"
  24676. ],
  24677. "Ext.AbstractManager": [],
  24678. "Ext.chart.series.Radar": [],
  24679. "Ext.grid.property.Property": [
  24680. "Ext.PropGridProperty"
  24681. ],
  24682. "Ext.chart.TipSurface": [],
  24683. "Ext.grid.column.Boolean": [
  24684. "Ext.grid.BooleanColumn"
  24685. ],
  24686. "Ext.direct.PollingProvider": [],
  24687. "Ext.grid.plugin.HeaderResizer": [],
  24688. "Ext.data.writer.Xml": [
  24689. "Ext.data.XmlWriter"
  24690. ],
  24691. "Ext.tree.Column": [],
  24692. "Ext.slider.Multi": [
  24693. "Ext.slider.MultiSlider"
  24694. ],
  24695. "Ext.panel.AbstractPanel": [],
  24696. "Ext.layout.component.field.Slider": [],
  24697. "Ext.chart.axis.Numeric": [
  24698. "Ext.chart.NumericAxis"
  24699. ],
  24700. "Ext.layout.container.boxOverflow.Scroller": [
  24701. "Ext.layout.boxOverflow.Scroller"
  24702. ],
  24703. "Ext.data.Operation": [],
  24704. "Ext.layout.container.HBox": [
  24705. "Ext.layout.HBoxLayout"
  24706. ],
  24707. "Ext.resizer.Resizer": [
  24708. "Ext.Resizable"
  24709. ],
  24710. "Ext.selection.RowModel": [],
  24711. "Ext.layout.ContextItem": [],
  24712. "Ext.util.MixedCollection": [],
  24713. "Ext.perf.Monitor": [
  24714. "Ext.Perf"
  24715. ]
  24716. });Ext.ClassManager.addNameAliasMappings({
  24717. "Ext.draw.engine.ImageExporter": [],
  24718. "Ext.layout.component.Auto": [
  24719. "layout.autocomponent"
  24720. ],
  24721. "Ext.grid.property.Store": [],
  24722. "Ext.layout.container.Box": [
  24723. "layout.box"
  24724. ],
  24725. "Ext.direct.JsonProvider": [
  24726. "direct.jsonprovider"
  24727. ],
  24728. "Ext.tree.Panel": [
  24729. "widget.treepanel"
  24730. ],
  24731. "Ext.data.Model": [],
  24732. "Ext.data.reader.Reader": [],
  24733. "Ext.tab.Tab": [
  24734. "widget.tab"
  24735. ],
  24736. "Ext.button.Button": [
  24737. "widget.button"
  24738. ],
  24739. "Ext.util.Grouper": [],
  24740. "Ext.util.TaskRunner": [],
  24741. "Ext.direct.RemotingProvider": [
  24742. "direct.remotingprovider"
  24743. ],
  24744. "Ext.data.NodeInterface": [],
  24745. "Ext.grid.column.Date": [
  24746. "widget.datecolumn"
  24747. ],
  24748. "Ext.form.field.Trigger": [
  24749. "widget.triggerfield",
  24750. "widget.trigger"
  24751. ],
  24752. "Ext.grid.plugin.RowEditing": [
  24753. "plugin.rowediting"
  24754. ],
  24755. "Ext.tip.QuickTip": [
  24756. "widget.quicktip"
  24757. ],
  24758. "Ext.form.action.Load": [
  24759. "formaction.load"
  24760. ],
  24761. "Ext.form.field.ComboBox": [
  24762. "widget.combobox",
  24763. "widget.combo"
  24764. ],
  24765. "Ext.layout.container.Border": [
  24766. "layout.border"
  24767. ],
  24768. "Ext.data.JsonPStore": [
  24769. "store.jsonp"
  24770. ],
  24771. "Ext.layout.component.field.TextArea": [
  24772. "layout.textareafield"
  24773. ],
  24774. "Ext.dom.AbstractHelper": [],
  24775. "Ext.layout.container.Container": [],
  24776. "Ext.util.Sortable": [],
  24777. "Ext.selection.Model": [],
  24778. "Ext.draw.CompositeSprite": [],
  24779. "Ext.fx.Queue": [],
  24780. "Ext.dd.StatusProxy": [],
  24781. "Ext.form.field.Checkbox": [
  24782. "widget.checkboxfield",
  24783. "widget.checkbox"
  24784. ],
  24785. "Ext.XTemplateCompiler": [],
  24786. "Ext.direct.Transaction": [
  24787. "direct.transaction"
  24788. ],
  24789. "Ext.util.Offset": [],
  24790. "Ext.dom.Element": [],
  24791. "Ext.view.DragZone": [],
  24792. "Ext.util.KeyNav": [],
  24793. "Ext.form.field.File": [
  24794. "widget.filefield",
  24795. "widget.fileuploadfield"
  24796. ],
  24797. "Ext.slider.Single": [
  24798. "widget.slider",
  24799. "widget.sliderfield"
  24800. ],
  24801. "Ext.panel.Proxy": [],
  24802. "Ext.fx.target.Target": [],
  24803. "Ext.ComponentManager": [],
  24804. "Ext.grid.feature.GroupingSummary": [
  24805. "feature.groupingsummary"
  24806. ],
  24807. "Ext.grid.property.HeaderContainer": [],
  24808. "Ext.layout.component.BoundList": [
  24809. "layout.boundlist"
  24810. ],
  24811. "Ext.tab.Bar": [
  24812. "widget.tabbar"
  24813. ],
  24814. "Ext.app.Application": [],
  24815. "Ext.ShadowPool": [],
  24816. "Ext.layout.container.Accordion": [
  24817. "layout.accordion"
  24818. ],
  24819. "Ext.resizer.ResizeTracker": [],
  24820. "Ext.layout.container.boxOverflow.None": [],
  24821. "Ext.panel.Tool": [
  24822. "widget.tool"
  24823. ],
  24824. "Ext.tree.View": [
  24825. "widget.treeview"
  24826. ],
  24827. "Ext.ElementLoader": [],
  24828. "Ext.grid.ColumnComponentLayout": [
  24829. "layout.columncomponent"
  24830. ],
  24831. "Ext.toolbar.Separator": [
  24832. "widget.tbseparator"
  24833. ],
  24834. "Ext.dd.DragZone": [],
  24835. "Ext.util.Renderable": [],
  24836. "Ext.layout.component.FieldSet": [
  24837. "layout.fieldset"
  24838. ],
  24839. "Ext.util.Bindable": [],
  24840. "Ext.data.SortTypes": [],
  24841. "Ext.util.Animate": [],
  24842. "Ext.form.field.Date": [
  24843. "widget.datefield"
  24844. ],
  24845. "Ext.Component": [
  24846. "widget.component",
  24847. "widget.box"
  24848. ],
  24849. "Ext.chart.axis.Axis": [],
  24850. "Ext.fx.target.CompositeSprite": [],
  24851. "Ext.menu.DatePicker": [
  24852. "widget.datemenu"
  24853. ],
  24854. "Ext.form.field.Picker": [
  24855. "widget.pickerfield"
  24856. ],
  24857. "Ext.fx.Animator": [],
  24858. "Ext.Ajax": [],
  24859. "Ext.layout.component.Dock": [
  24860. "layout.dock"
  24861. ],
  24862. "Ext.util.Filter": [],
  24863. "Ext.dd.DragDrop": [],
  24864. "Ext.grid.Scroller": [],
  24865. "Ext.view.View": [
  24866. "widget.dataview"
  24867. ],
  24868. "Ext.data.association.BelongsTo": [
  24869. "association.belongsto"
  24870. ],
  24871. "Ext.fx.target.Element": [],
  24872. "Ext.draw.Surface": [],
  24873. "Ext.dd.DDProxy": [],
  24874. "Ext.data.AbstractStore": [],
  24875. "Ext.form.action.StandardSubmit": [
  24876. "formaction.standardsubmit"
  24877. ],
  24878. "Ext.grid.Lockable": [],
  24879. "Ext.dd.Registry": [],
  24880. "Ext.picker.Month": [
  24881. "widget.monthpicker"
  24882. ],
  24883. "Ext.container.Container": [
  24884. "widget.container"
  24885. ],
  24886. "Ext.menu.Manager": [],
  24887. "Ext.util.KeyMap": [],
  24888. "Ext.data.Batch": [],
  24889. "Ext.resizer.Handle": [],
  24890. "Ext.util.ElementContainer": [],
  24891. "Ext.grid.feature.Grouping": [
  24892. "feature.grouping"
  24893. ],
  24894. "Ext.tab.Panel": [
  24895. "widget.tabpanel"
  24896. ],
  24897. "Ext.layout.component.Body": [
  24898. "layout.body"
  24899. ],
  24900. "Ext.layout.Context": [],
  24901. "Ext.layout.component.field.ComboBox": [
  24902. "layout.combobox"
  24903. ],
  24904. "Ext.dd.DDTarget": [],
  24905. "Ext.chart.Chart": [
  24906. "widget.chart"
  24907. ],
  24908. "Ext.data.Field": [
  24909. "data.field"
  24910. ],
  24911. "Ext.chart.series.Gauge": [
  24912. "series.gauge"
  24913. ],
  24914. "Ext.data.StoreManager": [],
  24915. "Ext.tip.QuickTipManager": [],
  24916. "Ext.data.IdGenerator": [],
  24917. "Ext.grid.plugin.Editing": [
  24918. "editing.editing"
  24919. ],
  24920. "Ext.grid.RowEditor": [],
  24921. "Ext.state.LocalStorageProvider": [
  24922. "state.localstorage"
  24923. ],
  24924. "Ext.form.action.Action": [],
  24925. "Ext.ProgressBar": [
  24926. "widget.progressbar"
  24927. ],
  24928. "Ext.tree.ViewDragZone": [],
  24929. "Ext.data.reader.Array": [
  24930. "reader.array"
  24931. ],
  24932. "Ext.picker.Date": [
  24933. "widget.datepicker"
  24934. ],
  24935. "Ext.data.proxy.JsonP": [
  24936. "proxy.jsonp",
  24937. "proxy.scripttag"
  24938. ],
  24939. "Ext.chart.series.Area": [
  24940. "series.area"
  24941. ],
  24942. "Ext.fx.Anim": [],
  24943. "Ext.menu.Item": [
  24944. "widget.menuitem"
  24945. ],
  24946. "Ext.chart.Legend": [],
  24947. "Ext.grid.plugin.HeaderReorderer": [
  24948. "plugin.gridheaderreorderer"
  24949. ],
  24950. "Ext.layout.container.VBox": [
  24951. "layout.vbox"
  24952. ],
  24953. "Ext.view.DropZone": [],
  24954. "Ext.layout.component.Button": [
  24955. "layout.button"
  24956. ],
  24957. "Ext.form.field.Hidden": [
  24958. "widget.hiddenfield",
  24959. "widget.hidden"
  24960. ],
  24961. "Ext.form.FieldContainer": [
  24962. "widget.fieldcontainer"
  24963. ],
  24964. "Ext.data.proxy.Server": [
  24965. "proxy.server"
  24966. ],
  24967. "Ext.chart.series.Cartesian": [],
  24968. "Ext.grid.column.Column": [
  24969. "widget.gridcolumn"
  24970. ],
  24971. "Ext.data.ResultSet": [],
  24972. "Ext.data.association.HasMany": [
  24973. "association.hasmany"
  24974. ],
  24975. "Ext.layout.container.Fit": [
  24976. "layout.fit"
  24977. ],
  24978. "Ext.util.CSS": [],
  24979. "Ext.layout.component.field.Field": [
  24980. "layout.field"
  24981. ],
  24982. "Ext.data.proxy.Ajax": [
  24983. "proxy.ajax"
  24984. ],
  24985. "Ext.form.Label": [
  24986. "widget.label"
  24987. ],
  24988. "Ext.data.writer.Writer": [
  24989. "writer.base"
  24990. ],
  24991. "Ext.view.BoundListKeyNav": [],
  24992. "Ext.form.FieldSet": [
  24993. "widget.fieldset"
  24994. ],
  24995. "Ext.XTemplateParser": [],
  24996. "Ext.form.field.VTypes": [],
  24997. "Ext.fx.PropertyHandler": [],
  24998. "Ext.form.CheckboxGroup": [
  24999. "widget.checkboxgroup"
  25000. ],
  25001. "Ext.data.JsonP": [],
  25002. "Ext.draw.engine.Vml": [],
  25003. "Ext.layout.container.CheckboxGroup": [
  25004. "layout.checkboxgroup"
  25005. ],
  25006. "Ext.panel.Header": [
  25007. "widget.header"
  25008. ],
  25009. "Ext.app.Controller": [],
  25010. "Ext.grid.plugin.CellEditing": [
  25011. "plugin.cellediting"
  25012. ],
  25013. "Ext.form.field.Time": [
  25014. "widget.timefield"
  25015. ],
  25016. "Ext.fx.CubicBezier": [],
  25017. "Ext.button.Cycle": [
  25018. "widget.cycle"
  25019. ],
  25020. "Ext.data.Tree": [
  25021. "data.tree"
  25022. ],
  25023. "Ext.ModelManager": [],
  25024. "Ext.data.XmlStore": [
  25025. "store.xml"
  25026. ],
  25027. "Ext.grid.ViewDropZone": [],
  25028. "Ext.grid.header.DropZone": [],
  25029. "Ext.Layer": [],
  25030. "Ext.util.HashMap": [],
  25031. "Ext.grid.column.Template": [
  25032. "widget.templatecolumn"
  25033. ],
  25034. "Ext.ComponentLoader": [],
  25035. "Ext.EventObjectImpl": [],
  25036. "Ext.form.FieldAncestor": [],
  25037. "Ext.chart.axis.Gauge": [
  25038. "axis.gauge"
  25039. ],
  25040. "Ext.data.validations": [],
  25041. "Ext.data.Connection": [],
  25042. "Ext.dd.DropZone": [],
  25043. "Ext.direct.ExceptionEvent": [
  25044. "direct.exception"
  25045. ],
  25046. "Ext.resizer.Splitter": [
  25047. "widget.splitter"
  25048. ],
  25049. "Ext.form.RadioManager": [],
  25050. "Ext.data.association.HasOne": [
  25051. "association.hasone"
  25052. ],
  25053. "Ext.draw.Text": [
  25054. "widget.text"
  25055. ],
  25056. "Ext.window.MessageBox": [
  25057. "widget.messagebox"
  25058. ],
  25059. "Ext.fx.target.CompositeElementCSS": [],
  25060. "Ext.chart.series.Line": [
  25061. "series.line"
  25062. ],
  25063. "Ext.view.Table": [
  25064. "widget.tableview"
  25065. ],
  25066. "Ext.data.writer.Json": [
  25067. "writer.json"
  25068. ],
  25069. "Ext.fx.Manager": [],
  25070. "Ext.fx.target.CompositeElement": [],
  25071. "Ext.chart.Label": [],
  25072. "Ext.grid.View": [
  25073. "widget.gridview"
  25074. ],
  25075. "Ext.Action": [],
  25076. "Ext.form.Basic": [],
  25077. "Ext.container.Viewport": [
  25078. "widget.viewport"
  25079. ],
  25080. "Ext.state.Stateful": [],
  25081. "Ext.grid.feature.RowBody": [
  25082. "feature.rowbody"
  25083. ],
  25084. "Ext.form.field.Text": [
  25085. "widget.textfield"
  25086. ],
  25087. "Ext.data.reader.Xml": [
  25088. "reader.xml"
  25089. ],
  25090. "Ext.grid.feature.AbstractSummary": [
  25091. "feature.abstractsummary"
  25092. ],
  25093. "Ext.chart.axis.Category": [
  25094. "axis.category"
  25095. ],
  25096. "Ext.layout.container.Absolute": [
  25097. "layout.absolute"
  25098. ],
  25099. "Ext.data.reader.Json": [
  25100. "reader.json"
  25101. ],
  25102. "Ext.util.TextMetrics": [],
  25103. "Ext.data.TreeStore": [
  25104. "store.tree"
  25105. ],
  25106. "Ext.view.BoundList": [
  25107. "widget.boundlist"
  25108. ],
  25109. "Ext.form.field.HtmlEditor": [
  25110. "widget.htmleditor"
  25111. ],
  25112. "Ext.layout.container.Form": [
  25113. "layout.form"
  25114. ],
  25115. "Ext.chart.MaskLayer": [],
  25116. "Ext.util.Observable": [],
  25117. "Ext.resizer.BorderSplitterTracker": [],
  25118. "Ext.util.LruCache": [],
  25119. "Ext.tip.Tip": [],
  25120. "Ext.dom.CompositeElement": [],
  25121. "Ext.grid.feature.RowWrap": [
  25122. "feature.rowwrap"
  25123. ],
  25124. "Ext.data.proxy.Client": [],
  25125. "Ext.data.Types": [],
  25126. "Ext.draw.SpriteDD": [],
  25127. "Ext.layout.container.boxOverflow.Menu": [],
  25128. "Ext.LoadMask": [
  25129. "widget.loadmask"
  25130. ],
  25131. "Ext.toolbar.Paging": [
  25132. "widget.pagingtoolbar"
  25133. ],
  25134. "Ext.data.association.Association": [],
  25135. "Ext.tree.ViewDropZone": [],
  25136. "Ext.grid.LockingView": [],
  25137. "Ext.toolbar.Toolbar": [
  25138. "widget.toolbar"
  25139. ],
  25140. "Ext.tip.ToolTip": [
  25141. "widget.tooltip"
  25142. ],
  25143. "Ext.chart.Highlight": [],
  25144. "Ext.state.Manager": [],
  25145. "Ext.util.Inflector": [],
  25146. "Ext.grid.Panel": [
  25147. "widget.gridpanel",
  25148. "widget.grid"
  25149. ],
  25150. "Ext.XTemplate": [],
  25151. "Ext.data.NodeStore": [
  25152. "store.node"
  25153. ],
  25154. "Ext.Shadow": [],
  25155. "Ext.form.action.Submit": [
  25156. "formaction.submit"
  25157. ],
  25158. "Ext.form.Panel": [
  25159. "widget.form"
  25160. ],
  25161. "Ext.chart.series.Series": [],
  25162. "Ext.perf.Accumulator": [],
  25163. "Ext.data.Request": [],
  25164. "Ext.dd.DD": [],
  25165. "Ext.dom.CompositeElementLite": [],
  25166. "Ext.toolbar.Fill": [
  25167. "widget.tbfill"
  25168. ],
  25169. "Ext.grid.RowNumberer": [
  25170. "widget.rownumberer"
  25171. ],
  25172. "Ext.data.proxy.WebStorage": [],
  25173. "Ext.util.Floating": [],
  25174. "Ext.form.action.DirectSubmit": [
  25175. "formaction.directsubmit"
  25176. ],
  25177. "Ext.util.Cookies": [],
  25178. "Ext.data.UuidGenerator": [
  25179. "idgen.uuid"
  25180. ],
  25181. "Ext.util.Point": [],
  25182. "Ext.fx.target.Component": [],
  25183. "Ext.form.CheckboxManager": [],
  25184. "Ext.form.field.Field": [],
  25185. "Ext.form.field.Display": [
  25186. "widget.displayfield"
  25187. ],
  25188. "Ext.layout.container.Anchor": [
  25189. "layout.anchor"
  25190. ],
  25191. "Ext.layout.component.field.Text": [
  25192. "layout.textfield"
  25193. ],
  25194. "Ext.data.DirectStore": [
  25195. "store.direct"
  25196. ],
  25197. "Ext.data.BufferStore": [
  25198. "store.buffer"
  25199. ],
  25200. "Ext.grid.ColumnLayout": [
  25201. "layout.gridcolumn"
  25202. ],
  25203. "Ext.chart.series.Column": [
  25204. "series.column"
  25205. ],
  25206. "Ext.Template": [],
  25207. "Ext.AbstractComponent": [],
  25208. "Ext.flash.Component": [
  25209. "widget.flash"
  25210. ],
  25211. "Ext.form.field.Base": [
  25212. "widget.field"
  25213. ],
  25214. "Ext.data.SequentialIdGenerator": [
  25215. "idgen.sequential"
  25216. ],
  25217. "Ext.grid.header.Container": [
  25218. "widget.headercontainer"
  25219. ],
  25220. "Ext.container.ButtonGroup": [
  25221. "widget.buttongroup"
  25222. ],
  25223. "Ext.grid.column.Action": [
  25224. "widget.actioncolumn"
  25225. ],
  25226. "Ext.layout.component.field.Trigger": [
  25227. "layout.triggerfield"
  25228. ],
  25229. "Ext.layout.component.field.FieldContainer": [
  25230. "layout.fieldcontainer"
  25231. ],
  25232. "Ext.chart.Shape": [],
  25233. "Ext.panel.DD": [],
  25234. "Ext.container.AbstractContainer": [],
  25235. "Ext.data.ArrayStore": [
  25236. "store.array"
  25237. ],
  25238. "Ext.window.Window": [
  25239. "widget.window"
  25240. ],
  25241. "Ext.picker.Color": [
  25242. "widget.colorpicker"
  25243. ],
  25244. "Ext.grid.feature.Feature": [
  25245. "feature.feature"
  25246. ],
  25247. "Ext.chart.theme.Theme": [],
  25248. "Ext.util.ClickRepeater": [],
  25249. "Ext.form.field.Spinner": [
  25250. "widget.spinnerfield"
  25251. ],
  25252. "Ext.container.DockingContainer": [],
  25253. "Ext.selection.DataViewModel": [],
  25254. "Ext.dd.DragTracker": [],
  25255. "Ext.dd.DragDropManager": [],
  25256. "Ext.selection.CheckboxModel": [
  25257. "selection.checkboxmodel"
  25258. ],
  25259. "Ext.layout.container.Column": [
  25260. "layout.column"
  25261. ],
  25262. "Ext.menu.KeyNav": [],
  25263. "Ext.draw.Matrix": [],
  25264. "Ext.form.field.Number": [
  25265. "widget.numberfield"
  25266. ],
  25267. "Ext.data.proxy.Direct": [
  25268. "proxy.direct"
  25269. ],
  25270. "Ext.chart.Navigation": [],
  25271. "Ext.slider.Tip": [
  25272. "widget.slidertip"
  25273. ],
  25274. "Ext.chart.theme.Base": [],
  25275. "Ext.form.field.TextArea": [
  25276. "widget.textareafield",
  25277. "widget.textarea"
  25278. ],
  25279. "Ext.form.field.Radio": [
  25280. "widget.radiofield",
  25281. "widget.radio"
  25282. ],
  25283. "Ext.layout.component.ProgressBar": [
  25284. "layout.progressbar"
  25285. ],
  25286. "Ext.chart.series.Pie": [
  25287. "series.pie"
  25288. ],
  25289. "Ext.view.TableChunker": [],
  25290. "Ext.tree.plugin.TreeViewDragDrop": [
  25291. "plugin.treeviewdragdrop"
  25292. ],
  25293. "Ext.direct.Provider": [
  25294. "direct.provider"
  25295. ],
  25296. "Ext.layout.Layout": [],
  25297. "Ext.toolbar.TextItem": [
  25298. "widget.tbtext"
  25299. ],
  25300. "Ext.dom.Helper": [],
  25301. "Ext.util.AbstractMixedCollection": [],
  25302. "Ext.data.JsonStore": [
  25303. "store.json"
  25304. ],
  25305. "Ext.button.Split": [
  25306. "widget.splitbutton"
  25307. ],
  25308. "Ext.dd.DropTarget": [],
  25309. "Ext.direct.RemotingEvent": [
  25310. "direct.rpc"
  25311. ],
  25312. "Ext.draw.Sprite": [],
  25313. "Ext.fx.target.Sprite": [],
  25314. "Ext.data.proxy.LocalStorage": [
  25315. "proxy.localstorage"
  25316. ],
  25317. "Ext.layout.component.Draw": [
  25318. "layout.draw"
  25319. ],
  25320. "Ext.AbstractPlugin": [],
  25321. "Ext.Editor": [
  25322. "widget.editor"
  25323. ],
  25324. "Ext.chart.axis.Radial": [
  25325. "axis.radial"
  25326. ],
  25327. "Ext.chart.Tip": [],
  25328. "Ext.layout.container.Table": [
  25329. "layout.table"
  25330. ],
  25331. "Ext.chart.axis.Abstract": [],
  25332. "Ext.data.proxy.Rest": [
  25333. "proxy.rest"
  25334. ],
  25335. "Ext.util.Queue": [],
  25336. "Ext.state.CookieProvider": [],
  25337. "Ext.Img": [
  25338. "widget.image",
  25339. "widget.imagecomponent"
  25340. ],
  25341. "Ext.dd.DragSource": [],
  25342. "Ext.grid.CellEditor": [],
  25343. "Ext.layout.ClassList": [],
  25344. "Ext.util.Sorter": [],
  25345. "Ext.resizer.SplitterTracker": [],
  25346. "Ext.panel.Table": [
  25347. "widget.tablepanel"
  25348. ],
  25349. "Ext.draw.Color": [],
  25350. "Ext.chart.series.Bar": [
  25351. "series.bar"
  25352. ],
  25353. "Ext.PluginManager": [],
  25354. "Ext.util.ComponentDragger": [],
  25355. "Ext.chart.series.Scatter": [
  25356. "series.scatter"
  25357. ],
  25358. "Ext.chart.Callout": [],
  25359. "Ext.data.Store": [
  25360. "store.store"
  25361. ],
  25362. "Ext.grid.feature.Summary": [
  25363. "feature.summary"
  25364. ],
  25365. "Ext.layout.component.Component": [],
  25366. "Ext.util.ProtoElement": [],
  25367. "Ext.direct.Manager": [],
  25368. "Ext.data.proxy.Proxy": [
  25369. "proxy.proxy"
  25370. ],
  25371. "Ext.menu.CheckItem": [
  25372. "widget.menucheckitem"
  25373. ],
  25374. "Ext.dom.AbstractElement": [],
  25375. "Ext.layout.container.Card": [
  25376. "layout.card"
  25377. ],
  25378. "Ext.draw.Component": [
  25379. "widget.draw"
  25380. ],
  25381. "Ext.toolbar.Item": [
  25382. "widget.tbitem"
  25383. ],
  25384. "Ext.form.RadioGroup": [
  25385. "widget.radiogroup"
  25386. ],
  25387. "Ext.slider.Thumb": [],
  25388. "Ext.grid.header.DragZone": [],
  25389. "Ext.form.action.DirectLoad": [
  25390. "formaction.directload"
  25391. ],
  25392. "Ext.picker.Time": [
  25393. "widget.timepicker"
  25394. ],
  25395. "Ext.resizer.BorderSplitter": [
  25396. "widget.bordersplitter"
  25397. ],
  25398. "Ext.ZIndexManager": [],
  25399. "Ext.menu.ColorPicker": [
  25400. "widget.colormenu"
  25401. ],
  25402. "Ext.menu.Menu": [
  25403. "widget.menu"
  25404. ],
  25405. "Ext.chart.LegendItem": [],
  25406. "Ext.toolbar.Spacer": [
  25407. "widget.tbspacer"
  25408. ],
  25409. "Ext.panel.Panel": [
  25410. "widget.panel"
  25411. ],
  25412. "Ext.util.Memento": [],
  25413. "Ext.data.proxy.Memory": [
  25414. "proxy.memory"
  25415. ],
  25416. "Ext.chart.axis.Time": [
  25417. "axis.time"
  25418. ],
  25419. "Ext.grid.plugin.DragDrop": [
  25420. "plugin.gridviewdragdrop"
  25421. ],
  25422. "Ext.layout.component.Tab": [
  25423. "layout.tab"
  25424. ],
  25425. "Ext.ComponentQuery": [],
  25426. "Ext.draw.engine.SvgExporter": [],
  25427. "Ext.grid.feature.Chunking": [
  25428. "feature.chunking"
  25429. ],
  25430. "Ext.layout.container.Auto": [
  25431. "layout.auto",
  25432. "layout.autocontainer"
  25433. ],
  25434. "Ext.view.AbstractView": [],
  25435. "Ext.util.Region": [],
  25436. "Ext.draw.Draw": [],
  25437. "Ext.fx.target.ElementCSS": [],
  25438. "Ext.grid.PagingScroller": [],
  25439. "Ext.layout.component.field.HtmlEditor": [
  25440. "layout.htmleditor"
  25441. ],
  25442. "Ext.data.proxy.SessionStorage": [
  25443. "proxy.sessionstorage"
  25444. ],
  25445. "Ext.app.EventBus": [],
  25446. "Ext.menu.Separator": [
  25447. "widget.menuseparator"
  25448. ],
  25449. "Ext.util.History": [],
  25450. "Ext.direct.Event": [
  25451. "direct.event"
  25452. ],
  25453. "Ext.direct.RemotingMethod": [],
  25454. "Ext.dd.ScrollManager": [],
  25455. "Ext.chart.Mask": [],
  25456. "Ext.selection.CellModel": [
  25457. "selection.cellmodel"
  25458. ],
  25459. "Ext.view.TableLayout": [
  25460. "layout.tableview"
  25461. ],
  25462. "Ext.state.Provider": [],
  25463. "Ext.layout.container.Editor": [
  25464. "layout.editor"
  25465. ],
  25466. "Ext.data.Errors": [],
  25467. "Ext.dom.AbstractQuery": [],
  25468. "Ext.selection.TreeModel": [
  25469. "selection.treemodel"
  25470. ],
  25471. "Ext.form.Labelable": [],
  25472. "Ext.grid.column.Number": [
  25473. "widget.numbercolumn"
  25474. ],
  25475. "Ext.draw.engine.Svg": [],
  25476. "Ext.grid.property.Grid": [
  25477. "widget.propertygrid"
  25478. ],
  25479. "Ext.FocusManager": [],
  25480. "Ext.AbstractManager": [],
  25481. "Ext.chart.series.Radar": [
  25482. "series.radar"
  25483. ],
  25484. "Ext.grid.property.Property": [],
  25485. "Ext.chart.TipSurface": [],
  25486. "Ext.grid.column.Boolean": [
  25487. "widget.booleancolumn"
  25488. ],
  25489. "Ext.direct.PollingProvider": [
  25490. "direct.pollingprovider"
  25491. ],
  25492. "Ext.grid.plugin.HeaderResizer": [
  25493. "plugin.gridheaderresizer"
  25494. ],
  25495. "Ext.data.writer.Xml": [
  25496. "writer.xml"
  25497. ],
  25498. "Ext.tree.Column": [
  25499. "widget.treecolumn"
  25500. ],
  25501. "Ext.slider.Multi": [
  25502. "widget.multislider"
  25503. ],
  25504. "Ext.panel.AbstractPanel": [],
  25505. "Ext.layout.component.field.Slider": [
  25506. "layout.sliderfield"
  25507. ],
  25508. "Ext.chart.axis.Numeric": [
  25509. "axis.numeric"
  25510. ],
  25511. "Ext.layout.container.boxOverflow.Scroller": [],
  25512. "Ext.data.Operation": [],
  25513. "Ext.layout.container.HBox": [
  25514. "layout.hbox"
  25515. ],
  25516. "Ext.resizer.Resizer": [],
  25517. "Ext.selection.RowModel": [
  25518. "selection.rowmodel"
  25519. ],
  25520. "Ext.layout.ContextItem": [],
  25521. "Ext.util.MixedCollection": [],
  25522. "Ext.perf.Monitor": []
  25523. });