ext-foundation-debug-w-comments.js 357 KB

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