foundation.js 367 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583
  1. /**
  2. * @class Ext
  3. * @singleton
  4. */
  5. var Ext = Ext || {};
  6. Ext._startTime = new Date().getTime();
  7. (function() {
  8. var global = this,
  9. objectPrototype = Object.prototype,
  10. toString = objectPrototype.toString,
  11. enumerables = true,
  12. enumerablesTest = { toString: 1 },
  13. emptyFn = function () {},
  14. // This is the "$previous" method of a hook function on an instance. When called, it
  15. // calls through the class prototype by the name of the called method.
  16. callOverrideParent = function () {
  17. var method = callOverrideParent.caller.caller; // skip callParent (our caller)
  18. return method.$owner.prototype[method.$name].apply(this, arguments);
  19. },
  20. i;
  21. Ext.global = global;
  22. for (i in enumerablesTest) {
  23. enumerables = null;
  24. }
  25. if (enumerables) {
  26. enumerables = ['hasOwnProperty', 'valueOf', 'isPrototypeOf', 'propertyIsEnumerable',
  27. 'toLocaleString', 'toString', 'constructor'];
  28. }
  29. /**
  30. * An array containing extra enumerables for old browsers
  31. * @property {String[]}
  32. */
  33. Ext.enumerables = enumerables;
  34. /**
  35. * Copies all the properties of config to the specified object.
  36. * Note that if recursive merging and cloning without referencing the original objects / arrays is needed, use
  37. * {@link Ext.Object#merge} instead.
  38. * @param {Object} object The receiver of the properties
  39. * @param {Object} config The source of the properties
  40. * @param {Object} [defaults] A different object that will also be applied for default values
  41. * @return {Object} returns obj
  42. */
  43. Ext.apply = function(object, config, defaults) {
  44. if (defaults) {
  45. Ext.apply(object, defaults);
  46. }
  47. if (object && config && typeof config === 'object') {
  48. var i, j, k;
  49. for (i in config) {
  50. object[i] = config[i];
  51. }
  52. if (enumerables) {
  53. for (j = enumerables.length; j--;) {
  54. k = enumerables[j];
  55. if (config.hasOwnProperty(k)) {
  56. object[k] = config[k];
  57. }
  58. }
  59. }
  60. }
  61. return object;
  62. };
  63. Ext.buildSettings = Ext.apply({
  64. baseCSSPrefix: 'x-',
  65. scopeResetCSS: false
  66. }, Ext.buildSettings || {});
  67. Ext.apply(Ext, {
  68. /**
  69. * @property {String} [name='Ext']
  70. * <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>
  71. * <p>This is usually <code>"Ext"</code>, but if a sandboxed build of ExtJS is being used, this will be an alternative name.</p>
  72. * <p>If code is being generated for use by <code>eval</code> or to create a <code>new Function</code>, and the global instance
  73. * of Ext must be referenced, this is the name that should be built into the code.</p>
  74. */
  75. name: Ext.sandboxName || 'Ext',
  76. /**
  77. * A reusable empty function
  78. */
  79. emptyFn: emptyFn,
  80. /**
  81. * A zero length string which will pass a truth test. Useful for passing to methods
  82. * which use a truth test to reject <i>falsy</i> values where a string value must be cleared.
  83. */
  84. emptyString: new String(),
  85. baseCSSPrefix: Ext.buildSettings.baseCSSPrefix,
  86. /**
  87. * Copies all the properties of config to object if they don't already exist.
  88. * @param {Object} object The receiver of the properties
  89. * @param {Object} config The source of the properties
  90. * @return {Object} returns obj
  91. */
  92. applyIf: function(object, config) {
  93. var property;
  94. if (object) {
  95. for (property in config) {
  96. if (object[property] === undefined) {
  97. object[property] = config[property];
  98. }
  99. }
  100. }
  101. return object;
  102. },
  103. /**
  104. * Iterates either an array or an object. This method delegates to
  105. * {@link Ext.Array#each Ext.Array.each} if the given value is iterable, and {@link Ext.Object#each Ext.Object.each} otherwise.
  106. *
  107. * @param {Object/Array} object The object or array to be iterated.
  108. * @param {Function} fn The function to be called for each iteration. See and {@link Ext.Array#each Ext.Array.each} and
  109. * {@link Ext.Object#each Ext.Object.each} for detailed lists of arguments passed to this function depending on the given object
  110. * type that is being iterated.
  111. * @param {Object} scope (Optional) The scope (`this` reference) in which the specified function is executed.
  112. * Defaults to the object being iterated itself.
  113. * @markdown
  114. */
  115. iterate: function(object, fn, scope) {
  116. if (Ext.isEmpty(object)) {
  117. return;
  118. }
  119. if (scope === undefined) {
  120. scope = object;
  121. }
  122. if (Ext.isIterable(object)) {
  123. Ext.Array.each.call(Ext.Array, object, fn, scope);
  124. }
  125. else {
  126. Ext.Object.each.call(Ext.Object, object, fn, scope);
  127. }
  128. }
  129. });
  130. Ext.apply(Ext, {
  131. /**
  132. * This method deprecated. Use {@link Ext#define Ext.define} instead.
  133. * @method
  134. * @param {Function} superclass
  135. * @param {Object} overrides
  136. * @return {Function} The subclass constructor from the <tt>overrides</tt> parameter, or a generated one if not provided.
  137. * @deprecated 4.0.0 Use {@link Ext#define Ext.define} instead
  138. */
  139. extend: (function() {
  140. // inline overrides
  141. var objectConstructor = objectPrototype.constructor,
  142. inlineOverrides = function(o) {
  143. for (var m in o) {
  144. if (!o.hasOwnProperty(m)) {
  145. continue;
  146. }
  147. this[m] = o[m];
  148. }
  149. };
  150. return function(subclass, superclass, overrides) {
  151. // First we check if the user passed in just the superClass with overrides
  152. if (Ext.isObject(superclass)) {
  153. overrides = superclass;
  154. superclass = subclass;
  155. subclass = overrides.constructor !== objectConstructor ? overrides.constructor : function() {
  156. superclass.apply(this, arguments);
  157. };
  158. }
  159. //<debug>
  160. if (!superclass) {
  161. Ext.Error.raise({
  162. sourceClass: 'Ext',
  163. sourceMethod: 'extend',
  164. msg: 'Attempting to extend from a class which has not been loaded on the page.'
  165. });
  166. }
  167. //</debug>
  168. // We create a new temporary class
  169. var F = function() {},
  170. subclassProto, superclassProto = superclass.prototype;
  171. F.prototype = superclassProto;
  172. subclassProto = subclass.prototype = new F();
  173. subclassProto.constructor = subclass;
  174. subclass.superclass = superclassProto;
  175. if (superclassProto.constructor === objectConstructor) {
  176. superclassProto.constructor = superclass;
  177. }
  178. subclass.override = function(overrides) {
  179. Ext.override(subclass, overrides);
  180. };
  181. subclassProto.override = inlineOverrides;
  182. subclassProto.proto = subclassProto;
  183. subclass.override(overrides);
  184. subclass.extend = function(o) {
  185. return Ext.extend(subclass, o);
  186. };
  187. return subclass;
  188. };
  189. }()),
  190. /**
  191. * Overrides members of the specified `target` with the given values.
  192. *
  193. * If the `target` is a class declared using {@link Ext#define Ext.define}, the
  194. * `override` method of that class is called (see {@link Ext.Base#override}) given
  195. * the `overrides`.
  196. *
  197. * If the `target` is a function, it is assumed to be a constructor and the contents
  198. * of `overrides` are applied to its `prototype` using {@link Ext#apply Ext.apply}.
  199. *
  200. * If the `target` is an instance of a class declared using {@link Ext#define Ext.define},
  201. * the `overrides` are applied to only that instance. In this case, methods are
  202. * specially processed to allow them to use {@link Ext.Base#callParent}.
  203. *
  204. * var panel = new Ext.Panel({ ... });
  205. *
  206. * Ext.override(panel, {
  207. * initComponent: function () {
  208. * // extra processing...
  209. *
  210. * this.callParent();
  211. * }
  212. * });
  213. *
  214. * If the `target` is none of these, the `overrides` are applied to the `target`
  215. * using {@link Ext#apply Ext.apply}.
  216. *
  217. * Please refer to {@link Ext#define Ext.define} and {@link Ext.Base#override} for
  218. * further details.
  219. *
  220. * @param {Object} target The target to override.
  221. * @param {Object} overrides The properties to add or replace on `target`.
  222. * @method override
  223. */
  224. override: function (target, overrides) {
  225. if (target.$isClass) {
  226. target.override(overrides);
  227. } else if (typeof target == 'function') {
  228. Ext.apply(target.prototype, overrides);
  229. } else {
  230. var owner = target.self,
  231. name, value;
  232. if (owner && owner.$isClass) { // if (instance of Ext.define'd class)
  233. for (name in overrides) {
  234. if (overrides.hasOwnProperty(name)) {
  235. value = overrides[name];
  236. if (typeof value == 'function') {
  237. //<debug>
  238. if (owner.$className) {
  239. value.displayName = owner.$className + '#' + name;
  240. }
  241. //</debug>
  242. value.$name = name;
  243. value.$owner = owner;
  244. value.$previous = target.hasOwnProperty(name)
  245. ? target[name] // already hooked, so call previous hook
  246. : callOverrideParent; // calls by name on prototype
  247. }
  248. target[name] = value;
  249. }
  250. }
  251. } else {
  252. Ext.apply(target, overrides);
  253. }
  254. }
  255. return target;
  256. }
  257. });
  258. // A full set of static methods to do type checking
  259. Ext.apply(Ext, {
  260. /**
  261. * Returns the given value itself if it's not empty, as described in {@link Ext#isEmpty}; returns the default
  262. * value (second argument) otherwise.
  263. *
  264. * @param {Object} value The value to test
  265. * @param {Object} defaultValue The value to return if the original value is empty
  266. * @param {Boolean} allowBlank (optional) true to allow zero length strings to qualify as non-empty (defaults to false)
  267. * @return {Object} value, if non-empty, else defaultValue
  268. */
  269. valueFrom: function(value, defaultValue, allowBlank){
  270. return Ext.isEmpty(value, allowBlank) ? defaultValue : value;
  271. },
  272. /**
  273. * Returns the type of the given variable in string format. List of possible values are:
  274. *
  275. * - `undefined`: If the given value is `undefined`
  276. * - `null`: If the given value is `null`
  277. * - `string`: If the given value is a string
  278. * - `number`: If the given value is a number
  279. * - `boolean`: If the given value is a boolean value
  280. * - `date`: If the given value is a `Date` object
  281. * - `function`: If the given value is a function reference
  282. * - `object`: If the given value is an object
  283. * - `array`: If the given value is an array
  284. * - `regexp`: If the given value is a regular expression
  285. * - `element`: If the given value is a DOM Element
  286. * - `textnode`: If the given value is a DOM text node and contains something other than whitespace
  287. * - `whitespace`: If the given value is a DOM text node and contains only whitespace
  288. *
  289. * @param {Object} value
  290. * @return {String}
  291. * @markdown
  292. */
  293. typeOf: function(value) {
  294. var type,
  295. typeToString;
  296. if (value === null) {
  297. return 'null';
  298. }
  299. type = typeof value;
  300. if (type === 'undefined' || type === 'string' || type === 'number' || type === 'boolean') {
  301. return type;
  302. }
  303. typeToString = toString.call(value);
  304. switch(typeToString) {
  305. case '[object Array]':
  306. return 'array';
  307. case '[object Date]':
  308. return 'date';
  309. case '[object Boolean]':
  310. return 'boolean';
  311. case '[object Number]':
  312. return 'number';
  313. case '[object RegExp]':
  314. return 'regexp';
  315. }
  316. if (type === 'function') {
  317. return 'function';
  318. }
  319. if (type === 'object') {
  320. if (value.nodeType !== undefined) {
  321. if (value.nodeType === 3) {
  322. return (/\S/).test(value.nodeValue) ? 'textnode' : 'whitespace';
  323. }
  324. else {
  325. return 'element';
  326. }
  327. }
  328. return 'object';
  329. }
  330. //<debug error>
  331. Ext.Error.raise({
  332. sourceClass: 'Ext',
  333. sourceMethod: 'typeOf',
  334. msg: 'Failed to determine the type of the specified value "' + value + '". This is most likely a bug.'
  335. });
  336. //</debug>
  337. },
  338. /**
  339. * Returns true if the passed value is empty, false otherwise. The value is deemed to be empty if it is either:
  340. *
  341. * - `null`
  342. * - `undefined`
  343. * - a zero-length array
  344. * - a zero-length string (Unless the `allowEmptyString` parameter is set to `true`)
  345. *
  346. * @param {Object} value The value to test
  347. * @param {Boolean} allowEmptyString (optional) true to allow empty strings (defaults to false)
  348. * @return {Boolean}
  349. * @markdown
  350. */
  351. isEmpty: function(value, allowEmptyString) {
  352. return (value === null) || (value === undefined) || (!allowEmptyString ? value === '' : false) || (Ext.isArray(value) && value.length === 0);
  353. },
  354. /**
  355. * Returns true if the passed value is a JavaScript Array, false otherwise.
  356. *
  357. * @param {Object} target The target to test
  358. * @return {Boolean}
  359. * @method
  360. */
  361. isArray: ('isArray' in Array) ? Array.isArray : function(value) {
  362. return toString.call(value) === '[object Array]';
  363. },
  364. /**
  365. * Returns true if the passed value is a JavaScript Date object, false otherwise.
  366. * @param {Object} object The object to test
  367. * @return {Boolean}
  368. */
  369. isDate: function(value) {
  370. return toString.call(value) === '[object Date]';
  371. },
  372. /**
  373. * Returns true if the passed value is a JavaScript Object, false otherwise.
  374. * @param {Object} value The value to test
  375. * @return {Boolean}
  376. * @method
  377. */
  378. isObject: (toString.call(null) === '[object Object]') ?
  379. function(value) {
  380. // check ownerDocument here as well to exclude DOM nodes
  381. return value !== null && value !== undefined && toString.call(value) === '[object Object]' && value.ownerDocument === undefined;
  382. } :
  383. function(value) {
  384. return toString.call(value) === '[object Object]';
  385. },
  386. /**
  387. * @private
  388. */
  389. isSimpleObject: function(value) {
  390. return value instanceof Object && value.constructor === Object;
  391. },
  392. /**
  393. * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.
  394. * @param {Object} value The value to test
  395. * @return {Boolean}
  396. */
  397. isPrimitive: function(value) {
  398. var type = typeof value;
  399. return type === 'string' || type === 'number' || type === 'boolean';
  400. },
  401. /**
  402. * Returns true if the passed value is a JavaScript Function, false otherwise.
  403. * @param {Object} value The value to test
  404. * @return {Boolean}
  405. * @method
  406. */
  407. isFunction:
  408. // Safari 3.x and 4.x returns 'function' for typeof <NodeList>, hence we need to fall back to using
  409. // Object.prototype.toString (slower)
  410. (typeof document !== 'undefined' && typeof document.getElementsByTagName('body') === 'function') ? function(value) {
  411. return toString.call(value) === '[object Function]';
  412. } : function(value) {
  413. return typeof value === 'function';
  414. },
  415. /**
  416. * Returns true if the passed value is a number. Returns false for non-finite numbers.
  417. * @param {Object} value The value to test
  418. * @return {Boolean}
  419. */
  420. isNumber: function(value) {
  421. return typeof value === 'number' && isFinite(value);
  422. },
  423. /**
  424. * Validates that a value is numeric.
  425. * @param {Object} value Examples: 1, '1', '2.34'
  426. * @return {Boolean} True if numeric, false otherwise
  427. */
  428. isNumeric: function(value) {
  429. return !isNaN(parseFloat(value)) && isFinite(value);
  430. },
  431. /**
  432. * Returns true if the passed value is a string.
  433. * @param {Object} value The value to test
  434. * @return {Boolean}
  435. */
  436. isString: function(value) {
  437. return typeof value === 'string';
  438. },
  439. /**
  440. * Returns true if the passed value is a boolean.
  441. *
  442. * @param {Object} value The value to test
  443. * @return {Boolean}
  444. */
  445. isBoolean: function(value) {
  446. return typeof value === 'boolean';
  447. },
  448. /**
  449. * Returns true if the passed value is an HTMLElement
  450. * @param {Object} value The value to test
  451. * @return {Boolean}
  452. */
  453. isElement: function(value) {
  454. return value ? value.nodeType === 1 : false;
  455. },
  456. /**
  457. * Returns true if the passed value is a TextNode
  458. * @param {Object} value The value to test
  459. * @return {Boolean}
  460. */
  461. isTextNode: function(value) {
  462. return value ? value.nodeName === "#text" : false;
  463. },
  464. /**
  465. * Returns true if the passed value is defined.
  466. * @param {Object} value The value to test
  467. * @return {Boolean}
  468. */
  469. isDefined: function(value) {
  470. return typeof value !== 'undefined';
  471. },
  472. /**
  473. * Returns true if the passed value is iterable, false otherwise
  474. * @param {Object} value The value to test
  475. * @return {Boolean}
  476. */
  477. isIterable: function(value) {
  478. var type = typeof value,
  479. checkLength = false;
  480. if (value && type != 'string') {
  481. // Functions have a length property, so we need to filter them out
  482. if (type == 'function') {
  483. // In Safari, NodeList/HTMLCollection both return "function" when using typeof, so we need
  484. // to explicitly check them here.
  485. if (Ext.isSafari) {
  486. checkLength = value instanceof NodeList || value instanceof HTMLCollection;
  487. }
  488. } else {
  489. checkLength = true;
  490. }
  491. }
  492. return checkLength ? value.length !== undefined : false;
  493. }
  494. });
  495. Ext.apply(Ext, {
  496. /**
  497. * Clone simple variables including array, {}-like objects, DOM nodes and Date without keeping the old reference.
  498. * A reference for the object itself is returned if it's not a direct decendant of Object. For model cloning,
  499. * see {@link Ext.data.Model#copy Model.copy}.
  500. *
  501. * @param {Object} item The variable to clone
  502. * @return {Object} clone
  503. */
  504. clone: function(item) {
  505. var type,
  506. i,
  507. j,
  508. k,
  509. clone,
  510. key;
  511. if (item === null || item === undefined) {
  512. return item;
  513. }
  514. // DOM nodes
  515. // TODO proxy this to Ext.Element.clone to handle automatic id attribute changing
  516. // recursively
  517. if (item.nodeType && item.cloneNode) {
  518. return item.cloneNode(true);
  519. }
  520. type = toString.call(item);
  521. // Date
  522. if (type === '[object Date]') {
  523. return new Date(item.getTime());
  524. }
  525. // Array
  526. if (type === '[object Array]') {
  527. i = item.length;
  528. clone = [];
  529. while (i--) {
  530. clone[i] = Ext.clone(item[i]);
  531. }
  532. }
  533. // Object
  534. else if (type === '[object Object]' && item.constructor === Object) {
  535. clone = {};
  536. for (key in item) {
  537. clone[key] = Ext.clone(item[key]);
  538. }
  539. if (enumerables) {
  540. for (j = enumerables.length; j--;) {
  541. k = enumerables[j];
  542. clone[k] = item[k];
  543. }
  544. }
  545. }
  546. return clone || item;
  547. },
  548. /**
  549. * @private
  550. * Generate a unique reference of Ext in the global scope, useful for sandboxing
  551. */
  552. getUniqueGlobalNamespace: function() {
  553. var uniqueGlobalNamespace = this.uniqueGlobalNamespace,
  554. i;
  555. if (uniqueGlobalNamespace === undefined) {
  556. i = 0;
  557. do {
  558. uniqueGlobalNamespace = 'ExtBox' + (++i);
  559. } while (Ext.global[uniqueGlobalNamespace] !== undefined);
  560. Ext.global[uniqueGlobalNamespace] = Ext;
  561. this.uniqueGlobalNamespace = uniqueGlobalNamespace;
  562. }
  563. return uniqueGlobalNamespace;
  564. },
  565. /**
  566. * @private
  567. */
  568. functionFactoryCache: {},
  569. cacheableFunctionFactory: function() {
  570. var me = this,
  571. args = Array.prototype.slice.call(arguments),
  572. cache = me.functionFactoryCache,
  573. idx, fn, ln;
  574. if (Ext.isSandboxed) {
  575. ln = args.length;
  576. if (ln > 0) {
  577. ln--;
  578. args[ln] = 'var Ext=window.' + Ext.name + ';' + args[ln];
  579. }
  580. }
  581. idx = args.join('');
  582. fn = cache[idx];
  583. if (!fn) {
  584. fn = Function.prototype.constructor.apply(Function.prototype, args);
  585. cache[idx] = fn;
  586. }
  587. return fn;
  588. },
  589. functionFactory: function() {
  590. var me = this,
  591. args = Array.prototype.slice.call(arguments),
  592. ln;
  593. if (Ext.isSandboxed) {
  594. ln = args.length;
  595. if (ln > 0) {
  596. ln--;
  597. args[ln] = 'var Ext=window.' + Ext.name + ';' + args[ln];
  598. }
  599. }
  600. return Function.prototype.constructor.apply(Function.prototype, args);
  601. },
  602. /**
  603. * @private
  604. * @property
  605. */
  606. Logger: {
  607. verbose: emptyFn,
  608. log: emptyFn,
  609. info: emptyFn,
  610. warn: emptyFn,
  611. error: function(message) {
  612. throw new Error(message);
  613. },
  614. deprecate: emptyFn
  615. }
  616. });
  617. /**
  618. * Old alias to {@link Ext#typeOf}
  619. * @deprecated 4.0.0 Use {@link Ext#typeOf} instead
  620. * @method
  621. * @inheritdoc Ext#typeOf
  622. */
  623. Ext.type = Ext.typeOf;
  624. }());
  625. /*
  626. * This method evaluates the given code free of any local variable. In some browsers this
  627. * will be at global scope, in others it will be in a function.
  628. * @parma {String} code The code to evaluate.
  629. * @private
  630. * @method
  631. */
  632. Ext.globalEval = Ext.global.execScript
  633. ? function(code) {
  634. execScript(code);
  635. }
  636. : function($$code) {
  637. // IMPORTANT: because we use eval we cannot place this in the above function or it
  638. // will break the compressor's ability to rename local variables...
  639. (function(){
  640. eval($$code);
  641. }());
  642. };
  643. /**
  644. * @author Jacky Nguyen <jacky@sencha.com>
  645. * @docauthor Jacky Nguyen <jacky@sencha.com>
  646. * @class Ext.Version
  647. *
  648. * A utility class that wrap around a string version number and provide convenient
  649. * method to perform comparison. See also: {@link Ext.Version#compare compare}. Example:
  650. *
  651. * var version = new Ext.Version('1.0.2beta');
  652. * console.log("Version is " + version); // Version is 1.0.2beta
  653. *
  654. * console.log(version.getMajor()); // 1
  655. * console.log(version.getMinor()); // 0
  656. * console.log(version.getPatch()); // 2
  657. * console.log(version.getBuild()); // 0
  658. * console.log(version.getRelease()); // beta
  659. *
  660. * console.log(version.isGreaterThan('1.0.1')); // True
  661. * console.log(version.isGreaterThan('1.0.2alpha')); // True
  662. * console.log(version.isGreaterThan('1.0.2RC')); // False
  663. * console.log(version.isGreaterThan('1.0.2')); // False
  664. * console.log(version.isLessThan('1.0.2')); // True
  665. *
  666. * console.log(version.match(1.0)); // True
  667. * console.log(version.match('1.0.2')); // True
  668. *
  669. */
  670. (function() {
  671. // Current core version
  672. var version = '4.1.1', Version;
  673. Ext.Version = Version = Ext.extend(Object, {
  674. /**
  675. * @param {String/Number} version The version number in the following standard format:
  676. *
  677. * major[.minor[.patch[.build[release]]]]
  678. *
  679. * Examples:
  680. *
  681. * 1.0
  682. * 1.2.3beta
  683. * 1.2.3.4RC
  684. *
  685. * @return {Ext.Version} this
  686. */
  687. constructor: function(version) {
  688. var parts, releaseStartIndex;
  689. if (version instanceof Version) {
  690. return version;
  691. }
  692. this.version = this.shortVersion = String(version).toLowerCase().replace(/_/g, '.').replace(/[\-+]/g, '');
  693. releaseStartIndex = this.version.search(/([^\d\.])/);
  694. if (releaseStartIndex !== -1) {
  695. this.release = this.version.substr(releaseStartIndex, version.length);
  696. this.shortVersion = this.version.substr(0, releaseStartIndex);
  697. }
  698. this.shortVersion = this.shortVersion.replace(/[^\d]/g, '');
  699. parts = this.version.split('.');
  700. this.major = parseInt(parts.shift() || 0, 10);
  701. this.minor = parseInt(parts.shift() || 0, 10);
  702. this.patch = parseInt(parts.shift() || 0, 10);
  703. this.build = parseInt(parts.shift() || 0, 10);
  704. return this;
  705. },
  706. /**
  707. * Override the native toString method
  708. * @private
  709. * @return {String} version
  710. */
  711. toString: function() {
  712. return this.version;
  713. },
  714. /**
  715. * Override the native valueOf method
  716. * @private
  717. * @return {String} version
  718. */
  719. valueOf: function() {
  720. return this.version;
  721. },
  722. /**
  723. * Returns the major component value
  724. * @return {Number} major
  725. */
  726. getMajor: function() {
  727. return this.major || 0;
  728. },
  729. /**
  730. * Returns the minor component value
  731. * @return {Number} minor
  732. */
  733. getMinor: function() {
  734. return this.minor || 0;
  735. },
  736. /**
  737. * Returns the patch component value
  738. * @return {Number} patch
  739. */
  740. getPatch: function() {
  741. return this.patch || 0;
  742. },
  743. /**
  744. * Returns the build component value
  745. * @return {Number} build
  746. */
  747. getBuild: function() {
  748. return this.build || 0;
  749. },
  750. /**
  751. * Returns the release component value
  752. * @return {Number} release
  753. */
  754. getRelease: function() {
  755. return this.release || '';
  756. },
  757. /**
  758. * Returns whether this version if greater than the supplied argument
  759. * @param {String/Number} target The version to compare with
  760. * @return {Boolean} True if this version if greater than the target, false otherwise
  761. */
  762. isGreaterThan: function(target) {
  763. return Version.compare(this.version, target) === 1;
  764. },
  765. /**
  766. * Returns whether this version if greater than or equal to the supplied argument
  767. * @param {String/Number} target The version to compare with
  768. * @return {Boolean} True if this version if greater than or equal to the target, false otherwise
  769. */
  770. isGreaterThanOrEqual: function(target) {
  771. return Version.compare(this.version, target) >= 0;
  772. },
  773. /**
  774. * Returns whether this version if smaller than the supplied argument
  775. * @param {String/Number} target The version to compare with
  776. * @return {Boolean} True if this version if smaller than the target, false otherwise
  777. */
  778. isLessThan: function(target) {
  779. return Version.compare(this.version, target) === -1;
  780. },
  781. /**
  782. * Returns whether this version if less than or equal to the supplied argument
  783. * @param {String/Number} target The version to compare with
  784. * @return {Boolean} True if this version if less than or equal to the target, false otherwise
  785. */
  786. isLessThanOrEqual: function(target) {
  787. return Version.compare(this.version, target) <= 0;
  788. },
  789. /**
  790. * Returns whether this version equals to the supplied argument
  791. * @param {String/Number} target The version to compare with
  792. * @return {Boolean} True if this version equals to the target, false otherwise
  793. */
  794. equals: function(target) {
  795. return Version.compare(this.version, target) === 0;
  796. },
  797. /**
  798. * Returns whether this version matches the supplied argument. Example:
  799. *
  800. * var version = new Ext.Version('1.0.2beta');
  801. * console.log(version.match(1)); // True
  802. * console.log(version.match(1.0)); // True
  803. * console.log(version.match('1.0.2')); // True
  804. * console.log(version.match('1.0.2RC')); // False
  805. *
  806. * @param {String/Number} target The version to compare with
  807. * @return {Boolean} True if this version matches the target, false otherwise
  808. */
  809. match: function(target) {
  810. target = String(target);
  811. return this.version.substr(0, target.length) === target;
  812. },
  813. /**
  814. * Returns this format: [major, minor, patch, build, release]. Useful for comparison
  815. * @return {Number[]}
  816. */
  817. toArray: function() {
  818. return [this.getMajor(), this.getMinor(), this.getPatch(), this.getBuild(), this.getRelease()];
  819. },
  820. /**
  821. * Returns shortVersion version without dots and release
  822. * @return {String}
  823. */
  824. getShortVersion: function() {
  825. return this.shortVersion;
  826. },
  827. /**
  828. * Convenient alias to {@link Ext.Version#isGreaterThan isGreaterThan}
  829. * @param {String/Number} target
  830. * @return {Boolean}
  831. */
  832. gt: function() {
  833. return this.isGreaterThan.apply(this, arguments);
  834. },
  835. /**
  836. * Convenient alias to {@link Ext.Version#isLessThan isLessThan}
  837. * @param {String/Number} target
  838. * @return {Boolean}
  839. */
  840. lt: function() {
  841. return this.isLessThan.apply(this, arguments);
  842. },
  843. /**
  844. * Convenient alias to {@link Ext.Version#isGreaterThanOrEqual isGreaterThanOrEqual}
  845. * @param {String/Number} target
  846. * @return {Boolean}
  847. */
  848. gtEq: function() {
  849. return this.isGreaterThanOrEqual.apply(this, arguments);
  850. },
  851. /**
  852. * Convenient alias to {@link Ext.Version#isLessThanOrEqual isLessThanOrEqual}
  853. * @param {String/Number} target
  854. * @return {Boolean}
  855. */
  856. ltEq: function() {
  857. return this.isLessThanOrEqual.apply(this, arguments);
  858. }
  859. });
  860. Ext.apply(Version, {
  861. // @private
  862. releaseValueMap: {
  863. 'dev': -6,
  864. 'alpha': -5,
  865. 'a': -5,
  866. 'beta': -4,
  867. 'b': -4,
  868. 'rc': -3,
  869. '#': -2,
  870. 'p': -1,
  871. 'pl': -1
  872. },
  873. /**
  874. * Converts a version component to a comparable value
  875. *
  876. * @static
  877. * @param {Object} value The value to convert
  878. * @return {Object}
  879. */
  880. getComponentValue: function(value) {
  881. return !value ? 0 : (isNaN(value) ? this.releaseValueMap[value] || value : parseInt(value, 10));
  882. },
  883. /**
  884. * Compare 2 specified versions, starting from left to right. If a part contains special version strings,
  885. * they are handled in the following order:
  886. * 'dev' < 'alpha' = 'a' < 'beta' = 'b' < 'RC' = 'rc' < '#' < 'pl' = 'p' < 'anything else'
  887. *
  888. * @static
  889. * @param {String} current The current version to compare to
  890. * @param {String} target The target version to compare to
  891. * @return {Number} Returns -1 if the current version is smaller than the target version, 1 if greater, and 0 if they're equivalent
  892. */
  893. compare: function(current, target) {
  894. var currentValue, targetValue, i;
  895. current = new Version(current).toArray();
  896. target = new Version(target).toArray();
  897. for (i = 0; i < Math.max(current.length, target.length); i++) {
  898. currentValue = this.getComponentValue(current[i]);
  899. targetValue = this.getComponentValue(target[i]);
  900. if (currentValue < targetValue) {
  901. return -1;
  902. } else if (currentValue > targetValue) {
  903. return 1;
  904. }
  905. }
  906. return 0;
  907. }
  908. });
  909. /**
  910. * @class Ext
  911. */
  912. Ext.apply(Ext, {
  913. /**
  914. * @private
  915. */
  916. versions: {},
  917. /**
  918. * @private
  919. */
  920. lastRegisteredVersion: null,
  921. /**
  922. * Set version number for the given package name.
  923. *
  924. * @param {String} packageName The package name, for example: 'core', 'touch', 'extjs'
  925. * @param {String/Ext.Version} version The version, for example: '1.2.3alpha', '2.4.0-dev'
  926. * @return {Ext}
  927. */
  928. setVersion: function(packageName, version) {
  929. Ext.versions[packageName] = new Version(version);
  930. Ext.lastRegisteredVersion = Ext.versions[packageName];
  931. return this;
  932. },
  933. /**
  934. * Get the version number of the supplied package name; will return the last registered version
  935. * (last Ext.setVersion call) if there's no package name given.
  936. *
  937. * @param {String} packageName (Optional) The package name, for example: 'core', 'touch', 'extjs'
  938. * @return {Ext.Version} The version
  939. */
  940. getVersion: function(packageName) {
  941. if (packageName === undefined) {
  942. return Ext.lastRegisteredVersion;
  943. }
  944. return Ext.versions[packageName];
  945. },
  946. /**
  947. * Create a closure for deprecated code.
  948. *
  949. * // This means Ext.oldMethod is only supported in 4.0.0beta and older.
  950. * // If Ext.getVersion('extjs') returns a version that is later than '4.0.0beta', for example '4.0.0RC',
  951. * // the closure will not be invoked
  952. * Ext.deprecate('extjs', '4.0.0beta', function() {
  953. * Ext.oldMethod = Ext.newMethod;
  954. *
  955. * ...
  956. * });
  957. *
  958. * @param {String} packageName The package name
  959. * @param {String} since The last version before it's deprecated
  960. * @param {Function} closure The callback function to be executed with the specified version is less than the current version
  961. * @param {Object} scope The execution scope (`this`) if the closure
  962. */
  963. deprecate: function(packageName, since, closure, scope) {
  964. if (Version.compare(Ext.getVersion(packageName), since) < 1) {
  965. closure.call(scope);
  966. }
  967. }
  968. }); // End Versioning
  969. Ext.setVersion('core', version);
  970. }());
  971. /**
  972. * @class Ext.String
  973. *
  974. * A collection of useful static methods to deal with strings
  975. * @singleton
  976. */
  977. Ext.String = (function() {
  978. 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,
  979. escapeRe = /('|\\)/g,
  980. formatRe = /\{(\d+)\}/g,
  981. escapeRegexRe = /([-.*+?\^${}()|\[\]\/\\])/g,
  982. basicTrimRe = /^\s+|\s+$/g,
  983. whitespaceRe = /\s+/,
  984. varReplace = /(^[^a-z]*|[^\w])/gi,
  985. charToEntity,
  986. entityToChar,
  987. charToEntityRegex,
  988. entityToCharRegex,
  989. htmlEncodeReplaceFn = function(match, capture) {
  990. return charToEntity[capture];
  991. },
  992. htmlDecodeReplaceFn = function(match, capture) {
  993. return (capture in entityToChar) ? entityToChar[capture] : String.fromCharCode(parseInt(capture.substr(2), 10));
  994. };
  995. return {
  996. /**
  997. * Converts a string of characters into a legal, parseable Javascript `var` name as long as the passed
  998. * string contains at least one alphabetic character. Non alphanumeric characters, and *leading* non alphabetic
  999. * characters will be removed.
  1000. * @param {String} s A string to be converted into a `var` name.
  1001. * @return {String} A legal Javascript `var` name.
  1002. */
  1003. createVarName: function(s) {
  1004. return s.replace(varReplace, '');
  1005. },
  1006. /**
  1007. * Convert certain characters (&, <, >, ', and ") to their HTML character equivalents for literal display in web pages.
  1008. * @param {String} value The string to encode
  1009. * @return {String} The encoded text
  1010. * @method
  1011. */
  1012. htmlEncode: function(value) {
  1013. return (!value) ? value : String(value).replace(charToEntityRegex, htmlEncodeReplaceFn);
  1014. },
  1015. /**
  1016. * Convert certain characters (&, <, >, ', and ") from their HTML character equivalents.
  1017. * @param {String} value The string to decode
  1018. * @return {String} The decoded text
  1019. * @method
  1020. */
  1021. htmlDecode: function(value) {
  1022. return (!value) ? value : String(value).replace(entityToCharRegex, htmlDecodeReplaceFn);
  1023. },
  1024. /**
  1025. * Adds a set of character entity definitions to the set used by
  1026. * {@link Ext.String#htmlEncode} and {@link Ext.String#htmlDecode}.
  1027. *
  1028. * This object should be keyed by the entity name sequence,
  1029. * with the value being the textual representation of the entity.
  1030. *
  1031. * Ext.String.addCharacterEntities({
  1032. * '&amp;Uuml;':'Ü',
  1033. * '&amp;ccedil;':'ç',
  1034. * '&amp;ntilde;':'ñ',
  1035. * '&amp;egrave;':'è'
  1036. * });
  1037. * var s = Ext.String.htmlEncode("A string with entities: èÜçñ");
  1038. *
  1039. * Note: the values of the character entites defined on this object are expected
  1040. * to be single character values. As such, the actual values represented by the
  1041. * characters are sensitive to the character encoding of the javascript source
  1042. * file when defined in string literal form. Script tasgs referencing server
  1043. * resources with character entities must ensure that the 'charset' attribute
  1044. * of the script node is consistent with the actual character encoding of the
  1045. * server resource.
  1046. *
  1047. * The set of character entities may be reset back to the default state by using
  1048. * the {@link Ext.String#resetCharacterEntities} method
  1049. *
  1050. * @param {Object} entities The set of character entities to add to the current
  1051. * definitions.
  1052. */
  1053. addCharacterEntities: function(newEntities) {
  1054. var charKeys = [],
  1055. entityKeys = [],
  1056. key, echar;
  1057. for (key in newEntities) {
  1058. echar = newEntities[key];
  1059. entityToChar[key] = echar;
  1060. charToEntity[echar] = key;
  1061. charKeys.push(echar);
  1062. entityKeys.push(key);
  1063. }
  1064. charToEntityRegex = new RegExp('(' + charKeys.join('|') + ')', 'g');
  1065. entityToCharRegex = new RegExp('(' + entityKeys.join('|') + '|&#[0-9]{1,5};' + ')', 'g');
  1066. },
  1067. /**
  1068. * Resets the set of character entity definitions used by
  1069. * {@link Ext.String#htmlEncode} and {@link Ext.String#htmlDecode} back to the
  1070. * default state.
  1071. */
  1072. resetCharacterEntities: function() {
  1073. charToEntity = {};
  1074. entityToChar = {};
  1075. // add the default set
  1076. this.addCharacterEntities({
  1077. '&amp;' : '&',
  1078. '&gt;' : '>',
  1079. '&lt;' : '<',
  1080. '&quot;' : '"',
  1081. '&#39;' : "'"
  1082. });
  1083. },
  1084. /**
  1085. * Appends content to the query string of a URL, handling logic for whether to place
  1086. * a question mark or ampersand.
  1087. * @param {String} url The URL to append to.
  1088. * @param {String} string The content to append to the URL.
  1089. * @return {String} The resulting URL
  1090. */
  1091. urlAppend : function(url, string) {
  1092. if (!Ext.isEmpty(string)) {
  1093. return url + (url.indexOf('?') === -1 ? '?' : '&') + string;
  1094. }
  1095. return url;
  1096. },
  1097. /**
  1098. * Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
  1099. * @example
  1100. var s = ' foo bar ';
  1101. alert('-' + s + '-'); //alerts "- foo bar -"
  1102. alert('-' + Ext.String.trim(s) + '-'); //alerts "-foo bar-"
  1103. * @param {String} string The string to escape
  1104. * @return {String} The trimmed string
  1105. */
  1106. trim: function(string) {
  1107. return string.replace(trimRegex, "");
  1108. },
  1109. /**
  1110. * Capitalize the given string
  1111. * @param {String} string
  1112. * @return {String}
  1113. */
  1114. capitalize: function(string) {
  1115. return string.charAt(0).toUpperCase() + string.substr(1);
  1116. },
  1117. /**
  1118. * Uncapitalize the given string
  1119. * @param {String} string
  1120. * @return {String}
  1121. */
  1122. uncapitalize: function(string) {
  1123. return string.charAt(0).toLowerCase() + string.substr(1);
  1124. },
  1125. /**
  1126. * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
  1127. * @param {String} value The string to truncate
  1128. * @param {Number} length The maximum length to allow before truncating
  1129. * @param {Boolean} word True to try to find a common word break
  1130. * @return {String} The converted text
  1131. */
  1132. ellipsis: function(value, len, word) {
  1133. if (value && value.length > len) {
  1134. if (word) {
  1135. var vs = value.substr(0, len - 2),
  1136. index = Math.max(vs.lastIndexOf(' '), vs.lastIndexOf('.'), vs.lastIndexOf('!'), vs.lastIndexOf('?'));
  1137. if (index !== -1 && index >= (len - 15)) {
  1138. return vs.substr(0, index) + "...";
  1139. }
  1140. }
  1141. return value.substr(0, len - 3) + "...";
  1142. }
  1143. return value;
  1144. },
  1145. /**
  1146. * Escapes the passed string for use in a regular expression
  1147. * @param {String} string
  1148. * @return {String}
  1149. */
  1150. escapeRegex: function(string) {
  1151. return string.replace(escapeRegexRe, "\\$1");
  1152. },
  1153. /**
  1154. * Escapes the passed string for ' and \
  1155. * @param {String} string The string to escape
  1156. * @return {String} The escaped string
  1157. */
  1158. escape: function(string) {
  1159. return string.replace(escapeRe, "\\$1");
  1160. },
  1161. /**
  1162. * Utility function that allows you to easily switch a string between two alternating values. The passed value
  1163. * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
  1164. * they are already different, the first value passed in is returned. Note that this method returns the new value
  1165. * but does not change the current string.
  1166. * <pre><code>
  1167. // alternate sort directions
  1168. sort = Ext.String.toggle(sort, 'ASC', 'DESC');
  1169. // instead of conditional logic:
  1170. sort = (sort == 'ASC' ? 'DESC' : 'ASC');
  1171. </code></pre>
  1172. * @param {String} string The current string
  1173. * @param {String} value The value to compare to the current string
  1174. * @param {String} other The new value to use if the string already equals the first value passed in
  1175. * @return {String} The new value
  1176. */
  1177. toggle: function(string, value, other) {
  1178. return string === value ? other : value;
  1179. },
  1180. /**
  1181. * Pads the left side of a string with a specified character. This is especially useful
  1182. * for normalizing number and date strings. Example usage:
  1183. *
  1184. * <pre><code>
  1185. var s = Ext.String.leftPad('123', 5, '0');
  1186. // s now contains the string: '00123'
  1187. </code></pre>
  1188. * @param {String} string The original string
  1189. * @param {Number} size The total length of the output string
  1190. * @param {String} character (optional) The character with which to pad the original string (defaults to empty string " ")
  1191. * @return {String} The padded string
  1192. */
  1193. leftPad: function(string, size, character) {
  1194. var result = String(string);
  1195. character = character || " ";
  1196. while (result.length < size) {
  1197. result = character + result;
  1198. }
  1199. return result;
  1200. },
  1201. /**
  1202. * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
  1203. * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
  1204. * <pre><code>
  1205. var cls = 'my-class', text = 'Some text';
  1206. var s = Ext.String.format('&lt;div class="{0}">{1}&lt;/div>', cls, text);
  1207. // s now contains the string: '&lt;div class="my-class">Some text&lt;/div>'
  1208. </code></pre>
  1209. * @param {String} string The tokenized string to be formatted
  1210. * @param {String} value1 The value to replace token {0}
  1211. * @param {String} value2 Etc...
  1212. * @return {String} The formatted string
  1213. */
  1214. format: function(format) {
  1215. var args = Ext.Array.toArray(arguments, 1);
  1216. return format.replace(formatRe, function(m, i) {
  1217. return args[i];
  1218. });
  1219. },
  1220. /**
  1221. * Returns a string with a specified number of repititions a given string pattern.
  1222. * The pattern be separated by a different string.
  1223. *
  1224. * var s = Ext.String.repeat('---', 4); // = '------------'
  1225. * var t = Ext.String.repeat('--', 3, '/'); // = '--/--/--'
  1226. *
  1227. * @param {String} pattern The pattern to repeat.
  1228. * @param {Number} count The number of times to repeat the pattern (may be 0).
  1229. * @param {String} sep An option string to separate each pattern.
  1230. */
  1231. repeat: function(pattern, count, sep) {
  1232. for (var buf = [], i = count; i--; ) {
  1233. buf.push(pattern);
  1234. }
  1235. return buf.join(sep || '');
  1236. },
  1237. /**
  1238. * Splits a string of space separated words into an array, trimming as needed. If the
  1239. * words are already an array, it is returned.
  1240. *
  1241. * @param {String/Array} words
  1242. */
  1243. splitWords: function (words) {
  1244. if (words && typeof words == 'string') {
  1245. return words.replace(basicTrimRe, '').split(whitespaceRe);
  1246. }
  1247. return words || [];
  1248. }
  1249. };
  1250. }());
  1251. // initialize the default encode / decode entities
  1252. Ext.String.resetCharacterEntities();
  1253. /**
  1254. * Old alias to {@link Ext.String#htmlEncode}
  1255. * @deprecated Use {@link Ext.String#htmlEncode} instead
  1256. * @method
  1257. * @member Ext
  1258. * @inheritdoc Ext.String#htmlEncode
  1259. */
  1260. Ext.htmlEncode = Ext.String.htmlEncode;
  1261. /**
  1262. * Old alias to {@link Ext.String#htmlDecode}
  1263. * @deprecated Use {@link Ext.String#htmlDecode} instead
  1264. * @method
  1265. * @member Ext
  1266. * @inheritdoc Ext.String#htmlDecode
  1267. */
  1268. Ext.htmlDecode = Ext.String.htmlDecode;
  1269. /**
  1270. * Old alias to {@link Ext.String#urlAppend}
  1271. * @deprecated Use {@link Ext.String#urlAppend} instead
  1272. * @method
  1273. * @member Ext
  1274. * @inheritdoc Ext.String#urlAppend
  1275. */
  1276. Ext.urlAppend = Ext.String.urlAppend;
  1277. /**
  1278. * @class Ext.Number
  1279. *
  1280. * A collection of useful static methods to deal with numbers
  1281. * @singleton
  1282. */
  1283. Ext.Number = new function() {
  1284. var me = this,
  1285. isToFixedBroken = (0.9).toFixed() !== '1',
  1286. math = Math;
  1287. Ext.apply(this, {
  1288. /**
  1289. * Checks whether or not the passed number is within a desired range. If the number is already within the
  1290. * range it is returned, otherwise the min or max value is returned depending on which side of the range is
  1291. * exceeded. Note that this method returns the constrained value but does not change the current number.
  1292. * @param {Number} number The number to check
  1293. * @param {Number} min The minimum number in the range
  1294. * @param {Number} max The maximum number in the range
  1295. * @return {Number} The constrained value if outside the range, otherwise the current value
  1296. */
  1297. constrain: function(number, min, max) {
  1298. var x = parseFloat(number);
  1299. // Watch out for NaN in Chrome 18
  1300. // V8bug: http://code.google.com/p/v8/issues/detail?id=2056
  1301. // Operators are faster than Math.min/max. See http://jsperf.com/number-constrain
  1302. // ... and (x < Nan) || (x < undefined) == false
  1303. // ... same for (x > NaN) || (x > undefined)
  1304. // so if min or max are undefined or NaN, we never return them... sadly, this
  1305. // is not true of null (but even Math.max(-1,null)==0 and isNaN(null)==false)
  1306. return (x < min) ? min : ((x > max) ? max : x);
  1307. },
  1308. /**
  1309. * Snaps the passed number between stopping points based upon a passed increment value.
  1310. *
  1311. * The difference between this and {@link #snapInRange} is that {@link #snapInRange} uses the minValue
  1312. * when calculating snap points:
  1313. *
  1314. * r = Ext.Number.snap(56, 2, 55, 65); // Returns 56 - snap points are zero based
  1315. *
  1316. * r = Ext.Number.snapInRange(56, 2, 55, 65); // Returns 57 - snap points are based from minValue
  1317. *
  1318. * @param {Number} value The unsnapped value.
  1319. * @param {Number} increment The increment by which the value must move.
  1320. * @param {Number} minValue The minimum value to which the returned value must be constrained. Overrides the increment.
  1321. * @param {Number} maxValue The maximum value to which the returned value must be constrained. Overrides the increment.
  1322. * @return {Number} The value of the nearest snap target.
  1323. */
  1324. snap : function(value, increment, minValue, maxValue) {
  1325. var m;
  1326. // If no value passed, or minValue was passed and value is less than minValue (anything < undefined is false)
  1327. // Then use the minValue (or zero if the value was undefined)
  1328. if (value === undefined || value < minValue) {
  1329. return minValue || 0;
  1330. }
  1331. if (increment) {
  1332. m = value % increment;
  1333. if (m !== 0) {
  1334. value -= m;
  1335. if (m * 2 >= increment) {
  1336. value += increment;
  1337. } else if (m * 2 < -increment) {
  1338. value -= increment;
  1339. }
  1340. }
  1341. }
  1342. return me.constrain(value, minValue, maxValue);
  1343. },
  1344. /**
  1345. * Snaps the passed number between stopping points based upon a passed increment value.
  1346. *
  1347. * The difference between this and {@link #snap} is that {@link #snap} does not use the minValue
  1348. * when calculating snap points:
  1349. *
  1350. * r = Ext.Number.snap(56, 2, 55, 65); // Returns 56 - snap points are zero based
  1351. *
  1352. * r = Ext.Number.snapInRange(56, 2, 55, 65); // Returns 57 - snap points are based from minValue
  1353. *
  1354. * @param {Number} value The unsnapped value.
  1355. * @param {Number} increment The increment by which the value must move.
  1356. * @param {Number} [minValue=0] The minimum value to which the returned value must be constrained.
  1357. * @param {Number} [maxValue=Infinity] The maximum value to which the returned value must be constrained.
  1358. * @return {Number} The value of the nearest snap target.
  1359. */
  1360. snapInRange : function(value, increment, minValue, maxValue) {
  1361. var tween;
  1362. // default minValue to zero
  1363. minValue = (minValue || 0);
  1364. // If value is undefined, or less than minValue, use minValue
  1365. if (value === undefined || value < minValue) {
  1366. return minValue;
  1367. }
  1368. // Calculate how many snap points from the minValue the passed value is.
  1369. if (increment && (tween = ((value - minValue) % increment))) {
  1370. value -= tween;
  1371. tween *= 2;
  1372. if (tween >= increment) {
  1373. value += increment;
  1374. }
  1375. }
  1376. // If constraining within a maximum, ensure the maximum is on a snap point
  1377. if (maxValue !== undefined) {
  1378. if (value > (maxValue = me.snapInRange(maxValue, increment, minValue))) {
  1379. value = maxValue;
  1380. }
  1381. }
  1382. return value;
  1383. },
  1384. /**
  1385. * Formats a number using fixed-point notation
  1386. * @param {Number} value The number to format
  1387. * @param {Number} precision The number of digits to show after the decimal point
  1388. */
  1389. toFixed: isToFixedBroken ? function(value, precision) {
  1390. precision = precision || 0;
  1391. var pow = math.pow(10, precision);
  1392. return (math.round(value * pow) / pow).toFixed(precision);
  1393. } : function(value, precision) {
  1394. return value.toFixed(precision);
  1395. },
  1396. /**
  1397. * Validate that a value is numeric and convert it to a number if necessary. Returns the specified default value if
  1398. * it is not.
  1399. Ext.Number.from('1.23', 1); // returns 1.23
  1400. Ext.Number.from('abc', 1); // returns 1
  1401. * @param {Object} value
  1402. * @param {Number} defaultValue The value to return if the original value is non-numeric
  1403. * @return {Number} value, if numeric, defaultValue otherwise
  1404. */
  1405. from: function(value, defaultValue) {
  1406. if (isFinite(value)) {
  1407. value = parseFloat(value);
  1408. }
  1409. return !isNaN(value) ? value : defaultValue;
  1410. },
  1411. /**
  1412. * Returns a random integer between the specified range (inclusive)
  1413. * @param {Number} from Lowest value to return.
  1414. * @param {Number} to Highst value to return.
  1415. * @return {Number} A random integer within the specified range.
  1416. */
  1417. randomInt: function (from, to) {
  1418. return math.floor(math.random() * (to - from + 1) + from);
  1419. }
  1420. });
  1421. /**
  1422. * @deprecated 4.0.0 Please use {@link Ext.Number#from} instead.
  1423. * @member Ext
  1424. * @method num
  1425. * @inheritdoc Ext.Number#from
  1426. */
  1427. Ext.num = function() {
  1428. return me.from.apply(this, arguments);
  1429. };
  1430. };
  1431. /**
  1432. * @class Ext.Array
  1433. * @singleton
  1434. * @author Jacky Nguyen <jacky@sencha.com>
  1435. * @docauthor Jacky Nguyen <jacky@sencha.com>
  1436. *
  1437. * A set of useful static methods to deal with arrays; provide missing methods for older browsers.
  1438. */
  1439. (function() {
  1440. var arrayPrototype = Array.prototype,
  1441. slice = arrayPrototype.slice,
  1442. supportsSplice = (function () {
  1443. var array = [],
  1444. lengthBefore,
  1445. j = 20;
  1446. if (!array.splice) {
  1447. return false;
  1448. }
  1449. // This detects a bug in IE8 splice method:
  1450. // see http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/6e946d03-e09f-4b22-a4dd-cd5e276bf05a/
  1451. while (j--) {
  1452. array.push("A");
  1453. }
  1454. 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");
  1455. lengthBefore = array.length; //41
  1456. array.splice(13, 0, "XXX"); // add one element
  1457. if (lengthBefore+1 != array.length) {
  1458. return false;
  1459. }
  1460. // end IE8 bug
  1461. return true;
  1462. }()),
  1463. supportsForEach = 'forEach' in arrayPrototype,
  1464. supportsMap = 'map' in arrayPrototype,
  1465. supportsIndexOf = 'indexOf' in arrayPrototype,
  1466. supportsEvery = 'every' in arrayPrototype,
  1467. supportsSome = 'some' in arrayPrototype,
  1468. supportsFilter = 'filter' in arrayPrototype,
  1469. supportsSort = (function() {
  1470. var a = [1,2,3,4,5].sort(function(){ return 0; });
  1471. return a[0] === 1 && a[1] === 2 && a[2] === 3 && a[3] === 4 && a[4] === 5;
  1472. }()),
  1473. supportsSliceOnNodeList = true,
  1474. ExtArray,
  1475. erase,
  1476. replace,
  1477. splice;
  1478. try {
  1479. // IE 6 - 8 will throw an error when using Array.prototype.slice on NodeList
  1480. if (typeof document !== 'undefined') {
  1481. slice.call(document.getElementsByTagName('body'));
  1482. }
  1483. } catch (e) {
  1484. supportsSliceOnNodeList = false;
  1485. }
  1486. function fixArrayIndex (array, index) {
  1487. return (index < 0) ? Math.max(0, array.length + index)
  1488. : Math.min(array.length, index);
  1489. }
  1490. /*
  1491. Does the same work as splice, but with a slightly more convenient signature. The splice
  1492. method has bugs in IE8, so this is the implementation we use on that platform.
  1493. The rippling of items in the array can be tricky. Consider two use cases:
  1494. index=2
  1495. removeCount=2
  1496. /=====\
  1497. +---+---+---+---+---+---+---+---+
  1498. | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
  1499. +---+---+---+---+---+---+---+---+
  1500. / \/ \/ \/ \
  1501. / /\ /\ /\ \
  1502. / / \/ \/ \ +--------------------------+
  1503. / / /\ /\ +--------------------------+ \
  1504. / / / \/ +--------------------------+ \ \
  1505. / / / /+--------------------------+ \ \ \
  1506. / / / / \ \ \ \
  1507. v v v v v v v v
  1508. +---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+
  1509. | 0 | 1 | 4 | 5 | 6 | 7 | | 0 | 1 | a | b | c | 4 | 5 | 6 | 7 |
  1510. +---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+
  1511. A B \=========/
  1512. insert=[a,b,c]
  1513. In case A, it is obvious that copying of [4,5,6,7] must be left-to-right so
  1514. that we don't end up with [0,1,6,7,6,7]. In case B, we have the opposite; we
  1515. must go right-to-left or else we would end up with [0,1,a,b,c,4,4,4,4].
  1516. */
  1517. function replaceSim (array, index, removeCount, insert) {
  1518. var add = insert ? insert.length : 0,
  1519. length = array.length,
  1520. pos = fixArrayIndex(array, index),
  1521. remove,
  1522. tailOldPos,
  1523. tailNewPos,
  1524. tailCount,
  1525. lengthAfterRemove,
  1526. i;
  1527. // we try to use Array.push when we can for efficiency...
  1528. if (pos === length) {
  1529. if (add) {
  1530. array.push.apply(array, insert);
  1531. }
  1532. } else {
  1533. remove = Math.min(removeCount, length - pos);
  1534. tailOldPos = pos + remove;
  1535. tailNewPos = tailOldPos + add - remove;
  1536. tailCount = length - tailOldPos;
  1537. lengthAfterRemove = length - remove;
  1538. if (tailNewPos < tailOldPos) { // case A
  1539. for (i = 0; i < tailCount; ++i) {
  1540. array[tailNewPos+i] = array[tailOldPos+i];
  1541. }
  1542. } else if (tailNewPos > tailOldPos) { // case B
  1543. for (i = tailCount; i--; ) {
  1544. array[tailNewPos+i] = array[tailOldPos+i];
  1545. }
  1546. } // else, add == remove (nothing to do)
  1547. if (add && pos === lengthAfterRemove) {
  1548. array.length = lengthAfterRemove; // truncate array
  1549. array.push.apply(array, insert);
  1550. } else {
  1551. array.length = lengthAfterRemove + add; // reserves space
  1552. for (i = 0; i < add; ++i) {
  1553. array[pos+i] = insert[i];
  1554. }
  1555. }
  1556. }
  1557. return array;
  1558. }
  1559. function replaceNative (array, index, removeCount, insert) {
  1560. if (insert && insert.length) {
  1561. if (index < array.length) {
  1562. array.splice.apply(array, [index, removeCount].concat(insert));
  1563. } else {
  1564. array.push.apply(array, insert);
  1565. }
  1566. } else {
  1567. array.splice(index, removeCount);
  1568. }
  1569. return array;
  1570. }
  1571. function eraseSim (array, index, removeCount) {
  1572. return replaceSim(array, index, removeCount);
  1573. }
  1574. function eraseNative (array, index, removeCount) {
  1575. array.splice(index, removeCount);
  1576. return array;
  1577. }
  1578. function spliceSim (array, index, removeCount) {
  1579. var pos = fixArrayIndex(array, index),
  1580. removed = array.slice(index, fixArrayIndex(array, pos+removeCount));
  1581. if (arguments.length < 4) {
  1582. replaceSim(array, pos, removeCount);
  1583. } else {
  1584. replaceSim(array, pos, removeCount, slice.call(arguments, 3));
  1585. }
  1586. return removed;
  1587. }
  1588. function spliceNative (array) {
  1589. return array.splice.apply(array, slice.call(arguments, 1));
  1590. }
  1591. erase = supportsSplice ? eraseNative : eraseSim;
  1592. replace = supportsSplice ? replaceNative : replaceSim;
  1593. splice = supportsSplice ? spliceNative : spliceSim;
  1594. // NOTE: from here on, use erase, replace or splice (not native methods)...
  1595. ExtArray = Ext.Array = {
  1596. /**
  1597. * Iterates an array or an iterable value and invoke the given callback function for each item.
  1598. *
  1599. * var countries = ['Vietnam', 'Singapore', 'United States', 'Russia'];
  1600. *
  1601. * Ext.Array.each(countries, function(name, index, countriesItSelf) {
  1602. * console.log(name);
  1603. * });
  1604. *
  1605. * var sum = function() {
  1606. * var sum = 0;
  1607. *
  1608. * Ext.Array.each(arguments, function(value) {
  1609. * sum += value;
  1610. * });
  1611. *
  1612. * return sum;
  1613. * };
  1614. *
  1615. * sum(1, 2, 3); // returns 6
  1616. *
  1617. * The iteration can be stopped by returning false in the function callback.
  1618. *
  1619. * Ext.Array.each(countries, function(name, index, countriesItSelf) {
  1620. * if (name === 'Singapore') {
  1621. * return false; // break here
  1622. * }
  1623. * });
  1624. *
  1625. * {@link Ext#each Ext.each} is alias for {@link Ext.Array#each Ext.Array.each}
  1626. *
  1627. * @param {Array/NodeList/Object} iterable The value to be iterated. If this
  1628. * argument is not iterable, the callback function is called once.
  1629. * @param {Function} fn The callback function. If it returns false, the iteration stops and this method returns
  1630. * the current `index`.
  1631. * @param {Object} fn.item The item at the current `index` in the passed `array`
  1632. * @param {Number} fn.index The current `index` within the `array`
  1633. * @param {Array} fn.allItems The `array` itself which was passed as the first argument
  1634. * @param {Boolean} fn.return Return false to stop iteration.
  1635. * @param {Object} scope (Optional) The scope (`this` reference) in which the specified function is executed.
  1636. * @param {Boolean} reverse (Optional) Reverse the iteration order (loop from the end to the beginning)
  1637. * Defaults false
  1638. * @return {Boolean} See description for the `fn` parameter.
  1639. */
  1640. each: function(array, fn, scope, reverse) {
  1641. array = ExtArray.from(array);
  1642. var i,
  1643. ln = array.length;
  1644. if (reverse !== true) {
  1645. for (i = 0; i < ln; i++) {
  1646. if (fn.call(scope || array[i], array[i], i, array) === false) {
  1647. return i;
  1648. }
  1649. }
  1650. }
  1651. else {
  1652. for (i = ln - 1; i > -1; i--) {
  1653. if (fn.call(scope || array[i], array[i], i, array) === false) {
  1654. return i;
  1655. }
  1656. }
  1657. }
  1658. return true;
  1659. },
  1660. /**
  1661. * Iterates an array and invoke the given callback function for each item. Note that this will simply
  1662. * delegate to the native Array.prototype.forEach method if supported. It doesn't support stopping the
  1663. * iteration by returning false in the callback function like {@link Ext.Array#each}. However, performance
  1664. * could be much better in modern browsers comparing with {@link Ext.Array#each}
  1665. *
  1666. * @param {Array} array The array to iterate
  1667. * @param {Function} fn The callback function.
  1668. * @param {Object} fn.item The item at the current `index` in the passed `array`
  1669. * @param {Number} fn.index The current `index` within the `array`
  1670. * @param {Array} fn.allItems The `array` itself which was passed as the first argument
  1671. * @param {Object} scope (Optional) The execution scope (`this`) in which the specified function is executed.
  1672. */
  1673. forEach: supportsForEach ? function(array, fn, scope) {
  1674. return array.forEach(fn, scope);
  1675. } : function(array, fn, scope) {
  1676. var i = 0,
  1677. ln = array.length;
  1678. for (; i < ln; i++) {
  1679. fn.call(scope, array[i], i, array);
  1680. }
  1681. },
  1682. /**
  1683. * Get the index of the provided `item` in the given `array`, a supplement for the
  1684. * missing arrayPrototype.indexOf in Internet Explorer.
  1685. *
  1686. * @param {Array} array The array to check
  1687. * @param {Object} item The item to look for
  1688. * @param {Number} from (Optional) The index at which to begin the search
  1689. * @return {Number} The index of item in the array (or -1 if it is not found)
  1690. */
  1691. indexOf: supportsIndexOf ? function(array, item, from) {
  1692. return array.indexOf(item, from);
  1693. } : function(array, item, from) {
  1694. var i, length = array.length;
  1695. for (i = (from < 0) ? Math.max(0, length + from) : from || 0; i < length; i++) {
  1696. if (array[i] === item) {
  1697. return i;
  1698. }
  1699. }
  1700. return -1;
  1701. },
  1702. /**
  1703. * Checks whether or not the given `array` contains the specified `item`
  1704. *
  1705. * @param {Array} array The array to check
  1706. * @param {Object} item The item to look for
  1707. * @return {Boolean} True if the array contains the item, false otherwise
  1708. */
  1709. contains: supportsIndexOf ? function(array, item) {
  1710. return array.indexOf(item) !== -1;
  1711. } : function(array, item) {
  1712. var i, ln;
  1713. for (i = 0, ln = array.length; i < ln; i++) {
  1714. if (array[i] === item) {
  1715. return true;
  1716. }
  1717. }
  1718. return false;
  1719. },
  1720. /**
  1721. * Converts any iterable (numeric indices and a length property) into a true array.
  1722. *
  1723. * function test() {
  1724. * var args = Ext.Array.toArray(arguments),
  1725. * fromSecondToLastArgs = Ext.Array.toArray(arguments, 1);
  1726. *
  1727. * alert(args.join(' '));
  1728. * alert(fromSecondToLastArgs.join(' '));
  1729. * }
  1730. *
  1731. * test('just', 'testing', 'here'); // alerts 'just testing here';
  1732. * // alerts 'testing here';
  1733. *
  1734. * Ext.Array.toArray(document.getElementsByTagName('div')); // will convert the NodeList into an array
  1735. * Ext.Array.toArray('splitted'); // returns ['s', 'p', 'l', 'i', 't', 't', 'e', 'd']
  1736. * Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l']
  1737. *
  1738. * {@link Ext#toArray Ext.toArray} is alias for {@link Ext.Array#toArray Ext.Array.toArray}
  1739. *
  1740. * @param {Object} iterable the iterable object to be turned into a true Array.
  1741. * @param {Number} start (Optional) a zero-based index that specifies the start of extraction. Defaults to 0
  1742. * @param {Number} end (Optional) a 1-based index that specifies the end of extraction. Defaults to the last
  1743. * index of the iterable value
  1744. * @return {Array} array
  1745. */
  1746. toArray: function(iterable, start, end){
  1747. if (!iterable || !iterable.length) {
  1748. return [];
  1749. }
  1750. if (typeof iterable === 'string') {
  1751. iterable = iterable.split('');
  1752. }
  1753. if (supportsSliceOnNodeList) {
  1754. return slice.call(iterable, start || 0, end || iterable.length);
  1755. }
  1756. var array = [],
  1757. i;
  1758. start = start || 0;
  1759. end = end ? ((end < 0) ? iterable.length + end : end) : iterable.length;
  1760. for (i = start; i < end; i++) {
  1761. array.push(iterable[i]);
  1762. }
  1763. return array;
  1764. },
  1765. /**
  1766. * Plucks the value of a property from each item in the Array. Example:
  1767. *
  1768. * Ext.Array.pluck(Ext.query("p"), "className"); // [el1.className, el2.className, ..., elN.className]
  1769. *
  1770. * @param {Array/NodeList} array The Array of items to pluck the value from.
  1771. * @param {String} propertyName The property name to pluck from each element.
  1772. * @return {Array} The value from each item in the Array.
  1773. */
  1774. pluck: function(array, propertyName) {
  1775. var ret = [],
  1776. i, ln, item;
  1777. for (i = 0, ln = array.length; i < ln; i++) {
  1778. item = array[i];
  1779. ret.push(item[propertyName]);
  1780. }
  1781. return ret;
  1782. },
  1783. /**
  1784. * Creates a new array with the results of calling a provided function on every element in this array.
  1785. *
  1786. * @param {Array} array
  1787. * @param {Function} fn Callback function for each item
  1788. * @param {Object} scope Callback function scope
  1789. * @return {Array} results
  1790. */
  1791. map: supportsMap ? function(array, fn, scope) {
  1792. //<debug>
  1793. if (!fn) {
  1794. Ext.Error.raise('Ext.Array.map must have a callback function passed as second argument.');
  1795. }
  1796. //</debug>
  1797. return array.map(fn, scope);
  1798. } : function(array, fn, scope) {
  1799. //<debug>
  1800. if (!fn) {
  1801. Ext.Error.raise('Ext.Array.map must have a callback function passed as second argument.');
  1802. }
  1803. //</debug>
  1804. var results = [],
  1805. i = 0,
  1806. len = array.length;
  1807. for (; i < len; i++) {
  1808. results[i] = fn.call(scope, array[i], i, array);
  1809. }
  1810. return results;
  1811. },
  1812. /**
  1813. * Executes the specified function for each array element until the function returns a falsy value.
  1814. * If such an item is found, the function will return false immediately.
  1815. * Otherwise, it will return true.
  1816. *
  1817. * @param {Array} array
  1818. * @param {Function} fn Callback function for each item
  1819. * @param {Object} scope Callback function scope
  1820. * @return {Boolean} True if no false value is returned by the callback function.
  1821. */
  1822. every: supportsEvery ? function(array, fn, scope) {
  1823. //<debug>
  1824. if (!fn) {
  1825. Ext.Error.raise('Ext.Array.every must have a callback function passed as second argument.');
  1826. }
  1827. //</debug>
  1828. return array.every(fn, scope);
  1829. } : function(array, fn, scope) {
  1830. //<debug>
  1831. if (!fn) {
  1832. Ext.Error.raise('Ext.Array.every must have a callback function passed as second argument.');
  1833. }
  1834. //</debug>
  1835. var i = 0,
  1836. ln = array.length;
  1837. for (; i < ln; ++i) {
  1838. if (!fn.call(scope, array[i], i, array)) {
  1839. return false;
  1840. }
  1841. }
  1842. return true;
  1843. },
  1844. /**
  1845. * Executes the specified function for each array element until the function returns a truthy value.
  1846. * If such an item is found, the function will return true immediately. Otherwise, it will return false.
  1847. *
  1848. * @param {Array} array
  1849. * @param {Function} fn Callback function for each item
  1850. * @param {Object} scope Callback function scope
  1851. * @return {Boolean} True if the callback function returns a truthy value.
  1852. */
  1853. some: supportsSome ? function(array, fn, scope) {
  1854. //<debug>
  1855. if (!fn) {
  1856. Ext.Error.raise('Ext.Array.some must have a callback function passed as second argument.');
  1857. }
  1858. //</debug>
  1859. return array.some(fn, scope);
  1860. } : function(array, fn, scope) {
  1861. //<debug>
  1862. if (!fn) {
  1863. Ext.Error.raise('Ext.Array.some must have a callback function passed as second argument.');
  1864. }
  1865. //</debug>
  1866. var i = 0,
  1867. ln = array.length;
  1868. for (; i < ln; ++i) {
  1869. if (fn.call(scope, array[i], i, array)) {
  1870. return true;
  1871. }
  1872. }
  1873. return false;
  1874. },
  1875. /**
  1876. * Filter through an array and remove empty item as defined in {@link Ext#isEmpty Ext.isEmpty}
  1877. *
  1878. * See {@link Ext.Array#filter}
  1879. *
  1880. * @param {Array} array
  1881. * @return {Array} results
  1882. */
  1883. clean: function(array) {
  1884. var results = [],
  1885. i = 0,
  1886. ln = array.length,
  1887. item;
  1888. for (; i < ln; i++) {
  1889. item = array[i];
  1890. if (!Ext.isEmpty(item)) {
  1891. results.push(item);
  1892. }
  1893. }
  1894. return results;
  1895. },
  1896. /**
  1897. * Returns a new array with unique items
  1898. *
  1899. * @param {Array} array
  1900. * @return {Array} results
  1901. */
  1902. unique: function(array) {
  1903. var clone = [],
  1904. i = 0,
  1905. ln = array.length,
  1906. item;
  1907. for (; i < ln; i++) {
  1908. item = array[i];
  1909. if (ExtArray.indexOf(clone, item) === -1) {
  1910. clone.push(item);
  1911. }
  1912. }
  1913. return clone;
  1914. },
  1915. /**
  1916. * Creates a new array with all of the elements of this array for which
  1917. * the provided filtering function returns true.
  1918. *
  1919. * @param {Array} array
  1920. * @param {Function} fn Callback function for each item
  1921. * @param {Object} scope Callback function scope
  1922. * @return {Array} results
  1923. */
  1924. filter: supportsFilter ? function(array, fn, scope) {
  1925. //<debug>
  1926. if (!fn) {
  1927. Ext.Error.raise('Ext.Array.filter must have a callback function passed as second argument.');
  1928. }
  1929. //</debug>
  1930. return array.filter(fn, scope);
  1931. } : function(array, fn, scope) {
  1932. //<debug>
  1933. if (!fn) {
  1934. Ext.Error.raise('Ext.Array.filter must have a callback function passed as second argument.');
  1935. }
  1936. //</debug>
  1937. var results = [],
  1938. i = 0,
  1939. ln = array.length;
  1940. for (; i < ln; i++) {
  1941. if (fn.call(scope, array[i], i, array)) {
  1942. results.push(array[i]);
  1943. }
  1944. }
  1945. return results;
  1946. },
  1947. /**
  1948. * Converts a value to an array if it's not already an array; returns:
  1949. *
  1950. * - An empty array if given value is `undefined` or `null`
  1951. * - Itself if given value is already an array
  1952. * - An array copy if given value is {@link Ext#isIterable iterable} (arguments, NodeList and alike)
  1953. * - An array with one item which is the given value, otherwise
  1954. *
  1955. * @param {Object} value The value to convert to an array if it's not already is an array
  1956. * @param {Boolean} newReference (Optional) True to clone the given array and return a new reference if necessary,
  1957. * defaults to false
  1958. * @return {Array} array
  1959. */
  1960. from: function(value, newReference) {
  1961. if (value === undefined || value === null) {
  1962. return [];
  1963. }
  1964. if (Ext.isArray(value)) {
  1965. return (newReference) ? slice.call(value) : value;
  1966. }
  1967. var type = typeof value;
  1968. // Both strings and functions will have a length property. In phantomJS, NodeList
  1969. // instances report typeof=='function' but don't have an apply method...
  1970. if (value && value.length !== undefined && type !== 'string' && (type !== 'function' || !value.apply)) {
  1971. return ExtArray.toArray(value);
  1972. }
  1973. return [value];
  1974. },
  1975. /**
  1976. * Removes the specified item from the array if it exists
  1977. *
  1978. * @param {Array} array The array
  1979. * @param {Object} item The item to remove
  1980. * @return {Array} The passed array itself
  1981. */
  1982. remove: function(array, item) {
  1983. var index = ExtArray.indexOf(array, item);
  1984. if (index !== -1) {
  1985. erase(array, index, 1);
  1986. }
  1987. return array;
  1988. },
  1989. /**
  1990. * Push an item into the array only if the array doesn't contain it yet
  1991. *
  1992. * @param {Array} array The array
  1993. * @param {Object} item The item to include
  1994. */
  1995. include: function(array, item) {
  1996. if (!ExtArray.contains(array, item)) {
  1997. array.push(item);
  1998. }
  1999. },
  2000. /**
  2001. * Clone a flat array without referencing the previous one. Note that this is different
  2002. * from Ext.clone since it doesn't handle recursive cloning. It's simply a convenient, easy-to-remember method
  2003. * for Array.prototype.slice.call(array)
  2004. *
  2005. * @param {Array} array The array
  2006. * @return {Array} The clone array
  2007. */
  2008. clone: function(array) {
  2009. return slice.call(array);
  2010. },
  2011. /**
  2012. * Merge multiple arrays into one with unique items.
  2013. *
  2014. * {@link Ext.Array#union} is alias for {@link Ext.Array#merge}
  2015. *
  2016. * @param {Array} array1
  2017. * @param {Array} array2
  2018. * @param {Array} etc
  2019. * @return {Array} merged
  2020. */
  2021. merge: function() {
  2022. var args = slice.call(arguments),
  2023. array = [],
  2024. i, ln;
  2025. for (i = 0, ln = args.length; i < ln; i++) {
  2026. array = array.concat(args[i]);
  2027. }
  2028. return ExtArray.unique(array);
  2029. },
  2030. /**
  2031. * Merge multiple arrays into one with unique items that exist in all of the arrays.
  2032. *
  2033. * @param {Array} array1
  2034. * @param {Array} array2
  2035. * @param {Array} etc
  2036. * @return {Array} intersect
  2037. */
  2038. intersect: function() {
  2039. var intersection = [],
  2040. arrays = slice.call(arguments),
  2041. arraysLength,
  2042. array,
  2043. arrayLength,
  2044. minArray,
  2045. minArrayIndex,
  2046. minArrayCandidate,
  2047. minArrayLength,
  2048. element,
  2049. elementCandidate,
  2050. elementCount,
  2051. i, j, k;
  2052. if (!arrays.length) {
  2053. return intersection;
  2054. }
  2055. // Find the smallest array
  2056. arraysLength = arrays.length;
  2057. for (i = minArrayIndex = 0; i < arraysLength; i++) {
  2058. minArrayCandidate = arrays[i];
  2059. if (!minArray || minArrayCandidate.length < minArray.length) {
  2060. minArray = minArrayCandidate;
  2061. minArrayIndex = i;
  2062. }
  2063. }
  2064. minArray = ExtArray.unique(minArray);
  2065. erase(arrays, minArrayIndex, 1);
  2066. // Use the smallest unique'd array as the anchor loop. If the other array(s) do contain
  2067. // an item in the small array, we're likely to find it before reaching the end
  2068. // of the inner loop and can terminate the search early.
  2069. minArrayLength = minArray.length;
  2070. arraysLength = arrays.length;
  2071. for (i = 0; i < minArrayLength; i++) {
  2072. element = minArray[i];
  2073. elementCount = 0;
  2074. for (j = 0; j < arraysLength; j++) {
  2075. array = arrays[j];
  2076. arrayLength = array.length;
  2077. for (k = 0; k < arrayLength; k++) {
  2078. elementCandidate = array[k];
  2079. if (element === elementCandidate) {
  2080. elementCount++;
  2081. break;
  2082. }
  2083. }
  2084. }
  2085. if (elementCount === arraysLength) {
  2086. intersection.push(element);
  2087. }
  2088. }
  2089. return intersection;
  2090. },
  2091. /**
  2092. * Perform a set difference A-B by subtracting all items in array B from array A.
  2093. *
  2094. * @param {Array} arrayA
  2095. * @param {Array} arrayB
  2096. * @return {Array} difference
  2097. */
  2098. difference: function(arrayA, arrayB) {
  2099. var clone = slice.call(arrayA),
  2100. ln = clone.length,
  2101. i, j, lnB;
  2102. for (i = 0,lnB = arrayB.length; i < lnB; i++) {
  2103. for (j = 0; j < ln; j++) {
  2104. if (clone[j] === arrayB[i]) {
  2105. erase(clone, j, 1);
  2106. j--;
  2107. ln--;
  2108. }
  2109. }
  2110. }
  2111. return clone;
  2112. },
  2113. /**
  2114. * Returns a shallow copy of a part of an array. This is equivalent to the native
  2115. * call "Array.prototype.slice.call(array, begin, end)". This is often used when "array"
  2116. * is "arguments" since the arguments object does not supply a slice method but can
  2117. * be the context object to Array.prototype.slice.
  2118. *
  2119. * @param {Array} array The array (or arguments object).
  2120. * @param {Number} begin The index at which to begin. Negative values are offsets from
  2121. * the end of the array.
  2122. * @param {Number} end The index at which to end. The copied items do not include
  2123. * end. Negative values are offsets from the end of the array. If end is omitted,
  2124. * all items up to the end of the array are copied.
  2125. * @return {Array} The copied piece of the array.
  2126. * @method slice
  2127. */
  2128. // Note: IE6 will return [] on slice.call(x, undefined).
  2129. slice: ([1,2].slice(1, undefined).length ?
  2130. function (array, begin, end) {
  2131. return slice.call(array, begin, end);
  2132. } :
  2133. // at least IE6 uses arguments.length for variadic signature
  2134. function (array, begin, end) {
  2135. // After tested for IE 6, the one below is of the best performance
  2136. // see http://jsperf.com/slice-fix
  2137. if (typeof begin === 'undefined') {
  2138. return slice.call(array);
  2139. }
  2140. if (typeof end === 'undefined') {
  2141. return slice.call(array, begin);
  2142. }
  2143. return slice.call(array, begin, end);
  2144. }
  2145. ),
  2146. /**
  2147. * Sorts the elements of an Array.
  2148. * By default, this method sorts the elements alphabetically and ascending.
  2149. *
  2150. * @param {Array} array The array to sort.
  2151. * @param {Function} sortFn (optional) The comparison function.
  2152. * @return {Array} The sorted array.
  2153. */
  2154. sort: supportsSort ? function(array, sortFn) {
  2155. if (sortFn) {
  2156. return array.sort(sortFn);
  2157. } else {
  2158. return array.sort();
  2159. }
  2160. } : function(array, sortFn) {
  2161. var length = array.length,
  2162. i = 0,
  2163. comparison,
  2164. j, min, tmp;
  2165. for (; i < length; i++) {
  2166. min = i;
  2167. for (j = i + 1; j < length; j++) {
  2168. if (sortFn) {
  2169. comparison = sortFn(array[j], array[min]);
  2170. if (comparison < 0) {
  2171. min = j;
  2172. }
  2173. } else if (array[j] < array[min]) {
  2174. min = j;
  2175. }
  2176. }
  2177. if (min !== i) {
  2178. tmp = array[i];
  2179. array[i] = array[min];
  2180. array[min] = tmp;
  2181. }
  2182. }
  2183. return array;
  2184. },
  2185. /**
  2186. * Recursively flattens into 1-d Array. Injects Arrays inline.
  2187. *
  2188. * @param {Array} array The array to flatten
  2189. * @return {Array} The 1-d array.
  2190. */
  2191. flatten: function(array) {
  2192. var worker = [];
  2193. function rFlatten(a) {
  2194. var i, ln, v;
  2195. for (i = 0, ln = a.length; i < ln; i++) {
  2196. v = a[i];
  2197. if (Ext.isArray(v)) {
  2198. rFlatten(v);
  2199. } else {
  2200. worker.push(v);
  2201. }
  2202. }
  2203. return worker;
  2204. }
  2205. return rFlatten(array);
  2206. },
  2207. /**
  2208. * Returns the minimum value in the Array.
  2209. *
  2210. * @param {Array/NodeList} array The Array from which to select the minimum value.
  2211. * @param {Function} comparisonFn (optional) a function to perform the comparision which determines minimization.
  2212. * If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1
  2213. * @return {Object} minValue The minimum value
  2214. */
  2215. min: function(array, comparisonFn) {
  2216. var min = array[0],
  2217. i, ln, item;
  2218. for (i = 0, ln = array.length; i < ln; i++) {
  2219. item = array[i];
  2220. if (comparisonFn) {
  2221. if (comparisonFn(min, item) === 1) {
  2222. min = item;
  2223. }
  2224. }
  2225. else {
  2226. if (item < min) {
  2227. min = item;
  2228. }
  2229. }
  2230. }
  2231. return min;
  2232. },
  2233. /**
  2234. * Returns the maximum value in the Array.
  2235. *
  2236. * @param {Array/NodeList} array The Array from which to select the maximum value.
  2237. * @param {Function} comparisonFn (optional) a function to perform the comparision which determines maximization.
  2238. * If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1
  2239. * @return {Object} maxValue The maximum value
  2240. */
  2241. max: function(array, comparisonFn) {
  2242. var max = array[0],
  2243. i, ln, item;
  2244. for (i = 0, ln = array.length; i < ln; i++) {
  2245. item = array[i];
  2246. if (comparisonFn) {
  2247. if (comparisonFn(max, item) === -1) {
  2248. max = item;
  2249. }
  2250. }
  2251. else {
  2252. if (item > max) {
  2253. max = item;
  2254. }
  2255. }
  2256. }
  2257. return max;
  2258. },
  2259. /**
  2260. * Calculates the mean of all items in the array.
  2261. *
  2262. * @param {Array} array The Array to calculate the mean value of.
  2263. * @return {Number} The mean.
  2264. */
  2265. mean: function(array) {
  2266. return array.length > 0 ? ExtArray.sum(array) / array.length : undefined;
  2267. },
  2268. /**
  2269. * Calculates the sum of all items in the given array.
  2270. *
  2271. * @param {Array} array The Array to calculate the sum value of.
  2272. * @return {Number} The sum.
  2273. */
  2274. sum: function(array) {
  2275. var sum = 0,
  2276. i, ln, item;
  2277. for (i = 0,ln = array.length; i < ln; i++) {
  2278. item = array[i];
  2279. sum += item;
  2280. }
  2281. return sum;
  2282. },
  2283. /**
  2284. * Creates a map (object) keyed by the elements of the given array. The values in
  2285. * the map are the index+1 of the array element. For example:
  2286. *
  2287. * var map = Ext.Array.toMap(['a','b','c']);
  2288. *
  2289. * // map = { a: 1, b: 2, c: 3 };
  2290. *
  2291. * Or a key property can be specified:
  2292. *
  2293. * var map = Ext.Array.toMap([
  2294. * { name: 'a' },
  2295. * { name: 'b' },
  2296. * { name: 'c' }
  2297. * ], 'name');
  2298. *
  2299. * // map = { a: 1, b: 2, c: 3 };
  2300. *
  2301. * Lastly, a key extractor can be provided:
  2302. *
  2303. * var map = Ext.Array.toMap([
  2304. * { name: 'a' },
  2305. * { name: 'b' },
  2306. * { name: 'c' }
  2307. * ], function (obj) { return obj.name.toUpperCase(); });
  2308. *
  2309. * // map = { A: 1, B: 2, C: 3 };
  2310. */
  2311. toMap: function(array, getKey, scope) {
  2312. var map = {},
  2313. i = array.length;
  2314. if (!getKey) {
  2315. while (i--) {
  2316. map[array[i]] = i+1;
  2317. }
  2318. } else if (typeof getKey == 'string') {
  2319. while (i--) {
  2320. map[array[i][getKey]] = i+1;
  2321. }
  2322. } else {
  2323. while (i--) {
  2324. map[getKey.call(scope, array[i])] = i+1;
  2325. }
  2326. }
  2327. return map;
  2328. },
  2329. //<debug>
  2330. _replaceSim: replaceSim, // for unit testing
  2331. _spliceSim: spliceSim,
  2332. //</debug>
  2333. /**
  2334. * Removes items from an array. This is functionally equivalent to the splice method
  2335. * of Array, but works around bugs in IE8's splice method and does not copy the
  2336. * removed elements in order to return them (because very often they are ignored).
  2337. *
  2338. * @param {Array} array The Array on which to replace.
  2339. * @param {Number} index The index in the array at which to operate.
  2340. * @param {Number} removeCount The number of items to remove at index.
  2341. * @return {Array} The array passed.
  2342. * @method
  2343. */
  2344. erase: erase,
  2345. /**
  2346. * Inserts items in to an array.
  2347. *
  2348. * @param {Array} array The Array in which to insert.
  2349. * @param {Number} index The index in the array at which to operate.
  2350. * @param {Array} items The array of items to insert at index.
  2351. * @return {Array} The array passed.
  2352. */
  2353. insert: function (array, index, items) {
  2354. return replace(array, index, 0, items);
  2355. },
  2356. /**
  2357. * Replaces items in an array. This is functionally equivalent to the splice method
  2358. * of Array, but works around bugs in IE8's splice method and is often more convenient
  2359. * to call because it accepts an array of items to insert rather than use a variadic
  2360. * argument list.
  2361. *
  2362. * @param {Array} array The Array on which to replace.
  2363. * @param {Number} index The index in the array at which to operate.
  2364. * @param {Number} removeCount The number of items to remove at index (can be 0).
  2365. * @param {Array} insert (optional) An array of items to insert at index.
  2366. * @return {Array} The array passed.
  2367. * @method
  2368. */
  2369. replace: replace,
  2370. /**
  2371. * Replaces items in an array. This is equivalent to the splice method of Array, but
  2372. * works around bugs in IE8's splice method. The signature is exactly the same as the
  2373. * splice method except that the array is the first argument. All arguments following
  2374. * removeCount are inserted in the array at index.
  2375. *
  2376. * @param {Array} array The Array on which to replace.
  2377. * @param {Number} index The index in the array at which to operate.
  2378. * @param {Number} removeCount The number of items to remove at index (can be 0).
  2379. * @param {Object...} elements The elements to add to the array. If you don't specify
  2380. * any elements, splice simply removes elements from the array.
  2381. * @return {Array} An array containing the removed items.
  2382. * @method
  2383. */
  2384. splice: splice,
  2385. /**
  2386. * Pushes new items onto the end of an Array.
  2387. *
  2388. * Passed parameters may be single items, or arrays of items. If an Array is found in the argument list, all its
  2389. * elements are pushed into the end of the target Array.
  2390. *
  2391. * @param {Array} target The Array onto which to push new items
  2392. * @param {Object...} elements The elements to add to the array. Each parameter may
  2393. * be an Array, in which case all the elements of that Array will be pushed into the end of the
  2394. * destination Array.
  2395. * @return {Array} An array containing all the new items push onto the end.
  2396. *
  2397. */
  2398. push: function(array) {
  2399. var len = arguments.length,
  2400. i = 1,
  2401. newItem;
  2402. if (array === undefined) {
  2403. array = [];
  2404. } else if (!Ext.isArray(array)) {
  2405. array = [array];
  2406. }
  2407. for (; i < len; i++) {
  2408. newItem = arguments[i];
  2409. Array.prototype.push[Ext.isArray(newItem) ? 'apply' : 'call'](array, newItem);
  2410. }
  2411. return array;
  2412. }
  2413. };
  2414. /**
  2415. * @method
  2416. * @member Ext
  2417. * @inheritdoc Ext.Array#each
  2418. */
  2419. Ext.each = ExtArray.each;
  2420. /**
  2421. * @method
  2422. * @member Ext.Array
  2423. * @inheritdoc Ext.Array#merge
  2424. */
  2425. ExtArray.union = ExtArray.merge;
  2426. /**
  2427. * Old alias to {@link Ext.Array#min}
  2428. * @deprecated 4.0.0 Use {@link Ext.Array#min} instead
  2429. * @method
  2430. * @member Ext
  2431. * @inheritdoc Ext.Array#min
  2432. */
  2433. Ext.min = ExtArray.min;
  2434. /**
  2435. * Old alias to {@link Ext.Array#max}
  2436. * @deprecated 4.0.0 Use {@link Ext.Array#max} instead
  2437. * @method
  2438. * @member Ext
  2439. * @inheritdoc Ext.Array#max
  2440. */
  2441. Ext.max = ExtArray.max;
  2442. /**
  2443. * Old alias to {@link Ext.Array#sum}
  2444. * @deprecated 4.0.0 Use {@link Ext.Array#sum} instead
  2445. * @method
  2446. * @member Ext
  2447. * @inheritdoc Ext.Array#sum
  2448. */
  2449. Ext.sum = ExtArray.sum;
  2450. /**
  2451. * Old alias to {@link Ext.Array#mean}
  2452. * @deprecated 4.0.0 Use {@link Ext.Array#mean} instead
  2453. * @method
  2454. * @member Ext
  2455. * @inheritdoc Ext.Array#mean
  2456. */
  2457. Ext.mean = ExtArray.mean;
  2458. /**
  2459. * Old alias to {@link Ext.Array#flatten}
  2460. * @deprecated 4.0.0 Use {@link Ext.Array#flatten} instead
  2461. * @method
  2462. * @member Ext
  2463. * @inheritdoc Ext.Array#flatten
  2464. */
  2465. Ext.flatten = ExtArray.flatten;
  2466. /**
  2467. * Old alias to {@link Ext.Array#clean}
  2468. * @deprecated 4.0.0 Use {@link Ext.Array#clean} instead
  2469. * @method
  2470. * @member Ext
  2471. * @inheritdoc Ext.Array#clean
  2472. */
  2473. Ext.clean = ExtArray.clean;
  2474. /**
  2475. * Old alias to {@link Ext.Array#unique}
  2476. * @deprecated 4.0.0 Use {@link Ext.Array#unique} instead
  2477. * @method
  2478. * @member Ext
  2479. * @inheritdoc Ext.Array#unique
  2480. */
  2481. Ext.unique = ExtArray.unique;
  2482. /**
  2483. * Old alias to {@link Ext.Array#pluck Ext.Array.pluck}
  2484. * @deprecated 4.0.0 Use {@link Ext.Array#pluck Ext.Array.pluck} instead
  2485. * @method
  2486. * @member Ext
  2487. * @inheritdoc Ext.Array#pluck
  2488. */
  2489. Ext.pluck = ExtArray.pluck;
  2490. /**
  2491. * @method
  2492. * @member Ext
  2493. * @inheritdoc Ext.Array#toArray
  2494. */
  2495. Ext.toArray = function() {
  2496. return ExtArray.toArray.apply(ExtArray, arguments);
  2497. };
  2498. }());
  2499. /**
  2500. * @class Ext.Function
  2501. *
  2502. * A collection of useful static methods to deal with function callbacks
  2503. * @singleton
  2504. * @alternateClassName Ext.util.Functions
  2505. */
  2506. Ext.Function = {
  2507. /**
  2508. * A very commonly used method throughout the framework. It acts as a wrapper around another method
  2509. * which originally accepts 2 arguments for `name` and `value`.
  2510. * The wrapped function then allows "flexible" value setting of either:
  2511. *
  2512. * - `name` and `value` as 2 arguments
  2513. * - one single object argument with multiple key - value pairs
  2514. *
  2515. * For example:
  2516. *
  2517. * var setValue = Ext.Function.flexSetter(function(name, value) {
  2518. * this[name] = value;
  2519. * });
  2520. *
  2521. * // Afterwards
  2522. * // Setting a single name - value
  2523. * setValue('name1', 'value1');
  2524. *
  2525. * // Settings multiple name - value pairs
  2526. * setValue({
  2527. * name1: 'value1',
  2528. * name2: 'value2',
  2529. * name3: 'value3'
  2530. * });
  2531. *
  2532. * @param {Function} setter
  2533. * @returns {Function} flexSetter
  2534. */
  2535. flexSetter: function(fn) {
  2536. return function(a, b) {
  2537. var k, i;
  2538. if (a === null) {
  2539. return this;
  2540. }
  2541. if (typeof a !== 'string') {
  2542. for (k in a) {
  2543. if (a.hasOwnProperty(k)) {
  2544. fn.call(this, k, a[k]);
  2545. }
  2546. }
  2547. if (Ext.enumerables) {
  2548. for (i = Ext.enumerables.length; i--;) {
  2549. k = Ext.enumerables[i];
  2550. if (a.hasOwnProperty(k)) {
  2551. fn.call(this, k, a[k]);
  2552. }
  2553. }
  2554. }
  2555. } else {
  2556. fn.call(this, a, b);
  2557. }
  2558. return this;
  2559. };
  2560. },
  2561. /**
  2562. * Create a new function from the provided `fn`, change `this` to the provided scope, optionally
  2563. * overrides arguments for the call. (Defaults to the arguments passed by the caller)
  2564. *
  2565. * {@link Ext#bind Ext.bind} is alias for {@link Ext.Function#bind Ext.Function.bind}
  2566. *
  2567. * @param {Function} fn The function to delegate.
  2568. * @param {Object} scope (optional) The scope (`this` reference) in which the function is executed.
  2569. * **If omitted, defaults to the default global environment object (usually the browser window).**
  2570. * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
  2571. * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
  2572. * if a number the args are inserted at the specified position
  2573. * @return {Function} The new function
  2574. */
  2575. bind: function(fn, scope, args, appendArgs) {
  2576. if (arguments.length === 2) {
  2577. return function() {
  2578. return fn.apply(scope, arguments);
  2579. };
  2580. }
  2581. var method = fn,
  2582. slice = Array.prototype.slice;
  2583. return function() {
  2584. var callArgs = args || arguments;
  2585. if (appendArgs === true) {
  2586. callArgs = slice.call(arguments, 0);
  2587. callArgs = callArgs.concat(args);
  2588. }
  2589. else if (typeof appendArgs == 'number') {
  2590. callArgs = slice.call(arguments, 0); // copy arguments first
  2591. Ext.Array.insert(callArgs, appendArgs, args);
  2592. }
  2593. return method.apply(scope || Ext.global, callArgs);
  2594. };
  2595. },
  2596. /**
  2597. * Create a new function from the provided `fn`, the arguments of which are pre-set to `args`.
  2598. * New arguments passed to the newly created callback when it's invoked are appended after the pre-set ones.
  2599. * This is especially useful when creating callbacks.
  2600. *
  2601. * For example:
  2602. *
  2603. * var originalFunction = function(){
  2604. * alert(Ext.Array.from(arguments).join(' '));
  2605. * };
  2606. *
  2607. * var callback = Ext.Function.pass(originalFunction, ['Hello', 'World']);
  2608. *
  2609. * callback(); // alerts 'Hello World'
  2610. * callback('by Me'); // alerts 'Hello World by Me'
  2611. *
  2612. * {@link Ext#pass Ext.pass} is alias for {@link Ext.Function#pass Ext.Function.pass}
  2613. *
  2614. * @param {Function} fn The original function
  2615. * @param {Array} args The arguments to pass to new callback
  2616. * @param {Object} scope (optional) The scope (`this` reference) in which the function is executed.
  2617. * @return {Function} The new callback function
  2618. */
  2619. pass: function(fn, args, scope) {
  2620. if (!Ext.isArray(args)) {
  2621. if (Ext.isIterable(args)) {
  2622. args = Ext.Array.clone(args);
  2623. } else {
  2624. args = args !== undefined ? [args] : [];
  2625. }
  2626. }
  2627. return function() {
  2628. var fnArgs = [].concat(args);
  2629. fnArgs.push.apply(fnArgs, arguments);
  2630. return fn.apply(scope || this, fnArgs);
  2631. };
  2632. },
  2633. /**
  2634. * Create an alias to the provided method property with name `methodName` of `object`.
  2635. * Note that the execution scope will still be bound to the provided `object` itself.
  2636. *
  2637. * @param {Object/Function} object
  2638. * @param {String} methodName
  2639. * @return {Function} aliasFn
  2640. */
  2641. alias: function(object, methodName) {
  2642. return function() {
  2643. return object[methodName].apply(object, arguments);
  2644. };
  2645. },
  2646. /**
  2647. * Create a "clone" of the provided method. The returned method will call the given
  2648. * method passing along all arguments and the "this" pointer and return its result.
  2649. *
  2650. * @param {Function} method
  2651. * @return {Function} cloneFn
  2652. */
  2653. clone: function(method) {
  2654. return function() {
  2655. return method.apply(this, arguments);
  2656. };
  2657. },
  2658. /**
  2659. * Creates an interceptor function. The passed function is called before the original one. If it returns false,
  2660. * the original one is not called. The resulting function returns the results of the original function.
  2661. * The passed function is called with the parameters of the original function. Example usage:
  2662. *
  2663. * var sayHi = function(name){
  2664. * alert('Hi, ' + name);
  2665. * }
  2666. *
  2667. * sayHi('Fred'); // alerts "Hi, Fred"
  2668. *
  2669. * // create a new function that validates input without
  2670. * // directly modifying the original function:
  2671. * var sayHiToFriend = Ext.Function.createInterceptor(sayHi, function(name){
  2672. * return name == 'Brian';
  2673. * });
  2674. *
  2675. * sayHiToFriend('Fred'); // no alert
  2676. * sayHiToFriend('Brian'); // alerts "Hi, Brian"
  2677. *
  2678. * @param {Function} origFn The original function.
  2679. * @param {Function} newFn The function to call before the original
  2680. * @param {Object} scope (optional) The scope (`this` reference) in which the passed function is executed.
  2681. * **If omitted, defaults to the scope in which the original function is called or the browser window.**
  2682. * @param {Object} returnValue (optional) The value to return if the passed function return false (defaults to null).
  2683. * @return {Function} The new function
  2684. */
  2685. createInterceptor: function(origFn, newFn, scope, returnValue) {
  2686. var method = origFn;
  2687. if (!Ext.isFunction(newFn)) {
  2688. return origFn;
  2689. }
  2690. else {
  2691. return function() {
  2692. var me = this,
  2693. args = arguments;
  2694. newFn.target = me;
  2695. newFn.method = origFn;
  2696. return (newFn.apply(scope || me || Ext.global, args) !== false) ? origFn.apply(me || Ext.global, args) : returnValue || null;
  2697. };
  2698. }
  2699. },
  2700. /**
  2701. * Creates a delegate (callback) which, when called, executes after a specific delay.
  2702. *
  2703. * @param {Function} fn The function which will be called on a delay when the returned function is called.
  2704. * Optionally, a replacement (or additional) argument list may be specified.
  2705. * @param {Number} delay The number of milliseconds to defer execution by whenever called.
  2706. * @param {Object} scope (optional) The scope (`this` reference) used by the function at execution time.
  2707. * @param {Array} args (optional) Override arguments for the call. (Defaults to the arguments passed by the caller)
  2708. * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
  2709. * if a number the args are inserted at the specified position.
  2710. * @return {Function} A function which, when called, executes the original function after the specified delay.
  2711. */
  2712. createDelayed: function(fn, delay, scope, args, appendArgs) {
  2713. if (scope || args) {
  2714. fn = Ext.Function.bind(fn, scope, args, appendArgs);
  2715. }
  2716. return function() {
  2717. var me = this,
  2718. args = Array.prototype.slice.call(arguments);
  2719. setTimeout(function() {
  2720. fn.apply(me, args);
  2721. }, delay);
  2722. };
  2723. },
  2724. /**
  2725. * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
  2726. *
  2727. * var sayHi = function(name){
  2728. * alert('Hi, ' + name);
  2729. * }
  2730. *
  2731. * // executes immediately:
  2732. * sayHi('Fred');
  2733. *
  2734. * // executes after 2 seconds:
  2735. * Ext.Function.defer(sayHi, 2000, this, ['Fred']);
  2736. *
  2737. * // this syntax is sometimes useful for deferring
  2738. * // execution of an anonymous function:
  2739. * Ext.Function.defer(function(){
  2740. * alert('Anonymous');
  2741. * }, 100);
  2742. *
  2743. * {@link Ext#defer Ext.defer} is alias for {@link Ext.Function#defer Ext.Function.defer}
  2744. *
  2745. * @param {Function} fn The function to defer.
  2746. * @param {Number} millis The number of milliseconds for the setTimeout call
  2747. * (if less than or equal to 0 the function is executed immediately)
  2748. * @param {Object} scope (optional) The scope (`this` reference) in which the function is executed.
  2749. * **If omitted, defaults to the browser window.**
  2750. * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
  2751. * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
  2752. * if a number the args are inserted at the specified position
  2753. * @return {Number} The timeout id that can be used with clearTimeout
  2754. */
  2755. defer: function(fn, millis, scope, args, appendArgs) {
  2756. fn = Ext.Function.bind(fn, scope, args, appendArgs);
  2757. if (millis > 0) {
  2758. return setTimeout(Ext.supports.TimeoutActualLateness ? function () {
  2759. fn();
  2760. } : fn, millis);
  2761. }
  2762. fn();
  2763. return 0;
  2764. },
  2765. /**
  2766. * Create a combined function call sequence of the original function + the passed function.
  2767. * The resulting function returns the results of the original function.
  2768. * The passed function is called with the parameters of the original function. Example usage:
  2769. *
  2770. * var sayHi = function(name){
  2771. * alert('Hi, ' + name);
  2772. * }
  2773. *
  2774. * sayHi('Fred'); // alerts "Hi, Fred"
  2775. *
  2776. * var sayGoodbye = Ext.Function.createSequence(sayHi, function(name){
  2777. * alert('Bye, ' + name);
  2778. * });
  2779. *
  2780. * sayGoodbye('Fred'); // both alerts show
  2781. *
  2782. * @param {Function} originalFn The original function.
  2783. * @param {Function} newFn The function to sequence
  2784. * @param {Object} scope (optional) The scope (`this` reference) in which the passed function is executed.
  2785. * If omitted, defaults to the scope in which the original function is called or the default global environment object (usually the browser window).
  2786. * @return {Function} The new function
  2787. */
  2788. createSequence: function(originalFn, newFn, scope) {
  2789. if (!newFn) {
  2790. return originalFn;
  2791. }
  2792. else {
  2793. return function() {
  2794. var result = originalFn.apply(this, arguments);
  2795. newFn.apply(scope || this, arguments);
  2796. return result;
  2797. };
  2798. }
  2799. },
  2800. /**
  2801. * Creates a delegate function, optionally with a bound scope which, when called, buffers
  2802. * the execution of the passed function for the configured number of milliseconds.
  2803. * If called again within that period, the impending invocation will be canceled, and the
  2804. * timeout period will begin again.
  2805. *
  2806. * @param {Function} fn The function to invoke on a buffered timer.
  2807. * @param {Number} buffer The number of milliseconds by which to buffer the invocation of the
  2808. * function.
  2809. * @param {Object} scope (optional) The scope (`this` reference) in which
  2810. * the passed function is executed. If omitted, defaults to the scope specified by the caller.
  2811. * @param {Array} args (optional) Override arguments for the call. Defaults to the arguments
  2812. * passed by the caller.
  2813. * @return {Function} A function which invokes the passed function after buffering for the specified time.
  2814. */
  2815. createBuffered: function(fn, buffer, scope, args) {
  2816. var timerId;
  2817. return function() {
  2818. var callArgs = args || Array.prototype.slice.call(arguments, 0),
  2819. me = scope || this;
  2820. if (timerId) {
  2821. clearTimeout(timerId);
  2822. }
  2823. timerId = setTimeout(function(){
  2824. fn.apply(me, callArgs);
  2825. }, buffer);
  2826. };
  2827. },
  2828. /**
  2829. * Creates a throttled version of the passed function which, when called repeatedly and
  2830. * rapidly, invokes the passed function only after a certain interval has elapsed since the
  2831. * previous invocation.
  2832. *
  2833. * This is useful for wrapping functions which may be called repeatedly, such as
  2834. * a handler of a mouse move event when the processing is expensive.
  2835. *
  2836. * @param {Function} fn The function to execute at a regular time interval.
  2837. * @param {Number} interval The interval **in milliseconds** on which the passed function is executed.
  2838. * @param {Object} scope (optional) The scope (`this` reference) in which
  2839. * the passed function is executed. If omitted, defaults to the scope specified by the caller.
  2840. * @returns {Function} A function which invokes the passed function at the specified interval.
  2841. */
  2842. createThrottled: function(fn, interval, scope) {
  2843. var lastCallTime, elapsed, lastArgs, timer, execute = function() {
  2844. fn.apply(scope || this, lastArgs);
  2845. lastCallTime = new Date().getTime();
  2846. };
  2847. return function() {
  2848. elapsed = new Date().getTime() - lastCallTime;
  2849. lastArgs = arguments;
  2850. clearTimeout(timer);
  2851. if (!lastCallTime || (elapsed >= interval)) {
  2852. execute();
  2853. } else {
  2854. timer = setTimeout(execute, interval - elapsed);
  2855. }
  2856. };
  2857. },
  2858. /**
  2859. * Adds behavior to an existing method that is executed before the
  2860. * original behavior of the function. For example:
  2861. *
  2862. * var soup = {
  2863. * contents: [],
  2864. * add: function(ingredient) {
  2865. * this.contents.push(ingredient);
  2866. * }
  2867. * };
  2868. * Ext.Function.interceptBefore(soup, "add", function(ingredient){
  2869. * if (!this.contents.length && ingredient !== "water") {
  2870. * // Always add water to start with
  2871. * this.contents.push("water");
  2872. * }
  2873. * });
  2874. * soup.add("onions");
  2875. * soup.add("salt");
  2876. * soup.contents; // will contain: water, onions, salt
  2877. *
  2878. * @param {Object} object The target object
  2879. * @param {String} methodName Name of the method to override
  2880. * @param {Function} fn Function with the new behavior. It will
  2881. * be called with the same arguments as the original method. The
  2882. * return value of this function will be the return value of the
  2883. * new method.
  2884. * @param {Object} [scope] The scope to execute the interceptor function. Defaults to the object.
  2885. * @return {Function} The new function just created.
  2886. */
  2887. interceptBefore: function(object, methodName, fn, scope) {
  2888. var method = object[methodName] || Ext.emptyFn;
  2889. return (object[methodName] = function() {
  2890. var ret = fn.apply(scope || this, arguments);
  2891. method.apply(this, arguments);
  2892. return ret;
  2893. });
  2894. },
  2895. /**
  2896. * Adds behavior to an existing method that is executed after the
  2897. * original behavior of the function. For example:
  2898. *
  2899. * var soup = {
  2900. * contents: [],
  2901. * add: function(ingredient) {
  2902. * this.contents.push(ingredient);
  2903. * }
  2904. * };
  2905. * Ext.Function.interceptAfter(soup, "add", function(ingredient){
  2906. * // Always add a bit of extra salt
  2907. * this.contents.push("salt");
  2908. * });
  2909. * soup.add("water");
  2910. * soup.add("onions");
  2911. * soup.contents; // will contain: water, salt, onions, salt
  2912. *
  2913. * @param {Object} object The target object
  2914. * @param {String} methodName Name of the method to override
  2915. * @param {Function} fn Function with the new behavior. It will
  2916. * be called with the same arguments as the original method. The
  2917. * return value of this function will be the return value of the
  2918. * new method.
  2919. * @param {Object} [scope] The scope to execute the interceptor function. Defaults to the object.
  2920. * @return {Function} The new function just created.
  2921. */
  2922. interceptAfter: function(object, methodName, fn, scope) {
  2923. var method = object[methodName] || Ext.emptyFn;
  2924. return (object[methodName] = function() {
  2925. method.apply(this, arguments);
  2926. return fn.apply(scope || this, arguments);
  2927. });
  2928. }
  2929. };
  2930. /**
  2931. * @method
  2932. * @member Ext
  2933. * @inheritdoc Ext.Function#defer
  2934. */
  2935. Ext.defer = Ext.Function.alias(Ext.Function, 'defer');
  2936. /**
  2937. * @method
  2938. * @member Ext
  2939. * @inheritdoc Ext.Function#pass
  2940. */
  2941. Ext.pass = Ext.Function.alias(Ext.Function, 'pass');
  2942. /**
  2943. * @method
  2944. * @member Ext
  2945. * @inheritdoc Ext.Function#bind
  2946. */
  2947. Ext.bind = Ext.Function.alias(Ext.Function, 'bind');
  2948. /**
  2949. * @author Jacky Nguyen <jacky@sencha.com>
  2950. * @docauthor Jacky Nguyen <jacky@sencha.com>
  2951. * @class Ext.Object
  2952. *
  2953. * A collection of useful static methods to deal with objects.
  2954. *
  2955. * @singleton
  2956. */
  2957. (function() {
  2958. // The "constructor" for chain:
  2959. var TemplateClass = function(){},
  2960. ExtObject = Ext.Object = {
  2961. /**
  2962. * Returns a new object with the given object as the prototype chain.
  2963. * @param {Object} object The prototype chain for the new object.
  2964. */
  2965. chain: function (object) {
  2966. TemplateClass.prototype = object;
  2967. var result = new TemplateClass();
  2968. TemplateClass.prototype = null;
  2969. return result;
  2970. },
  2971. /**
  2972. * Converts a `name` - `value` pair to an array of objects with support for nested structures. Useful to construct
  2973. * query strings. For example:
  2974. *
  2975. * var objects = Ext.Object.toQueryObjects('hobbies', ['reading', 'cooking', 'swimming']);
  2976. *
  2977. * // objects then equals:
  2978. * [
  2979. * { name: 'hobbies', value: 'reading' },
  2980. * { name: 'hobbies', value: 'cooking' },
  2981. * { name: 'hobbies', value: 'swimming' },
  2982. * ];
  2983. *
  2984. * var objects = Ext.Object.toQueryObjects('dateOfBirth', {
  2985. * day: 3,
  2986. * month: 8,
  2987. * year: 1987,
  2988. * extra: {
  2989. * hour: 4
  2990. * minute: 30
  2991. * }
  2992. * }, true); // Recursive
  2993. *
  2994. * // objects then equals:
  2995. * [
  2996. * { name: 'dateOfBirth[day]', value: 3 },
  2997. * { name: 'dateOfBirth[month]', value: 8 },
  2998. * { name: 'dateOfBirth[year]', value: 1987 },
  2999. * { name: 'dateOfBirth[extra][hour]', value: 4 },
  3000. * { name: 'dateOfBirth[extra][minute]', value: 30 },
  3001. * ];
  3002. *
  3003. * @param {String} name
  3004. * @param {Object/Array} value
  3005. * @param {Boolean} [recursive=false] True to traverse object recursively
  3006. * @return {Array}
  3007. */
  3008. toQueryObjects: function(name, value, recursive) {
  3009. var self = ExtObject.toQueryObjects,
  3010. objects = [],
  3011. i, ln;
  3012. if (Ext.isArray(value)) {
  3013. for (i = 0, ln = value.length; i < ln; i++) {
  3014. if (recursive) {
  3015. objects = objects.concat(self(name + '[' + i + ']', value[i], true));
  3016. }
  3017. else {
  3018. objects.push({
  3019. name: name,
  3020. value: value[i]
  3021. });
  3022. }
  3023. }
  3024. }
  3025. else if (Ext.isObject(value)) {
  3026. for (i in value) {
  3027. if (value.hasOwnProperty(i)) {
  3028. if (recursive) {
  3029. objects = objects.concat(self(name + '[' + i + ']', value[i], true));
  3030. }
  3031. else {
  3032. objects.push({
  3033. name: name,
  3034. value: value[i]
  3035. });
  3036. }
  3037. }
  3038. }
  3039. }
  3040. else {
  3041. objects.push({
  3042. name: name,
  3043. value: value
  3044. });
  3045. }
  3046. return objects;
  3047. },
  3048. /**
  3049. * Takes an object and converts it to an encoded query string.
  3050. *
  3051. * Non-recursive:
  3052. *
  3053. * Ext.Object.toQueryString({foo: 1, bar: 2}); // returns "foo=1&bar=2"
  3054. * Ext.Object.toQueryString({foo: null, bar: 2}); // returns "foo=&bar=2"
  3055. * Ext.Object.toQueryString({'some price': '$300'}); // returns "some%20price=%24300"
  3056. * Ext.Object.toQueryString({date: new Date(2011, 0, 1)}); // returns "date=%222011-01-01T00%3A00%3A00%22"
  3057. * Ext.Object.toQueryString({colors: ['red', 'green', 'blue']}); // returns "colors=red&colors=green&colors=blue"
  3058. *
  3059. * Recursive:
  3060. *
  3061. * Ext.Object.toQueryString({
  3062. * username: 'Jacky',
  3063. * dateOfBirth: {
  3064. * day: 1,
  3065. * month: 2,
  3066. * year: 1911
  3067. * },
  3068. * hobbies: ['coding', 'eating', 'sleeping', ['nested', 'stuff']]
  3069. * }, true); // returns the following string (broken down and url-decoded for ease of reading purpose):
  3070. * // username=Jacky
  3071. * // &dateOfBirth[day]=1&dateOfBirth[month]=2&dateOfBirth[year]=1911
  3072. * // &hobbies[0]=coding&hobbies[1]=eating&hobbies[2]=sleeping&hobbies[3][0]=nested&hobbies[3][1]=stuff
  3073. *
  3074. * @param {Object} object The object to encode
  3075. * @param {Boolean} [recursive=false] Whether or not to interpret the object in recursive format.
  3076. * (PHP / Ruby on Rails servers and similar).
  3077. * @return {String} queryString
  3078. */
  3079. toQueryString: function(object, recursive) {
  3080. var paramObjects = [],
  3081. params = [],
  3082. i, j, ln, paramObject, value;
  3083. for (i in object) {
  3084. if (object.hasOwnProperty(i)) {
  3085. paramObjects = paramObjects.concat(ExtObject.toQueryObjects(i, object[i], recursive));
  3086. }
  3087. }
  3088. for (j = 0, ln = paramObjects.length; j < ln; j++) {
  3089. paramObject = paramObjects[j];
  3090. value = paramObject.value;
  3091. if (Ext.isEmpty(value)) {
  3092. value = '';
  3093. }
  3094. else if (Ext.isDate(value)) {
  3095. value = Ext.Date.toString(value);
  3096. }
  3097. params.push(encodeURIComponent(paramObject.name) + '=' + encodeURIComponent(String(value)));
  3098. }
  3099. return params.join('&');
  3100. },
  3101. /**
  3102. * Converts a query string back into an object.
  3103. *
  3104. * Non-recursive:
  3105. *
  3106. * Ext.Object.fromQueryString("foo=1&bar=2"); // returns {foo: 1, bar: 2}
  3107. * Ext.Object.fromQueryString("foo=&bar=2"); // returns {foo: null, bar: 2}
  3108. * Ext.Object.fromQueryString("some%20price=%24300"); // returns {'some price': '$300'}
  3109. * Ext.Object.fromQueryString("colors=red&colors=green&colors=blue"); // returns {colors: ['red', 'green', 'blue']}
  3110. *
  3111. * Recursive:
  3112. *
  3113. * Ext.Object.fromQueryString(
  3114. * "username=Jacky&"+
  3115. * "dateOfBirth[day]=1&dateOfBirth[month]=2&dateOfBirth[year]=1911&"+
  3116. * "hobbies[0]=coding&hobbies[1]=eating&hobbies[2]=sleeping&"+
  3117. * "hobbies[3][0]=nested&hobbies[3][1]=stuff", true);
  3118. *
  3119. * // returns
  3120. * {
  3121. * username: 'Jacky',
  3122. * dateOfBirth: {
  3123. * day: '1',
  3124. * month: '2',
  3125. * year: '1911'
  3126. * },
  3127. * hobbies: ['coding', 'eating', 'sleeping', ['nested', 'stuff']]
  3128. * }
  3129. *
  3130. * @param {String} queryString The query string to decode
  3131. * @param {Boolean} [recursive=false] Whether or not to recursively decode the string. This format is supported by
  3132. * PHP / Ruby on Rails servers and similar.
  3133. * @return {Object}
  3134. */
  3135. fromQueryString: function(queryString, recursive) {
  3136. var parts = queryString.replace(/^\?/, '').split('&'),
  3137. object = {},
  3138. temp, components, name, value, i, ln,
  3139. part, j, subLn, matchedKeys, matchedName,
  3140. keys, key, nextKey;
  3141. for (i = 0, ln = parts.length; i < ln; i++) {
  3142. part = parts[i];
  3143. if (part.length > 0) {
  3144. components = part.split('=');
  3145. name = decodeURIComponent(components[0]);
  3146. value = (components[1] !== undefined) ? decodeURIComponent(components[1]) : '';
  3147. if (!recursive) {
  3148. if (object.hasOwnProperty(name)) {
  3149. if (!Ext.isArray(object[name])) {
  3150. object[name] = [object[name]];
  3151. }
  3152. object[name].push(value);
  3153. }
  3154. else {
  3155. object[name] = value;
  3156. }
  3157. }
  3158. else {
  3159. matchedKeys = name.match(/(\[):?([^\]]*)\]/g);
  3160. matchedName = name.match(/^([^\[]+)/);
  3161. //<debug error>
  3162. if (!matchedName) {
  3163. throw new Error('[Ext.Object.fromQueryString] Malformed query string given, failed parsing name from "' + part + '"');
  3164. }
  3165. //</debug>
  3166. name = matchedName[0];
  3167. keys = [];
  3168. if (matchedKeys === null) {
  3169. object[name] = value;
  3170. continue;
  3171. }
  3172. for (j = 0, subLn = matchedKeys.length; j < subLn; j++) {
  3173. key = matchedKeys[j];
  3174. key = (key.length === 2) ? '' : key.substring(1, key.length - 1);
  3175. keys.push(key);
  3176. }
  3177. keys.unshift(name);
  3178. temp = object;
  3179. for (j = 0, subLn = keys.length; j < subLn; j++) {
  3180. key = keys[j];
  3181. if (j === subLn - 1) {
  3182. if (Ext.isArray(temp) && key === '') {
  3183. temp.push(value);
  3184. }
  3185. else {
  3186. temp[key] = value;
  3187. }
  3188. }
  3189. else {
  3190. if (temp[key] === undefined || typeof temp[key] === 'string') {
  3191. nextKey = keys[j+1];
  3192. temp[key] = (Ext.isNumeric(nextKey) || nextKey === '') ? [] : {};
  3193. }
  3194. temp = temp[key];
  3195. }
  3196. }
  3197. }
  3198. }
  3199. }
  3200. return object;
  3201. },
  3202. /**
  3203. * Iterates through an object and invokes the given callback function for each iteration.
  3204. * The iteration can be stopped by returning `false` in the callback function. For example:
  3205. *
  3206. * var person = {
  3207. * name: 'Jacky'
  3208. * hairColor: 'black'
  3209. * loves: ['food', 'sleeping', 'wife']
  3210. * };
  3211. *
  3212. * Ext.Object.each(person, function(key, value, myself) {
  3213. * console.log(key + ":" + value);
  3214. *
  3215. * if (key === 'hairColor') {
  3216. * return false; // stop the iteration
  3217. * }
  3218. * });
  3219. *
  3220. * @param {Object} object The object to iterate
  3221. * @param {Function} fn The callback function.
  3222. * @param {String} fn.key
  3223. * @param {Object} fn.value
  3224. * @param {Object} fn.object The object itself
  3225. * @param {Object} [scope] The execution scope (`this`) of the callback function
  3226. */
  3227. each: function(object, fn, scope) {
  3228. for (var property in object) {
  3229. if (object.hasOwnProperty(property)) {
  3230. if (fn.call(scope || object, property, object[property], object) === false) {
  3231. return;
  3232. }
  3233. }
  3234. }
  3235. },
  3236. /**
  3237. * Merges any number of objects recursively without referencing them or their children.
  3238. *
  3239. * var extjs = {
  3240. * companyName: 'Ext JS',
  3241. * products: ['Ext JS', 'Ext GWT', 'Ext Designer'],
  3242. * isSuperCool: true,
  3243. * office: {
  3244. * size: 2000,
  3245. * location: 'Palo Alto',
  3246. * isFun: true
  3247. * }
  3248. * };
  3249. *
  3250. * var newStuff = {
  3251. * companyName: 'Sencha Inc.',
  3252. * products: ['Ext JS', 'Ext GWT', 'Ext Designer', 'Sencha Touch', 'Sencha Animator'],
  3253. * office: {
  3254. * size: 40000,
  3255. * location: 'Redwood City'
  3256. * }
  3257. * };
  3258. *
  3259. * var sencha = Ext.Object.merge(extjs, newStuff);
  3260. *
  3261. * // extjs and sencha then equals to
  3262. * {
  3263. * companyName: 'Sencha Inc.',
  3264. * products: ['Ext JS', 'Ext GWT', 'Ext Designer', 'Sencha Touch', 'Sencha Animator'],
  3265. * isSuperCool: true,
  3266. * office: {
  3267. * size: 40000,
  3268. * location: 'Redwood City',
  3269. * isFun: true
  3270. * }
  3271. * }
  3272. *
  3273. * @param {Object} destination The object into which all subsequent objects are merged.
  3274. * @param {Object...} object Any number of objects to merge into the destination.
  3275. * @return {Object} merged The destination object with all passed objects merged in.
  3276. */
  3277. merge: function(destination) {
  3278. var i = 1,
  3279. ln = arguments.length,
  3280. mergeFn = ExtObject.merge,
  3281. cloneFn = Ext.clone,
  3282. object, key, value, sourceKey;
  3283. for (; i < ln; i++) {
  3284. object = arguments[i];
  3285. for (key in object) {
  3286. value = object[key];
  3287. if (value && value.constructor === Object) {
  3288. sourceKey = destination[key];
  3289. if (sourceKey && sourceKey.constructor === Object) {
  3290. mergeFn(sourceKey, value);
  3291. }
  3292. else {
  3293. destination[key] = cloneFn(value);
  3294. }
  3295. }
  3296. else {
  3297. destination[key] = value;
  3298. }
  3299. }
  3300. }
  3301. return destination;
  3302. },
  3303. /**
  3304. * @private
  3305. * @param destination
  3306. */
  3307. mergeIf: function(destination) {
  3308. var i = 1,
  3309. ln = arguments.length,
  3310. cloneFn = Ext.clone,
  3311. object, key, value;
  3312. for (; i < ln; i++) {
  3313. object = arguments[i];
  3314. for (key in object) {
  3315. if (!(key in destination)) {
  3316. value = object[key];
  3317. if (value && value.constructor === Object) {
  3318. destination[key] = cloneFn(value);
  3319. }
  3320. else {
  3321. destination[key] = value;
  3322. }
  3323. }
  3324. }
  3325. }
  3326. return destination;
  3327. },
  3328. /**
  3329. * Returns the first matching key corresponding to the given value.
  3330. * If no matching value is found, null is returned.
  3331. *
  3332. * var person = {
  3333. * name: 'Jacky',
  3334. * loves: 'food'
  3335. * };
  3336. *
  3337. * alert(Ext.Object.getKey(person, 'food')); // alerts 'loves'
  3338. *
  3339. * @param {Object} object
  3340. * @param {Object} value The value to find
  3341. */
  3342. getKey: function(object, value) {
  3343. for (var property in object) {
  3344. if (object.hasOwnProperty(property) && object[property] === value) {
  3345. return property;
  3346. }
  3347. }
  3348. return null;
  3349. },
  3350. /**
  3351. * Gets all values of the given object as an array.
  3352. *
  3353. * var values = Ext.Object.getValues({
  3354. * name: 'Jacky',
  3355. * loves: 'food'
  3356. * }); // ['Jacky', 'food']
  3357. *
  3358. * @param {Object} object
  3359. * @return {Array} An array of values from the object
  3360. */
  3361. getValues: function(object) {
  3362. var values = [],
  3363. property;
  3364. for (property in object) {
  3365. if (object.hasOwnProperty(property)) {
  3366. values.push(object[property]);
  3367. }
  3368. }
  3369. return values;
  3370. },
  3371. /**
  3372. * Gets all keys of the given object as an array.
  3373. *
  3374. * var values = Ext.Object.getKeys({
  3375. * name: 'Jacky',
  3376. * loves: 'food'
  3377. * }); // ['name', 'loves']
  3378. *
  3379. * @param {Object} object
  3380. * @return {String[]} An array of keys from the object
  3381. * @method
  3382. */
  3383. getKeys: (typeof Object.keys == 'function')
  3384. ? function(object){
  3385. if (!object) {
  3386. return [];
  3387. }
  3388. return Object.keys(object);
  3389. }
  3390. : function(object) {
  3391. var keys = [],
  3392. property;
  3393. for (property in object) {
  3394. if (object.hasOwnProperty(property)) {
  3395. keys.push(property);
  3396. }
  3397. }
  3398. return keys;
  3399. },
  3400. /**
  3401. * Gets the total number of this object's own properties
  3402. *
  3403. * var size = Ext.Object.getSize({
  3404. * name: 'Jacky',
  3405. * loves: 'food'
  3406. * }); // size equals 2
  3407. *
  3408. * @param {Object} object
  3409. * @return {Number} size
  3410. */
  3411. getSize: function(object) {
  3412. var size = 0,
  3413. property;
  3414. for (property in object) {
  3415. if (object.hasOwnProperty(property)) {
  3416. size++;
  3417. }
  3418. }
  3419. return size;
  3420. },
  3421. /**
  3422. * @private
  3423. */
  3424. classify: function(object) {
  3425. var prototype = object,
  3426. objectProperties = [],
  3427. propertyClassesMap = {},
  3428. objectClass = function() {
  3429. var i = 0,
  3430. ln = objectProperties.length,
  3431. property;
  3432. for (; i < ln; i++) {
  3433. property = objectProperties[i];
  3434. this[property] = new propertyClassesMap[property]();
  3435. }
  3436. },
  3437. key, value;
  3438. for (key in object) {
  3439. if (object.hasOwnProperty(key)) {
  3440. value = object[key];
  3441. if (value && value.constructor === Object) {
  3442. objectProperties.push(key);
  3443. propertyClassesMap[key] = ExtObject.classify(value);
  3444. }
  3445. }
  3446. }
  3447. objectClass.prototype = prototype;
  3448. return objectClass;
  3449. }
  3450. };
  3451. /**
  3452. * A convenient alias method for {@link Ext.Object#merge}.
  3453. *
  3454. * @member Ext
  3455. * @method merge
  3456. * @inheritdoc Ext.Object#merge
  3457. */
  3458. Ext.merge = Ext.Object.merge;
  3459. /**
  3460. * @private
  3461. * @member Ext
  3462. */
  3463. Ext.mergeIf = Ext.Object.mergeIf;
  3464. /**
  3465. *
  3466. * @member Ext
  3467. * @method urlEncode
  3468. * @inheritdoc Ext.Object#toQueryString
  3469. * @deprecated 4.0.0 Use {@link Ext.Object#toQueryString} instead
  3470. */
  3471. Ext.urlEncode = function() {
  3472. var args = Ext.Array.from(arguments),
  3473. prefix = '';
  3474. // Support for the old `pre` argument
  3475. if ((typeof args[1] === 'string')) {
  3476. prefix = args[1] + '&';
  3477. args[1] = false;
  3478. }
  3479. return prefix + ExtObject.toQueryString.apply(ExtObject, args);
  3480. };
  3481. /**
  3482. * Alias for {@link Ext.Object#fromQueryString}.
  3483. *
  3484. * @member Ext
  3485. * @method urlDecode
  3486. * @inheritdoc Ext.Object#fromQueryString
  3487. * @deprecated 4.0.0 Use {@link Ext.Object#fromQueryString} instead
  3488. */
  3489. Ext.urlDecode = function() {
  3490. return ExtObject.fromQueryString.apply(ExtObject, arguments);
  3491. };
  3492. }());
  3493. /**
  3494. * @class Ext.Date
  3495. * A set of useful static methods to deal with date
  3496. * Note that if Ext.Date is required and loaded, it will copy all methods / properties to
  3497. * this object for convenience
  3498. *
  3499. * The date parsing and formatting syntax contains a subset of
  3500. * <a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
  3501. * supported will provide results equivalent to their PHP versions.
  3502. *
  3503. * The following is a list of all currently supported formats:
  3504. * <pre class="">
  3505. Format Description Example returned values
  3506. ------ ----------------------------------------------------------------------- -----------------------
  3507. d Day of the month, 2 digits with leading zeros 01 to 31
  3508. D A short textual representation of the day of the week Mon to Sun
  3509. j Day of the month without leading zeros 1 to 31
  3510. l A full textual representation of the day of the week Sunday to Saturday
  3511. N ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)
  3512. S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
  3513. w Numeric representation of the day of the week 0 (for Sunday) to 6 (for Saturday)
  3514. z The day of the year (starting from 0) 0 to 364 (365 in leap years)
  3515. W ISO-8601 week number of year, weeks starting on Monday 01 to 53
  3516. F A full textual representation of a month, such as January or March January to December
  3517. m Numeric representation of a month, with leading zeros 01 to 12
  3518. M A short textual representation of a month Jan to Dec
  3519. n Numeric representation of a month, without leading zeros 1 to 12
  3520. t Number of days in the given month 28 to 31
  3521. L Whether it&#39;s a leap year 1 if it is a leap year, 0 otherwise.
  3522. o ISO-8601 year number (identical to (Y), but if the ISO week number (W) Examples: 1998 or 2004
  3523. belongs to the previous or next year, that year is used instead)
  3524. Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003
  3525. y A two digit representation of a year Examples: 99 or 03
  3526. a Lowercase Ante meridiem and Post meridiem am or pm
  3527. A Uppercase Ante meridiem and Post meridiem AM or PM
  3528. g 12-hour format of an hour without leading zeros 1 to 12
  3529. G 24-hour format of an hour without leading zeros 0 to 23
  3530. h 12-hour format of an hour with leading zeros 01 to 12
  3531. H 24-hour format of an hour with leading zeros 00 to 23
  3532. i Minutes, with leading zeros 00 to 59
  3533. s Seconds, with leading zeros 00 to 59
  3534. u Decimal fraction of a second Examples:
  3535. (minimum 1 digit, arbitrary number of digits allowed) 001 (i.e. 0.001s) or
  3536. 100 (i.e. 0.100s) or
  3537. 999 (i.e. 0.999s) or
  3538. 999876543210 (i.e. 0.999876543210s)
  3539. O Difference to Greenwich time (GMT) in hours and minutes Example: +1030
  3540. P Difference to Greenwich time (GMT) with colon between hours and minutes Example: -08:00
  3541. T Timezone abbreviation of the machine running the code Examples: EST, MDT, PDT ...
  3542. Z Timezone offset in seconds (negative if west of UTC, positive if east) -43200 to 50400
  3543. c ISO 8601 date
  3544. Notes: Examples:
  3545. 1) If unspecified, the month / day defaults to the current month / day, 1991 or
  3546. the time defaults to midnight, while the timezone defaults to the 1992-10 or
  3547. browser's timezone. If a time is specified, it must include both hours 1993-09-20 or
  3548. and minutes. The "T" delimiter, seconds, milliseconds and timezone 1994-08-19T16:20+01:00 or
  3549. are optional. 1995-07-18T17:21:28-02:00 or
  3550. 2) The decimal fraction of a second, if specified, must contain at 1996-06-17T18:22:29.98765+03:00 or
  3551. least 1 digit (there is no limit to the maximum number 1997-05-16T19:23:30,12345-0400 or
  3552. of digits allowed), and may be delimited by either a '.' or a ',' 1998-04-15T20:24:31.2468Z or
  3553. Refer to the examples on the right for the various levels of 1999-03-14T20:24:32Z or
  3554. date-time granularity which are supported, or see 2000-02-13T21:25:33
  3555. http://www.w3.org/TR/NOTE-datetime for more info. 2001-01-12 22:26:34
  3556. U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 1193432466 or -2138434463
  3557. MS Microsoft AJAX serialized dates \/Date(1238606590509)\/ (i.e. UTC milliseconds since epoch) or
  3558. \/Date(1238606590509+0800)\/
  3559. </pre>
  3560. *
  3561. * Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
  3562. * <pre><code>
  3563. // Sample date:
  3564. // 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
  3565. var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
  3566. console.log(Ext.Date.format(dt, 'Y-m-d')); // 2007-01-10
  3567. console.log(Ext.Date.format(dt, 'F j, Y, g:i a')); // January 10, 2007, 3:05 pm
  3568. 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
  3569. </code></pre>
  3570. *
  3571. * Here are some standard date/time patterns that you might find helpful. They
  3572. * are not part of the source of Ext.Date, but to use them you can simply copy this
  3573. * block of code into any script that is included after Ext.Date and they will also become
  3574. * globally available on the Date object. Feel free to add or remove patterns as needed in your code.
  3575. * <pre><code>
  3576. Ext.Date.patterns = {
  3577. ISO8601Long:"Y-m-d H:i:s",
  3578. ISO8601Short:"Y-m-d",
  3579. ShortDate: "n/j/Y",
  3580. LongDate: "l, F d, Y",
  3581. FullDateTime: "l, F d, Y g:i:s A",
  3582. MonthDay: "F d",
  3583. ShortTime: "g:i A",
  3584. LongTime: "g:i:s A",
  3585. SortableDateTime: "Y-m-d\\TH:i:s",
  3586. UniversalSortableDateTime: "Y-m-d H:i:sO",
  3587. YearMonth: "F, Y"
  3588. };
  3589. </code></pre>
  3590. *
  3591. * Example usage:
  3592. * <pre><code>
  3593. var dt = new Date();
  3594. console.log(Ext.Date.format(dt, Ext.Date.patterns.ShortDate));
  3595. </code></pre>
  3596. * <p>Developer-written, custom formats may be used by supplying both a formatting and a parsing function
  3597. * which perform to specialized requirements. The functions are stored in {@link #parseFunctions} and {@link #formatFunctions}.</p>
  3598. * @singleton
  3599. */
  3600. /*
  3601. * Most of the date-formatting functions below are the excellent work of Baron Schwartz.
  3602. * (see http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/)
  3603. * They generate precompiled functions from format patterns instead of parsing and
  3604. * processing each pattern every time a date is formatted. These functions are available
  3605. * on every Date object.
  3606. */
  3607. (function() {
  3608. // create private copy of Ext's Ext.util.Format.format() method
  3609. // - to remove unnecessary dependency
  3610. // - to resolve namespace conflict with MS-Ajax's implementation
  3611. function xf(format) {
  3612. var args = Array.prototype.slice.call(arguments, 1);
  3613. return format.replace(/\{(\d+)\}/g, function(m, i) {
  3614. return args[i];
  3615. });
  3616. }
  3617. Ext.Date = {
  3618. /**
  3619. * Returns the current timestamp.
  3620. * @return {Number} Milliseconds since UNIX epoch.
  3621. * @method
  3622. */
  3623. now: Date.now || function() {
  3624. return +new Date();
  3625. },
  3626. /**
  3627. * @private
  3628. * Private for now
  3629. */
  3630. toString: function(date) {
  3631. var pad = Ext.String.leftPad;
  3632. return date.getFullYear() + "-"
  3633. + pad(date.getMonth() + 1, 2, '0') + "-"
  3634. + pad(date.getDate(), 2, '0') + "T"
  3635. + pad(date.getHours(), 2, '0') + ":"
  3636. + pad(date.getMinutes(), 2, '0') + ":"
  3637. + pad(date.getSeconds(), 2, '0');
  3638. },
  3639. /**
  3640. * Returns the number of milliseconds between two dates
  3641. * @param {Date} dateA The first date
  3642. * @param {Date} dateB (optional) The second date, defaults to now
  3643. * @return {Number} The difference in milliseconds
  3644. */
  3645. getElapsed: function(dateA, dateB) {
  3646. return Math.abs(dateA - (dateB || new Date()));
  3647. },
  3648. /**
  3649. * Global flag which determines if strict date parsing should be used.
  3650. * Strict date parsing will not roll-over invalid dates, which is the
  3651. * default behaviour of javascript Date objects.
  3652. * (see {@link #parse} for more information)
  3653. * Defaults to <tt>false</tt>.
  3654. * @type Boolean
  3655. */
  3656. useStrict: false,
  3657. // private
  3658. formatCodeToRegex: function(character, currentGroup) {
  3659. // Note: currentGroup - position in regex result array (see notes for Ext.Date.parseCodes below)
  3660. var p = utilDate.parseCodes[character];
  3661. if (p) {
  3662. p = typeof p == 'function'? p() : p;
  3663. utilDate.parseCodes[character] = p; // reassign function result to prevent repeated execution
  3664. }
  3665. return p ? Ext.applyIf({
  3666. c: p.c ? xf(p.c, currentGroup || "{0}") : p.c
  3667. }, p) : {
  3668. g: 0,
  3669. c: null,
  3670. s: Ext.String.escapeRegex(character) // treat unrecognised characters as literals
  3671. };
  3672. },
  3673. /**
  3674. * <p>An object hash in which each property is a date parsing function. The property name is the
  3675. * format string which that function parses.</p>
  3676. * <p>This object is automatically populated with date parsing functions as
  3677. * date formats are requested for Ext standard formatting strings.</p>
  3678. * <p>Custom parsing functions may be inserted into this object, keyed by a name which from then on
  3679. * may be used as a format string to {@link #parse}.<p>
  3680. * <p>Example:</p><pre><code>
  3681. Ext.Date.parseFunctions['x-date-format'] = myDateParser;
  3682. </code></pre>
  3683. * <p>A parsing function should return a Date object, and is passed the following parameters:<div class="mdetail-params"><ul>
  3684. * <li><code>date</code> : String<div class="sub-desc">The date string to parse.</div></li>
  3685. * <li><code>strict</code> : Boolean<div class="sub-desc">True to validate date strings while parsing
  3686. * (i.e. prevent javascript Date "rollover") (The default must be false).
  3687. * Invalid date strings should return null when parsed.</div></li>
  3688. * </ul></div></p>
  3689. * <p>To enable Dates to also be <i>formatted</i> according to that format, a corresponding
  3690. * formatting function must be placed into the {@link #formatFunctions} property.
  3691. * @property parseFunctions
  3692. * @type Object
  3693. */
  3694. parseFunctions: {
  3695. "MS": function(input, strict) {
  3696. // note: the timezone offset is ignored since the MS Ajax server sends
  3697. // a UTC milliseconds-since-Unix-epoch value (negative values are allowed)
  3698. var re = new RegExp('\\/Date\\(([-+])?(\\d+)(?:[+-]\\d{4})?\\)\\/'),
  3699. r = (input || '').match(re);
  3700. return r? new Date(((r[1] || '') + r[2]) * 1) : null;
  3701. }
  3702. },
  3703. parseRegexes: [],
  3704. /**
  3705. * <p>An object hash in which each property is a date formatting function. The property name is the
  3706. * format string which corresponds to the produced formatted date string.</p>
  3707. * <p>This object is automatically populated with date formatting functions as
  3708. * date formats are requested for Ext standard formatting strings.</p>
  3709. * <p>Custom formatting functions may be inserted into this object, keyed by a name which from then on
  3710. * may be used as a format string to {@link #format}. Example:</p><pre><code>
  3711. Ext.Date.formatFunctions['x-date-format'] = myDateFormatter;
  3712. </code></pre>
  3713. * <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>
  3714. * <li><code>date</code> : Date<div class="sub-desc">The Date to format.</div></li>
  3715. * </ul></div></p>
  3716. * <p>To enable date strings to also be <i>parsed</i> according to that format, a corresponding
  3717. * parsing function must be placed into the {@link #parseFunctions} property.
  3718. * @property formatFunctions
  3719. * @type Object
  3720. */
  3721. formatFunctions: {
  3722. "MS": function() {
  3723. // UTC milliseconds since Unix epoch (MS-AJAX serialized date format (MRSF))
  3724. return '\\/Date(' + this.getTime() + ')\\/';
  3725. }
  3726. },
  3727. y2kYear : 50,
  3728. /**
  3729. * Date interval constant
  3730. * @type String
  3731. */
  3732. MILLI : "ms",
  3733. /**
  3734. * Date interval constant
  3735. * @type String
  3736. */
  3737. SECOND : "s",
  3738. /**
  3739. * Date interval constant
  3740. * @type String
  3741. */
  3742. MINUTE : "mi",
  3743. /** Date interval constant
  3744. * @type String
  3745. */
  3746. HOUR : "h",
  3747. /**
  3748. * Date interval constant
  3749. * @type String
  3750. */
  3751. DAY : "d",
  3752. /**
  3753. * Date interval constant
  3754. * @type String
  3755. */
  3756. MONTH : "mo",
  3757. /**
  3758. * Date interval constant
  3759. * @type String
  3760. */
  3761. YEAR : "y",
  3762. /**
  3763. * <p>An object hash containing default date values used during date parsing.</p>
  3764. * <p>The following properties are available:<div class="mdetail-params"><ul>
  3765. * <li><code>y</code> : Number<div class="sub-desc">The default year value. (defaults to undefined)</div></li>
  3766. * <li><code>m</code> : Number<div class="sub-desc">The default 1-based month value. (defaults to undefined)</div></li>
  3767. * <li><code>d</code> : Number<div class="sub-desc">The default day value. (defaults to undefined)</div></li>
  3768. * <li><code>h</code> : Number<div class="sub-desc">The default hour value. (defaults to undefined)</div></li>
  3769. * <li><code>i</code> : Number<div class="sub-desc">The default minute value. (defaults to undefined)</div></li>
  3770. * <li><code>s</code> : Number<div class="sub-desc">The default second value. (defaults to undefined)</div></li>
  3771. * <li><code>ms</code> : Number<div class="sub-desc">The default millisecond value. (defaults to undefined)</div></li>
  3772. * </ul></div></p>
  3773. * <p>Override these properties to customize the default date values used by the {@link #parse} method.</p>
  3774. * <p><b>Note: In countries which experience Daylight Saving Time (i.e. DST), the <tt>h</tt>, <tt>i</tt>, <tt>s</tt>
  3775. * and <tt>ms</tt> properties may coincide with the exact time in which DST takes effect.
  3776. * It is the responsiblity of the developer to account for this.</b></p>
  3777. * Example Usage:
  3778. * <pre><code>
  3779. // set default day value to the first day of the month
  3780. Ext.Date.defaults.d = 1;
  3781. // parse a February date string containing only year and month values.
  3782. // setting the default day value to 1 prevents weird date rollover issues
  3783. // when attempting to parse the following date string on, for example, March 31st 2009.
  3784. Ext.Date.parse('2009-02', 'Y-m'); // returns a Date object representing February 1st 2009
  3785. </code></pre>
  3786. * @property defaults
  3787. * @type Object
  3788. */
  3789. defaults: {},
  3790. //<locale type="array">
  3791. /**
  3792. * @property {String[]} dayNames
  3793. * An array of textual day names.
  3794. * Override these values for international dates.
  3795. * Example:
  3796. * <pre><code>
  3797. Ext.Date.dayNames = [
  3798. 'SundayInYourLang',
  3799. 'MondayInYourLang',
  3800. ...
  3801. ];
  3802. </code></pre>
  3803. */
  3804. dayNames : [
  3805. "Sunday",
  3806. "Monday",
  3807. "Tuesday",
  3808. "Wednesday",
  3809. "Thursday",
  3810. "Friday",
  3811. "Saturday"
  3812. ],
  3813. //</locale>
  3814. //<locale type="array">
  3815. /**
  3816. * @property {String[]} monthNames
  3817. * An array of textual month names.
  3818. * Override these values for international dates.
  3819. * Example:
  3820. * <pre><code>
  3821. Ext.Date.monthNames = [
  3822. 'JanInYourLang',
  3823. 'FebInYourLang',
  3824. ...
  3825. ];
  3826. </code></pre>
  3827. */
  3828. monthNames : [
  3829. "January",
  3830. "February",
  3831. "March",
  3832. "April",
  3833. "May",
  3834. "June",
  3835. "July",
  3836. "August",
  3837. "September",
  3838. "October",
  3839. "November",
  3840. "December"
  3841. ],
  3842. //</locale>
  3843. //<locale type="object">
  3844. /**
  3845. * @property {Object} monthNumbers
  3846. * An object hash of zero-based javascript month numbers (with short month names as keys. note: keys are case-sensitive).
  3847. * Override these values for international dates.
  3848. * Example:
  3849. * <pre><code>
  3850. Ext.Date.monthNumbers = {
  3851. 'LongJanNameInYourLang': 0,
  3852. 'ShortJanNameInYourLang':0,
  3853. 'LongFebNameInYourLang':1,
  3854. 'ShortFebNameInYourLang':1,
  3855. ...
  3856. };
  3857. </code></pre>
  3858. */
  3859. monthNumbers : {
  3860. January: 0,
  3861. Jan: 0,
  3862. February: 1,
  3863. Feb: 1,
  3864. March: 2,
  3865. Mar: 2,
  3866. April: 3,
  3867. Apr: 3,
  3868. May: 4,
  3869. June: 5,
  3870. Jun: 5,
  3871. July: 6,
  3872. Jul: 6,
  3873. August: 7,
  3874. Aug: 7,
  3875. September: 8,
  3876. Sep: 8,
  3877. October: 9,
  3878. Oct: 9,
  3879. November: 10,
  3880. Nov: 10,
  3881. December: 11,
  3882. Dec: 11
  3883. },
  3884. //</locale>
  3885. //<locale>
  3886. /**
  3887. * @property {String} defaultFormat
  3888. * <p>The date format string that the {@link Ext.util.Format#dateRenderer}
  3889. * and {@link Ext.util.Format#date} functions use. See {@link Ext.Date} for details.</p>
  3890. * <p>This may be overridden in a locale file.</p>
  3891. */
  3892. defaultFormat : "m/d/Y",
  3893. //</locale>
  3894. //<locale type="function">
  3895. /**
  3896. * Get the short month name for the given month number.
  3897. * Override this function for international dates.
  3898. * @param {Number} month A zero-based javascript month number.
  3899. * @return {String} The short month name.
  3900. */
  3901. getShortMonthName : function(month) {
  3902. return Ext.Date.monthNames[month].substring(0, 3);
  3903. },
  3904. //</locale>
  3905. //<locale type="function">
  3906. /**
  3907. * Get the short day name for the given day number.
  3908. * Override this function for international dates.
  3909. * @param {Number} day A zero-based javascript day number.
  3910. * @return {String} The short day name.
  3911. */
  3912. getShortDayName : function(day) {
  3913. return Ext.Date.dayNames[day].substring(0, 3);
  3914. },
  3915. //</locale>
  3916. //<locale type="function">
  3917. /**
  3918. * Get the zero-based javascript month number for the given short/full month name.
  3919. * Override this function for international dates.
  3920. * @param {String} name The short/full month name.
  3921. * @return {Number} The zero-based javascript month number.
  3922. */
  3923. getMonthNumber : function(name) {
  3924. // handle camel casing for english month names (since the keys for the Ext.Date.monthNumbers hash are case sensitive)
  3925. return Ext.Date.monthNumbers[name.substring(0, 1).toUpperCase() + name.substring(1, 3).toLowerCase()];
  3926. },
  3927. //</locale>
  3928. /**
  3929. * Checks if the specified format contains hour information
  3930. * @param {String} format The format to check
  3931. * @return {Boolean} True if the format contains hour information
  3932. * @method
  3933. */
  3934. formatContainsHourInfo : (function(){
  3935. var stripEscapeRe = /(\\.)/g,
  3936. hourInfoRe = /([gGhHisucUOPZ]|MS)/;
  3937. return function(format){
  3938. return hourInfoRe.test(format.replace(stripEscapeRe, ''));
  3939. };
  3940. }()),
  3941. /**
  3942. * Checks if the specified format contains information about
  3943. * anything other than the time.
  3944. * @param {String} format The format to check
  3945. * @return {Boolean} True if the format contains information about
  3946. * date/day information.
  3947. * @method
  3948. */
  3949. formatContainsDateInfo : (function(){
  3950. var stripEscapeRe = /(\\.)/g,
  3951. dateInfoRe = /([djzmnYycU]|MS)/;
  3952. return function(format){
  3953. return dateInfoRe.test(format.replace(stripEscapeRe, ''));
  3954. };
  3955. }()),
  3956. /**
  3957. * Removes all escaping for a date format string. In date formats,
  3958. * using a '\' can be used to escape special characters.
  3959. * @param {String} format The format to unescape
  3960. * @return {String} The unescaped format
  3961. * @method
  3962. */
  3963. unescapeFormat: (function() {
  3964. var slashRe = /\\/gi;
  3965. return function(format) {
  3966. // Escape the format, since \ can be used to escape special
  3967. // characters in a date format. For example, in a spanish
  3968. // locale the format may be: 'd \\de F \\de Y'
  3969. return format.replace(slashRe, '');
  3970. }
  3971. }()),
  3972. /**
  3973. * The base format-code to formatting-function hashmap used by the {@link #format} method.
  3974. * Formatting functions are strings (or functions which return strings) which
  3975. * will return the appropriate value when evaluated in the context of the Date object
  3976. * from which the {@link #format} method is called.
  3977. * Add to / override these mappings for custom date formatting.
  3978. * Note: Ext.Date.format() treats characters as literals if an appropriate mapping cannot be found.
  3979. * Example:
  3980. * <pre><code>
  3981. Ext.Date.formatCodes.x = "Ext.util.Format.leftPad(this.getDate(), 2, '0')";
  3982. console.log(Ext.Date.format(new Date(), 'X'); // returns the current day of the month
  3983. </code></pre>
  3984. * @type Object
  3985. */
  3986. formatCodes : {
  3987. d: "Ext.String.leftPad(this.getDate(), 2, '0')",
  3988. D: "Ext.Date.getShortDayName(this.getDay())", // get localised short day name
  3989. j: "this.getDate()",
  3990. l: "Ext.Date.dayNames[this.getDay()]",
  3991. N: "(this.getDay() ? this.getDay() : 7)",
  3992. S: "Ext.Date.getSuffix(this)",
  3993. w: "this.getDay()",
  3994. z: "Ext.Date.getDayOfYear(this)",
  3995. W: "Ext.String.leftPad(Ext.Date.getWeekOfYear(this), 2, '0')",
  3996. F: "Ext.Date.monthNames[this.getMonth()]",
  3997. m: "Ext.String.leftPad(this.getMonth() + 1, 2, '0')",
  3998. M: "Ext.Date.getShortMonthName(this.getMonth())", // get localised short month name
  3999. n: "(this.getMonth() + 1)",
  4000. t: "Ext.Date.getDaysInMonth(this)",
  4001. L: "(Ext.Date.isLeapYear(this) ? 1 : 0)",
  4002. o: "(this.getFullYear() + (Ext.Date.getWeekOfYear(this) == 1 && this.getMonth() > 0 ? +1 : (Ext.Date.getWeekOfYear(this) >= 52 && this.getMonth() < 11 ? -1 : 0)))",
  4003. Y: "Ext.String.leftPad(this.getFullYear(), 4, '0')",
  4004. y: "('' + this.getFullYear()).substring(2, 4)",
  4005. a: "(this.getHours() < 12 ? 'am' : 'pm')",
  4006. A: "(this.getHours() < 12 ? 'AM' : 'PM')",
  4007. g: "((this.getHours() % 12) ? this.getHours() % 12 : 12)",
  4008. G: "this.getHours()",
  4009. h: "Ext.String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0')",
  4010. H: "Ext.String.leftPad(this.getHours(), 2, '0')",
  4011. i: "Ext.String.leftPad(this.getMinutes(), 2, '0')",
  4012. s: "Ext.String.leftPad(this.getSeconds(), 2, '0')",
  4013. u: "Ext.String.leftPad(this.getMilliseconds(), 3, '0')",
  4014. O: "Ext.Date.getGMTOffset(this)",
  4015. P: "Ext.Date.getGMTOffset(this, true)",
  4016. T: "Ext.Date.getTimezone(this)",
  4017. Z: "(this.getTimezoneOffset() * -60)",
  4018. c: function() { // ISO-8601 -- GMT format
  4019. var c, code, i, l, e;
  4020. for (c = "Y-m-dTH:i:sP", code = [], i = 0, l = c.length; i < l; ++i) {
  4021. e = c.charAt(i);
  4022. code.push(e == "T" ? "'T'" : utilDate.getFormatCode(e)); // treat T as a character literal
  4023. }
  4024. return code.join(" + ");
  4025. },
  4026. /*
  4027. c: function() { // ISO-8601 -- UTC format
  4028. return [
  4029. "this.getUTCFullYear()", "'-'",
  4030. "Ext.util.Format.leftPad(this.getUTCMonth() + 1, 2, '0')", "'-'",
  4031. "Ext.util.Format.leftPad(this.getUTCDate(), 2, '0')",
  4032. "'T'",
  4033. "Ext.util.Format.leftPad(this.getUTCHours(), 2, '0')", "':'",
  4034. "Ext.util.Format.leftPad(this.getUTCMinutes(), 2, '0')", "':'",
  4035. "Ext.util.Format.leftPad(this.getUTCSeconds(), 2, '0')",
  4036. "'Z'"
  4037. ].join(" + ");
  4038. },
  4039. */
  4040. U: "Math.round(this.getTime() / 1000)"
  4041. },
  4042. /**
  4043. * Checks if the passed Date parameters will cause a javascript Date "rollover".
  4044. * @param {Number} year 4-digit year
  4045. * @param {Number} month 1-based month-of-year
  4046. * @param {Number} day Day of month
  4047. * @param {Number} hour (optional) Hour
  4048. * @param {Number} minute (optional) Minute
  4049. * @param {Number} second (optional) Second
  4050. * @param {Number} millisecond (optional) Millisecond
  4051. * @return {Boolean} true if the passed parameters do not cause a Date "rollover", false otherwise.
  4052. */
  4053. isValid : function(y, m, d, h, i, s, ms) {
  4054. // setup defaults
  4055. h = h || 0;
  4056. i = i || 0;
  4057. s = s || 0;
  4058. ms = ms || 0;
  4059. // Special handling for year < 100
  4060. var dt = utilDate.add(new Date(y < 100 ? 100 : y, m - 1, d, h, i, s, ms), utilDate.YEAR, y < 100 ? y - 100 : 0);
  4061. return y == dt.getFullYear() &&
  4062. m == dt.getMonth() + 1 &&
  4063. d == dt.getDate() &&
  4064. h == dt.getHours() &&
  4065. i == dt.getMinutes() &&
  4066. s == dt.getSeconds() &&
  4067. ms == dt.getMilliseconds();
  4068. },
  4069. /**
  4070. * Parses the passed string using the specified date format.
  4071. * Note that this function expects normal calendar dates, meaning that months are 1-based (i.e. 1 = January).
  4072. * The {@link #defaults} hash will be used for any date value (i.e. year, month, day, hour, minute, second or millisecond)
  4073. * which cannot be found in the passed string. If a corresponding default date value has not been specified in the {@link #defaults} hash,
  4074. * the current date's year, month, day or DST-adjusted zero-hour time value will be used instead.
  4075. * Keep in mind that the input date string must precisely match the specified format string
  4076. * in order for the parse operation to be successful (failed parse operations return a null value).
  4077. * <p>Example:</p><pre><code>
  4078. //dt = Fri May 25 2007 (current date)
  4079. var dt = new Date();
  4080. //dt = Thu May 25 2006 (today&#39;s month/day in 2006)
  4081. dt = Ext.Date.parse("2006", "Y");
  4082. //dt = Sun Jan 15 2006 (all date parts specified)
  4083. dt = Ext.Date.parse("2006-01-15", "Y-m-d");
  4084. //dt = Sun Jan 15 2006 15:20:01
  4085. dt = Ext.Date.parse("2006-01-15 3:20:01 PM", "Y-m-d g:i:s A");
  4086. // attempt to parse Sun Feb 29 2006 03:20:01 in strict mode
  4087. dt = Ext.Date.parse("2006-02-29 03:20:01", "Y-m-d H:i:s", true); // returns null
  4088. </code></pre>
  4089. * @param {String} input The raw date string.
  4090. * @param {String} format The expected date string format.
  4091. * @param {Boolean} strict (optional) True to validate date strings while parsing (i.e. prevents javascript Date "rollover")
  4092. (defaults to false). Invalid date strings will return null when parsed.
  4093. * @return {Date} The parsed Date.
  4094. */
  4095. parse : function(input, format, strict) {
  4096. var p = utilDate.parseFunctions;
  4097. if (p[format] == null) {
  4098. utilDate.createParser(format);
  4099. }
  4100. return p[format](input, Ext.isDefined(strict) ? strict : utilDate.useStrict);
  4101. },
  4102. // Backwards compat
  4103. parseDate: function(input, format, strict){
  4104. return utilDate.parse(input, format, strict);
  4105. },
  4106. // private
  4107. getFormatCode : function(character) {
  4108. var f = utilDate.formatCodes[character];
  4109. if (f) {
  4110. f = typeof f == 'function'? f() : f;
  4111. utilDate.formatCodes[character] = f; // reassign function result to prevent repeated execution
  4112. }
  4113. // note: unknown characters are treated as literals
  4114. return f || ("'" + Ext.String.escape(character) + "'");
  4115. },
  4116. // private
  4117. createFormat : function(format) {
  4118. var code = [],
  4119. special = false,
  4120. ch = '',
  4121. i;
  4122. for (i = 0; i < format.length; ++i) {
  4123. ch = format.charAt(i);
  4124. if (!special && ch == "\\") {
  4125. special = true;
  4126. } else if (special) {
  4127. special = false;
  4128. code.push("'" + Ext.String.escape(ch) + "'");
  4129. } else {
  4130. code.push(utilDate.getFormatCode(ch));
  4131. }
  4132. }
  4133. utilDate.formatFunctions[format] = Ext.functionFactory("return " + code.join('+'));
  4134. },
  4135. // private
  4136. createParser : (function() {
  4137. var code = [
  4138. "var dt, y, m, d, h, i, s, ms, o, z, zz, u, v,",
  4139. "def = Ext.Date.defaults,",
  4140. "results = String(input).match(Ext.Date.parseRegexes[{0}]);", // either null, or an array of matched strings
  4141. "if(results){",
  4142. "{1}",
  4143. "if(u != null){", // i.e. unix time is defined
  4144. "v = new Date(u * 1000);", // give top priority to UNIX time
  4145. "}else{",
  4146. // create Date object representing midnight of the current day;
  4147. // this will provide us with our date defaults
  4148. // (note: clearTime() handles Daylight Saving Time automatically)
  4149. "dt = Ext.Date.clearTime(new Date);",
  4150. // date calculations (note: these calculations create a dependency on Ext.Number.from())
  4151. "y = Ext.Number.from(y, Ext.Number.from(def.y, dt.getFullYear()));",
  4152. "m = Ext.Number.from(m, Ext.Number.from(def.m - 1, dt.getMonth()));",
  4153. "d = Ext.Number.from(d, Ext.Number.from(def.d, dt.getDate()));",
  4154. // time calculations (note: these calculations create a dependency on Ext.Number.from())
  4155. "h = Ext.Number.from(h, Ext.Number.from(def.h, dt.getHours()));",
  4156. "i = Ext.Number.from(i, Ext.Number.from(def.i, dt.getMinutes()));",
  4157. "s = Ext.Number.from(s, Ext.Number.from(def.s, dt.getSeconds()));",
  4158. "ms = Ext.Number.from(ms, Ext.Number.from(def.ms, dt.getMilliseconds()));",
  4159. "if(z >= 0 && y >= 0){",
  4160. // both the year and zero-based day of year are defined and >= 0.
  4161. // these 2 values alone provide sufficient info to create a full date object
  4162. // create Date object representing January 1st for the given year
  4163. // handle years < 100 appropriately
  4164. "v = Ext.Date.add(new Date(y < 100 ? 100 : y, 0, 1, h, i, s, ms), Ext.Date.YEAR, y < 100 ? y - 100 : 0);",
  4165. // then add day of year, checking for Date "rollover" if necessary
  4166. "v = !strict? v : (strict === true && (z <= 364 || (Ext.Date.isLeapYear(v) && z <= 365))? Ext.Date.add(v, Ext.Date.DAY, z) : null);",
  4167. "}else if(strict === true && !Ext.Date.isValid(y, m + 1, d, h, i, s, ms)){", // check for Date "rollover"
  4168. "v = null;", // invalid date, so return null
  4169. "}else{",
  4170. // plain old Date object
  4171. // handle years < 100 properly
  4172. "v = Ext.Date.add(new Date(y < 100 ? 100 : y, m, d, h, i, s, ms), Ext.Date.YEAR, y < 100 ? y - 100 : 0);",
  4173. "}",
  4174. "}",
  4175. "}",
  4176. "if(v){",
  4177. // favour UTC offset over GMT offset
  4178. "if(zz != null){",
  4179. // reset to UTC, then add offset
  4180. "v = Ext.Date.add(v, Ext.Date.SECOND, -v.getTimezoneOffset() * 60 - zz);",
  4181. "}else if(o){",
  4182. // reset to GMT, then add offset
  4183. "v = Ext.Date.add(v, Ext.Date.MINUTE, -v.getTimezoneOffset() + (sn == '+'? -1 : 1) * (hr * 60 + mn));",
  4184. "}",
  4185. "}",
  4186. "return v;"
  4187. ].join('\n');
  4188. return function(format) {
  4189. var regexNum = utilDate.parseRegexes.length,
  4190. currentGroup = 1,
  4191. calc = [],
  4192. regex = [],
  4193. special = false,
  4194. ch = "",
  4195. i = 0,
  4196. len = format.length,
  4197. atEnd = [],
  4198. obj;
  4199. for (; i < len; ++i) {
  4200. ch = format.charAt(i);
  4201. if (!special && ch == "\\") {
  4202. special = true;
  4203. } else if (special) {
  4204. special = false;
  4205. regex.push(Ext.String.escape(ch));
  4206. } else {
  4207. obj = utilDate.formatCodeToRegex(ch, currentGroup);
  4208. currentGroup += obj.g;
  4209. regex.push(obj.s);
  4210. if (obj.g && obj.c) {
  4211. if (obj.calcAtEnd) {
  4212. atEnd.push(obj.c);
  4213. } else {
  4214. calc.push(obj.c);
  4215. }
  4216. }
  4217. }
  4218. }
  4219. calc = calc.concat(atEnd);
  4220. utilDate.parseRegexes[regexNum] = new RegExp("^" + regex.join('') + "$", 'i');
  4221. utilDate.parseFunctions[format] = Ext.functionFactory("input", "strict", xf(code, regexNum, calc.join('')));
  4222. };
  4223. }()),
  4224. // private
  4225. parseCodes : {
  4226. /*
  4227. * Notes:
  4228. * g = {Number} calculation group (0 or 1. only group 1 contributes to date calculations.)
  4229. * c = {String} calculation method (required for group 1. null for group 0. {0} = currentGroup - position in regex result array)
  4230. * s = {String} regex pattern. all matches are stored in results[], and are accessible by the calculation mapped to 'c'
  4231. */
  4232. d: {
  4233. g:1,
  4234. c:"d = parseInt(results[{0}], 10);\n",
  4235. s:"(3[0-1]|[1-2][0-9]|0[1-9])" // day of month with leading zeroes (01 - 31)
  4236. },
  4237. j: {
  4238. g:1,
  4239. c:"d = parseInt(results[{0}], 10);\n",
  4240. s:"(3[0-1]|[1-2][0-9]|[1-9])" // day of month without leading zeroes (1 - 31)
  4241. },
  4242. D: function() {
  4243. for (var a = [], i = 0; i < 7; a.push(utilDate.getShortDayName(i)), ++i); // get localised short day names
  4244. return {
  4245. g:0,
  4246. c:null,
  4247. s:"(?:" + a.join("|") +")"
  4248. };
  4249. },
  4250. l: function() {
  4251. return {
  4252. g:0,
  4253. c:null,
  4254. s:"(?:" + utilDate.dayNames.join("|") + ")"
  4255. };
  4256. },
  4257. N: {
  4258. g:0,
  4259. c:null,
  4260. s:"[1-7]" // ISO-8601 day number (1 (monday) - 7 (sunday))
  4261. },
  4262. //<locale type="object" property="parseCodes">
  4263. S: {
  4264. g:0,
  4265. c:null,
  4266. s:"(?:st|nd|rd|th)"
  4267. },
  4268. //</locale>
  4269. w: {
  4270. g:0,
  4271. c:null,
  4272. s:"[0-6]" // javascript day number (0 (sunday) - 6 (saturday))
  4273. },
  4274. z: {
  4275. g:1,
  4276. c:"z = parseInt(results[{0}], 10);\n",
  4277. s:"(\\d{1,3})" // day of the year (0 - 364 (365 in leap years))
  4278. },
  4279. W: {
  4280. g:0,
  4281. c:null,
  4282. s:"(?:\\d{2})" // ISO-8601 week number (with leading zero)
  4283. },
  4284. F: function() {
  4285. return {
  4286. g:1,
  4287. c:"m = parseInt(Ext.Date.getMonthNumber(results[{0}]), 10);\n", // get localised month number
  4288. s:"(" + utilDate.monthNames.join("|") + ")"
  4289. };
  4290. },
  4291. M: function() {
  4292. for (var a = [], i = 0; i < 12; a.push(utilDate.getShortMonthName(i)), ++i); // get localised short month names
  4293. return Ext.applyIf({
  4294. s:"(" + a.join("|") + ")"
  4295. }, utilDate.formatCodeToRegex("F"));
  4296. },
  4297. m: {
  4298. g:1,
  4299. c:"m = parseInt(results[{0}], 10) - 1;\n",
  4300. s:"(1[0-2]|0[1-9])" // month number with leading zeros (01 - 12)
  4301. },
  4302. n: {
  4303. g:1,
  4304. c:"m = parseInt(results[{0}], 10) - 1;\n",
  4305. s:"(1[0-2]|[1-9])" // month number without leading zeros (1 - 12)
  4306. },
  4307. t: {
  4308. g:0,
  4309. c:null,
  4310. s:"(?:\\d{2})" // no. of days in the month (28 - 31)
  4311. },
  4312. L: {
  4313. g:0,
  4314. c:null,
  4315. s:"(?:1|0)"
  4316. },
  4317. o: function() {
  4318. return utilDate.formatCodeToRegex("Y");
  4319. },
  4320. Y: {
  4321. g:1,
  4322. c:"y = parseInt(results[{0}], 10);\n",
  4323. s:"(\\d{4})" // 4-digit year
  4324. },
  4325. y: {
  4326. g:1,
  4327. c:"var ty = parseInt(results[{0}], 10);\n"
  4328. + "y = ty > Ext.Date.y2kYear ? 1900 + ty : 2000 + ty;\n", // 2-digit year
  4329. s:"(\\d{1,2})"
  4330. },
  4331. /*
  4332. * In the am/pm parsing routines, we allow both upper and lower case
  4333. * even though it doesn't exactly match the spec. It gives much more flexibility
  4334. * in being able to specify case insensitive regexes.
  4335. */
  4336. //<locale type="object" property="parseCodes">
  4337. a: {
  4338. g:1,
  4339. c:"if (/(am)/i.test(results[{0}])) {\n"
  4340. + "if (!h || h == 12) { h = 0; }\n"
  4341. + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
  4342. s:"(am|pm|AM|PM)",
  4343. calcAtEnd: true
  4344. },
  4345. //</locale>
  4346. //<locale type="object" property="parseCodes">
  4347. A: {
  4348. g:1,
  4349. c:"if (/(am)/i.test(results[{0}])) {\n"
  4350. + "if (!h || h == 12) { h = 0; }\n"
  4351. + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
  4352. s:"(AM|PM|am|pm)",
  4353. calcAtEnd: true
  4354. },
  4355. //</locale>
  4356. g: {
  4357. g:1,
  4358. c:"h = parseInt(results[{0}], 10);\n",
  4359. s:"(1[0-2]|[0-9])" // 12-hr format of an hour without leading zeroes (1 - 12)
  4360. },
  4361. G: {
  4362. g:1,
  4363. c:"h = parseInt(results[{0}], 10);\n",
  4364. s:"(2[0-3]|1[0-9]|[0-9])" // 24-hr format of an hour without leading zeroes (0 - 23)
  4365. },
  4366. h: {
  4367. g:1,
  4368. c:"h = parseInt(results[{0}], 10);\n",
  4369. s:"(1[0-2]|0[1-9])" // 12-hr format of an hour with leading zeroes (01 - 12)
  4370. },
  4371. H: {
  4372. g:1,
  4373. c:"h = parseInt(results[{0}], 10);\n",
  4374. s:"(2[0-3]|[0-1][0-9])" // 24-hr format of an hour with leading zeroes (00 - 23)
  4375. },
  4376. i: {
  4377. g:1,
  4378. c:"i = parseInt(results[{0}], 10);\n",
  4379. s:"([0-5][0-9])" // minutes with leading zeros (00 - 59)
  4380. },
  4381. s: {
  4382. g:1,
  4383. c:"s = parseInt(results[{0}], 10);\n",
  4384. s:"([0-5][0-9])" // seconds with leading zeros (00 - 59)
  4385. },
  4386. u: {
  4387. g:1,
  4388. c:"ms = results[{0}]; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n",
  4389. s:"(\\d+)" // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
  4390. },
  4391. O: {
  4392. g:1,
  4393. c:[
  4394. "o = results[{0}];",
  4395. "var sn = o.substring(0,1),", // get + / - sign
  4396. "hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
  4397. "mn = o.substring(3,5) % 60;", // get minutes
  4398. "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
  4399. ].join("\n"),
  4400. s: "([+-]\\d{4})" // GMT offset in hrs and mins
  4401. },
  4402. P: {
  4403. g:1,
  4404. c:[
  4405. "o = results[{0}];",
  4406. "var sn = o.substring(0,1),", // get + / - sign
  4407. "hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
  4408. "mn = o.substring(4,6) % 60;", // get minutes
  4409. "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
  4410. ].join("\n"),
  4411. s: "([+-]\\d{2}:\\d{2})" // GMT offset in hrs and mins (with colon separator)
  4412. },
  4413. T: {
  4414. g:0,
  4415. c:null,
  4416. s:"[A-Z]{1,4}" // timezone abbrev. may be between 1 - 4 chars
  4417. },
  4418. Z: {
  4419. g:1,
  4420. c:"zz = results[{0}] * 1;\n" // -43200 <= UTC offset <= 50400
  4421. + "zz = (-43200 <= zz && zz <= 50400)? zz : null;\n",
  4422. s:"([+-]?\\d{1,5})" // leading '+' sign is optional for UTC offset
  4423. },
  4424. c: function() {
  4425. var calc = [],
  4426. arr = [
  4427. utilDate.formatCodeToRegex("Y", 1), // year
  4428. utilDate.formatCodeToRegex("m", 2), // month
  4429. utilDate.formatCodeToRegex("d", 3), // day
  4430. utilDate.formatCodeToRegex("H", 4), // hour
  4431. utilDate.formatCodeToRegex("i", 5), // minute
  4432. utilDate.formatCodeToRegex("s", 6), // second
  4433. {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)
  4434. {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
  4435. "if(results[8]) {", // timezone specified
  4436. "if(results[8] == 'Z'){",
  4437. "zz = 0;", // UTC
  4438. "}else if (results[8].indexOf(':') > -1){",
  4439. utilDate.formatCodeToRegex("P", 8).c, // timezone offset with colon separator
  4440. "}else{",
  4441. utilDate.formatCodeToRegex("O", 8).c, // timezone offset without colon separator
  4442. "}",
  4443. "}"
  4444. ].join('\n')}
  4445. ],
  4446. i,
  4447. l;
  4448. for (i = 0, l = arr.length; i < l; ++i) {
  4449. calc.push(arr[i].c);
  4450. }
  4451. return {
  4452. g:1,
  4453. c:calc.join(""),
  4454. s:[
  4455. arr[0].s, // year (required)
  4456. "(?:", "-", arr[1].s, // month (optional)
  4457. "(?:", "-", arr[2].s, // day (optional)
  4458. "(?:",
  4459. "(?:T| )?", // time delimiter -- either a "T" or a single blank space
  4460. 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
  4461. "(?::", arr[5].s, ")?", // seconds (optional)
  4462. "(?:(?:\\.|,)(\\d+))?", // decimal fraction of a second (e.g. ",12345" or ".98765") (optional)
  4463. "(Z|(?:[-+]\\d{2}(?::)?\\d{2}))?", // "Z" (UTC) or "-0530" (UTC offset without colon delimiter) or "+08:00" (UTC offset with colon delimiter) (optional)
  4464. ")?",
  4465. ")?",
  4466. ")?"
  4467. ].join("")
  4468. };
  4469. },
  4470. U: {
  4471. g:1,
  4472. c:"u = parseInt(results[{0}], 10);\n",
  4473. s:"(-?\\d+)" // leading minus sign indicates seconds before UNIX epoch
  4474. }
  4475. },
  4476. //Old Ext.Date prototype methods.
  4477. // private
  4478. dateFormat: function(date, format) {
  4479. return utilDate.format(date, format);
  4480. },
  4481. /**
  4482. * Compares if two dates are equal by comparing their values.
  4483. * @param {Date} date1
  4484. * @param {Date} date2
  4485. * @return {Boolean} True if the date values are equal
  4486. */
  4487. isEqual: function(date1, date2) {
  4488. // check we have 2 date objects
  4489. if (date1 && date2) {
  4490. return (date1.getTime() === date2.getTime());
  4491. }
  4492. // one or both isn't a date, only equal if both are falsey
  4493. return !(date1 || date2);
  4494. },
  4495. /**
  4496. * Formats a date given the supplied format string.
  4497. * @param {Date} date The date to format
  4498. * @param {String} format The format string
  4499. * @return {String} The formatted date or an empty string if date parameter is not a JavaScript Date object
  4500. */
  4501. format: function(date, format) {
  4502. var formatFunctions = utilDate.formatFunctions;
  4503. if (!Ext.isDate(date)) {
  4504. return '';
  4505. }
  4506. if (formatFunctions[format] == null) {
  4507. utilDate.createFormat(format);
  4508. }
  4509. return formatFunctions[format].call(date) + '';
  4510. },
  4511. /**
  4512. * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
  4513. *
  4514. * Note: The date string returned by the javascript Date object's toString() method varies
  4515. * between browsers (e.g. FF vs IE) and system region settings (e.g. IE in Asia vs IE in America).
  4516. * For a given date string e.g. "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)",
  4517. * getTimezone() first tries to get the timezone abbreviation from between a pair of parentheses
  4518. * (which may or may not be present), failing which it proceeds to get the timezone abbreviation
  4519. * from the GMT offset portion of the date string.
  4520. * @param {Date} date The date
  4521. * @return {String} The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).
  4522. */
  4523. getTimezone : function(date) {
  4524. // the following list shows the differences between date strings from different browsers on a WinXP SP2 machine from an Asian locale:
  4525. //
  4526. // Opera : "Thu, 25 Oct 2007 22:53:45 GMT+0800" -- shortest (weirdest) date string of the lot
  4527. // 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)
  4528. // FF : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone
  4529. // IE : "Thu Oct 25 22:54:35 UTC+0800 2007" -- (Asian system setting) look for 3-4 letter timezone abbrev
  4530. // IE : "Thu Oct 25 17:06:37 PDT 2007" -- (American system setting) look for 3-4 letter timezone abbrev
  4531. //
  4532. // this crazy regex attempts to guess the correct timezone abbreviation despite these differences.
  4533. // step 1: (?:\((.*)\) -- find timezone in parentheses
  4534. // 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
  4535. // step 3: remove all non uppercase characters found in step 1 and 2
  4536. return date.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, "$1$2").replace(/[^A-Z]/g, "");
  4537. },
  4538. /**
  4539. * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
  4540. * @param {Date} date The date
  4541. * @param {Boolean} colon (optional) true to separate the hours and minutes with a colon (defaults to false).
  4542. * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600').
  4543. */
  4544. getGMTOffset : function(date, colon) {
  4545. var offset = date.getTimezoneOffset();
  4546. return (offset > 0 ? "-" : "+")
  4547. + Ext.String.leftPad(Math.floor(Math.abs(offset) / 60), 2, "0")
  4548. + (colon ? ":" : "")
  4549. + Ext.String.leftPad(Math.abs(offset % 60), 2, "0");
  4550. },
  4551. /**
  4552. * Get the numeric day number of the year, adjusted for leap year.
  4553. * @param {Date} date The date
  4554. * @return {Number} 0 to 364 (365 in leap years).
  4555. */
  4556. getDayOfYear: function(date) {
  4557. var num = 0,
  4558. d = Ext.Date.clone(date),
  4559. m = date.getMonth(),
  4560. i;
  4561. for (i = 0, d.setDate(1), d.setMonth(0); i < m; d.setMonth(++i)) {
  4562. num += utilDate.getDaysInMonth(d);
  4563. }
  4564. return num + date.getDate() - 1;
  4565. },
  4566. /**
  4567. * Get the numeric ISO-8601 week number of the year.
  4568. * (equivalent to the format specifier 'W', but without a leading zero).
  4569. * @param {Date} date The date
  4570. * @return {Number} 1 to 53
  4571. * @method
  4572. */
  4573. getWeekOfYear : (function() {
  4574. // adapted from http://www.merlyn.demon.co.uk/weekcalc.htm
  4575. var ms1d = 864e5, // milliseconds in a day
  4576. ms7d = 7 * ms1d; // milliseconds in a week
  4577. return function(date) { // return a closure so constants get calculated only once
  4578. var DC3 = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate() + 3) / ms1d, // an Absolute Day Number
  4579. AWN = Math.floor(DC3 / 7), // an Absolute Week Number
  4580. Wyr = new Date(AWN * ms7d).getUTCFullYear();
  4581. return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1;
  4582. };
  4583. }()),
  4584. /**
  4585. * Checks if the current date falls within a leap year.
  4586. * @param {Date} date The date
  4587. * @return {Boolean} True if the current date falls within a leap year, false otherwise.
  4588. */
  4589. isLeapYear : function(date) {
  4590. var year = date.getFullYear();
  4591. return !!((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
  4592. },
  4593. /**
  4594. * Get the first day of the current month, adjusted for leap year. The returned value
  4595. * is the numeric day index within the week (0-6) which can be used in conjunction with
  4596. * the {@link #monthNames} array to retrieve the textual day name.
  4597. * Example:
  4598. * <pre><code>
  4599. var dt = new Date('1/10/2007'),
  4600. firstDay = Ext.Date.getFirstDayOfMonth(dt);
  4601. console.log(Ext.Date.dayNames[firstDay]); //output: 'Monday'
  4602. * </code></pre>
  4603. * @param {Date} date The date
  4604. * @return {Number} The day number (0-6).
  4605. */
  4606. getFirstDayOfMonth : function(date) {
  4607. var day = (date.getDay() - (date.getDate() - 1)) % 7;
  4608. return (day < 0) ? (day + 7) : day;
  4609. },
  4610. /**
  4611. * Get the last day of the current month, adjusted for leap year. The returned value
  4612. * is the numeric day index within the week (0-6) which can be used in conjunction with
  4613. * the {@link #monthNames} array to retrieve the textual day name.
  4614. * Example:
  4615. * <pre><code>
  4616. var dt = new Date('1/10/2007'),
  4617. lastDay = Ext.Date.getLastDayOfMonth(dt);
  4618. console.log(Ext.Date.dayNames[lastDay]); //output: 'Wednesday'
  4619. * </code></pre>
  4620. * @param {Date} date The date
  4621. * @return {Number} The day number (0-6).
  4622. */
  4623. getLastDayOfMonth : function(date) {
  4624. return utilDate.getLastDateOfMonth(date).getDay();
  4625. },
  4626. /**
  4627. * Get the date of the first day of the month in which this date resides.
  4628. * @param {Date} date The date
  4629. * @return {Date}
  4630. */
  4631. getFirstDateOfMonth : function(date) {
  4632. return new Date(date.getFullYear(), date.getMonth(), 1);
  4633. },
  4634. /**
  4635. * Get the date of the last day of the month in which this date resides.
  4636. * @param {Date} date The date
  4637. * @return {Date}
  4638. */
  4639. getLastDateOfMonth : function(date) {
  4640. return new Date(date.getFullYear(), date.getMonth(), utilDate.getDaysInMonth(date));
  4641. },
  4642. /**
  4643. * Get the number of days in the current month, adjusted for leap year.
  4644. * @param {Date} date The date
  4645. * @return {Number} The number of days in the month.
  4646. * @method
  4647. */
  4648. getDaysInMonth: (function() {
  4649. var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  4650. return function(date) { // return a closure for efficiency
  4651. var m = date.getMonth();
  4652. return m == 1 && utilDate.isLeapYear(date) ? 29 : daysInMonth[m];
  4653. };
  4654. }()),
  4655. //<locale type="function">
  4656. /**
  4657. * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
  4658. * @param {Date} date The date
  4659. * @return {String} 'st, 'nd', 'rd' or 'th'.
  4660. */
  4661. getSuffix : function(date) {
  4662. switch (date.getDate()) {
  4663. case 1:
  4664. case 21:
  4665. case 31:
  4666. return "st";
  4667. case 2:
  4668. case 22:
  4669. return "nd";
  4670. case 3:
  4671. case 23:
  4672. return "rd";
  4673. default:
  4674. return "th";
  4675. }
  4676. },
  4677. //</locale>
  4678. /**
  4679. * Creates and returns a new Date instance with the exact same date value as the called instance.
  4680. * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
  4681. * variable will also be changed. When the intention is to create a new variable that will not
  4682. * modify the original instance, you should create a clone.
  4683. *
  4684. * Example of correctly cloning a date:
  4685. * <pre><code>
  4686. //wrong way:
  4687. var orig = new Date('10/1/2006');
  4688. var copy = orig;
  4689. copy.setDate(5);
  4690. console.log(orig); //returns 'Thu Oct 05 2006'!
  4691. //correct way:
  4692. var orig = new Date('10/1/2006'),
  4693. copy = Ext.Date.clone(orig);
  4694. copy.setDate(5);
  4695. console.log(orig); //returns 'Thu Oct 01 2006'
  4696. * </code></pre>
  4697. * @param {Date} date The date
  4698. * @return {Date} The new Date instance.
  4699. */
  4700. clone : function(date) {
  4701. return new Date(date.getTime());
  4702. },
  4703. /**
  4704. * Checks if the current date is affected by Daylight Saving Time (DST).
  4705. * @param {Date} date The date
  4706. * @return {Boolean} True if the current date is affected by DST.
  4707. */
  4708. isDST : function(date) {
  4709. // adapted from http://sencha.com/forum/showthread.php?p=247172#post247172
  4710. // courtesy of @geoffrey.mcgill
  4711. return new Date(date.getFullYear(), 0, 1).getTimezoneOffset() != date.getTimezoneOffset();
  4712. },
  4713. /**
  4714. * Attempts to clear all time information from this Date by setting the time to midnight of the same day,
  4715. * automatically adjusting for Daylight Saving Time (DST) where applicable.
  4716. * (note: DST timezone information for the browser's host operating system is assumed to be up-to-date)
  4717. * @param {Date} date The date
  4718. * @param {Boolean} clone true to create a clone of this date, clear the time and return it (defaults to false).
  4719. * @return {Date} this or the clone.
  4720. */
  4721. clearTime : function(date, clone) {
  4722. if (clone) {
  4723. return Ext.Date.clearTime(Ext.Date.clone(date));
  4724. }
  4725. // get current date before clearing time
  4726. var d = date.getDate(),
  4727. hr,
  4728. c;
  4729. // clear time
  4730. date.setHours(0);
  4731. date.setMinutes(0);
  4732. date.setSeconds(0);
  4733. date.setMilliseconds(0);
  4734. if (date.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
  4735. // note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the case)
  4736. // refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule
  4737. // increment hour until cloned date == current date
  4738. for (hr = 1, c = utilDate.add(date, Ext.Date.HOUR, hr); c.getDate() != d; hr++, c = utilDate.add(date, Ext.Date.HOUR, hr));
  4739. date.setDate(d);
  4740. date.setHours(c.getHours());
  4741. }
  4742. return date;
  4743. },
  4744. /**
  4745. * Provides a convenient method for performing basic date arithmetic. This method
  4746. * does not modify the Date instance being called - it creates and returns
  4747. * a new Date instance containing the resulting date value.
  4748. *
  4749. * Examples:
  4750. * <pre><code>
  4751. // Basic usage:
  4752. var dt = Ext.Date.add(new Date('10/29/2006'), Ext.Date.DAY, 5);
  4753. console.log(dt); //returns 'Fri Nov 03 2006 00:00:00'
  4754. // Negative values will be subtracted:
  4755. var dt2 = Ext.Date.add(new Date('10/1/2006'), Ext.Date.DAY, -5);
  4756. console.log(dt2); //returns 'Tue Sep 26 2006 00:00:00'
  4757. * </code></pre>
  4758. *
  4759. * @param {Date} date The date to modify
  4760. * @param {String} interval A valid date interval enum value.
  4761. * @param {Number} value The amount to add to the current date.
  4762. * @return {Date} The new Date instance.
  4763. */
  4764. add : function(date, interval, value) {
  4765. var d = Ext.Date.clone(date),
  4766. Date = Ext.Date,
  4767. day;
  4768. if (!interval || value === 0) {
  4769. return d;
  4770. }
  4771. switch(interval.toLowerCase()) {
  4772. case Ext.Date.MILLI:
  4773. d.setMilliseconds(d.getMilliseconds() + value);
  4774. break;
  4775. case Ext.Date.SECOND:
  4776. d.setSeconds(d.getSeconds() + value);
  4777. break;
  4778. case Ext.Date.MINUTE:
  4779. d.setMinutes(d.getMinutes() + value);
  4780. break;
  4781. case Ext.Date.HOUR:
  4782. d.setHours(d.getHours() + value);
  4783. break;
  4784. case Ext.Date.DAY:
  4785. d.setDate(d.getDate() + value);
  4786. break;
  4787. case Ext.Date.MONTH:
  4788. day = date.getDate();
  4789. if (day > 28) {
  4790. day = Math.min(day, Ext.Date.getLastDateOfMonth(Ext.Date.add(Ext.Date.getFirstDateOfMonth(date), Ext.Date.MONTH, value)).getDate());
  4791. }
  4792. d.setDate(day);
  4793. d.setMonth(date.getMonth() + value);
  4794. break;
  4795. case Ext.Date.YEAR:
  4796. day = date.getDate();
  4797. if (day > 28) {
  4798. day = Math.min(day, Ext.Date.getLastDateOfMonth(Ext.Date.add(Ext.Date.getFirstDateOfMonth(date), Ext.Date.YEAR, value)).getDate());
  4799. }
  4800. d.setDate(day);
  4801. d.setFullYear(date.getFullYear() + value);
  4802. break;
  4803. }
  4804. return d;
  4805. },
  4806. /**
  4807. * Checks if a date falls on or between the given start and end dates.
  4808. * @param {Date} date The date to check
  4809. * @param {Date} start Start date
  4810. * @param {Date} end End date
  4811. * @return {Boolean} true if this date falls on or between the given start and end dates.
  4812. */
  4813. between : function(date, start, end) {
  4814. var t = date.getTime();
  4815. return start.getTime() <= t && t <= end.getTime();
  4816. },
  4817. //Maintains compatibility with old static and prototype window.Date methods.
  4818. compat: function() {
  4819. var nativeDate = window.Date,
  4820. p, u,
  4821. 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'],
  4822. proto = ['dateFormat', 'format', 'getTimezone', 'getGMTOffset', 'getDayOfYear', 'getWeekOfYear', 'isLeapYear', 'getFirstDayOfMonth', 'getLastDayOfMonth', 'getDaysInMonth', 'getSuffix', 'clone', 'isDST', 'clearTime', 'add', 'between'],
  4823. sLen = statics.length,
  4824. pLen = proto.length,
  4825. stat, prot, s;
  4826. //Append statics
  4827. for (s = 0; s < sLen; s++) {
  4828. stat = statics[s];
  4829. nativeDate[stat] = utilDate[stat];
  4830. }
  4831. //Append to prototype
  4832. for (p = 0; p < pLen; p++) {
  4833. prot = proto[p];
  4834. nativeDate.prototype[prot] = function() {
  4835. var args = Array.prototype.slice.call(arguments);
  4836. args.unshift(this);
  4837. return utilDate[prot].apply(utilDate, args);
  4838. };
  4839. }
  4840. }
  4841. };
  4842. var utilDate = Ext.Date;
  4843. }());
  4844. /**
  4845. * @author Jacky Nguyen <jacky@sencha.com>
  4846. * @docauthor Jacky Nguyen <jacky@sencha.com>
  4847. * @class Ext.Base
  4848. *
  4849. * The root of all classes created with {@link Ext#define}.
  4850. *
  4851. * Ext.Base is the building block of all Ext classes. All classes in Ext inherit from Ext.Base.
  4852. * All prototype and static members of this class are inherited by all other classes.
  4853. */
  4854. (function(flexSetter) {
  4855. var noArgs = [],
  4856. Base = function(){};
  4857. // These static properties will be copied to every newly created class with {@link Ext#define}
  4858. Ext.apply(Base, {
  4859. $className: 'Ext.Base',
  4860. $isClass: true,
  4861. /**
  4862. * Create a new instance of this Class.
  4863. *
  4864. * Ext.define('My.cool.Class', {
  4865. * ...
  4866. * });
  4867. *
  4868. * My.cool.Class.create({
  4869. * someConfig: true
  4870. * });
  4871. *
  4872. * All parameters are passed to the constructor of the class.
  4873. *
  4874. * @return {Object} the created instance.
  4875. * @static
  4876. * @inheritable
  4877. */
  4878. create: function() {
  4879. return Ext.create.apply(Ext, [this].concat(Array.prototype.slice.call(arguments, 0)));
  4880. },
  4881. /**
  4882. * @private
  4883. * @static
  4884. * @inheritable
  4885. * @param config
  4886. */
  4887. extend: function(parent) {
  4888. var parentPrototype = parent.prototype,
  4889. basePrototype, prototype, i, ln, name, statics;
  4890. prototype = this.prototype = Ext.Object.chain(parentPrototype);
  4891. prototype.self = this;
  4892. this.superclass = prototype.superclass = parentPrototype;
  4893. if (!parent.$isClass) {
  4894. basePrototype = Ext.Base.prototype;
  4895. for (i in basePrototype) {
  4896. if (i in prototype) {
  4897. prototype[i] = basePrototype[i];
  4898. }
  4899. }
  4900. }
  4901. //<feature classSystem.inheritableStatics>
  4902. // Statics inheritance
  4903. statics = parentPrototype.$inheritableStatics;
  4904. if (statics) {
  4905. for (i = 0,ln = statics.length; i < ln; i++) {
  4906. name = statics[i];
  4907. if (!this.hasOwnProperty(name)) {
  4908. this[name] = parent[name];
  4909. }
  4910. }
  4911. }
  4912. //</feature>
  4913. if (parent.$onExtended) {
  4914. this.$onExtended = parent.$onExtended.slice();
  4915. }
  4916. //<feature classSystem.config>
  4917. prototype.config = new prototype.configClass();
  4918. prototype.initConfigList = prototype.initConfigList.slice();
  4919. prototype.initConfigMap = Ext.clone(prototype.initConfigMap);
  4920. prototype.configMap = Ext.Object.chain(prototype.configMap);
  4921. //</feature>
  4922. },
  4923. /**
  4924. * @private
  4925. * @static
  4926. * @inheritable
  4927. */
  4928. $onExtended: [],
  4929. /**
  4930. * @private
  4931. * @static
  4932. * @inheritable
  4933. */
  4934. triggerExtended: function() {
  4935. var callbacks = this.$onExtended,
  4936. ln = callbacks.length,
  4937. i, callback;
  4938. if (ln > 0) {
  4939. for (i = 0; i < ln; i++) {
  4940. callback = callbacks[i];
  4941. callback.fn.apply(callback.scope || this, arguments);
  4942. }
  4943. }
  4944. },
  4945. /**
  4946. * @private
  4947. * @static
  4948. * @inheritable
  4949. */
  4950. onExtended: function(fn, scope) {
  4951. this.$onExtended.push({
  4952. fn: fn,
  4953. scope: scope
  4954. });
  4955. return this;
  4956. },
  4957. /**
  4958. * @private
  4959. * @static
  4960. * @inheritable
  4961. * @param config
  4962. */
  4963. addConfig: function(config, fullMerge) {
  4964. var prototype = this.prototype,
  4965. configNameCache = Ext.Class.configNameCache,
  4966. hasConfig = prototype.configMap,
  4967. initConfigList = prototype.initConfigList,
  4968. initConfigMap = prototype.initConfigMap,
  4969. defaultConfig = prototype.config,
  4970. initializedName, name, value;
  4971. for (name in config) {
  4972. if (config.hasOwnProperty(name)) {
  4973. if (!hasConfig[name]) {
  4974. hasConfig[name] = true;
  4975. }
  4976. value = config[name];
  4977. initializedName = configNameCache[name].initialized;
  4978. if (!initConfigMap[name] && value !== null && !prototype[initializedName]) {
  4979. initConfigMap[name] = true;
  4980. initConfigList.push(name);
  4981. }
  4982. }
  4983. }
  4984. if (fullMerge) {
  4985. Ext.merge(defaultConfig, config);
  4986. }
  4987. else {
  4988. Ext.mergeIf(defaultConfig, config);
  4989. }
  4990. prototype.configClass = Ext.Object.classify(defaultConfig);
  4991. },
  4992. /**
  4993. * Add / override static properties of this class.
  4994. *
  4995. * Ext.define('My.cool.Class', {
  4996. * ...
  4997. * });
  4998. *
  4999. * My.cool.Class.addStatics({
  5000. * someProperty: 'someValue', // My.cool.Class.someProperty = 'someValue'
  5001. * method1: function() { ... }, // My.cool.Class.method1 = function() { ... };
  5002. * method2: function() { ... } // My.cool.Class.method2 = function() { ... };
  5003. * });
  5004. *
  5005. * @param {Object} members
  5006. * @return {Ext.Base} this
  5007. * @static
  5008. * @inheritable
  5009. */
  5010. addStatics: function(members) {
  5011. var member, name;
  5012. for (name in members) {
  5013. if (members.hasOwnProperty(name)) {
  5014. member = members[name];
  5015. //<debug>
  5016. if (typeof member == 'function') {
  5017. member.displayName = Ext.getClassName(this) + '.' + name;
  5018. }
  5019. //</debug>
  5020. this[name] = member;
  5021. }
  5022. }
  5023. return this;
  5024. },
  5025. /**
  5026. * @private
  5027. * @static
  5028. * @inheritable
  5029. * @param {Object} members
  5030. */
  5031. addInheritableStatics: function(members) {
  5032. var inheritableStatics,
  5033. hasInheritableStatics,
  5034. prototype = this.prototype,
  5035. name, member;
  5036. inheritableStatics = prototype.$inheritableStatics;
  5037. hasInheritableStatics = prototype.$hasInheritableStatics;
  5038. if (!inheritableStatics) {
  5039. inheritableStatics = prototype.$inheritableStatics = [];
  5040. hasInheritableStatics = prototype.$hasInheritableStatics = {};
  5041. }
  5042. for (name in members) {
  5043. if (members.hasOwnProperty(name)) {
  5044. member = members[name];
  5045. //<debug>
  5046. if (typeof member == 'function') {
  5047. member.displayName = Ext.getClassName(this) + '.' + name;
  5048. }
  5049. //</debug>
  5050. this[name] = member;
  5051. if (!hasInheritableStatics[name]) {
  5052. hasInheritableStatics[name] = true;
  5053. inheritableStatics.push(name);
  5054. }
  5055. }
  5056. }
  5057. return this;
  5058. },
  5059. /**
  5060. * Add methods / properties to the prototype of this class.
  5061. *
  5062. * Ext.define('My.awesome.Cat', {
  5063. * constructor: function() {
  5064. * ...
  5065. * }
  5066. * });
  5067. *
  5068. * My.awesome.Cat.addMembers({
  5069. * meow: function() {
  5070. * alert('Meowww...');
  5071. * }
  5072. * });
  5073. *
  5074. * var kitty = new My.awesome.Cat;
  5075. * kitty.meow();
  5076. *
  5077. * @param {Object} members
  5078. * @static
  5079. * @inheritable
  5080. */
  5081. addMembers: function(members) {
  5082. var prototype = this.prototype,
  5083. enumerables = Ext.enumerables,
  5084. names = [],
  5085. i, ln, name, member;
  5086. for (name in members) {
  5087. names.push(name);
  5088. }
  5089. if (enumerables) {
  5090. names.push.apply(names, enumerables);
  5091. }
  5092. for (i = 0,ln = names.length; i < ln; i++) {
  5093. name = names[i];
  5094. if (members.hasOwnProperty(name)) {
  5095. member = members[name];
  5096. if (typeof member == 'function' && !member.$isClass && member !== Ext.emptyFn) {
  5097. member.$owner = this;
  5098. member.$name = name;
  5099. //<debug>
  5100. member.displayName = (this.$className || '') + '#' + name;
  5101. //</debug>
  5102. }
  5103. prototype[name] = member;
  5104. }
  5105. }
  5106. return this;
  5107. },
  5108. /**
  5109. * @private
  5110. * @static
  5111. * @inheritable
  5112. * @param name
  5113. * @param member
  5114. */
  5115. addMember: function(name, member) {
  5116. if (typeof member == 'function' && !member.$isClass && member !== Ext.emptyFn) {
  5117. member.$owner = this;
  5118. member.$name = name;
  5119. //<debug>
  5120. member.displayName = (this.$className || '') + '#' + name;
  5121. //</debug>
  5122. }
  5123. this.prototype[name] = member;
  5124. return this;
  5125. },
  5126. /**
  5127. * Adds members to class.
  5128. * @static
  5129. * @inheritable
  5130. * @deprecated 4.1 Use {@link #addMembers} instead.
  5131. */
  5132. implement: function() {
  5133. this.addMembers.apply(this, arguments);
  5134. },
  5135. /**
  5136. * Borrow another class' members to the prototype of this class.
  5137. *
  5138. * Ext.define('Bank', {
  5139. * money: '$$$',
  5140. * printMoney: function() {
  5141. * alert('$$$$$$$');
  5142. * }
  5143. * });
  5144. *
  5145. * Ext.define('Thief', {
  5146. * ...
  5147. * });
  5148. *
  5149. * Thief.borrow(Bank, ['money', 'printMoney']);
  5150. *
  5151. * var steve = new Thief();
  5152. *
  5153. * alert(steve.money); // alerts '$$$'
  5154. * steve.printMoney(); // alerts '$$$$$$$'
  5155. *
  5156. * @param {Ext.Base} fromClass The class to borrow members from
  5157. * @param {Array/String} members The names of the members to borrow
  5158. * @return {Ext.Base} this
  5159. * @static
  5160. * @inheritable
  5161. * @private
  5162. */
  5163. borrow: function(fromClass, members) {
  5164. var prototype = this.prototype,
  5165. fromPrototype = fromClass.prototype,
  5166. //<debug>
  5167. className = Ext.getClassName(this),
  5168. //</debug>
  5169. i, ln, name, fn, toBorrow;
  5170. members = Ext.Array.from(members);
  5171. for (i = 0,ln = members.length; i < ln; i++) {
  5172. name = members[i];
  5173. toBorrow = fromPrototype[name];
  5174. if (typeof toBorrow == 'function') {
  5175. fn = Ext.Function.clone(toBorrow);
  5176. //<debug>
  5177. if (className) {
  5178. fn.displayName = className + '#' + name;
  5179. }
  5180. //</debug>
  5181. fn.$owner = this;
  5182. fn.$name = name;
  5183. prototype[name] = fn;
  5184. }
  5185. else {
  5186. prototype[name] = toBorrow;
  5187. }
  5188. }
  5189. return this;
  5190. },
  5191. /**
  5192. * Override members of this class. Overridden methods can be invoked via
  5193. * {@link Ext.Base#callParent}.
  5194. *
  5195. * Ext.define('My.Cat', {
  5196. * constructor: function() {
  5197. * alert("I'm a cat!");
  5198. * }
  5199. * });
  5200. *
  5201. * My.Cat.override({
  5202. * constructor: function() {
  5203. * alert("I'm going to be a cat!");
  5204. *
  5205. * this.callParent(arguments);
  5206. *
  5207. * alert("Meeeeoooowwww");
  5208. * }
  5209. * });
  5210. *
  5211. * var kitty = new My.Cat(); // alerts "I'm going to be a cat!"
  5212. * // alerts "I'm a cat!"
  5213. * // alerts "Meeeeoooowwww"
  5214. *
  5215. * As of 4.1, direct use of this method is deprecated. Use {@link Ext#define Ext.define}
  5216. * instead:
  5217. *
  5218. * Ext.define('My.CatOverride', {
  5219. * override: 'My.Cat',
  5220. * constructor: function() {
  5221. * alert("I'm going to be a cat!");
  5222. *
  5223. * this.callParent(arguments);
  5224. *
  5225. * alert("Meeeeoooowwww");
  5226. * }
  5227. * });
  5228. *
  5229. * The above accomplishes the same result but can be managed by the {@link Ext.Loader}
  5230. * which can properly order the override and its target class and the build process
  5231. * can determine whether the override is needed based on the required state of the
  5232. * target class (My.Cat).
  5233. *
  5234. * @param {Object} members The properties to add to this class. This should be
  5235. * specified as an object literal containing one or more properties.
  5236. * @return {Ext.Base} this class
  5237. * @static
  5238. * @inheritable
  5239. * @markdown
  5240. * @deprecated 4.1.0 Use {@link Ext#define Ext.define} instead
  5241. */
  5242. override: function(members) {
  5243. var me = this,
  5244. enumerables = Ext.enumerables,
  5245. target = me.prototype,
  5246. cloneFunction = Ext.Function.clone,
  5247. name, index, member, statics, names, previous;
  5248. if (arguments.length === 2) {
  5249. name = members;
  5250. members = {};
  5251. members[name] = arguments[1];
  5252. enumerables = null;
  5253. }
  5254. do {
  5255. names = []; // clean slate for prototype (1st pass) and static (2nd pass)
  5256. statics = null; // not needed 1st pass, but needs to be cleared for 2nd pass
  5257. for (name in members) { // hasOwnProperty is checked in the next loop...
  5258. if (name == 'statics') {
  5259. statics = members[name];
  5260. } else if (name == 'config') {
  5261. me.addConfig(members[name], true);
  5262. } else {
  5263. names.push(name);
  5264. }
  5265. }
  5266. if (enumerables) {
  5267. names.push.apply(names, enumerables);
  5268. }
  5269. for (index = names.length; index--; ) {
  5270. name = names[index];
  5271. if (members.hasOwnProperty(name)) {
  5272. member = members[name];
  5273. if (typeof member == 'function' && !member.$className && member !== Ext.emptyFn) {
  5274. if (typeof member.$owner != 'undefined') {
  5275. member = cloneFunction(member);
  5276. }
  5277. //<debug>
  5278. if (me.$className) {
  5279. member.displayName = me.$className + '#' + name;
  5280. }
  5281. //</debug>
  5282. member.$owner = me;
  5283. member.$name = name;
  5284. previous = target[name];
  5285. if (previous) {
  5286. member.$previous = previous;
  5287. }
  5288. }
  5289. target[name] = member;
  5290. }
  5291. }
  5292. target = me; // 2nd pass is for statics
  5293. members = statics; // statics will be null on 2nd pass
  5294. } while (members);
  5295. return this;
  5296. },
  5297. // Documented downwards
  5298. callParent: function(args) {
  5299. var method;
  5300. // This code is intentionally inlined for the least number of debugger stepping
  5301. return (method = this.callParent.caller) && (method.$previous ||
  5302. ((method = method.$owner ? method : method.caller) &&
  5303. method.$owner.superclass.$class[method.$name])).apply(this, args || noArgs);
  5304. },
  5305. //<feature classSystem.mixins>
  5306. /**
  5307. * Used internally by the mixins pre-processor
  5308. * @private
  5309. * @static
  5310. * @inheritable
  5311. */
  5312. mixin: function(name, mixinClass) {
  5313. var mixin = mixinClass.prototype,
  5314. prototype = this.prototype,
  5315. key;
  5316. if (typeof mixin.onClassMixedIn != 'undefined') {
  5317. mixin.onClassMixedIn.call(mixinClass, this);
  5318. }
  5319. if (!prototype.hasOwnProperty('mixins')) {
  5320. if ('mixins' in prototype) {
  5321. prototype.mixins = Ext.Object.chain(prototype.mixins);
  5322. }
  5323. else {
  5324. prototype.mixins = {};
  5325. }
  5326. }
  5327. for (key in mixin) {
  5328. if (key === 'mixins') {
  5329. Ext.merge(prototype.mixins, mixin[key]);
  5330. }
  5331. else if (typeof prototype[key] == 'undefined' && key != 'mixinId' && key != 'config') {
  5332. prototype[key] = mixin[key];
  5333. }
  5334. }
  5335. //<feature classSystem.config>
  5336. if ('config' in mixin) {
  5337. this.addConfig(mixin.config, false);
  5338. }
  5339. //</feature>
  5340. prototype.mixins[name] = mixin;
  5341. },
  5342. //</feature>
  5343. /**
  5344. * Get the current class' name in string format.
  5345. *
  5346. * Ext.define('My.cool.Class', {
  5347. * constructor: function() {
  5348. * alert(this.self.getName()); // alerts 'My.cool.Class'
  5349. * }
  5350. * });
  5351. *
  5352. * My.cool.Class.getName(); // 'My.cool.Class'
  5353. *
  5354. * @return {String} className
  5355. * @static
  5356. * @inheritable
  5357. */
  5358. getName: function() {
  5359. return Ext.getClassName(this);
  5360. },
  5361. /**
  5362. * Create aliases for existing prototype methods. Example:
  5363. *
  5364. * Ext.define('My.cool.Class', {
  5365. * method1: function() { ... },
  5366. * method2: function() { ... }
  5367. * });
  5368. *
  5369. * var test = new My.cool.Class();
  5370. *
  5371. * My.cool.Class.createAlias({
  5372. * method3: 'method1',
  5373. * method4: 'method2'
  5374. * });
  5375. *
  5376. * test.method3(); // test.method1()
  5377. *
  5378. * My.cool.Class.createAlias('method5', 'method3');
  5379. *
  5380. * test.method5(); // test.method3() -> test.method1()
  5381. *
  5382. * @param {String/Object} alias The new method name, or an object to set multiple aliases. See
  5383. * {@link Ext.Function#flexSetter flexSetter}
  5384. * @param {String/Object} origin The original method name
  5385. * @static
  5386. * @inheritable
  5387. * @method
  5388. */
  5389. createAlias: flexSetter(function(alias, origin) {
  5390. this.override(alias, function() {
  5391. return this[origin].apply(this, arguments);
  5392. });
  5393. }),
  5394. /**
  5395. * @private
  5396. * @static
  5397. * @inheritable
  5398. */
  5399. addXtype: function(xtype) {
  5400. var prototype = this.prototype,
  5401. xtypesMap = prototype.xtypesMap,
  5402. xtypes = prototype.xtypes,
  5403. xtypesChain = prototype.xtypesChain;
  5404. if (!prototype.hasOwnProperty('xtypesMap')) {
  5405. xtypesMap = prototype.xtypesMap = Ext.merge({}, prototype.xtypesMap || {});
  5406. xtypes = prototype.xtypes = prototype.xtypes ? [].concat(prototype.xtypes) : [];
  5407. xtypesChain = prototype.xtypesChain = prototype.xtypesChain ? [].concat(prototype.xtypesChain) : [];
  5408. prototype.xtype = xtype;
  5409. }
  5410. if (!xtypesMap[xtype]) {
  5411. xtypesMap[xtype] = true;
  5412. xtypes.push(xtype);
  5413. xtypesChain.push(xtype);
  5414. Ext.ClassManager.setAlias(this, 'widget.' + xtype);
  5415. }
  5416. return this;
  5417. }
  5418. });
  5419. Base.implement({
  5420. /** @private */
  5421. isInstance: true,
  5422. /** @private */
  5423. $className: 'Ext.Base',
  5424. /** @private */
  5425. configClass: Ext.emptyFn,
  5426. /** @private */
  5427. initConfigList: [],
  5428. /** @private */
  5429. configMap: {},
  5430. /** @private */
  5431. initConfigMap: {},
  5432. /**
  5433. * Get the reference to the class from which this object was instantiated. Note that unlike {@link Ext.Base#self},
  5434. * `this.statics()` is scope-independent and it always returns the class from which it was called, regardless of what
  5435. * `this` points to during run-time
  5436. *
  5437. * Ext.define('My.Cat', {
  5438. * statics: {
  5439. * totalCreated: 0,
  5440. * speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
  5441. * },
  5442. *
  5443. * constructor: function() {
  5444. * var statics = this.statics();
  5445. *
  5446. * alert(statics.speciesName); // always equals to 'Cat' no matter what 'this' refers to
  5447. * // equivalent to: My.Cat.speciesName
  5448. *
  5449. * alert(this.self.speciesName); // dependent on 'this'
  5450. *
  5451. * statics.totalCreated++;
  5452. * },
  5453. *
  5454. * clone: function() {
  5455. * var cloned = new this.self; // dependent on 'this'
  5456. *
  5457. * cloned.groupName = this.statics().speciesName; // equivalent to: My.Cat.speciesName
  5458. *
  5459. * return cloned;
  5460. * }
  5461. * });
  5462. *
  5463. *
  5464. * Ext.define('My.SnowLeopard', {
  5465. * extend: 'My.Cat',
  5466. *
  5467. * statics: {
  5468. * speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'
  5469. * },
  5470. *
  5471. * constructor: function() {
  5472. * this.callParent();
  5473. * }
  5474. * });
  5475. *
  5476. * var cat = new My.Cat(); // alerts 'Cat', then alerts 'Cat'
  5477. *
  5478. * var snowLeopard = new My.SnowLeopard(); // alerts 'Cat', then alerts 'Snow Leopard'
  5479. *
  5480. * var clone = snowLeopard.clone();
  5481. * alert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'
  5482. * alert(clone.groupName); // alerts 'Cat'
  5483. *
  5484. * alert(My.Cat.totalCreated); // alerts 3
  5485. *
  5486. * @protected
  5487. * @return {Ext.Class}
  5488. */
  5489. statics: function() {
  5490. var method = this.statics.caller,
  5491. self = this.self;
  5492. if (!method) {
  5493. return self;
  5494. }
  5495. return method.$owner;
  5496. },
  5497. /**
  5498. * Call the "parent" method of the current method. That is the method previously
  5499. * overridden by derivation or by an override (see {@link Ext#define}).
  5500. *
  5501. * Ext.define('My.Base', {
  5502. * constructor: function (x) {
  5503. * this.x = x;
  5504. * },
  5505. *
  5506. * statics: {
  5507. * method: function (x) {
  5508. * return x;
  5509. * }
  5510. * }
  5511. * });
  5512. *
  5513. * Ext.define('My.Derived', {
  5514. * extend: 'My.Base',
  5515. *
  5516. * constructor: function () {
  5517. * this.callParent([21]);
  5518. * }
  5519. * });
  5520. *
  5521. * var obj = new My.Derived();
  5522. *
  5523. * alert(obj.x); // alerts 21
  5524. *
  5525. * This can be used with an override as follows:
  5526. *
  5527. * Ext.define('My.DerivedOverride', {
  5528. * override: 'My.Derived',
  5529. *
  5530. * constructor: function (x) {
  5531. * this.callParent([x*2]); // calls original My.Derived constructor
  5532. * }
  5533. * });
  5534. *
  5535. * var obj = new My.Derived();
  5536. *
  5537. * alert(obj.x); // now alerts 42
  5538. *
  5539. * This also works with static methods.
  5540. *
  5541. * Ext.define('My.Derived2', {
  5542. * extend: 'My.Base',
  5543. *
  5544. * statics: {
  5545. * method: function (x) {
  5546. * return this.callParent([x*2]); // calls My.Base.method
  5547. * }
  5548. * }
  5549. * });
  5550. *
  5551. * alert(My.Base.method(10); // alerts 10
  5552. * alert(My.Derived2.method(10); // alerts 20
  5553. *
  5554. * Lastly, it also works with overridden static methods.
  5555. *
  5556. * Ext.define('My.Derived2Override', {
  5557. * override: 'My.Derived2',
  5558. *
  5559. * statics: {
  5560. * method: function (x) {
  5561. * return this.callParent([x*2]); // calls My.Derived2.method
  5562. * }
  5563. * }
  5564. * });
  5565. *
  5566. * alert(My.Derived2.method(10); // now alerts 40
  5567. *
  5568. * @protected
  5569. * @param {Array/Arguments} args The arguments, either an array or the `arguments` object
  5570. * from the current method, for example: `this.callParent(arguments)`
  5571. * @return {Object} Returns the result of calling the parent method
  5572. */
  5573. callParent: function(args) {
  5574. // NOTE: this code is deliberately as few expressions (and no function calls)
  5575. // as possible so that a debugger can skip over this noise with the minimum number
  5576. // of steps. Basically, just hit Step Into until you are where you really wanted
  5577. // to be.
  5578. var method,
  5579. superMethod = (method = this.callParent.caller) && (method.$previous ||
  5580. ((method = method.$owner ? method : method.caller) &&
  5581. method.$owner.superclass[method.$name]));
  5582. //<debug error>
  5583. if (!superMethod) {
  5584. method = this.callParent.caller;
  5585. var parentClass, methodName;
  5586. if (!method.$owner) {
  5587. if (!method.caller) {
  5588. throw new Error("Attempting to call a protected method from the public scope, which is not allowed");
  5589. }
  5590. method = method.caller;
  5591. }
  5592. parentClass = method.$owner.superclass;
  5593. methodName = method.$name;
  5594. if (!(methodName in parentClass)) {
  5595. throw new Error("this.callParent() was called but there's no such method (" + methodName +
  5596. ") found in the parent class (" + (Ext.getClassName(parentClass) || 'Object') + ")");
  5597. }
  5598. }
  5599. //</debug>
  5600. return superMethod.apply(this, args || noArgs);
  5601. },
  5602. /**
  5603. * @property {Ext.Class} self
  5604. *
  5605. * Get the reference to the current class from which this object was instantiated. Unlike {@link Ext.Base#statics},
  5606. * `this.self` is scope-dependent and it's meant to be used for dynamic inheritance. See {@link Ext.Base#statics}
  5607. * for a detailed comparison
  5608. *
  5609. * Ext.define('My.Cat', {
  5610. * statics: {
  5611. * speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
  5612. * },
  5613. *
  5614. * constructor: function() {
  5615. * alert(this.self.speciesName); // dependent on 'this'
  5616. * },
  5617. *
  5618. * clone: function() {
  5619. * return new this.self();
  5620. * }
  5621. * });
  5622. *
  5623. *
  5624. * Ext.define('My.SnowLeopard', {
  5625. * extend: 'My.Cat',
  5626. * statics: {
  5627. * speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'
  5628. * }
  5629. * });
  5630. *
  5631. * var cat = new My.Cat(); // alerts 'Cat'
  5632. * var snowLeopard = new My.SnowLeopard(); // alerts 'Snow Leopard'
  5633. *
  5634. * var clone = snowLeopard.clone();
  5635. * alert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'
  5636. *
  5637. * @protected
  5638. */
  5639. self: Base,
  5640. // Default constructor, simply returns `this`
  5641. constructor: function() {
  5642. return this;
  5643. },
  5644. //<feature classSystem.config>
  5645. /**
  5646. * Initialize configuration for this class. a typical example:
  5647. *
  5648. * Ext.define('My.awesome.Class', {
  5649. * // The default config
  5650. * config: {
  5651. * name: 'Awesome',
  5652. * isAwesome: true
  5653. * },
  5654. *
  5655. * constructor: function(config) {
  5656. * this.initConfig(config);
  5657. * }
  5658. * });
  5659. *
  5660. * var awesome = new My.awesome.Class({
  5661. * name: 'Super Awesome'
  5662. * });
  5663. *
  5664. * alert(awesome.getName()); // 'Super Awesome'
  5665. *
  5666. * @protected
  5667. * @param {Object} config
  5668. * @return {Ext.Base} this
  5669. */
  5670. initConfig: function(config) {
  5671. var instanceConfig = config,
  5672. configNameCache = Ext.Class.configNameCache,
  5673. defaultConfig = new this.configClass(),
  5674. defaultConfigList = this.initConfigList,
  5675. hasConfig = this.configMap,
  5676. nameMap, i, ln, name, initializedName;
  5677. this.initConfig = Ext.emptyFn;
  5678. this.initialConfig = instanceConfig || {};
  5679. this.config = config = (instanceConfig) ? Ext.merge(defaultConfig, config) : defaultConfig;
  5680. if (instanceConfig) {
  5681. defaultConfigList = defaultConfigList.slice();
  5682. for (name in instanceConfig) {
  5683. if (hasConfig[name]) {
  5684. if (instanceConfig[name] !== null) {
  5685. defaultConfigList.push(name);
  5686. this[configNameCache[name].initialized] = false;
  5687. }
  5688. }
  5689. }
  5690. }
  5691. for (i = 0,ln = defaultConfigList.length; i < ln; i++) {
  5692. name = defaultConfigList[i];
  5693. nameMap = configNameCache[name];
  5694. initializedName = nameMap.initialized;
  5695. if (!this[initializedName]) {
  5696. this[initializedName] = true;
  5697. this[nameMap.set].call(this, config[name]);
  5698. }
  5699. }
  5700. return this;
  5701. },
  5702. /**
  5703. * @private
  5704. * @param config
  5705. */
  5706. hasConfig: function(name) {
  5707. return Boolean(this.configMap[name]);
  5708. },
  5709. /**
  5710. * @private
  5711. */
  5712. setConfig: function(config, applyIfNotSet) {
  5713. if (!config) {
  5714. return this;
  5715. }
  5716. var configNameCache = Ext.Class.configNameCache,
  5717. currentConfig = this.config,
  5718. hasConfig = this.configMap,
  5719. initialConfig = this.initialConfig,
  5720. name, value;
  5721. applyIfNotSet = Boolean(applyIfNotSet);
  5722. for (name in config) {
  5723. if (applyIfNotSet && initialConfig.hasOwnProperty(name)) {
  5724. continue;
  5725. }
  5726. value = config[name];
  5727. currentConfig[name] = value;
  5728. if (hasConfig[name]) {
  5729. this[configNameCache[name].set](value);
  5730. }
  5731. }
  5732. return this;
  5733. },
  5734. /**
  5735. * @private
  5736. * @param name
  5737. */
  5738. getConfig: function(name) {
  5739. var configNameCache = Ext.Class.configNameCache;
  5740. return this[configNameCache[name].get]();
  5741. },
  5742. /**
  5743. * Returns the initial configuration passed to constructor when instantiating
  5744. * this class.
  5745. * @param {String} [name] Name of the config option to return.
  5746. * @return {Object/Mixed} The full config object or a single config value
  5747. * when `name` parameter specified.
  5748. */
  5749. getInitialConfig: function(name) {
  5750. var config = this.config;
  5751. if (!name) {
  5752. return config;
  5753. }
  5754. else {
  5755. return config[name];
  5756. }
  5757. },
  5758. /**
  5759. * @private
  5760. * @param names
  5761. * @param callback
  5762. * @param scope
  5763. */
  5764. onConfigUpdate: function(names, callback, scope) {
  5765. var self = this.self,
  5766. //<debug>
  5767. className = self.$className,
  5768. //</debug>
  5769. i, ln, name,
  5770. updaterName, updater, newUpdater;
  5771. names = Ext.Array.from(names);
  5772. scope = scope || this;
  5773. for (i = 0,ln = names.length; i < ln; i++) {
  5774. name = names[i];
  5775. updaterName = 'update' + Ext.String.capitalize(name);
  5776. updater = this[updaterName] || Ext.emptyFn;
  5777. newUpdater = function() {
  5778. updater.apply(this, arguments);
  5779. scope[callback].apply(scope, arguments);
  5780. };
  5781. newUpdater.$name = updaterName;
  5782. newUpdater.$owner = self;
  5783. //<debug>
  5784. newUpdater.displayName = className + '#' + updaterName;
  5785. //</debug>
  5786. this[updaterName] = newUpdater;
  5787. }
  5788. },
  5789. //</feature>
  5790. /**
  5791. * @private
  5792. */
  5793. destroy: function() {
  5794. this.destroy = Ext.emptyFn;
  5795. }
  5796. });
  5797. /**
  5798. * Call the original method that was previously overridden with {@link Ext.Base#override}
  5799. *
  5800. * Ext.define('My.Cat', {
  5801. * constructor: function() {
  5802. * alert("I'm a cat!");
  5803. * }
  5804. * });
  5805. *
  5806. * My.Cat.override({
  5807. * constructor: function() {
  5808. * alert("I'm going to be a cat!");
  5809. *
  5810. * this.callOverridden();
  5811. *
  5812. * alert("Meeeeoooowwww");
  5813. * }
  5814. * });
  5815. *
  5816. * var kitty = new My.Cat(); // alerts "I'm going to be a cat!"
  5817. * // alerts "I'm a cat!"
  5818. * // alerts "Meeeeoooowwww"
  5819. *
  5820. * @param {Array/Arguments} args The arguments, either an array or the `arguments` object
  5821. * from the current method, for example: `this.callOverridden(arguments)`
  5822. * @return {Object} Returns the result of calling the overridden method
  5823. * @protected
  5824. * @deprecated as of 4.1. Use {@link #callParent} instead.
  5825. */
  5826. Base.prototype.callOverridden = Base.prototype.callParent;
  5827. Ext.Base = Base;
  5828. }(Ext.Function.flexSetter));
  5829. /**
  5830. * @author Jacky Nguyen <jacky@sencha.com>
  5831. * @docauthor Jacky Nguyen <jacky@sencha.com>
  5832. * @class Ext.Class
  5833. *
  5834. * Handles class creation throughout the framework. This is a low level factory that is used by Ext.ClassManager and generally
  5835. * should not be used directly. If you choose to use Ext.Class you will lose out on the namespace, aliasing and depency loading
  5836. * features made available by Ext.ClassManager. The only time you would use Ext.Class directly is to create an anonymous class.
  5837. *
  5838. * If you wish to create a class you should use {@link Ext#define Ext.define} which aliases
  5839. * {@link Ext.ClassManager#create Ext.ClassManager.create} to enable namespacing and dynamic dependency resolution.
  5840. *
  5841. * Ext.Class is the factory and **not** the superclass of everything. For the base class that **all** Ext classes inherit
  5842. * from, see {@link Ext.Base}.
  5843. */
  5844. (function() {
  5845. var ExtClass,
  5846. Base = Ext.Base,
  5847. baseStaticMembers = [],
  5848. baseStaticMember, baseStaticMemberLength;
  5849. for (baseStaticMember in Base) {
  5850. if (Base.hasOwnProperty(baseStaticMember)) {
  5851. baseStaticMembers.push(baseStaticMember);
  5852. }
  5853. }
  5854. baseStaticMemberLength = baseStaticMembers.length;
  5855. // Creates a constructor that has nothing extra in its scope chain.
  5856. function makeCtor (className) {
  5857. function constructor () {
  5858. // Opera has some problems returning from a constructor when Dragonfly isn't running. The || null seems to
  5859. // be sufficient to stop it misbehaving. Known to be required against 10.53, 11.51 and 11.61.
  5860. return this.constructor.apply(this, arguments) || null;
  5861. }
  5862. //<debug>
  5863. if (className) {
  5864. constructor.displayName = className;
  5865. }
  5866. //</debug>
  5867. return constructor;
  5868. }
  5869. /**
  5870. * @method constructor
  5871. * Create a new anonymous class.
  5872. *
  5873. * @param {Object} data An object represent the properties of this class
  5874. * @param {Function} onCreated Optional, the callback function to be executed when this class is fully created.
  5875. * Note that the creation process can be asynchronous depending on the pre-processors used.
  5876. *
  5877. * @return {Ext.Base} The newly created class
  5878. */
  5879. Ext.Class = ExtClass = function(Class, data, onCreated) {
  5880. if (typeof Class != 'function') {
  5881. onCreated = data;
  5882. data = Class;
  5883. Class = null;
  5884. }
  5885. if (!data) {
  5886. data = {};
  5887. }
  5888. Class = ExtClass.create(Class, data);
  5889. ExtClass.process(Class, data, onCreated);
  5890. return Class;
  5891. };
  5892. Ext.apply(ExtClass, {
  5893. /**
  5894. * @private
  5895. * @param Class
  5896. * @param data
  5897. * @param hooks
  5898. */
  5899. onBeforeCreated: function(Class, data, hooks) {
  5900. Class.addMembers(data);
  5901. hooks.onCreated.call(Class, Class);
  5902. },
  5903. /**
  5904. * @private
  5905. * @param Class
  5906. * @param classData
  5907. * @param onClassCreated
  5908. */
  5909. create: function(Class, data) {
  5910. var name, i;
  5911. if (!Class) {
  5912. Class = makeCtor(
  5913. //<debug>
  5914. data.$className
  5915. //</debug>
  5916. );
  5917. }
  5918. for (i = 0; i < baseStaticMemberLength; i++) {
  5919. name = baseStaticMembers[i];
  5920. Class[name] = Base[name];
  5921. }
  5922. return Class;
  5923. },
  5924. /**
  5925. * @private
  5926. * @param Class
  5927. * @param data
  5928. * @param onCreated
  5929. */
  5930. process: function(Class, data, onCreated) {
  5931. var preprocessorStack = data.preprocessors || ExtClass.defaultPreprocessors,
  5932. registeredPreprocessors = this.preprocessors,
  5933. hooks = {
  5934. onBeforeCreated: this.onBeforeCreated
  5935. },
  5936. preprocessors = [],
  5937. preprocessor, preprocessorsProperties,
  5938. i, ln, j, subLn, preprocessorProperty, process;
  5939. delete data.preprocessors;
  5940. for (i = 0,ln = preprocessorStack.length; i < ln; i++) {
  5941. preprocessor = preprocessorStack[i];
  5942. if (typeof preprocessor == 'string') {
  5943. preprocessor = registeredPreprocessors[preprocessor];
  5944. preprocessorsProperties = preprocessor.properties;
  5945. if (preprocessorsProperties === true) {
  5946. preprocessors.push(preprocessor.fn);
  5947. }
  5948. else if (preprocessorsProperties) {
  5949. for (j = 0,subLn = preprocessorsProperties.length; j < subLn; j++) {
  5950. preprocessorProperty = preprocessorsProperties[j];
  5951. if (data.hasOwnProperty(preprocessorProperty)) {
  5952. preprocessors.push(preprocessor.fn);
  5953. break;
  5954. }
  5955. }
  5956. }
  5957. }
  5958. else {
  5959. preprocessors.push(preprocessor);
  5960. }
  5961. }
  5962. hooks.onCreated = onCreated ? onCreated : Ext.emptyFn;
  5963. hooks.preprocessors = preprocessors;
  5964. this.doProcess(Class, data, hooks);
  5965. },
  5966. doProcess: function(Class, data, hooks){
  5967. var me = this,
  5968. preprocessor = hooks.preprocessors.shift();
  5969. if (!preprocessor) {
  5970. hooks.onBeforeCreated.apply(me, arguments);
  5971. return;
  5972. }
  5973. if (preprocessor.call(me, Class, data, hooks, me.doProcess) !== false) {
  5974. me.doProcess(Class, data, hooks);
  5975. }
  5976. },
  5977. /** @private */
  5978. preprocessors: {},
  5979. /**
  5980. * Register a new pre-processor to be used during the class creation process
  5981. *
  5982. * @param {String} name The pre-processor's name
  5983. * @param {Function} fn The callback function to be executed. Typical format:
  5984. *
  5985. * function(cls, data, fn) {
  5986. * // Your code here
  5987. *
  5988. * // Execute this when the processing is finished.
  5989. * // Asynchronous processing is perfectly ok
  5990. * if (fn) {
  5991. * fn.call(this, cls, data);
  5992. * }
  5993. * });
  5994. *
  5995. * @param {Function} fn.cls The created class
  5996. * @param {Object} fn.data The set of properties passed in {@link Ext.Class} constructor
  5997. * @param {Function} fn.fn The callback function that **must** to be executed when this
  5998. * pre-processor finishes, regardless of whether the processing is synchronous or aynchronous.
  5999. * @return {Ext.Class} this
  6000. * @private
  6001. * @static
  6002. */
  6003. registerPreprocessor: function(name, fn, properties, position, relativeTo) {
  6004. if (!position) {
  6005. position = 'last';
  6006. }
  6007. if (!properties) {
  6008. properties = [name];
  6009. }
  6010. this.preprocessors[name] = {
  6011. name: name,
  6012. properties: properties || false,
  6013. fn: fn
  6014. };
  6015. this.setDefaultPreprocessorPosition(name, position, relativeTo);
  6016. return this;
  6017. },
  6018. /**
  6019. * Retrieve a pre-processor callback function by its name, which has been registered before
  6020. *
  6021. * @param {String} name
  6022. * @return {Function} preprocessor
  6023. * @private
  6024. * @static
  6025. */
  6026. getPreprocessor: function(name) {
  6027. return this.preprocessors[name];
  6028. },
  6029. /**
  6030. * @private
  6031. */
  6032. getPreprocessors: function() {
  6033. return this.preprocessors;
  6034. },
  6035. /**
  6036. * @private
  6037. */
  6038. defaultPreprocessors: [],
  6039. /**
  6040. * Retrieve the array stack of default pre-processors
  6041. * @return {Function[]} defaultPreprocessors
  6042. * @private
  6043. * @static
  6044. */
  6045. getDefaultPreprocessors: function() {
  6046. return this.defaultPreprocessors;
  6047. },
  6048. /**
  6049. * Set the default array stack of default pre-processors
  6050. *
  6051. * @private
  6052. * @param {Array} preprocessors
  6053. * @return {Ext.Class} this
  6054. * @static
  6055. */
  6056. setDefaultPreprocessors: function(preprocessors) {
  6057. this.defaultPreprocessors = Ext.Array.from(preprocessors);
  6058. return this;
  6059. },
  6060. /**
  6061. * Insert this pre-processor at a specific position in the stack, optionally relative to
  6062. * any existing pre-processor. For example:
  6063. *
  6064. * Ext.Class.registerPreprocessor('debug', function(cls, data, fn) {
  6065. * // Your code here
  6066. *
  6067. * if (fn) {
  6068. * fn.call(this, cls, data);
  6069. * }
  6070. * }).setDefaultPreprocessorPosition('debug', 'last');
  6071. *
  6072. * @private
  6073. * @param {String} name The pre-processor name. Note that it needs to be registered with
  6074. * {@link Ext.Class#registerPreprocessor registerPreprocessor} before this
  6075. * @param {String} offset The insertion position. Four possible values are:
  6076. * 'first', 'last', or: 'before', 'after' (relative to the name provided in the third argument)
  6077. * @param {String} relativeName
  6078. * @return {Ext.Class} this
  6079. * @static
  6080. */
  6081. setDefaultPreprocessorPosition: function(name, offset, relativeName) {
  6082. var defaultPreprocessors = this.defaultPreprocessors,
  6083. index;
  6084. if (typeof offset == 'string') {
  6085. if (offset === 'first') {
  6086. defaultPreprocessors.unshift(name);
  6087. return this;
  6088. }
  6089. else if (offset === 'last') {
  6090. defaultPreprocessors.push(name);
  6091. return this;
  6092. }
  6093. offset = (offset === 'after') ? 1 : -1;
  6094. }
  6095. index = Ext.Array.indexOf(defaultPreprocessors, relativeName);
  6096. if (index !== -1) {
  6097. Ext.Array.splice(defaultPreprocessors, Math.max(0, index + offset), 0, name);
  6098. }
  6099. return this;
  6100. },
  6101. configNameCache: {},
  6102. getConfigNameMap: function(name) {
  6103. var cache = this.configNameCache,
  6104. map = cache[name],
  6105. capitalizedName;
  6106. if (!map) {
  6107. capitalizedName = name.charAt(0).toUpperCase() + name.substr(1);
  6108. map = cache[name] = {
  6109. internal: name,
  6110. initialized: '_is' + capitalizedName + 'Initialized',
  6111. apply: 'apply' + capitalizedName,
  6112. update: 'update' + capitalizedName,
  6113. 'set': 'set' + capitalizedName,
  6114. 'get': 'get' + capitalizedName,
  6115. doSet : 'doSet' + capitalizedName,
  6116. changeEvent: name.toLowerCase() + 'change'
  6117. };
  6118. }
  6119. return map;
  6120. }
  6121. });
  6122. /**
  6123. * @cfg {String} extend
  6124. * The parent class that this class extends. For example:
  6125. *
  6126. * Ext.define('Person', {
  6127. * say: function(text) { alert(text); }
  6128. * });
  6129. *
  6130. * Ext.define('Developer', {
  6131. * extend: 'Person',
  6132. * say: function(text) { this.callParent(["print "+text]); }
  6133. * });
  6134. */
  6135. ExtClass.registerPreprocessor('extend', function(Class, data) {
  6136. var Base = Ext.Base,
  6137. basePrototype = Base.prototype,
  6138. extend = data.extend,
  6139. Parent, parentPrototype, i;
  6140. delete data.extend;
  6141. if (extend && extend !== Object) {
  6142. Parent = extend;
  6143. }
  6144. else {
  6145. Parent = Base;
  6146. }
  6147. parentPrototype = Parent.prototype;
  6148. if (!Parent.$isClass) {
  6149. for (i in basePrototype) {
  6150. if (!parentPrototype[i]) {
  6151. parentPrototype[i] = basePrototype[i];
  6152. }
  6153. }
  6154. }
  6155. Class.extend(Parent);
  6156. Class.triggerExtended.apply(Class, arguments);
  6157. if (data.onClassExtended) {
  6158. Class.onExtended(data.onClassExtended, Class);
  6159. delete data.onClassExtended;
  6160. }
  6161. }, true);
  6162. //<feature classSystem.statics>
  6163. /**
  6164. * @cfg {Object} statics
  6165. * List of static methods for this class. For example:
  6166. *
  6167. * Ext.define('Computer', {
  6168. * statics: {
  6169. * factory: function(brand) {
  6170. * // 'this' in static methods refer to the class itself
  6171. * return new this(brand);
  6172. * }
  6173. * },
  6174. *
  6175. * constructor: function() { ... }
  6176. * });
  6177. *
  6178. * var dellComputer = Computer.factory('Dell');
  6179. */
  6180. ExtClass.registerPreprocessor('statics', function(Class, data) {
  6181. Class.addStatics(data.statics);
  6182. delete data.statics;
  6183. });
  6184. //</feature>
  6185. //<feature classSystem.inheritableStatics>
  6186. /**
  6187. * @cfg {Object} inheritableStatics
  6188. * List of inheritable static methods for this class.
  6189. * Otherwise just like {@link #statics} but subclasses inherit these methods.
  6190. */
  6191. ExtClass.registerPreprocessor('inheritableStatics', function(Class, data) {
  6192. Class.addInheritableStatics(data.inheritableStatics);
  6193. delete data.inheritableStatics;
  6194. });
  6195. //</feature>
  6196. //<feature classSystem.config>
  6197. /**
  6198. * @cfg {Object} config
  6199. * List of configuration options with their default values, for which automatically
  6200. * accessor methods are generated. For example:
  6201. *
  6202. * Ext.define('SmartPhone', {
  6203. * config: {
  6204. * hasTouchScreen: false,
  6205. * operatingSystem: 'Other',
  6206. * price: 500
  6207. * },
  6208. * constructor: function(cfg) {
  6209. * this.initConfig(cfg);
  6210. * }
  6211. * });
  6212. *
  6213. * var iPhone = new SmartPhone({
  6214. * hasTouchScreen: true,
  6215. * operatingSystem: 'iOS'
  6216. * });
  6217. *
  6218. * iPhone.getPrice(); // 500;
  6219. * iPhone.getOperatingSystem(); // 'iOS'
  6220. * iPhone.getHasTouchScreen(); // true;
  6221. */
  6222. ExtClass.registerPreprocessor('config', function(Class, data) {
  6223. var config = data.config,
  6224. prototype = Class.prototype;
  6225. delete data.config;
  6226. Ext.Object.each(config, function(name, value) {
  6227. var nameMap = ExtClass.getConfigNameMap(name),
  6228. internalName = nameMap.internal,
  6229. initializedName = nameMap.initialized,
  6230. applyName = nameMap.apply,
  6231. updateName = nameMap.update,
  6232. setName = nameMap.set,
  6233. getName = nameMap.get,
  6234. hasOwnSetter = (setName in prototype) || data.hasOwnProperty(setName),
  6235. hasOwnApplier = (applyName in prototype) || data.hasOwnProperty(applyName),
  6236. hasOwnUpdater = (updateName in prototype) || data.hasOwnProperty(updateName),
  6237. optimizedGetter, customGetter;
  6238. if (value === null || (!hasOwnSetter && !hasOwnApplier && !hasOwnUpdater)) {
  6239. prototype[internalName] = value;
  6240. prototype[initializedName] = true;
  6241. }
  6242. else {
  6243. prototype[initializedName] = false;
  6244. }
  6245. if (!hasOwnSetter) {
  6246. data[setName] = function(value) {
  6247. var oldValue = this[internalName],
  6248. applier = this[applyName],
  6249. updater = this[updateName];
  6250. if (!this[initializedName]) {
  6251. this[initializedName] = true;
  6252. }
  6253. if (applier) {
  6254. value = applier.call(this, value, oldValue);
  6255. }
  6256. if (typeof value != 'undefined') {
  6257. this[internalName] = value;
  6258. if (updater && value !== oldValue) {
  6259. updater.call(this, value, oldValue);
  6260. }
  6261. }
  6262. return this;
  6263. };
  6264. }
  6265. if (!(getName in prototype) || data.hasOwnProperty(getName)) {
  6266. customGetter = data[getName] || false;
  6267. if (customGetter) {
  6268. optimizedGetter = function() {
  6269. return customGetter.apply(this, arguments);
  6270. };
  6271. }
  6272. else {
  6273. optimizedGetter = function() {
  6274. return this[internalName];
  6275. };
  6276. }
  6277. data[getName] = function() {
  6278. var currentGetter;
  6279. if (!this[initializedName]) {
  6280. this[initializedName] = true;
  6281. this[setName](this.config[name]);
  6282. }
  6283. currentGetter = this[getName];
  6284. if ('$previous' in currentGetter) {
  6285. currentGetter.$previous = optimizedGetter;
  6286. }
  6287. else {
  6288. this[getName] = optimizedGetter;
  6289. }
  6290. return optimizedGetter.apply(this, arguments);
  6291. };
  6292. }
  6293. });
  6294. Class.addConfig(config, true);
  6295. });
  6296. //</feature>
  6297. //<feature classSystem.mixins>
  6298. /**
  6299. * @cfg {String[]/Object} mixins
  6300. * List of classes to mix into this class. For example:
  6301. *
  6302. * Ext.define('CanSing', {
  6303. * sing: function() {
  6304. * alert("I'm on the highway to hell...")
  6305. * }
  6306. * });
  6307. *
  6308. * Ext.define('Musician', {
  6309. * mixins: ['CanSing']
  6310. * })
  6311. *
  6312. * In this case the Musician class will get a `sing` method from CanSing mixin.
  6313. *
  6314. * But what if the Musician already has a `sing` method? Or you want to mix
  6315. * in two classes, both of which define `sing`? In such a cases it's good
  6316. * to define mixins as an object, where you assign a name to each mixin:
  6317. *
  6318. * Ext.define('Musician', {
  6319. * mixins: {
  6320. * canSing: 'CanSing'
  6321. * },
  6322. *
  6323. * sing: function() {
  6324. * // delegate singing operation to mixin
  6325. * this.mixins.canSing.sing.call(this);
  6326. * }
  6327. * })
  6328. *
  6329. * In this case the `sing` method of Musician will overwrite the
  6330. * mixed in `sing` method. But you can access the original mixed in method
  6331. * through special `mixins` property.
  6332. */
  6333. ExtClass.registerPreprocessor('mixins', function(Class, data, hooks) {
  6334. var mixins = data.mixins,
  6335. name, mixin, i, ln;
  6336. delete data.mixins;
  6337. Ext.Function.interceptBefore(hooks, 'onCreated', function() {
  6338. if (mixins instanceof Array) {
  6339. for (i = 0,ln = mixins.length; i < ln; i++) {
  6340. mixin = mixins[i];
  6341. name = mixin.prototype.mixinId || mixin.$className;
  6342. Class.mixin(name, mixin);
  6343. }
  6344. }
  6345. else {
  6346. for (var mixinName in mixins) {
  6347. if (mixins.hasOwnProperty(mixinName)) {
  6348. Class.mixin(mixinName, mixins[mixinName]);
  6349. }
  6350. }
  6351. }
  6352. });
  6353. });
  6354. //</feature>
  6355. //<feature classSystem.backwardsCompatible>
  6356. // Backwards compatible
  6357. Ext.extend = function(Class, Parent, members) {
  6358. if (arguments.length === 2 && Ext.isObject(Parent)) {
  6359. members = Parent;
  6360. Parent = Class;
  6361. Class = null;
  6362. }
  6363. var cls;
  6364. if (!Parent) {
  6365. throw new Error("[Ext.extend] Attempting to extend from a class which has not been loaded on the page.");
  6366. }
  6367. members.extend = Parent;
  6368. members.preprocessors = [
  6369. 'extend'
  6370. //<feature classSystem.statics>
  6371. ,'statics'
  6372. //</feature>
  6373. //<feature classSystem.inheritableStatics>
  6374. ,'inheritableStatics'
  6375. //</feature>
  6376. //<feature classSystem.mixins>
  6377. ,'mixins'
  6378. //</feature>
  6379. //<feature classSystem.config>
  6380. ,'config'
  6381. //</feature>
  6382. ];
  6383. if (Class) {
  6384. cls = new ExtClass(Class, members);
  6385. // The 'constructor' is given as 'Class' but also needs to be on prototype
  6386. cls.prototype.constructor = Class;
  6387. } else {
  6388. cls = new ExtClass(members);
  6389. }
  6390. cls.prototype.override = function(o) {
  6391. for (var m in o) {
  6392. if (o.hasOwnProperty(m)) {
  6393. this[m] = o[m];
  6394. }
  6395. }
  6396. };
  6397. return cls;
  6398. };
  6399. //</feature>
  6400. }());
  6401. /**
  6402. * @author Jacky Nguyen <jacky@sencha.com>
  6403. * @docauthor Jacky Nguyen <jacky@sencha.com>
  6404. * @class Ext.ClassManager
  6405. *
  6406. * Ext.ClassManager manages all classes and handles mapping from string class name to
  6407. * actual class objects throughout the whole framework. It is not generally accessed directly, rather through
  6408. * these convenient shorthands:
  6409. *
  6410. * - {@link Ext#define Ext.define}
  6411. * - {@link Ext#create Ext.create}
  6412. * - {@link Ext#widget Ext.widget}
  6413. * - {@link Ext#getClass Ext.getClass}
  6414. * - {@link Ext#getClassName Ext.getClassName}
  6415. *
  6416. * # Basic syntax:
  6417. *
  6418. * Ext.define(className, properties);
  6419. *
  6420. * in which `properties` is an object represent a collection of properties that apply to the class. See
  6421. * {@link Ext.ClassManager#create} for more detailed instructions.
  6422. *
  6423. * Ext.define('Person', {
  6424. * name: 'Unknown',
  6425. *
  6426. * constructor: function(name) {
  6427. * if (name) {
  6428. * this.name = name;
  6429. * }
  6430. * },
  6431. *
  6432. * eat: function(foodType) {
  6433. * alert("I'm eating: " + foodType);
  6434. *
  6435. * return this;
  6436. * }
  6437. * });
  6438. *
  6439. * var aaron = new Person("Aaron");
  6440. * aaron.eat("Sandwich"); // alert("I'm eating: Sandwich");
  6441. *
  6442. * Ext.Class has a powerful set of extensible {@link Ext.Class#registerPreprocessor pre-processors} which takes care of
  6443. * everything related to class creation, including but not limited to inheritance, mixins, configuration, statics, etc.
  6444. *
  6445. * # Inheritance:
  6446. *
  6447. * Ext.define('Developer', {
  6448. * extend: 'Person',
  6449. *
  6450. * constructor: function(name, isGeek) {
  6451. * this.isGeek = isGeek;
  6452. *
  6453. * // Apply a method from the parent class' prototype
  6454. * this.callParent([name]);
  6455. * },
  6456. *
  6457. * code: function(language) {
  6458. * alert("I'm coding in: " + language);
  6459. *
  6460. * this.eat("Bugs");
  6461. *
  6462. * return this;
  6463. * }
  6464. * });
  6465. *
  6466. * var jacky = new Developer("Jacky", true);
  6467. * jacky.code("JavaScript"); // alert("I'm coding in: JavaScript");
  6468. * // alert("I'm eating: Bugs");
  6469. *
  6470. * See {@link Ext.Base#callParent} for more details on calling superclass' methods
  6471. *
  6472. * # Mixins:
  6473. *
  6474. * Ext.define('CanPlayGuitar', {
  6475. * playGuitar: function() {
  6476. * alert("F#...G...D...A");
  6477. * }
  6478. * });
  6479. *
  6480. * Ext.define('CanComposeSongs', {
  6481. * composeSongs: function() { ... }
  6482. * });
  6483. *
  6484. * Ext.define('CanSing', {
  6485. * sing: function() {
  6486. * alert("I'm on the highway to hell...")
  6487. * }
  6488. * });
  6489. *
  6490. * Ext.define('Musician', {
  6491. * extend: 'Person',
  6492. *
  6493. * mixins: {
  6494. * canPlayGuitar: 'CanPlayGuitar',
  6495. * canComposeSongs: 'CanComposeSongs',
  6496. * canSing: 'CanSing'
  6497. * }
  6498. * })
  6499. *
  6500. * Ext.define('CoolPerson', {
  6501. * extend: 'Person',
  6502. *
  6503. * mixins: {
  6504. * canPlayGuitar: 'CanPlayGuitar',
  6505. * canSing: 'CanSing'
  6506. * },
  6507. *
  6508. * sing: function() {
  6509. * alert("Ahem....");
  6510. *
  6511. * this.mixins.canSing.sing.call(this);
  6512. *
  6513. * alert("[Playing guitar at the same time...]");
  6514. *
  6515. * this.playGuitar();
  6516. * }
  6517. * });
  6518. *
  6519. * var me = new CoolPerson("Jacky");
  6520. *
  6521. * me.sing(); // alert("Ahem...");
  6522. * // alert("I'm on the highway to hell...");
  6523. * // alert("[Playing guitar at the same time...]");
  6524. * // alert("F#...G...D...A");
  6525. *
  6526. * # Config:
  6527. *
  6528. * Ext.define('SmartPhone', {
  6529. * config: {
  6530. * hasTouchScreen: false,
  6531. * operatingSystem: 'Other',
  6532. * price: 500
  6533. * },
  6534. *
  6535. * isExpensive: false,
  6536. *
  6537. * constructor: function(config) {
  6538. * this.initConfig(config);
  6539. * },
  6540. *
  6541. * applyPrice: function(price) {
  6542. * this.isExpensive = (price > 500);
  6543. *
  6544. * return price;
  6545. * },
  6546. *
  6547. * applyOperatingSystem: function(operatingSystem) {
  6548. * if (!(/^(iOS|Android|BlackBerry)$/i).test(operatingSystem)) {
  6549. * return 'Other';
  6550. * }
  6551. *
  6552. * return operatingSystem;
  6553. * }
  6554. * });
  6555. *
  6556. * var iPhone = new SmartPhone({
  6557. * hasTouchScreen: true,
  6558. * operatingSystem: 'iOS'
  6559. * });
  6560. *
  6561. * iPhone.getPrice(); // 500;
  6562. * iPhone.getOperatingSystem(); // 'iOS'
  6563. * iPhone.getHasTouchScreen(); // true;
  6564. * iPhone.hasTouchScreen(); // true
  6565. *
  6566. * iPhone.isExpensive; // false;
  6567. * iPhone.setPrice(600);
  6568. * iPhone.getPrice(); // 600
  6569. * iPhone.isExpensive; // true;
  6570. *
  6571. * iPhone.setOperatingSystem('AlienOS');
  6572. * iPhone.getOperatingSystem(); // 'Other'
  6573. *
  6574. * # Statics:
  6575. *
  6576. * Ext.define('Computer', {
  6577. * statics: {
  6578. * factory: function(brand) {
  6579. * // 'this' in static methods refer to the class itself
  6580. * return new this(brand);
  6581. * }
  6582. * },
  6583. *
  6584. * constructor: function() { ... }
  6585. * });
  6586. *
  6587. * var dellComputer = Computer.factory('Dell');
  6588. *
  6589. * Also see {@link Ext.Base#statics} and {@link Ext.Base#self} for more details on accessing
  6590. * static properties within class methods
  6591. *
  6592. * @singleton
  6593. */
  6594. (function(Class, alias, arraySlice, arrayFrom, global) {
  6595. // Creates a constructor that has nothing extra in its scope chain.
  6596. function makeCtor () {
  6597. function constructor () {
  6598. // Opera has some problems returning from a constructor when Dragonfly isn't running. The || null seems to
  6599. // be sufficient to stop it misbehaving. Known to be required against 10.53, 11.51 and 11.61.
  6600. return this.constructor.apply(this, arguments) || null;
  6601. }
  6602. return constructor;
  6603. }
  6604. var Manager = Ext.ClassManager = {
  6605. /**
  6606. * @property {Object} classes
  6607. * All classes which were defined through the ClassManager. Keys are the
  6608. * name of the classes and the values are references to the classes.
  6609. * @private
  6610. */
  6611. classes: {},
  6612. /**
  6613. * @private
  6614. */
  6615. existCache: {},
  6616. /**
  6617. * @private
  6618. */
  6619. namespaceRewrites: [{
  6620. from: 'Ext.',
  6621. to: Ext
  6622. }],
  6623. /**
  6624. * @private
  6625. */
  6626. maps: {
  6627. alternateToName: {},
  6628. aliasToName: {},
  6629. nameToAliases: {},
  6630. nameToAlternates: {}
  6631. },
  6632. /** @private */
  6633. enableNamespaceParseCache: true,
  6634. /** @private */
  6635. namespaceParseCache: {},
  6636. /** @private */
  6637. instantiators: [],
  6638. /**
  6639. * Checks if a class has already been created.
  6640. *
  6641. * @param {String} className
  6642. * @return {Boolean} exist
  6643. */
  6644. isCreated: function(className) {
  6645. var existCache = this.existCache,
  6646. i, ln, part, root, parts;
  6647. //<debug error>
  6648. if (typeof className != 'string' || className.length < 1) {
  6649. throw new Error("[Ext.ClassManager] Invalid classname, must be a string and must not be empty");
  6650. }
  6651. //</debug>
  6652. if (this.classes[className] || existCache[className]) {
  6653. return true;
  6654. }
  6655. root = global;
  6656. parts = this.parseNamespace(className);
  6657. for (i = 0, ln = parts.length; i < ln; i++) {
  6658. part = parts[i];
  6659. if (typeof part != 'string') {
  6660. root = part;
  6661. } else {
  6662. if (!root || !root[part]) {
  6663. return false;
  6664. }
  6665. root = root[part];
  6666. }
  6667. }
  6668. existCache[className] = true;
  6669. this.triggerCreated(className);
  6670. return true;
  6671. },
  6672. /**
  6673. * @private
  6674. */
  6675. createdListeners: [],
  6676. /**
  6677. * @private
  6678. */
  6679. nameCreatedListeners: {},
  6680. /**
  6681. * @private
  6682. */
  6683. triggerCreated: function(className) {
  6684. var listeners = this.createdListeners,
  6685. nameListeners = this.nameCreatedListeners,
  6686. alternateNames = this.maps.nameToAlternates[className],
  6687. names = [className],
  6688. i, ln, j, subLn, listener, name;
  6689. for (i = 0,ln = listeners.length; i < ln; i++) {
  6690. listener = listeners[i];
  6691. listener.fn.call(listener.scope, className);
  6692. }
  6693. if (alternateNames) {
  6694. names.push.apply(names, alternateNames);
  6695. }
  6696. for (i = 0,ln = names.length; i < ln; i++) {
  6697. name = names[i];
  6698. listeners = nameListeners[name];
  6699. if (listeners) {
  6700. for (j = 0,subLn = listeners.length; j < subLn; j++) {
  6701. listener = listeners[j];
  6702. listener.fn.call(listener.scope, name);
  6703. }
  6704. delete nameListeners[name];
  6705. }
  6706. }
  6707. },
  6708. /**
  6709. * @private
  6710. */
  6711. onCreated: function(fn, scope, className) {
  6712. var listeners = this.createdListeners,
  6713. nameListeners = this.nameCreatedListeners,
  6714. listener = {
  6715. fn: fn,
  6716. scope: scope
  6717. };
  6718. if (className) {
  6719. if (this.isCreated(className)) {
  6720. fn.call(scope, className);
  6721. return;
  6722. }
  6723. if (!nameListeners[className]) {
  6724. nameListeners[className] = [];
  6725. }
  6726. nameListeners[className].push(listener);
  6727. }
  6728. else {
  6729. listeners.push(listener);
  6730. }
  6731. },
  6732. /**
  6733. * Supports namespace rewriting
  6734. * @private
  6735. */
  6736. parseNamespace: function(namespace) {
  6737. //<debug error>
  6738. if (typeof namespace != 'string') {
  6739. throw new Error("[Ext.ClassManager] Invalid namespace, must be a string");
  6740. }
  6741. //</debug>
  6742. var cache = this.namespaceParseCache,
  6743. parts,
  6744. rewrites,
  6745. root,
  6746. name,
  6747. rewrite, from, to, i, ln;
  6748. if (this.enableNamespaceParseCache) {
  6749. if (cache.hasOwnProperty(namespace)) {
  6750. return cache[namespace];
  6751. }
  6752. }
  6753. parts = [];
  6754. rewrites = this.namespaceRewrites;
  6755. root = global;
  6756. name = namespace;
  6757. for (i = 0, ln = rewrites.length; i < ln; i++) {
  6758. rewrite = rewrites[i];
  6759. from = rewrite.from;
  6760. to = rewrite.to;
  6761. if (name === from || name.substring(0, from.length) === from) {
  6762. name = name.substring(from.length);
  6763. if (typeof to != 'string') {
  6764. root = to;
  6765. } else {
  6766. parts = parts.concat(to.split('.'));
  6767. }
  6768. break;
  6769. }
  6770. }
  6771. parts.push(root);
  6772. parts = parts.concat(name.split('.'));
  6773. if (this.enableNamespaceParseCache) {
  6774. cache[namespace] = parts;
  6775. }
  6776. return parts;
  6777. },
  6778. /**
  6779. * Creates a namespace and assign the `value` to the created object
  6780. *
  6781. * Ext.ClassManager.setNamespace('MyCompany.pkg.Example', someObject);
  6782. *
  6783. * alert(MyCompany.pkg.Example === someObject); // alerts true
  6784. *
  6785. * @param {String} name
  6786. * @param {Object} value
  6787. */
  6788. setNamespace: function(name, value) {
  6789. var root = global,
  6790. parts = this.parseNamespace(name),
  6791. ln = parts.length - 1,
  6792. leaf = parts[ln],
  6793. i, part;
  6794. for (i = 0; i < ln; i++) {
  6795. part = parts[i];
  6796. if (typeof part != 'string') {
  6797. root = part;
  6798. } else {
  6799. if (!root[part]) {
  6800. root[part] = {};
  6801. }
  6802. root = root[part];
  6803. }
  6804. }
  6805. root[leaf] = value;
  6806. return root[leaf];
  6807. },
  6808. /**
  6809. * The new Ext.ns, supports namespace rewriting
  6810. * @private
  6811. */
  6812. createNamespaces: function() {
  6813. var root = global,
  6814. parts, part, i, j, ln, subLn;
  6815. for (i = 0, ln = arguments.length; i < ln; i++) {
  6816. parts = this.parseNamespace(arguments[i]);
  6817. for (j = 0, subLn = parts.length; j < subLn; j++) {
  6818. part = parts[j];
  6819. if (typeof part != 'string') {
  6820. root = part;
  6821. } else {
  6822. if (!root[part]) {
  6823. root[part] = {};
  6824. }
  6825. root = root[part];
  6826. }
  6827. }
  6828. }
  6829. return root;
  6830. },
  6831. /**
  6832. * Sets a name reference to a class.
  6833. *
  6834. * @param {String} name
  6835. * @param {Object} value
  6836. * @return {Ext.ClassManager} this
  6837. */
  6838. set: function(name, value) {
  6839. var me = this,
  6840. maps = me.maps,
  6841. nameToAlternates = maps.nameToAlternates,
  6842. targetName = me.getName(value),
  6843. alternates;
  6844. me.classes[name] = me.setNamespace(name, value);
  6845. if (targetName && targetName !== name) {
  6846. maps.alternateToName[name] = targetName;
  6847. alternates = nameToAlternates[targetName] || (nameToAlternates[targetName] = []);
  6848. alternates.push(name);
  6849. }
  6850. return this;
  6851. },
  6852. /**
  6853. * Retrieve a class by its name.
  6854. *
  6855. * @param {String} name
  6856. * @return {Ext.Class} class
  6857. */
  6858. get: function(name) {
  6859. var classes = this.classes,
  6860. root,
  6861. parts,
  6862. part, i, ln;
  6863. if (classes[name]) {
  6864. return classes[name];
  6865. }
  6866. root = global;
  6867. parts = this.parseNamespace(name);
  6868. for (i = 0, ln = parts.length; i < ln; i++) {
  6869. part = parts[i];
  6870. if (typeof part != 'string') {
  6871. root = part;
  6872. } else {
  6873. if (!root || !root[part]) {
  6874. return null;
  6875. }
  6876. root = root[part];
  6877. }
  6878. }
  6879. return root;
  6880. },
  6881. /**
  6882. * Register the alias for a class.
  6883. *
  6884. * @param {Ext.Class/String} cls a reference to a class or a className
  6885. * @param {String} alias Alias to use when referring to this class
  6886. */
  6887. setAlias: function(cls, alias) {
  6888. var aliasToNameMap = this.maps.aliasToName,
  6889. nameToAliasesMap = this.maps.nameToAliases,
  6890. className;
  6891. if (typeof cls == 'string') {
  6892. className = cls;
  6893. } else {
  6894. className = this.getName(cls);
  6895. }
  6896. if (alias && aliasToNameMap[alias] !== className) {
  6897. //<debug info>
  6898. if (aliasToNameMap[alias] && Ext.isDefined(global.console)) {
  6899. global.console.log("[Ext.ClassManager] Overriding existing alias: '" + alias + "' " +
  6900. "of: '" + aliasToNameMap[alias] + "' with: '" + className + "'. Be sure it's intentional.");
  6901. }
  6902. //</debug>
  6903. aliasToNameMap[alias] = className;
  6904. }
  6905. if (!nameToAliasesMap[className]) {
  6906. nameToAliasesMap[className] = [];
  6907. }
  6908. if (alias) {
  6909. Ext.Array.include(nameToAliasesMap[className], alias);
  6910. }
  6911. return this;
  6912. },
  6913. /**
  6914. * Get a reference to the class by its alias.
  6915. *
  6916. * @param {String} alias
  6917. * @return {Ext.Class} class
  6918. */
  6919. getByAlias: function(alias) {
  6920. return this.get(this.getNameByAlias(alias));
  6921. },
  6922. /**
  6923. * Get the name of a class by its alias.
  6924. *
  6925. * @param {String} alias
  6926. * @return {String} className
  6927. */
  6928. getNameByAlias: function(alias) {
  6929. return this.maps.aliasToName[alias] || '';
  6930. },
  6931. /**
  6932. * Get the name of a class by its alternate name.
  6933. *
  6934. * @param {String} alternate
  6935. * @return {String} className
  6936. */
  6937. getNameByAlternate: function(alternate) {
  6938. return this.maps.alternateToName[alternate] || '';
  6939. },
  6940. /**
  6941. * Get the aliases of a class by the class name
  6942. *
  6943. * @param {String} name
  6944. * @return {Array} aliases
  6945. */
  6946. getAliasesByName: function(name) {
  6947. return this.maps.nameToAliases[name] || [];
  6948. },
  6949. /**
  6950. * Get the name of the class by its reference or its instance;
  6951. * usually invoked by the shorthand {@link Ext#getClassName Ext.getClassName}
  6952. *
  6953. * Ext.ClassManager.getName(Ext.Action); // returns "Ext.Action"
  6954. *
  6955. * @param {Ext.Class/Object} object
  6956. * @return {String} className
  6957. */
  6958. getName: function(object) {
  6959. return object && object.$className || '';
  6960. },
  6961. /**
  6962. * Get the class of the provided object; returns null if it's not an instance
  6963. * of any class created with Ext.define. This is usually invoked by the shorthand {@link Ext#getClass Ext.getClass}
  6964. *
  6965. * var component = new Ext.Component();
  6966. *
  6967. * Ext.ClassManager.getClass(component); // returns Ext.Component
  6968. *
  6969. * @param {Object} object
  6970. * @return {Ext.Class} class
  6971. */
  6972. getClass: function(object) {
  6973. return object && object.self || null;
  6974. },
  6975. /**
  6976. * Defines a class.
  6977. * @deprecated 4.1.0 Use {@link Ext#define} instead, as that also supports creating overrides.
  6978. */
  6979. create: function(className, data, createdFn) {
  6980. //<debug error>
  6981. if (className != null && typeof className != 'string') {
  6982. throw new Error("[Ext.define] Invalid class name '" + className + "' specified, must be a non-empty string");
  6983. }
  6984. //</debug>
  6985. var ctor = makeCtor();
  6986. if (typeof data == 'function') {
  6987. data = data(ctor);
  6988. }
  6989. //<debug>
  6990. if (className) {
  6991. ctor.displayName = className;
  6992. }
  6993. //</debug>
  6994. data.$className = className;
  6995. return new Class(ctor, data, function() {
  6996. var postprocessorStack = data.postprocessors || Manager.defaultPostprocessors,
  6997. registeredPostprocessors = Manager.postprocessors,
  6998. postprocessors = [],
  6999. postprocessor, i, ln, j, subLn, postprocessorProperties, postprocessorProperty;
  7000. delete data.postprocessors;
  7001. for (i = 0,ln = postprocessorStack.length; i < ln; i++) {
  7002. postprocessor = postprocessorStack[i];
  7003. if (typeof postprocessor == 'string') {
  7004. postprocessor = registeredPostprocessors[postprocessor];
  7005. postprocessorProperties = postprocessor.properties;
  7006. if (postprocessorProperties === true) {
  7007. postprocessors.push(postprocessor.fn);
  7008. }
  7009. else if (postprocessorProperties) {
  7010. for (j = 0,subLn = postprocessorProperties.length; j < subLn; j++) {
  7011. postprocessorProperty = postprocessorProperties[j];
  7012. if (data.hasOwnProperty(postprocessorProperty)) {
  7013. postprocessors.push(postprocessor.fn);
  7014. break;
  7015. }
  7016. }
  7017. }
  7018. }
  7019. else {
  7020. postprocessors.push(postprocessor);
  7021. }
  7022. }
  7023. data.postprocessors = postprocessors;
  7024. data.createdFn = createdFn;
  7025. Manager.processCreate(className, this, data);
  7026. });
  7027. },
  7028. processCreate: function(className, cls, clsData){
  7029. var me = this,
  7030. postprocessor = clsData.postprocessors.shift(),
  7031. createdFn = clsData.createdFn;
  7032. if (!postprocessor) {
  7033. if (className) {
  7034. me.set(className, cls);
  7035. }
  7036. if (createdFn) {
  7037. createdFn.call(cls, cls);
  7038. }
  7039. if (className) {
  7040. me.triggerCreated(className);
  7041. }
  7042. return;
  7043. }
  7044. if (postprocessor.call(me, className, cls, clsData, me.processCreate) !== false) {
  7045. me.processCreate(className, cls, clsData);
  7046. }
  7047. },
  7048. createOverride: function (className, data, createdFn) {
  7049. var me = this,
  7050. overriddenClassName = data.override,
  7051. requires = data.requires,
  7052. uses = data.uses,
  7053. classReady = function () {
  7054. var cls, temp;
  7055. if (requires) {
  7056. temp = requires;
  7057. requires = null; // do the real thing next time (which may be now)
  7058. // Since the override is going to be used (its target class is now
  7059. // created), we need to fetch the required classes for the override
  7060. // and call us back once they are loaded:
  7061. Ext.Loader.require(temp, classReady);
  7062. } else {
  7063. // The target class and the required classes for this override are
  7064. // ready, so we can apply the override now:
  7065. cls = me.get(overriddenClassName);
  7066. // We don't want to apply these:
  7067. delete data.override;
  7068. delete data.requires;
  7069. delete data.uses;
  7070. Ext.override(cls, data);
  7071. // This pushes the overridding file itself into Ext.Loader.history
  7072. // Hence if the target class never exists, the overriding file will
  7073. // never be included in the build.
  7074. me.triggerCreated(className);
  7075. if (uses) {
  7076. Ext.Loader.addUsedClasses(uses); // get these classes too!
  7077. }
  7078. if (createdFn) {
  7079. createdFn.call(cls); // last but not least!
  7080. }
  7081. }
  7082. };
  7083. me.existCache[className] = true;
  7084. // Override the target class right after it's created
  7085. me.onCreated(classReady, me, overriddenClassName);
  7086. return me;
  7087. },
  7088. /**
  7089. * Instantiate a class by its alias; usually invoked by the convenient shorthand {@link Ext#createByAlias Ext.createByAlias}
  7090. * If {@link Ext.Loader} is {@link Ext.Loader#setConfig enabled} and the class has not been defined yet, it will
  7091. * attempt to load the class via synchronous loading.
  7092. *
  7093. * var window = Ext.ClassManager.instantiateByAlias('widget.window', { width: 600, height: 800, ... });
  7094. *
  7095. * @param {String} alias
  7096. * @param {Object...} args Additional arguments after the alias will be passed to the
  7097. * class constructor.
  7098. * @return {Object} instance
  7099. */
  7100. instantiateByAlias: function() {
  7101. var alias = arguments[0],
  7102. args = arraySlice.call(arguments),
  7103. className = this.getNameByAlias(alias);
  7104. if (!className) {
  7105. className = this.maps.aliasToName[alias];
  7106. //<debug error>
  7107. if (!className) {
  7108. throw new Error("[Ext.createByAlias] Cannot create an instance of unrecognized alias: " + alias);
  7109. }
  7110. //</debug>
  7111. //<debug warn>
  7112. if (global.console) {
  7113. global.console.warn("[Ext.Loader] Synchronously loading '" + className + "'; consider adding " +
  7114. "Ext.require('" + alias + "') above Ext.onReady");
  7115. }
  7116. //</debug>
  7117. Ext.syncRequire(className);
  7118. }
  7119. args[0] = className;
  7120. return this.instantiate.apply(this, args);
  7121. },
  7122. /**
  7123. * @private
  7124. */
  7125. instantiate: function() {
  7126. var name = arguments[0],
  7127. nameType = typeof name,
  7128. args = arraySlice.call(arguments, 1),
  7129. alias = name,
  7130. possibleName, cls;
  7131. if (nameType != 'function') {
  7132. if (nameType != 'string' && args.length === 0) {
  7133. args = [name];
  7134. name = name.xclass;
  7135. }
  7136. //<debug error>
  7137. if (typeof name != 'string' || name.length < 1) {
  7138. throw new Error("[Ext.create] Invalid class name or alias '" + name + "' specified, must be a non-empty string");
  7139. }
  7140. //</debug>
  7141. cls = this.get(name);
  7142. }
  7143. else {
  7144. cls = name;
  7145. }
  7146. // No record of this class name, it's possibly an alias, so look it up
  7147. if (!cls) {
  7148. possibleName = this.getNameByAlias(name);
  7149. if (possibleName) {
  7150. name = possibleName;
  7151. cls = this.get(name);
  7152. }
  7153. }
  7154. // Still no record of this class name, it's possibly an alternate name, so look it up
  7155. if (!cls) {
  7156. possibleName = this.getNameByAlternate(name);
  7157. if (possibleName) {
  7158. name = possibleName;
  7159. cls = this.get(name);
  7160. }
  7161. }
  7162. // Still not existing at this point, try to load it via synchronous mode as the last resort
  7163. if (!cls) {
  7164. //<debug warn>
  7165. if (global.console) {
  7166. global.console.warn("[Ext.Loader] Synchronously loading '" + name + "'; consider adding " +
  7167. "Ext.require('" + ((possibleName) ? alias : name) + "') above Ext.onReady");
  7168. }
  7169. //</debug>
  7170. Ext.syncRequire(name);
  7171. cls = this.get(name);
  7172. }
  7173. //<debug error>
  7174. if (!cls) {
  7175. throw new Error("[Ext.create] Cannot create an instance of unrecognized class name / alias: " + alias);
  7176. }
  7177. if (typeof cls != 'function') {
  7178. throw new Error("[Ext.create] '" + name + "' is a singleton and cannot be instantiated");
  7179. }
  7180. //</debug>
  7181. return this.getInstantiator(args.length)(cls, args);
  7182. },
  7183. /**
  7184. * @private
  7185. * @param name
  7186. * @param args
  7187. */
  7188. dynInstantiate: function(name, args) {
  7189. args = arrayFrom(args, true);
  7190. args.unshift(name);
  7191. return this.instantiate.apply(this, args);
  7192. },
  7193. /**
  7194. * @private
  7195. * @param length
  7196. */
  7197. getInstantiator: function(length) {
  7198. var instantiators = this.instantiators,
  7199. instantiator,
  7200. i,
  7201. args;
  7202. instantiator = instantiators[length];
  7203. if (!instantiator) {
  7204. i = length;
  7205. args = [];
  7206. for (i = 0; i < length; i++) {
  7207. args.push('a[' + i + ']');
  7208. }
  7209. instantiator = instantiators[length] = new Function('c', 'a', 'return new c(' + args.join(',') + ')');
  7210. //<debug>
  7211. instantiator.displayName = "Ext.ClassManager.instantiate" + length;
  7212. //</debug>
  7213. }
  7214. return instantiator;
  7215. },
  7216. /**
  7217. * @private
  7218. */
  7219. postprocessors: {},
  7220. /**
  7221. * @private
  7222. */
  7223. defaultPostprocessors: [],
  7224. /**
  7225. * Register a post-processor function.
  7226. *
  7227. * @private
  7228. * @param {String} name
  7229. * @param {Function} postprocessor
  7230. */
  7231. registerPostprocessor: function(name, fn, properties, position, relativeTo) {
  7232. if (!position) {
  7233. position = 'last';
  7234. }
  7235. if (!properties) {
  7236. properties = [name];
  7237. }
  7238. this.postprocessors[name] = {
  7239. name: name,
  7240. properties: properties || false,
  7241. fn: fn
  7242. };
  7243. this.setDefaultPostprocessorPosition(name, position, relativeTo);
  7244. return this;
  7245. },
  7246. /**
  7247. * Set the default post processors array stack which are applied to every class.
  7248. *
  7249. * @private
  7250. * @param {String/Array} The name of a registered post processor or an array of registered names.
  7251. * @return {Ext.ClassManager} this
  7252. */
  7253. setDefaultPostprocessors: function(postprocessors) {
  7254. this.defaultPostprocessors = arrayFrom(postprocessors);
  7255. return this;
  7256. },
  7257. /**
  7258. * Insert this post-processor at a specific position in the stack, optionally relative to
  7259. * any existing post-processor
  7260. *
  7261. * @private
  7262. * @param {String} name The post-processor name. Note that it needs to be registered with
  7263. * {@link Ext.ClassManager#registerPostprocessor} before this
  7264. * @param {String} offset The insertion position. Four possible values are:
  7265. * 'first', 'last', or: 'before', 'after' (relative to the name provided in the third argument)
  7266. * @param {String} relativeName
  7267. * @return {Ext.ClassManager} this
  7268. */
  7269. setDefaultPostprocessorPosition: function(name, offset, relativeName) {
  7270. var defaultPostprocessors = this.defaultPostprocessors,
  7271. index;
  7272. if (typeof offset == 'string') {
  7273. if (offset === 'first') {
  7274. defaultPostprocessors.unshift(name);
  7275. return this;
  7276. }
  7277. else if (offset === 'last') {
  7278. defaultPostprocessors.push(name);
  7279. return this;
  7280. }
  7281. offset = (offset === 'after') ? 1 : -1;
  7282. }
  7283. index = Ext.Array.indexOf(defaultPostprocessors, relativeName);
  7284. if (index !== -1) {
  7285. Ext.Array.splice(defaultPostprocessors, Math.max(0, index + offset), 0, name);
  7286. }
  7287. return this;
  7288. },
  7289. /**
  7290. * Converts a string expression to an array of matching class names. An expression can either refers to class aliases
  7291. * or class names. Expressions support wildcards:
  7292. *
  7293. * // returns ['Ext.window.Window']
  7294. * var window = Ext.ClassManager.getNamesByExpression('widget.window');
  7295. *
  7296. * // returns ['widget.panel', 'widget.window', ...]
  7297. * var allWidgets = Ext.ClassManager.getNamesByExpression('widget.*');
  7298. *
  7299. * // returns ['Ext.data.Store', 'Ext.data.ArrayProxy', ...]
  7300. * var allData = Ext.ClassManager.getNamesByExpression('Ext.data.*');
  7301. *
  7302. * @param {String} expression
  7303. * @return {String[]} classNames
  7304. */
  7305. getNamesByExpression: function(expression) {
  7306. var nameToAliasesMap = this.maps.nameToAliases,
  7307. names = [],
  7308. name, alias, aliases, possibleName, regex, i, ln;
  7309. //<debug error>
  7310. if (typeof expression != 'string' || expression.length < 1) {
  7311. throw new Error("[Ext.ClassManager.getNamesByExpression] Expression " + expression + " is invalid, must be a non-empty string");
  7312. }
  7313. //</debug>
  7314. if (expression.indexOf('*') !== -1) {
  7315. expression = expression.replace(/\*/g, '(.*?)');
  7316. regex = new RegExp('^' + expression + '$');
  7317. for (name in nameToAliasesMap) {
  7318. if (nameToAliasesMap.hasOwnProperty(name)) {
  7319. aliases = nameToAliasesMap[name];
  7320. if (name.search(regex) !== -1) {
  7321. names.push(name);
  7322. }
  7323. else {
  7324. for (i = 0, ln = aliases.length; i < ln; i++) {
  7325. alias = aliases[i];
  7326. if (alias.search(regex) !== -1) {
  7327. names.push(name);
  7328. break;
  7329. }
  7330. }
  7331. }
  7332. }
  7333. }
  7334. } else {
  7335. possibleName = this.getNameByAlias(expression);
  7336. if (possibleName) {
  7337. names.push(possibleName);
  7338. } else {
  7339. possibleName = this.getNameByAlternate(expression);
  7340. if (possibleName) {
  7341. names.push(possibleName);
  7342. } else {
  7343. names.push(expression);
  7344. }
  7345. }
  7346. }
  7347. return names;
  7348. }
  7349. };
  7350. //<feature classSystem.alias>
  7351. /**
  7352. * @cfg {String[]} alias
  7353. * @member Ext.Class
  7354. * List of short aliases for class names. Most useful for defining xtypes for widgets:
  7355. *
  7356. * Ext.define('MyApp.CoolPanel', {
  7357. * extend: 'Ext.panel.Panel',
  7358. * alias: ['widget.coolpanel'],
  7359. * title: 'Yeah!'
  7360. * });
  7361. *
  7362. * // Using Ext.create
  7363. * Ext.create('widget.coolpanel');
  7364. *
  7365. * // Using the shorthand for defining widgets by xtype
  7366. * Ext.widget('panel', {
  7367. * items: [
  7368. * {xtype: 'coolpanel', html: 'Foo'},
  7369. * {xtype: 'coolpanel', html: 'Bar'}
  7370. * ]
  7371. * });
  7372. *
  7373. * Besides "widget" for xtype there are alias namespaces like "feature" for ftype and "plugin" for ptype.
  7374. */
  7375. Manager.registerPostprocessor('alias', function(name, cls, data) {
  7376. var aliases = data.alias,
  7377. i, ln;
  7378. for (i = 0,ln = aliases.length; i < ln; i++) {
  7379. alias = aliases[i];
  7380. this.setAlias(cls, alias);
  7381. }
  7382. }, ['xtype', 'alias']);
  7383. //</feature>
  7384. //<feature classSystem.singleton>
  7385. /**
  7386. * @cfg {Boolean} singleton
  7387. * @member Ext.Class
  7388. * When set to true, the class will be instantiated as singleton. For example:
  7389. *
  7390. * Ext.define('Logger', {
  7391. * singleton: true,
  7392. * log: function(msg) {
  7393. * console.log(msg);
  7394. * }
  7395. * });
  7396. *
  7397. * Logger.log('Hello');
  7398. */
  7399. Manager.registerPostprocessor('singleton', function(name, cls, data, fn) {
  7400. fn.call(this, name, new cls(), data);
  7401. return false;
  7402. });
  7403. //</feature>
  7404. //<feature classSystem.alternateClassName>
  7405. /**
  7406. * @cfg {String/String[]} alternateClassName
  7407. * @member Ext.Class
  7408. * Defines alternate names for this class. For example:
  7409. *
  7410. * Ext.define('Developer', {
  7411. * alternateClassName: ['Coder', 'Hacker'],
  7412. * code: function(msg) {
  7413. * alert('Typing... ' + msg);
  7414. * }
  7415. * });
  7416. *
  7417. * var joe = Ext.create('Developer');
  7418. * joe.code('stackoverflow');
  7419. *
  7420. * var rms = Ext.create('Hacker');
  7421. * rms.code('hack hack');
  7422. */
  7423. Manager.registerPostprocessor('alternateClassName', function(name, cls, data) {
  7424. var alternates = data.alternateClassName,
  7425. i, ln, alternate;
  7426. if (!(alternates instanceof Array)) {
  7427. alternates = [alternates];
  7428. }
  7429. for (i = 0, ln = alternates.length; i < ln; i++) {
  7430. alternate = alternates[i];
  7431. //<debug error>
  7432. if (typeof alternate != 'string') {
  7433. throw new Error("[Ext.define] Invalid alternate of: '" + alternate + "' for class: '" + name + "'; must be a valid string");
  7434. }
  7435. //</debug>
  7436. this.set(alternate, cls);
  7437. }
  7438. });
  7439. //</feature>
  7440. Ext.apply(Ext, {
  7441. /**
  7442. * Instantiate a class by either full name, alias or alternate name.
  7443. *
  7444. * If {@link Ext.Loader} is {@link Ext.Loader#setConfig enabled} and the class has
  7445. * not been defined yet, it will attempt to load the class via synchronous loading.
  7446. *
  7447. * For example, all these three lines return the same result:
  7448. *
  7449. * // alias
  7450. * var window = Ext.create('widget.window', {
  7451. * width: 600,
  7452. * height: 800,
  7453. * ...
  7454. * });
  7455. *
  7456. * // alternate name
  7457. * var window = Ext.create('Ext.Window', {
  7458. * width: 600,
  7459. * height: 800,
  7460. * ...
  7461. * });
  7462. *
  7463. * // full class name
  7464. * var window = Ext.create('Ext.window.Window', {
  7465. * width: 600,
  7466. * height: 800,
  7467. * ...
  7468. * });
  7469. *
  7470. * // single object with xclass property:
  7471. * var window = Ext.create({
  7472. * xclass: 'Ext.window.Window', // any valid value for 'name' (above)
  7473. * width: 600,
  7474. * height: 800,
  7475. * ...
  7476. * });
  7477. *
  7478. * @param {String} [name] The class name or alias. Can be specified as `xclass`
  7479. * property if only one object parameter is specified.
  7480. * @param {Object...} [args] Additional arguments after the name will be passed to
  7481. * the class' constructor.
  7482. * @return {Object} instance
  7483. * @member Ext
  7484. * @method create
  7485. */
  7486. create: alias(Manager, 'instantiate'),
  7487. /**
  7488. * Convenient shorthand to create a widget by its xtype or a config object.
  7489. * See also {@link Ext.ClassManager#instantiateByAlias}.
  7490. *
  7491. * var button = Ext.widget('button'); // Equivalent to Ext.create('widget.button');
  7492. *
  7493. * var panel = Ext.widget('panel', { // Equivalent to Ext.create('widget.panel')
  7494. * title: 'Panel'
  7495. * });
  7496. *
  7497. * var grid = Ext.widget({
  7498. * xtype: 'grid',
  7499. * ...
  7500. * });
  7501. *
  7502. * If a {@link Ext.Component component} instance is passed, it is simply returned.
  7503. *
  7504. * @member Ext
  7505. * @param {String} [name] The xtype of the widget to create.
  7506. * @param {Object} [config] The configuration object for the widget constructor.
  7507. * @return {Object} The widget instance
  7508. */
  7509. widget: function(name, config) {
  7510. // forms:
  7511. // 1: (xtype)
  7512. // 2: (xtype, config)
  7513. // 3: (config)
  7514. // 4: (xtype, component)
  7515. // 5: (component)
  7516. //
  7517. var xtype = name,
  7518. alias, className, T, load;
  7519. if (typeof xtype != 'string') { // if (form 3 or 5)
  7520. // first arg is config or component
  7521. config = name; // arguments[0]
  7522. xtype = config.xtype;
  7523. } else {
  7524. config = config || {};
  7525. }
  7526. if (config.isComponent) {
  7527. return config;
  7528. }
  7529. alias = 'widget.' + xtype;
  7530. className = Manager.getNameByAlias(alias);
  7531. // this is needed to support demand loading of the class
  7532. if (!className) {
  7533. load = true;
  7534. }
  7535. T = Manager.get(className);
  7536. if (load || !T) {
  7537. return Manager.instantiateByAlias(alias, config);
  7538. }
  7539. return new T(config);
  7540. },
  7541. /**
  7542. * Convenient shorthand, see {@link Ext.ClassManager#instantiateByAlias}
  7543. * @member Ext
  7544. * @method createByAlias
  7545. */
  7546. createByAlias: alias(Manager, 'instantiateByAlias'),
  7547. /**
  7548. * @method
  7549. * Defines a class or override. A basic class is defined like this:
  7550. *
  7551. * Ext.define('My.awesome.Class', {
  7552. * someProperty: 'something',
  7553. *
  7554. * someMethod: function(s) {
  7555. * alert(s + this.someProperty);
  7556. * }
  7557. *
  7558. * ...
  7559. * });
  7560. *
  7561. * var obj = new My.awesome.Class();
  7562. *
  7563. * obj.someMethod('Say '); // alerts 'Say something'
  7564. *
  7565. * To create an anonymous class, pass `null` for the `className`:
  7566. *
  7567. * Ext.define(null, {
  7568. * constructor: function () {
  7569. * // ...
  7570. * }
  7571. * });
  7572. *
  7573. * In some cases, it is helpful to create a nested scope to contain some private
  7574. * properties. The best way to do this is to pass a function instead of an object
  7575. * as the second parameter. This function will be called to produce the class
  7576. * body:
  7577. *
  7578. * Ext.define('MyApp.foo.Bar', function () {
  7579. * var id = 0;
  7580. *
  7581. * return {
  7582. * nextId: function () {
  7583. * return ++id;
  7584. * }
  7585. * };
  7586. * });
  7587. *
  7588. * When using this form of `Ext.define`, the function is passed a reference to its
  7589. * class. This can be used as an efficient way to access any static properties you
  7590. * may have:
  7591. *
  7592. * Ext.define('MyApp.foo.Bar', function (Bar) {
  7593. * return {
  7594. * statics: {
  7595. * staticMethod: function () {
  7596. * // ...
  7597. * }
  7598. * },
  7599. *
  7600. * method: function () {
  7601. * return Bar.staticMethod();
  7602. * }
  7603. * };
  7604. * });
  7605. *
  7606. * To define an override, include the `override` property. The content of an
  7607. * override is aggregated with the specified class in order to extend or modify
  7608. * that class. This can be as simple as setting default property values or it can
  7609. * extend and/or replace methods. This can also extend the statics of the class.
  7610. *
  7611. * One use for an override is to break a large class into manageable pieces.
  7612. *
  7613. * // File: /src/app/Panel.js
  7614. *
  7615. * Ext.define('My.app.Panel', {
  7616. * extend: 'Ext.panel.Panel',
  7617. * requires: [
  7618. * 'My.app.PanelPart2',
  7619. * 'My.app.PanelPart3'
  7620. * ]
  7621. *
  7622. * constructor: function (config) {
  7623. * this.callParent(arguments); // calls Ext.panel.Panel's constructor
  7624. * //...
  7625. * },
  7626. *
  7627. * statics: {
  7628. * method: function () {
  7629. * return 'abc';
  7630. * }
  7631. * }
  7632. * });
  7633. *
  7634. * // File: /src/app/PanelPart2.js
  7635. * Ext.define('My.app.PanelPart2', {
  7636. * override: 'My.app.Panel',
  7637. *
  7638. * constructor: function (config) {
  7639. * this.callParent(arguments); // calls My.app.Panel's constructor
  7640. * //...
  7641. * }
  7642. * });
  7643. *
  7644. * Another use of overrides is to provide optional parts of classes that can be
  7645. * independently required. In this case, the class may even be unaware of the
  7646. * override altogether.
  7647. *
  7648. * Ext.define('My.ux.CoolTip', {
  7649. * override: 'Ext.tip.ToolTip',
  7650. *
  7651. * constructor: function (config) {
  7652. * this.callParent(arguments); // calls Ext.tip.ToolTip's constructor
  7653. * //...
  7654. * }
  7655. * });
  7656. *
  7657. * The above override can now be required as normal.
  7658. *
  7659. * Ext.define('My.app.App', {
  7660. * requires: [
  7661. * 'My.ux.CoolTip'
  7662. * ]
  7663. * });
  7664. *
  7665. * Overrides can also contain statics:
  7666. *
  7667. * Ext.define('My.app.BarMod', {
  7668. * override: 'Ext.foo.Bar',
  7669. *
  7670. * statics: {
  7671. * method: function (x) {
  7672. * return this.callParent([x * 2]); // call Ext.foo.Bar.method
  7673. * }
  7674. * }
  7675. * });
  7676. *
  7677. * IMPORTANT: An override is only included in a build if the class it overrides is
  7678. * required. Otherwise, the override, like the target class, is not included.
  7679. *
  7680. * @param {String} className The class name to create in string dot-namespaced format, for example:
  7681. * 'My.very.awesome.Class', 'FeedViewer.plugin.CoolPager'
  7682. * It is highly recommended to follow this simple convention:
  7683. * - The root and the class name are 'CamelCased'
  7684. * - Everything else is lower-cased
  7685. * Pass `null` to create an anonymous class.
  7686. * @param {Object} data The key - value pairs of properties to apply to this class. Property names can be of any valid
  7687. * strings, except those in the reserved listed below:
  7688. * - `mixins`
  7689. * - `statics`
  7690. * - `config`
  7691. * - `alias`
  7692. * - `self`
  7693. * - `singleton`
  7694. * - `alternateClassName`
  7695. * - `override`
  7696. *
  7697. * @param {Function} createdFn Optional callback to execute after the class is created, the execution scope of which
  7698. * (`this`) will be the newly created class itself.
  7699. * @return {Ext.Base}
  7700. * @markdown
  7701. * @member Ext
  7702. * @method define
  7703. */
  7704. define: function (className, data, createdFn) {
  7705. if (data.override) {
  7706. return Manager.createOverride.apply(Manager, arguments);
  7707. }
  7708. return Manager.create.apply(Manager, arguments);
  7709. },
  7710. /**
  7711. * Convenient shorthand, see {@link Ext.ClassManager#getName}
  7712. * @member Ext
  7713. * @method getClassName
  7714. */
  7715. getClassName: alias(Manager, 'getName'),
  7716. /**
  7717. * Returns the displayName property or className or object. When all else fails, returns "Anonymous".
  7718. * @param {Object} object
  7719. * @return {String}
  7720. */
  7721. getDisplayName: function(object) {
  7722. if (object) {
  7723. if (object.displayName) {
  7724. return object.displayName;
  7725. }
  7726. if (object.$name && object.$class) {
  7727. return Ext.getClassName(object.$class) + '#' + object.$name;
  7728. }
  7729. if (object.$className) {
  7730. return object.$className;
  7731. }
  7732. }
  7733. return 'Anonymous';
  7734. },
  7735. /**
  7736. * Convenient shorthand, see {@link Ext.ClassManager#getClass}
  7737. * @member Ext
  7738. * @method getClass
  7739. */
  7740. getClass: alias(Manager, 'getClass'),
  7741. /**
  7742. * Creates namespaces to be used for scoping variables and classes so that they are not global.
  7743. * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
  7744. *
  7745. * Ext.namespace('Company', 'Company.data');
  7746. *
  7747. * // equivalent and preferable to the above syntax
  7748. * Ext.ns('Company.data');
  7749. *
  7750. * Company.Widget = function() { ... };
  7751. *
  7752. * Company.data.CustomStore = function(config) { ... };
  7753. *
  7754. * @param {String...} namespaces
  7755. * @return {Object} The namespace object.
  7756. * (If multiple arguments are passed, this will be the last namespace created)
  7757. * @member Ext
  7758. * @method namespace
  7759. */
  7760. namespace: alias(Manager, 'createNamespaces')
  7761. });
  7762. /**
  7763. * Old name for {@link Ext#widget}.
  7764. * @deprecated 4.0.0 Use {@link Ext#widget} instead.
  7765. * @method createWidget
  7766. * @member Ext
  7767. */
  7768. Ext.createWidget = Ext.widget;
  7769. /**
  7770. * Convenient alias for {@link Ext#namespace Ext.namespace}.
  7771. * @inheritdoc Ext#namespace
  7772. * @member Ext
  7773. * @method ns
  7774. */
  7775. Ext.ns = Ext.namespace;
  7776. Class.registerPreprocessor('className', function(cls, data) {
  7777. if (data.$className) {
  7778. cls.$className = data.$className;
  7779. //<debug>
  7780. cls.displayName = cls.$className;
  7781. //</debug>
  7782. }
  7783. }, true, 'first');
  7784. Class.registerPreprocessor('alias', function(cls, data) {
  7785. var prototype = cls.prototype,
  7786. xtypes = arrayFrom(data.xtype),
  7787. aliases = arrayFrom(data.alias),
  7788. widgetPrefix = 'widget.',
  7789. widgetPrefixLength = widgetPrefix.length,
  7790. xtypesChain = Array.prototype.slice.call(prototype.xtypesChain || []),
  7791. xtypesMap = Ext.merge({}, prototype.xtypesMap || {}),
  7792. i, ln, alias, xtype;
  7793. for (i = 0,ln = aliases.length; i < ln; i++) {
  7794. alias = aliases[i];
  7795. //<debug error>
  7796. if (typeof alias != 'string' || alias.length < 1) {
  7797. throw new Error("[Ext.define] Invalid alias of: '" + alias + "' for class: '" + name + "'; must be a valid string");
  7798. }
  7799. //</debug>
  7800. if (alias.substring(0, widgetPrefixLength) === widgetPrefix) {
  7801. xtype = alias.substring(widgetPrefixLength);
  7802. Ext.Array.include(xtypes, xtype);
  7803. }
  7804. }
  7805. cls.xtype = data.xtype = xtypes[0];
  7806. data.xtypes = xtypes;
  7807. for (i = 0,ln = xtypes.length; i < ln; i++) {
  7808. xtype = xtypes[i];
  7809. if (!xtypesMap[xtype]) {
  7810. xtypesMap[xtype] = true;
  7811. xtypesChain.push(xtype);
  7812. }
  7813. }
  7814. data.xtypesChain = xtypesChain;
  7815. data.xtypesMap = xtypesMap;
  7816. Ext.Function.interceptAfter(data, 'onClassCreated', function() {
  7817. var mixins = prototype.mixins,
  7818. key, mixin;
  7819. for (key in mixins) {
  7820. if (mixins.hasOwnProperty(key)) {
  7821. mixin = mixins[key];
  7822. xtypes = mixin.xtypes;
  7823. if (xtypes) {
  7824. for (i = 0,ln = xtypes.length; i < ln; i++) {
  7825. xtype = xtypes[i];
  7826. if (!xtypesMap[xtype]) {
  7827. xtypesMap[xtype] = true;
  7828. xtypesChain.push(xtype);
  7829. }
  7830. }
  7831. }
  7832. }
  7833. }
  7834. });
  7835. for (i = 0,ln = xtypes.length; i < ln; i++) {
  7836. xtype = xtypes[i];
  7837. //<debug error>
  7838. if (typeof xtype != 'string' || xtype.length < 1) {
  7839. throw new Error("[Ext.define] Invalid xtype of: '" + xtype + "' for class: '" + name + "'; must be a valid non-empty string");
  7840. }
  7841. //</debug>
  7842. Ext.Array.include(aliases, widgetPrefix + xtype);
  7843. }
  7844. data.alias = aliases;
  7845. }, ['xtype', 'alias']);
  7846. }(Ext.Class, Ext.Function.alias, Array.prototype.slice, Ext.Array.from, Ext.global));
  7847. /**
  7848. * @author Jacky Nguyen <jacky@sencha.com>
  7849. * @docauthor Jacky Nguyen <jacky@sencha.com>
  7850. * @class Ext.Loader
  7851. *
  7852. * Ext.Loader is the heart of the new dynamic dependency loading capability in Ext JS 4+. It is most commonly used
  7853. * via the {@link Ext#require} shorthand. Ext.Loader supports both asynchronous and synchronous loading
  7854. * approaches, and leverage their advantages for the best development flow. We'll discuss about the pros and cons of each approach:
  7855. *
  7856. * # Asynchronous Loading #
  7857. *
  7858. * - Advantages:
  7859. * + Cross-domain
  7860. * + No web server needed: you can run the application via the file system protocol (i.e: `file://path/to/your/index
  7861. * .html`)
  7862. * + Best possible debugging experience: error messages come with the exact file name and line number
  7863. *
  7864. * - Disadvantages:
  7865. * + Dependencies need to be specified before-hand
  7866. *
  7867. * ### Method 1: Explicitly include what you need: ###
  7868. *
  7869. * // Syntax
  7870. * Ext.require({String/Array} expressions);
  7871. *
  7872. * // Example: Single alias
  7873. * Ext.require('widget.window');
  7874. *
  7875. * // Example: Single class name
  7876. * Ext.require('Ext.window.Window');
  7877. *
  7878. * // Example: Multiple aliases / class names mix
  7879. * Ext.require(['widget.window', 'layout.border', 'Ext.data.Connection']);
  7880. *
  7881. * // Wildcards
  7882. * Ext.require(['widget.*', 'layout.*', 'Ext.data.*']);
  7883. *
  7884. * ### Method 2: Explicitly exclude what you don't need: ###
  7885. *
  7886. * // Syntax: Note that it must be in this chaining format.
  7887. * Ext.exclude({String/Array} expressions)
  7888. * .require({String/Array} expressions);
  7889. *
  7890. * // Include everything except Ext.data.*
  7891. * Ext.exclude('Ext.data.*').require('*');
  7892. *
  7893. * // Include all widgets except widget.checkbox*,
  7894. * // which will match widget.checkbox, widget.checkboxfield, widget.checkboxgroup, etc.
  7895. * Ext.exclude('widget.checkbox*').require('widget.*');
  7896. *
  7897. * # Synchronous Loading on Demand #
  7898. *
  7899. * - Advantages:
  7900. * + There's no need to specify dependencies before-hand, which is always the convenience of including ext-all.js
  7901. * before
  7902. *
  7903. * - Disadvantages:
  7904. * + Not as good debugging experience since file name won't be shown (except in Firebug at the moment)
  7905. * + Must be from the same domain due to XHR restriction
  7906. * + Need a web server, same reason as above
  7907. *
  7908. * There's one simple rule to follow: Instantiate everything with Ext.create instead of the `new` keyword
  7909. *
  7910. * Ext.create('widget.window', { ... }); // Instead of new Ext.window.Window({...});
  7911. *
  7912. * Ext.create('Ext.window.Window', {}); // Same as above, using full class name instead of alias
  7913. *
  7914. * Ext.widget('window', {}); // Same as above, all you need is the traditional `xtype`
  7915. *
  7916. * Behind the scene, {@link Ext.ClassManager} will automatically check whether the given class name / alias has already
  7917. * existed on the page. If it's not, Ext.Loader will immediately switch itself to synchronous mode and automatic load the given
  7918. * class and all its dependencies.
  7919. *
  7920. * # Hybrid Loading - The Best of Both Worlds #
  7921. *
  7922. * It has all the advantages combined from asynchronous and synchronous loading. The development flow is simple:
  7923. *
  7924. * ### Step 1: Start writing your application using synchronous approach.
  7925. *
  7926. * Ext.Loader will automatically fetch all dependencies on demand as they're needed during run-time. For example:
  7927. *
  7928. * Ext.onReady(function(){
  7929. * var window = Ext.widget('window', {
  7930. * width: 500,
  7931. * height: 300,
  7932. * layout: {
  7933. * type: 'border',
  7934. * padding: 5
  7935. * },
  7936. * title: 'Hello Dialog',
  7937. * items: [{
  7938. * title: 'Navigation',
  7939. * collapsible: true,
  7940. * region: 'west',
  7941. * width: 200,
  7942. * html: 'Hello',
  7943. * split: true
  7944. * }, {
  7945. * title: 'TabPanel',
  7946. * region: 'center'
  7947. * }]
  7948. * });
  7949. *
  7950. * window.show();
  7951. * })
  7952. *
  7953. * ### Step 2: Along the way, when you need better debugging ability, watch the console for warnings like these: ###
  7954. *
  7955. * [Ext.Loader] Synchronously loading 'Ext.window.Window'; consider adding Ext.require('Ext.window.Window') before your application's code
  7956. * ClassManager.js:432
  7957. * [Ext.Loader] Synchronously loading 'Ext.layout.container.Border'; consider adding Ext.require('Ext.layout.container.Border') before your application's code
  7958. *
  7959. * Simply copy and paste the suggested code above `Ext.onReady`, i.e:
  7960. *
  7961. * Ext.require('Ext.window.Window');
  7962. * Ext.require('Ext.layout.container.Border');
  7963. *
  7964. * Ext.onReady(...);
  7965. *
  7966. * Everything should now load via asynchronous mode.
  7967. *
  7968. * # Deployment #
  7969. *
  7970. * It's important to note that dynamic loading should only be used during development on your local machines.
  7971. * During production, all dependencies should be combined into one single JavaScript file. Ext.Loader makes
  7972. * the whole process of transitioning from / to between development / maintenance and production as easy as
  7973. * possible. Internally {@link Ext.Loader#history Ext.Loader.history} maintains the list of all dependencies your application
  7974. * needs in the exact loading sequence. It's as simple as concatenating all files in this array into one,
  7975. * then include it on top of your application.
  7976. *
  7977. * This process will be automated with Sencha Command, to be released and documented towards Ext JS 4 Final.
  7978. *
  7979. * @singleton
  7980. */
  7981. Ext.Loader = new function() {
  7982. var Loader = this,
  7983. Manager = Ext.ClassManager,
  7984. Class = Ext.Class,
  7985. flexSetter = Ext.Function.flexSetter,
  7986. alias = Ext.Function.alias,
  7987. pass = Ext.Function.pass,
  7988. defer = Ext.Function.defer,
  7989. arrayErase = Ext.Array.erase,
  7990. //<if nonBrowser>
  7991. isNonBrowser = typeof window == 'undefined',
  7992. isNodeJS = isNonBrowser && (typeof require == 'function'),
  7993. isJsdb = isNonBrowser && typeof system != 'undefined' && system.program.search(/jsdb/) !== -1,
  7994. isPhantomJS = (typeof phantom != 'undefined' && phantom.fs),
  7995. //</if>
  7996. dependencyProperties = ['extend', 'mixins', 'requires'],
  7997. isInHistory = {},
  7998. history = [],
  7999. slashDotSlashRe = /\/\.\//g,
  8000. dotRe = /\./g;
  8001. Ext.apply(Loader, {
  8002. /**
  8003. * @private
  8004. */
  8005. isInHistory: isInHistory,
  8006. /**
  8007. * An array of class names to keep track of the dependency loading order.
  8008. * This is not guaranteed to be the same everytime due to the asynchronous
  8009. * nature of the Loader.
  8010. *
  8011. * @property {Array} history
  8012. */
  8013. history: history,
  8014. /**
  8015. * Configuration
  8016. * @private
  8017. */
  8018. config: {
  8019. /**
  8020. * @cfg {Boolean} enabled
  8021. * Whether or not to enable the dynamic dependency loading feature.
  8022. */
  8023. enabled: false,
  8024. /**
  8025. * @cfg {Boolean} scriptChainDelay
  8026. * millisecond delay between asynchronous script injection (prevents stack overflow on some user agents)
  8027. * 'false' disables delay but potentially increases stack load.
  8028. */
  8029. scriptChainDelay : false,
  8030. /**
  8031. * @cfg {Boolean} disableCaching
  8032. * Appends current timestamp to script files to prevent caching.
  8033. */
  8034. disableCaching: true,
  8035. /**
  8036. * @cfg {String} disableCachingParam
  8037. * The get parameter name for the cache buster's timestamp.
  8038. */
  8039. disableCachingParam: '_dc',
  8040. /**
  8041. * @cfg {Boolean} garbageCollect
  8042. * True to prepare an asynchronous script tag for garbage collection (effective only
  8043. * if {@link #preserveScripts preserveScripts} is false)
  8044. */
  8045. garbageCollect : false,
  8046. /**
  8047. * @cfg {Object} paths
  8048. * The mapping from namespaces to file paths
  8049. *
  8050. * {
  8051. * 'Ext': '.', // This is set by default, Ext.layout.container.Container will be
  8052. * // loaded from ./layout/Container.js
  8053. *
  8054. * 'My': './src/my_own_folder' // My.layout.Container will be loaded from
  8055. * // ./src/my_own_folder/layout/Container.js
  8056. * }
  8057. *
  8058. * Note that all relative paths are relative to the current HTML document.
  8059. * If not being specified, for example, <code>Other.awesome.Class</code>
  8060. * will simply be loaded from <code>./Other/awesome/Class.js</code>
  8061. */
  8062. paths: {
  8063. 'Ext': '.'
  8064. },
  8065. /**
  8066. * @cfg {Boolean} preserveScripts
  8067. * False to remove and optionally {@link #garbageCollect garbage-collect} asynchronously loaded scripts,
  8068. * True to retain script element for browser debugger compatibility and improved load performance.
  8069. */
  8070. preserveScripts : true,
  8071. /**
  8072. * @cfg {String} scriptCharset
  8073. * Optional charset to specify encoding of dynamic script content.
  8074. */
  8075. scriptCharset : undefined
  8076. },
  8077. /**
  8078. * Set the configuration for the loader. This should be called right after ext-(debug).js
  8079. * is included in the page, and before Ext.onReady. i.e:
  8080. *
  8081. * <script type="text/javascript" src="ext-core-debug.js"></script>
  8082. * <script type="text/javascript">
  8083. * Ext.Loader.setConfig({
  8084. * enabled: true,
  8085. * paths: {
  8086. * 'My': 'my_own_path'
  8087. * }
  8088. * });
  8089. * </script>
  8090. * <script type="text/javascript">
  8091. * Ext.require(...);
  8092. *
  8093. * Ext.onReady(function() {
  8094. * // application code here
  8095. * });
  8096. * </script>
  8097. *
  8098. * Refer to config options of {@link Ext.Loader} for the list of possible properties
  8099. *
  8100. * @param {Object} config The config object to override the default values
  8101. * @return {Ext.Loader} this
  8102. */
  8103. setConfig: function(name, value) {
  8104. if (Ext.isObject(name) && arguments.length === 1) {
  8105. Ext.merge(Loader.config, name);
  8106. }
  8107. else {
  8108. Loader.config[name] = (Ext.isObject(value)) ? Ext.merge(Loader.config[name], value) : value;
  8109. }
  8110. return Loader;
  8111. },
  8112. /**
  8113. * Get the config value corresponding to the specified name. If no name is given, will return the config object
  8114. * @param {String} name The config property name
  8115. * @return {Object}
  8116. */
  8117. getConfig: function(name) {
  8118. if (name) {
  8119. return Loader.config[name];
  8120. }
  8121. return Loader.config;
  8122. },
  8123. /**
  8124. * Sets the path of a namespace.
  8125. * For Example:
  8126. *
  8127. * Ext.Loader.setPath('Ext', '.');
  8128. *
  8129. * @param {String/Object} name See {@link Ext.Function#flexSetter flexSetter}
  8130. * @param {String} path See {@link Ext.Function#flexSetter flexSetter}
  8131. * @return {Ext.Loader} this
  8132. * @method
  8133. */
  8134. setPath: flexSetter(function(name, path) {
  8135. Loader.config.paths[name] = path;
  8136. return Loader;
  8137. }),
  8138. /**
  8139. * Translates a className to a file path by adding the
  8140. * the proper prefix and converting the .'s to /'s. For example:
  8141. *
  8142. * Ext.Loader.setPath('My', '/path/to/My');
  8143. *
  8144. * alert(Ext.Loader.getPath('My.awesome.Class')); // alerts '/path/to/My/awesome/Class.js'
  8145. *
  8146. * Note that the deeper namespace levels, if explicitly set, are always resolved first. For example:
  8147. *
  8148. * Ext.Loader.setPath({
  8149. * 'My': '/path/to/lib',
  8150. * 'My.awesome': '/other/path/for/awesome/stuff',
  8151. * 'My.awesome.more': '/more/awesome/path'
  8152. * });
  8153. *
  8154. * alert(Ext.Loader.getPath('My.awesome.Class')); // alerts '/other/path/for/awesome/stuff/Class.js'
  8155. *
  8156. * alert(Ext.Loader.getPath('My.awesome.more.Class')); // alerts '/more/awesome/path/Class.js'
  8157. *
  8158. * alert(Ext.Loader.getPath('My.cool.Class')); // alerts '/path/to/lib/cool/Class.js'
  8159. *
  8160. * alert(Ext.Loader.getPath('Unknown.strange.Stuff')); // alerts 'Unknown/strange/Stuff.js'
  8161. *
  8162. * @param {String} className
  8163. * @return {String} path
  8164. */
  8165. getPath: function(className) {
  8166. var path = '',
  8167. paths = Loader.config.paths,
  8168. prefix = Loader.getPrefix(className);
  8169. if (prefix.length > 0) {
  8170. if (prefix === className) {
  8171. return paths[prefix];
  8172. }
  8173. path = paths[prefix];
  8174. className = className.substring(prefix.length + 1);
  8175. }
  8176. if (path.length > 0) {
  8177. path += '/';
  8178. }
  8179. return path.replace(slashDotSlashRe, '/') + className.replace(dotRe, "/") + '.js';
  8180. },
  8181. /**
  8182. * @private
  8183. * @param {String} className
  8184. */
  8185. getPrefix: function(className) {
  8186. var paths = Loader.config.paths,
  8187. prefix, deepestPrefix = '';
  8188. if (paths.hasOwnProperty(className)) {
  8189. return className;
  8190. }
  8191. for (prefix in paths) {
  8192. if (paths.hasOwnProperty(prefix) && prefix + '.' === className.substring(0, prefix.length + 1)) {
  8193. if (prefix.length > deepestPrefix.length) {
  8194. deepestPrefix = prefix;
  8195. }
  8196. }
  8197. }
  8198. return deepestPrefix;
  8199. },
  8200. /**
  8201. * @private
  8202. * @param {String} className
  8203. */
  8204. isAClassNameWithAKnownPrefix: function(className) {
  8205. var prefix = Loader.getPrefix(className);
  8206. // we can only say it's really a class if className is not equal to any known namespace
  8207. return prefix !== '' && prefix !== className;
  8208. },
  8209. /**
  8210. * Loads all classes by the given names and all their direct dependencies; optionally executes the given callback function when
  8211. * finishes, within the optional scope. This method is aliased by {@link Ext#require Ext.require} for convenience
  8212. * @param {String/Array} expressions Can either be a string or an array of string
  8213. * @param {Function} fn (Optional) The callback function
  8214. * @param {Object} scope (Optional) The execution scope (`this`) of the callback function
  8215. * @param {String/Array} excludes (Optional) Classes to be excluded, useful when being used with expressions
  8216. */
  8217. require: function(expressions, fn, scope, excludes) {
  8218. if (fn) {
  8219. fn.call(scope);
  8220. }
  8221. },
  8222. /**
  8223. * 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
  8224. * @param {String/Array} expressions Can either be a string or an array of string
  8225. * @param {Function} fn (Optional) The callback function
  8226. * @param {Object} scope (Optional) The execution scope (`this`) of the callback function
  8227. * @param {String/Array} excludes (Optional) Classes to be excluded, useful when being used with expressions
  8228. */
  8229. syncRequire: function() {},
  8230. /**
  8231. * Explicitly exclude files from being loaded. Useful when used in conjunction with a broad include expression.
  8232. * Can be chained with more `require` and `exclude` methods, eg:
  8233. *
  8234. * Ext.exclude('Ext.data.*').require('*');
  8235. *
  8236. * Ext.exclude('widget.button*').require('widget.*');
  8237. *
  8238. * @param {Array} excludes
  8239. * @return {Object} object contains `require` method for chaining
  8240. */
  8241. exclude: function(excludes) {
  8242. return {
  8243. require: function(expressions, fn, scope) {
  8244. return Loader.require(expressions, fn, scope, excludes);
  8245. },
  8246. syncRequire: function(expressions, fn, scope) {
  8247. return Loader.syncRequire(expressions, fn, scope, excludes);
  8248. }
  8249. };
  8250. },
  8251. /**
  8252. * Add a new listener to be executed when all required scripts are fully loaded
  8253. *
  8254. * @param {Function} fn The function callback to be executed
  8255. * @param {Object} scope The execution scope (<code>this</code>) of the callback function
  8256. * @param {Boolean} withDomReady Whether or not to wait for document dom ready as well
  8257. */
  8258. onReady: function(fn, scope, withDomReady, options) {
  8259. var oldFn;
  8260. if (withDomReady !== false && Ext.onDocumentReady) {
  8261. oldFn = fn;
  8262. fn = function() {
  8263. Ext.onDocumentReady(oldFn, scope, options);
  8264. };
  8265. }
  8266. fn.call(scope);
  8267. }
  8268. });
  8269. //<feature classSystem.loader>
  8270. var queue = [],
  8271. isClassFileLoaded = {},
  8272. isFileLoaded = {},
  8273. classNameToFilePathMap = {},
  8274. scriptElements = {},
  8275. readyListeners = [],
  8276. usedClasses = [],
  8277. requiresMap = {};
  8278. Ext.apply(Loader, {
  8279. /**
  8280. * @private
  8281. */
  8282. documentHead: typeof document != 'undefined' && (document.head || document.getElementsByTagName('head')[0]),
  8283. /**
  8284. * Flag indicating whether there are still files being loaded
  8285. * @private
  8286. */
  8287. isLoading: false,
  8288. /**
  8289. * Maintain the queue for all dependencies. Each item in the array is an object of the format:
  8290. *
  8291. * {
  8292. * requires: [...], // The required classes for this queue item
  8293. * callback: function() { ... } // The function to execute when all classes specified in requires exist
  8294. * }
  8295. *
  8296. * @private
  8297. */
  8298. queue: queue,
  8299. /**
  8300. * Maintain the list of files that have already been handled so that they never get double-loaded
  8301. * @private
  8302. */
  8303. isClassFileLoaded: isClassFileLoaded,
  8304. /**
  8305. * @private
  8306. */
  8307. isFileLoaded: isFileLoaded,
  8308. /**
  8309. * Maintain the list of listeners to execute when all required scripts are fully loaded
  8310. * @private
  8311. */
  8312. readyListeners: readyListeners,
  8313. /**
  8314. * Contains classes referenced in `uses` properties.
  8315. * @private
  8316. */
  8317. optionalRequires: usedClasses,
  8318. /**
  8319. * Map of fully qualified class names to an array of dependent classes.
  8320. * @private
  8321. */
  8322. requiresMap: requiresMap,
  8323. /**
  8324. * @private
  8325. */
  8326. numPendingFiles: 0,
  8327. /**
  8328. * @private
  8329. */
  8330. numLoadedFiles: 0,
  8331. /** @private */
  8332. hasFileLoadError: false,
  8333. /**
  8334. * @private
  8335. */
  8336. classNameToFilePathMap: classNameToFilePathMap,
  8337. /**
  8338. * The number of scripts loading via loadScript.
  8339. * @private
  8340. */
  8341. scriptsLoading: 0,
  8342. /**
  8343. * @private
  8344. */
  8345. syncModeEnabled: false,
  8346. scriptElements: scriptElements,
  8347. /**
  8348. * Refresh all items in the queue. If all dependencies for an item exist during looping,
  8349. * it will execute the callback and call refreshQueue again. Triggers onReady when the queue is
  8350. * empty
  8351. * @private
  8352. */
  8353. refreshQueue: function() {
  8354. var ln = queue.length,
  8355. i, item, j, requires;
  8356. // When the queue of loading classes reaches zero, trigger readiness
  8357. if (!ln && !Loader.scriptsLoading) {
  8358. return Loader.triggerReady();
  8359. }
  8360. for (i = 0; i < ln; i++) {
  8361. item = queue[i];
  8362. if (item) {
  8363. requires = item.requires;
  8364. // Don't bother checking when the number of files loaded
  8365. // is still less than the array length
  8366. if (requires.length > Loader.numLoadedFiles) {
  8367. continue;
  8368. }
  8369. // Remove any required classes that are loaded
  8370. for (j = 0; j < requires.length; ) {
  8371. if (Manager.isCreated(requires[j])) {
  8372. // Take out from the queue
  8373. arrayErase(requires, j, 1);
  8374. }
  8375. else {
  8376. j++;
  8377. }
  8378. }
  8379. // If we've ended up with no required classes, call the callback
  8380. if (item.requires.length === 0) {
  8381. arrayErase(queue, i, 1);
  8382. item.callback.call(item.scope);
  8383. Loader.refreshQueue();
  8384. break;
  8385. }
  8386. }
  8387. }
  8388. return Loader;
  8389. },
  8390. /**
  8391. * Inject a script element to document's head, call onLoad and onError accordingly
  8392. * @private
  8393. */
  8394. injectScriptElement: function(url, onLoad, onError, scope, charset) {
  8395. var script = document.createElement('script'),
  8396. dispatched = false,
  8397. config = Loader.config,
  8398. onLoadFn = function() {
  8399. if(!dispatched) {
  8400. dispatched = true;
  8401. script.onload = script.onreadystatechange = script.onerror = null;
  8402. if (typeof config.scriptChainDelay == 'number') {
  8403. //free the stack (and defer the next script)
  8404. defer(onLoad, config.scriptChainDelay, scope);
  8405. } else {
  8406. onLoad.call(scope);
  8407. }
  8408. Loader.cleanupScriptElement(script, config.preserveScripts === false, config.garbageCollect);
  8409. }
  8410. },
  8411. onErrorFn = function(arg) {
  8412. defer(onError, 1, scope); //free the stack
  8413. Loader.cleanupScriptElement(script, config.preserveScripts === false, config.garbageCollect);
  8414. };
  8415. script.type = 'text/javascript';
  8416. script.onerror = onErrorFn;
  8417. charset = charset || config.scriptCharset;
  8418. if (charset) {
  8419. script.charset = charset;
  8420. }
  8421. /*
  8422. * IE9 Standards mode (and others) SHOULD follow the load event only
  8423. * (Note: IE9 supports both onload AND readystatechange events)
  8424. */
  8425. if ('addEventListener' in script ) {
  8426. script.onload = onLoadFn;
  8427. } else if ('readyState' in script) { // for <IE9 Compatability
  8428. script.onreadystatechange = function() {
  8429. if ( this.readyState == 'loaded' || this.readyState == 'complete' ) {
  8430. onLoadFn();
  8431. }
  8432. };
  8433. } else {
  8434. script.onload = onLoadFn;
  8435. }
  8436. script.src = url;
  8437. (Loader.documentHead || document.getElementsByTagName('head')[0]).appendChild(script);
  8438. return script;
  8439. },
  8440. /**
  8441. * @private
  8442. */
  8443. removeScriptElement: function(url) {
  8444. if (scriptElements[url]) {
  8445. Loader.cleanupScriptElement(scriptElements[url], true, !!Loader.getConfig('garbageCollect'));
  8446. delete scriptElements[url];
  8447. }
  8448. return Loader;
  8449. },
  8450. /**
  8451. * @private
  8452. */
  8453. cleanupScriptElement: function(script, remove, collect) {
  8454. var prop;
  8455. script.onload = script.onreadystatechange = script.onerror = null;
  8456. if (remove) {
  8457. Ext.removeNode(script); // Remove, since its useless now
  8458. if (collect) {
  8459. for (prop in script) {
  8460. try {
  8461. script[prop] = null;
  8462. delete script[prop]; // and prepare for GC
  8463. } catch (cleanEx) {
  8464. //ignore
  8465. }
  8466. }
  8467. }
  8468. }
  8469. return Loader;
  8470. },
  8471. /**
  8472. * Loads the specified script URL and calls the supplied callbacks. If this method
  8473. * is called before {@link Ext#isReady}, the script's load will delay the transition
  8474. * to ready. This can be used to load arbitrary scripts that may contain further
  8475. * {@link Ext#require Ext.require} calls.
  8476. *
  8477. * @param {Object/String} options The options object or simply the URL to load.
  8478. * @param {String} options.url The URL from which to load the script.
  8479. * @param {Function} [options.onLoad] The callback to call on successful load.
  8480. * @param {Function} [options.onError] The callback to call on failure to load.
  8481. * @param {Object} [options.scope] The scope (`this`) for the supplied callbacks.
  8482. */
  8483. loadScript: function (options) {
  8484. var config = Loader.getConfig(),
  8485. isString = typeof options == 'string',
  8486. url = isString ? options : options.url,
  8487. onError = !isString && options.onError,
  8488. onLoad = !isString && options.onLoad,
  8489. scope = !isString && options.scope,
  8490. onScriptError = function() {
  8491. Loader.numPendingFiles--;
  8492. Loader.scriptsLoading--;
  8493. if (onError) {
  8494. onError.call(scope, "Failed loading '" + url + "', please verify that the file exists");
  8495. }
  8496. if (Loader.numPendingFiles + Loader.scriptsLoading === 0) {
  8497. Loader.refreshQueue();
  8498. }
  8499. },
  8500. onScriptLoad = function () {
  8501. Loader.numPendingFiles--;
  8502. Loader.scriptsLoading--;
  8503. if (onLoad) {
  8504. onLoad.call(scope);
  8505. }
  8506. if (Loader.numPendingFiles + Loader.scriptsLoading === 0) {
  8507. Loader.refreshQueue();
  8508. }
  8509. },
  8510. src;
  8511. Loader.isLoading = true;
  8512. Loader.numPendingFiles++;
  8513. Loader.scriptsLoading++;
  8514. src = config.disableCaching ?
  8515. (url + '?' + config.disableCachingParam + '=' + Ext.Date.now()) : url;
  8516. scriptElements[url] = Loader.injectScriptElement(src, onScriptLoad, onScriptError);
  8517. },
  8518. /**
  8519. * Load a script file, supports both asynchronous and synchronous approaches
  8520. * @private
  8521. */
  8522. loadScriptFile: function(url, onLoad, onError, scope, synchronous) {
  8523. if (isFileLoaded[url]) {
  8524. return Loader;
  8525. }
  8526. var config = Loader.getConfig(),
  8527. noCacheUrl = url + (config.disableCaching ? ('?' + config.disableCachingParam + '=' + Ext.Date.now()) : ''),
  8528. isCrossOriginRestricted = false,
  8529. xhr, status, onScriptError,
  8530. debugSourceURL = "";
  8531. scope = scope || Loader;
  8532. Loader.isLoading = true;
  8533. if (!synchronous) {
  8534. onScriptError = function() {
  8535. //<debug error>
  8536. onError.call(scope, "Failed loading '" + url + "', please verify that the file exists", synchronous);
  8537. //</debug>
  8538. };
  8539. scriptElements[url] = Loader.injectScriptElement(noCacheUrl, onLoad, onScriptError, scope);
  8540. } else {
  8541. if (typeof XMLHttpRequest != 'undefined') {
  8542. xhr = new XMLHttpRequest();
  8543. } else {
  8544. xhr = new ActiveXObject('Microsoft.XMLHTTP');
  8545. }
  8546. try {
  8547. xhr.open('GET', noCacheUrl, false);
  8548. xhr.send(null);
  8549. } catch (e) {
  8550. isCrossOriginRestricted = true;
  8551. }
  8552. status = (xhr.status === 1223) ? 204 :
  8553. (xhr.status === 0 && (self.location || {}).protocol == 'file:') ? 200 : xhr.status;
  8554. isCrossOriginRestricted = isCrossOriginRestricted || (status === 0);
  8555. if (isCrossOriginRestricted
  8556. //<if isNonBrowser>
  8557. && !isPhantomJS
  8558. //</if>
  8559. ) {
  8560. //<debug error>
  8561. onError.call(Loader, "Failed loading synchronously via XHR: '" + url + "'; It's likely that the file is either " +
  8562. "being loaded from a different domain or from the local file system whereby cross origin " +
  8563. "requests are not allowed due to security reasons. Use asynchronous loading with " +
  8564. "Ext.require instead.", synchronous);
  8565. //</debug>
  8566. }
  8567. else if ((status >= 200 && status < 300) || (status === 304)
  8568. //<if isNonBrowser>
  8569. || isPhantomJS
  8570. //</if>
  8571. ) {
  8572. // Debugger friendly, file names are still shown even though they're eval'ed code
  8573. // Breakpoints work on both Firebug and Chrome's Web Inspector
  8574. if (!Ext.isIE) {
  8575. debugSourceURL = "\n//@ sourceURL=" + url;
  8576. }
  8577. Ext.globalEval(xhr.responseText + debugSourceURL);
  8578. onLoad.call(scope);
  8579. }
  8580. else {
  8581. //<debug>
  8582. onError.call(Loader, "Failed loading synchronously via XHR: '" + url + "'; please " +
  8583. "verify that the file exists. " +
  8584. "XHR status code: " + status, synchronous);
  8585. //</debug>
  8586. }
  8587. // Prevent potential IE memory leak
  8588. xhr = null;
  8589. }
  8590. },
  8591. // documented above
  8592. syncRequire: function() {
  8593. var syncModeEnabled = Loader.syncModeEnabled;
  8594. if (!syncModeEnabled) {
  8595. Loader.syncModeEnabled = true;
  8596. }
  8597. Loader.require.apply(Loader, arguments);
  8598. if (!syncModeEnabled) {
  8599. Loader.syncModeEnabled = false;
  8600. }
  8601. Loader.refreshQueue();
  8602. },
  8603. // documented above
  8604. require: function(expressions, fn, scope, excludes) {
  8605. var excluded = {},
  8606. included = {},
  8607. excludedClassNames = [],
  8608. possibleClassNames = [],
  8609. classNames = [],
  8610. references = [],
  8611. callback,
  8612. syncModeEnabled,
  8613. filePath, expression, exclude, className,
  8614. possibleClassName, i, j, ln, subLn;
  8615. if (excludes) {
  8616. // Convert possible single string to an array.
  8617. excludes = (typeof excludes === 'string') ? [ excludes ] : excludes;
  8618. for (i = 0,ln = excludes.length; i < ln; i++) {
  8619. exclude = excludes[i];
  8620. if (typeof exclude == 'string' && exclude.length > 0) {
  8621. excludedClassNames = Manager.getNamesByExpression(exclude);
  8622. for (j = 0,subLn = excludedClassNames.length; j < subLn; j++) {
  8623. excluded[excludedClassNames[j]] = true;
  8624. }
  8625. }
  8626. }
  8627. }
  8628. // Convert possible single string to an array.
  8629. expressions = (typeof expressions === 'string') ? [ expressions ] : (expressions ? expressions : []);
  8630. if (fn) {
  8631. if (fn.length > 0) {
  8632. callback = function() {
  8633. var classes = [],
  8634. i, ln;
  8635. for (i = 0,ln = references.length; i < ln; i++) {
  8636. classes.push(Manager.get(references[i]));
  8637. }
  8638. return fn.apply(this, classes);
  8639. };
  8640. }
  8641. else {
  8642. callback = fn;
  8643. }
  8644. }
  8645. else {
  8646. callback = Ext.emptyFn;
  8647. }
  8648. scope = scope || Ext.global;
  8649. for (i = 0,ln = expressions.length; i < ln; i++) {
  8650. expression = expressions[i];
  8651. if (typeof expression == 'string' && expression.length > 0) {
  8652. possibleClassNames = Manager.getNamesByExpression(expression);
  8653. subLn = possibleClassNames.length;
  8654. for (j = 0; j < subLn; j++) {
  8655. possibleClassName = possibleClassNames[j];
  8656. if (excluded[possibleClassName] !== true) {
  8657. references.push(possibleClassName);
  8658. if (!Manager.isCreated(possibleClassName) && !included[possibleClassName]) {
  8659. included[possibleClassName] = true;
  8660. classNames.push(possibleClassName);
  8661. }
  8662. }
  8663. }
  8664. }
  8665. }
  8666. // If the dynamic dependency feature is not being used, throw an error
  8667. // if the dependencies are not defined
  8668. if (classNames.length > 0) {
  8669. if (!Loader.config.enabled) {
  8670. throw new Error("Ext.Loader is not enabled, so dependencies cannot be resolved dynamically. " +
  8671. "Missing required class" + ((classNames.length > 1) ? "es" : "") + ": " + classNames.join(', '));
  8672. }
  8673. }
  8674. else {
  8675. callback.call(scope);
  8676. return Loader;
  8677. }
  8678. syncModeEnabled = Loader.syncModeEnabled;
  8679. if (!syncModeEnabled) {
  8680. queue.push({
  8681. requires: classNames.slice(), // this array will be modified as the queue is processed,
  8682. // so we need a copy of it
  8683. callback: callback,
  8684. scope: scope
  8685. });
  8686. }
  8687. ln = classNames.length;
  8688. for (i = 0; i < ln; i++) {
  8689. className = classNames[i];
  8690. filePath = Loader.getPath(className);
  8691. // If we are synchronously loading a file that has already been asychronously loaded before
  8692. // we need to destroy the script tag and revert the count
  8693. // This file will then be forced loaded in synchronous
  8694. if (syncModeEnabled && isClassFileLoaded.hasOwnProperty(className)) {
  8695. Loader.numPendingFiles--;
  8696. Loader.removeScriptElement(filePath);
  8697. delete isClassFileLoaded[className];
  8698. }
  8699. if (!isClassFileLoaded.hasOwnProperty(className)) {
  8700. isClassFileLoaded[className] = false;
  8701. classNameToFilePathMap[className] = filePath;
  8702. Loader.numPendingFiles++;
  8703. Loader.loadScriptFile(
  8704. filePath,
  8705. pass(Loader.onFileLoaded, [className, filePath], Loader),
  8706. pass(Loader.onFileLoadError, [className, filePath], Loader),
  8707. Loader,
  8708. syncModeEnabled
  8709. );
  8710. }
  8711. }
  8712. if (syncModeEnabled) {
  8713. callback.call(scope);
  8714. if (ln === 1) {
  8715. return Manager.get(className);
  8716. }
  8717. }
  8718. return Loader;
  8719. },
  8720. /**
  8721. * @private
  8722. * @param {String} className
  8723. * @param {String} filePath
  8724. */
  8725. onFileLoaded: function(className, filePath) {
  8726. Loader.numLoadedFiles++;
  8727. isClassFileLoaded[className] = true;
  8728. isFileLoaded[filePath] = true;
  8729. Loader.numPendingFiles--;
  8730. if (Loader.numPendingFiles === 0) {
  8731. Loader.refreshQueue();
  8732. }
  8733. //<debug>
  8734. if (!Loader.syncModeEnabled && Loader.numPendingFiles === 0 && Loader.isLoading && !Loader.hasFileLoadError) {
  8735. var missingClasses = [],
  8736. missingPaths = [],
  8737. requires,
  8738. i, ln, j, subLn;
  8739. for (i = 0,ln = queue.length; i < ln; i++) {
  8740. requires = queue[i].requires;
  8741. for (j = 0,subLn = requires.length; j < subLn; j++) {
  8742. if (isClassFileLoaded[requires[j]]) {
  8743. missingClasses.push(requires[j]);
  8744. }
  8745. }
  8746. }
  8747. if (missingClasses.length < 1) {
  8748. return;
  8749. }
  8750. missingClasses = Ext.Array.filter(Ext.Array.unique(missingClasses), function(item) {
  8751. return !requiresMap.hasOwnProperty(item);
  8752. }, Loader);
  8753. for (i = 0,ln = missingClasses.length; i < ln; i++) {
  8754. missingPaths.push(classNameToFilePathMap[missingClasses[i]]);
  8755. }
  8756. throw new Error("The following classes are not declared even if their files have been " +
  8757. "loaded: '" + missingClasses.join("', '") + "'. Please check the source code of their " +
  8758. "corresponding files for possible typos: '" + missingPaths.join("', '"));
  8759. }
  8760. //</debug>
  8761. },
  8762. /**
  8763. * @private
  8764. */
  8765. onFileLoadError: function(className, filePath, errorMessage, isSynchronous) {
  8766. Loader.numPendingFiles--;
  8767. Loader.hasFileLoadError = true;
  8768. //<debug error>
  8769. throw new Error("[Ext.Loader] " + errorMessage);
  8770. //</debug>
  8771. },
  8772. /**
  8773. * @private
  8774. * Ensure that any classes referenced in the `uses` property are loaded.
  8775. */
  8776. addUsedClasses: function (classes) {
  8777. var cls, i, ln;
  8778. if (classes) {
  8779. classes = (typeof classes == 'string') ? [classes] : classes;
  8780. for (i = 0, ln = classes.length; i < ln; i++) {
  8781. cls = classes[i];
  8782. if (typeof cls == 'string' && !Ext.Array.contains(usedClasses, cls)) {
  8783. usedClasses.push(cls);
  8784. }
  8785. }
  8786. }
  8787. return Loader;
  8788. },
  8789. /**
  8790. * @private
  8791. */
  8792. triggerReady: function() {
  8793. var listener,
  8794. i, refClasses = usedClasses;
  8795. if (Loader.isLoading) {
  8796. Loader.isLoading = false;
  8797. if (refClasses.length !== 0) {
  8798. // Clone then empty the array to eliminate potential recursive loop issue
  8799. refClasses = refClasses.slice();
  8800. usedClasses.length = 0;
  8801. // this may immediately call us back if all 'uses' classes
  8802. // have been loaded
  8803. Loader.require(refClasses, Loader.triggerReady, Loader);
  8804. return Loader;
  8805. }
  8806. }
  8807. // this method can be called with Loader.isLoading either true or false
  8808. // (can be called with false when all 'uses' classes are already loaded)
  8809. // this may bypass the above if condition
  8810. while (readyListeners.length && !Loader.isLoading) {
  8811. // calls to refreshQueue may re-enter triggerReady
  8812. // so we cannot necessarily iterate the readyListeners array
  8813. listener = readyListeners.shift();
  8814. listener.fn.call(listener.scope);
  8815. }
  8816. return Loader;
  8817. },
  8818. // Documented above already
  8819. onReady: function(fn, scope, withDomReady, options) {
  8820. var oldFn;
  8821. if (withDomReady !== false && Ext.onDocumentReady) {
  8822. oldFn = fn;
  8823. fn = function() {
  8824. Ext.onDocumentReady(oldFn, scope, options);
  8825. };
  8826. }
  8827. if (!Loader.isLoading) {
  8828. fn.call(scope);
  8829. }
  8830. else {
  8831. readyListeners.push({
  8832. fn: fn,
  8833. scope: scope
  8834. });
  8835. }
  8836. },
  8837. /**
  8838. * @private
  8839. * @param {String} className
  8840. */
  8841. historyPush: function(className) {
  8842. if (className && isClassFileLoaded.hasOwnProperty(className) && !isInHistory[className]) {
  8843. isInHistory[className] = true;
  8844. history.push(className);
  8845. }
  8846. return Loader;
  8847. }
  8848. });
  8849. /**
  8850. * Turns on or off the "cache buster" applied to dynamically loaded scripts. Normally
  8851. * dynamically loaded scripts have an extra query parameter appended to avoid stale
  8852. * cached scripts. This method can be used to disable this mechanism, and is primarily
  8853. * useful for testing. This is done using a cookie.
  8854. * @param {Boolean} disable True to disable the cache buster.
  8855. * @param {String} [path="/"] An optional path to scope the cookie.
  8856. * @private
  8857. */
  8858. Ext.disableCacheBuster = function (disable, path) {
  8859. var date = new Date();
  8860. date.setTime(date.getTime() + (disable ? 10*365 : -1) * 24*60*60*1000);
  8861. date = date.toGMTString();
  8862. document.cookie = 'ext-cache=1; expires=' + date + '; path='+(path || '/');
  8863. };
  8864. //<if nonBrowser>
  8865. if (isNonBrowser) {
  8866. if (isNodeJS) {
  8867. Ext.apply(Loader, {
  8868. syncModeEnabled: true,
  8869. setPath: flexSetter(function(name, path) {
  8870. path = require('fs').realpathSync(path);
  8871. Loader.config.paths[name] = path;
  8872. return Loader;
  8873. }),
  8874. loadScriptFile: function(filePath, onLoad, onError, scope, synchronous) {
  8875. require(filePath);
  8876. onLoad.call(scope);
  8877. }
  8878. });
  8879. }
  8880. else if (isJsdb) {
  8881. Ext.apply(Loader, {
  8882. syncModeEnabled: true,
  8883. loadScriptFile: function(filePath, onLoad, onError, scope, synchronous) {
  8884. load(filePath);
  8885. onLoad.call(scope);
  8886. }
  8887. });
  8888. }
  8889. }
  8890. //</if>
  8891. //</feature>
  8892. /**
  8893. * Convenient alias of {@link Ext.Loader#require}. Please see the introduction documentation of
  8894. * {@link Ext.Loader} for examples.
  8895. * @member Ext
  8896. * @method require
  8897. */
  8898. Ext.require = alias(Loader, 'require');
  8899. /**
  8900. * Synchronous version of {@link Ext#require}, convenient alias of {@link Ext.Loader#syncRequire}.
  8901. *
  8902. * @member Ext
  8903. * @method syncRequire
  8904. */
  8905. Ext.syncRequire = alias(Loader, 'syncRequire');
  8906. /**
  8907. * Convenient shortcut to {@link Ext.Loader#exclude}
  8908. * @member Ext
  8909. * @method exclude
  8910. */
  8911. Ext.exclude = alias(Loader, 'exclude');
  8912. /**
  8913. * @member Ext
  8914. * @method onReady
  8915. * @ignore
  8916. */
  8917. Ext.onReady = function(fn, scope, options) {
  8918. Loader.onReady(fn, scope, true, options);
  8919. };
  8920. /**
  8921. * @cfg {String[]} requires
  8922. * @member Ext.Class
  8923. * List of classes that have to be loaded before instantiating this class.
  8924. * For example:
  8925. *
  8926. * Ext.define('Mother', {
  8927. * requires: ['Child'],
  8928. * giveBirth: function() {
  8929. * // we can be sure that child class is available.
  8930. * return new Child();
  8931. * }
  8932. * });
  8933. */
  8934. Class.registerPreprocessor('loader', function(cls, data, hooks, continueFn) {
  8935. var me = this,
  8936. dependencies = [],
  8937. dependency,
  8938. className = Manager.getName(cls),
  8939. i, j, ln, subLn, value, propertyName, propertyValue,
  8940. requiredMap, requiredDep;
  8941. /*
  8942. Loop through the dependencyProperties, look for string class names and push
  8943. them into a stack, regardless of whether the property's value is a string, array or object. For example:
  8944. {
  8945. extend: 'Ext.MyClass',
  8946. requires: ['Ext.some.OtherClass'],
  8947. mixins: {
  8948. observable: 'Ext.util.Observable';
  8949. }
  8950. }
  8951. which will later be transformed into:
  8952. {
  8953. extend: Ext.MyClass,
  8954. requires: [Ext.some.OtherClass],
  8955. mixins: {
  8956. observable: Ext.util.Observable;
  8957. }
  8958. }
  8959. */
  8960. for (i = 0,ln = dependencyProperties.length; i < ln; i++) {
  8961. propertyName = dependencyProperties[i];
  8962. if (data.hasOwnProperty(propertyName)) {
  8963. propertyValue = data[propertyName];
  8964. if (typeof propertyValue == 'string') {
  8965. dependencies.push(propertyValue);
  8966. }
  8967. else if (propertyValue instanceof Array) {
  8968. for (j = 0, subLn = propertyValue.length; j < subLn; j++) {
  8969. value = propertyValue[j];
  8970. if (typeof value == 'string') {
  8971. dependencies.push(value);
  8972. }
  8973. }
  8974. }
  8975. else if (typeof propertyValue != 'function') {
  8976. for (j in propertyValue) {
  8977. if (propertyValue.hasOwnProperty(j)) {
  8978. value = propertyValue[j];
  8979. if (typeof value == 'string') {
  8980. dependencies.push(value);
  8981. }
  8982. }
  8983. }
  8984. }
  8985. }
  8986. }
  8987. if (dependencies.length === 0) {
  8988. return;
  8989. }
  8990. //<feature classSystem.loader>
  8991. //<debug error>
  8992. var deadlockPath = [],
  8993. detectDeadlock;
  8994. /*
  8995. Automatically detect deadlocks before-hand,
  8996. will throw an error with detailed path for ease of debugging. Examples of deadlock cases:
  8997. - A extends B, then B extends A
  8998. - A requires B, B requires C, then C requires A
  8999. The detectDeadlock function will recursively transverse till the leaf, hence it can detect deadlocks
  9000. no matter how deep the path is.
  9001. */
  9002. if (className) {
  9003. requiresMap[className] = dependencies;
  9004. //<debug>
  9005. requiredMap = Loader.requiredByMap || (Loader.requiredByMap = {});
  9006. for (i = 0,ln = dependencies.length; i < ln; i++) {
  9007. dependency = dependencies[i];
  9008. (requiredMap[dependency] || (requiredMap[dependency] = [])).push(className);
  9009. }
  9010. //</debug>
  9011. detectDeadlock = function(cls) {
  9012. deadlockPath.push(cls);
  9013. if (requiresMap[cls]) {
  9014. if (Ext.Array.contains(requiresMap[cls], className)) {
  9015. throw new Error("Deadlock detected while loading dependencies! '" + className + "' and '" +
  9016. deadlockPath[1] + "' " + "mutually require each other. Path: " +
  9017. deadlockPath.join(' -> ') + " -> " + deadlockPath[0]);
  9018. }
  9019. for (i = 0,ln = requiresMap[cls].length; i < ln; i++) {
  9020. detectDeadlock(requiresMap[cls][i]);
  9021. }
  9022. }
  9023. };
  9024. detectDeadlock(className);
  9025. }
  9026. //</debug>
  9027. //</feature>
  9028. Loader.require(dependencies, function() {
  9029. for (i = 0,ln = dependencyProperties.length; i < ln; i++) {
  9030. propertyName = dependencyProperties[i];
  9031. if (data.hasOwnProperty(propertyName)) {
  9032. propertyValue = data[propertyName];
  9033. if (typeof propertyValue == 'string') {
  9034. data[propertyName] = Manager.get(propertyValue);
  9035. }
  9036. else if (propertyValue instanceof Array) {
  9037. for (j = 0, subLn = propertyValue.length; j < subLn; j++) {
  9038. value = propertyValue[j];
  9039. if (typeof value == 'string') {
  9040. data[propertyName][j] = Manager.get(value);
  9041. }
  9042. }
  9043. }
  9044. else if (typeof propertyValue != 'function') {
  9045. for (var k in propertyValue) {
  9046. if (propertyValue.hasOwnProperty(k)) {
  9047. value = propertyValue[k];
  9048. if (typeof value == 'string') {
  9049. data[propertyName][k] = Manager.get(value);
  9050. }
  9051. }
  9052. }
  9053. }
  9054. }
  9055. }
  9056. continueFn.call(me, cls, data, hooks);
  9057. });
  9058. return false;
  9059. }, true, 'after', 'className');
  9060. //<feature classSystem.loader>
  9061. /**
  9062. * @cfg {String[]} uses
  9063. * @member Ext.Class
  9064. * List of optional classes to load together with this class. These aren't neccessarily loaded before
  9065. * this class is created, but are guaranteed to be available before Ext.onReady listeners are
  9066. * invoked. For example:
  9067. *
  9068. * Ext.define('Mother', {
  9069. * uses: ['Child'],
  9070. * giveBirth: function() {
  9071. * // This code might, or might not work:
  9072. * // return new Child();
  9073. *
  9074. * // Instead use Ext.create() to load the class at the spot if not loaded already:
  9075. * return Ext.create('Child');
  9076. * }
  9077. * });
  9078. */
  9079. Manager.registerPostprocessor('uses', function(name, cls, data) {
  9080. var uses = data.uses;
  9081. if (uses) {
  9082. Loader.addUsedClasses(uses);
  9083. }
  9084. });
  9085. Manager.onCreated(Loader.historyPush);
  9086. //</feature>
  9087. };
  9088. /**
  9089. * @author Brian Moeskau <brian@sencha.com>
  9090. * @docauthor Brian Moeskau <brian@sencha.com>
  9091. *
  9092. * A wrapper class for the native JavaScript Error object that adds a few useful capabilities for handling
  9093. * errors in an Ext application. When you use Ext.Error to {@link #raise} an error from within any class that
  9094. * uses the Ext 4 class system, the Error class can automatically add the source class and method from which
  9095. * the error was raised. It also includes logic to automatically log the eroor to the console, if available,
  9096. * with additional metadata about the error. In all cases, the error will always be thrown at the end so that
  9097. * execution will halt.
  9098. *
  9099. * Ext.Error also offers a global error {@link #handle handling} method that can be overridden in order to
  9100. * handle application-wide errors in a single spot. You can optionally {@link #ignore} errors altogether,
  9101. * although in a real application it's usually a better idea to override the handling function and perform
  9102. * logging or some other method of reporting the errors in a way that is meaningful to the application.
  9103. *
  9104. * At its simplest you can simply raise an error as a simple string from within any code:
  9105. *
  9106. * Example usage:
  9107. *
  9108. * Ext.Error.raise('Something bad happened!');
  9109. *
  9110. * If raised from plain JavaScript code, the error will be logged to the console (if available) and the message
  9111. * displayed. In most cases however you'll be raising errors from within a class, and it may often be useful to add
  9112. * additional metadata about the error being raised. The {@link #raise} method can also take a config object.
  9113. * In this form the `msg` attribute becomes the error description, and any other data added to the config gets
  9114. * added to the error object and, if the console is available, logged to the console for inspection.
  9115. *
  9116. * Example usage:
  9117. *
  9118. * Ext.define('Ext.Foo', {
  9119. * doSomething: function(option){
  9120. * if (someCondition === false) {
  9121. * Ext.Error.raise({
  9122. * msg: 'You cannot do that!',
  9123. * option: option, // whatever was passed into the method
  9124. * 'error code': 100 // other arbitrary info
  9125. * });
  9126. * }
  9127. * }
  9128. * });
  9129. *
  9130. * If a console is available (that supports the `console.dir` function) you'll see console output like:
  9131. *
  9132. * An error was raised with the following data:
  9133. * option: Object { foo: "bar"}
  9134. * foo: "bar"
  9135. * error code: 100
  9136. * msg: "You cannot do that!"
  9137. * sourceClass: "Ext.Foo"
  9138. * sourceMethod: "doSomething"
  9139. *
  9140. * uncaught exception: You cannot do that!
  9141. *
  9142. * As you can see, the error will report exactly where it was raised and will include as much information as the
  9143. * raising code can usefully provide.
  9144. *
  9145. * If you want to handle all application errors globally you can simply override the static {@link #handle} method
  9146. * and provide whatever handling logic you need. If the method returns true then the error is considered handled
  9147. * and will not be thrown to the browser. If anything but true is returned then the error will be thrown normally.
  9148. *
  9149. * Example usage:
  9150. *
  9151. * Ext.Error.handle = function(err) {
  9152. * if (err.someProperty == 'NotReallyAnError') {
  9153. * // maybe log something to the application here if applicable
  9154. * return true;
  9155. * }
  9156. * // any non-true return value (including none) will cause the error to be thrown
  9157. * }
  9158. *
  9159. */
  9160. Ext.Error = Ext.extend(Error, {
  9161. statics: {
  9162. /**
  9163. * @property {Boolean} ignore
  9164. * Static flag that can be used to globally disable error reporting to the browser if set to true
  9165. * (defaults to false). Note that if you ignore Ext errors it's likely that some other code may fail
  9166. * and throw a native JavaScript error thereafter, so use with caution. In most cases it will probably
  9167. * be preferable to supply a custom error {@link #handle handling} function instead.
  9168. *
  9169. * Example usage:
  9170. *
  9171. * Ext.Error.ignore = true;
  9172. *
  9173. * @static
  9174. */
  9175. ignore: false,
  9176. /**
  9177. * @property {Boolean} notify
  9178. * Static flag that can be used to globally control error notification to the user. Unlike
  9179. * Ex.Error.ignore, this does not effect exceptions. They are still thrown. This value can be
  9180. * set to false to disable the alert notification (default is true for IE6 and IE7).
  9181. *
  9182. * Only the first error will generate an alert. Internally this flag is set to false when the
  9183. * first error occurs prior to displaying the alert.
  9184. *
  9185. * This flag is not used in a release build.
  9186. *
  9187. * Example usage:
  9188. *
  9189. * Ext.Error.notify = false;
  9190. *
  9191. * @static
  9192. */
  9193. //notify: Ext.isIE6 || Ext.isIE7,
  9194. /**
  9195. * Raise an error that can include additional data and supports automatic console logging if available.
  9196. * You can pass a string error message or an object with the `msg` attribute which will be used as the
  9197. * error message. The object can contain any other name-value attributes (or objects) to be logged
  9198. * along with the error.
  9199. *
  9200. * Note that after displaying the error message a JavaScript error will ultimately be thrown so that
  9201. * execution will halt.
  9202. *
  9203. * Example usage:
  9204. *
  9205. * Ext.Error.raise('A simple string error message');
  9206. *
  9207. * // or...
  9208. *
  9209. * Ext.define('Ext.Foo', {
  9210. * doSomething: function(option){
  9211. * if (someCondition === false) {
  9212. * Ext.Error.raise({
  9213. * msg: 'You cannot do that!',
  9214. * option: option, // whatever was passed into the method
  9215. * 'error code': 100 // other arbitrary info
  9216. * });
  9217. * }
  9218. * }
  9219. * });
  9220. *
  9221. * @param {String/Object} err The error message string, or an object containing the attribute "msg" that will be
  9222. * used as the error message. Any other data included in the object will also be logged to the browser console,
  9223. * if available.
  9224. * @static
  9225. */
  9226. raise: function(err){
  9227. err = err || {};
  9228. if (Ext.isString(err)) {
  9229. err = { msg: err };
  9230. }
  9231. var method = this.raise.caller,
  9232. msg;
  9233. if (method) {
  9234. if (method.$name) {
  9235. err.sourceMethod = method.$name;
  9236. }
  9237. if (method.$owner) {
  9238. err.sourceClass = method.$owner.$className;
  9239. }
  9240. }
  9241. if (Ext.Error.handle(err) !== true) {
  9242. msg = Ext.Error.prototype.toString.call(err);
  9243. Ext.log({
  9244. msg: msg,
  9245. level: 'error',
  9246. dump: err,
  9247. stack: true
  9248. });
  9249. throw new Ext.Error(err);
  9250. }
  9251. },
  9252. /**
  9253. * Globally handle any Ext errors that may be raised, optionally providing custom logic to
  9254. * handle different errors individually. Return true from the function to bypass throwing the
  9255. * error to the browser, otherwise the error will be thrown and execution will halt.
  9256. *
  9257. * Example usage:
  9258. *
  9259. * Ext.Error.handle = function(err) {
  9260. * if (err.someProperty == 'NotReallyAnError') {
  9261. * // maybe log something to the application here if applicable
  9262. * return true;
  9263. * }
  9264. * // any non-true return value (including none) will cause the error to be thrown
  9265. * }
  9266. *
  9267. * @param {Ext.Error} err The Ext.Error object being raised. It will contain any attributes that were originally
  9268. * raised with it, plus properties about the method and class from which the error originated (if raised from a
  9269. * class that uses the Ext 4 class system).
  9270. * @static
  9271. */
  9272. handle: function(){
  9273. return Ext.Error.ignore;
  9274. }
  9275. },
  9276. // This is the standard property that is the name of the constructor.
  9277. name: 'Ext.Error',
  9278. /**
  9279. * Creates new Error object.
  9280. * @param {String/Object} config The error message string, or an object containing the
  9281. * attribute "msg" that will be used as the error message. Any other data included in
  9282. * the object will be applied to the error instance and logged to the browser console, if available.
  9283. */
  9284. constructor: function(config){
  9285. if (Ext.isString(config)) {
  9286. config = { msg: config };
  9287. }
  9288. var me = this;
  9289. Ext.apply(me, config);
  9290. me.message = me.message || me.msg; // 'message' is standard ('msg' is non-standard)
  9291. // note: the above does not work in old WebKit (me.message is readonly) (Safari 4)
  9292. },
  9293. /**
  9294. * Provides a custom string representation of the error object. This is an override of the base JavaScript
  9295. * `Object.toString` method, which is useful so that when logged to the browser console, an error object will
  9296. * be displayed with a useful message instead of `[object Object]`, the default `toString` result.
  9297. *
  9298. * The default implementation will include the error message along with the raising class and method, if available,
  9299. * but this can be overridden with a custom implementation either at the prototype level (for all errors) or on
  9300. * a particular error instance, if you want to provide a custom description that will show up in the console.
  9301. * @return {String} The error message. If raised from within the Ext 4 class system, the error message will also
  9302. * include the raising class and method names, if available.
  9303. */
  9304. toString: function(){
  9305. var me = this,
  9306. className = me.sourceClass ? me.sourceClass : '',
  9307. methodName = me.sourceMethod ? '.' + me.sourceMethod + '(): ' : '',
  9308. msg = me.msg || '(No description provided)';
  9309. return className + methodName + msg;
  9310. }
  9311. });
  9312. /*
  9313. * Create a function that will throw an error if called (in debug mode) with a message that
  9314. * indicates the method has been removed.
  9315. * @param {String} suggestion Optional text to include in the message (a workaround perhaps).
  9316. * @return {Function} The generated function.
  9317. * @private
  9318. */
  9319. Ext.deprecated = function (suggestion) {
  9320. //<debug>
  9321. if (!suggestion) {
  9322. suggestion = '';
  9323. }
  9324. function fail () {
  9325. Ext.Error.raise('The method "' + fail.$owner.$className + '.' + fail.$name +
  9326. '" has been removed. ' + suggestion);
  9327. }
  9328. return fail;
  9329. //</debug>
  9330. return Ext.emptyFn;
  9331. };
  9332. /*
  9333. * This mechanism is used to notify the user of the first error encountered on the page. This
  9334. * was previously internal to Ext.Error.raise and is a desirable feature since errors often
  9335. * slip silently under the radar. It cannot live in Ext.Error.raise since there are times
  9336. * where exceptions are handled in a try/catch.
  9337. */
  9338. //<debug>
  9339. (function () {
  9340. var timer, errors = 0,
  9341. win = Ext.global,
  9342. msg;
  9343. if (typeof window === 'undefined') {
  9344. return; // build system or some such environment...
  9345. }
  9346. // This method is called to notify the user of the current error status.
  9347. function notify () {
  9348. var counters = Ext.log.counters,
  9349. supports = Ext.supports,
  9350. hasOnError = supports && supports.WindowOnError; // TODO - timing
  9351. // Put log counters to the status bar (for most browsers):
  9352. if (counters && (counters.error + counters.warn + counters.info + counters.log)) {
  9353. msg = [ 'Logged Errors:',counters.error, 'Warnings:',counters.warn,
  9354. 'Info:',counters.info, 'Log:',counters.log].join(' ');
  9355. if (errors) {
  9356. msg = '*** Errors: ' + errors + ' - ' + msg;
  9357. } else if (counters.error) {
  9358. msg = '*** ' + msg;
  9359. }
  9360. win.status = msg;
  9361. }
  9362. // Display an alert on the first error:
  9363. if (!Ext.isDefined(Ext.Error.notify)) {
  9364. Ext.Error.notify = Ext.isIE6 || Ext.isIE7; // TODO - timing
  9365. }
  9366. if (Ext.Error.notify && (hasOnError ? errors : (counters && counters.error))) {
  9367. Ext.Error.notify = false;
  9368. if (timer) {
  9369. win.clearInterval(timer); // ticks can queue up so stop...
  9370. timer = null;
  9371. }
  9372. alert('Unhandled error on page: See console or log');
  9373. poll();
  9374. }
  9375. }
  9376. // Sets up polling loop. This is the only way to know about errors in some browsers
  9377. // (Opera/Safari) and is the only way to update the status bar for warnings and other
  9378. // non-errors.
  9379. function poll () {
  9380. timer = win.setInterval(notify, 1000);
  9381. }
  9382. // window.onerror sounds ideal but it prevents the built-in error dialog from doing
  9383. // its (better) thing.
  9384. poll();
  9385. }());
  9386. //</debug>