dom.js 440 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436
  1. /**
  2. * @class Ext.util.DelayedTask
  3. *
  4. * The DelayedTask class provides a convenient way to "buffer" the execution of a method,
  5. * performing setTimeout where a new timeout cancels the old timeout. When called, the
  6. * task will wait the specified time period before executing. If durng that time period,
  7. * the task is called again, the original call will be cancelled. This continues so that
  8. * the function is only called a single time for each iteration.
  9. *
  10. * This method is especially useful for things like detecting whether a user has finished
  11. * typing in a text field. An example would be performing validation on a keypress. You can
  12. * use this class to buffer the keypress events for a certain number of milliseconds, and
  13. * perform only if they stop for that amount of time.
  14. *
  15. * ## Usage
  16. *
  17. * var task = new Ext.util.DelayedTask(function(){
  18. * alert(Ext.getDom('myInputField').value.length);
  19. * });
  20. *
  21. * // Wait 500ms before calling our function. If the user presses another key
  22. * // during that 500ms, it will be cancelled and we'll wait another 500ms.
  23. * Ext.get('myInputField').on('keypress', function(){
  24. * task.{@link #delay}(500);
  25. * });
  26. *
  27. * Note that we are using a DelayedTask here to illustrate a point. The configuration
  28. * option `buffer` for {@link Ext.util.Observable#addListener addListener/on} will
  29. * also setup a delayed task for you to buffer events.
  30. *
  31. * @constructor The parameters to this constructor serve as defaults and are not required.
  32. * @param {Function} fn (optional) The default function to call. If not specified here, it must be specified during the {@link #delay} call.
  33. * @param {Object} scope (optional) The default scope (The <code><b>this</b></code> reference) in which the
  34. * function is called. If not specified, <code>this</code> will refer to the browser window.
  35. * @param {Array} args (optional) The default Array of arguments.
  36. */
  37. Ext.util.DelayedTask = function(fn, scope, args) {
  38. var me = this,
  39. id,
  40. call = function() {
  41. clearInterval(id);
  42. id = null;
  43. fn.apply(scope, args || []);
  44. };
  45. /**
  46. * Cancels any pending timeout and queues a new one
  47. * @param {Number} delay The milliseconds to delay
  48. * @param {Function} newFn (optional) Overrides function passed to constructor
  49. * @param {Object} newScope (optional) Overrides scope passed to constructor. Remember that if no scope
  50. * is specified, <code>this</code> will refer to the browser window.
  51. * @param {Array} newArgs (optional) Overrides args passed to constructor
  52. */
  53. this.delay = function(delay, newFn, newScope, newArgs) {
  54. me.cancel();
  55. fn = newFn || fn;
  56. scope = newScope || scope;
  57. args = newArgs || args;
  58. id = setInterval(call, delay);
  59. };
  60. /**
  61. * Cancel the last queued timeout
  62. */
  63. this.cancel = function(){
  64. if (id) {
  65. clearInterval(id);
  66. id = null;
  67. }
  68. };
  69. };
  70. Ext.require('Ext.util.DelayedTask', function() {
  71. /**
  72. * Represents single event type that an Observable object listens to.
  73. * All actual listeners are tracked inside here. When the event fires,
  74. * it calls all the registered listener functions.
  75. *
  76. * @private
  77. */
  78. Ext.util.Event = Ext.extend(Object, (function() {
  79. var noOptions = {};
  80. function createTargeted(handler, listener, o, scope){
  81. return function(){
  82. if (o.target === arguments[0]){
  83. handler.apply(scope, arguments);
  84. }
  85. };
  86. }
  87. function createBuffered(handler, listener, o, scope) {
  88. listener.task = new Ext.util.DelayedTask();
  89. return function() {
  90. listener.task.delay(o.buffer, handler, scope, Ext.Array.toArray(arguments));
  91. };
  92. }
  93. function createDelayed(handler, listener, o, scope) {
  94. return function() {
  95. var task = new Ext.util.DelayedTask();
  96. if (!listener.tasks) {
  97. listener.tasks = [];
  98. }
  99. listener.tasks.push(task);
  100. task.delay(o.delay || 10, handler, scope, Ext.Array.toArray(arguments));
  101. };
  102. }
  103. function createSingle(handler, listener, o, scope) {
  104. return function() {
  105. var event = listener.ev;
  106. if (event.removeListener(listener.fn, scope) && event.observable) {
  107. // Removing from a regular Observable-owned, named event (not an anonymous
  108. // event such as Ext's readyEvent): Decrement the listeners count
  109. event.observable.hasListeners[event.name]--;
  110. }
  111. return handler.apply(scope, arguments);
  112. };
  113. }
  114. return {
  115. /**
  116. * @property {Boolean} isEvent
  117. * `true` in this class to identify an object as an instantiated Event, or subclass thereof.
  118. */
  119. isEvent: true,
  120. constructor: function(observable, name) {
  121. this.name = name;
  122. this.observable = observable;
  123. this.listeners = [];
  124. },
  125. addListener: function(fn, scope, options) {
  126. var me = this,
  127. listener;
  128. scope = scope || me.observable;
  129. //<debug error>
  130. if (!fn) {
  131. Ext.Error.raise({
  132. sourceClass: Ext.getClassName(this.observable),
  133. sourceMethod: "addListener",
  134. msg: "The specified callback function is undefined"
  135. });
  136. }
  137. //</debug>
  138. if (!me.isListening(fn, scope)) {
  139. listener = me.createListener(fn, scope, options);
  140. if (me.firing) {
  141. // if we are currently firing this event, don't disturb the listener loop
  142. me.listeners = me.listeners.slice(0);
  143. }
  144. me.listeners.push(listener);
  145. }
  146. },
  147. createListener: function(fn, scope, options) {
  148. options = options || noOptions;
  149. scope = scope || this.observable;
  150. var listener = {
  151. fn: fn,
  152. scope: scope,
  153. o: options,
  154. ev: this
  155. },
  156. handler = fn;
  157. // The order is important. The 'single' wrapper must be wrapped by the 'buffer' and 'delayed' wrapper
  158. // because the event removal that the single listener does destroys the listener's DelayedTask(s)
  159. if (options.single) {
  160. handler = createSingle(handler, listener, options, scope);
  161. }
  162. if (options.target) {
  163. handler = createTargeted(handler, listener, options, scope);
  164. }
  165. if (options.delay) {
  166. handler = createDelayed(handler, listener, options, scope);
  167. }
  168. if (options.buffer) {
  169. handler = createBuffered(handler, listener, options, scope);
  170. }
  171. listener.fireFn = handler;
  172. return listener;
  173. },
  174. findListener: function(fn, scope) {
  175. var listeners = this.listeners,
  176. i = listeners.length,
  177. listener,
  178. s;
  179. while (i--) {
  180. listener = listeners[i];
  181. if (listener) {
  182. s = listener.scope;
  183. // Compare the listener's scope with *JUST THE PASSED SCOPE* if one is passed, and only fall back to the owning Observable if none is passed.
  184. // We cannot use the test (s == scope || s == this.observable)
  185. // Otherwise, if the Observable itself adds Ext.emptyFn as a listener, and then Ext.emptyFn is added under another scope, there will be a false match.
  186. if (listener.fn == fn && (s == (scope || this.observable))) {
  187. return i;
  188. }
  189. }
  190. }
  191. return - 1;
  192. },
  193. isListening: function(fn, scope) {
  194. return this.findListener(fn, scope) !== -1;
  195. },
  196. removeListener: function(fn, scope) {
  197. var me = this,
  198. index,
  199. listener,
  200. k;
  201. index = me.findListener(fn, scope);
  202. if (index != -1) {
  203. listener = me.listeners[index];
  204. if (me.firing) {
  205. me.listeners = me.listeners.slice(0);
  206. }
  207. // cancel and remove a buffered handler that hasn't fired yet
  208. if (listener.task) {
  209. listener.task.cancel();
  210. delete listener.task;
  211. }
  212. // cancel and remove all delayed handlers that haven't fired yet
  213. k = listener.tasks && listener.tasks.length;
  214. if (k) {
  215. while (k--) {
  216. listener.tasks[k].cancel();
  217. }
  218. delete listener.tasks;
  219. }
  220. // remove this listener from the listeners array
  221. Ext.Array.erase(me.listeners, index, 1);
  222. return true;
  223. }
  224. return false;
  225. },
  226. // Iterate to stop any buffered/delayed events
  227. clearListeners: function() {
  228. var listeners = this.listeners,
  229. i = listeners.length;
  230. while (i--) {
  231. this.removeListener(listeners[i].fn, listeners[i].scope);
  232. }
  233. },
  234. fire: function() {
  235. var me = this,
  236. listeners = me.listeners,
  237. count = listeners.length,
  238. i,
  239. args,
  240. listener;
  241. if (count > 0) {
  242. me.firing = true;
  243. for (i = 0; i < count; i++) {
  244. listener = listeners[i];
  245. args = arguments.length ? Array.prototype.slice.call(arguments, 0) : [];
  246. if (listener.o) {
  247. args.push(listener.o);
  248. }
  249. if (listener && listener.fireFn.apply(listener.scope || me.observable, args) === false) {
  250. return (me.firing = false);
  251. }
  252. }
  253. }
  254. me.firing = false;
  255. return true;
  256. }
  257. };
  258. }()));
  259. });
  260. /**
  261. * @class Ext.EventManager
  262. * Registers event handlers that want to receive a normalized EventObject instead of the standard browser event and provides
  263. * several useful events directly.
  264. * See {@link Ext.EventObject} for more details on normalized event objects.
  265. * @singleton
  266. */
  267. Ext.EventManager = new function() {
  268. var EventManager = this,
  269. doc = document,
  270. win = window,
  271. initExtCss = function() {
  272. // find the body element
  273. var bd = doc.body || doc.getElementsByTagName('body')[0],
  274. baseCSSPrefix = Ext.baseCSSPrefix,
  275. cls = [baseCSSPrefix + 'body'],
  276. htmlCls = [],
  277. supportsLG = Ext.supports.CSS3LinearGradient,
  278. supportsBR = Ext.supports.CSS3BorderRadius,
  279. resetCls = [],
  280. html,
  281. resetElementSpec;
  282. if (!bd) {
  283. return false;
  284. }
  285. html = bd.parentNode;
  286. function add (c) {
  287. cls.push(baseCSSPrefix + c);
  288. }
  289. //Let's keep this human readable!
  290. if (Ext.isIE) {
  291. add('ie');
  292. // very often CSS needs to do checks like "IE7+" or "IE6 or 7". To help
  293. // reduce the clutter (since CSS/SCSS cannot do these tests), we add some
  294. // additional classes:
  295. //
  296. // x-ie7p : IE7+ : 7 <= ieVer
  297. // x-ie7m : IE7- : ieVer <= 7
  298. // x-ie8p : IE8+ : 8 <= ieVer
  299. // x-ie8m : IE8- : ieVer <= 8
  300. // x-ie9p : IE9+ : 9 <= ieVer
  301. // x-ie78 : IE7 or 8 : 7 <= ieVer <= 8
  302. //
  303. if (Ext.isIE6) {
  304. add('ie6');
  305. } else { // ignore pre-IE6 :)
  306. add('ie7p');
  307. if (Ext.isIE7) {
  308. add('ie7');
  309. } else {
  310. add('ie8p');
  311. if (Ext.isIE8) {
  312. add('ie8');
  313. } else {
  314. add('ie9p');
  315. if (Ext.isIE9) {
  316. add('ie9');
  317. }
  318. }
  319. }
  320. }
  321. if (Ext.isIE6 || Ext.isIE7) {
  322. add('ie7m');
  323. }
  324. if (Ext.isIE6 || Ext.isIE7 || Ext.isIE8) {
  325. add('ie8m');
  326. }
  327. if (Ext.isIE7 || Ext.isIE8) {
  328. add('ie78');
  329. }
  330. }
  331. if (Ext.isGecko) {
  332. add('gecko');
  333. if (Ext.isGecko3) {
  334. add('gecko3');
  335. }
  336. if (Ext.isGecko4) {
  337. add('gecko4');
  338. }
  339. if (Ext.isGecko5) {
  340. add('gecko5');
  341. }
  342. }
  343. if (Ext.isOpera) {
  344. add('opera');
  345. }
  346. if (Ext.isWebKit) {
  347. add('webkit');
  348. }
  349. if (Ext.isSafari) {
  350. add('safari');
  351. if (Ext.isSafari2) {
  352. add('safari2');
  353. }
  354. if (Ext.isSafari3) {
  355. add('safari3');
  356. }
  357. if (Ext.isSafari4) {
  358. add('safari4');
  359. }
  360. if (Ext.isSafari5) {
  361. add('safari5');
  362. }
  363. if (Ext.isSafari5_0) {
  364. add('safari5_0')
  365. }
  366. }
  367. if (Ext.isChrome) {
  368. add('chrome');
  369. }
  370. if (Ext.isMac) {
  371. add('mac');
  372. }
  373. if (Ext.isLinux) {
  374. add('linux');
  375. }
  376. if (!supportsBR) {
  377. add('nbr');
  378. }
  379. if (!supportsLG) {
  380. add('nlg');
  381. }
  382. // If we are not globally resetting scope, but just resetting it in a wrapper around
  383. // serarately rendered widgets, then create a common reset element for use when creating
  384. // measurable elements. Using a common DomHelper spec.
  385. if (Ext.scopeResetCSS) {
  386. // Create Ext.resetElementSpec for use in Renderable when wrapping top level Components.
  387. resetElementSpec = Ext.resetElementSpec = {
  388. cls: baseCSSPrefix + 'reset'
  389. };
  390. if (!supportsLG) {
  391. resetCls.push(baseCSSPrefix + 'nlg');
  392. }
  393. if (!supportsBR) {
  394. resetCls.push(baseCSSPrefix + 'nbr');
  395. }
  396. if (resetCls.length) {
  397. resetElementSpec.cn = {
  398. cls: resetCls.join(' ')
  399. };
  400. }
  401. Ext.resetElement = Ext.getBody().createChild(resetElementSpec);
  402. if (resetCls.length) {
  403. Ext.resetElement = Ext.get(Ext.resetElement.dom.firstChild);
  404. }
  405. }
  406. // Otherwise, the common reset element is the document body
  407. else {
  408. Ext.resetElement = Ext.getBody();
  409. add('reset');
  410. }
  411. // add to the parent to allow for selectors x-strict x-border-box, also set the isBorderBox property correctly
  412. if (html) {
  413. if (Ext.isStrict && (Ext.isIE6 || Ext.isIE7)) {
  414. Ext.isBorderBox = false;
  415. }
  416. else {
  417. Ext.isBorderBox = true;
  418. }
  419. if(Ext.isBorderBox) {
  420. htmlCls.push(baseCSSPrefix + 'border-box');
  421. }
  422. if (Ext.isStrict) {
  423. htmlCls.push(baseCSSPrefix + 'strict');
  424. } else {
  425. htmlCls.push(baseCSSPrefix + 'quirks');
  426. }
  427. Ext.fly(html, '_internal').addCls(htmlCls);
  428. }
  429. Ext.fly(bd, '_internal').addCls(cls);
  430. return true;
  431. };
  432. Ext.apply(EventManager, {
  433. /**
  434. * Check if we have bound our global onReady listener
  435. * @private
  436. */
  437. hasBoundOnReady: false,
  438. /**
  439. * Check if fireDocReady has been called
  440. * @private
  441. */
  442. hasFiredReady: false,
  443. /**
  444. * Additionally, allow the 'DOM' listener thread to complete (usually desirable with mobWebkit, Gecko)
  445. * before firing the entire onReady chain (high stack load on Loader) by specifying a delay value
  446. * @default 1ms
  447. * @private
  448. */
  449. deferReadyEvent : 1,
  450. /*
  451. * diags: a list of event names passed to onReadyEvent (in chron order)
  452. * @private
  453. */
  454. onReadyChain : [],
  455. /**
  456. * Holds references to any onReady functions
  457. * @private
  458. */
  459. readyEvent:
  460. (function () {
  461. var event = new Ext.util.Event();
  462. event.fire = function () {
  463. Ext._beforeReadyTime = Ext._beforeReadyTime || new Date().getTime();
  464. event.self.prototype.fire.apply(event, arguments);
  465. Ext._afterReadytime = new Date().getTime();
  466. };
  467. return event;
  468. }()),
  469. /**
  470. * Fires when a DOM event handler finishes its run, just before returning to browser control.
  471. * This can be useful for performing cleanup, or upfdate tasks which need to happen only
  472. * after all code in an event handler has been run, but which should not be executed in a timer
  473. * due to the intervening browser reflow/repaint which would take place.
  474. *
  475. */
  476. idleEvent: new Ext.util.Event(),
  477. /**
  478. * detects whether the EventManager has been placed in a paused state for synchronization
  479. * with external debugging / perf tools (PageAnalyzer)
  480. * @private
  481. */
  482. isReadyPaused: function(){
  483. return (/[?&]ext-pauseReadyFire\b/i.test(location.search) && !Ext._continueFireReady);
  484. },
  485. /**
  486. * Binds the appropriate browser event for checking if the DOM has loaded.
  487. * @private
  488. */
  489. bindReadyEvent: function() {
  490. if (EventManager.hasBoundOnReady) {
  491. return;
  492. }
  493. // Test scenario where Core is dynamically loaded AFTER window.load
  494. if ( doc.readyState == 'complete' ) { // Firefox4+ got support for this state, others already do.
  495. EventManager.onReadyEvent({
  496. type: doc.readyState || 'body'
  497. });
  498. } else {
  499. document.addEventListener('DOMContentLoaded', EventManager.onReadyEvent, false);
  500. window.addEventListener('load', EventManager.onReadyEvent, false);
  501. EventManager.hasBoundOnReady = true;
  502. }
  503. },
  504. onReadyEvent : function(e) {
  505. if (e && e.type) {
  506. EventManager.onReadyChain.push(e.type);
  507. }
  508. if (EventManager.hasBoundOnReady) {
  509. document.removeEventListener('DOMContentLoaded', EventManager.onReadyEvent, false);
  510. window.removeEventListener('load', EventManager.onReadyEvent, false);
  511. }
  512. if (!Ext.isReady) {
  513. EventManager.fireDocReady();
  514. }
  515. },
  516. /**
  517. * We know the document is loaded, so trigger any onReady events.
  518. * @private
  519. */
  520. fireDocReady: function() {
  521. if (!Ext.isReady) {
  522. Ext._readyTime = new Date().getTime();
  523. Ext.isReady = true;
  524. Ext.supports.init();
  525. EventManager.onWindowUnload();
  526. EventManager.readyEvent.onReadyChain = EventManager.onReadyChain; //diags report
  527. if (Ext.isNumber(EventManager.deferReadyEvent)) {
  528. Ext.Function.defer(EventManager.fireReadyEvent, EventManager.deferReadyEvent);
  529. EventManager.hasDocReadyTimer = true;
  530. } else {
  531. EventManager.fireReadyEvent();
  532. }
  533. }
  534. },
  535. /**
  536. * Fires the ready event
  537. * @private
  538. */
  539. fireReadyEvent: function(){
  540. var readyEvent = EventManager.readyEvent;
  541. // Unset the timer flag here since other onReady events may be
  542. // added during the fire() call and we don't want to block them
  543. EventManager.hasDocReadyTimer = false;
  544. EventManager.isFiring = true;
  545. // Ready events are all single: true, if we get to the end
  546. // & there are more listeners, it means they were added
  547. // inside some other ready event
  548. while (readyEvent.listeners.length && !EventManager.isReadyPaused()) {
  549. readyEvent.fire();
  550. }
  551. EventManager.isFiring = false;
  552. EventManager.hasFiredReady = true;
  553. },
  554. /**
  555. * Adds a listener to be notified when the document is ready (before onload and before images are loaded).
  556. *
  557. * @param {Function} fn The method the event invokes.
  558. * @param {Object} [scope] The scope (`this` reference) in which the handler function executes.
  559. * Defaults to the browser window.
  560. * @param {Object} [options] Options object as passed to {@link Ext.Element#addListener}.
  561. */
  562. onDocumentReady: function(fn, scope, options) {
  563. options = options || {};
  564. // force single, only ever fire it once
  565. options.single = true;
  566. EventManager.readyEvent.addListener(fn, scope, options);
  567. // If we're in the middle of firing, or we have a deferred timer
  568. // pending, drop out since the event will be fired later
  569. if (!(EventManager.isFiring || EventManager.hasDocReadyTimer)) {
  570. if (Ext.isReady) {
  571. EventManager.fireReadyEvent();
  572. } else {
  573. EventManager.bindReadyEvent();
  574. }
  575. }
  576. },
  577. // --------------------- event binding ---------------------
  578. /**
  579. * Contains a list of all document mouse downs, so we can ensure they fire even when stopEvent is called.
  580. * @private
  581. */
  582. stoppedMouseDownEvent: new Ext.util.Event(),
  583. /**
  584. * Options to parse for the 4th argument to addListener.
  585. * @private
  586. */
  587. propRe: /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate|freezeEvent)$/,
  588. /**
  589. * Get the id of the element. If one has not been assigned, automatically assign it.
  590. * @param {HTMLElement/Ext.Element} element The element to get the id for.
  591. * @return {String} id
  592. */
  593. getId : function(element) {
  594. var id;
  595. element = Ext.getDom(element);
  596. if (element === doc || element === win) {
  597. id = element === doc ? Ext.documentId : Ext.windowId;
  598. }
  599. else {
  600. id = Ext.id(element);
  601. }
  602. if (!Ext.cache[id]) {
  603. Ext.addCacheEntry(id, null, element);
  604. }
  605. return id;
  606. },
  607. /**
  608. * Convert a "config style" listener into a set of flat arguments so they can be passed to addListener
  609. * @private
  610. * @param {Object} element The element the event is for
  611. * @param {Object} event The event configuration
  612. * @param {Object} isRemove True if a removal should be performed, otherwise an add will be done.
  613. */
  614. prepareListenerConfig: function(element, config, isRemove) {
  615. var propRe = EventManager.propRe,
  616. key, value, args;
  617. // loop over all the keys in the object
  618. for (key in config) {
  619. if (config.hasOwnProperty(key)) {
  620. // if the key is something else then an event option
  621. if (!propRe.test(key)) {
  622. value = config[key];
  623. // if the value is a function it must be something like click: function() {}, scope: this
  624. // which means that there might be multiple event listeners with shared options
  625. if (typeof value == 'function') {
  626. // shared options
  627. args = [element, key, value, config.scope, config];
  628. } else {
  629. // if its not a function, it must be an object like click: {fn: function() {}, scope: this}
  630. args = [element, key, value.fn, value.scope, value];
  631. }
  632. if (isRemove) {
  633. EventManager.removeListener.apply(EventManager, args);
  634. } else {
  635. EventManager.addListener.apply(EventManager, args);
  636. }
  637. }
  638. }
  639. }
  640. },
  641. mouseEnterLeaveRe: /mouseenter|mouseleave/,
  642. /**
  643. * Normalize cross browser event differences
  644. * @private
  645. * @param {Object} eventName The event name
  646. * @param {Object} fn The function to execute
  647. * @return {Object} The new event name/function
  648. */
  649. normalizeEvent: function(eventName, fn) {
  650. if (EventManager.mouseEnterLeaveRe.test(eventName) && !Ext.supports.MouseEnterLeave) {
  651. if (fn) {
  652. fn = Ext.Function.createInterceptor(fn, EventManager.contains);
  653. }
  654. eventName = eventName == 'mouseenter' ? 'mouseover' : 'mouseout';
  655. } else if (eventName == 'mousewheel' && !Ext.supports.MouseWheel && !Ext.isOpera) {
  656. eventName = 'DOMMouseScroll';
  657. }
  658. return {
  659. eventName: eventName,
  660. fn: fn
  661. };
  662. },
  663. /**
  664. * Checks whether the event's relatedTarget is contained inside (or <b>is</b>) the element.
  665. * @private
  666. * @param {Object} event
  667. */
  668. contains: function(event) {
  669. var parent = event.browserEvent.currentTarget,
  670. child = EventManager.getRelatedTarget(event);
  671. if (parent && parent.firstChild) {
  672. while (child) {
  673. if (child === parent) {
  674. return false;
  675. }
  676. child = child.parentNode;
  677. if (child && (child.nodeType != 1)) {
  678. child = null;
  679. }
  680. }
  681. }
  682. return true;
  683. },
  684. /**
  685. * Appends an event handler to an element. The shorthand version {@link #on} is equivalent. Typically you will
  686. * use {@link Ext.Element#addListener} directly on an Element in favor of calling this version.
  687. * @param {String/HTMLElement} el The html element or id to assign the event handler to.
  688. * @param {String} eventName The name of the event to listen for.
  689. * @param {Function} handler The handler function the event invokes. This function is passed
  690. * the following parameters:<ul>
  691. * <li>evt : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li>
  692. * <li>t : Element<div class="sub-desc">The {@link Ext.Element Element} which was the target of the event.
  693. * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li>
  694. * <li>o : Object<div class="sub-desc">The options object from the addListener call.</div></li>
  695. * </ul>
  696. * @param {Object} scope (optional) The scope (<b><code>this</code></b> reference) in which the handler function is executed. <b>Defaults to the Element</b>.
  697. * @param {Object} options (optional) An object containing handler configuration properties.
  698. * This may contain any of the following properties:<ul>
  699. * <li>scope : Object<div class="sub-desc">The scope (<b><code>this</code></b> reference) in which the handler function is executed. <b>Defaults to the Element</b>.</div></li>
  700. * <li>delegate : String<div class="sub-desc">A simple selector to filter the target or look for a descendant of the target</div></li>
  701. * <li>stopEvent : Boolean<div class="sub-desc">True to stop the event. That is stop propagation, and prevent the default action.</div></li>
  702. * <li>preventDefault : Boolean<div class="sub-desc">True to prevent the default action</div></li>
  703. * <li>stopPropagation : Boolean<div class="sub-desc">True to prevent event propagation</div></li>
  704. * <li>normalized : Boolean<div class="sub-desc">False to pass a browser event to the handler function instead of an Ext.EventObject</div></li>
  705. * <li>delay : Number<div class="sub-desc">The number of milliseconds to delay the invocation of the handler after te event fires.</div></li>
  706. * <li>single : Boolean<div class="sub-desc">True to add a handler to handle just the next firing of the event, and then remove itself.</div></li>
  707. * <li>buffer : Number<div class="sub-desc">Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
  708. * by the specified number of milliseconds. If the event fires again within that time, the original
  709. * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li>
  710. * <li>target : Element<div class="sub-desc">Only call the handler if the event was fired on the target Element, <i>not</i> if the event was bubbled up from a child node.</div></li>
  711. * </ul><br>
  712. * <p>See {@link Ext.Element#addListener} for examples of how to use these options.</p>
  713. */
  714. addListener: function(element, eventName, fn, scope, options) {
  715. // Check if we've been passed a "config style" event.
  716. if (typeof eventName !== 'string') {
  717. EventManager.prepareListenerConfig(element, eventName);
  718. return;
  719. }
  720. var dom = element.dom || Ext.getDom(element),
  721. bind, wrap;
  722. //<debug>
  723. if (!fn) {
  724. Ext.Error.raise({
  725. sourceClass: 'Ext.EventManager',
  726. sourceMethod: 'addListener',
  727. targetElement: element,
  728. eventName: eventName,
  729. msg: 'Error adding "' + eventName + '\" listener. The handler function is undefined.'
  730. });
  731. }
  732. //</debug>
  733. // create the wrapper function
  734. options = options || {};
  735. bind = EventManager.normalizeEvent(eventName, fn);
  736. wrap = EventManager.createListenerWrap(dom, eventName, bind.fn, scope, options);
  737. if (dom.attachEvent) {
  738. dom.attachEvent('on' + bind.eventName, wrap);
  739. } else {
  740. dom.addEventListener(bind.eventName, wrap, options.capture || false);
  741. }
  742. if (dom == doc && eventName == 'mousedown') {
  743. EventManager.stoppedMouseDownEvent.addListener(wrap);
  744. }
  745. // add all required data into the event cache
  746. EventManager.getEventListenerCache(element.dom ? element : dom, eventName).push({
  747. fn: fn,
  748. wrap: wrap,
  749. scope: scope
  750. });
  751. },
  752. /**
  753. * Removes an event handler from an element. The shorthand version {@link #un} is equivalent. Typically
  754. * you will use {@link Ext.Element#removeListener} directly on an Element in favor of calling this version.
  755. * @param {String/HTMLElement} el The id or html element from which to remove the listener.
  756. * @param {String} eventName The name of the event.
  757. * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
  758. * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
  759. * then this must refer to the same object.
  760. */
  761. removeListener : function(element, eventName, fn, scope) {
  762. // handle our listener config object syntax
  763. if (typeof eventName !== 'string') {
  764. EventManager.prepareListenerConfig(element, eventName, true);
  765. return;
  766. }
  767. var dom = Ext.getDom(element),
  768. el = element.dom ? element : Ext.get(dom),
  769. cache = EventManager.getEventListenerCache(el, eventName),
  770. bindName = EventManager.normalizeEvent(eventName).eventName,
  771. i = cache.length, j,
  772. listener, wrap, tasks;
  773. while (i--) {
  774. listener = cache[i];
  775. if (listener && (!fn || listener.fn == fn) && (!scope || listener.scope === scope)) {
  776. wrap = listener.wrap;
  777. // clear buffered calls
  778. if (wrap.task) {
  779. clearTimeout(wrap.task);
  780. delete wrap.task;
  781. }
  782. // clear delayed calls
  783. j = wrap.tasks && wrap.tasks.length;
  784. if (j) {
  785. while (j--) {
  786. clearTimeout(wrap.tasks[j]);
  787. }
  788. delete wrap.tasks;
  789. }
  790. if (dom.detachEvent) {
  791. dom.detachEvent('on' + bindName, wrap);
  792. } else {
  793. dom.removeEventListener(bindName, wrap, false);
  794. }
  795. if (wrap && dom == doc && eventName == 'mousedown') {
  796. EventManager.stoppedMouseDownEvent.removeListener(wrap);
  797. }
  798. // remove listener from cache
  799. Ext.Array.erase(cache, i, 1);
  800. }
  801. }
  802. },
  803. /**
  804. * Removes all event handers from an element. Typically you will use {@link Ext.Element#removeAllListeners}
  805. * directly on an Element in favor of calling this version.
  806. * @param {String/HTMLElement} el The id or html element from which to remove all event handlers.
  807. */
  808. removeAll : function(element) {
  809. var el = element.dom ? element : Ext.get(element),
  810. cache, events, eventName;
  811. if (!el) {
  812. return;
  813. }
  814. cache = (el.$cache || el.getCache());
  815. events = cache.events;
  816. for (eventName in events) {
  817. if (events.hasOwnProperty(eventName)) {
  818. EventManager.removeListener(el, eventName);
  819. }
  820. }
  821. cache.events = {};
  822. },
  823. /**
  824. * Recursively removes all previous added listeners from an element and its children. Typically you will use {@link Ext.Element#purgeAllListeners}
  825. * directly on an Element in favor of calling this version.
  826. * @param {String/HTMLElement} el The id or html element from which to remove all event handlers.
  827. * @param {String} eventName (optional) The name of the event.
  828. */
  829. purgeElement : function(element, eventName) {
  830. var dom = Ext.getDom(element),
  831. i = 0, len;
  832. if (eventName) {
  833. EventManager.removeListener(element, eventName);
  834. }
  835. else {
  836. EventManager.removeAll(element);
  837. }
  838. if (dom && dom.childNodes) {
  839. for (len = element.childNodes.length; i < len; i++) {
  840. EventManager.purgeElement(element.childNodes[i], eventName);
  841. }
  842. }
  843. },
  844. /**
  845. * Create the wrapper function for the event
  846. * @private
  847. * @param {HTMLElement} dom The dom element
  848. * @param {String} ename The event name
  849. * @param {Function} fn The function to execute
  850. * @param {Object} scope The scope to execute callback in
  851. * @param {Object} options The options
  852. * @return {Function} the wrapper function
  853. */
  854. createListenerWrap : function(dom, ename, fn, scope, options) {
  855. options = options || {};
  856. var f, gen, escapeRx = /\\/g, wrap = function(e, args) {
  857. // Compile the implementation upon first firing
  858. if (!gen) {
  859. f = ['if(!' + Ext.name + ') {return;}'];
  860. if(options.buffer || options.delay || options.freezeEvent) {
  861. f.push('e = new X.EventObjectImpl(e, ' + (options.freezeEvent ? 'true' : 'false' ) + ');');
  862. } else {
  863. f.push('e = X.EventObject.setEvent(e);');
  864. }
  865. if (options.delegate) {
  866. // double up '\' characters so escape sequences survive the
  867. // string-literal translation
  868. f.push('var result, t = e.getTarget("' + (options.delegate + '').replace(escapeRx, '\\\\') + '", this);');
  869. f.push('if(!t) {return;}');
  870. } else {
  871. f.push('var t = e.target, result;');
  872. }
  873. if (options.target) {
  874. f.push('if(e.target !== options.target) {return;}');
  875. }
  876. if(options.stopEvent) {
  877. f.push('e.stopEvent();');
  878. } else {
  879. if(options.preventDefault) {
  880. f.push('e.preventDefault();');
  881. }
  882. if(options.stopPropagation) {
  883. f.push('e.stopPropagation();');
  884. }
  885. }
  886. if(options.normalized === false) {
  887. f.push('e = e.browserEvent;');
  888. }
  889. if(options.buffer) {
  890. f.push('(wrap.task && clearTimeout(wrap.task));');
  891. f.push('wrap.task = setTimeout(function() {');
  892. }
  893. if(options.delay) {
  894. f.push('wrap.tasks = wrap.tasks || [];');
  895. f.push('wrap.tasks.push(setTimeout(function() {');
  896. }
  897. // finally call the actual handler fn
  898. f.push('result = fn.call(scope || dom, e, t, options);');
  899. if(options.single) {
  900. f.push('evtMgr.removeListener(dom, ename, fn, scope);');
  901. }
  902. // Fire the global idle event for all events except mousemove which is too common, and
  903. // fires too frequently and fast to be use in tiggering onIdle processing.
  904. if (ename !== 'mousemove') {
  905. f.push('if (evtMgr.idleEvent.listeners.length) {');
  906. f.push('evtMgr.idleEvent.fire();');
  907. f.push('}');
  908. }
  909. if(options.delay) {
  910. f.push('}, ' + options.delay + '));');
  911. }
  912. if(options.buffer) {
  913. f.push('}, ' + options.buffer + ');');
  914. }
  915. f.push('return result;')
  916. gen = Ext.cacheableFunctionFactory('e', 'options', 'fn', 'scope', 'ename', 'dom', 'wrap', 'args', 'X', 'evtMgr', f.join('\n'));
  917. }
  918. return gen.call(dom, e, options, fn, scope, ename, dom, wrap, args, Ext, EventManager);
  919. };
  920. return wrap;
  921. },
  922. /**
  923. * Get the event cache for a particular element for a particular event
  924. * @private
  925. * @param {HTMLElement} element The element
  926. * @param {Object} eventName The event name
  927. * @return {Array} The events for the element
  928. */
  929. getEventListenerCache : function(element, eventName) {
  930. var elementCache, eventCache;
  931. if (!element) {
  932. return [];
  933. }
  934. if (element.$cache) {
  935. elementCache = element.$cache;
  936. } else {
  937. // getId will populate the cache for this element if it isn't already present
  938. elementCache = Ext.cache[EventManager.getId(element)];
  939. }
  940. eventCache = elementCache.events || (elementCache.events = {});
  941. return eventCache[eventName] || (eventCache[eventName] = []);
  942. },
  943. // --------------------- utility methods ---------------------
  944. mouseLeaveRe: /(mouseout|mouseleave)/,
  945. mouseEnterRe: /(mouseover|mouseenter)/,
  946. /**
  947. * Stop the event (preventDefault and stopPropagation)
  948. * @param {Event} The event to stop
  949. */
  950. stopEvent: function(event) {
  951. EventManager.stopPropagation(event);
  952. EventManager.preventDefault(event);
  953. },
  954. /**
  955. * Cancels bubbling of the event.
  956. * @param {Event} The event to stop bubbling.
  957. */
  958. stopPropagation: function(event) {
  959. event = event.browserEvent || event;
  960. if (event.stopPropagation) {
  961. event.stopPropagation();
  962. } else {
  963. event.cancelBubble = true;
  964. }
  965. },
  966. /**
  967. * Prevents the browsers default handling of the event.
  968. * @param {Event} The event to prevent the default
  969. */
  970. preventDefault: function(event) {
  971. event = event.browserEvent || event;
  972. if (event.preventDefault) {
  973. event.preventDefault();
  974. } else {
  975. event.returnValue = false;
  976. // Some keys events require setting the keyCode to -1 to be prevented
  977. try {
  978. // all ctrl + X and F1 -> F12
  979. if (event.ctrlKey || event.keyCode > 111 && event.keyCode < 124) {
  980. event.keyCode = -1;
  981. }
  982. } catch (e) {
  983. // see this outdated document http://support.microsoft.com/kb/934364/en-us for more info
  984. }
  985. }
  986. },
  987. /**
  988. * Gets the related target from the event.
  989. * @param {Object} event The event
  990. * @return {HTMLElement} The related target.
  991. */
  992. getRelatedTarget: function(event) {
  993. event = event.browserEvent || event;
  994. var target = event.relatedTarget;
  995. if (!target) {
  996. if (EventManager.mouseLeaveRe.test(event.type)) {
  997. target = event.toElement;
  998. } else if (EventManager.mouseEnterRe.test(event.type)) {
  999. target = event.fromElement;
  1000. }
  1001. }
  1002. return EventManager.resolveTextNode(target);
  1003. },
  1004. /**
  1005. * Gets the x coordinate from the event
  1006. * @param {Object} event The event
  1007. * @return {Number} The x coordinate
  1008. */
  1009. getPageX: function(event) {
  1010. return EventManager.getPageXY(event)[0];
  1011. },
  1012. /**
  1013. * Gets the y coordinate from the event
  1014. * @param {Object} event The event
  1015. * @return {Number} The y coordinate
  1016. */
  1017. getPageY: function(event) {
  1018. return EventManager.getPageXY(event)[1];
  1019. },
  1020. /**
  1021. * Gets the x & y coordinate from the event
  1022. * @param {Object} event The event
  1023. * @return {Number[]} The x/y coordinate
  1024. */
  1025. getPageXY: function(event) {
  1026. event = event.browserEvent || event;
  1027. var x = event.pageX,
  1028. y = event.pageY,
  1029. docEl = doc.documentElement,
  1030. body = doc.body;
  1031. // pageX/pageY not available (undefined, not null), use clientX/clientY instead
  1032. if (!x && x !== 0) {
  1033. x = event.clientX + (docEl && docEl.scrollLeft || body && body.scrollLeft || 0) - (docEl && docEl.clientLeft || body && body.clientLeft || 0);
  1034. y = event.clientY + (docEl && docEl.scrollTop || body && body.scrollTop || 0) - (docEl && docEl.clientTop || body && body.clientTop || 0);
  1035. }
  1036. return [x, y];
  1037. },
  1038. /**
  1039. * Gets the target of the event.
  1040. * @param {Object} event The event
  1041. * @return {HTMLElement} target
  1042. */
  1043. getTarget: function(event) {
  1044. event = event.browserEvent || event;
  1045. return EventManager.resolveTextNode(event.target || event.srcElement);
  1046. },
  1047. // technically no need to browser sniff this, however it makes
  1048. // no sense to check this every time, for every event, whether
  1049. // the string is equal.
  1050. /**
  1051. * Resolve any text nodes accounting for browser differences.
  1052. * @private
  1053. * @param {HTMLElement} node The node
  1054. * @return {HTMLElement} The resolved node
  1055. */
  1056. resolveTextNode: Ext.isGecko ?
  1057. function(node) {
  1058. if (!node) {
  1059. return;
  1060. }
  1061. // work around firefox bug, https://bugzilla.mozilla.org/show_bug.cgi?id=101197
  1062. var s = HTMLElement.prototype.toString.call(node);
  1063. if (s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]') {
  1064. return;
  1065. }
  1066. return node.nodeType == 3 ? node.parentNode: node;
  1067. }: function(node) {
  1068. return node && node.nodeType == 3 ? node.parentNode: node;
  1069. },
  1070. // --------------------- custom event binding ---------------------
  1071. // Keep track of the current width/height
  1072. curWidth: 0,
  1073. curHeight: 0,
  1074. /**
  1075. * Adds a listener to be notified when the browser window is resized and provides resize event buffering (100 milliseconds),
  1076. * passes new viewport width and height to handlers.
  1077. * @param {Function} fn The handler function the window resize event invokes.
  1078. * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
  1079. * @param {Boolean} options Options object as passed to {@link Ext.Element#addListener}
  1080. */
  1081. onWindowResize: function(fn, scope, options) {
  1082. var resize = EventManager.resizeEvent;
  1083. if (!resize) {
  1084. EventManager.resizeEvent = resize = new Ext.util.Event();
  1085. EventManager.on(win, 'resize', EventManager.fireResize, null, {buffer: 100});
  1086. }
  1087. resize.addListener(fn, scope, options);
  1088. },
  1089. /**
  1090. * Fire the resize event.
  1091. * @private
  1092. */
  1093. fireResize: function() {
  1094. var w = Ext.Element.getViewWidth(),
  1095. h = Ext.Element.getViewHeight();
  1096. //whacky problem in IE where the resize event will sometimes fire even though the w/h are the same.
  1097. if (EventManager.curHeight != h || EventManager.curWidth != w) {
  1098. EventManager.curHeight = h;
  1099. EventManager.curWidth = w;
  1100. EventManager.resizeEvent.fire(w, h);
  1101. }
  1102. },
  1103. /**
  1104. * Removes the passed window resize listener.
  1105. * @param {Function} fn The method the event invokes
  1106. * @param {Object} scope The scope of handler
  1107. */
  1108. removeResizeListener: function(fn, scope) {
  1109. var resize = EventManager.resizeEvent;
  1110. if (resize) {
  1111. resize.removeListener(fn, scope);
  1112. }
  1113. },
  1114. /**
  1115. * Adds a listener to be notified when the browser window is unloaded.
  1116. * @param {Function} fn The handler function the window unload event invokes.
  1117. * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
  1118. * @param {Boolean} options Options object as passed to {@link Ext.Element#addListener}
  1119. */
  1120. onWindowUnload: function(fn, scope, options) {
  1121. var unload = EventManager.unloadEvent;
  1122. if (!unload) {
  1123. EventManager.unloadEvent = unload = new Ext.util.Event();
  1124. EventManager.addListener(win, 'unload', EventManager.fireUnload);
  1125. }
  1126. if (fn) {
  1127. unload.addListener(fn, scope, options);
  1128. }
  1129. },
  1130. /**
  1131. * Fires the unload event for items bound with onWindowUnload
  1132. * @private
  1133. */
  1134. fireUnload: function() {
  1135. // wrap in a try catch, could have some problems during unload
  1136. try {
  1137. // relinquish references.
  1138. doc = win = undefined;
  1139. var gridviews, i, ln,
  1140. el, cache;
  1141. EventManager.unloadEvent.fire();
  1142. // Work around FF3 remembering the last scroll position when refreshing the grid and then losing grid view
  1143. if (Ext.isGecko3) {
  1144. gridviews = Ext.ComponentQuery.query('gridview');
  1145. i = 0;
  1146. ln = gridviews.length;
  1147. for (; i < ln; i++) {
  1148. gridviews[i].scrollToTop();
  1149. }
  1150. }
  1151. // Purge all elements in the cache
  1152. cache = Ext.cache;
  1153. for (el in cache) {
  1154. if (cache.hasOwnProperty(el)) {
  1155. EventManager.removeAll(el);
  1156. }
  1157. }
  1158. } catch(e) {
  1159. }
  1160. },
  1161. /**
  1162. * Removes the passed window unload listener.
  1163. * @param {Function} fn The method the event invokes
  1164. * @param {Object} scope The scope of handler
  1165. */
  1166. removeUnloadListener: function(fn, scope) {
  1167. var unload = EventManager.unloadEvent;
  1168. if (unload) {
  1169. unload.removeListener(fn, scope);
  1170. }
  1171. },
  1172. /**
  1173. * note 1: IE fires ONLY the keydown event on specialkey autorepeat
  1174. * note 2: Safari < 3.1, Gecko (Mac/Linux) & Opera fire only the keypress event on specialkey autorepeat
  1175. * (research done by Jan Wolter at http://unixpapa.com/js/key.html)
  1176. * @private
  1177. */
  1178. useKeyDown: Ext.isWebKit ?
  1179. parseInt(navigator.userAgent.match(/AppleWebKit\/(\d+)/)[1], 10) >= 525 :
  1180. !((Ext.isGecko && !Ext.isWindows) || Ext.isOpera),
  1181. /**
  1182. * Indicates which event to use for getting key presses.
  1183. * @return {String} The appropriate event name.
  1184. */
  1185. getKeyEvent: function() {
  1186. return EventManager.useKeyDown ? 'keydown' : 'keypress';
  1187. }
  1188. });
  1189. // route "< ie9-Standards" to a legacy IE onReady implementation
  1190. if(!('addEventListener' in document) && document.attachEvent) {
  1191. Ext.apply( EventManager, {
  1192. /* Customized implementation for Legacy IE. The default implementation is configured for use
  1193. * with all other 'standards compliant' agents.
  1194. * References: http://javascript.nwbox.com/IEContentLoaded/
  1195. * licensed courtesy of http://developer.yahoo.com/yui/license.html
  1196. */
  1197. /**
  1198. * This strategy has minimal benefits for Sencha solutions that build themselves (ie. minimal initial page markup).
  1199. * However, progressively-enhanced pages (with image content and/or embedded frames) will benefit the most from it.
  1200. * Browser timer resolution is too poor to ensure a doScroll check more than once on a page loaded with minimal
  1201. * assets (the readystatechange event 'complete' usually beats the doScroll timer on a 'lightly-loaded' initial document).
  1202. */
  1203. pollScroll : function() {
  1204. var scrollable = true;
  1205. try {
  1206. document.documentElement.doScroll('left');
  1207. } catch(e) {
  1208. scrollable = false;
  1209. }
  1210. // on IE8, when running within an iFrame, document.body is not immediately available
  1211. if (scrollable && document.body) {
  1212. EventManager.onReadyEvent({
  1213. type:'doScroll'
  1214. });
  1215. } else {
  1216. /*
  1217. * minimize thrashing --
  1218. * adjusted for setTimeout's close-to-minimums (not too low),
  1219. * as this method SHOULD always be called once initially
  1220. */
  1221. EventManager.scrollTimeout = setTimeout(EventManager.pollScroll, 20);
  1222. }
  1223. return scrollable;
  1224. },
  1225. /**
  1226. * Timer for doScroll polling
  1227. * @private
  1228. */
  1229. scrollTimeout: null,
  1230. /* @private
  1231. */
  1232. readyStatesRe : /complete/i,
  1233. /* @private
  1234. */
  1235. checkReadyState: function() {
  1236. var state = document.readyState;
  1237. if (EventManager.readyStatesRe.test(state)) {
  1238. EventManager.onReadyEvent({
  1239. type: state
  1240. });
  1241. }
  1242. },
  1243. bindReadyEvent: function() {
  1244. var topContext = true;
  1245. if (EventManager.hasBoundOnReady) {
  1246. return;
  1247. }
  1248. //are we in an IFRAME? (doScroll ineffective here)
  1249. try {
  1250. topContext = window.frameElement === undefined;
  1251. } catch(e) {
  1252. // If we throw an exception, it means we're probably getting access denied,
  1253. // which means we're in an iframe cross domain.
  1254. topContext = false;
  1255. }
  1256. if (!topContext || !doc.documentElement.doScroll) {
  1257. EventManager.pollScroll = Ext.emptyFn; //then noop this test altogether
  1258. }
  1259. // starts doScroll polling if necessary
  1260. if (EventManager.pollScroll() === true) {
  1261. return;
  1262. }
  1263. // Core is loaded AFTER initial document write/load ?
  1264. if (doc.readyState == 'complete' ) {
  1265. EventManager.onReadyEvent({type: 'already ' + (doc.readyState || 'body') });
  1266. } else {
  1267. doc.attachEvent('onreadystatechange', EventManager.checkReadyState);
  1268. window.attachEvent('onload', EventManager.onReadyEvent);
  1269. EventManager.hasBoundOnReady = true;
  1270. }
  1271. },
  1272. onReadyEvent : function(e) {
  1273. if (e && e.type) {
  1274. EventManager.onReadyChain.push(e.type);
  1275. }
  1276. if (EventManager.hasBoundOnReady) {
  1277. document.detachEvent('onreadystatechange', EventManager.checkReadyState);
  1278. window.detachEvent('onload', EventManager.onReadyEvent);
  1279. }
  1280. if (Ext.isNumber(EventManager.scrollTimeout)) {
  1281. clearTimeout(EventManager.scrollTimeout);
  1282. delete EventManager.scrollTimeout;
  1283. }
  1284. if (!Ext.isReady) {
  1285. EventManager.fireDocReady();
  1286. }
  1287. },
  1288. //diags: a list of event types passed to onReadyEvent (in chron order)
  1289. onReadyChain : []
  1290. });
  1291. }
  1292. /**
  1293. * Alias for {@link Ext.Loader#onReady Ext.Loader.onReady} with withDomReady set to true
  1294. * @member Ext
  1295. * @method onReady
  1296. */
  1297. Ext.onReady = function(fn, scope, options) {
  1298. Ext.Loader.onReady(fn, scope, true, options);
  1299. };
  1300. /**
  1301. * Alias for {@link Ext.EventManager#onDocumentReady Ext.EventManager.onDocumentReady}
  1302. * @member Ext
  1303. * @method onDocumentReady
  1304. */
  1305. Ext.onDocumentReady = EventManager.onDocumentReady;
  1306. /**
  1307. * Alias for {@link Ext.EventManager#addListener Ext.EventManager.addListener}
  1308. * @member Ext.EventManager
  1309. * @method on
  1310. */
  1311. EventManager.on = EventManager.addListener;
  1312. /**
  1313. * Alias for {@link Ext.EventManager#removeListener Ext.EventManager.removeListener}
  1314. * @member Ext.EventManager
  1315. * @method un
  1316. */
  1317. EventManager.un = EventManager.removeListener;
  1318. Ext.onReady(initExtCss);
  1319. };
  1320. /**
  1321. * @class Ext.EventObject
  1322. Just as {@link Ext.Element} wraps around a native DOM node, Ext.EventObject
  1323. wraps the browser's native event-object normalizing cross-browser differences,
  1324. such as which mouse button is clicked, keys pressed, mechanisms to stop
  1325. event-propagation along with a method to prevent default actions from taking place.
  1326. For example:
  1327. function handleClick(e, t){ // e is not a standard event object, it is a Ext.EventObject
  1328. e.preventDefault();
  1329. var target = e.getTarget(); // same as t (the target HTMLElement)
  1330. ...
  1331. }
  1332. var myDiv = {@link Ext#get Ext.get}("myDiv"); // get reference to an {@link Ext.Element}
  1333. myDiv.on( // 'on' is shorthand for addListener
  1334. "click", // perform an action on click of myDiv
  1335. handleClick // reference to the action handler
  1336. );
  1337. // other methods to do the same:
  1338. Ext.EventManager.on("myDiv", 'click', handleClick);
  1339. Ext.EventManager.addListener("myDiv", 'click', handleClick);
  1340. * @singleton
  1341. * @markdown
  1342. */
  1343. Ext.define('Ext.EventObjectImpl', {
  1344. uses: ['Ext.util.Point'],
  1345. /** Key constant @type Number */
  1346. BACKSPACE: 8,
  1347. /** Key constant @type Number */
  1348. TAB: 9,
  1349. /** Key constant @type Number */
  1350. NUM_CENTER: 12,
  1351. /** Key constant @type Number */
  1352. ENTER: 13,
  1353. /** Key constant @type Number */
  1354. RETURN: 13,
  1355. /** Key constant @type Number */
  1356. SHIFT: 16,
  1357. /** Key constant @type Number */
  1358. CTRL: 17,
  1359. /** Key constant @type Number */
  1360. ALT: 18,
  1361. /** Key constant @type Number */
  1362. PAUSE: 19,
  1363. /** Key constant @type Number */
  1364. CAPS_LOCK: 20,
  1365. /** Key constant @type Number */
  1366. ESC: 27,
  1367. /** Key constant @type Number */
  1368. SPACE: 32,
  1369. /** Key constant @type Number */
  1370. PAGE_UP: 33,
  1371. /** Key constant @type Number */
  1372. PAGE_DOWN: 34,
  1373. /** Key constant @type Number */
  1374. END: 35,
  1375. /** Key constant @type Number */
  1376. HOME: 36,
  1377. /** Key constant @type Number */
  1378. LEFT: 37,
  1379. /** Key constant @type Number */
  1380. UP: 38,
  1381. /** Key constant @type Number */
  1382. RIGHT: 39,
  1383. /** Key constant @type Number */
  1384. DOWN: 40,
  1385. /** Key constant @type Number */
  1386. PRINT_SCREEN: 44,
  1387. /** Key constant @type Number */
  1388. INSERT: 45,
  1389. /** Key constant @type Number */
  1390. DELETE: 46,
  1391. /** Key constant @type Number */
  1392. ZERO: 48,
  1393. /** Key constant @type Number */
  1394. ONE: 49,
  1395. /** Key constant @type Number */
  1396. TWO: 50,
  1397. /** Key constant @type Number */
  1398. THREE: 51,
  1399. /** Key constant @type Number */
  1400. FOUR: 52,
  1401. /** Key constant @type Number */
  1402. FIVE: 53,
  1403. /** Key constant @type Number */
  1404. SIX: 54,
  1405. /** Key constant @type Number */
  1406. SEVEN: 55,
  1407. /** Key constant @type Number */
  1408. EIGHT: 56,
  1409. /** Key constant @type Number */
  1410. NINE: 57,
  1411. /** Key constant @type Number */
  1412. A: 65,
  1413. /** Key constant @type Number */
  1414. B: 66,
  1415. /** Key constant @type Number */
  1416. C: 67,
  1417. /** Key constant @type Number */
  1418. D: 68,
  1419. /** Key constant @type Number */
  1420. E: 69,
  1421. /** Key constant @type Number */
  1422. F: 70,
  1423. /** Key constant @type Number */
  1424. G: 71,
  1425. /** Key constant @type Number */
  1426. H: 72,
  1427. /** Key constant @type Number */
  1428. I: 73,
  1429. /** Key constant @type Number */
  1430. J: 74,
  1431. /** Key constant @type Number */
  1432. K: 75,
  1433. /** Key constant @type Number */
  1434. L: 76,
  1435. /** Key constant @type Number */
  1436. M: 77,
  1437. /** Key constant @type Number */
  1438. N: 78,
  1439. /** Key constant @type Number */
  1440. O: 79,
  1441. /** Key constant @type Number */
  1442. P: 80,
  1443. /** Key constant @type Number */
  1444. Q: 81,
  1445. /** Key constant @type Number */
  1446. R: 82,
  1447. /** Key constant @type Number */
  1448. S: 83,
  1449. /** Key constant @type Number */
  1450. T: 84,
  1451. /** Key constant @type Number */
  1452. U: 85,
  1453. /** Key constant @type Number */
  1454. V: 86,
  1455. /** Key constant @type Number */
  1456. W: 87,
  1457. /** Key constant @type Number */
  1458. X: 88,
  1459. /** Key constant @type Number */
  1460. Y: 89,
  1461. /** Key constant @type Number */
  1462. Z: 90,
  1463. /** Key constant @type Number */
  1464. CONTEXT_MENU: 93,
  1465. /** Key constant @type Number */
  1466. NUM_ZERO: 96,
  1467. /** Key constant @type Number */
  1468. NUM_ONE: 97,
  1469. /** Key constant @type Number */
  1470. NUM_TWO: 98,
  1471. /** Key constant @type Number */
  1472. NUM_THREE: 99,
  1473. /** Key constant @type Number */
  1474. NUM_FOUR: 100,
  1475. /** Key constant @type Number */
  1476. NUM_FIVE: 101,
  1477. /** Key constant @type Number */
  1478. NUM_SIX: 102,
  1479. /** Key constant @type Number */
  1480. NUM_SEVEN: 103,
  1481. /** Key constant @type Number */
  1482. NUM_EIGHT: 104,
  1483. /** Key constant @type Number */
  1484. NUM_NINE: 105,
  1485. /** Key constant @type Number */
  1486. NUM_MULTIPLY: 106,
  1487. /** Key constant @type Number */
  1488. NUM_PLUS: 107,
  1489. /** Key constant @type Number */
  1490. NUM_MINUS: 109,
  1491. /** Key constant @type Number */
  1492. NUM_PERIOD: 110,
  1493. /** Key constant @type Number */
  1494. NUM_DIVISION: 111,
  1495. /** Key constant @type Number */
  1496. F1: 112,
  1497. /** Key constant @type Number */
  1498. F2: 113,
  1499. /** Key constant @type Number */
  1500. F3: 114,
  1501. /** Key constant @type Number */
  1502. F4: 115,
  1503. /** Key constant @type Number */
  1504. F5: 116,
  1505. /** Key constant @type Number */
  1506. F6: 117,
  1507. /** Key constant @type Number */
  1508. F7: 118,
  1509. /** Key constant @type Number */
  1510. F8: 119,
  1511. /** Key constant @type Number */
  1512. F9: 120,
  1513. /** Key constant @type Number */
  1514. F10: 121,
  1515. /** Key constant @type Number */
  1516. F11: 122,
  1517. /** Key constant @type Number */
  1518. F12: 123,
  1519. /**
  1520. * The mouse wheel delta scaling factor. This value depends on browser version and OS and
  1521. * attempts to produce a similar scrolling experience across all platforms and browsers.
  1522. *
  1523. * To change this value:
  1524. *
  1525. * Ext.EventObjectImpl.prototype.WHEEL_SCALE = 72;
  1526. *
  1527. * @type Number
  1528. * @markdown
  1529. */
  1530. WHEEL_SCALE: (function () {
  1531. var scale;
  1532. if (Ext.isGecko) {
  1533. // Firefox uses 3 on all platforms
  1534. scale = 3;
  1535. } else if (Ext.isMac) {
  1536. // Continuous scrolling devices have momentum and produce much more scroll than
  1537. // discrete devices on the same OS and browser. To make things exciting, Safari
  1538. // (and not Chrome) changed from small values to 120 (like IE).
  1539. if (Ext.isSafari && Ext.webKitVersion >= 532.0) {
  1540. // Safari changed the scrolling factor to match IE (for details see
  1541. // https://bugs.webkit.org/show_bug.cgi?id=24368). The WebKit version where this
  1542. // change was introduced was 532.0
  1543. // Detailed discussion:
  1544. // https://bugs.webkit.org/show_bug.cgi?id=29601
  1545. // http://trac.webkit.org/browser/trunk/WebKit/chromium/src/mac/WebInputEventFactory.mm#L1063
  1546. scale = 120;
  1547. } else {
  1548. // MS optical wheel mouse produces multiples of 12 which is close enough
  1549. // to help tame the speed of the continuous mice...
  1550. scale = 12;
  1551. }
  1552. // Momentum scrolling produces very fast scrolling, so increase the scale factor
  1553. // to help produce similar results cross platform. This could be even larger and
  1554. // it would help those mice, but other mice would become almost unusable as a
  1555. // result (since we cannot tell which device type is in use).
  1556. scale *= 3;
  1557. } else {
  1558. // IE, Opera and other Windows browsers use 120.
  1559. scale = 120;
  1560. }
  1561. return scale;
  1562. }()),
  1563. /**
  1564. * Simple click regex
  1565. * @private
  1566. */
  1567. clickRe: /(dbl)?click/,
  1568. // safari keypress events for special keys return bad keycodes
  1569. safariKeys: {
  1570. 3: 13, // enter
  1571. 63234: 37, // left
  1572. 63235: 39, // right
  1573. 63232: 38, // up
  1574. 63233: 40, // down
  1575. 63276: 33, // page up
  1576. 63277: 34, // page down
  1577. 63272: 46, // delete
  1578. 63273: 36, // home
  1579. 63275: 35 // end
  1580. },
  1581. // normalize button clicks, don't see any way to feature detect this.
  1582. btnMap: Ext.isIE ? {
  1583. 1: 0,
  1584. 4: 1,
  1585. 2: 2
  1586. } : {
  1587. 0: 0,
  1588. 1: 1,
  1589. 2: 2
  1590. },
  1591. /**
  1592. * @property {Boolean} ctrlKey
  1593. * True if the control key was down during the event.
  1594. * In Mac this will also be true when meta key was down.
  1595. */
  1596. /**
  1597. * @property {Boolean} altKey
  1598. * True if the alt key was down during the event.
  1599. */
  1600. /**
  1601. * @property {Boolean} shiftKey
  1602. * True if the shift key was down during the event.
  1603. */
  1604. constructor: function(event, freezeEvent){
  1605. if (event) {
  1606. this.setEvent(event.browserEvent || event, freezeEvent);
  1607. }
  1608. },
  1609. setEvent: function(event, freezeEvent){
  1610. var me = this, button, options;
  1611. if (event == me || (event && event.browserEvent)) { // already wrapped
  1612. return event;
  1613. }
  1614. me.browserEvent = event;
  1615. if (event) {
  1616. // normalize buttons
  1617. button = event.button ? me.btnMap[event.button] : (event.which ? event.which - 1 : -1);
  1618. if (me.clickRe.test(event.type) && button == -1) {
  1619. button = 0;
  1620. }
  1621. options = {
  1622. type: event.type,
  1623. button: button,
  1624. shiftKey: event.shiftKey,
  1625. // mac metaKey behaves like ctrlKey
  1626. ctrlKey: event.ctrlKey || event.metaKey || false,
  1627. altKey: event.altKey,
  1628. // in getKey these will be normalized for the mac
  1629. keyCode: event.keyCode,
  1630. charCode: event.charCode,
  1631. // cache the targets for the delayed and or buffered events
  1632. target: Ext.EventManager.getTarget(event),
  1633. relatedTarget: Ext.EventManager.getRelatedTarget(event),
  1634. currentTarget: event.currentTarget,
  1635. xy: (freezeEvent ? me.getXY() : null)
  1636. };
  1637. } else {
  1638. options = {
  1639. button: -1,
  1640. shiftKey: false,
  1641. ctrlKey: false,
  1642. altKey: false,
  1643. keyCode: 0,
  1644. charCode: 0,
  1645. target: null,
  1646. xy: [0, 0]
  1647. };
  1648. }
  1649. Ext.apply(me, options);
  1650. return me;
  1651. },
  1652. /**
  1653. * Stop the event (preventDefault and stopPropagation)
  1654. */
  1655. stopEvent: function(){
  1656. this.stopPropagation();
  1657. this.preventDefault();
  1658. },
  1659. /**
  1660. * Prevents the browsers default handling of the event.
  1661. */
  1662. preventDefault: function(){
  1663. if (this.browserEvent) {
  1664. Ext.EventManager.preventDefault(this.browserEvent);
  1665. }
  1666. },
  1667. /**
  1668. * Cancels bubbling of the event.
  1669. */
  1670. stopPropagation: function(){
  1671. var browserEvent = this.browserEvent;
  1672. if (browserEvent) {
  1673. if (browserEvent.type == 'mousedown') {
  1674. Ext.EventManager.stoppedMouseDownEvent.fire(this);
  1675. }
  1676. Ext.EventManager.stopPropagation(browserEvent);
  1677. }
  1678. },
  1679. /**
  1680. * Gets the character code for the event.
  1681. * @return {Number}
  1682. */
  1683. getCharCode: function(){
  1684. return this.charCode || this.keyCode;
  1685. },
  1686. /**
  1687. * Returns a normalized keyCode for the event.
  1688. * @return {Number} The key code
  1689. */
  1690. getKey: function(){
  1691. return this.normalizeKey(this.keyCode || this.charCode);
  1692. },
  1693. /**
  1694. * Normalize key codes across browsers
  1695. * @private
  1696. * @param {Number} key The key code
  1697. * @return {Number} The normalized code
  1698. */
  1699. normalizeKey: function(key){
  1700. // can't feature detect this
  1701. return Ext.isWebKit ? (this.safariKeys[key] || key) : key;
  1702. },
  1703. /**
  1704. * Gets the x coordinate of the event.
  1705. * @return {Number}
  1706. * @deprecated 4.0 Replaced by {@link #getX}
  1707. */
  1708. getPageX: function(){
  1709. return this.getX();
  1710. },
  1711. /**
  1712. * Gets the y coordinate of the event.
  1713. * @return {Number}
  1714. * @deprecated 4.0 Replaced by {@link #getY}
  1715. */
  1716. getPageY: function(){
  1717. return this.getY();
  1718. },
  1719. /**
  1720. * Gets the x coordinate of the event.
  1721. * @return {Number}
  1722. */
  1723. getX: function() {
  1724. return this.getXY()[0];
  1725. },
  1726. /**
  1727. * Gets the y coordinate of the event.
  1728. * @return {Number}
  1729. */
  1730. getY: function() {
  1731. return this.getXY()[1];
  1732. },
  1733. /**
  1734. * Gets the page coordinates of the event.
  1735. * @return {Number[]} The xy values like [x, y]
  1736. */
  1737. getXY: function() {
  1738. if (!this.xy) {
  1739. // same for XY
  1740. this.xy = Ext.EventManager.getPageXY(this.browserEvent);
  1741. }
  1742. return this.xy;
  1743. },
  1744. /**
  1745. * Gets the target for the event.
  1746. * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
  1747. * @param {Number/HTMLElement} maxDepth (optional) The max depth to search as a number or element (defaults to 10 || document.body)
  1748. * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
  1749. * @return {HTMLElement}
  1750. */
  1751. getTarget : function(selector, maxDepth, returnEl){
  1752. if (selector) {
  1753. return Ext.fly(this.target).findParent(selector, maxDepth, returnEl);
  1754. }
  1755. return returnEl ? Ext.get(this.target) : this.target;
  1756. },
  1757. /**
  1758. * Gets the related target.
  1759. * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
  1760. * @param {Number/HTMLElement} maxDepth (optional) The max depth to search as a number or element (defaults to 10 || document.body)
  1761. * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
  1762. * @return {HTMLElement}
  1763. */
  1764. getRelatedTarget : function(selector, maxDepth, returnEl){
  1765. if (selector) {
  1766. return Ext.fly(this.relatedTarget).findParent(selector, maxDepth, returnEl);
  1767. }
  1768. return returnEl ? Ext.get(this.relatedTarget) : this.relatedTarget;
  1769. },
  1770. /**
  1771. * Correctly scales a given wheel delta.
  1772. * @param {Number} delta The delta value.
  1773. */
  1774. correctWheelDelta : function (delta) {
  1775. var scale = this.WHEEL_SCALE,
  1776. ret = Math.round(delta / scale);
  1777. if (!ret && delta) {
  1778. ret = (delta < 0) ? -1 : 1; // don't allow non-zero deltas to go to zero!
  1779. }
  1780. return ret;
  1781. },
  1782. /**
  1783. * Returns the mouse wheel deltas for this event.
  1784. * @return {Object} An object with "x" and "y" properties holding the mouse wheel deltas.
  1785. */
  1786. getWheelDeltas : function () {
  1787. var me = this,
  1788. event = me.browserEvent,
  1789. dx = 0, dy = 0; // the deltas
  1790. if (Ext.isDefined(event.wheelDeltaX)) { // WebKit has both dimensions
  1791. dx = event.wheelDeltaX;
  1792. dy = event.wheelDeltaY;
  1793. } else if (event.wheelDelta) { // old WebKit and IE
  1794. dy = event.wheelDelta;
  1795. } else if (event.detail) { // Gecko
  1796. dy = -event.detail; // gecko is backwards
  1797. // Gecko sometimes returns really big values if the user changes settings to
  1798. // scroll a whole page per scroll
  1799. if (dy > 100) {
  1800. dy = 3;
  1801. } else if (dy < -100) {
  1802. dy = -3;
  1803. }
  1804. // Firefox 3.1 adds an axis field to the event to indicate direction of
  1805. // scroll. See https://developer.mozilla.org/en/Gecko-Specific_DOM_Events
  1806. if (Ext.isDefined(event.axis) && event.axis === event.HORIZONTAL_AXIS) {
  1807. dx = dy;
  1808. dy = 0;
  1809. }
  1810. }
  1811. return {
  1812. x: me.correctWheelDelta(dx),
  1813. y: me.correctWheelDelta(dy)
  1814. };
  1815. },
  1816. /**
  1817. * Normalizes mouse wheel y-delta across browsers. To get x-delta information, use
  1818. * {@link #getWheelDeltas} instead.
  1819. * @return {Number} The mouse wheel y-delta
  1820. */
  1821. getWheelDelta : function(){
  1822. var deltas = this.getWheelDeltas();
  1823. return deltas.y;
  1824. },
  1825. /**
  1826. * Returns true if the target of this event is a child of el. Unless the allowEl parameter is set, it will return false if if the target is el.
  1827. * Example usage:<pre><code>
  1828. // Handle click on any child of an element
  1829. Ext.getBody().on('click', function(e){
  1830. if(e.within('some-el')){
  1831. alert('Clicked on a child of some-el!');
  1832. }
  1833. });
  1834. // Handle click directly on an element, ignoring clicks on child nodes
  1835. Ext.getBody().on('click', function(e,t){
  1836. if((t.id == 'some-el') && !e.within(t, true)){
  1837. alert('Clicked directly on some-el!');
  1838. }
  1839. });
  1840. </code></pre>
  1841. * @param {String/HTMLElement/Ext.Element} el The id, DOM element or Ext.Element to check
  1842. * @param {Boolean} related (optional) true to test if the related target is within el instead of the target
  1843. * @param {Boolean} allowEl (optional) true to also check if the passed element is the target or related target
  1844. * @return {Boolean}
  1845. */
  1846. within : function(el, related, allowEl){
  1847. if(el){
  1848. var t = related ? this.getRelatedTarget() : this.getTarget(),
  1849. result;
  1850. if (t) {
  1851. result = Ext.fly(el).contains(t);
  1852. if (!result && allowEl) {
  1853. result = t == Ext.getDom(el);
  1854. }
  1855. return result;
  1856. }
  1857. }
  1858. return false;
  1859. },
  1860. /**
  1861. * Checks if the key pressed was a "navigation" key
  1862. * @return {Boolean} True if the press is a navigation keypress
  1863. */
  1864. isNavKeyPress : function(){
  1865. var me = this,
  1866. k = this.normalizeKey(me.keyCode);
  1867. return (k >= 33 && k <= 40) || // Page Up/Down, End, Home, Left, Up, Right, Down
  1868. k == me.RETURN ||
  1869. k == me.TAB ||
  1870. k == me.ESC;
  1871. },
  1872. /**
  1873. * Checks if the key pressed was a "special" key
  1874. * @return {Boolean} True if the press is a special keypress
  1875. */
  1876. isSpecialKey : function(){
  1877. var k = this.normalizeKey(this.keyCode);
  1878. return (this.type == 'keypress' && this.ctrlKey) ||
  1879. this.isNavKeyPress() ||
  1880. (k == this.BACKSPACE) || // Backspace
  1881. (k >= 16 && k <= 20) || // Shift, Ctrl, Alt, Pause, Caps Lock
  1882. (k >= 44 && k <= 46); // Print Screen, Insert, Delete
  1883. },
  1884. /**
  1885. * Returns a point object that consists of the object coordinates.
  1886. * @return {Ext.util.Point} point
  1887. */
  1888. getPoint : function(){
  1889. var xy = this.getXY();
  1890. return new Ext.util.Point(xy[0], xy[1]);
  1891. },
  1892. /**
  1893. * Returns true if the control, meta, shift or alt key was pressed during this event.
  1894. * @return {Boolean}
  1895. */
  1896. hasModifier : function(){
  1897. return this.ctrlKey || this.altKey || this.shiftKey || this.metaKey;
  1898. },
  1899. /**
  1900. * Injects a DOM event using the data in this object and (optionally) a new target.
  1901. * This is a low-level technique and not likely to be used by application code. The
  1902. * currently supported event types are:
  1903. * <p><b>HTMLEvents</b></p>
  1904. * <ul>
  1905. * <li>load</li>
  1906. * <li>unload</li>
  1907. * <li>select</li>
  1908. * <li>change</li>
  1909. * <li>submit</li>
  1910. * <li>reset</li>
  1911. * <li>resize</li>
  1912. * <li>scroll</li>
  1913. * </ul>
  1914. * <p><b>MouseEvents</b></p>
  1915. * <ul>
  1916. * <li>click</li>
  1917. * <li>dblclick</li>
  1918. * <li>mousedown</li>
  1919. * <li>mouseup</li>
  1920. * <li>mouseover</li>
  1921. * <li>mousemove</li>
  1922. * <li>mouseout</li>
  1923. * </ul>
  1924. * <p><b>UIEvents</b></p>
  1925. * <ul>
  1926. * <li>focusin</li>
  1927. * <li>focusout</li>
  1928. * <li>activate</li>
  1929. * <li>focus</li>
  1930. * <li>blur</li>
  1931. * </ul>
  1932. * @param {Ext.Element/HTMLElement} target (optional) If specified, the target for the event. This
  1933. * is likely to be used when relaying a DOM event. If not specified, {@link #getTarget}
  1934. * is used to determine the target.
  1935. */
  1936. injectEvent: (function () {
  1937. var API,
  1938. dispatchers = {}, // keyed by event type (e.g., 'mousedown')
  1939. crazyIEButtons;
  1940. // Good reference: http://developer.yahoo.com/yui/docs/UserAction.js.html
  1941. // IE9 has createEvent, but this code causes major problems with htmleditor (it
  1942. // blocks all mouse events and maybe more). TODO
  1943. if (!Ext.isIE && document.createEvent) { // if (DOM compliant)
  1944. API = {
  1945. createHtmlEvent: function (doc, type, bubbles, cancelable) {
  1946. var event = doc.createEvent('HTMLEvents');
  1947. event.initEvent(type, bubbles, cancelable);
  1948. return event;
  1949. },
  1950. createMouseEvent: function (doc, type, bubbles, cancelable, detail,
  1951. clientX, clientY, ctrlKey, altKey, shiftKey, metaKey,
  1952. button, relatedTarget) {
  1953. var event = doc.createEvent('MouseEvents'),
  1954. view = doc.defaultView || window;
  1955. if (event.initMouseEvent) {
  1956. event.initMouseEvent(type, bubbles, cancelable, view, detail,
  1957. clientX, clientY, clientX, clientY, ctrlKey, altKey,
  1958. shiftKey, metaKey, button, relatedTarget);
  1959. } else { // old Safari
  1960. event = doc.createEvent('UIEvents');
  1961. event.initEvent(type, bubbles, cancelable);
  1962. event.view = view;
  1963. event.detail = detail;
  1964. event.screenX = clientX;
  1965. event.screenY = clientY;
  1966. event.clientX = clientX;
  1967. event.clientY = clientY;
  1968. event.ctrlKey = ctrlKey;
  1969. event.altKey = altKey;
  1970. event.metaKey = metaKey;
  1971. event.shiftKey = shiftKey;
  1972. event.button = button;
  1973. event.relatedTarget = relatedTarget;
  1974. }
  1975. return event;
  1976. },
  1977. createUIEvent: function (doc, type, bubbles, cancelable, detail) {
  1978. var event = doc.createEvent('UIEvents'),
  1979. view = doc.defaultView || window;
  1980. event.initUIEvent(type, bubbles, cancelable, view, detail);
  1981. return event;
  1982. },
  1983. fireEvent: function (target, type, event) {
  1984. target.dispatchEvent(event);
  1985. },
  1986. fixTarget: function (target) {
  1987. // Safari3 doesn't have window.dispatchEvent()
  1988. if (target == window && !target.dispatchEvent) {
  1989. return document;
  1990. }
  1991. return target;
  1992. }
  1993. };
  1994. } else if (document.createEventObject) { // else if (IE)
  1995. crazyIEButtons = { 0: 1, 1: 4, 2: 2 };
  1996. API = {
  1997. createHtmlEvent: function (doc, type, bubbles, cancelable) {
  1998. var event = doc.createEventObject();
  1999. event.bubbles = bubbles;
  2000. event.cancelable = cancelable;
  2001. return event;
  2002. },
  2003. createMouseEvent: function (doc, type, bubbles, cancelable, detail,
  2004. clientX, clientY, ctrlKey, altKey, shiftKey, metaKey,
  2005. button, relatedTarget) {
  2006. var event = doc.createEventObject();
  2007. event.bubbles = bubbles;
  2008. event.cancelable = cancelable;
  2009. event.detail = detail;
  2010. event.screenX = clientX;
  2011. event.screenY = clientY;
  2012. event.clientX = clientX;
  2013. event.clientY = clientY;
  2014. event.ctrlKey = ctrlKey;
  2015. event.altKey = altKey;
  2016. event.shiftKey = shiftKey;
  2017. event.metaKey = metaKey;
  2018. event.button = crazyIEButtons[button] || button;
  2019. event.relatedTarget = relatedTarget; // cannot assign to/fromElement
  2020. return event;
  2021. },
  2022. createUIEvent: function (doc, type, bubbles, cancelable, detail) {
  2023. var event = doc.createEventObject();
  2024. event.bubbles = bubbles;
  2025. event.cancelable = cancelable;
  2026. return event;
  2027. },
  2028. fireEvent: function (target, type, event) {
  2029. target.fireEvent('on' + type, event);
  2030. },
  2031. fixTarget: function (target) {
  2032. if (target == document) {
  2033. // IE6,IE7 thinks window==document and doesn't have window.fireEvent()
  2034. // IE6,IE7 cannot properly call document.fireEvent()
  2035. return document.documentElement;
  2036. }
  2037. return target;
  2038. }
  2039. };
  2040. }
  2041. //----------------
  2042. // HTMLEvents
  2043. Ext.Object.each({
  2044. load: [false, false],
  2045. unload: [false, false],
  2046. select: [true, false],
  2047. change: [true, false],
  2048. submit: [true, true],
  2049. reset: [true, false],
  2050. resize: [true, false],
  2051. scroll: [true, false]
  2052. },
  2053. function (name, value) {
  2054. var bubbles = value[0], cancelable = value[1];
  2055. dispatchers[name] = function (targetEl, srcEvent) {
  2056. var e = API.createHtmlEvent(name, bubbles, cancelable);
  2057. API.fireEvent(targetEl, name, e);
  2058. };
  2059. });
  2060. //----------------
  2061. // MouseEvents
  2062. function createMouseEventDispatcher (type, detail) {
  2063. var cancelable = (type != 'mousemove');
  2064. return function (targetEl, srcEvent) {
  2065. var xy = srcEvent.getXY(),
  2066. e = API.createMouseEvent(targetEl.ownerDocument, type, true, cancelable,
  2067. detail, xy[0], xy[1], srcEvent.ctrlKey, srcEvent.altKey,
  2068. srcEvent.shiftKey, srcEvent.metaKey, srcEvent.button,
  2069. srcEvent.relatedTarget);
  2070. API.fireEvent(targetEl, type, e);
  2071. };
  2072. }
  2073. Ext.each(['click', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mousemove', 'mouseout'],
  2074. function (eventName) {
  2075. dispatchers[eventName] = createMouseEventDispatcher(eventName, 1);
  2076. });
  2077. //----------------
  2078. // UIEvents
  2079. Ext.Object.each({
  2080. focusin: [true, false],
  2081. focusout: [true, false],
  2082. activate: [true, true],
  2083. focus: [false, false],
  2084. blur: [false, false]
  2085. },
  2086. function (name, value) {
  2087. var bubbles = value[0], cancelable = value[1];
  2088. dispatchers[name] = function (targetEl, srcEvent) {
  2089. var e = API.createUIEvent(targetEl.ownerDocument, name, bubbles, cancelable, 1);
  2090. API.fireEvent(targetEl, name, e);
  2091. };
  2092. });
  2093. //---------
  2094. if (!API) {
  2095. // not even sure what ancient browsers fall into this category...
  2096. dispatchers = {}; // never mind all those we just built :P
  2097. API = {
  2098. fixTarget: function (t) {
  2099. return t;
  2100. }
  2101. };
  2102. }
  2103. function cannotInject (target, srcEvent) {
  2104. //<debug>
  2105. // TODO log something
  2106. //</debug>
  2107. }
  2108. return function (target) {
  2109. var me = this,
  2110. dispatcher = dispatchers[me.type] || cannotInject,
  2111. t = target ? (target.dom || target) : me.getTarget();
  2112. t = API.fixTarget(t);
  2113. dispatcher(t, me);
  2114. };
  2115. }()) // call to produce method
  2116. }, function() {
  2117. Ext.EventObject = new Ext.EventObjectImpl();
  2118. });
  2119. /**
  2120. * @class Ext.dom.AbstractQuery
  2121. * @private
  2122. */
  2123. Ext.define('Ext.dom.AbstractQuery', {
  2124. /**
  2125. * Selects a group of elements.
  2126. * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
  2127. * @param {HTMLElement/String} [root] The start of the query (defaults to document).
  2128. * @return {HTMLElement[]} An Array of DOM elements which match the selector. If there are
  2129. * no matches, and empty Array is returned.
  2130. */
  2131. select: function(q, root) {
  2132. var results = [],
  2133. nodes,
  2134. i,
  2135. j,
  2136. qlen,
  2137. nlen;
  2138. root = root || document;
  2139. if (typeof root == 'string') {
  2140. root = document.getElementById(root);
  2141. }
  2142. q = q.split(",");
  2143. for (i = 0,qlen = q.length; i < qlen; i++) {
  2144. if (typeof q[i] == 'string') {
  2145. //support for node attribute selection
  2146. if (typeof q[i][0] == '@') {
  2147. nodes = root.getAttributeNode(q[i].substring(1));
  2148. results.push(nodes);
  2149. } else {
  2150. nodes = root.querySelectorAll(q[i]);
  2151. for (j = 0,nlen = nodes.length; j < nlen; j++) {
  2152. results.push(nodes[j]);
  2153. }
  2154. }
  2155. }
  2156. }
  2157. return results;
  2158. },
  2159. /**
  2160. * Selects a single element.
  2161. * @param {String} selector The selector/xpath query
  2162. * @param {HTMLElement/String} [root] The start of the query (defaults to document).
  2163. * @return {HTMLElement} The DOM element which matched the selector.
  2164. */
  2165. selectNode: function(q, root) {
  2166. return this.select(q, root)[0];
  2167. },
  2168. /**
  2169. * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
  2170. * @param {String/HTMLElement/Array} el An element id, element or array of elements
  2171. * @param {String} selector The simple selector to test
  2172. * @return {Boolean}
  2173. */
  2174. is: function(el, q) {
  2175. if (typeof el == "string") {
  2176. el = document.getElementById(el);
  2177. }
  2178. return this.select(q).indexOf(el) !== -1;
  2179. }
  2180. });
  2181. /**
  2182. * Abstract base class for {@link Ext.dom.Helper}.
  2183. * @private
  2184. */
  2185. Ext.define('Ext.dom.AbstractHelper', {
  2186. emptyTags : /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i,
  2187. confRe : /(?:tag|children|cn|html|tpl|tplData)$/i,
  2188. endRe : /end/i,
  2189. // Since cls & for are reserved words, we need to transform them
  2190. attributeTransform: { cls : 'class', htmlFor : 'for' },
  2191. closeTags: {},
  2192. decamelizeName : (function () {
  2193. var camelCaseRe = /([a-z])([A-Z])/g,
  2194. cache = {};
  2195. function decamel (match, p1, p2) {
  2196. return p1 + '-' + p2.toLowerCase();
  2197. }
  2198. return function (s) {
  2199. return cache[s] || (cache[s] = s.replace(camelCaseRe, decamel));
  2200. };
  2201. }()),
  2202. generateMarkup: function(spec, buffer) {
  2203. var me = this,
  2204. attr, val, tag, i, closeTags;
  2205. if (typeof spec == "string") {
  2206. buffer.push(spec);
  2207. } else if (Ext.isArray(spec)) {
  2208. for (i = 0; i < spec.length; i++) {
  2209. if (spec[i]) {
  2210. me.generateMarkup(spec[i], buffer);
  2211. }
  2212. }
  2213. } else {
  2214. tag = spec.tag || 'div';
  2215. buffer.push('<', tag);
  2216. for (attr in spec) {
  2217. if (spec.hasOwnProperty(attr)) {
  2218. val = spec[attr];
  2219. if (!me.confRe.test(attr)) {
  2220. if (typeof val == "object") {
  2221. buffer.push(' ', attr, '="');
  2222. me.generateStyles(val, buffer).push('"');
  2223. } else {
  2224. buffer.push(' ', me.attributeTransform[attr] || attr, '="', val, '"');
  2225. }
  2226. }
  2227. }
  2228. }
  2229. // Now either just close the tag or try to add children and close the tag.
  2230. if (me.emptyTags.test(tag)) {
  2231. buffer.push('/>');
  2232. } else {
  2233. buffer.push('>');
  2234. // Apply the tpl html, and cn specifications
  2235. if ((val = spec.tpl)) {
  2236. val.applyOut(spec.tplData, buffer);
  2237. }
  2238. if ((val = spec.html)) {
  2239. buffer.push(val);
  2240. }
  2241. if ((val = spec.cn || spec.children)) {
  2242. me.generateMarkup(val, buffer);
  2243. }
  2244. // we generate a lot of close tags, so cache them rather than push 3 parts
  2245. closeTags = me.closeTags;
  2246. buffer.push(closeTags[tag] || (closeTags[tag] = '</' + tag + '>'));
  2247. }
  2248. }
  2249. return buffer;
  2250. },
  2251. /**
  2252. * Converts the styles from the given object to text. The styles are CSS style names
  2253. * with their associated value.
  2254. *
  2255. * The basic form of this method returns a string:
  2256. *
  2257. * var s = Ext.DomHelper.generateStyles({
  2258. * backgroundColor: 'red'
  2259. * });
  2260. *
  2261. * // s = 'background-color:red;'
  2262. *
  2263. * Alternatively, this method can append to an output array.
  2264. *
  2265. * var buf = [];
  2266. *
  2267. * ...
  2268. *
  2269. * Ext.DomHelper.generateStyles({
  2270. * backgroundColor: 'red'
  2271. * }, buf);
  2272. *
  2273. * In this case, the style text is pushed on to the array and the array is returned.
  2274. *
  2275. * @param {Object} styles The object describing the styles.
  2276. * @param {String[]} [buffer] The output buffer.
  2277. * @return {String/String[]} If buffer is passed, it is returned. Otherwise the style
  2278. * string is returned.
  2279. */
  2280. generateStyles: function (styles, buffer) {
  2281. var a = buffer || [],
  2282. name;
  2283. for (name in styles) {
  2284. if (styles.hasOwnProperty(name)) {
  2285. a.push(this.decamelizeName(name), ':', styles[name], ';');
  2286. }
  2287. }
  2288. return buffer || a.join('');
  2289. },
  2290. /**
  2291. * Returns the markup for the passed Element(s) config.
  2292. * @param {Object} spec The DOM object spec (and children)
  2293. * @return {String}
  2294. */
  2295. markup: function(spec) {
  2296. if (typeof spec == "string") {
  2297. return spec;
  2298. }
  2299. var buf = this.generateMarkup(spec, []);
  2300. return buf.join('');
  2301. },
  2302. /**
  2303. * Applies a style specification to an element.
  2304. * @param {String/HTMLElement} el The element to apply styles to
  2305. * @param {String/Object/Function} styles A style specification string e.g. 'width:100px', or object in the form {width:'100px'}, or
  2306. * a function which returns such a specification.
  2307. */
  2308. applyStyles: function(el, styles) {
  2309. if (styles) {
  2310. var i = 0,
  2311. len,
  2312. style;
  2313. el = Ext.fly(el);
  2314. if (typeof styles == 'function') {
  2315. styles = styles.call();
  2316. }
  2317. if (typeof styles == 'string'){
  2318. styles = Ext.util.Format.trim(styles).split(/\s*(?::|;)\s*/);
  2319. for(len = styles.length; i < len;){
  2320. el.setStyle(styles[i++], styles[i++]);
  2321. }
  2322. } else if (Ext.isObject(styles)) {
  2323. el.setStyle(styles);
  2324. }
  2325. }
  2326. },
  2327. /**
  2328. * Inserts an HTML fragment into the DOM.
  2329. * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.
  2330. *
  2331. * For example take the following HTML: `<div>Contents</div>`
  2332. *
  2333. * Using different `where` values inserts element to the following places:
  2334. *
  2335. * - beforeBegin: `<HERE><div>Contents</div>`
  2336. * - afterBegin: `<div><HERE>Contents</div>`
  2337. * - beforeEnd: `<div>Contents<HERE></div>`
  2338. * - afterEnd: `<div>Contents</div><HERE>`
  2339. *
  2340. * @param {HTMLElement/TextNode} el The context element
  2341. * @param {String} html The HTML fragment
  2342. * @return {HTMLElement} The new node
  2343. */
  2344. insertHtml: function(where, el, html) {
  2345. var hash = {},
  2346. hashVal,
  2347. setStart,
  2348. range,
  2349. frag,
  2350. rangeEl,
  2351. rs;
  2352. where = where.toLowerCase();
  2353. // add these here because they are used in both branches of the condition.
  2354. hash['beforebegin'] = ['BeforeBegin', 'previousSibling'];
  2355. hash['afterend'] = ['AfterEnd', 'nextSibling'];
  2356. range = el.ownerDocument.createRange();
  2357. setStart = 'setStart' + (this.endRe.test(where) ? 'After' : 'Before');
  2358. if (hash[where]) {
  2359. range[setStart](el);
  2360. frag = range.createContextualFragment(html);
  2361. el.parentNode.insertBefore(frag, where == 'beforebegin' ? el : el.nextSibling);
  2362. return el[(where == 'beforebegin' ? 'previous' : 'next') + 'Sibling'];
  2363. }
  2364. else {
  2365. rangeEl = (where == 'afterbegin' ? 'first' : 'last') + 'Child';
  2366. if (el.firstChild) {
  2367. range[setStart](el[rangeEl]);
  2368. frag = range.createContextualFragment(html);
  2369. if (where == 'afterbegin') {
  2370. el.insertBefore(frag, el.firstChild);
  2371. }
  2372. else {
  2373. el.appendChild(frag);
  2374. }
  2375. }
  2376. else {
  2377. el.innerHTML = html;
  2378. }
  2379. return el[rangeEl];
  2380. }
  2381. throw 'Illegal insertion point -> "' + where + '"';
  2382. },
  2383. /**
  2384. * Creates new DOM element(s) and inserts them before el.
  2385. * @param {String/HTMLElement/Ext.Element} el The context element
  2386. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  2387. * @param {Boolean} [returnElement] true to return a Ext.Element
  2388. * @return {HTMLElement/Ext.Element} The new node
  2389. */
  2390. insertBefore: function(el, o, returnElement) {
  2391. return this.doInsert(el, o, returnElement, 'beforebegin');
  2392. },
  2393. /**
  2394. * Creates new DOM element(s) and inserts them after el.
  2395. * @param {String/HTMLElement/Ext.Element} el The context element
  2396. * @param {Object} o The DOM object spec (and children)
  2397. * @param {Boolean} [returnElement] true to return a Ext.Element
  2398. * @return {HTMLElement/Ext.Element} The new node
  2399. */
  2400. insertAfter: function(el, o, returnElement) {
  2401. return this.doInsert(el, o, returnElement, 'afterend', 'nextSibling');
  2402. },
  2403. /**
  2404. * Creates new DOM element(s) and inserts them as the first child of el.
  2405. * @param {String/HTMLElement/Ext.Element} el The context element
  2406. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  2407. * @param {Boolean} [returnElement] true to return a Ext.Element
  2408. * @return {HTMLElement/Ext.Element} The new node
  2409. */
  2410. insertFirst: function(el, o, returnElement) {
  2411. return this.doInsert(el, o, returnElement, 'afterbegin', 'firstChild');
  2412. },
  2413. /**
  2414. * Creates new DOM element(s) and appends them to el.
  2415. * @param {String/HTMLElement/Ext.Element} el The context element
  2416. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  2417. * @param {Boolean} [returnElement] true to return a Ext.Element
  2418. * @return {HTMLElement/Ext.Element} The new node
  2419. */
  2420. append: function(el, o, returnElement) {
  2421. return this.doInsert(el, o, returnElement, 'beforeend', '', true);
  2422. },
  2423. /**
  2424. * Creates new DOM element(s) and overwrites the contents of el with them.
  2425. * @param {String/HTMLElement/Ext.Element} el The context element
  2426. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  2427. * @param {Boolean} [returnElement] true to return a Ext.Element
  2428. * @return {HTMLElement/Ext.Element} The new node
  2429. */
  2430. overwrite: function(el, o, returnElement) {
  2431. el = Ext.getDom(el);
  2432. el.innerHTML = this.markup(o);
  2433. return returnElement ? Ext.get(el.firstChild) : el.firstChild;
  2434. },
  2435. doInsert: function(el, o, returnElement, pos, sibling, append) {
  2436. var newNode = this.insertHtml(pos, Ext.getDom(el), this.markup(o));
  2437. return returnElement ? Ext.get(newNode, true) : newNode;
  2438. }
  2439. });
  2440. /**
  2441. * @class Ext.dom.AbstractElement
  2442. * @extend Ext.Base
  2443. * @private
  2444. */
  2445. (function() {
  2446. var document = window.document,
  2447. trimRe = /^\s+|\s+$/g,
  2448. whitespaceRe = /\s/;
  2449. if (!Ext.cache){
  2450. Ext.cache = {};
  2451. }
  2452. Ext.define('Ext.dom.AbstractElement', {
  2453. inheritableStatics: {
  2454. /**
  2455. * Retrieves Ext.dom.Element objects. {@link Ext#get} is alias for {@link Ext.dom.Element#get}.
  2456. *
  2457. * **This method does not retrieve {@link Ext.Component Component}s.** This method retrieves Ext.dom.Element
  2458. * objects which encapsulate DOM elements. To retrieve a Component by its ID, use {@link Ext.ComponentManager#get}.
  2459. *
  2460. * Uses simple caching to consistently return the same object. Automatically fixes if an object was recreated with
  2461. * the same id via AJAX or DOM.
  2462. *
  2463. * @param {String/HTMLElement/Ext.Element} el The id of the node, a DOM Node or an existing Element.
  2464. * @return {Ext.dom.Element} The Element object (or null if no matching element was found)
  2465. * @static
  2466. * @inheritable
  2467. */
  2468. get: function(el) {
  2469. var me = this,
  2470. El = Ext.dom.Element,
  2471. cacheItem,
  2472. extEl,
  2473. dom,
  2474. id;
  2475. if (!el) {
  2476. return null;
  2477. }
  2478. if (typeof el == "string") { // element id
  2479. if (el == Ext.windowId) {
  2480. return El.get(window);
  2481. } else if (el == Ext.documentId) {
  2482. return El.get(document);
  2483. }
  2484. cacheItem = Ext.cache[el];
  2485. // This code is here to catch the case where we've got a reference to a document of an iframe
  2486. // It getElementById will fail because it's not part of the document, so if we're skipping
  2487. // GC it means it's a window/document object that isn't the default window/document, which we have
  2488. // already handled above
  2489. if (cacheItem && cacheItem.skipGarbageCollection) {
  2490. extEl = cacheItem.el;
  2491. return extEl;
  2492. }
  2493. if (!(dom = document.getElementById(el))) {
  2494. return null;
  2495. }
  2496. if (cacheItem && cacheItem.el) {
  2497. extEl = Ext.updateCacheEntry(cacheItem, dom).el;
  2498. } else {
  2499. // Force new element if there's a cache but no el attached
  2500. extEl = new El(dom, !!cacheItem);
  2501. }
  2502. return extEl;
  2503. } else if (el.tagName) { // dom element
  2504. if (!(id = el.id)) {
  2505. id = Ext.id(el);
  2506. }
  2507. cacheItem = Ext.cache[id];
  2508. if (cacheItem && cacheItem.el) {
  2509. extEl = Ext.updateCacheEntry(cacheItem, el).el;
  2510. } else {
  2511. // Force new element if there's a cache but no el attached
  2512. extEl = new El(el, !!cacheItem);
  2513. }
  2514. return extEl;
  2515. } else if (el instanceof me) {
  2516. if (el != me.docEl && el != me.winEl) {
  2517. id = el.id;
  2518. // refresh dom element in case no longer valid,
  2519. // catch case where it hasn't been appended
  2520. cacheItem = Ext.cache[id];
  2521. if (cacheItem) {
  2522. Ext.updateCacheEntry(cacheItem, document.getElementById(id) || el.dom);
  2523. }
  2524. }
  2525. return el;
  2526. } else if (el.isComposite) {
  2527. return el;
  2528. } else if (Ext.isArray(el)) {
  2529. return me.select(el);
  2530. } else if (el === document) {
  2531. // create a bogus element object representing the document object
  2532. if (!me.docEl) {
  2533. me.docEl = Ext.Object.chain(El.prototype);
  2534. me.docEl.dom = document;
  2535. me.docEl.id = Ext.id(document);
  2536. me.addToCache(me.docEl);
  2537. }
  2538. return me.docEl;
  2539. } else if (el === window) {
  2540. if (!me.winEl) {
  2541. me.winEl = Ext.Object.chain(El.prototype);
  2542. me.winEl.dom = window;
  2543. me.winEl.id = Ext.id(window);
  2544. me.addToCache(me.winEl);
  2545. }
  2546. return me.winEl;
  2547. }
  2548. return null;
  2549. },
  2550. addToCache: function(el, id) {
  2551. if (el) {
  2552. Ext.addCacheEntry(id, el);
  2553. }
  2554. return el;
  2555. },
  2556. addMethods: function() {
  2557. this.override.apply(this, arguments);
  2558. },
  2559. /**
  2560. * <p>Returns an array of unique class names based upon the input strings, or string arrays.</p>
  2561. * <p>The number of parameters is unlimited.</p>
  2562. * <p>Example</p><code><pre>
  2563. // Add x-invalid and x-mandatory classes, do not duplicate
  2564. myElement.dom.className = Ext.core.Element.mergeClsList(this.initialClasses, 'x-invalid x-mandatory');
  2565. </pre></code>
  2566. * @param {Mixed} clsList1 A string of class names, or an array of class names.
  2567. * @param {Mixed} clsList2 A string of class names, or an array of class names.
  2568. * @return {Array} An array of strings representing remaining unique, merged class names. If class names were added to the first list, the <code>changed</code> property will be <code>true</code>.
  2569. * @static
  2570. * @inheritable
  2571. */
  2572. mergeClsList: function() {
  2573. var clsList, clsHash = {},
  2574. i, length, j, listLength, clsName, result = [],
  2575. changed = false;
  2576. for (i = 0, length = arguments.length; i < length; i++) {
  2577. clsList = arguments[i];
  2578. if (Ext.isString(clsList)) {
  2579. clsList = clsList.replace(trimRe, '').split(whitespaceRe);
  2580. }
  2581. if (clsList) {
  2582. for (j = 0, listLength = clsList.length; j < listLength; j++) {
  2583. clsName = clsList[j];
  2584. if (!clsHash[clsName]) {
  2585. if (i) {
  2586. changed = true;
  2587. }
  2588. clsHash[clsName] = true;
  2589. }
  2590. }
  2591. }
  2592. }
  2593. for (clsName in clsHash) {
  2594. result.push(clsName);
  2595. }
  2596. result.changed = changed;
  2597. return result;
  2598. },
  2599. /**
  2600. * <p>Returns an array of unique class names deom the first parameter with all class names
  2601. * from the second parameter removed.</p>
  2602. * <p>Example</p><code><pre>
  2603. // Remove x-invalid and x-mandatory classes if present.
  2604. myElement.dom.className = Ext.core.Element.removeCls(this.initialClasses, 'x-invalid x-mandatory');
  2605. </pre></code>
  2606. * @param {Mixed} existingClsList A string of class names, or an array of class names.
  2607. * @param {Mixed} removeClsList A string of class names, or an array of class names to remove from <code>existingClsList</code>.
  2608. * @return {Array} An array of strings representing remaining class names. If class names were removed, the <code>changed</code> property will be <code>true</code>.
  2609. * @static
  2610. * @inheritable
  2611. */
  2612. removeCls: function(existingClsList, removeClsList) {
  2613. var clsHash = {},
  2614. i, length, clsName, result = [],
  2615. changed = false;
  2616. if (existingClsList) {
  2617. if (Ext.isString(existingClsList)) {
  2618. existingClsList = existingClsList.replace(trimRe, '').split(whitespaceRe);
  2619. }
  2620. for (i = 0, length = existingClsList.length; i < length; i++) {
  2621. clsHash[existingClsList[i]] = true;
  2622. }
  2623. }
  2624. if (removeClsList) {
  2625. if (Ext.isString(removeClsList)) {
  2626. removeClsList = removeClsList.split(whitespaceRe);
  2627. }
  2628. for (i = 0, length = removeClsList.length; i < length; i++) {
  2629. clsName = removeClsList[i];
  2630. if (clsHash[clsName]) {
  2631. changed = true;
  2632. delete clsHash[clsName];
  2633. }
  2634. }
  2635. }
  2636. for (clsName in clsHash) {
  2637. result.push(clsName);
  2638. }
  2639. result.changed = changed;
  2640. return result;
  2641. },
  2642. /**
  2643. * @property
  2644. * Visibility mode constant for use with {@link Ext.dom.Element#setVisibilityMode}.
  2645. * Use the CSS 'visibility' property to hide the element.
  2646. *
  2647. * Note that in this mode, {@link Ext.dom.Element#isVisible isVisible} may return true
  2648. * for an element even though it actually has a parent element that is hidden. For this
  2649. * reason, and in most cases, using the {@link #OFFSETS} mode is a better choice.
  2650. * @static
  2651. * @inheritable
  2652. */
  2653. VISIBILITY: 1,
  2654. /**
  2655. * @property
  2656. * Visibility mode constant for use with {@link Ext.dom.Element#setVisibilityMode}.
  2657. * Use the CSS 'display' property to hide the element.
  2658. * @static
  2659. * @inheritable
  2660. */
  2661. DISPLAY: 2,
  2662. /**
  2663. * @property
  2664. * Visibility mode constant for use with {@link Ext.dom.Element#setVisibilityMode}.
  2665. * Use CSS absolute positioning and top/left offsets to hide the element.
  2666. * @static
  2667. * @inheritable
  2668. */
  2669. OFFSETS: 3,
  2670. /**
  2671. * @property
  2672. * Visibility mode constant for use with {@link Ext.dom.Element#setVisibilityMode}.
  2673. * Add or remove the {@link Ext.Layer#visibilityCls} class to hide the element.
  2674. * @static
  2675. * @inheritable
  2676. */
  2677. ASCLASS: 4
  2678. },
  2679. constructor: function(element, forceNew) {
  2680. var me = this,
  2681. dom = typeof element == 'string'
  2682. ? document.getElementById(element)
  2683. : element,
  2684. id;
  2685. if (!dom) {
  2686. return null;
  2687. }
  2688. id = dom.id;
  2689. if (!forceNew && id && Ext.cache[id]) {
  2690. // element object already exists
  2691. return Ext.cache[id].el;
  2692. }
  2693. /**
  2694. * @property {HTMLElement} dom
  2695. * The DOM element
  2696. */
  2697. me.dom = dom;
  2698. /**
  2699. * @property {String} id
  2700. * The DOM element ID
  2701. */
  2702. me.id = id || Ext.id(dom);
  2703. me.self.addToCache(me);
  2704. },
  2705. /**
  2706. * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
  2707. * @param {Object} o The object with the attributes
  2708. * @param {Boolean} [useSet=true] false to override the default setAttribute to use expandos.
  2709. * @return {Ext.dom.Element} this
  2710. */
  2711. set: function(o, useSet) {
  2712. var el = this.dom,
  2713. attr,
  2714. value;
  2715. for (attr in o) {
  2716. if (o.hasOwnProperty(attr)) {
  2717. value = o[attr];
  2718. if (attr == 'style') {
  2719. this.applyStyles(value);
  2720. }
  2721. else if (attr == 'cls') {
  2722. el.className = value;
  2723. }
  2724. else if (useSet !== false) {
  2725. if (value === undefined) {
  2726. el.removeAttribute(attr);
  2727. } else {
  2728. el.setAttribute(attr, value);
  2729. }
  2730. }
  2731. else {
  2732. el[attr] = value;
  2733. }
  2734. }
  2735. }
  2736. return this;
  2737. },
  2738. /**
  2739. * @property {String} defaultUnit
  2740. * The default unit to append to CSS values where a unit isn't provided.
  2741. */
  2742. defaultUnit: "px",
  2743. /**
  2744. * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
  2745. * @param {String} selector The simple selector to test
  2746. * @return {Boolean} True if this element matches the selector, else false
  2747. */
  2748. is: function(simpleSelector) {
  2749. return Ext.DomQuery.is(this.dom, simpleSelector);
  2750. },
  2751. /**
  2752. * Returns the value of the "value" attribute
  2753. * @param {Boolean} asNumber true to parse the value as a number
  2754. * @return {String/Number}
  2755. */
  2756. getValue: function(asNumber) {
  2757. var val = this.dom.value;
  2758. return asNumber ? parseInt(val, 10) : val;
  2759. },
  2760. /**
  2761. * Removes this element's dom reference. Note that event and cache removal is handled at {@link Ext#removeNode
  2762. * Ext.removeNode}
  2763. */
  2764. remove: function() {
  2765. var me = this,
  2766. dom = me.dom;
  2767. if (dom) {
  2768. Ext.removeNode(dom);
  2769. delete me.dom;
  2770. }
  2771. },
  2772. /**
  2773. * Returns true if this element is an ancestor of the passed element
  2774. * @param {HTMLElement/String} el The element to check
  2775. * @return {Boolean} True if this element is an ancestor of el, else false
  2776. */
  2777. contains: function(el) {
  2778. if (!el) {
  2779. return false;
  2780. }
  2781. var me = this,
  2782. dom = el.dom || el;
  2783. // we need el-contains-itself logic here because isAncestor does not do that:
  2784. return (dom === me.dom) || Ext.dom.AbstractElement.isAncestor(me.dom, dom);
  2785. },
  2786. /**
  2787. * Returns the value of an attribute from the element's underlying DOM node.
  2788. * @param {String} name The attribute name
  2789. * @param {String} [namespace] The namespace in which to look for the attribute
  2790. * @return {String} The attribute value
  2791. */
  2792. getAttribute: function(name, ns) {
  2793. var dom = this.dom;
  2794. return dom.getAttributeNS(ns, name) || dom.getAttribute(ns + ":" + name) || dom.getAttribute(name) || dom[name];
  2795. },
  2796. /**
  2797. * Update the innerHTML of this element
  2798. * @param {String} html The new HTML
  2799. * @return {Ext.dom.Element} this
  2800. */
  2801. update: function(html) {
  2802. if (this.dom) {
  2803. this.dom.innerHTML = html;
  2804. }
  2805. return this;
  2806. },
  2807. /**
  2808. * Set the innerHTML of this element
  2809. * @param {String} html The new HTML
  2810. * @return {Ext.Element} this
  2811. */
  2812. setHTML: function(html) {
  2813. if(this.dom) {
  2814. this.dom.innerHTML = html;
  2815. }
  2816. return this;
  2817. },
  2818. /**
  2819. * Returns the innerHTML of an Element or an empty string if the element's
  2820. * dom no longer exists.
  2821. */
  2822. getHTML: function() {
  2823. return this.dom ? this.dom.innerHTML : '';
  2824. },
  2825. /**
  2826. * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
  2827. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  2828. * @return {Ext.Element} this
  2829. */
  2830. hide: function() {
  2831. this.setVisible(false);
  2832. return this;
  2833. },
  2834. /**
  2835. * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
  2836. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  2837. * @return {Ext.Element} this
  2838. */
  2839. show: function() {
  2840. this.setVisible(true);
  2841. return this;
  2842. },
  2843. /**
  2844. * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
  2845. * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
  2846. * @param {Boolean} visible Whether the element is visible
  2847. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  2848. * @return {Ext.Element} this
  2849. */
  2850. setVisible: function(visible, animate) {
  2851. var me = this,
  2852. statics = me.self,
  2853. mode = me.getVisibilityMode(),
  2854. prefix = Ext.baseCSSPrefix;
  2855. switch (mode) {
  2856. case statics.VISIBILITY:
  2857. me.removeCls([prefix + 'hidden-display', prefix + 'hidden-offsets']);
  2858. me[visible ? 'removeCls' : 'addCls'](prefix + 'hidden-visibility');
  2859. break;
  2860. case statics.DISPLAY:
  2861. me.removeCls([prefix + 'hidden-visibility', prefix + 'hidden-offsets']);
  2862. me[visible ? 'removeCls' : 'addCls'](prefix + 'hidden-display');
  2863. break;
  2864. case statics.OFFSETS:
  2865. me.removeCls([prefix + 'hidden-visibility', prefix + 'hidden-display']);
  2866. me[visible ? 'removeCls' : 'addCls'](prefix + 'hidden-offsets');
  2867. break;
  2868. }
  2869. return me;
  2870. },
  2871. getVisibilityMode: function() {
  2872. // Only flyweights won't have a $cache object, by calling getCache the cache
  2873. // will be created for future accesses. As such, we're eliminating the method
  2874. // call since it's mostly redundant
  2875. var data = (this.$cache || this.getCache()).data,
  2876. visMode = data.visibilityMode;
  2877. if (visMode === undefined) {
  2878. data.visibilityMode = visMode = this.self.DISPLAY;
  2879. }
  2880. return visMode;
  2881. },
  2882. /**
  2883. * Use this to change the visibility mode between {@link #VISIBILITY}, {@link #DISPLAY}, {@link #OFFSETS} or {@link #ASCLASS}.
  2884. */
  2885. setVisibilityMode: function(mode) {
  2886. (this.$cache || this.getCache()).data.visibilityMode = mode;
  2887. return this;
  2888. },
  2889. getCache: function() {
  2890. var me = this,
  2891. id = me.dom.id || Ext.id(me.dom);
  2892. // Note that we do not assign an ID to the calling object here.
  2893. // An Ext.dom.Element will have one assigned at construction, and an Ext.dom.AbstractElement.Fly must not have one.
  2894. // We assign an ID to the DOM element if it does not have one.
  2895. me.$cache = Ext.cache[id] || Ext.addCacheEntry(id, null, me.dom);
  2896. return me.$cache;
  2897. }
  2898. }, function() {
  2899. var AbstractElement = this;
  2900. /**
  2901. * @private
  2902. * @member Ext
  2903. */
  2904. Ext.getDetachedBody = function () {
  2905. var detachedEl = AbstractElement.detachedBodyEl;
  2906. if (!detachedEl) {
  2907. detachedEl = document.createElement('div');
  2908. AbstractElement.detachedBodyEl = detachedEl = new AbstractElement.Fly(detachedEl);
  2909. detachedEl.isDetachedBody = true;
  2910. }
  2911. return detachedEl;
  2912. };
  2913. /**
  2914. * @private
  2915. * @member Ext
  2916. */
  2917. Ext.getElementById = function (id) {
  2918. var el = document.getElementById(id),
  2919. detachedBodyEl;
  2920. if (!el && (detachedBodyEl = AbstractElement.detachedBodyEl)) {
  2921. el = detachedBodyEl.dom.querySelector('#' + Ext.escapeId(id));
  2922. }
  2923. return el;
  2924. };
  2925. /**
  2926. * @member Ext
  2927. * @method get
  2928. * @inheritdoc Ext.dom.Element#get
  2929. */
  2930. Ext.get = function(el) {
  2931. return Ext.dom.Element.get(el);
  2932. };
  2933. this.addStatics({
  2934. /**
  2935. * @class Ext.dom.AbstractElement.Fly
  2936. * @extends Ext.dom.AbstractElement
  2937. *
  2938. * A non-persistent wrapper for a DOM element which may be used to execute methods of {@link Ext.dom.Element}
  2939. * upon a DOM element without creating an instance of {@link Ext.dom.Element}.
  2940. *
  2941. * A **singleton** instance of this class is returned when you use {@link Ext#fly}
  2942. *
  2943. * Because it is a singleton, this Flyweight does not have an ID, and must be used and discarded in a single line.
  2944. * You should not keep and use the reference to this singleton over multiple lines because methods that you call
  2945. * may themselves make use of {@link Ext#fly} and may change the DOM element to which the instance refers.
  2946. */
  2947. Fly: new Ext.Class({
  2948. extend: AbstractElement,
  2949. /**
  2950. * @property {Boolean} isFly
  2951. * This is `true` to identify Element flyweights
  2952. */
  2953. isFly: true,
  2954. constructor: function(dom) {
  2955. this.dom = dom;
  2956. },
  2957. /**
  2958. * @private
  2959. * Attach this fliyweight instance to the passed DOM element.
  2960. *
  2961. * Note that a flightweight does **not** have an ID, and does not acquire the ID of the DOM element.
  2962. */
  2963. attach: function (dom) {
  2964. // Attach to the passed DOM element. The same code as in Ext.Fly
  2965. this.dom = dom;
  2966. // Use cached data if there is existing cached data for the referenced DOM element,
  2967. // otherwise it will be created when needed by getCache.
  2968. this.$cache = dom.id ? Ext.cache[dom.id] : null;
  2969. return this;
  2970. }
  2971. }),
  2972. _flyweights: {},
  2973. /**
  2974. * Gets the singleton {@link Ext.dom.AbstractElement.Fly flyweight} element, with the passed node as the active element.
  2975. *
  2976. * Because it is a singleton, this Flyweight does not have an ID, and must be used and discarded in a single line.
  2977. * You may not keep and use the reference to this singleton over multiple lines because methods that you call
  2978. * may themselves make use of {@link Ext#fly} and may change the DOM element to which the instance refers.
  2979. *
  2980. * {@link Ext#fly} is alias for {@link Ext.dom.AbstractElement#fly}.
  2981. *
  2982. * Use this to make one-time references to DOM elements which are not going to be accessed again either by
  2983. * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link
  2984. * Ext#get Ext.get} will be more appropriate to take advantage of the caching provided by the Ext.dom.Element
  2985. * class.
  2986. *
  2987. * @param {String/HTMLElement} dom The dom node or id
  2988. * @param {String} [named] Allows for creation of named reusable flyweights to prevent conflicts (e.g.
  2989. * internally Ext uses "_global")
  2990. * @return {Ext.dom.AbstractElement.Fly} The singleton flyweight object (or null if no matching element was found)
  2991. * @static
  2992. * @member Ext.dom.AbstractElement
  2993. */
  2994. fly: function(dom, named) {
  2995. var fly = null,
  2996. _flyweights = AbstractElement._flyweights;
  2997. named = named || '_global';
  2998. dom = Ext.getDom(dom);
  2999. if (dom) {
  3000. fly = _flyweights[named] || (_flyweights[named] = new AbstractElement.Fly());
  3001. // Attach to the passed DOM element.
  3002. // This code performs the same function as Fly.attach, but inline it for efficiency
  3003. fly.dom = dom;
  3004. // Use cached data if there is existing cached data for the referenced DOM element,
  3005. // otherwise it will be created when needed by getCache.
  3006. fly.$cache = dom.id ? Ext.cache[dom.id] : null;
  3007. }
  3008. return fly;
  3009. }
  3010. });
  3011. /**
  3012. * @member Ext
  3013. * @method fly
  3014. * @inheritdoc Ext.dom.AbstractElement#fly
  3015. */
  3016. Ext.fly = function() {
  3017. return AbstractElement.fly.apply(AbstractElement, arguments);
  3018. };
  3019. (function (proto) {
  3020. /**
  3021. * @method destroy
  3022. * @member Ext.dom.AbstractElement
  3023. * @inheritdoc Ext.dom.AbstractElement#remove
  3024. * Alias to {@link #remove}.
  3025. */
  3026. proto.destroy = proto.remove;
  3027. /**
  3028. * Returns a child element of this element given its `id`.
  3029. * @method getById
  3030. * @member Ext.dom.AbstractElement
  3031. * @param {String} id The id of the desired child element.
  3032. * @param {Boolean} [asDom=false] True to return the DOM element, false to return a
  3033. * wrapped Element object.
  3034. */
  3035. if (document.querySelector) {
  3036. proto.getById = function (id, asDom) {
  3037. // for normal elements getElementById is the best solution, but if the el is
  3038. // not part of the document.body, we have to resort to querySelector
  3039. var dom = document.getElementById(id) ||
  3040. this.dom.querySelector('#'+Ext.escapeId(id));
  3041. return asDom ? dom : (dom ? Ext.get(dom) : null);
  3042. };
  3043. } else {
  3044. proto.getById = function (id, asDom) {
  3045. var dom = document.getElementById(id);
  3046. return asDom ? dom : (dom ? Ext.get(dom) : null);
  3047. };
  3048. }
  3049. }(this.prototype));
  3050. });
  3051. }());
  3052. /**
  3053. * @class Ext.dom.AbstractElement
  3054. */
  3055. Ext.dom.AbstractElement.addInheritableStatics({
  3056. unitRe: /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i,
  3057. camelRe: /(-[a-z])/gi,
  3058. cssRe: /([a-z0-9\-]+)\s*:\s*([^;\s]+(?:\s*[^;\s]+)*);?/gi,
  3059. opacityRe: /alpha\(opacity=(.*)\)/i,
  3060. propertyCache: {},
  3061. defaultUnit : "px",
  3062. borders: {l: 'border-left-width', r: 'border-right-width', t: 'border-top-width', b: 'border-bottom-width'},
  3063. paddings: {l: 'padding-left', r: 'padding-right', t: 'padding-top', b: 'padding-bottom'},
  3064. margins: {l: 'margin-left', r: 'margin-right', t: 'margin-top', b: 'margin-bottom'},
  3065. /**
  3066. * Test if size has a unit, otherwise appends the passed unit string, or the default for this Element.
  3067. * @param size {Object} The size to set
  3068. * @param units {String} The units to append to a numeric size value
  3069. * @private
  3070. * @static
  3071. */
  3072. addUnits: function(size, units) {
  3073. // Most common case first: Size is set to a number
  3074. if (typeof size == 'number') {
  3075. return size + (units || this.defaultUnit || 'px');
  3076. }
  3077. // Size set to a value which means "auto"
  3078. if (size === "" || size == "auto" || size === undefined || size === null) {
  3079. return size || '';
  3080. }
  3081. // Otherwise, warn if it's not a valid CSS measurement
  3082. if (!this.unitRe.test(size)) {
  3083. //<debug>
  3084. if (Ext.isDefined(Ext.global.console)) {
  3085. Ext.global.console.warn("Warning, size detected as NaN on Element.addUnits.");
  3086. }
  3087. //</debug>
  3088. return size || '';
  3089. }
  3090. return size;
  3091. },
  3092. /**
  3093. * @static
  3094. * @private
  3095. */
  3096. isAncestor: function(p, c) {
  3097. var ret = false;
  3098. p = Ext.getDom(p);
  3099. c = Ext.getDom(c);
  3100. if (p && c) {
  3101. if (p.contains) {
  3102. return p.contains(c);
  3103. } else if (p.compareDocumentPosition) {
  3104. return !!(p.compareDocumentPosition(c) & 16);
  3105. } else {
  3106. while ((c = c.parentNode)) {
  3107. ret = c == p || ret;
  3108. }
  3109. }
  3110. }
  3111. return ret;
  3112. },
  3113. /**
  3114. * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations
  3115. * (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result)
  3116. * @static
  3117. * @param {Number/String} box The encoded margins
  3118. * @return {Object} An object with margin sizes for top, right, bottom and left
  3119. */
  3120. parseBox: function(box) {
  3121. if (typeof box != 'string') {
  3122. box = box.toString();
  3123. }
  3124. var parts = box.split(' '),
  3125. ln = parts.length;
  3126. if (ln == 1) {
  3127. parts[1] = parts[2] = parts[3] = parts[0];
  3128. }
  3129. else if (ln == 2) {
  3130. parts[2] = parts[0];
  3131. parts[3] = parts[1];
  3132. }
  3133. else if (ln == 3) {
  3134. parts[3] = parts[1];
  3135. }
  3136. return {
  3137. top :parseFloat(parts[0]) || 0,
  3138. right :parseFloat(parts[1]) || 0,
  3139. bottom:parseFloat(parts[2]) || 0,
  3140. left :parseFloat(parts[3]) || 0
  3141. };
  3142. },
  3143. /**
  3144. * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations
  3145. * (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result)
  3146. * @static
  3147. * @param {Number/String} box The encoded margins
  3148. * @param {String} units The type of units to add
  3149. * @return {String} An string with unitized (px if units is not specified) metrics for top, right, bottom and left
  3150. */
  3151. unitizeBox: function(box, units) {
  3152. var a = this.addUnits,
  3153. b = this.parseBox(box);
  3154. return a(b.top, units) + ' ' +
  3155. a(b.right, units) + ' ' +
  3156. a(b.bottom, units) + ' ' +
  3157. a(b.left, units);
  3158. },
  3159. // private
  3160. camelReplaceFn: function(m, a) {
  3161. return a.charAt(1).toUpperCase();
  3162. },
  3163. /**
  3164. * Normalizes CSS property keys from dash delimited to camel case JavaScript Syntax.
  3165. * For example:
  3166. *
  3167. * - border-width -> borderWidth
  3168. * - padding-top -> paddingTop
  3169. *
  3170. * @static
  3171. * @param {String} prop The property to normalize
  3172. * @return {String} The normalized string
  3173. */
  3174. normalize: function(prop) {
  3175. // TODO: Mobile optimization?
  3176. if (prop == 'float') {
  3177. prop = Ext.supports.Float ? 'cssFloat' : 'styleFloat';
  3178. }
  3179. return this.propertyCache[prop] || (this.propertyCache[prop] = prop.replace(this.camelRe, this.camelReplaceFn));
  3180. },
  3181. /**
  3182. * Retrieves the document height
  3183. * @static
  3184. * @return {Number} documentHeight
  3185. */
  3186. getDocumentHeight: function() {
  3187. return Math.max(!Ext.isStrict ? document.body.scrollHeight : document.documentElement.scrollHeight, this.getViewportHeight());
  3188. },
  3189. /**
  3190. * Retrieves the document width
  3191. * @static
  3192. * @return {Number} documentWidth
  3193. */
  3194. getDocumentWidth: function() {
  3195. return Math.max(!Ext.isStrict ? document.body.scrollWidth : document.documentElement.scrollWidth, this.getViewportWidth());
  3196. },
  3197. /**
  3198. * Retrieves the viewport height of the window.
  3199. * @static
  3200. * @return {Number} viewportHeight
  3201. */
  3202. getViewportHeight: function(){
  3203. return window.innerHeight;
  3204. },
  3205. /**
  3206. * Retrieves the viewport width of the window.
  3207. * @static
  3208. * @return {Number} viewportWidth
  3209. */
  3210. getViewportWidth: function() {
  3211. return window.innerWidth;
  3212. },
  3213. /**
  3214. * Retrieves the viewport size of the window.
  3215. * @static
  3216. * @return {Object} object containing width and height properties
  3217. */
  3218. getViewSize: function() {
  3219. return {
  3220. width: window.innerWidth,
  3221. height: window.innerHeight
  3222. };
  3223. },
  3224. /**
  3225. * Retrieves the current orientation of the window. This is calculated by
  3226. * determing if the height is greater than the width.
  3227. * @static
  3228. * @return {String} Orientation of window: 'portrait' or 'landscape'
  3229. */
  3230. getOrientation: function() {
  3231. if (Ext.supports.OrientationChange) {
  3232. return (window.orientation == 0) ? 'portrait' : 'landscape';
  3233. }
  3234. return (window.innerHeight > window.innerWidth) ? 'portrait' : 'landscape';
  3235. },
  3236. /**
  3237. * Returns the top Element that is located at the passed coordinates
  3238. * @static
  3239. * @param {Number} x The x coordinate
  3240. * @param {Number} y The y coordinate
  3241. * @return {String} The found Element
  3242. */
  3243. fromPoint: function(x, y) {
  3244. return Ext.get(document.elementFromPoint(x, y));
  3245. },
  3246. /**
  3247. * Converts a CSS string into an object with a property for each style.
  3248. *
  3249. * The sample code below would return an object with 2 properties, one
  3250. * for background-color and one for color.
  3251. *
  3252. * var css = 'background-color: red;color: blue; ';
  3253. * console.log(Ext.dom.Element.parseStyles(css));
  3254. *
  3255. * @static
  3256. * @param {String} styles A CSS string
  3257. * @return {Object} styles
  3258. */
  3259. parseStyles: function(styles){
  3260. var out = {},
  3261. cssRe = this.cssRe,
  3262. matches;
  3263. if (styles) {
  3264. // Since we're using the g flag on the regex, we need to set the lastIndex.
  3265. // This automatically happens on some implementations, but not others, see:
  3266. // http://stackoverflow.com/questions/2645273/javascript-regular-expression-literal-persists-between-function-calls
  3267. // http://blog.stevenlevithan.com/archives/fixing-javascript-regexp
  3268. cssRe.lastIndex = 0;
  3269. while ((matches = cssRe.exec(styles))) {
  3270. out[matches[1]] = matches[2];
  3271. }
  3272. }
  3273. return out;
  3274. }
  3275. });
  3276. //TODO Need serious cleanups
  3277. (function(){
  3278. var doc = document,
  3279. AbstractElement = Ext.dom.AbstractElement,
  3280. activeElement = null,
  3281. isCSS1 = doc.compatMode == "CSS1Compat",
  3282. flyInstance,
  3283. fly = function (el) {
  3284. if (!flyInstance) {
  3285. flyInstance = new AbstractElement.Fly();
  3286. }
  3287. flyInstance.attach(el);
  3288. return flyInstance;
  3289. };
  3290. // If the browser does not support document.activeElement we need some assistance.
  3291. // This covers old Safari 3.2 (4.0 added activeElement along with just about all
  3292. // other browsers). We need this support to handle issues with old Safari.
  3293. if (!('activeElement' in doc) && doc.addEventListener) {
  3294. doc.addEventListener('focus',
  3295. function (ev) {
  3296. if (ev && ev.target) {
  3297. activeElement = (ev.target == doc) ? null : ev.target;
  3298. }
  3299. }, true);
  3300. }
  3301. /*
  3302. * Helper function to create the function that will restore the selection.
  3303. */
  3304. function makeSelectionRestoreFn (activeEl, start, end) {
  3305. return function () {
  3306. activeEl.selectionStart = start;
  3307. activeEl.selectionEnd = end;
  3308. };
  3309. }
  3310. AbstractElement.addInheritableStatics({
  3311. /**
  3312. * Returns the active element in the DOM. If the browser supports activeElement
  3313. * on the document, this is returned. If not, the focus is tracked and the active
  3314. * element is maintained internally.
  3315. * @return {HTMLElement} The active (focused) element in the document.
  3316. */
  3317. getActiveElement: function () {
  3318. return doc.activeElement || activeElement;
  3319. },
  3320. /**
  3321. * Creates a function to call to clean up problems with the work-around for the
  3322. * WebKit RightMargin bug. The work-around is to add "display: 'inline-block'" to
  3323. * the element before calling getComputedStyle and then to restore its original
  3324. * display value. The problem with this is that it corrupts the selection of an
  3325. * INPUT or TEXTAREA element (as in the "I-beam" goes away but ths focus remains).
  3326. * To cleanup after this, we need to capture the selection of any such element and
  3327. * then restore it after we have restored the display style.
  3328. *
  3329. * @param {Ext.dom.Element} target The top-most element being adjusted.
  3330. * @private
  3331. */
  3332. getRightMarginFixCleaner: function (target) {
  3333. var supports = Ext.supports,
  3334. hasInputBug = supports.DisplayChangeInputSelectionBug,
  3335. hasTextAreaBug = supports.DisplayChangeTextAreaSelectionBug,
  3336. activeEl,
  3337. tag,
  3338. start,
  3339. end;
  3340. if (hasInputBug || hasTextAreaBug) {
  3341. activeEl = doc.activeElement || activeElement; // save a call
  3342. tag = activeEl && activeEl.tagName;
  3343. if ((hasTextAreaBug && tag == 'TEXTAREA') ||
  3344. (hasInputBug && tag == 'INPUT' && activeEl.type == 'text')) {
  3345. if (Ext.dom.Element.isAncestor(target, activeEl)) {
  3346. start = activeEl.selectionStart;
  3347. end = activeEl.selectionEnd;
  3348. if (Ext.isNumber(start) && Ext.isNumber(end)) { // to be safe...
  3349. // We don't create the raw closure here inline because that
  3350. // will be costly even if we don't want to return it (nested
  3351. // function decls and exprs are often instantiated on entry
  3352. // regardless of whether execution ever reaches them):
  3353. return makeSelectionRestoreFn(activeEl, start, end);
  3354. }
  3355. }
  3356. }
  3357. }
  3358. return Ext.emptyFn; // avoid special cases, just return a nop
  3359. },
  3360. getViewWidth: function(full) {
  3361. return full ? Ext.dom.Element.getDocumentWidth() : Ext.dom.Element.getViewportWidth();
  3362. },
  3363. getViewHeight: function(full) {
  3364. return full ? Ext.dom.Element.getDocumentHeight() : Ext.dom.Element.getViewportHeight();
  3365. },
  3366. getDocumentHeight: function() {
  3367. return Math.max(!isCSS1 ? doc.body.scrollHeight : doc.documentElement.scrollHeight, Ext.dom.Element.getViewportHeight());
  3368. },
  3369. getDocumentWidth: function() {
  3370. return Math.max(!isCSS1 ? doc.body.scrollWidth : doc.documentElement.scrollWidth, Ext.dom.Element.getViewportWidth());
  3371. },
  3372. getViewportHeight: function(){
  3373. return Ext.isIE ?
  3374. (Ext.isStrict ? doc.documentElement.clientHeight : doc.body.clientHeight) :
  3375. self.innerHeight;
  3376. },
  3377. getViewportWidth: function() {
  3378. return (!Ext.isStrict && !Ext.isOpera) ? doc.body.clientWidth :
  3379. Ext.isIE ? doc.documentElement.clientWidth : self.innerWidth;
  3380. },
  3381. getY: function(el) {
  3382. return Ext.dom.Element.getXY(el)[1];
  3383. },
  3384. getX: function(el) {
  3385. return Ext.dom.Element.getXY(el)[0];
  3386. },
  3387. getXY: function(el) {
  3388. var bd = doc.body,
  3389. docEl = doc.documentElement,
  3390. leftBorder = 0,
  3391. topBorder = 0,
  3392. ret = [0,0],
  3393. round = Math.round,
  3394. box,
  3395. scroll;
  3396. el = Ext.getDom(el);
  3397. if(el != doc && el != bd){
  3398. // IE has the potential to throw when getBoundingClientRect called
  3399. // on element not attached to dom
  3400. if (Ext.isIE) {
  3401. try {
  3402. box = el.getBoundingClientRect();
  3403. // In some versions of IE, the documentElement (HTML element) will have a 2px border that gets included, so subtract it off
  3404. topBorder = docEl.clientTop || bd.clientTop;
  3405. leftBorder = docEl.clientLeft || bd.clientLeft;
  3406. } catch (ex) {
  3407. box = { left: 0, top: 0 };
  3408. }
  3409. } else {
  3410. box = el.getBoundingClientRect();
  3411. }
  3412. scroll = fly(document).getScroll();
  3413. ret = [round(box.left + scroll.left - leftBorder), round(box.top + scroll.top - topBorder)];
  3414. }
  3415. return ret;
  3416. },
  3417. setXY: function(el, xy) {
  3418. (el = Ext.fly(el, '_setXY')).position();
  3419. var pts = el.translatePoints(xy),
  3420. style = el.dom.style,
  3421. pos;
  3422. for (pos in pts) {
  3423. if (!isNaN(pts[pos])) {
  3424. style[pos] = pts[pos] + "px";
  3425. }
  3426. }
  3427. },
  3428. setX: function(el, x) {
  3429. Ext.dom.Element.setXY(el, [x, false]);
  3430. },
  3431. setY: function(el, y) {
  3432. Ext.dom.Element.setXY(el, [false, y]);
  3433. },
  3434. /**
  3435. * Serializes a DOM form into a url encoded string
  3436. * @param {Object} form The form
  3437. * @return {String} The url encoded form
  3438. */
  3439. serializeForm: function(form) {
  3440. var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements,
  3441. hasSubmit = false,
  3442. encoder = encodeURIComponent,
  3443. data = '',
  3444. eLen = fElements.length,
  3445. element, name, type, options, hasValue, e,
  3446. o, oLen, opt;
  3447. for (e = 0; e < eLen; e++) {
  3448. element = fElements[e];
  3449. name = element.name;
  3450. type = element.type;
  3451. options = element.options;
  3452. if (!element.disabled && name) {
  3453. if (/select-(one|multiple)/i.test(type)) {
  3454. oLen = options.length;
  3455. for (o = 0; o < oLen; o++) {
  3456. opt = options[o];
  3457. if (opt.selected) {
  3458. hasValue = opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttributeNode('value').specified;
  3459. data += Ext.String.format("{0}={1}&", encoder(name), encoder(hasValue ? opt.value : opt.text));
  3460. }
  3461. }
  3462. } else if (!(/file|undefined|reset|button/i.test(type))) {
  3463. if (!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)) {
  3464. data += encoder(name) + '=' + encoder(element.value) + '&';
  3465. hasSubmit = /submit/i.test(type);
  3466. }
  3467. }
  3468. }
  3469. }
  3470. return data.substr(0, data.length - 1);
  3471. }
  3472. });
  3473. }());
  3474. /**
  3475. * @class Ext.dom.AbstractElement
  3476. */
  3477. Ext.dom.AbstractElement.override({
  3478. /**
  3479. * Gets the x,y coordinates specified by the anchor position on the element.
  3480. * @param {String} [anchor] The specified anchor position (defaults to "c"). See {@link Ext.dom.Element#alignTo}
  3481. * for details on supported anchor positions.
  3482. * @param {Boolean} [local] True to get the local (element top/left-relative) anchor position instead
  3483. * of page coordinates
  3484. * @param {Object} [size] An object containing the size to use for calculating anchor position
  3485. * {width: (target width), height: (target height)} (defaults to the element's current size)
  3486. * @return {Array} [x, y] An array containing the element's x and y coordinates
  3487. */
  3488. getAnchorXY: function(anchor, local, size) {
  3489. //Passing a different size is useful for pre-calculating anchors,
  3490. //especially for anchored animations that change the el size.
  3491. anchor = (anchor || "tl").toLowerCase();
  3492. size = size || {};
  3493. var me = this,
  3494. vp = me.dom == document.body || me.dom == document,
  3495. width = size.width || vp ? window.innerWidth: me.getWidth(),
  3496. height = size.height || vp ? window.innerHeight: me.getHeight(),
  3497. xy,
  3498. rnd = Math.round,
  3499. myXY = me.getXY(),
  3500. extraX = vp ? 0: !local ? myXY[0] : 0,
  3501. extraY = vp ? 0: !local ? myXY[1] : 0,
  3502. hash = {
  3503. c: [rnd(width * 0.5), rnd(height * 0.5)],
  3504. t: [rnd(width * 0.5), 0],
  3505. l: [0, rnd(height * 0.5)],
  3506. r: [width, rnd(height * 0.5)],
  3507. b: [rnd(width * 0.5), height],
  3508. tl: [0, 0],
  3509. bl: [0, height],
  3510. br: [width, height],
  3511. tr: [width, 0]
  3512. };
  3513. xy = hash[anchor];
  3514. return [xy[0] + extraX, xy[1] + extraY];
  3515. },
  3516. alignToRe: /^([a-z]+)-([a-z]+)(\?)?$/,
  3517. /**
  3518. * Gets the x,y coordinates to align this element with another element. See {@link Ext.dom.Element#alignTo} for more info on the
  3519. * supported position values.
  3520. * @param {Ext.Element/HTMLElement/String} element The element to align to.
  3521. * @param {String} [position="tl-bl?"] The position to align to.
  3522. * @param {Array} [offsets=[0,0]] Offset the positioning by [x, y]
  3523. * @return {Array} [x, y]
  3524. */
  3525. getAlignToXY: function(el, position, offsets, local) {
  3526. local = !!local;
  3527. el = Ext.get(el);
  3528. //<debug>
  3529. if (!el || !el.dom) {
  3530. throw new Error("Element.alignToXY with an element that doesn't exist");
  3531. }
  3532. //</debug>
  3533. offsets = offsets || [0, 0];
  3534. if (!position || position == '?') {
  3535. position = 'tl-bl?';
  3536. }
  3537. else if (! (/-/).test(position) && position !== "") {
  3538. position = 'tl-' + position;
  3539. }
  3540. position = position.toLowerCase();
  3541. var me = this,
  3542. matches = position.match(this.alignToRe),
  3543. dw = window.innerWidth,
  3544. dh = window.innerHeight,
  3545. p1 = "",
  3546. p2 = "",
  3547. a1,
  3548. a2,
  3549. x,
  3550. y,
  3551. swapX,
  3552. swapY,
  3553. p1x,
  3554. p1y,
  3555. p2x,
  3556. p2y,
  3557. width,
  3558. height,
  3559. region,
  3560. constrain;
  3561. if (!matches) {
  3562. throw "Element.alignTo with an invalid alignment " + position;
  3563. }
  3564. p1 = matches[1];
  3565. p2 = matches[2];
  3566. constrain = !!matches[3];
  3567. //Subtract the aligned el's internal xy from the target's offset xy
  3568. //plus custom offset to get the aligned el's new offset xy
  3569. a1 = me.getAnchorXY(p1, true);
  3570. a2 = el.getAnchorXY(p2, local);
  3571. x = a2[0] - a1[0] + offsets[0];
  3572. y = a2[1] - a1[1] + offsets[1];
  3573. if (constrain) {
  3574. width = me.getWidth();
  3575. height = me.getHeight();
  3576. region = el.getPageBox();
  3577. //If we are at a viewport boundary and the aligned el is anchored on a target border that is
  3578. //perpendicular to the vp border, allow the aligned el to slide on that border,
  3579. //otherwise swap the aligned el to the opposite border of the target.
  3580. p1y = p1.charAt(0);
  3581. p1x = p1.charAt(p1.length - 1);
  3582. p2y = p2.charAt(0);
  3583. p2x = p2.charAt(p2.length - 1);
  3584. swapY = ((p1y == "t" && p2y == "b") || (p1y == "b" && p2y == "t"));
  3585. swapX = ((p1x == "r" && p2x == "l") || (p1x == "l" && p2x == "r"));
  3586. if (x + width > dw) {
  3587. x = swapX ? region.left - width: dw - width;
  3588. }
  3589. if (x < 0) {
  3590. x = swapX ? region.right: 0;
  3591. }
  3592. if (y + height > dh) {
  3593. y = swapY ? region.top - height: dh - height;
  3594. }
  3595. if (y < 0) {
  3596. y = swapY ? region.bottom: 0;
  3597. }
  3598. }
  3599. return [x, y];
  3600. },
  3601. // private
  3602. getAnchor: function(){
  3603. var data = (this.$cache || this.getCache()).data,
  3604. anchor;
  3605. if (!this.dom) {
  3606. return;
  3607. }
  3608. anchor = data._anchor;
  3609. if(!anchor){
  3610. anchor = data._anchor = {};
  3611. }
  3612. return anchor;
  3613. },
  3614. // private ==> used outside of core
  3615. adjustForConstraints: function(xy, parent) {
  3616. var vector = this.getConstrainVector(parent, xy);
  3617. if (vector) {
  3618. xy[0] += vector[0];
  3619. xy[1] += vector[1];
  3620. }
  3621. return xy;
  3622. }
  3623. });
  3624. /**
  3625. * @class Ext.dom.AbstractElement
  3626. */
  3627. Ext.dom.AbstractElement.addMethods({
  3628. /**
  3629. * Appends the passed element(s) to this element
  3630. * @param {String/HTMLElement/Ext.dom.AbstractElement} el
  3631. * The id of the node, a DOM Node or an existing Element.
  3632. * @return {Ext.dom.AbstractElement} This element
  3633. */
  3634. appendChild: function(el) {
  3635. return Ext.get(el).appendTo(this);
  3636. },
  3637. /**
  3638. * Appends this element to the passed element
  3639. * @param {String/HTMLElement/Ext.dom.AbstractElement} el The new parent element.
  3640. * The id of the node, a DOM Node or an existing Element.
  3641. * @return {Ext.dom.AbstractElement} This element
  3642. */
  3643. appendTo: function(el) {
  3644. Ext.getDom(el).appendChild(this.dom);
  3645. return this;
  3646. },
  3647. /**
  3648. * Inserts this element before the passed element in the DOM
  3649. * @param {String/HTMLElement/Ext.dom.AbstractElement} el The element before which this element will be inserted.
  3650. * The id of the node, a DOM Node or an existing Element.
  3651. * @return {Ext.dom.AbstractElement} This element
  3652. */
  3653. insertBefore: function(el) {
  3654. el = Ext.getDom(el);
  3655. el.parentNode.insertBefore(this.dom, el);
  3656. return this;
  3657. },
  3658. /**
  3659. * Inserts this element after the passed element in the DOM
  3660. * @param {String/HTMLElement/Ext.dom.AbstractElement} el The element to insert after.
  3661. * The id of the node, a DOM Node or an existing Element.
  3662. * @return {Ext.dom.AbstractElement} This element
  3663. */
  3664. insertAfter: function(el) {
  3665. el = Ext.getDom(el);
  3666. el.parentNode.insertBefore(this.dom, el.nextSibling);
  3667. return this;
  3668. },
  3669. /**
  3670. * Inserts (or creates) an element (or DomHelper config) as the first child of this element
  3671. * @param {String/HTMLElement/Ext.dom.AbstractElement/Object} el The id or element to insert or a DomHelper config
  3672. * to create and insert
  3673. * @return {Ext.dom.AbstractElement} The new child
  3674. */
  3675. insertFirst: function(el, returnDom) {
  3676. el = el || {};
  3677. if (el.nodeType || el.dom || typeof el == 'string') { // element
  3678. el = Ext.getDom(el);
  3679. this.dom.insertBefore(el, this.dom.firstChild);
  3680. return !returnDom ? Ext.get(el) : el;
  3681. }
  3682. else { // dh config
  3683. return this.createChild(el, this.dom.firstChild, returnDom);
  3684. }
  3685. },
  3686. /**
  3687. * Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element
  3688. * @param {String/HTMLElement/Ext.dom.AbstractElement/Object/Array} el The id, element to insert or a DomHelper config
  3689. * to create and insert *or* an array of any of those.
  3690. * @param {String} [where='before'] 'before' or 'after'
  3691. * @param {Boolean} [returnDom=false] True to return the .;ll;l,raw DOM element instead of Ext.dom.AbstractElement
  3692. * @return {Ext.dom.AbstractElement} The inserted Element. If an array is passed, the last inserted element is returned.
  3693. */
  3694. insertSibling: function(el, where, returnDom){
  3695. var me = this,
  3696. isAfter = (where || 'before').toLowerCase() == 'after',
  3697. rt, insertEl, eLen, e;
  3698. if (Ext.isArray(el)) {
  3699. insertEl = me;
  3700. eLen = el.length;
  3701. for (e = 0; e < eLen; e++) {
  3702. rt = Ext.fly(insertEl, '_internal').insertSibling(el[e], where, returnDom);
  3703. if (isAfter) {
  3704. insertEl = rt;
  3705. }
  3706. }
  3707. return rt;
  3708. }
  3709. el = el || {};
  3710. if(el.nodeType || el.dom){
  3711. rt = me.dom.parentNode.insertBefore(Ext.getDom(el), isAfter ? me.dom.nextSibling : me.dom);
  3712. if (!returnDom) {
  3713. rt = Ext.get(rt);
  3714. }
  3715. }else{
  3716. if (isAfter && !me.dom.nextSibling) {
  3717. rt = Ext.core.DomHelper.append(me.dom.parentNode, el, !returnDom);
  3718. } else {
  3719. rt = Ext.core.DomHelper[isAfter ? 'insertAfter' : 'insertBefore'](me.dom, el, !returnDom);
  3720. }
  3721. }
  3722. return rt;
  3723. },
  3724. /**
  3725. * Replaces the passed element with this element
  3726. * @param {String/HTMLElement/Ext.dom.AbstractElement} el The element to replace.
  3727. * The id of the node, a DOM Node or an existing Element.
  3728. * @return {Ext.dom.AbstractElement} This element
  3729. */
  3730. replace: function(el) {
  3731. el = Ext.get(el);
  3732. this.insertBefore(el);
  3733. el.remove();
  3734. return this;
  3735. },
  3736. /**
  3737. * Replaces this element with the passed element
  3738. * @param {String/HTMLElement/Ext.dom.AbstractElement/Object} el The new element (id of the node, a DOM Node
  3739. * or an existing Element) or a DomHelper config of an element to create
  3740. * @return {Ext.dom.AbstractElement} This element
  3741. */
  3742. replaceWith: function(el){
  3743. var me = this;
  3744. if(el.nodeType || el.dom || typeof el == 'string'){
  3745. el = Ext.get(el);
  3746. me.dom.parentNode.insertBefore(el, me.dom);
  3747. }else{
  3748. el = Ext.core.DomHelper.insertBefore(me.dom, el);
  3749. }
  3750. delete Ext.cache[me.id];
  3751. Ext.removeNode(me.dom);
  3752. me.id = Ext.id(me.dom = el);
  3753. Ext.dom.AbstractElement.addToCache(me.isFlyweight ? new Ext.dom.AbstractElement(me.dom) : me);
  3754. return me;
  3755. },
  3756. /**
  3757. * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
  3758. * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
  3759. * automatically generated with the specified attributes.
  3760. * @param {HTMLElement} [insertBefore] a child element of this element
  3761. * @param {Boolean} [returnDom=false] true to return the dom node instead of creating an Element
  3762. * @return {Ext.dom.AbstractElement} The new child element
  3763. */
  3764. createChild: function(config, insertBefore, returnDom) {
  3765. config = config || {tag:'div'};
  3766. if (insertBefore) {
  3767. return Ext.core.DomHelper.insertBefore(insertBefore, config, returnDom !== true);
  3768. }
  3769. else {
  3770. return Ext.core.DomHelper[!this.dom.firstChild ? 'insertFirst' : 'append'](this.dom, config, returnDom !== true);
  3771. }
  3772. },
  3773. /**
  3774. * Creates and wraps this element with another element
  3775. * @param {Object} [config] DomHelper element config object for the wrapper element or null for an empty div
  3776. * @param {Boolean} [returnDom=false] True to return the raw DOM element instead of Ext.dom.AbstractElement
  3777. * @param {String} [selector] A {@link Ext.dom.Query DomQuery} selector to select a descendant node within the created element to use as the wrapping element.
  3778. * @return {HTMLElement/Ext.dom.AbstractElement} The newly created wrapper element
  3779. */
  3780. wrap: function(config, returnDom, selector) {
  3781. var newEl = Ext.core.DomHelper.insertBefore(this.dom, config || {tag: "div"}, true),
  3782. target = newEl;
  3783. if (selector) {
  3784. target = Ext.DomQuery.selectNode(selector, newEl.dom);
  3785. }
  3786. target.appendChild(this.dom);
  3787. return returnDom ? newEl.dom : newEl;
  3788. },
  3789. /**
  3790. * Inserts an html fragment into this element
  3791. * @param {String} where Where to insert the html in relation to this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
  3792. * See {@link Ext.dom.Helper#insertHtml} for details.
  3793. * @param {String} html The HTML fragment
  3794. * @param {Boolean} [returnEl=false] True to return an Ext.dom.AbstractElement
  3795. * @return {HTMLElement/Ext.dom.AbstractElement} The inserted node (or nearest related if more than 1 inserted)
  3796. */
  3797. insertHtml: function(where, html, returnEl) {
  3798. var el = Ext.core.DomHelper.insertHtml(where, this.dom, html);
  3799. return returnEl ? Ext.get(el) : el;
  3800. }
  3801. });
  3802. /**
  3803. * @class Ext.dom.AbstractElement
  3804. */
  3805. (function(){
  3806. var Element = Ext.dom.AbstractElement;
  3807. Element.override({
  3808. /**
  3809. * Gets the current X position of the element based on page coordinates. Element must be part of the DOM
  3810. * tree to have page coordinates (display:none or elements not appended return false).
  3811. * @return {Number} The X position of the element
  3812. */
  3813. getX: function(el) {
  3814. return this.getXY(el)[0];
  3815. },
  3816. /**
  3817. * Gets the current Y position of the element based on page coordinates. Element must be part of the DOM
  3818. * tree to have page coordinates (display:none or elements not appended return false).
  3819. * @return {Number} The Y position of the element
  3820. */
  3821. getY: function(el) {
  3822. return this.getXY(el)[1];
  3823. },
  3824. /**
  3825. * Gets the current position of the element based on page coordinates. Element must be part of the DOM
  3826. * tree to have page coordinates (display:none or elements not appended return false).
  3827. * @return {Array} The XY position of the element
  3828. */
  3829. getXY: function() {
  3830. // @FEATUREDETECT
  3831. var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0));
  3832. return [point.x, point.y];
  3833. },
  3834. /**
  3835. * Returns the offsets of this element from the passed element. Both element must be part of the DOM
  3836. * tree and not have display:none to have page coordinates.
  3837. * @param {Ext.Element/HTMLElement/String} element The element to get the offsets from.
  3838. * @return {Array} The XY page offsets (e.g. [100, -200])
  3839. */
  3840. getOffsetsTo: function(el){
  3841. var o = this.getXY(),
  3842. e = Ext.fly(el, '_internal').getXY();
  3843. return [o[0]-e[0],o[1]-e[1]];
  3844. },
  3845. /**
  3846. * Sets the X position of the element based on page coordinates. Element must be part of the DOM tree
  3847. * to have page coordinates (display:none or elements not appended return false).
  3848. * @param {Number} The X position of the element
  3849. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element
  3850. * animation config object
  3851. * @return {Ext.dom.AbstractElement} this
  3852. */
  3853. setX: function(x){
  3854. return this.setXY([x, this.getY()]);
  3855. },
  3856. /**
  3857. * Sets the Y position of the element based on page coordinates. Element must be part of the DOM tree
  3858. * to have page coordinates (display:none or elements not appended return false).
  3859. * @param {Number} The Y position of the element
  3860. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element
  3861. * animation config object
  3862. * @return {Ext.dom.AbstractElement} this
  3863. */
  3864. setY: function(y) {
  3865. return this.setXY([this.getX(), y]);
  3866. },
  3867. /**
  3868. * Sets the element's left position directly using CSS style (instead of {@link #setX}).
  3869. * @param {String} left The left CSS property value
  3870. * @return {Ext.dom.AbstractElement} this
  3871. */
  3872. setLeft: function(left) {
  3873. this.setStyle('left', Element.addUnits(left));
  3874. return this;
  3875. },
  3876. /**
  3877. * Sets the element's top position directly using CSS style (instead of {@link #setY}).
  3878. * @param {String} top The top CSS property value
  3879. * @return {Ext.dom.AbstractElement} this
  3880. */
  3881. setTop: function(top) {
  3882. this.setStyle('top', Element.addUnits(top));
  3883. return this;
  3884. },
  3885. /**
  3886. * Sets the element's CSS right style.
  3887. * @param {String} right The right CSS property value
  3888. * @return {Ext.dom.AbstractElement} this
  3889. */
  3890. setRight: function(right) {
  3891. this.setStyle('right', Element.addUnits(right));
  3892. return this;
  3893. },
  3894. /**
  3895. * Sets the element's CSS bottom style.
  3896. * @param {String} bottom The bottom CSS property value
  3897. * @return {Ext.dom.AbstractElement} this
  3898. */
  3899. setBottom: function(bottom) {
  3900. this.setStyle('bottom', Element.addUnits(bottom));
  3901. return this;
  3902. },
  3903. /**
  3904. * Sets the position of the element in page coordinates, regardless of how the element is positioned.
  3905. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  3906. * @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
  3907. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element animation config object
  3908. * @return {Ext.dom.AbstractElement} this
  3909. */
  3910. setXY: function(pos) {
  3911. var me = this,
  3912. pts,
  3913. style,
  3914. pt;
  3915. if (arguments.length > 1) {
  3916. pos = [pos, arguments[1]];
  3917. }
  3918. // me.position();
  3919. pts = me.translatePoints(pos);
  3920. style = me.dom.style;
  3921. for (pt in pts) {
  3922. if (!pts.hasOwnProperty(pt)) {
  3923. continue;
  3924. }
  3925. if (!isNaN(pts[pt])) {
  3926. style[pt] = pts[pt] + "px";
  3927. }
  3928. }
  3929. return me;
  3930. },
  3931. /**
  3932. * Gets the left X coordinate
  3933. * @param {Boolean} local True to get the local css position instead of page coordinate
  3934. * @return {Number}
  3935. */
  3936. getLeft: function(local) {
  3937. return parseInt(this.getStyle('left'), 10) || 0;
  3938. },
  3939. /**
  3940. * Gets the right X coordinate of the element (element X position + element width)
  3941. * @param {Boolean} local True to get the local css position instead of page coordinate
  3942. * @return {Number}
  3943. */
  3944. getRight: function(local) {
  3945. return parseInt(this.getStyle('right'), 10) || 0;
  3946. },
  3947. /**
  3948. * Gets the top Y coordinate
  3949. * @param {Boolean} local True to get the local css position instead of page coordinate
  3950. * @return {Number}
  3951. */
  3952. getTop: function(local) {
  3953. return parseInt(this.getStyle('top'), 10) || 0;
  3954. },
  3955. /**
  3956. * Gets the bottom Y coordinate of the element (element Y position + element height)
  3957. * @param {Boolean} local True to get the local css position instead of page coordinate
  3958. * @return {Number}
  3959. */
  3960. getBottom: function(local) {
  3961. return parseInt(this.getStyle('bottom'), 10) || 0;
  3962. },
  3963. /**
  3964. * Translates the passed page coordinates into left/top css values for this element
  3965. * @param {Number/Array} x The page x or an array containing [x, y]
  3966. * @param {Number} [y] The page y, required if x is not an array
  3967. * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
  3968. */
  3969. translatePoints: function(x, y) {
  3970. y = isNaN(x[1]) ? y : x[1];
  3971. x = isNaN(x[0]) ? x : x[0];
  3972. var me = this,
  3973. relative = me.isStyle('position', 'relative'),
  3974. o = me.getXY(),
  3975. l = parseInt(me.getStyle('left'), 10),
  3976. t = parseInt(me.getStyle('top'), 10);
  3977. l = !isNaN(l) ? l : (relative ? 0 : me.dom.offsetLeft);
  3978. t = !isNaN(t) ? t : (relative ? 0 : me.dom.offsetTop);
  3979. return {left: (x - o[0] + l), top: (y - o[1] + t)};
  3980. },
  3981. /**
  3982. * Sets the element's box. Use getBox() on another element to get a box obj.
  3983. * If animate is true then width, height, x and y will be animated concurrently.
  3984. * @param {Object} box The box to fill {x, y, width, height}
  3985. * @param {Boolean} [adjust] Whether to adjust for box-model issues automatically
  3986. * @param {Boolean/Object} [animate] true for the default animation or a standard
  3987. * Element animation config object
  3988. * @return {Ext.dom.AbstractElement} this
  3989. */
  3990. setBox: function(box) {
  3991. var me = this,
  3992. width = box.width,
  3993. height = box.height,
  3994. top = box.top,
  3995. left = box.left;
  3996. if (left !== undefined) {
  3997. me.setLeft(left);
  3998. }
  3999. if (top !== undefined) {
  4000. me.setTop(top);
  4001. }
  4002. if (width !== undefined) {
  4003. me.setWidth(width);
  4004. }
  4005. if (height !== undefined) {
  4006. me.setHeight(height);
  4007. }
  4008. return this;
  4009. },
  4010. /**
  4011. * Return an object defining the area of this Element which can be passed to {@link #setBox} to
  4012. * set another Element's size/location to match this element.
  4013. *
  4014. * @param {Boolean} [contentBox] If true a box for the content of the element is returned.
  4015. * @param {Boolean} [local] If true the element's left and top are returned instead of page x/y.
  4016. * @return {Object} box An object in the format:
  4017. *
  4018. * {
  4019. * x: <Element's X position>,
  4020. * y: <Element's Y position>,
  4021. * width: <Element's width>,
  4022. * height: <Element's height>,
  4023. * bottom: <Element's lower bound>,
  4024. * right: <Element's rightmost bound>
  4025. * }
  4026. *
  4027. * The returned object may also be addressed as an Array where index 0 contains the X position
  4028. * and index 1 contains the Y position. So the result may also be used for {@link #setXY}
  4029. */
  4030. getBox: function(contentBox, local) {
  4031. var me = this,
  4032. dom = me.dom,
  4033. width = dom.offsetWidth,
  4034. height = dom.offsetHeight,
  4035. xy, box, l, r, t, b;
  4036. if (!local) {
  4037. xy = me.getXY();
  4038. }
  4039. else if (contentBox) {
  4040. xy = [0,0];
  4041. }
  4042. else {
  4043. xy = [parseInt(me.getStyle("left"), 10) || 0, parseInt(me.getStyle("top"), 10) || 0];
  4044. }
  4045. if (!contentBox) {
  4046. box = {
  4047. x: xy[0],
  4048. y: xy[1],
  4049. 0: xy[0],
  4050. 1: xy[1],
  4051. width: width,
  4052. height: height
  4053. };
  4054. }
  4055. else {
  4056. l = me.getBorderWidth.call(me, "l") + me.getPadding.call(me, "l");
  4057. r = me.getBorderWidth.call(me, "r") + me.getPadding.call(me, "r");
  4058. t = me.getBorderWidth.call(me, "t") + me.getPadding.call(me, "t");
  4059. b = me.getBorderWidth.call(me, "b") + me.getPadding.call(me, "b");
  4060. box = {
  4061. x: xy[0] + l,
  4062. y: xy[1] + t,
  4063. 0: xy[0] + l,
  4064. 1: xy[1] + t,
  4065. width: width - (l + r),
  4066. height: height - (t + b)
  4067. };
  4068. }
  4069. box.left = box.x;
  4070. box.top = box.y;
  4071. box.right = box.x + box.width;
  4072. box.bottom = box.y + box.height;
  4073. return box;
  4074. },
  4075. /**
  4076. * Return an object defining the area of this Element which can be passed to {@link #setBox} to
  4077. * set another Element's size/location to match this element.
  4078. *
  4079. * @param {Boolean} [asRegion] If true an Ext.util.Region will be returned
  4080. * @return {Object} box An object in the format
  4081. *
  4082. * {
  4083. * left: <Element's X position>,
  4084. * top: <Element's Y position>,
  4085. * width: <Element's width>,
  4086. * height: <Element's height>,
  4087. * bottom: <Element's lower bound>,
  4088. * right: <Element's rightmost bound>
  4089. * }
  4090. *
  4091. * The returned object may also be addressed as an Array where index 0 contains the X position
  4092. * and index 1 contains the Y position. So the result may also be used for {@link #setXY}
  4093. */
  4094. getPageBox: function(getRegion) {
  4095. var me = this,
  4096. el = me.dom,
  4097. w = el.offsetWidth,
  4098. h = el.offsetHeight,
  4099. xy = me.getXY(),
  4100. t = xy[1],
  4101. r = xy[0] + w,
  4102. b = xy[1] + h,
  4103. l = xy[0];
  4104. if (!el) {
  4105. return new Ext.util.Region();
  4106. }
  4107. if (getRegion) {
  4108. return new Ext.util.Region(t, r, b, l);
  4109. }
  4110. else {
  4111. return {
  4112. left: l,
  4113. top: t,
  4114. width: w,
  4115. height: h,
  4116. right: r,
  4117. bottom: b
  4118. };
  4119. }
  4120. }
  4121. });
  4122. }());
  4123. /**
  4124. * @class Ext.dom.AbstractElement
  4125. */
  4126. (function(){
  4127. // local style camelizing for speed
  4128. var Element = Ext.dom.AbstractElement,
  4129. view = document.defaultView,
  4130. array = Ext.Array,
  4131. trimRe = /^\s+|\s+$/g,
  4132. wordsRe = /\w/g,
  4133. spacesRe = /\s+/,
  4134. transparentRe = /^(?:transparent|(?:rgba[(](?:\s*\d+\s*[,]){3}\s*0\s*[)]))$/i,
  4135. hasClassList = Ext.supports.ClassList,
  4136. PADDING = 'padding',
  4137. MARGIN = 'margin',
  4138. BORDER = 'border',
  4139. LEFT_SUFFIX = '-left',
  4140. RIGHT_SUFFIX = '-right',
  4141. TOP_SUFFIX = '-top',
  4142. BOTTOM_SUFFIX = '-bottom',
  4143. WIDTH = '-width',
  4144. // special markup used throughout Ext when box wrapping elements
  4145. borders = {l: BORDER + LEFT_SUFFIX + WIDTH, r: BORDER + RIGHT_SUFFIX + WIDTH, t: BORDER + TOP_SUFFIX + WIDTH, b: BORDER + BOTTOM_SUFFIX + WIDTH},
  4146. paddings = {l: PADDING + LEFT_SUFFIX, r: PADDING + RIGHT_SUFFIX, t: PADDING + TOP_SUFFIX, b: PADDING + BOTTOM_SUFFIX},
  4147. margins = {l: MARGIN + LEFT_SUFFIX, r: MARGIN + RIGHT_SUFFIX, t: MARGIN + TOP_SUFFIX, b: MARGIN + BOTTOM_SUFFIX};
  4148. Element.override({
  4149. /**
  4150. * This shared object is keyed by style name (e.g., 'margin-left' or 'marginLeft'). The
  4151. * values are objects with the following properties:
  4152. *
  4153. * * `name` (String) : The actual name to be presented to the DOM. This is typically the value
  4154. * returned by {@link #normalize}.
  4155. * * `get` (Function) : A hook function that will perform the get on this style. These
  4156. * functions receive "(dom, el)" arguments. The `dom` parameter is the DOM Element
  4157. * from which to get ths tyle. The `el` argument (may be null) is the Ext.Element.
  4158. * * `set` (Function) : A hook function that will perform the set on this style. These
  4159. * functions receive "(dom, value, el)" arguments. The `dom` parameter is the DOM Element
  4160. * from which to get ths tyle. The `value` parameter is the new value for the style. The
  4161. * `el` argument (may be null) is the Ext.Element.
  4162. *
  4163. * The `this` pointer is the object that contains `get` or `set`, which means that
  4164. * `this.name` can be accessed if needed. The hook functions are both optional.
  4165. * @private
  4166. */
  4167. styleHooks: {},
  4168. // private
  4169. addStyles : function(sides, styles){
  4170. var totalSize = 0,
  4171. sidesArr = (sides || '').match(wordsRe),
  4172. i,
  4173. len = sidesArr.length,
  4174. side,
  4175. styleSides = [];
  4176. if (len == 1) {
  4177. totalSize = Math.abs(parseFloat(this.getStyle(styles[sidesArr[0]])) || 0);
  4178. } else if (len) {
  4179. for (i = 0; i < len; i++) {
  4180. side = sidesArr[i];
  4181. styleSides.push(styles[side]);
  4182. }
  4183. //Gather all at once, returning a hash
  4184. styleSides = this.getStyle(styleSides);
  4185. for (i=0; i < len; i++) {
  4186. side = sidesArr[i];
  4187. totalSize += Math.abs(parseFloat(styleSides[styles[side]]) || 0);
  4188. }
  4189. }
  4190. return totalSize;
  4191. },
  4192. /**
  4193. * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
  4194. * @param {String/String[]} className The CSS classes to add separated by space, or an array of classes
  4195. * @return {Ext.dom.Element} this
  4196. * @method
  4197. */
  4198. addCls: hasClassList ?
  4199. function (className) {
  4200. //<debug warn>
  4201. if (String(className).indexOf('undefined') > -1) {
  4202. Ext.Logger.warn("called with an undefined className: " + className);
  4203. }
  4204. //</debug>
  4205. var me = this,
  4206. dom = me.dom,
  4207. classList,
  4208. newCls,
  4209. i,
  4210. len,
  4211. cls;
  4212. if (typeof(className) == 'string') {
  4213. // split string on spaces to make an array of className
  4214. className = className.replace(trimRe, '').split(spacesRe);
  4215. }
  4216. // the gain we have here is that we can skip parsing className and use the
  4217. // classList.contains method, so now O(M) not O(M+N)
  4218. if (dom && className && !!(len = className.length)) {
  4219. if (!dom.className) {
  4220. dom.className = className.join(' ');
  4221. } else {
  4222. classList = dom.classList;
  4223. for (i = 0; i < len; ++i) {
  4224. cls = className[i];
  4225. if (cls) {
  4226. if (!classList.contains(cls)) {
  4227. if (newCls) {
  4228. newCls.push(cls);
  4229. } else {
  4230. newCls = dom.className.replace(trimRe, '');
  4231. newCls = newCls ? [newCls, cls] : [cls];
  4232. }
  4233. }
  4234. }
  4235. }
  4236. if (newCls) {
  4237. dom.className = newCls.join(' '); // write to DOM once
  4238. }
  4239. }
  4240. }
  4241. return me;
  4242. } :
  4243. function(className) {
  4244. //<debug warn>
  4245. if (String(className).indexOf('undefined') > -1) {
  4246. Ext.Logger.warn("called with an undefined className: '" + className + "'");
  4247. }
  4248. //</debug>
  4249. var me = this,
  4250. dom = me.dom,
  4251. changed,
  4252. elClasses;
  4253. if (dom && className && className.length) {
  4254. elClasses = Ext.Element.mergeClsList(dom.className, className);
  4255. if (elClasses.changed) {
  4256. dom.className = elClasses.join(' '); // write to DOM once
  4257. }
  4258. }
  4259. return me;
  4260. },
  4261. /**
  4262. * Removes one or more CSS classes from the element.
  4263. * @param {String/String[]} className The CSS classes to remove separated by space, or an array of classes
  4264. * @return {Ext.dom.Element} this
  4265. */
  4266. removeCls: function(className) {
  4267. var me = this,
  4268. dom = me.dom,
  4269. len,
  4270. elClasses;
  4271. if (typeof(className) == 'string') {
  4272. // split string on spaces to make an array of className
  4273. className = className.replace(trimRe, '').split(spacesRe);
  4274. }
  4275. if (dom && dom.className && className && !!(len = className.length)) {
  4276. if (len == 1 && hasClassList) {
  4277. if (className[0]) {
  4278. dom.classList.remove(className[0]); // one DOM write
  4279. }
  4280. } else {
  4281. elClasses = Ext.Element.removeCls(dom.className, className);
  4282. if (elClasses.changed) {
  4283. dom.className = elClasses.join(' ');
  4284. }
  4285. }
  4286. }
  4287. return me;
  4288. },
  4289. /**
  4290. * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
  4291. * @param {String/String[]} className The CSS class to add, or an array of classes
  4292. * @return {Ext.dom.Element} this
  4293. */
  4294. radioCls: function(className) {
  4295. var cn = this.dom.parentNode.childNodes,
  4296. v,
  4297. i, len;
  4298. className = Ext.isArray(className) ? className: [className];
  4299. for (i = 0, len = cn.length; i < len; i++) {
  4300. v = cn[i];
  4301. if (v && v.nodeType == 1) {
  4302. Ext.fly(v, '_internal').removeCls(className);
  4303. }
  4304. }
  4305. return this.addCls(className);
  4306. },
  4307. /**
  4308. * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
  4309. * @param {String} className The CSS class to toggle
  4310. * @return {Ext.dom.Element} this
  4311. * @method
  4312. */
  4313. toggleCls: hasClassList ?
  4314. function (className) {
  4315. var me = this,
  4316. dom = me.dom;
  4317. if (dom) {
  4318. className = className.replace(trimRe, '');
  4319. if (className) {
  4320. dom.classList.toggle(className);
  4321. }
  4322. }
  4323. return me;
  4324. } :
  4325. function(className) {
  4326. var me = this;
  4327. return me.hasCls(className) ? me.removeCls(className) : me.addCls(className);
  4328. },
  4329. /**
  4330. * Checks if the specified CSS class exists on this element's DOM node.
  4331. * @param {String} className The CSS class to check for
  4332. * @return {Boolean} True if the class exists, else false
  4333. * @method
  4334. */
  4335. hasCls: hasClassList ?
  4336. function (className) {
  4337. var dom = this.dom;
  4338. return (dom && className) ? dom.classList.contains(className) : false;
  4339. } :
  4340. function(className) {
  4341. var dom = this.dom;
  4342. return dom ? className && (' '+dom.className+' ').indexOf(' '+className+' ') != -1 : false;
  4343. },
  4344. /**
  4345. * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
  4346. * @param {String} oldClassName The CSS class to replace
  4347. * @param {String} newClassName The replacement CSS class
  4348. * @return {Ext.dom.Element} this
  4349. */
  4350. replaceCls: function(oldClassName, newClassName){
  4351. return this.removeCls(oldClassName).addCls(newClassName);
  4352. },
  4353. /**
  4354. * Checks if the current value of a style is equal to a given value.
  4355. * @param {String} style property whose value is returned.
  4356. * @param {String} value to check against.
  4357. * @return {Boolean} true for when the current value equals the given value.
  4358. */
  4359. isStyle: function(style, val) {
  4360. return this.getStyle(style) == val;
  4361. },
  4362. /**
  4363. * Returns a named style property based on computed/currentStyle (primary) and
  4364. * inline-style if primary is not available.
  4365. *
  4366. * @param {String/String[]} property The style property (or multiple property names
  4367. * in an array) whose value is returned.
  4368. * @param {Boolean} [inline=false] if `true` only inline styles will be returned.
  4369. * @return {String/Object} The current value of the style property for this element
  4370. * (or a hash of named style values if multiple property arguments are requested).
  4371. * @method
  4372. */
  4373. getStyle: function (property, inline) {
  4374. var me = this,
  4375. dom = me.dom,
  4376. multiple = typeof property != 'string',
  4377. hooks = me.styleHooks,
  4378. prop = property,
  4379. props = prop,
  4380. len = 1,
  4381. domStyle, camel, values, hook, out, style, i;
  4382. if (multiple) {
  4383. values = {};
  4384. prop = props[0];
  4385. i = 0;
  4386. if (!(len = props.length)) {
  4387. return values;
  4388. }
  4389. }
  4390. if (!dom || dom.documentElement) {
  4391. return values || '';
  4392. }
  4393. domStyle = dom.style;
  4394. if (inline) {
  4395. style = domStyle;
  4396. } else {
  4397. // Caution: Firefox will not render "presentation" (ie. computed styles) in
  4398. // iframes that are display:none or those inheriting display:none. Similar
  4399. // issues with legacy Safari.
  4400. //
  4401. style = dom.ownerDocument.defaultView.getComputedStyle(dom, null);
  4402. // fallback to inline style if rendering context not available
  4403. if (!style) {
  4404. inline = true;
  4405. style = domStyle;
  4406. }
  4407. }
  4408. do {
  4409. hook = hooks[prop];
  4410. if (!hook) {
  4411. hooks[prop] = hook = { name: Element.normalize(prop) };
  4412. }
  4413. if (hook.get) {
  4414. out = hook.get(dom, me, inline, style);
  4415. } else {
  4416. camel = hook.name;
  4417. out = style[camel];
  4418. }
  4419. if (!multiple) {
  4420. return out;
  4421. }
  4422. values[prop] = out;
  4423. prop = props[++i];
  4424. } while (i < len);
  4425. return values;
  4426. },
  4427. getStyles: function () {
  4428. var props = Ext.Array.slice(arguments),
  4429. len = props.length,
  4430. inline;
  4431. if (len && typeof props[len-1] == 'boolean') {
  4432. inline = props.pop();
  4433. }
  4434. return this.getStyle(props, inline);
  4435. },
  4436. /**
  4437. * Returns true if the value of the given property is visually transparent. This
  4438. * may be due to a 'transparent' style value or an rgba value with 0 in the alpha
  4439. * component.
  4440. * @param {String} prop The style property whose value is to be tested.
  4441. * @return {Boolean} True if the style property is visually transparent.
  4442. */
  4443. isTransparent: function (prop) {
  4444. var value = this.getStyle(prop);
  4445. return value ? transparentRe.test(value) : false;
  4446. },
  4447. /**
  4448. * Wrapper for setting style properties, also takes single object parameter of multiple styles.
  4449. * @param {String/Object} property The style property to be set, or an object of multiple styles.
  4450. * @param {String} [value] The value to apply to the given property, or null if an object was passed.
  4451. * @return {Ext.dom.Element} this
  4452. */
  4453. setStyle: function(prop, value) {
  4454. var me = this,
  4455. dom = me.dom,
  4456. hooks = me.styleHooks,
  4457. style = dom.style,
  4458. name = prop,
  4459. hook;
  4460. // we don't promote the 2-arg form to object-form to avoid the overhead...
  4461. if (typeof name == 'string') {
  4462. hook = hooks[name];
  4463. if (!hook) {
  4464. hooks[name] = hook = { name: Element.normalize(name) };
  4465. }
  4466. value = (value == null) ? '' : value;
  4467. if (hook.set) {
  4468. hook.set(dom, value, me);
  4469. } else {
  4470. style[hook.name] = value;
  4471. }
  4472. if (hook.afterSet) {
  4473. hook.afterSet(dom, value, me);
  4474. }
  4475. } else {
  4476. for (name in prop) {
  4477. if (prop.hasOwnProperty(name)) {
  4478. hook = hooks[name];
  4479. if (!hook) {
  4480. hooks[name] = hook = { name: Element.normalize(name) };
  4481. }
  4482. value = prop[name];
  4483. value = (value == null) ? '' : value;
  4484. if (hook.set) {
  4485. hook.set(dom, value, me);
  4486. } else {
  4487. style[hook.name] = value;
  4488. }
  4489. if (hook.afterSet) {
  4490. hook.afterSet(dom, value, me);
  4491. }
  4492. }
  4493. }
  4494. }
  4495. return me;
  4496. },
  4497. /**
  4498. * Returns the offset height of the element
  4499. * @param {Boolean} [contentHeight] true to get the height minus borders and padding
  4500. * @return {Number} The element's height
  4501. */
  4502. getHeight: function(contentHeight) {
  4503. var dom = this.dom,
  4504. height = contentHeight ? (dom.clientHeight - this.getPadding("tb")) : dom.offsetHeight;
  4505. return height > 0 ? height: 0;
  4506. },
  4507. /**
  4508. * Returns the offset width of the element
  4509. * @param {Boolean} [contentWidth] true to get the width minus borders and padding
  4510. * @return {Number} The element's width
  4511. */
  4512. getWidth: function(contentWidth) {
  4513. var dom = this.dom,
  4514. width = contentWidth ? (dom.clientWidth - this.getPadding("lr")) : dom.offsetWidth;
  4515. return width > 0 ? width: 0;
  4516. },
  4517. /**
  4518. * Set the width of this Element.
  4519. * @param {Number/String} width The new width. This may be one of:
  4520. *
  4521. * - A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).
  4522. * - A String used to set the CSS width style. Animation may **not** be used.
  4523. *
  4524. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  4525. * @return {Ext.dom.Element} this
  4526. */
  4527. setWidth: function(width) {
  4528. var me = this;
  4529. me.dom.style.width = Element.addUnits(width);
  4530. return me;
  4531. },
  4532. /**
  4533. * Set the height of this Element.
  4534. *
  4535. * // change the height to 200px and animate with default configuration
  4536. * Ext.fly('elementId').setHeight(200, true);
  4537. *
  4538. * // change the height to 150px and animate with a custom configuration
  4539. * Ext.fly('elId').setHeight(150, {
  4540. * duration : 500, // animation will have a duration of .5 seconds
  4541. * // will change the content to "finished"
  4542. * callback: function(){ this.{@link #update}("finished"); }
  4543. * });
  4544. *
  4545. * @param {Number/String} height The new height. This may be one of:
  4546. *
  4547. * - A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels.)
  4548. * - A String used to set the CSS height style. Animation may **not** be used.
  4549. *
  4550. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  4551. * @return {Ext.dom.Element} this
  4552. */
  4553. setHeight: function(height) {
  4554. var me = this;
  4555. me.dom.style.height = Element.addUnits(height);
  4556. return me;
  4557. },
  4558. /**
  4559. * Gets the width of the border(s) for the specified side(s)
  4560. * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
  4561. * passing `'lr'` would get the border **l**eft width + the border **r**ight width.
  4562. * @return {Number} The width of the sides passed added together
  4563. */
  4564. getBorderWidth: function(side){
  4565. return this.addStyles(side, borders);
  4566. },
  4567. /**
  4568. * Gets the width of the padding(s) for the specified side(s)
  4569. * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
  4570. * passing `'lr'` would get the padding **l**eft + the padding **r**ight.
  4571. * @return {Number} The padding of the sides passed added together
  4572. */
  4573. getPadding: function(side){
  4574. return this.addStyles(side, paddings);
  4575. },
  4576. margins : margins,
  4577. /**
  4578. * More flexible version of {@link #setStyle} for setting style properties.
  4579. * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
  4580. * a function which returns such a specification.
  4581. * @return {Ext.dom.Element} this
  4582. */
  4583. applyStyles: function(styles) {
  4584. if (styles) {
  4585. var i,
  4586. len,
  4587. dom = this.dom;
  4588. if (typeof styles == 'function') {
  4589. styles = styles.call();
  4590. }
  4591. if (typeof styles == 'string') {
  4592. styles = Ext.util.Format.trim(styles).split(/\s*(?::|;)\s*/);
  4593. for (i = 0, len = styles.length; i < len;) {
  4594. dom.style[Element.normalize(styles[i++])] = styles[i++];
  4595. }
  4596. }
  4597. else if (typeof styles == 'object') {
  4598. this.setStyle(styles);
  4599. }
  4600. }
  4601. },
  4602. /**
  4603. * Set the size of this Element. If animation is true, both width and height will be animated concurrently.
  4604. * @param {Number/String} width The new width. This may be one of:
  4605. *
  4606. * - A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).
  4607. * - A String used to set the CSS width style. Animation may **not** be used.
  4608. * - A size object in the format `{width: widthValue, height: heightValue}`.
  4609. *
  4610. * @param {Number/String} height The new height. This may be one of:
  4611. *
  4612. * - A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels).
  4613. * - A String used to set the CSS height style. Animation may **not** be used.
  4614. *
  4615. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  4616. * @return {Ext.dom.Element} this
  4617. */
  4618. setSize: function(width, height) {
  4619. var me = this,
  4620. style = me.dom.style;
  4621. if (Ext.isObject(width)) {
  4622. // in case of object from getSize()
  4623. height = width.height;
  4624. width = width.width;
  4625. }
  4626. style.width = Element.addUnits(width);
  4627. style.height = Element.addUnits(height);
  4628. return me;
  4629. },
  4630. /**
  4631. * Returns the dimensions of the element available to lay content out in.
  4632. *
  4633. * If the element (or any ancestor element) has CSS style `display: none`, the dimensions will be zero.
  4634. *
  4635. * Example:
  4636. *
  4637. * var vpSize = Ext.getBody().getViewSize();
  4638. *
  4639. * // all Windows created afterwards will have a default value of 90% height and 95% width
  4640. * Ext.Window.override({
  4641. * width: vpSize.width * 0.9,
  4642. * height: vpSize.height * 0.95
  4643. * });
  4644. * // To handle window resizing you would have to hook onto onWindowResize.
  4645. *
  4646. * getViewSize utilizes clientHeight/clientWidth which excludes sizing of scrollbars.
  4647. * To obtain the size including scrollbars, use getStyleSize
  4648. *
  4649. * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
  4650. *
  4651. * @return {Object} Object describing width and height.
  4652. * @return {Number} return.width
  4653. * @return {Number} return.height
  4654. */
  4655. getViewSize: function() {
  4656. var doc = document,
  4657. dom = this.dom;
  4658. if (dom == doc || dom == doc.body) {
  4659. return {
  4660. width: Element.getViewportWidth(),
  4661. height: Element.getViewportHeight()
  4662. };
  4663. }
  4664. else {
  4665. return {
  4666. width: dom.clientWidth,
  4667. height: dom.clientHeight
  4668. };
  4669. }
  4670. },
  4671. /**
  4672. * Returns the size of the element.
  4673. * @param {Boolean} [contentSize] true to get the width/size minus borders and padding
  4674. * @return {Object} An object containing the element's size:
  4675. * @return {Number} return.width
  4676. * @return {Number} return.height
  4677. */
  4678. getSize: function(contentSize) {
  4679. var dom = this.dom;
  4680. return {
  4681. width: Math.max(0, contentSize ? (dom.clientWidth - this.getPadding("lr")) : dom.offsetWidth),
  4682. height: Math.max(0, contentSize ? (dom.clientHeight - this.getPadding("tb")) : dom.offsetHeight)
  4683. };
  4684. },
  4685. /**
  4686. * Forces the browser to repaint this element
  4687. * @return {Ext.dom.Element} this
  4688. */
  4689. repaint: function(){
  4690. var dom = this.dom;
  4691. this.addCls(Ext.baseCSSPrefix + 'repaint');
  4692. setTimeout(function(){
  4693. Ext.fly(dom).removeCls(Ext.baseCSSPrefix + 'repaint');
  4694. }, 1);
  4695. return this;
  4696. },
  4697. /**
  4698. * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
  4699. * then it returns the calculated width of the sides (see getPadding)
  4700. * @param {String} [sides] Any combination of l, r, t, b to get the sum of those sides
  4701. * @return {Object/Number}
  4702. */
  4703. getMargin: function(side){
  4704. var me = this,
  4705. hash = {t:"top", l:"left", r:"right", b: "bottom"},
  4706. key,
  4707. o,
  4708. margins;
  4709. if (!side) {
  4710. margins = [];
  4711. for (key in me.margins) {
  4712. if(me.margins.hasOwnProperty(key)) {
  4713. margins.push(me.margins[key]);
  4714. }
  4715. }
  4716. o = me.getStyle(margins);
  4717. if(o && typeof o == 'object') {
  4718. //now mixin nomalized values (from hash table)
  4719. for (key in me.margins) {
  4720. if(me.margins.hasOwnProperty(key)) {
  4721. o[hash[key]] = parseFloat(o[me.margins[key]]) || 0;
  4722. }
  4723. }
  4724. }
  4725. return o;
  4726. } else {
  4727. return me.addStyles.call(me, side, me.margins);
  4728. }
  4729. },
  4730. /**
  4731. * Puts a mask over this element to disable user interaction. Requires core.css.
  4732. * This method can only be applied to elements which accept child nodes.
  4733. * @param {String} [msg] A message to display in the mask
  4734. * @param {String} [msgCls] A css class to apply to the msg element
  4735. */
  4736. mask: function(msg, msgCls, transparent) {
  4737. var me = this,
  4738. dom = me.dom,
  4739. data = (me.$cache || me.getCache()).data,
  4740. el = data.mask,
  4741. mask,
  4742. size,
  4743. cls = '',
  4744. prefix = Ext.baseCSSPrefix;
  4745. me.addCls(prefix + 'masked');
  4746. if (me.getStyle("position") == "static") {
  4747. me.addCls(prefix + 'masked-relative');
  4748. }
  4749. if (el) {
  4750. el.remove();
  4751. }
  4752. if (msgCls && typeof msgCls == 'string' ) {
  4753. cls = ' ' + msgCls;
  4754. }
  4755. else {
  4756. cls = ' ' + prefix + 'mask-gray';
  4757. }
  4758. mask = me.createChild({
  4759. cls: prefix + 'mask' + ((transparent !== false) ? '' : (' ' + prefix + 'mask-gray')),
  4760. html: msg ? ('<div class="' + (msgCls || (prefix + 'mask-message')) + '">' + msg + '</div>') : ''
  4761. });
  4762. size = me.getSize();
  4763. data.mask = mask;
  4764. if (dom === document.body) {
  4765. size.height = window.innerHeight;
  4766. if (me.orientationHandler) {
  4767. Ext.EventManager.unOrientationChange(me.orientationHandler, me);
  4768. }
  4769. me.orientationHandler = function() {
  4770. size = me.getSize();
  4771. size.height = window.innerHeight;
  4772. mask.setSize(size);
  4773. };
  4774. Ext.EventManager.onOrientationChange(me.orientationHandler, me);
  4775. }
  4776. mask.setSize(size);
  4777. if (Ext.is.iPad) {
  4778. Ext.repaint();
  4779. }
  4780. },
  4781. /**
  4782. * Removes a previously applied mask.
  4783. */
  4784. unmask: function() {
  4785. var me = this,
  4786. data = (me.$cache || me.getCache()).data,
  4787. mask = data.mask,
  4788. prefix = Ext.baseCSSPrefix;
  4789. if (mask) {
  4790. mask.remove();
  4791. delete data.mask;
  4792. }
  4793. me.removeCls([prefix + 'masked', prefix + 'masked-relative']);
  4794. if (me.dom === document.body) {
  4795. Ext.EventManager.unOrientationChange(me.orientationHandler, me);
  4796. delete me.orientationHandler;
  4797. }
  4798. }
  4799. });
  4800. /**
  4801. * Creates mappings for 'margin-before' to 'marginLeft' (etc.) given the output
  4802. * map and an ordering pair (e.g., ['left', 'right']). The ordering pair is in
  4803. * before/after order.
  4804. */
  4805. Element.populateStyleMap = function (map, order) {
  4806. var baseStyles = ['margin-', 'padding-', 'border-width-'],
  4807. beforeAfter = ['before', 'after'],
  4808. index, style, name, i;
  4809. for (index = baseStyles.length; index--; ) {
  4810. for (i = 2; i--; ) {
  4811. style = baseStyles[index] + beforeAfter[i]; // margin-before
  4812. // ex: maps margin-before and marginBefore to marginLeft
  4813. map[Element.normalize(style)] = map[style] = {
  4814. name: Element.normalize(baseStyles[index] + order[i])
  4815. };
  4816. }
  4817. }
  4818. };
  4819. Ext.onReady(function () {
  4820. var supports = Ext.supports,
  4821. styleHooks,
  4822. colorStyles, i, name, camel;
  4823. function fixTransparent (dom, el, inline, style) {
  4824. var value = style[this.name] || '';
  4825. return transparentRe.test(value) ? 'transparent' : value;
  4826. }
  4827. function fixRightMargin (dom, el, inline, style) {
  4828. var result = style.marginRight,
  4829. domStyle, display;
  4830. // Ignore cases when the margin is correctly reported as 0, the bug only shows
  4831. // numbers larger.
  4832. if (result != '0px') {
  4833. domStyle = dom.style;
  4834. display = domStyle.display;
  4835. domStyle.display = 'inline-block';
  4836. result = (inline ? style : dom.ownerDocument.defaultView.getComputedStyle(dom, null)).marginRight;
  4837. domStyle.display = display;
  4838. }
  4839. return result;
  4840. }
  4841. function fixRightMarginAndInputFocus (dom, el, inline, style) {
  4842. var result = style.marginRight,
  4843. domStyle, cleaner, display;
  4844. if (result != '0px') {
  4845. domStyle = dom.style;
  4846. cleaner = Element.getRightMarginFixCleaner(dom);
  4847. display = domStyle.display;
  4848. domStyle.display = 'inline-block';
  4849. result = (inline ? style : dom.ownerDocument.defaultView.getComputedStyle(dom, '')).marginRight;
  4850. domStyle.display = display;
  4851. cleaner();
  4852. }
  4853. return result;
  4854. }
  4855. styleHooks = Element.prototype.styleHooks;
  4856. // Populate the LTR flavors of margin-before et.al. (see Ext.rtl.AbstractElement):
  4857. Element.populateStyleMap(styleHooks, ['left', 'right']);
  4858. // Ext.supports needs to be initialized (we run very early in the onready sequence),
  4859. // but it is OK to call Ext.supports.init() more times than necessary...
  4860. if (supports.init) {
  4861. supports.init();
  4862. }
  4863. // Fix bug caused by this: https://bugs.webkit.org/show_bug.cgi?id=13343
  4864. if (!supports.RightMargin) {
  4865. styleHooks.marginRight = styleHooks['margin-right'] = {
  4866. name: 'marginRight',
  4867. // TODO - Touch should use conditional compilation here or ensure that the
  4868. // underlying Ext.supports flags are set correctly...
  4869. get: (supports.DisplayChangeInputSelectionBug || supports.DisplayChangeTextAreaSelectionBug) ?
  4870. fixRightMarginAndInputFocus : fixRightMargin
  4871. };
  4872. }
  4873. if (!supports.TransparentColor) {
  4874. colorStyles = ['background-color', 'border-color', 'color', 'outline-color'];
  4875. for (i = colorStyles.length; i--; ) {
  4876. name = colorStyles[i];
  4877. camel = Element.normalize(name);
  4878. styleHooks[name] = styleHooks[camel] = {
  4879. name: camel,
  4880. get: fixTransparent
  4881. };
  4882. }
  4883. }
  4884. });
  4885. }());
  4886. /**
  4887. * @class Ext.dom.AbstractElement
  4888. */
  4889. Ext.dom.AbstractElement.override({
  4890. /**
  4891. * Looks at this node and then at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
  4892. * @param {String} selector The simple selector to test
  4893. * @param {Number/String/HTMLElement/Ext.Element} [limit]
  4894. * The max depth to search as a number or an element which causes the upward traversal to stop
  4895. * and is <b>not</b> considered for inclusion as the result. (defaults to 50 || document.documentElement)
  4896. * @param {Boolean} [returnEl=false] True to return a Ext.Element object instead of DOM node
  4897. * @return {HTMLElement} The matching DOM node (or null if no match was found)
  4898. */
  4899. findParent: function(simpleSelector, limit, returnEl) {
  4900. var target = this.dom,
  4901. topmost = document.documentElement,
  4902. depth = 0,
  4903. stopEl;
  4904. limit = limit || 50;
  4905. if (isNaN(limit)) {
  4906. stopEl = Ext.getDom(limit);
  4907. limit = Number.MAX_VALUE;
  4908. }
  4909. while (target && target.nodeType == 1 && depth < limit && target != topmost && target != stopEl) {
  4910. if (Ext.DomQuery.is(target, simpleSelector)) {
  4911. return returnEl ? Ext.get(target) : target;
  4912. }
  4913. depth++;
  4914. target = target.parentNode;
  4915. }
  4916. return null;
  4917. },
  4918. /**
  4919. * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
  4920. * @param {String} selector The simple selector to test
  4921. * @param {Number/String/HTMLElement/Ext.Element} [limit]
  4922. * The max depth to search as a number or an element which causes the upward traversal to stop
  4923. * and is <b>not</b> considered for inclusion as the result. (defaults to 50 || document.documentElement)
  4924. * @param {Boolean} [returnEl=false] True to return a Ext.Element object instead of DOM node
  4925. * @return {HTMLElement} The matching DOM node (or null if no match was found)
  4926. */
  4927. findParentNode: function(simpleSelector, limit, returnEl) {
  4928. var p = Ext.fly(this.dom.parentNode, '_internal');
  4929. return p ? p.findParent(simpleSelector, limit, returnEl) : null;
  4930. },
  4931. /**
  4932. * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child).
  4933. * This is a shortcut for findParentNode() that always returns an Ext.dom.Element.
  4934. * @param {String} selector The simple selector to test
  4935. * @param {Number/String/HTMLElement/Ext.Element} [limit]
  4936. * The max depth to search as a number or an element which causes the upward traversal to stop
  4937. * and is <b>not</b> considered for inclusion as the result. (defaults to 50 || document.documentElement)
  4938. * @return {Ext.Element} The matching DOM node (or null if no match was found)
  4939. */
  4940. up: function(simpleSelector, limit) {
  4941. return this.findParentNode(simpleSelector, limit, true);
  4942. },
  4943. /**
  4944. * Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
  4945. * @param {String} selector The CSS selector
  4946. * @param {Boolean} [unique] True to create a unique Ext.Element for each element. Defaults to a shared flyweight object.
  4947. * @return {Ext.CompositeElement} The composite element
  4948. */
  4949. select: function(selector, composite) {
  4950. return Ext.dom.Element.select(selector, this.dom, composite);
  4951. },
  4952. /**
  4953. * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
  4954. * @param {String} selector The CSS selector
  4955. * @return {HTMLElement[]} An array of the matched nodes
  4956. */
  4957. query: function(selector) {
  4958. return Ext.DomQuery.select(selector, this.dom);
  4959. },
  4960. /**
  4961. * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
  4962. * @param {String} selector The CSS selector
  4963. * @param {Boolean} [returnDom=false] True to return the DOM node instead of Ext.dom.Element
  4964. * @return {HTMLElement/Ext.dom.Element} The child Ext.dom.Element (or DOM node if returnDom = true)
  4965. */
  4966. down: function(selector, returnDom) {
  4967. var n = Ext.DomQuery.selectNode(selector, this.dom);
  4968. return returnDom ? n : Ext.get(n);
  4969. },
  4970. /**
  4971. * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
  4972. * @param {String} selector The CSS selector
  4973. * @param {Boolean} [returnDom=false] True to return the DOM node instead of Ext.dom.Element.
  4974. * @return {HTMLElement/Ext.dom.Element} The child Ext.dom.Element (or DOM node if returnDom = true)
  4975. */
  4976. child: function(selector, returnDom) {
  4977. var node,
  4978. me = this,
  4979. id;
  4980. // Pull the ID from the DOM (Ext.id also ensures that there *is* an ID).
  4981. // If this object is a Flyweight, it will not have an ID
  4982. id = Ext.id(me.dom);
  4983. // Escape "invalid" chars
  4984. id = Ext.escapeId(id);
  4985. node = Ext.DomQuery.selectNode('#' + id + " > " + selector, me.dom);
  4986. return returnDom ? node : Ext.get(node);
  4987. },
  4988. /**
  4989. * Gets the parent node for this element, optionally chaining up trying to match a selector
  4990. * @param {String} [selector] Find a parent node that matches the passed simple selector
  4991. * @param {Boolean} [returnDom=false] True to return a raw dom node instead of an Ext.dom.Element
  4992. * @return {Ext.dom.Element/HTMLElement} The parent node or null
  4993. */
  4994. parent: function(selector, returnDom) {
  4995. return this.matchNode('parentNode', 'parentNode', selector, returnDom);
  4996. },
  4997. /**
  4998. * Gets the next sibling, skipping text nodes
  4999. * @param {String} [selector] Find the next sibling that matches the passed simple selector
  5000. * @param {Boolean} [returnDom=false] True to return a raw dom node instead of an Ext.dom.Element
  5001. * @return {Ext.dom.Element/HTMLElement} The next sibling or null
  5002. */
  5003. next: function(selector, returnDom) {
  5004. return this.matchNode('nextSibling', 'nextSibling', selector, returnDom);
  5005. },
  5006. /**
  5007. * Gets the previous sibling, skipping text nodes
  5008. * @param {String} [selector] Find the previous sibling that matches the passed simple selector
  5009. * @param {Boolean} [returnDom=false] True to return a raw dom node instead of an Ext.dom.Element
  5010. * @return {Ext.dom.Element/HTMLElement} The previous sibling or null
  5011. */
  5012. prev: function(selector, returnDom) {
  5013. return this.matchNode('previousSibling', 'previousSibling', selector, returnDom);
  5014. },
  5015. /**
  5016. * Gets the first child, skipping text nodes
  5017. * @param {String} [selector] Find the next sibling that matches the passed simple selector
  5018. * @param {Boolean} [returnDom=false] True to return a raw dom node instead of an Ext.dom.Element
  5019. * @return {Ext.dom.Element/HTMLElement} The first child or null
  5020. */
  5021. first: function(selector, returnDom) {
  5022. return this.matchNode('nextSibling', 'firstChild', selector, returnDom);
  5023. },
  5024. /**
  5025. * Gets the last child, skipping text nodes
  5026. * @param {String} [selector] Find the previous sibling that matches the passed simple selector
  5027. * @param {Boolean} [returnDom=false] True to return a raw dom node instead of an Ext.dom.Element
  5028. * @return {Ext.dom.Element/HTMLElement} The last child or null
  5029. */
  5030. last: function(selector, returnDom) {
  5031. return this.matchNode('previousSibling', 'lastChild', selector, returnDom);
  5032. },
  5033. matchNode: function(dir, start, selector, returnDom) {
  5034. if (!this.dom) {
  5035. return null;
  5036. }
  5037. var n = this.dom[start];
  5038. while (n) {
  5039. if (n.nodeType == 1 && (!selector || Ext.DomQuery.is(n, selector))) {
  5040. return !returnDom ? Ext.get(n) : n;
  5041. }
  5042. n = n[dir];
  5043. }
  5044. return null;
  5045. },
  5046. isAncestor: function(element) {
  5047. return this.self.isAncestor.call(this.self, this.dom, element);
  5048. }
  5049. });
  5050. /**
  5051. * @class Ext.DomHelper
  5052. * @extends Ext.dom.Helper
  5053. * @alternateClassName Ext.core.DomHelper
  5054. * @singleton
  5055. *
  5056. * The DomHelper class provides a layer of abstraction from DOM and transparently supports creating elements via DOM or
  5057. * using HTML fragments. It also has the ability to create HTML fragment templates from your DOM building code.
  5058. *
  5059. * # DomHelper element specification object
  5060. *
  5061. * A specification object is used when creating elements. Attributes of this object are assumed to be element
  5062. * attributes, except for 4 special attributes:
  5063. *
  5064. * - **tag** - The tag name of the element.
  5065. * - **children** or **cn** - An array of the same kind of element definition objects to be created and appended.
  5066. * These can be nested as deep as you want.
  5067. * - **cls** - The class attribute of the element. This will end up being either the "class" attribute on a HTML
  5068. * fragment or className for a DOM node, depending on whether DomHelper is using fragments or DOM.
  5069. * - **html** - The innerHTML for the element.
  5070. *
  5071. * **NOTE:** For other arbitrary attributes, the value will currently **not** be automatically HTML-escaped prior to
  5072. * building the element's HTML string. This means that if your attribute value contains special characters that would
  5073. * not normally be allowed in a double-quoted attribute value, you **must** manually HTML-encode it beforehand (see
  5074. * {@link Ext.String#htmlEncode}) or risk malformed HTML being created. This behavior may change in a future release.
  5075. *
  5076. * # Insertion methods
  5077. *
  5078. * Commonly used insertion methods:
  5079. *
  5080. * - **{@link #append}**
  5081. * - **{@link #insertBefore}**
  5082. * - **{@link #insertAfter}**
  5083. * - **{@link #overwrite}**
  5084. * - **{@link #createTemplate}**
  5085. * - **{@link #insertHtml}**
  5086. *
  5087. * # Example
  5088. *
  5089. * This is an example, where an unordered list with 3 children items is appended to an existing element with
  5090. * id 'my-div':
  5091. *
  5092. * var dh = Ext.DomHelper; // create shorthand alias
  5093. * // specification object
  5094. * var spec = {
  5095. * id: 'my-ul',
  5096. * tag: 'ul',
  5097. * cls: 'my-list',
  5098. * // append children after creating
  5099. * children: [ // may also specify 'cn' instead of 'children'
  5100. * {tag: 'li', id: 'item0', html: 'List Item 0'},
  5101. * {tag: 'li', id: 'item1', html: 'List Item 1'},
  5102. * {tag: 'li', id: 'item2', html: 'List Item 2'}
  5103. * ]
  5104. * };
  5105. * var list = dh.append(
  5106. * 'my-div', // the context element 'my-div' can either be the id or the actual node
  5107. * spec // the specification object
  5108. * );
  5109. *
  5110. * Element creation specification parameters in this class may also be passed as an Array of specification objects. This
  5111. * can be used to insert multiple sibling nodes into an existing container very efficiently. For example, to add more
  5112. * list items to the example above:
  5113. *
  5114. * dh.append('my-ul', [
  5115. * {tag: 'li', id: 'item3', html: 'List Item 3'},
  5116. * {tag: 'li', id: 'item4', html: 'List Item 4'}
  5117. * ]);
  5118. *
  5119. * # Templating
  5120. *
  5121. * The real power is in the built-in templating. Instead of creating or appending any elements, {@link #createTemplate}
  5122. * returns a Template object which can be used over and over to insert new elements. Revisiting the example above, we
  5123. * could utilize templating this time:
  5124. *
  5125. * // create the node
  5126. * var list = dh.append('my-div', {tag: 'ul', cls: 'my-list'});
  5127. * // get template
  5128. * var tpl = dh.createTemplate({tag: 'li', id: 'item{0}', html: 'List Item {0}'});
  5129. *
  5130. * for(var i = 0; i < 5, i++){
  5131. * tpl.append(list, [i]); // use template to append to the actual node
  5132. * }
  5133. *
  5134. * An example using a template:
  5135. *
  5136. * var html = '<a id="{0}" href="{1}" class="nav">{2}</a>';
  5137. *
  5138. * var tpl = new Ext.DomHelper.createTemplate(html);
  5139. * tpl.append('blog-roll', ['link1', 'http://www.edspencer.net/', "Ed's Site"]);
  5140. * tpl.append('blog-roll', ['link2', 'http://www.dustindiaz.com/', "Dustin's Site"]);
  5141. *
  5142. * The same example using named parameters:
  5143. *
  5144. * var html = '<a id="{id}" href="{url}" class="nav">{text}</a>';
  5145. *
  5146. * var tpl = new Ext.DomHelper.createTemplate(html);
  5147. * tpl.append('blog-roll', {
  5148. * id: 'link1',
  5149. * url: 'http://www.edspencer.net/',
  5150. * text: "Ed's Site"
  5151. * });
  5152. * tpl.append('blog-roll', {
  5153. * id: 'link2',
  5154. * url: 'http://www.dustindiaz.com/',
  5155. * text: "Dustin's Site"
  5156. * });
  5157. *
  5158. * # Compiling Templates
  5159. *
  5160. * Templates are applied using regular expressions. The performance is great, but if you are adding a bunch of DOM
  5161. * elements using the same template, you can increase performance even further by {@link Ext.Template#compile
  5162. * "compiling"} the template. The way "{@link Ext.Template#compile compile()}" works is the template is parsed and
  5163. * broken up at the different variable points and a dynamic function is created and eval'ed. The generated function
  5164. * performs string concatenation of these parts and the passed variables instead of using regular expressions.
  5165. *
  5166. * var html = '<a id="{id}" href="{url}" class="nav">{text}</a>';
  5167. *
  5168. * var tpl = new Ext.DomHelper.createTemplate(html);
  5169. * tpl.compile();
  5170. *
  5171. * //... use template like normal
  5172. *
  5173. * # Performance Boost
  5174. *
  5175. * DomHelper will transparently create HTML fragments when it can. Using HTML fragments instead of DOM can significantly
  5176. * boost performance.
  5177. *
  5178. * Element creation specification parameters may also be strings. If {@link #useDom} is false, then the string is used
  5179. * as innerHTML. If {@link #useDom} is true, a string specification results in the creation of a text node. Usage:
  5180. *
  5181. * Ext.DomHelper.useDom = true; // force it to use DOM; reduces performance
  5182. *
  5183. */
  5184. (function() {
  5185. // kill repeat to save bytes
  5186. var afterbegin = 'afterbegin',
  5187. afterend = 'afterend',
  5188. beforebegin = 'beforebegin',
  5189. beforeend = 'beforeend',
  5190. ts = '<table>',
  5191. te = '</table>',
  5192. tbs = ts+'<tbody>',
  5193. tbe = '</tbody>'+te,
  5194. trs = tbs + '<tr>',
  5195. tre = '</tr>'+tbe,
  5196. detachedDiv = document.createElement('div'),
  5197. bbValues = ['BeforeBegin', 'previousSibling'],
  5198. aeValues = ['AfterEnd', 'nextSibling'],
  5199. bb_ae_PositionHash = {
  5200. beforebegin: bbValues,
  5201. afterend: aeValues
  5202. },
  5203. fullPositionHash = {
  5204. beforebegin: bbValues,
  5205. afterend: aeValues,
  5206. afterbegin: ['AfterBegin', 'firstChild'],
  5207. beforeend: ['BeforeEnd', 'lastChild']
  5208. };
  5209. /**
  5210. * The actual class of which {@link Ext.DomHelper} is instance of.
  5211. *
  5212. * Use singleton {@link Ext.DomHelper} instead.
  5213. *
  5214. * @private
  5215. */
  5216. Ext.define('Ext.dom.Helper', {
  5217. extend: 'Ext.dom.AbstractHelper',
  5218. tableRe: /^table|tbody|tr|td$/i,
  5219. tableElRe: /td|tr|tbody/i,
  5220. /**
  5221. * @property {Boolean} useDom
  5222. * True to force the use of DOM instead of html fragments.
  5223. */
  5224. useDom : false,
  5225. /**
  5226. * Creates new DOM element(s) without inserting them to the document.
  5227. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  5228. * @return {HTMLElement} The new uninserted node
  5229. */
  5230. createDom: function(o, parentNode){
  5231. var el,
  5232. doc = document,
  5233. useSet,
  5234. attr,
  5235. val,
  5236. cn,
  5237. i, l;
  5238. if (Ext.isArray(o)) { // Allow Arrays of siblings to be inserted
  5239. el = doc.createDocumentFragment(); // in one shot using a DocumentFragment
  5240. for (i = 0, l = o.length; i < l; i++) {
  5241. this.createDom(o[i], el);
  5242. }
  5243. } else if (typeof o == 'string') { // Allow a string as a child spec.
  5244. el = doc.createTextNode(o);
  5245. } else {
  5246. el = doc.createElement(o.tag || 'div');
  5247. useSet = !!el.setAttribute; // In IE some elements don't have setAttribute
  5248. for (attr in o) {
  5249. if (!this.confRe.test(attr)) {
  5250. val = o[attr];
  5251. if (attr == 'cls') {
  5252. el.className = val;
  5253. } else {
  5254. if (useSet) {
  5255. el.setAttribute(attr, val);
  5256. } else {
  5257. el[attr] = val;
  5258. }
  5259. }
  5260. }
  5261. }
  5262. Ext.DomHelper.applyStyles(el, o.style);
  5263. if ((cn = o.children || o.cn)) {
  5264. this.createDom(cn, el);
  5265. } else if (o.html) {
  5266. el.innerHTML = o.html;
  5267. }
  5268. }
  5269. if (parentNode) {
  5270. parentNode.appendChild(el);
  5271. }
  5272. return el;
  5273. },
  5274. ieTable: function(depth, openingTags, htmlContent, closingTags){
  5275. detachedDiv.innerHTML = [openingTags, htmlContent, closingTags].join('');
  5276. var i = -1,
  5277. el = detachedDiv,
  5278. ns;
  5279. while (++i < depth) {
  5280. el = el.firstChild;
  5281. }
  5282. // If the result is multiple siblings, then encapsulate them into one fragment.
  5283. ns = el.nextSibling;
  5284. if (ns) {
  5285. el = document.createDocumentFragment();
  5286. while (ns) {
  5287. el.appendChild(ns);
  5288. ns = ns.nextSibling;
  5289. }
  5290. }
  5291. return el;
  5292. },
  5293. /**
  5294. * @private
  5295. * Nasty code for IE's broken table implementation
  5296. */
  5297. insertIntoTable: function(tag, where, destinationEl, html) {
  5298. var node,
  5299. before,
  5300. bb = where == beforebegin,
  5301. ab = where == afterbegin,
  5302. be = where == beforeend,
  5303. ae = where == afterend;
  5304. if (tag == 'td' && (ab || be) || !this.tableElRe.test(tag) && (bb || ae)) {
  5305. return null;
  5306. }
  5307. before = bb ? destinationEl :
  5308. ae ? destinationEl.nextSibling :
  5309. ab ? destinationEl.firstChild : null;
  5310. if (bb || ae) {
  5311. destinationEl = destinationEl.parentNode;
  5312. }
  5313. if (tag == 'td' || (tag == 'tr' && (be || ab))) {
  5314. node = this.ieTable(4, trs, html, tre);
  5315. } else if ((tag == 'tbody' && (be || ab)) ||
  5316. (tag == 'tr' && (bb || ae))) {
  5317. node = this.ieTable(3, tbs, html, tbe);
  5318. } else {
  5319. node = this.ieTable(2, ts, html, te);
  5320. }
  5321. destinationEl.insertBefore(node, before);
  5322. return node;
  5323. },
  5324. /**
  5325. * @private
  5326. * Fix for IE9 createContextualFragment missing method
  5327. */
  5328. createContextualFragment: function(html) {
  5329. var fragment = document.createDocumentFragment(),
  5330. length, childNodes;
  5331. detachedDiv.innerHTML = html;
  5332. childNodes = detachedDiv.childNodes;
  5333. length = childNodes.length;
  5334. // Move nodes into fragment, don't clone: http://jsperf.com/create-fragment
  5335. while (length--) {
  5336. fragment.appendChild(childNodes[0]);
  5337. }
  5338. return fragment;
  5339. },
  5340. applyStyles: function(el, styles) {
  5341. if (styles) {
  5342. el = Ext.fly(el);
  5343. if (typeof styles == "function") {
  5344. styles = styles.call();
  5345. }
  5346. if (typeof styles == "string") {
  5347. styles = Ext.dom.Element.parseStyles(styles);
  5348. }
  5349. if (typeof styles == "object") {
  5350. el.setStyle(styles);
  5351. }
  5352. }
  5353. },
  5354. /**
  5355. * Alias for {@link #markup}.
  5356. * @inheritdoc Ext.dom.AbstractHelper#markup
  5357. */
  5358. createHtml: function(spec) {
  5359. return this.markup(spec);
  5360. },
  5361. doInsert: function(el, o, returnElement, pos, sibling, append) {
  5362. el = el.dom || Ext.getDom(el);
  5363. var newNode;
  5364. if (this.useDom) {
  5365. newNode = this.createDom(o, null);
  5366. if (append) {
  5367. el.appendChild(newNode);
  5368. }
  5369. else {
  5370. (sibling == 'firstChild' ? el : el.parentNode).insertBefore(newNode, el[sibling] || el);
  5371. }
  5372. } else {
  5373. newNode = this.insertHtml(pos, el, this.markup(o));
  5374. }
  5375. return returnElement ? Ext.get(newNode, true) : newNode;
  5376. },
  5377. /**
  5378. * Creates new DOM element(s) and overwrites the contents of el with them.
  5379. * @param {String/HTMLElement/Ext.Element} el The context element
  5380. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  5381. * @param {Boolean} [returnElement] true to return an Ext.Element
  5382. * @return {HTMLElement/Ext.Element} The new node
  5383. */
  5384. overwrite: function(el, html, returnElement) {
  5385. var newNode;
  5386. el = Ext.getDom(el);
  5387. html = this.markup(html);
  5388. // IE Inserting HTML into a table/tbody/tr requires extra processing: http://www.ericvasilik.com/2006/07/code-karma.html
  5389. if (Ext.isIE && this.tableRe.test(el.tagName)) {
  5390. // Clearing table elements requires removal of all elements.
  5391. while (el.firstChild) {
  5392. el.removeChild(el.firstChild);
  5393. }
  5394. if (html) {
  5395. newNode = this.insertHtml('afterbegin', el, html);
  5396. return returnElement ? Ext.get(newNode) : newNode;
  5397. }
  5398. return null;
  5399. }
  5400. el.innerHTML = html;
  5401. return returnElement ? Ext.get(el.firstChild) : el.firstChild;
  5402. },
  5403. insertHtml: function(where, el, html) {
  5404. var hashVal,
  5405. range,
  5406. rangeEl,
  5407. setStart,
  5408. frag;
  5409. where = where.toLowerCase();
  5410. // Has fast HTML insertion into existing DOM: http://www.w3.org/TR/html5/apis-in-html-documents.html#insertadjacenthtml
  5411. if (el.insertAdjacentHTML) {
  5412. // IE's incomplete table implementation: http://www.ericvasilik.com/2006/07/code-karma.html
  5413. if (Ext.isIE && this.tableRe.test(el.tagName) && (frag = this.insertIntoTable(el.tagName.toLowerCase(), where, el, html))) {
  5414. return frag;
  5415. }
  5416. if ((hashVal = fullPositionHash[where])) {
  5417. el.insertAdjacentHTML(hashVal[0], html);
  5418. return el[hashVal[1]];
  5419. }
  5420. // if (not IE and context element is an HTMLElement) or TextNode
  5421. } else {
  5422. // we cannot insert anything inside a textnode so...
  5423. if (el.nodeType === 3) {
  5424. where = where === 'afterbegin' ? 'beforebegin' : where;
  5425. where = where === 'beforeend' ? 'afterend' : where;
  5426. }
  5427. range = Ext.supports.CreateContextualFragment ? el.ownerDocument.createRange() : undefined;
  5428. setStart = 'setStart' + (this.endRe.test(where) ? 'After' : 'Before');
  5429. if (bb_ae_PositionHash[where]) {
  5430. if (range) {
  5431. range[setStart](el);
  5432. frag = range.createContextualFragment(html);
  5433. } else {
  5434. frag = this.createContextualFragment(html);
  5435. }
  5436. el.parentNode.insertBefore(frag, where == beforebegin ? el : el.nextSibling);
  5437. return el[(where == beforebegin ? 'previous' : 'next') + 'Sibling'];
  5438. } else {
  5439. rangeEl = (where == afterbegin ? 'first' : 'last') + 'Child';
  5440. if (el.firstChild) {
  5441. if (range) {
  5442. range[setStart](el[rangeEl]);
  5443. frag = range.createContextualFragment(html);
  5444. } else {
  5445. frag = this.createContextualFragment(html);
  5446. }
  5447. if (where == afterbegin) {
  5448. el.insertBefore(frag, el.firstChild);
  5449. } else {
  5450. el.appendChild(frag);
  5451. }
  5452. } else {
  5453. el.innerHTML = html;
  5454. }
  5455. return el[rangeEl];
  5456. }
  5457. }
  5458. //<debug>
  5459. Ext.Error.raise({
  5460. sourceClass: 'Ext.DomHelper',
  5461. sourceMethod: 'insertHtml',
  5462. htmlToInsert: html,
  5463. targetElement: el,
  5464. msg: 'Illegal insertion point reached: "' + where + '"'
  5465. });
  5466. //</debug>
  5467. },
  5468. /**
  5469. * Creates a new Ext.Template from the DOM object spec.
  5470. * @param {Object} o The DOM object spec (and children)
  5471. * @return {Ext.Template} The new template
  5472. */
  5473. createTemplate: function(o) {
  5474. var html = this.markup(o);
  5475. return new Ext.Template(html);
  5476. }
  5477. }, function() {
  5478. Ext.ns('Ext.core');
  5479. Ext.DomHelper = Ext.core.DomHelper = new this;
  5480. });
  5481. }());
  5482. /*
  5483. * This is code is also distributed under MIT license for use
  5484. * with jQuery and prototype JavaScript libraries.
  5485. */
  5486. /**
  5487. * @class Ext.dom.Query
  5488. * @alternateClassName Ext.DomQuery
  5489. * @alternateClassName Ext.core.DomQuery
  5490. * @singleton
  5491. *
  5492. * Provides high performance selector/xpath processing by compiling queries into reusable functions. New pseudo classes
  5493. * and matchers can be plugged. It works on HTML and XML documents (if a content node is passed in).
  5494. *
  5495. * DomQuery supports most of the [CSS3 selectors spec][1], along with some custom selectors and basic XPath.
  5496. *
  5497. * All selectors, attribute filters and pseudos below can be combined infinitely in any order. For example
  5498. * `div.foo:nth-child(odd)[@foo=bar].bar:first` would be a perfectly valid selector. Node filters are processed
  5499. * in the order in which they appear, which allows you to optimize your queries for your document structure.
  5500. *
  5501. * ## Element Selectors:
  5502. *
  5503. * - **`*`** any element
  5504. * - **`E`** an element with the tag E
  5505. * - **`E F`** All descendent elements of E that have the tag F
  5506. * - **`E > F`** or **E/F** all direct children elements of E that have the tag F
  5507. * - **`E + F`** all elements with the tag F that are immediately preceded by an element with the tag E
  5508. * - **`E ~ F`** all elements with the tag F that are preceded by a sibling element with the tag E
  5509. *
  5510. * ## Attribute Selectors:
  5511. *
  5512. * The use of `@` and quotes are optional. For example, `div[@foo='bar']` is also a valid attribute selector.
  5513. *
  5514. * - **`E[foo]`** has an attribute "foo"
  5515. * - **`E[foo=bar]`** has an attribute "foo" that equals "bar"
  5516. * - **`E[foo^=bar]`** has an attribute "foo" that starts with "bar"
  5517. * - **`E[foo$=bar]`** has an attribute "foo" that ends with "bar"
  5518. * - **`E[foo*=bar]`** has an attribute "foo" that contains the substring "bar"
  5519. * - **`E[foo%=2]`** has an attribute "foo" that is evenly divisible by 2
  5520. * - **`E[foo!=bar]`** attribute "foo" does not equal "bar"
  5521. *
  5522. * ## Pseudo Classes:
  5523. *
  5524. * - **`E:first-child`** E is the first child of its parent
  5525. * - **`E:last-child`** E is the last child of its parent
  5526. * - **`E:nth-child(_n_)`** E is the _n_th child of its parent (1 based as per the spec)
  5527. * - **`E:nth-child(odd)`** E is an odd child of its parent
  5528. * - **`E:nth-child(even)`** E is an even child of its parent
  5529. * - **`E:only-child`** E is the only child of its parent
  5530. * - **`E:checked`** E is an element that is has a checked attribute that is true (e.g. a radio or checkbox)
  5531. * - **`E:first`** the first E in the resultset
  5532. * - **`E:last`** the last E in the resultset
  5533. * - **`E:nth(_n_)`** the _n_th E in the resultset (1 based)
  5534. * - **`E:odd`** shortcut for :nth-child(odd)
  5535. * - **`E:even`** shortcut for :nth-child(even)
  5536. * - **`E:contains(foo)`** E's innerHTML contains the substring "foo"
  5537. * - **`E:nodeValue(foo)`** E contains a textNode with a nodeValue that equals "foo"
  5538. * - **`E:not(S)`** an E element that does not match simple selector S
  5539. * - **`E:has(S)`** an E element that has a descendent that matches simple selector S
  5540. * - **`E:next(S)`** an E element whose next sibling matches simple selector S
  5541. * - **`E:prev(S)`** an E element whose previous sibling matches simple selector S
  5542. * - **`E:any(S1|S2|S2)`** an E element which matches any of the simple selectors S1, S2 or S3
  5543. *
  5544. * ## CSS Value Selectors:
  5545. *
  5546. * - **`E{display=none}`** css value "display" that equals "none"
  5547. * - **`E{display^=none}`** css value "display" that starts with "none"
  5548. * - **`E{display$=none}`** css value "display" that ends with "none"
  5549. * - **`E{display*=none}`** css value "display" that contains the substring "none"
  5550. * - **`E{display%=2}`** css value "display" that is evenly divisible by 2
  5551. * - **`E{display!=none}`** css value "display" that does not equal "none"
  5552. *
  5553. * [1]: http://www.w3.org/TR/2005/WD-css3-selectors-20051215/#selectors
  5554. */
  5555. Ext.ns('Ext.core');
  5556. Ext.dom.Query = Ext.core.DomQuery = Ext.DomQuery = (function(){
  5557. var cache = {},
  5558. simpleCache = {},
  5559. valueCache = {},
  5560. nonSpace = /\S/,
  5561. trimRe = /^\s+|\s+$/g,
  5562. tplRe = /\{(\d+)\}/g,
  5563. modeRe = /^(\s?[\/>+~]\s?|\s|$)/,
  5564. tagTokenRe = /^(#)?([\w\-\*\\]+)/,
  5565. nthRe = /(\d*)n\+?(\d*)/,
  5566. nthRe2 = /\D/,
  5567. startIdRe = /^\s*\#/,
  5568. // This is for IE MSXML which does not support expandos.
  5569. // IE runs the same speed using setAttribute, however FF slows way down
  5570. // and Safari completely fails so they need to continue to use expandos.
  5571. isIE = window.ActiveXObject ? true : false,
  5572. key = 30803,
  5573. longHex = /\\([0-9a-fA-F]{6})/g,
  5574. shortHex = /\\([0-9a-fA-F]{1,6})\s{0,1}/g,
  5575. nonHex = /\\([^0-9a-fA-F]{1})/g,
  5576. escapes = /\\/g,
  5577. num, hasEscapes,
  5578. // replaces a long hex regex match group with the appropriate ascii value
  5579. // $args indicate regex match pos
  5580. longHexToChar = function($0, $1) {
  5581. return String.fromCharCode(parseInt($1, 16));
  5582. },
  5583. // converts a shortHex regex match to the long form
  5584. shortToLongHex = function($0, $1) {
  5585. while ($1.length < 6) {
  5586. $1 = '0' + $1;
  5587. }
  5588. return '\\' + $1;
  5589. },
  5590. // converts a single char escape to long escape form
  5591. charToLongHex = function($0, $1) {
  5592. num = $1.charCodeAt(0).toString(16);
  5593. if (num.length === 1) {
  5594. num = '0' + num;
  5595. }
  5596. return '\\0000' + num;
  5597. },
  5598. // Un-escapes an input selector string. Assumes all escape sequences have been
  5599. // normalized to the css '\\0000##' 6-hex-digit style escape sequence :
  5600. // will not handle any other escape formats
  5601. unescapeCssSelector = function (selector) {
  5602. return (hasEscapes)
  5603. ? selector.replace(longHex, longHexToChar)
  5604. : selector;
  5605. },
  5606. // checks if the path has escaping & does any appropriate replacements
  5607. setupEscapes = function(path){
  5608. hasEscapes = (path.indexOf('\\') > -1);
  5609. if (hasEscapes) {
  5610. path = path
  5611. .replace(shortHex, shortToLongHex)
  5612. .replace(nonHex, charToLongHex)
  5613. .replace(escapes, '\\\\'); // double the '\' for js compilation
  5614. }
  5615. return path;
  5616. };
  5617. // this eval is stop the compressor from
  5618. // renaming the variable to something shorter
  5619. eval("var batch = 30803;");
  5620. // Retrieve the child node from a particular
  5621. // parent at the specified index.
  5622. function child(parent, index){
  5623. var i = 0,
  5624. n = parent.firstChild;
  5625. while(n){
  5626. if(n.nodeType == 1){
  5627. if(++i == index){
  5628. return n;
  5629. }
  5630. }
  5631. n = n.nextSibling;
  5632. }
  5633. return null;
  5634. }
  5635. // retrieve the next element node
  5636. function next(n){
  5637. while((n = n.nextSibling) && n.nodeType != 1);
  5638. return n;
  5639. }
  5640. // retrieve the previous element node
  5641. function prev(n){
  5642. while((n = n.previousSibling) && n.nodeType != 1);
  5643. return n;
  5644. }
  5645. // Mark each child node with a nodeIndex skipping and
  5646. // removing empty text nodes.
  5647. function children(parent){
  5648. var n = parent.firstChild,
  5649. nodeIndex = -1,
  5650. nextNode;
  5651. while(n){
  5652. nextNode = n.nextSibling;
  5653. // clean worthless empty nodes.
  5654. if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
  5655. parent.removeChild(n);
  5656. }else{
  5657. // add an expando nodeIndex
  5658. n.nodeIndex = ++nodeIndex;
  5659. }
  5660. n = nextNode;
  5661. }
  5662. return this;
  5663. }
  5664. // nodeSet - array of nodes
  5665. // cls - CSS Class
  5666. function byClassName(nodeSet, cls){
  5667. cls = unescapeCssSelector(cls);
  5668. if(!cls){
  5669. return nodeSet;
  5670. }
  5671. var result = [], ri = -1,
  5672. i, ci;
  5673. for(i = 0, ci; ci = nodeSet[i]; i++){
  5674. if((' '+ci.className+' ').indexOf(cls) != -1){
  5675. result[++ri] = ci;
  5676. }
  5677. }
  5678. return result;
  5679. }
  5680. function attrValue(n, attr){
  5681. // if its an array, use the first node.
  5682. if(!n.tagName && typeof n.length != "undefined"){
  5683. n = n[0];
  5684. }
  5685. if(!n){
  5686. return null;
  5687. }
  5688. if(attr == "for"){
  5689. return n.htmlFor;
  5690. }
  5691. if(attr == "class" || attr == "className"){
  5692. return n.className;
  5693. }
  5694. return n.getAttribute(attr) || n[attr];
  5695. }
  5696. // ns - nodes
  5697. // mode - false, /, >, +, ~
  5698. // tagName - defaults to "*"
  5699. function getNodes(ns, mode, tagName){
  5700. var result = [], ri = -1, cs,
  5701. i, ni, j, ci, cn, utag, n, cj;
  5702. if(!ns){
  5703. return result;
  5704. }
  5705. tagName = tagName || "*";
  5706. // convert to array
  5707. if(typeof ns.getElementsByTagName != "undefined"){
  5708. ns = [ns];
  5709. }
  5710. // no mode specified, grab all elements by tagName
  5711. // at any depth
  5712. if(!mode){
  5713. for(i = 0, ni; ni = ns[i]; i++){
  5714. cs = ni.getElementsByTagName(tagName);
  5715. for(j = 0, ci; ci = cs[j]; j++){
  5716. result[++ri] = ci;
  5717. }
  5718. }
  5719. // Direct Child mode (/ or >)
  5720. // E > F or E/F all direct children elements of E that have the tag
  5721. } else if(mode == "/" || mode == ">"){
  5722. utag = tagName.toUpperCase();
  5723. for(i = 0, ni, cn; ni = ns[i]; i++){
  5724. cn = ni.childNodes;
  5725. for(j = 0, cj; cj = cn[j]; j++){
  5726. if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
  5727. result[++ri] = cj;
  5728. }
  5729. }
  5730. }
  5731. // Immediately Preceding mode (+)
  5732. // E + F all elements with the tag F that are immediately preceded by an element with the tag E
  5733. }else if(mode == "+"){
  5734. utag = tagName.toUpperCase();
  5735. for(i = 0, n; n = ns[i]; i++){
  5736. while((n = n.nextSibling) && n.nodeType != 1);
  5737. if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
  5738. result[++ri] = n;
  5739. }
  5740. }
  5741. // Sibling mode (~)
  5742. // E ~ F all elements with the tag F that are preceded by a sibling element with the tag E
  5743. }else if(mode == "~"){
  5744. utag = tagName.toUpperCase();
  5745. for(i = 0, n; n = ns[i]; i++){
  5746. while((n = n.nextSibling)){
  5747. if (n.nodeName == utag || n.nodeName == tagName || tagName == '*'){
  5748. result[++ri] = n;
  5749. }
  5750. }
  5751. }
  5752. }
  5753. return result;
  5754. }
  5755. function concat(a, b){
  5756. if(b.slice){
  5757. return a.concat(b);
  5758. }
  5759. for(var i = 0, l = b.length; i < l; i++){
  5760. a[a.length] = b[i];
  5761. }
  5762. return a;
  5763. }
  5764. function byTag(cs, tagName){
  5765. if(cs.tagName || cs == document){
  5766. cs = [cs];
  5767. }
  5768. if(!tagName){
  5769. return cs;
  5770. }
  5771. var result = [], ri = -1,
  5772. i, ci;
  5773. tagName = tagName.toLowerCase();
  5774. for(i = 0, ci; ci = cs[i]; i++){
  5775. if(ci.nodeType == 1 && ci.tagName.toLowerCase() == tagName){
  5776. result[++ri] = ci;
  5777. }
  5778. }
  5779. return result;
  5780. }
  5781. function byId(cs, id){
  5782. id = unescapeCssSelector(id);
  5783. if(cs.tagName || cs == document){
  5784. cs = [cs];
  5785. }
  5786. if(!id){
  5787. return cs;
  5788. }
  5789. var result = [], ri = -1,
  5790. i, ci;
  5791. for(i = 0, ci; ci = cs[i]; i++){
  5792. if(ci && ci.id == id){
  5793. result[++ri] = ci;
  5794. return result;
  5795. }
  5796. }
  5797. return result;
  5798. }
  5799. // operators are =, !=, ^=, $=, *=, %=, |= and ~=
  5800. // custom can be "{"
  5801. function byAttribute(cs, attr, value, op, custom){
  5802. var result = [],
  5803. ri = -1,
  5804. useGetStyle = custom == "{",
  5805. fn = Ext.DomQuery.operators[op],
  5806. a,
  5807. xml,
  5808. hasXml,
  5809. i, ci;
  5810. value = unescapeCssSelector(value);
  5811. for(i = 0, ci; ci = cs[i]; i++){
  5812. // skip non-element nodes.
  5813. if(ci.nodeType != 1){
  5814. continue;
  5815. }
  5816. // only need to do this for the first node
  5817. if(!hasXml){
  5818. xml = Ext.DomQuery.isXml(ci);
  5819. hasXml = true;
  5820. }
  5821. // we only need to change the property names if we're dealing with html nodes, not XML
  5822. if(!xml){
  5823. if(useGetStyle){
  5824. a = Ext.DomQuery.getStyle(ci, attr);
  5825. } else if (attr == "class" || attr == "className"){
  5826. a = ci.className;
  5827. } else if (attr == "for"){
  5828. a = ci.htmlFor;
  5829. } else if (attr == "href"){
  5830. // getAttribute href bug
  5831. // http://www.glennjones.net/Post/809/getAttributehrefbug.htm
  5832. a = ci.getAttribute("href", 2);
  5833. } else{
  5834. a = ci.getAttribute(attr);
  5835. }
  5836. }else{
  5837. a = ci.getAttribute(attr);
  5838. }
  5839. if((fn && fn(a, value)) || (!fn && a)){
  5840. result[++ri] = ci;
  5841. }
  5842. }
  5843. return result;
  5844. }
  5845. function byPseudo(cs, name, value){
  5846. value = unescapeCssSelector(value);
  5847. return Ext.DomQuery.pseudos[name](cs, value);
  5848. }
  5849. function nodupIEXml(cs){
  5850. var d = ++key,
  5851. r,
  5852. i, len, c;
  5853. cs[0].setAttribute("_nodup", d);
  5854. r = [cs[0]];
  5855. for(i = 1, len = cs.length; i < len; i++){
  5856. c = cs[i];
  5857. if(!c.getAttribute("_nodup") != d){
  5858. c.setAttribute("_nodup", d);
  5859. r[r.length] = c;
  5860. }
  5861. }
  5862. for(i = 0, len = cs.length; i < len; i++){
  5863. cs[i].removeAttribute("_nodup");
  5864. }
  5865. return r;
  5866. }
  5867. function nodup(cs){
  5868. if(!cs){
  5869. return [];
  5870. }
  5871. var len = cs.length, c, i, r = cs, cj, ri = -1, d, j;
  5872. if(!len || typeof cs.nodeType != "undefined" || len == 1){
  5873. return cs;
  5874. }
  5875. if(isIE && typeof cs[0].selectSingleNode != "undefined"){
  5876. return nodupIEXml(cs);
  5877. }
  5878. d = ++key;
  5879. cs[0]._nodup = d;
  5880. for(i = 1; c = cs[i]; i++){
  5881. if(c._nodup != d){
  5882. c._nodup = d;
  5883. }else{
  5884. r = [];
  5885. for(j = 0; j < i; j++){
  5886. r[++ri] = cs[j];
  5887. }
  5888. for(j = i+1; cj = cs[j]; j++){
  5889. if(cj._nodup != d){
  5890. cj._nodup = d;
  5891. r[++ri] = cj;
  5892. }
  5893. }
  5894. return r;
  5895. }
  5896. }
  5897. return r;
  5898. }
  5899. function quickDiffIEXml(c1, c2){
  5900. var d = ++key,
  5901. r = [],
  5902. i, len;
  5903. for(i = 0, len = c1.length; i < len; i++){
  5904. c1[i].setAttribute("_qdiff", d);
  5905. }
  5906. for(i = 0, len = c2.length; i < len; i++){
  5907. if(c2[i].getAttribute("_qdiff") != d){
  5908. r[r.length] = c2[i];
  5909. }
  5910. }
  5911. for(i = 0, len = c1.length; i < len; i++){
  5912. c1[i].removeAttribute("_qdiff");
  5913. }
  5914. return r;
  5915. }
  5916. function quickDiff(c1, c2){
  5917. var len1 = c1.length,
  5918. d = ++key,
  5919. r = [],
  5920. i, len;
  5921. if(!len1){
  5922. return c2;
  5923. }
  5924. if(isIE && typeof c1[0].selectSingleNode != "undefined"){
  5925. return quickDiffIEXml(c1, c2);
  5926. }
  5927. for(i = 0; i < len1; i++){
  5928. c1[i]._qdiff = d;
  5929. }
  5930. for(i = 0, len = c2.length; i < len; i++){
  5931. if(c2[i]._qdiff != d){
  5932. r[r.length] = c2[i];
  5933. }
  5934. }
  5935. return r;
  5936. }
  5937. function quickId(ns, mode, root, id){
  5938. if(ns == root){
  5939. id = unescapeCssSelector(id);
  5940. var d = root.ownerDocument || root;
  5941. return d.getElementById(id);
  5942. }
  5943. ns = getNodes(ns, mode, "*");
  5944. return byId(ns, id);
  5945. }
  5946. return {
  5947. getStyle : function(el, name){
  5948. return Ext.fly(el).getStyle(name);
  5949. },
  5950. /**
  5951. * Compiles a selector/xpath query into a reusable function. The returned function
  5952. * takes one parameter "root" (optional), which is the context node from where the query should start.
  5953. * @param {String} selector The selector/xpath query
  5954. * @param {String} [type="select"] Either "select" or "simple" for a simple selector match
  5955. * @return {Function}
  5956. */
  5957. compile : function(path, type){
  5958. type = type || "select";
  5959. // setup fn preamble
  5960. var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"],
  5961. mode,
  5962. lastPath,
  5963. matchers = Ext.DomQuery.matchers,
  5964. matchersLn = matchers.length,
  5965. modeMatch,
  5966. // accept leading mode switch
  5967. lmode = path.match(modeRe),
  5968. tokenMatch, matched, j, t, m;
  5969. path = setupEscapes(path);
  5970. if(lmode && lmode[1]){
  5971. fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";';
  5972. path = path.replace(lmode[1], "");
  5973. }
  5974. // strip leading slashes
  5975. while(path.substr(0, 1)=="/"){
  5976. path = path.substr(1);
  5977. }
  5978. while(path && lastPath != path){
  5979. lastPath = path;
  5980. tokenMatch = path.match(tagTokenRe);
  5981. if(type == "select"){
  5982. if(tokenMatch){
  5983. // ID Selector
  5984. if(tokenMatch[1] == "#"){
  5985. fn[fn.length] = 'n = quickId(n, mode, root, "'+tokenMatch[2]+'");';
  5986. }else{
  5987. fn[fn.length] = 'n = getNodes(n, mode, "'+tokenMatch[2]+'");';
  5988. }
  5989. path = path.replace(tokenMatch[0], "");
  5990. }else if(path.substr(0, 1) != '@'){
  5991. fn[fn.length] = 'n = getNodes(n, mode, "*");';
  5992. }
  5993. // type of "simple"
  5994. }else{
  5995. if(tokenMatch){
  5996. if(tokenMatch[1] == "#"){
  5997. fn[fn.length] = 'n = byId(n, "'+tokenMatch[2]+'");';
  5998. }else{
  5999. fn[fn.length] = 'n = byTag(n, "'+tokenMatch[2]+'");';
  6000. }
  6001. path = path.replace(tokenMatch[0], "");
  6002. }
  6003. }
  6004. while(!(modeMatch = path.match(modeRe))){
  6005. matched = false;
  6006. for(j = 0; j < matchersLn; j++){
  6007. t = matchers[j];
  6008. m = path.match(t.re);
  6009. if(m){
  6010. fn[fn.length] = t.select.replace(tplRe, function(x, i){
  6011. return m[i];
  6012. });
  6013. path = path.replace(m[0], "");
  6014. matched = true;
  6015. break;
  6016. }
  6017. }
  6018. // prevent infinite loop on bad selector
  6019. if(!matched){
  6020. Ext.Error.raise({
  6021. sourceClass: 'Ext.DomQuery',
  6022. sourceMethod: 'compile',
  6023. msg: 'Error parsing selector. Parsing failed at "' + path + '"'
  6024. });
  6025. }
  6026. }
  6027. if(modeMatch[1]){
  6028. fn[fn.length] = 'mode="'+modeMatch[1].replace(trimRe, "")+'";';
  6029. path = path.replace(modeMatch[1], "");
  6030. }
  6031. }
  6032. // close fn out
  6033. fn[fn.length] = "return nodup(n);\n}";
  6034. // eval fn and return it
  6035. eval(fn.join(""));
  6036. return f;
  6037. },
  6038. /**
  6039. * Selects an array of DOM nodes using JavaScript-only implementation.
  6040. *
  6041. * Use {@link #select} to take advantage of browsers built-in support for CSS selectors.
  6042. * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
  6043. * @param {HTMLElement/String} [root=document] The start of the query.
  6044. * @return {HTMLElement[]} An Array of DOM elements which match the selector. If there are
  6045. * no matches, and empty Array is returned.
  6046. */
  6047. jsSelect: function(path, root, type){
  6048. // set root to doc if not specified.
  6049. root = root || document;
  6050. if(typeof root == "string"){
  6051. root = document.getElementById(root);
  6052. }
  6053. var paths = path.split(","),
  6054. results = [],
  6055. i, len, subPath, result;
  6056. // loop over each selector
  6057. for(i = 0, len = paths.length; i < len; i++){
  6058. subPath = paths[i].replace(trimRe, "");
  6059. // compile and place in cache
  6060. if(!cache[subPath]){
  6061. // When we compile, escaping is handled inside the compile method
  6062. cache[subPath] = Ext.DomQuery.compile(subPath, type);
  6063. if(!cache[subPath]){
  6064. Ext.Error.raise({
  6065. sourceClass: 'Ext.DomQuery',
  6066. sourceMethod: 'jsSelect',
  6067. msg: subPath + ' is not a valid selector'
  6068. });
  6069. }
  6070. } else {
  6071. // If we've already compiled, we still need to check if the
  6072. // selector has escaping and setup the appropriate flags
  6073. setupEscapes(subPath);
  6074. }
  6075. result = cache[subPath](root);
  6076. if(result && result != document){
  6077. results = results.concat(result);
  6078. }
  6079. }
  6080. // if there were multiple selectors, make sure dups
  6081. // are eliminated
  6082. if(paths.length > 1){
  6083. return nodup(results);
  6084. }
  6085. return results;
  6086. },
  6087. isXml: function(el) {
  6088. var docEl = (el ? el.ownerDocument || el : 0).documentElement;
  6089. return docEl ? docEl.nodeName !== "HTML" : false;
  6090. },
  6091. /**
  6092. * Selects an array of DOM nodes by CSS/XPath selector.
  6093. *
  6094. * Uses [document.querySelectorAll][0] if browser supports that, otherwise falls back to
  6095. * {@link Ext.dom.Query#jsSelect} to do the work.
  6096. *
  6097. * Aliased as {@link Ext#query}.
  6098. *
  6099. * [0]: https://developer.mozilla.org/en/DOM/document.querySelectorAll
  6100. *
  6101. * @param {String} path The selector/xpath query
  6102. * @param {HTMLElement} [root=document] The start of the query.
  6103. * @return {HTMLElement[]} An array of DOM elements (not a NodeList as returned by `querySelectorAll`).
  6104. * @param {String} [type="select"] Either "select" or "simple" for a simple selector match (only valid when
  6105. * used when the call is deferred to the jsSelect method)
  6106. * @method
  6107. */
  6108. select : document.querySelectorAll ? function(path, root, type) {
  6109. root = root || document;
  6110. if (!Ext.DomQuery.isXml(root)) {
  6111. try {
  6112. /*
  6113. * This checking here is to "fix" the behaviour of querySelectorAll
  6114. * for non root document queries. The way qsa works is intentional,
  6115. * however it's definitely not the expected way it should work.
  6116. * When descendant selectors are used, only the lowest selector must be inside the root!
  6117. * More info: http://ejohn.org/blog/thoughts-on-queryselectorall/
  6118. * So we create a descendant selector by prepending the root's ID, and query the parent node.
  6119. * UNLESS the root has no parent in which qsa will work perfectly.
  6120. *
  6121. * We only modify the path for single selectors (ie, no multiples),
  6122. * without a full parser it makes it difficult to do this correctly.
  6123. */
  6124. if (root.parentNode && (root.nodeType !== 9) && path.indexOf(',') === -1 && !startIdRe.test(path)) {
  6125. path = '#' + Ext.escapeId(Ext.id(root)) + ' ' + path;
  6126. root = root.parentNode;
  6127. }
  6128. return Ext.Array.toArray(root.querySelectorAll(path));
  6129. }
  6130. catch (e) {
  6131. }
  6132. }
  6133. return Ext.DomQuery.jsSelect.call(this, path, root, type);
  6134. } : function(path, root, type) {
  6135. return Ext.DomQuery.jsSelect.call(this, path, root, type);
  6136. },
  6137. /**
  6138. * Selects a single element.
  6139. * @param {String} selector The selector/xpath query
  6140. * @param {HTMLElement} [root=document] The start of the query.
  6141. * @return {HTMLElement} The DOM element which matched the selector.
  6142. */
  6143. selectNode : function(path, root){
  6144. return Ext.DomQuery.select(path, root)[0];
  6145. },
  6146. /**
  6147. * Selects the value of a node, optionally replacing null with the defaultValue.
  6148. * @param {String} selector The selector/xpath query
  6149. * @param {HTMLElement} [root=document] The start of the query.
  6150. * @param {String} [defaultValue] When specified, this is return as empty value.
  6151. * @return {String}
  6152. */
  6153. selectValue : function(path, root, defaultValue){
  6154. path = path.replace(trimRe, "");
  6155. if (!valueCache[path]) {
  6156. valueCache[path] = Ext.DomQuery.compile(path, "select");
  6157. } else {
  6158. setupEscapes(path);
  6159. }
  6160. var n = valueCache[path](root),
  6161. v;
  6162. n = n[0] ? n[0] : n;
  6163. // overcome a limitation of maximum textnode size
  6164. // Rumored to potentially crash IE6 but has not been confirmed.
  6165. // http://reference.sitepoint.com/javascript/Node/normalize
  6166. // https://developer.mozilla.org/En/DOM/Node.normalize
  6167. if (typeof n.normalize == 'function') {
  6168. n.normalize();
  6169. }
  6170. v = (n && n.firstChild ? n.firstChild.nodeValue : null);
  6171. return ((v === null||v === undefined||v==='') ? defaultValue : v);
  6172. },
  6173. /**
  6174. * Selects the value of a node, parsing integers and floats.
  6175. * Returns the defaultValue, or 0 if none is specified.
  6176. * @param {String} selector The selector/xpath query
  6177. * @param {HTMLElement} [root=document] The start of the query.
  6178. * @param {Number} [defaultValue] When specified, this is return as empty value.
  6179. * @return {Number}
  6180. */
  6181. selectNumber : function(path, root, defaultValue){
  6182. var v = Ext.DomQuery.selectValue(path, root, defaultValue || 0);
  6183. return parseFloat(v);
  6184. },
  6185. /**
  6186. * Returns true if the passed element(s) match the passed simple selector
  6187. * (e.g. `div.some-class` or `span:first-child`)
  6188. * @param {String/HTMLElement/HTMLElement[]} el An element id, element or array of elements
  6189. * @param {String} selector The simple selector to test
  6190. * @return {Boolean}
  6191. */
  6192. is : function(el, ss){
  6193. if(typeof el == "string"){
  6194. el = document.getElementById(el);
  6195. }
  6196. var isArray = Ext.isArray(el),
  6197. result = Ext.DomQuery.filter(isArray ? el : [el], ss);
  6198. return isArray ? (result.length == el.length) : (result.length > 0);
  6199. },
  6200. /**
  6201. * Filters an array of elements to only include matches of a simple selector
  6202. * (e.g. `div.some-class` or `span:first-child`)
  6203. * @param {HTMLElement[]} el An array of elements to filter
  6204. * @param {String} selector The simple selector to test
  6205. * @param {Boolean} nonMatches If true, it returns the elements that DON'T match the selector instead of the
  6206. * ones that match
  6207. * @return {HTMLElement[]} An Array of DOM elements which match the selector. If there are no matches, and empty
  6208. * Array is returned.
  6209. */
  6210. filter : function(els, ss, nonMatches){
  6211. ss = ss.replace(trimRe, "");
  6212. if (!simpleCache[ss]) {
  6213. simpleCache[ss] = Ext.DomQuery.compile(ss, "simple");
  6214. } else {
  6215. setupEscapes(ss);
  6216. }
  6217. var result = simpleCache[ss](els);
  6218. return nonMatches ? quickDiff(result, els) : result;
  6219. },
  6220. /**
  6221. * Collection of matching regular expressions and code snippets.
  6222. * Each capture group within `()` will be replace the `{}` in the select
  6223. * statement as specified by their index.
  6224. */
  6225. matchers : [{
  6226. re: /^\.([\w\-\\]+)/,
  6227. select: 'n = byClassName(n, " {1} ");'
  6228. }, {
  6229. re: /^\:([\w\-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
  6230. select: 'n = byPseudo(n, "{1}", "{2}");'
  6231. },{
  6232. re: /^(?:([\[\{])(?:@)?([\w\-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
  6233. select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
  6234. }, {
  6235. re: /^#([\w\-\\]+)/,
  6236. select: 'n = byId(n, "{1}");'
  6237. },{
  6238. re: /^@([\w\-]+)/,
  6239. select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
  6240. }
  6241. ],
  6242. /**
  6243. * Collection of operator comparison functions.
  6244. * The default operators are `=`, `!=`, `^=`, `$=`, `*=`, `%=`, `|=` and `~=`.
  6245. * New operators can be added as long as the match the format *c*`=` where *c*
  6246. * is any character other than space, `>`, or `<`.
  6247. */
  6248. operators : {
  6249. "=" : function(a, v){
  6250. return a == v;
  6251. },
  6252. "!=" : function(a, v){
  6253. return a != v;
  6254. },
  6255. "^=" : function(a, v){
  6256. return a && a.substr(0, v.length) == v;
  6257. },
  6258. "$=" : function(a, v){
  6259. return a && a.substr(a.length-v.length) == v;
  6260. },
  6261. "*=" : function(a, v){
  6262. return a && a.indexOf(v) !== -1;
  6263. },
  6264. "%=" : function(a, v){
  6265. return (a % v) == 0;
  6266. },
  6267. "|=" : function(a, v){
  6268. return a && (a == v || a.substr(0, v.length+1) == v+'-');
  6269. },
  6270. "~=" : function(a, v){
  6271. return a && (' '+a+' ').indexOf(' '+v+' ') != -1;
  6272. }
  6273. },
  6274. /**
  6275. * Object hash of "pseudo class" filter functions which are used when filtering selections.
  6276. * Each function is passed two parameters:
  6277. *
  6278. * - **c** : Array
  6279. * An Array of DOM elements to filter.
  6280. *
  6281. * - **v** : String
  6282. * The argument (if any) supplied in the selector.
  6283. *
  6284. * A filter function returns an Array of DOM elements which conform to the pseudo class.
  6285. * In addition to the provided pseudo classes listed above such as `first-child` and `nth-child`,
  6286. * developers may add additional, custom psuedo class filters to select elements according to application-specific requirements.
  6287. *
  6288. * For example, to filter `a` elements to only return links to __external__ resources:
  6289. *
  6290. * Ext.DomQuery.pseudos.external = function(c, v){
  6291. * var r = [], ri = -1;
  6292. * for(var i = 0, ci; ci = c[i]; i++){
  6293. * // Include in result set only if it's a link to an external resource
  6294. * if(ci.hostname != location.hostname){
  6295. * r[++ri] = ci;
  6296. * }
  6297. * }
  6298. * return r;
  6299. * };
  6300. *
  6301. * Then external links could be gathered with the following statement:
  6302. *
  6303. * var externalLinks = Ext.select("a:external");
  6304. */
  6305. pseudos : {
  6306. "first-child" : function(c){
  6307. var r = [], ri = -1, n,
  6308. i, ci;
  6309. for(i = 0; (ci = n = c[i]); i++){
  6310. while((n = n.previousSibling) && n.nodeType != 1);
  6311. if(!n){
  6312. r[++ri] = ci;
  6313. }
  6314. }
  6315. return r;
  6316. },
  6317. "last-child" : function(c){
  6318. var r = [], ri = -1, n,
  6319. i, ci;
  6320. for(i = 0; (ci = n = c[i]); i++){
  6321. while((n = n.nextSibling) && n.nodeType != 1);
  6322. if(!n){
  6323. r[++ri] = ci;
  6324. }
  6325. }
  6326. return r;
  6327. },
  6328. "nth-child" : function(c, a) {
  6329. var r = [], ri = -1,
  6330. m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a),
  6331. f = (m[1] || 1) - 0, l = m[2] - 0,
  6332. i, n, j, cn, pn;
  6333. for(i = 0; n = c[i]; i++){
  6334. pn = n.parentNode;
  6335. if (batch != pn._batch) {
  6336. j = 0;
  6337. for(cn = pn.firstChild; cn; cn = cn.nextSibling){
  6338. if(cn.nodeType == 1){
  6339. cn.nodeIndex = ++j;
  6340. }
  6341. }
  6342. pn._batch = batch;
  6343. }
  6344. if (f == 1) {
  6345. if (l == 0 || n.nodeIndex == l){
  6346. r[++ri] = n;
  6347. }
  6348. } else if ((n.nodeIndex + l) % f == 0){
  6349. r[++ri] = n;
  6350. }
  6351. }
  6352. return r;
  6353. },
  6354. "only-child" : function(c){
  6355. var r = [], ri = -1,
  6356. i, ci;
  6357. for(i = 0; ci = c[i]; i++){
  6358. if(!prev(ci) && !next(ci)){
  6359. r[++ri] = ci;
  6360. }
  6361. }
  6362. return r;
  6363. },
  6364. "empty" : function(c){
  6365. var r = [], ri = -1,
  6366. i, ci, cns, j, cn, empty;
  6367. for(i = 0, ci; ci = c[i]; i++){
  6368. cns = ci.childNodes;
  6369. j = 0;
  6370. empty = true;
  6371. while(cn = cns[j]){
  6372. ++j;
  6373. if(cn.nodeType == 1 || cn.nodeType == 3){
  6374. empty = false;
  6375. break;
  6376. }
  6377. }
  6378. if(empty){
  6379. r[++ri] = ci;
  6380. }
  6381. }
  6382. return r;
  6383. },
  6384. "contains" : function(c, v){
  6385. var r = [], ri = -1,
  6386. i, ci;
  6387. for(i = 0; ci = c[i]; i++){
  6388. if((ci.textContent||ci.innerText||ci.text||'').indexOf(v) != -1){
  6389. r[++ri] = ci;
  6390. }
  6391. }
  6392. return r;
  6393. },
  6394. "nodeValue" : function(c, v){
  6395. var r = [], ri = -1,
  6396. i, ci;
  6397. for(i = 0; ci = c[i]; i++){
  6398. if(ci.firstChild && ci.firstChild.nodeValue == v){
  6399. r[++ri] = ci;
  6400. }
  6401. }
  6402. return r;
  6403. },
  6404. "checked" : function(c){
  6405. var r = [], ri = -1,
  6406. i, ci;
  6407. for(i = 0; ci = c[i]; i++){
  6408. if(ci.checked == true){
  6409. r[++ri] = ci;
  6410. }
  6411. }
  6412. return r;
  6413. },
  6414. "not" : function(c, ss){
  6415. return Ext.DomQuery.filter(c, ss, true);
  6416. },
  6417. "any" : function(c, selectors){
  6418. var ss = selectors.split('|'),
  6419. r = [], ri = -1, s,
  6420. i, ci, j;
  6421. for(i = 0; ci = c[i]; i++){
  6422. for(j = 0; s = ss[j]; j++){
  6423. if(Ext.DomQuery.is(ci, s)){
  6424. r[++ri] = ci;
  6425. break;
  6426. }
  6427. }
  6428. }
  6429. return r;
  6430. },
  6431. "odd" : function(c){
  6432. return this["nth-child"](c, "odd");
  6433. },
  6434. "even" : function(c){
  6435. return this["nth-child"](c, "even");
  6436. },
  6437. "nth" : function(c, a){
  6438. return c[a-1] || [];
  6439. },
  6440. "first" : function(c){
  6441. return c[0] || [];
  6442. },
  6443. "last" : function(c){
  6444. return c[c.length-1] || [];
  6445. },
  6446. "has" : function(c, ss){
  6447. var s = Ext.DomQuery.select,
  6448. r = [], ri = -1,
  6449. i, ci;
  6450. for(i = 0; ci = c[i]; i++){
  6451. if(s(ss, ci).length > 0){
  6452. r[++ri] = ci;
  6453. }
  6454. }
  6455. return r;
  6456. },
  6457. "next" : function(c, ss){
  6458. var is = Ext.DomQuery.is,
  6459. r = [], ri = -1,
  6460. i, ci, n;
  6461. for(i = 0; ci = c[i]; i++){
  6462. n = next(ci);
  6463. if(n && is(n, ss)){
  6464. r[++ri] = ci;
  6465. }
  6466. }
  6467. return r;
  6468. },
  6469. "prev" : function(c, ss){
  6470. var is = Ext.DomQuery.is,
  6471. r = [], ri = -1,
  6472. i, ci, n;
  6473. for(i = 0; ci = c[i]; i++){
  6474. n = prev(ci);
  6475. if(n && is(n, ss)){
  6476. r[++ri] = ci;
  6477. }
  6478. }
  6479. return r;
  6480. }
  6481. }
  6482. };
  6483. }());
  6484. /**
  6485. * Shorthand of {@link Ext.dom.Query#select}
  6486. * @member Ext
  6487. * @method query
  6488. * @inheritdoc Ext.dom.Query#select
  6489. */
  6490. Ext.query = Ext.DomQuery.select;
  6491. /**
  6492. * @class Ext.dom.Element
  6493. * @alternateClassName Ext.Element
  6494. * @alternateClassName Ext.core.Element
  6495. * @extend Ext.dom.AbstractElement
  6496. *
  6497. * Encapsulates a DOM element, adding simple DOM manipulation facilities, normalizing for browser differences.
  6498. *
  6499. * All instances of this class inherit the methods of {@link Ext.fx.Anim} making visual effects easily available to all
  6500. * DOM elements.
  6501. *
  6502. * Note that the events documented in this class are not Ext events, they encapsulate browser events. Some older browsers
  6503. * may not support the full range of events. Which events are supported is beyond the control of Ext JS.
  6504. *
  6505. * Usage:
  6506. *
  6507. * // by id
  6508. * var el = Ext.get("my-div");
  6509. *
  6510. * // by DOM element reference
  6511. * var el = Ext.get(myDivElement);
  6512. *
  6513. * # Animations
  6514. *
  6515. * When an element is manipulated, by default there is no animation.
  6516. *
  6517. * var el = Ext.get("my-div");
  6518. *
  6519. * // no animation
  6520. * el.setWidth(100);
  6521. *
  6522. * Many of the functions for manipulating an element have an optional "animate" parameter. This parameter can be
  6523. * specified as boolean (true) for default animation effects.
  6524. *
  6525. * // default animation
  6526. * el.setWidth(100, true);
  6527. *
  6528. * To configure the effects, an object literal with animation options to use as the Element animation configuration
  6529. * object can also be specified. Note that the supported Element animation configuration options are a subset of the
  6530. * {@link Ext.fx.Anim} animation options specific to Fx effects. The supported Element animation configuration options
  6531. * are:
  6532. *
  6533. * Option Default Description
  6534. * --------- -------- ---------------------------------------------
  6535. * {@link Ext.fx.Anim#duration duration} 350 The duration of the animation in milliseconds
  6536. * {@link Ext.fx.Anim#easing easing} easeOut The easing method
  6537. * {@link Ext.fx.Anim#callback callback} none A function to execute when the anim completes
  6538. * {@link Ext.fx.Anim#scope scope} this The scope (this) of the callback function
  6539. *
  6540. * Usage:
  6541. *
  6542. * // Element animation options object
  6543. * var opt = {
  6544. * {@link Ext.fx.Anim#duration duration}: 1000,
  6545. * {@link Ext.fx.Anim#easing easing}: 'elasticIn',
  6546. * {@link Ext.fx.Anim#callback callback}: this.foo,
  6547. * {@link Ext.fx.Anim#scope scope}: this
  6548. * };
  6549. * // animation with some options set
  6550. * el.setWidth(100, opt);
  6551. *
  6552. * The Element animation object being used for the animation will be set on the options object as "anim", which allows
  6553. * you to stop or manipulate the animation. Here is an example:
  6554. *
  6555. * // using the "anim" property to get the Anim object
  6556. * if(opt.anim.isAnimated()){
  6557. * opt.anim.stop();
  6558. * }
  6559. *
  6560. * # Composite (Collections of) Elements
  6561. *
  6562. * For working with collections of Elements, see {@link Ext.CompositeElement}
  6563. *
  6564. * @constructor
  6565. * Creates new Element directly.
  6566. * @param {String/HTMLElement} element
  6567. * @param {Boolean} [forceNew] By default the constructor checks to see if there is already an instance of this
  6568. * element in the cache and if there is it returns the same instance. This will skip that check (useful for extending
  6569. * this class).
  6570. * @return {Object}
  6571. */
  6572. (function() {
  6573. var HIDDEN = 'hidden',
  6574. DOC = document,
  6575. VISIBILITY = "visibility",
  6576. DISPLAY = "display",
  6577. NONE = "none",
  6578. XMASKED = Ext.baseCSSPrefix + "masked",
  6579. XMASKEDRELATIVE = Ext.baseCSSPrefix + "masked-relative",
  6580. EXTELMASKMSG = Ext.baseCSSPrefix + "mask-msg",
  6581. bodyRe = /^body/i,
  6582. visFly,
  6583. // speedy lookup for elements never to box adjust
  6584. noBoxAdjust = Ext.isStrict ? {
  6585. select: 1
  6586. }: {
  6587. input: 1,
  6588. select: 1,
  6589. textarea: 1
  6590. },
  6591. // Pseudo for use by cacheScrollValues
  6592. isScrolled = function(c) {
  6593. var r = [], ri = -1,
  6594. i, ci;
  6595. for (i = 0; ci = c[i]; i++) {
  6596. if (ci.scrollTop > 0 || ci.scrollLeft > 0) {
  6597. r[++ri] = ci;
  6598. }
  6599. }
  6600. return r;
  6601. },
  6602. Element = Ext.define('Ext.dom.Element', {
  6603. extend: 'Ext.dom.AbstractElement',
  6604. alternateClassName: ['Ext.Element', 'Ext.core.Element'],
  6605. addUnits: function() {
  6606. return this.self.addUnits.apply(this.self, arguments);
  6607. },
  6608. /**
  6609. * Tries to focus the element. Any exceptions are caught and ignored.
  6610. * @param {Number} [defer] Milliseconds to defer the focus
  6611. * @return {Ext.dom.Element} this
  6612. */
  6613. focus: function(defer, /* private */ dom) {
  6614. var me = this,
  6615. scrollTop,
  6616. body;
  6617. dom = dom || me.dom;
  6618. body = (dom.ownerDocument || DOC).body || DOC.body;
  6619. try {
  6620. if (Number(defer)) {
  6621. Ext.defer(me.focus, defer, me, [null, dom]);
  6622. } else {
  6623. // Focusing a large element, the browser attempts to scroll as much of it into view
  6624. // as possible. We need to override this behaviour.
  6625. if (dom.offsetHeight > Element.getViewHeight()) {
  6626. scrollTop = body.scrollTop;
  6627. }
  6628. dom.focus();
  6629. if (scrollTop !== undefined) {
  6630. body.scrollTop = scrollTop;
  6631. }
  6632. }
  6633. } catch(e) {
  6634. }
  6635. return me;
  6636. },
  6637. /**
  6638. * Tries to blur the element. Any exceptions are caught and ignored.
  6639. * @return {Ext.dom.Element} this
  6640. */
  6641. blur: function() {
  6642. try {
  6643. this.dom.blur();
  6644. } catch(e) {
  6645. }
  6646. return this;
  6647. },
  6648. /**
  6649. * Tests various css rules/browsers to determine if this element uses a border box
  6650. * @return {Boolean}
  6651. */
  6652. isBorderBox: function() {
  6653. var box = Ext.isBorderBox;
  6654. if (box) {
  6655. box = !((this.dom.tagName || "").toLowerCase() in noBoxAdjust);
  6656. }
  6657. return box;
  6658. },
  6659. /**
  6660. * Sets up event handlers to call the passed functions when the mouse is moved into and out of the Element.
  6661. * @param {Function} overFn The function to call when the mouse enters the Element.
  6662. * @param {Function} outFn The function to call when the mouse leaves the Element.
  6663. * @param {Object} [scope] The scope (`this` reference) in which the functions are executed. Defaults
  6664. * to the Element's DOM element.
  6665. * @param {Object} [options] Options for the listener. See {@link Ext.util.Observable#addListener the
  6666. * options parameter}.
  6667. * @return {Ext.dom.Element} this
  6668. */
  6669. hover: function(overFn, outFn, scope, options) {
  6670. var me = this;
  6671. me.on('mouseenter', overFn, scope || me.dom, options);
  6672. me.on('mouseleave', outFn, scope || me.dom, options);
  6673. return me;
  6674. },
  6675. /**
  6676. * Returns the value of a namespaced attribute from the element's underlying DOM node.
  6677. * @param {String} namespace The namespace in which to look for the attribute
  6678. * @param {String} name The attribute name
  6679. * @return {String} The attribute value
  6680. */
  6681. getAttributeNS: function(ns, name) {
  6682. return this.getAttribute(name, ns);
  6683. },
  6684. getAttribute: (Ext.isIE && !(Ext.isIE9 && DOC.documentMode === 9)) ?
  6685. function(name, ns) {
  6686. var d = this.dom,
  6687. type;
  6688. if (ns) {
  6689. type = typeof d[ns + ":" + name];
  6690. if (type != 'undefined' && type != 'unknown') {
  6691. return d[ns + ":" + name] || null;
  6692. }
  6693. return null;
  6694. }
  6695. if (name === "for") {
  6696. name = "htmlFor";
  6697. }
  6698. return d[name] || null;
  6699. } : function(name, ns) {
  6700. var d = this.dom;
  6701. if (ns) {
  6702. return d.getAttributeNS(ns, name) || d.getAttribute(ns + ":" + name);
  6703. }
  6704. return d.getAttribute(name) || d[name] || null;
  6705. },
  6706. /**
  6707. * When an element is moved around in the DOM, or is hidden using `display:none`, it loses layout, and therefore
  6708. * all scroll positions of all descendant elements are lost.
  6709. *
  6710. * This function caches them, and returns a function, which when run will restore the cached positions.
  6711. * In the following example, the Panel is moved from one Container to another which will cause it to lose all scroll positions:
  6712. *
  6713. * var restoreScroll = myPanel.el.cacheScrollValues();
  6714. * myOtherContainer.add(myPanel);
  6715. * restoreScroll();
  6716. *
  6717. * @return {Function} A function which will restore all descentant elements of this Element to their scroll
  6718. * positions recorded when this function was executed. Be aware that the returned function is a closure which has
  6719. * captured the scope of `cacheScrollValues`, so take care to derefence it as soon as not needed - if is it is a `var`
  6720. * it will drop out of scope, and the reference will be freed.
  6721. */
  6722. cacheScrollValues: function() {
  6723. var me = this,
  6724. scrolledDescendants,
  6725. el, i,
  6726. scrollValues = [],
  6727. result = function() {
  6728. for (i = 0; i < scrolledDescendants.length; i++) {
  6729. el = scrolledDescendants[i];
  6730. el.scrollLeft = scrollValues[i][0];
  6731. el.scrollTop = scrollValues[i][1];
  6732. }
  6733. };
  6734. if (!Ext.DomQuery.pseudos.isScrolled) {
  6735. Ext.DomQuery.pseudos.isScrolled = isScrolled;
  6736. }
  6737. scrolledDescendants = me.query(':isScrolled');
  6738. for (i = 0; i < scrolledDescendants.length; i++) {
  6739. el = scrolledDescendants[i];
  6740. scrollValues[i] = [el.scrollLeft, el.scrollTop];
  6741. }
  6742. return result;
  6743. },
  6744. /**
  6745. * @property {Boolean} autoBoxAdjust
  6746. * True to automatically adjust width and height settings for box-model issues.
  6747. */
  6748. autoBoxAdjust: true,
  6749. /**
  6750. * Checks whether the element is currently visible using both visibility and display properties.
  6751. * @param {Boolean} [deep=false] True to walk the dom and see if parent elements are hidden.
  6752. * If false, the function only checks the visibility of the element itself and it may return
  6753. * `true` even though a parent is not visible.
  6754. * @return {Boolean} `true` if the element is currently visible, else `false`
  6755. */
  6756. isVisible : function(deep) {
  6757. var me = this,
  6758. dom = me.dom,
  6759. stopNode = dom.ownerDocument.documentElement;
  6760. if (!visFly) {
  6761. visFly = new Element.Fly();
  6762. }
  6763. while (dom !== stopNode) {
  6764. // We're invisible if we hit a nonexistent parentNode or a document
  6765. // fragment or computed style visibility:hidden or display:none
  6766. if (!dom || dom.nodeType === 11 || (visFly.attach(dom)).isStyle(VISIBILITY, HIDDEN) || visFly.isStyle(DISPLAY, NONE)) {
  6767. return false;
  6768. }
  6769. // Quit now unless we are being asked to check parent nodes.
  6770. if (!deep) {
  6771. break;
  6772. }
  6773. dom = dom.parentNode;
  6774. }
  6775. return true;
  6776. },
  6777. /**
  6778. * Returns true if display is not "none"
  6779. * @return {Boolean}
  6780. */
  6781. isDisplayed : function() {
  6782. return !this.isStyle(DISPLAY, NONE);
  6783. },
  6784. /**
  6785. * Convenience method for setVisibilityMode(Element.DISPLAY)
  6786. * @param {String} [display] What to set display to when visible
  6787. * @return {Ext.dom.Element} this
  6788. */
  6789. enableDisplayMode : function(display) {
  6790. var me = this;
  6791. me.setVisibilityMode(Element.DISPLAY);
  6792. if (!Ext.isEmpty(display)) {
  6793. (me.$cache || me.getCache()).data.originalDisplay = display;
  6794. }
  6795. return me;
  6796. },
  6797. /**
  6798. * Puts a mask over this element to disable user interaction. Requires core.css.
  6799. * This method can only be applied to elements which accept child nodes.
  6800. * @param {String} [msg] A message to display in the mask
  6801. * @param {String} [msgCls] A css class to apply to the msg element
  6802. * @return {Ext.dom.Element} The mask element
  6803. */
  6804. mask : function(msg, msgCls /* private - passed by AbstractComponent.mask to avoid the need to interrogate the DOM to get the height*/, elHeight) {
  6805. var me = this,
  6806. dom = me.dom,
  6807. // In some cases, setExpression will exist but not be of a function type,
  6808. // so we check it explicitly here to stop IE throwing errors
  6809. setExpression = dom.style.setExpression,
  6810. data = (me.$cache || me.getCache()).data,
  6811. maskEl = data.maskEl,
  6812. maskMsg = data.maskMsg;
  6813. if (!(bodyRe.test(dom.tagName) && me.getStyle('position') == 'static')) {
  6814. me.addCls(XMASKEDRELATIVE);
  6815. }
  6816. // We always needs to recreate the mask since the DOM element may have been re-created
  6817. if (maskEl) {
  6818. maskEl.remove();
  6819. }
  6820. if (maskMsg) {
  6821. maskMsg.remove();
  6822. }
  6823. Ext.DomHelper.append(dom, [{
  6824. cls : Ext.baseCSSPrefix + "mask"
  6825. }, {
  6826. cls : msgCls ? EXTELMASKMSG + " " + msgCls : EXTELMASKMSG,
  6827. cn : {
  6828. tag: 'div',
  6829. html: msg || ''
  6830. }
  6831. }]);
  6832. maskMsg = Ext.get(dom.lastChild);
  6833. maskEl = Ext.get(maskMsg.dom.previousSibling);
  6834. data.maskMsg = maskMsg;
  6835. data.maskEl = maskEl;
  6836. me.addCls(XMASKED);
  6837. maskEl.setDisplayed(true);
  6838. if (typeof msg == 'string') {
  6839. maskMsg.setDisplayed(true);
  6840. maskMsg.center(me);
  6841. } else {
  6842. maskMsg.setDisplayed(false);
  6843. }
  6844. // NOTE: CSS expressions are resource intensive and to be used only as a last resort
  6845. // These expressions are removed as soon as they are no longer necessary - in the unmask method.
  6846. // In normal use cases an element will be masked for a limited period of time.
  6847. // Fix for https://sencha.jira.com/browse/EXTJSIV-19.
  6848. // IE6 strict mode and IE6-9 quirks mode takes off left+right padding when calculating width!
  6849. if (!Ext.supports.IncludePaddingInWidthCalculation && setExpression) {
  6850. // In an occasional case setExpression will throw an exception
  6851. try {
  6852. maskEl.dom.style.setExpression('width', 'this.parentNode.clientWidth + "px"');
  6853. } catch (e) {}
  6854. }
  6855. // Some versions and modes of IE subtract top+bottom padding when calculating height.
  6856. // Different versions from those which make the same error for width!
  6857. if (!Ext.supports.IncludePaddingInHeightCalculation && setExpression) {
  6858. // In an occasional case setExpression will throw an exception
  6859. try {
  6860. maskEl.dom.style.setExpression('height', 'this.parentNode.' + (dom == DOC.body ? 'scrollHeight' : 'offsetHeight') + ' + "px"');
  6861. } catch (e) {}
  6862. }
  6863. // ie will not expand full height automatically
  6864. else if (Ext.isIE && !(Ext.isIE7 && Ext.isStrict) && me.getStyle('height') == 'auto') {
  6865. maskEl.setSize(undefined, elHeight || me.getHeight());
  6866. }
  6867. return maskEl;
  6868. },
  6869. /**
  6870. * Hides a previously applied mask.
  6871. */
  6872. unmask : function() {
  6873. var me = this,
  6874. data = (me.$cache || me.getCache()).data,
  6875. maskEl = data.maskEl,
  6876. maskMsg = data.maskMsg,
  6877. style;
  6878. if (maskEl) {
  6879. style = maskEl.dom.style;
  6880. // Remove resource-intensive CSS expressions as soon as they are not required.
  6881. if (style.clearExpression) {
  6882. style.clearExpression('width');
  6883. style.clearExpression('height');
  6884. }
  6885. if (maskEl) {
  6886. maskEl.remove();
  6887. delete data.maskEl;
  6888. }
  6889. if (maskMsg) {
  6890. maskMsg.remove();
  6891. delete data.maskMsg;
  6892. }
  6893. me.removeCls([XMASKED, XMASKEDRELATIVE]);
  6894. }
  6895. },
  6896. /**
  6897. * Returns true if this element is masked. Also re-centers any displayed message within the mask.
  6898. * @return {Boolean}
  6899. */
  6900. isMasked : function() {
  6901. var me = this,
  6902. data = (me.$cache || me.getCache()).data,
  6903. maskEl = data.maskEl,
  6904. maskMsg = data.maskMsg,
  6905. hasMask = false;
  6906. if (maskEl && maskEl.isVisible()) {
  6907. if (maskMsg) {
  6908. maskMsg.center(me);
  6909. }
  6910. hasMask = true;
  6911. }
  6912. return hasMask;
  6913. },
  6914. /**
  6915. * Creates an iframe shim for this element to keep selects and other windowed objects from
  6916. * showing through.
  6917. * @return {Ext.dom.Element} The new shim element
  6918. */
  6919. createShim : function() {
  6920. var el = DOC.createElement('iframe'),
  6921. shim;
  6922. el.frameBorder = '0';
  6923. el.className = Ext.baseCSSPrefix + 'shim';
  6924. el.src = Ext.SSL_SECURE_URL;
  6925. shim = Ext.get(this.dom.parentNode.insertBefore(el, this.dom));
  6926. shim.autoBoxAdjust = false;
  6927. return shim;
  6928. },
  6929. /**
  6930. * Convenience method for constructing a KeyMap
  6931. * @param {String/Number/Number[]/Object} key Either a string with the keys to listen for, the numeric key code,
  6932. * array of key codes or an object with the following options:
  6933. * @param {Number/Array} key.key
  6934. * @param {Boolean} key.shift
  6935. * @param {Boolean} key.ctrl
  6936. * @param {Boolean} key.alt
  6937. * @param {Function} fn The function to call
  6938. * @param {Object} [scope] The scope (`this` reference) in which the specified function is executed. Defaults to this Element.
  6939. * @return {Ext.util.KeyMap} The KeyMap created
  6940. */
  6941. addKeyListener : function(key, fn, scope){
  6942. var config;
  6943. if(typeof key != 'object' || Ext.isArray(key)){
  6944. config = {
  6945. target: this,
  6946. key: key,
  6947. fn: fn,
  6948. scope: scope
  6949. };
  6950. }else{
  6951. config = {
  6952. target: this,
  6953. key : key.key,
  6954. shift : key.shift,
  6955. ctrl : key.ctrl,
  6956. alt : key.alt,
  6957. fn: fn,
  6958. scope: scope
  6959. };
  6960. }
  6961. return new Ext.util.KeyMap(config);
  6962. },
  6963. /**
  6964. * Creates a KeyMap for this element
  6965. * @param {Object} config The KeyMap config. See {@link Ext.util.KeyMap} for more details
  6966. * @return {Ext.util.KeyMap} The KeyMap created
  6967. */
  6968. addKeyMap : function(config) {
  6969. return new Ext.util.KeyMap(Ext.apply({
  6970. target: this
  6971. }, config));
  6972. },
  6973. // Mouse events
  6974. /**
  6975. * @event click
  6976. * Fires when a mouse click is detected within the element.
  6977. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  6978. * @param {HTMLElement} t The target of the event.
  6979. */
  6980. /**
  6981. * @event contextmenu
  6982. * Fires when a right click is detected within the element.
  6983. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  6984. * @param {HTMLElement} t The target of the event.
  6985. */
  6986. /**
  6987. * @event dblclick
  6988. * Fires when a mouse double click is detected within the element.
  6989. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  6990. * @param {HTMLElement} t The target of the event.
  6991. */
  6992. /**
  6993. * @event mousedown
  6994. * Fires when a mousedown is detected within the element.
  6995. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  6996. * @param {HTMLElement} t The target of the event.
  6997. */
  6998. /**
  6999. * @event mouseup
  7000. * Fires when a mouseup is detected within the element.
  7001. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7002. * @param {HTMLElement} t The target of the event.
  7003. */
  7004. /**
  7005. * @event mouseover
  7006. * Fires when a mouseover is detected within the element.
  7007. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7008. * @param {HTMLElement} t The target of the event.
  7009. */
  7010. /**
  7011. * @event mousemove
  7012. * Fires when a mousemove is detected with the element.
  7013. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7014. * @param {HTMLElement} t The target of the event.
  7015. */
  7016. /**
  7017. * @event mouseout
  7018. * Fires when a mouseout is detected with the element.
  7019. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7020. * @param {HTMLElement} t The target of the event.
  7021. */
  7022. /**
  7023. * @event mouseenter
  7024. * Fires when the mouse enters the element.
  7025. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7026. * @param {HTMLElement} t The target of the event.
  7027. */
  7028. /**
  7029. * @event mouseleave
  7030. * Fires when the mouse leaves the element.
  7031. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7032. * @param {HTMLElement} t The target of the event.
  7033. */
  7034. // Keyboard events
  7035. /**
  7036. * @event keypress
  7037. * Fires when a keypress is detected within the element.
  7038. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7039. * @param {HTMLElement} t The target of the event.
  7040. */
  7041. /**
  7042. * @event keydown
  7043. * Fires when a keydown is detected within the element.
  7044. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7045. * @param {HTMLElement} t The target of the event.
  7046. */
  7047. /**
  7048. * @event keyup
  7049. * Fires when a keyup is detected within the element.
  7050. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7051. * @param {HTMLElement} t The target of the event.
  7052. */
  7053. // HTML frame/object events
  7054. /**
  7055. * @event load
  7056. * Fires when the user agent finishes loading all content within the element. Only supported by window, frames,
  7057. * objects and images.
  7058. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7059. * @param {HTMLElement} t The target of the event.
  7060. */
  7061. /**
  7062. * @event unload
  7063. * Fires when the user agent removes all content from a window or frame. For elements, it fires when the target
  7064. * element or any of its content has been removed.
  7065. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7066. * @param {HTMLElement} t The target of the event.
  7067. */
  7068. /**
  7069. * @event abort
  7070. * Fires when an object/image is stopped from loading before completely loaded.
  7071. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7072. * @param {HTMLElement} t The target of the event.
  7073. */
  7074. /**
  7075. * @event error
  7076. * Fires when an object/image/frame cannot be loaded properly.
  7077. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7078. * @param {HTMLElement} t The target of the event.
  7079. */
  7080. /**
  7081. * @event resize
  7082. * Fires when a document view is resized.
  7083. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7084. * @param {HTMLElement} t The target of the event.
  7085. */
  7086. /**
  7087. * @event scroll
  7088. * Fires when a document view is scrolled.
  7089. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7090. * @param {HTMLElement} t The target of the event.
  7091. */
  7092. // Form events
  7093. /**
  7094. * @event select
  7095. * Fires when a user selects some text in a text field, including input and textarea.
  7096. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7097. * @param {HTMLElement} t The target of the event.
  7098. */
  7099. /**
  7100. * @event change
  7101. * Fires when a control loses the input focus and its value has been modified since gaining focus.
  7102. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7103. * @param {HTMLElement} t The target of the event.
  7104. */
  7105. /**
  7106. * @event submit
  7107. * Fires when a form is submitted.
  7108. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7109. * @param {HTMLElement} t The target of the event.
  7110. */
  7111. /**
  7112. * @event reset
  7113. * Fires when a form is reset.
  7114. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7115. * @param {HTMLElement} t The target of the event.
  7116. */
  7117. /**
  7118. * @event focus
  7119. * Fires when an element receives focus either via the pointing device or by tab navigation.
  7120. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7121. * @param {HTMLElement} t The target of the event.
  7122. */
  7123. /**
  7124. * @event blur
  7125. * Fires when an element loses focus either via the pointing device or by tabbing navigation.
  7126. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7127. * @param {HTMLElement} t The target of the event.
  7128. */
  7129. // User Interface events
  7130. /**
  7131. * @event DOMFocusIn
  7132. * Where supported. Similar to HTML focus event, but can be applied to any focusable element.
  7133. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7134. * @param {HTMLElement} t The target of the event.
  7135. */
  7136. /**
  7137. * @event DOMFocusOut
  7138. * Where supported. Similar to HTML blur event, but can be applied to any focusable element.
  7139. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7140. * @param {HTMLElement} t The target of the event.
  7141. */
  7142. /**
  7143. * @event DOMActivate
  7144. * Where supported. Fires when an element is activated, for instance, through a mouse click or a keypress.
  7145. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7146. * @param {HTMLElement} t The target of the event.
  7147. */
  7148. // DOM Mutation events
  7149. /**
  7150. * @event DOMSubtreeModified
  7151. * Where supported. Fires when the subtree is modified.
  7152. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7153. * @param {HTMLElement} t The target of the event.
  7154. */
  7155. /**
  7156. * @event DOMNodeInserted
  7157. * Where supported. Fires when a node has been added as a child of another node.
  7158. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7159. * @param {HTMLElement} t The target of the event.
  7160. */
  7161. /**
  7162. * @event DOMNodeRemoved
  7163. * Where supported. Fires when a descendant node of the element is removed.
  7164. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7165. * @param {HTMLElement} t The target of the event.
  7166. */
  7167. /**
  7168. * @event DOMNodeRemovedFromDocument
  7169. * Where supported. Fires when a node is being removed from a document.
  7170. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7171. * @param {HTMLElement} t The target of the event.
  7172. */
  7173. /**
  7174. * @event DOMNodeInsertedIntoDocument
  7175. * Where supported. Fires when a node is being inserted into a document.
  7176. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7177. * @param {HTMLElement} t The target of the event.
  7178. */
  7179. /**
  7180. * @event DOMAttrModified
  7181. * Where supported. Fires when an attribute has been modified.
  7182. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7183. * @param {HTMLElement} t The target of the event.
  7184. */
  7185. /**
  7186. * @event DOMCharacterDataModified
  7187. * Where supported. Fires when the character data has been modified.
  7188. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  7189. * @param {HTMLElement} t The target of the event.
  7190. */
  7191. /**
  7192. * Appends an event handler to this element.
  7193. *
  7194. * @param {String} eventName The name of event to handle.
  7195. *
  7196. * @param {Function} fn The handler function the event invokes. This function is passed the following parameters:
  7197. *
  7198. * - **evt** : EventObject
  7199. *
  7200. * The {@link Ext.EventObject EventObject} describing the event.
  7201. *
  7202. * - **el** : HtmlElement
  7203. *
  7204. * The DOM element which was the target of the event. Note that this may be filtered by using the delegate option.
  7205. *
  7206. * - **o** : Object
  7207. *
  7208. * The options object from the call that setup the listener.
  7209. *
  7210. * @param {Object} scope (optional) The scope (**this** reference) in which the handler function is executed. **If
  7211. * omitted, defaults to this Element.**
  7212. *
  7213. * @param {Object} options (optional) An object containing handler configuration properties. This may contain any of
  7214. * the following properties:
  7215. *
  7216. * - **scope** Object :
  7217. *
  7218. * The scope (**this** reference) in which the handler function is executed. **If omitted, defaults to this
  7219. * Element.**
  7220. *
  7221. * - **delegate** String:
  7222. *
  7223. * A simple selector to filter the target or look for a descendant of the target. See below for additional details.
  7224. *
  7225. * - **stopEvent** Boolean:
  7226. *
  7227. * True to stop the event. That is stop propagation, and prevent the default action.
  7228. *
  7229. * - **preventDefault** Boolean:
  7230. *
  7231. * True to prevent the default action
  7232. *
  7233. * - **stopPropagation** Boolean:
  7234. *
  7235. * True to prevent event propagation
  7236. *
  7237. * - **normalized** Boolean:
  7238. *
  7239. * False to pass a browser event to the handler function instead of an Ext.EventObject
  7240. *
  7241. * - **target** Ext.dom.Element:
  7242. *
  7243. * Only call the handler if the event was fired on the target Element, _not_ if the event was bubbled up from a
  7244. * child node.
  7245. *
  7246. * - **delay** Number:
  7247. *
  7248. * The number of milliseconds to delay the invocation of the handler after the event fires.
  7249. *
  7250. * - **single** Boolean:
  7251. *
  7252. * True to add a handler to handle just the next firing of the event, and then remove itself.
  7253. *
  7254. * - **buffer** Number:
  7255. *
  7256. * Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed by the specified number of
  7257. * milliseconds. If the event fires again within that time, the original handler is _not_ invoked, but the new
  7258. * handler is scheduled in its place.
  7259. *
  7260. * **Combining Options**
  7261. *
  7262. * Using the options argument, it is possible to combine different types of listeners:
  7263. *
  7264. * A delayed, one-time listener that auto stops the event and adds a custom argument (forumId) to the options
  7265. * object. The options object is available as the third parameter in the handler function.
  7266. *
  7267. * Code:
  7268. *
  7269. * el.on('click', this.onClick, this, {
  7270. * single: true,
  7271. * delay: 100,
  7272. * stopEvent : true,
  7273. * forumId: 4
  7274. * });
  7275. *
  7276. * **Attaching multiple handlers in 1 call**
  7277. *
  7278. * The method also allows for a single argument to be passed which is a config object containing properties which
  7279. * specify multiple handlers.
  7280. *
  7281. * Code:
  7282. *
  7283. * el.on({
  7284. * 'click' : {
  7285. * fn: this.onClick,
  7286. * scope: this,
  7287. * delay: 100
  7288. * },
  7289. * 'mouseover' : {
  7290. * fn: this.onMouseOver,
  7291. * scope: this
  7292. * },
  7293. * 'mouseout' : {
  7294. * fn: this.onMouseOut,
  7295. * scope: this
  7296. * }
  7297. * });
  7298. *
  7299. * Or a shorthand syntax:
  7300. *
  7301. * Code:
  7302. *
  7303. * el.on({
  7304. * 'click' : this.onClick,
  7305. * 'mouseover' : this.onMouseOver,
  7306. * 'mouseout' : this.onMouseOut,
  7307. * scope: this
  7308. * });
  7309. *
  7310. * **delegate**
  7311. *
  7312. * This is a configuration option that you can pass along when registering a handler for an event to assist with
  7313. * event delegation. Event delegation is a technique that is used to reduce memory consumption and prevent exposure
  7314. * to memory-leaks. By registering an event for a container element as opposed to each element within a container.
  7315. * By setting this configuration option to a simple selector, the target element will be filtered to look for a
  7316. * descendant of the target. For example:
  7317. *
  7318. * // using this markup:
  7319. * <div id='elId'>
  7320. * <p id='p1'>paragraph one</p>
  7321. * <p id='p2' class='clickable'>paragraph two</p>
  7322. * <p id='p3'>paragraph three</p>
  7323. * </div>
  7324. *
  7325. * // utilize event delegation to registering just one handler on the container element:
  7326. * el = Ext.get('elId');
  7327. * el.on(
  7328. * 'click',
  7329. * function(e,t) {
  7330. * // handle click
  7331. * console.info(t.id); // 'p2'
  7332. * },
  7333. * this,
  7334. * {
  7335. * // filter the target element to be a descendant with the class 'clickable'
  7336. * delegate: '.clickable'
  7337. * }
  7338. * );
  7339. *
  7340. * @return {Ext.dom.Element} this
  7341. */
  7342. on: function(eventName, fn, scope, options) {
  7343. Ext.EventManager.on(this, eventName, fn, scope || this, options);
  7344. return this;
  7345. },
  7346. /**
  7347. * Removes an event handler from this element.
  7348. *
  7349. * **Note**: if a *scope* was explicitly specified when {@link #on adding} the listener,
  7350. * the same scope must be specified here.
  7351. *
  7352. * Example:
  7353. *
  7354. * el.un('click', this.handlerFn);
  7355. * // or
  7356. * el.removeListener('click', this.handlerFn);
  7357. *
  7358. * @param {String} eventName The name of the event from which to remove the handler.
  7359. * @param {Function} fn The handler function to remove. **This must be a reference to the function passed into the
  7360. * {@link #on} call.**
  7361. * @param {Object} scope If a scope (**this** reference) was specified when the listener was added, then this must
  7362. * refer to the same object.
  7363. * @return {Ext.dom.Element} this
  7364. */
  7365. un: function(eventName, fn, scope) {
  7366. Ext.EventManager.un(this, eventName, fn, scope || this);
  7367. return this;
  7368. },
  7369. /**
  7370. * Removes all previous added listeners from this element
  7371. * @return {Ext.dom.Element} this
  7372. */
  7373. removeAllListeners: function() {
  7374. Ext.EventManager.removeAll(this);
  7375. return this;
  7376. },
  7377. /**
  7378. * Recursively removes all previous added listeners from this element and its children
  7379. * @return {Ext.dom.Element} this
  7380. */
  7381. purgeAllListeners: function() {
  7382. Ext.EventManager.purgeElement(this);
  7383. return this;
  7384. }
  7385. }, function() {
  7386. var EC = Ext.cache,
  7387. El = this,
  7388. AbstractElement = Ext.dom.AbstractElement,
  7389. focusRe = /a|button|embed|iframe|img|input|object|select|textarea/i,
  7390. nonSpaceRe = /\S/,
  7391. scriptTagRe = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig,
  7392. replaceScriptTagRe = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig,
  7393. srcRe = /\ssrc=([\'\"])(.*?)\1/i,
  7394. typeRe = /\stype=([\'\"])(.*?)\1/i,
  7395. useDocForId = !(Ext.isIE6 || Ext.isIE7 || Ext.isIE8);
  7396. El.boxMarkup = '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div><div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div><div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
  7397. //</!if>
  7398. // private
  7399. // Garbage collection - uncache elements/purge listeners on orphaned elements
  7400. // so we don't hold a reference and cause the browser to retain them
  7401. function garbageCollect() {
  7402. if (!Ext.enableGarbageCollector) {
  7403. clearInterval(El.collectorThreadId);
  7404. } else {
  7405. var eid,
  7406. d,
  7407. o,
  7408. t;
  7409. for (eid in EC) {
  7410. if (!EC.hasOwnProperty(eid)) {
  7411. continue;
  7412. }
  7413. o = EC[eid];
  7414. // Skip document and window elements
  7415. if (o.skipGarbageCollection) {
  7416. continue;
  7417. }
  7418. d = o.dom;
  7419. //<debug>
  7420. // Should always have a DOM node
  7421. if (!d) {
  7422. Ext.Error.raise('Missing DOM node in element garbage collection: ' + eid);
  7423. }
  7424. // Check that document and window elements haven't got through
  7425. if (d && (d.getElementById || d.navigator)) {
  7426. Ext.Error.raise('Unexpected document or window element in element garbage collection');
  7427. }
  7428. //</debug>
  7429. // -------------------------------------------------------
  7430. // Determining what is garbage:
  7431. // -------------------------------------------------------
  7432. // !d.parentNode
  7433. // no parentNode == direct orphan, definitely garbage
  7434. // -------------------------------------------------------
  7435. // !d.offsetParent && !document.getElementById(eid)
  7436. // display none elements have no offsetParent so we will
  7437. // also try to look it up by it's id. However, check
  7438. // offsetParent first so we don't do unneeded lookups.
  7439. // This enables collection of elements that are not orphans
  7440. // directly, but somewhere up the line they have an orphan
  7441. // parent.
  7442. // -------------------------------------------------------
  7443. if (!d.parentNode || (!d.offsetParent && !Ext.getElementById(eid))) {
  7444. if (d && Ext.enableListenerCollection) {
  7445. Ext.EventManager.removeAll(d);
  7446. }
  7447. delete EC[eid];
  7448. }
  7449. }
  7450. // Cleanup IE Object leaks
  7451. if (Ext.isIE) {
  7452. t = {};
  7453. for (eid in EC) {
  7454. if (!EC.hasOwnProperty(eid)) {
  7455. continue;
  7456. }
  7457. t[eid] = EC[eid];
  7458. }
  7459. EC = Ext.cache = t;
  7460. }
  7461. }
  7462. }
  7463. El.collectorThreadId = setInterval(garbageCollect, 30000);
  7464. //Stuff from Element-more.js
  7465. El.addMethods({
  7466. /**
  7467. * Monitors this Element for the mouse leaving. Calls the function after the specified delay only if
  7468. * the mouse was not moved back into the Element within the delay. If the mouse *was* moved
  7469. * back in, the function is not called.
  7470. * @param {Number} delay The delay **in milliseconds** to wait for possible mouse re-entry before calling the handler function.
  7471. * @param {Function} handler The function to call if the mouse remains outside of this Element for the specified time.
  7472. * @param {Object} [scope] The scope (`this` reference) in which the handler function executes. Defaults to this Element.
  7473. * @return {Object} The listeners object which was added to this element so that monitoring can be stopped. Example usage:
  7474. *
  7475. * // Hide the menu if the mouse moves out for 250ms or more
  7476. * this.mouseLeaveMonitor = this.menuEl.monitorMouseLeave(250, this.hideMenu, this);
  7477. *
  7478. * ...
  7479. * // Remove mouseleave monitor on menu destroy
  7480. * this.menuEl.un(this.mouseLeaveMonitor);
  7481. *
  7482. */
  7483. monitorMouseLeave: function(delay, handler, scope) {
  7484. var me = this,
  7485. timer,
  7486. listeners = {
  7487. mouseleave: function(e) {
  7488. timer = setTimeout(Ext.Function.bind(handler, scope||me, [e]), delay);
  7489. },
  7490. mouseenter: function() {
  7491. clearTimeout(timer);
  7492. },
  7493. freezeEvent: true
  7494. };
  7495. me.on(listeners);
  7496. return listeners;
  7497. },
  7498. /**
  7499. * Stops the specified event(s) from bubbling and optionally prevents the default action
  7500. * @param {String/String[]} eventName an event / array of events to stop from bubbling
  7501. * @param {Boolean} [preventDefault] true to prevent the default action too
  7502. * @return {Ext.dom.Element} this
  7503. */
  7504. swallowEvent : function(eventName, preventDefault) {
  7505. var me = this,
  7506. e, eLen;
  7507. function fn(e) {
  7508. e.stopPropagation();
  7509. if (preventDefault) {
  7510. e.preventDefault();
  7511. }
  7512. }
  7513. if (Ext.isArray(eventName)) {
  7514. eLen = eventName.length;
  7515. for (e = 0; e < eLen; e++) {
  7516. me.on(eventName[e], fn);
  7517. }
  7518. return me;
  7519. }
  7520. me.on(eventName, fn);
  7521. return me;
  7522. },
  7523. /**
  7524. * Create an event handler on this element such that when the event fires and is handled by this element,
  7525. * it will be relayed to another object (i.e., fired again as if it originated from that object instead).
  7526. * @param {String} eventName The type of event to relay
  7527. * @param {Object} observable Any object that extends {@link Ext.util.Observable} that will provide the context
  7528. * for firing the relayed event
  7529. */
  7530. relayEvent : function(eventName, observable) {
  7531. this.on(eventName, function(e) {
  7532. observable.fireEvent(eventName, e);
  7533. });
  7534. },
  7535. /**
  7536. * Removes Empty, or whitespace filled text nodes. Combines adjacent text nodes.
  7537. * @param {Boolean} [forceReclean=false] By default the element keeps track if it has been cleaned already
  7538. * so you can call this over and over. However, if you update the element and need to force a reclean, you
  7539. * can pass true.
  7540. */
  7541. clean : function(forceReclean) {
  7542. var me = this,
  7543. dom = me.dom,
  7544. data = (me.$cache || me.getCache()).data,
  7545. n = dom.firstChild,
  7546. ni = -1,
  7547. nx;
  7548. if (data.isCleaned && forceReclean !== true) {
  7549. return me;
  7550. }
  7551. while (n) {
  7552. nx = n.nextSibling;
  7553. if (n.nodeType == 3) {
  7554. // Remove empty/whitespace text nodes
  7555. if (!(nonSpaceRe.test(n.nodeValue))) {
  7556. dom.removeChild(n);
  7557. // Combine adjacent text nodes
  7558. } else if (nx && nx.nodeType == 3) {
  7559. n.appendData(Ext.String.trim(nx.data));
  7560. dom.removeChild(nx);
  7561. nx = n.nextSibling;
  7562. n.nodeIndex = ++ni;
  7563. }
  7564. } else {
  7565. // Recursively clean
  7566. Ext.fly(n).clean();
  7567. n.nodeIndex = ++ni;
  7568. }
  7569. n = nx;
  7570. }
  7571. data.isCleaned = true;
  7572. return me;
  7573. },
  7574. /**
  7575. * Direct access to the Ext.ElementLoader {@link Ext.ElementLoader#method-load} method. The method takes the same object
  7576. * parameter as {@link Ext.ElementLoader#method-load}
  7577. * @return {Ext.dom.Element} this
  7578. */
  7579. load : function(options) {
  7580. this.getLoader().load(options);
  7581. return this;
  7582. },
  7583. /**
  7584. * Gets this element's {@link Ext.ElementLoader ElementLoader}
  7585. * @return {Ext.ElementLoader} The loader
  7586. */
  7587. getLoader : function() {
  7588. var me = this,
  7589. data = (me.$cache || me.getCache()).data,
  7590. loader = data.loader;
  7591. if (!loader) {
  7592. data.loader = loader = new Ext.ElementLoader({
  7593. target: me
  7594. });
  7595. }
  7596. return loader;
  7597. },
  7598. /**
  7599. * @private.
  7600. * Currently used for updating grid cells without modifying DOM structure
  7601. *
  7602. * Synchronizes content of this Element with the content of the passed element.
  7603. *
  7604. * Style and CSS class are copied from source into this Element, and contents are synched
  7605. * recursively. If a child node is a text node, the textual data is copied.
  7606. */
  7607. syncContent: function(source) {
  7608. source = Ext.getDom(source);
  7609. var me = this,
  7610. sourceNodes = source.childNodes,
  7611. sourceLen = sourceNodes.length,
  7612. dest = me.dom,
  7613. destNodes = dest.childNodes,
  7614. destLen = destNodes.length,
  7615. i, destNode, sourceNode,
  7616. nodeType;
  7617. // Copy top node's style and CSS class
  7618. dest.style.cssText = source.style.cssText;
  7619. dest.className = source.className;
  7620. // If the number of child nodes does not match, fall back to replacing innerHTML
  7621. if (sourceLen !== destLen) {
  7622. source.innerHTML = dest.innerHTML;
  7623. return;
  7624. }
  7625. // Loop through source nodes.
  7626. // If there are fewer, we must remove excess
  7627. for (i = 0; i < sourceLen; i++) {
  7628. sourceNode = sourceNodes[i];
  7629. destNode = destNodes[i];
  7630. nodeType = sourceNode.nodeType;
  7631. // If node structure is out of sync, just drop innerHTML in and return
  7632. if (nodeType !== destNode.nodeType || (nodeType === 1 && sourceNode.tagName !== destNode.tagName)) {
  7633. dest.innerHTML = source.innerHTML;
  7634. return;
  7635. }
  7636. // Update text node
  7637. if (nodeType === 3) {
  7638. destNode.data = sourceNode.data;
  7639. }
  7640. // Sync element content
  7641. else {
  7642. if (sourceNode.id && destNode.id !== sourceNode.id) {
  7643. destNode.id = sourceNode.id;
  7644. }
  7645. destNode.style.cssText = sourceNode.style.cssText;
  7646. destNode.className = sourceNode.className;
  7647. Ext.fly(destNode).syncContent(sourceNode);
  7648. }
  7649. }
  7650. },
  7651. /**
  7652. * Updates the innerHTML of this element, optionally searching for and processing scripts.
  7653. * @param {String} html The new HTML
  7654. * @param {Boolean} [loadScripts] True to look for and process scripts (defaults to false)
  7655. * @param {Function} [callback] For async script loading you can be notified when the update completes
  7656. * @return {Ext.dom.Element} this
  7657. */
  7658. update : function(html, loadScripts, callback) {
  7659. var me = this,
  7660. id,
  7661. dom,
  7662. interval;
  7663. if (!me.dom) {
  7664. return me;
  7665. }
  7666. html = html || '';
  7667. dom = me.dom;
  7668. if (loadScripts !== true) {
  7669. dom.innerHTML = html;
  7670. Ext.callback(callback, me);
  7671. return me;
  7672. }
  7673. id = Ext.id();
  7674. html += '<span id="' + id + '"></span>';
  7675. interval = setInterval(function() {
  7676. var hd,
  7677. match,
  7678. attrs,
  7679. srcMatch,
  7680. typeMatch,
  7681. el,
  7682. s;
  7683. if (!(el = DOC.getElementById(id))) {
  7684. return false;
  7685. }
  7686. clearInterval(interval);
  7687. Ext.removeNode(el);
  7688. hd = Ext.getHead().dom;
  7689. while ((match = scriptTagRe.exec(html))) {
  7690. attrs = match[1];
  7691. srcMatch = attrs ? attrs.match(srcRe) : false;
  7692. if (srcMatch && srcMatch[2]) {
  7693. s = DOC.createElement("script");
  7694. s.src = srcMatch[2];
  7695. typeMatch = attrs.match(typeRe);
  7696. if (typeMatch && typeMatch[2]) {
  7697. s.type = typeMatch[2];
  7698. }
  7699. hd.appendChild(s);
  7700. } else if (match[2] && match[2].length > 0) {
  7701. if (window.execScript) {
  7702. window.execScript(match[2]);
  7703. } else {
  7704. window.eval(match[2]);
  7705. }
  7706. }
  7707. }
  7708. Ext.callback(callback, me);
  7709. }, 20);
  7710. dom.innerHTML = html.replace(replaceScriptTagRe, '');
  7711. return me;
  7712. },
  7713. // inherit docs, overridden so we can add removeAnchor
  7714. removeAllListeners : function() {
  7715. this.removeAnchor();
  7716. Ext.EventManager.removeAll(this.dom);
  7717. return this;
  7718. },
  7719. /**
  7720. * Creates a proxy element of this element
  7721. * @param {String/Object} config The class name of the proxy element or a DomHelper config object
  7722. * @param {String/HTMLElement} [renderTo] The element or element id to render the proxy to. Defaults to: document.body.
  7723. * @param {Boolean} [matchBox=false] True to align and size the proxy to this element now.
  7724. * @return {Ext.dom.Element} The new proxy element
  7725. */
  7726. createProxy : function(config, renderTo, matchBox) {
  7727. config = (typeof config == 'object') ? config : {tag : "div", cls: config};
  7728. var me = this,
  7729. proxy = renderTo ? Ext.DomHelper.append(renderTo, config, true) :
  7730. Ext.DomHelper.insertBefore(me.dom, config, true);
  7731. proxy.setVisibilityMode(Element.DISPLAY);
  7732. proxy.hide();
  7733. if (matchBox && me.setBox && me.getBox) { // check to make sure Element.position.js is loaded
  7734. proxy.setBox(me.getBox());
  7735. }
  7736. return proxy;
  7737. },
  7738. /**
  7739. * Gets the parent node of the current element taking into account Ext.scopeResetCSS
  7740. * @protected
  7741. * @return {HTMLElement} The parent element
  7742. */
  7743. getScopeParent: function() {
  7744. var parent = this.dom.parentNode;
  7745. if (Ext.scopeResetCSS) {
  7746. // If it's a normal reset, we will be wrapped in a single x-reset element, so grab the parent
  7747. parent = parent.parentNode;
  7748. if (!Ext.supports.CSS3LinearGradient || !Ext.supports.CSS3BorderRadius) {
  7749. // In the cases where we have nbr or nlg, it will be wrapped in a second element,
  7750. // so we need to go and get the parent again.
  7751. parent = parent.parentNode;
  7752. }
  7753. }
  7754. return parent;
  7755. },
  7756. /**
  7757. * Returns true if this element needs an explicit tabIndex to make it focusable. Input fields, text areas, buttons
  7758. * anchors elements **with an href** etc do not need a tabIndex, but structural elements do.
  7759. */
  7760. needsTabIndex: function() {
  7761. if (this.dom) {
  7762. if ((this.dom.nodeName === 'a') && (!this.dom.href)) {
  7763. return true;
  7764. }
  7765. return !focusRe.test(this.dom.nodeName);
  7766. }
  7767. },
  7768. /**
  7769. * Checks whether this element can be focused.
  7770. * @return {Boolean} True if the element is focusable
  7771. */
  7772. focusable: function () {
  7773. var dom = this.dom,
  7774. nodeName = dom.nodeName,
  7775. canFocus = false;
  7776. if (!dom.disabled) {
  7777. if (focusRe.test(nodeName)) {
  7778. if ((nodeName !== 'a') || dom.href) {
  7779. canFocus = true;
  7780. }
  7781. } else {
  7782. canFocus = !isNaN(dom.tabIndex);
  7783. }
  7784. }
  7785. return canFocus && this.isVisible(true);
  7786. }
  7787. });
  7788. if (Ext.isIE) {
  7789. El.prototype.getById = function (id, asDom) {
  7790. var dom = this.dom,
  7791. cacheItem, el, ret;
  7792. if (dom) {
  7793. // for normal elements getElementById is the best solution, but if the el is
  7794. // not part of the document.body, we need to use all[]
  7795. el = (useDocForId && DOC.getElementById(id)) || dom.all[id];
  7796. if (el) {
  7797. if (asDom) {
  7798. ret = el;
  7799. } else {
  7800. // calling El.get here is a real hit (2x slower) because it has to
  7801. // redetermine that we are giving it a dom el.
  7802. cacheItem = EC[id];
  7803. if (cacheItem && cacheItem.el) {
  7804. ret = Ext.updateCacheEntry(cacheItem, el).el;
  7805. } else {
  7806. ret = new Element(el);
  7807. }
  7808. }
  7809. return ret;
  7810. }
  7811. }
  7812. return asDom ? Ext.getDom(id) : El.get(id);
  7813. };
  7814. }
  7815. El.createAlias({
  7816. /**
  7817. * @method
  7818. * @inheritdoc Ext.dom.Element#on
  7819. * Shorthand for {@link #on}.
  7820. */
  7821. addListener: 'on',
  7822. /**
  7823. * @method
  7824. * @inheritdoc Ext.dom.Element#un
  7825. * Shorthand for {@link #un}.
  7826. */
  7827. removeListener: 'un',
  7828. /**
  7829. * @method
  7830. * @inheritdoc Ext.dom.Element#removeAllListeners
  7831. * Alias for {@link #removeAllListeners}.
  7832. */
  7833. clearListeners: 'removeAllListeners'
  7834. });
  7835. El.Fly = AbstractElement.Fly = new Ext.Class({
  7836. extend: El,
  7837. constructor: function(dom) {
  7838. this.dom = dom;
  7839. },
  7840. attach: AbstractElement.Fly.prototype.attach
  7841. });
  7842. if (Ext.isIE) {
  7843. Ext.getElementById = function (id) {
  7844. var el = DOC.getElementById(id),
  7845. detachedBodyEl;
  7846. if (!el && (detachedBodyEl = AbstractElement.detachedBodyEl)) {
  7847. el = detachedBodyEl.dom.all[id];
  7848. }
  7849. return el;
  7850. };
  7851. } else if (!DOC.querySelector) {
  7852. Ext.getDetachedBody = Ext.getBody;
  7853. Ext.getElementById = function (id) {
  7854. return DOC.getElementById(id);
  7855. };
  7856. }
  7857. });
  7858. }());
  7859. /**
  7860. * @class Ext.dom.Element
  7861. */
  7862. Ext.dom.Element.override((function() {
  7863. var doc = document,
  7864. win = window,
  7865. alignRe = /^([a-z]+)-([a-z]+)(\?)?$/,
  7866. round = Math.round;
  7867. return {
  7868. /**
  7869. * Gets the x,y coordinates specified by the anchor position on the element.
  7870. * @param {String} [anchor='c'] The specified anchor position. See {@link #alignTo}
  7871. * for details on supported anchor positions.
  7872. * @param {Boolean} [local] True to get the local (element top/left-relative) anchor position instead
  7873. * of page coordinates
  7874. * @param {Object} [size] An object containing the size to use for calculating anchor position
  7875. * {width: (target width), height: (target height)} (defaults to the element's current size)
  7876. * @return {Number[]} [x, y] An array containing the element's x and y coordinates
  7877. */
  7878. getAnchorXY: function(anchor, local, mySize) {
  7879. //Passing a different size is useful for pre-calculating anchors,
  7880. //especially for anchored animations that change the el size.
  7881. anchor = (anchor || "tl").toLowerCase();
  7882. mySize = mySize || {};
  7883. var me = this,
  7884. isViewport = me.dom == doc.body || me.dom == doc,
  7885. myWidth = mySize.width || isViewport ? Ext.dom.Element.getViewWidth() : me.getWidth(),
  7886. myHeight = mySize.height || isViewport ? Ext.dom.Element.getViewHeight() : me.getHeight(),
  7887. xy,
  7888. myPos = me.getXY(),
  7889. scroll = me.getScroll(),
  7890. extraX = isViewport ? scroll.left : !local ? myPos[0] : 0,
  7891. extraY = isViewport ? scroll.top : !local ? myPos[1] : 0;
  7892. // Calculate anchor position.
  7893. // Test most common cases for picker alignment first.
  7894. switch (anchor) {
  7895. case 'tl' : xy = [ 0, 0];
  7896. break;
  7897. case 'bl' : xy = [ 0, myHeight];
  7898. break;
  7899. case 'tr' : xy = [ myWidth, 0];
  7900. break;
  7901. case 'c' : xy = [ round(myWidth * 0.5), round(myHeight * 0.5)];
  7902. break;
  7903. case 't' : xy = [ round(myWidth * 0.5), 0];
  7904. break;
  7905. case 'l' : xy = [ 0, round(myHeight * 0.5)];
  7906. break;
  7907. case 'r' : xy = [ myWidth, round(myHeight * 0.5)];
  7908. break;
  7909. case 'b' : xy = [ round(myWidth * 0.5), myHeight];
  7910. break;
  7911. case 'br' : xy = [ myWidth, myHeight];
  7912. }
  7913. return [xy[0] + extraX, xy[1] + extraY];
  7914. },
  7915. /**
  7916. * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the
  7917. * supported position values.
  7918. * @param {String/HTMLElement/Ext.Element} element The element to align to.
  7919. * @param {String} [position="tl-bl?"] The position to align to (defaults to )
  7920. * @param {Number[]} [offsets] Offset the positioning by [x, y]
  7921. * @return {Number[]} [x, y]
  7922. */
  7923. getAlignToXY : function(alignToEl, posSpec, offset) {
  7924. alignToEl = Ext.get(alignToEl);
  7925. if (!alignToEl || !alignToEl.dom) {
  7926. //<debug>
  7927. Ext.Error.raise({
  7928. sourceClass: 'Ext.dom.Element',
  7929. sourceMethod: 'getAlignToXY',
  7930. msg: 'Attempted to align an element that doesn\'t exist'
  7931. });
  7932. //</debug>
  7933. }
  7934. offset = offset || [0,0];
  7935. posSpec = (!posSpec || posSpec == "?" ? "tl-bl?" : (!(/-/).test(posSpec) && posSpec !== "" ? "tl-" + posSpec : posSpec || "tl-bl")).toLowerCase();
  7936. var me = this,
  7937. myPosition,
  7938. alignToElPosition,
  7939. x,
  7940. y,
  7941. myWidth,
  7942. myHeight,
  7943. alignToElRegion,
  7944. viewportWidth = Ext.dom.Element.getViewWidth() - 10, // 10px of margin for ie
  7945. viewportHeight = Ext.dom.Element.getViewHeight() - 10, // 10px of margin for ie
  7946. p1y,
  7947. p1x,
  7948. p2y,
  7949. p2x,
  7950. swapY,
  7951. swapX,
  7952. docElement = doc.documentElement,
  7953. docBody = doc.body,
  7954. scrollX = (docElement.scrollLeft || docBody.scrollLeft || 0),// + 5, WHY was 5 ever added?
  7955. scrollY = (docElement.scrollTop || docBody.scrollTop || 0),// + 5, It means align will fail if the alignTo el was at less than 5,5
  7956. constrain, //constrain to viewport
  7957. align1,
  7958. align2,
  7959. alignMatch = posSpec.match(alignRe);
  7960. //<debug>
  7961. if (!alignMatch) {
  7962. Ext.Error.raise({
  7963. sourceClass: 'Ext.dom.Element',
  7964. sourceMethod: 'getAlignToXY',
  7965. el: alignToEl,
  7966. position: posSpec,
  7967. offset: offset,
  7968. msg: 'Attemmpted to align an element with an invalid position: "' + posSpec + '"'
  7969. });
  7970. }
  7971. //</debug>
  7972. align1 = alignMatch[1];
  7973. align2 = alignMatch[2];
  7974. constrain = !!alignMatch[3];
  7975. //Subtract the aligned el's internal xy from the target's offset xy
  7976. //plus custom offset to get this Element's new offset xy
  7977. myPosition = me.getAnchorXY(align1, true);
  7978. alignToElPosition = alignToEl.getAnchorXY(align2, false);
  7979. x = alignToElPosition[0] - myPosition[0] + offset[0];
  7980. y = alignToElPosition[1] - myPosition[1] + offset[1];
  7981. // If position spec ended with a "?", then constrain to viewport is necessary
  7982. if (constrain) {
  7983. myWidth = me.getWidth();
  7984. myHeight = me.getHeight();
  7985. alignToElRegion = alignToEl.getRegion();
  7986. //If we are at a viewport boundary and the aligned el is anchored on a target border that is
  7987. //perpendicular to the vp border, allow the aligned el to slide on that border,
  7988. //otherwise swap the aligned el to the opposite border of the target.
  7989. p1y = align1.charAt(0);
  7990. p1x = align1.charAt(align1.length - 1);
  7991. p2y = align2.charAt(0);
  7992. p2x = align2.charAt(align2.length - 1);
  7993. swapY = ((p1y == "t" && p2y == "b") || (p1y == "b" && p2y == "t"));
  7994. swapX = ((p1x == "r" && p2x == "l") || (p1x == "l" && p2x == "r"));
  7995. if (x + myWidth > viewportWidth + scrollX) {
  7996. x = swapX ? alignToElRegion.left - myWidth : viewportWidth + scrollX - myWidth;
  7997. }
  7998. if (x < scrollX) {
  7999. x = swapX ? alignToElRegion.right : scrollX;
  8000. }
  8001. if (y + myHeight > viewportHeight + scrollY) {
  8002. y = swapY ? alignToElRegion.top - myHeight : viewportHeight + scrollY - myHeight;
  8003. }
  8004. if (y < scrollY) {
  8005. y = swapY ? alignToElRegion.bottom : scrollY;
  8006. }
  8007. }
  8008. return [x,y];
  8009. },
  8010. /**
  8011. * Anchors an element to another element and realigns it when the window is resized.
  8012. * @param {String/HTMLElement/Ext.Element} element The element to align to.
  8013. * @param {String} position The position to align to.
  8014. * @param {Number[]} [offsets] Offset the positioning by [x, y]
  8015. * @param {Boolean/Object} [animate] True for the default animation or a standard Element animation config object
  8016. * @param {Boolean/Number} [monitorScroll] True to monitor body scroll and reposition. If this parameter
  8017. * is a number, it is used as the buffer delay (defaults to 50ms).
  8018. * @param {Function} [callback] The function to call after the animation finishes
  8019. * @return {Ext.Element} this
  8020. */
  8021. anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback) {
  8022. var me = this,
  8023. dom = me.dom,
  8024. scroll = !Ext.isEmpty(monitorScroll),
  8025. action = function() {
  8026. Ext.fly(dom).alignTo(el, alignment, offsets, animate);
  8027. Ext.callback(callback, Ext.fly(dom));
  8028. },
  8029. anchor = this.getAnchor();
  8030. // previous listener anchor, remove it
  8031. this.removeAnchor();
  8032. Ext.apply(anchor, {
  8033. fn: action,
  8034. scroll: scroll
  8035. });
  8036. Ext.EventManager.onWindowResize(action, null);
  8037. if (scroll) {
  8038. Ext.EventManager.on(win, 'scroll', action, null,
  8039. {buffer: !isNaN(monitorScroll) ? monitorScroll : 50});
  8040. }
  8041. action.call(me); // align immediately
  8042. return me;
  8043. },
  8044. /**
  8045. * Remove any anchor to this element. See {@link #anchorTo}.
  8046. * @return {Ext.dom.Element} this
  8047. */
  8048. removeAnchor : function() {
  8049. var me = this,
  8050. anchor = this.getAnchor();
  8051. if (anchor && anchor.fn) {
  8052. Ext.EventManager.removeResizeListener(anchor.fn);
  8053. if (anchor.scroll) {
  8054. Ext.EventManager.un(win, 'scroll', anchor.fn);
  8055. }
  8056. delete anchor.fn;
  8057. }
  8058. return me;
  8059. },
  8060. getAlignVector: function(el, spec, offset) {
  8061. var me = this,
  8062. myPos = me.getXY(),
  8063. alignedPos = me.getAlignToXY(el, spec, offset);
  8064. el = Ext.get(el);
  8065. //<debug>
  8066. if (!el || !el.dom) {
  8067. Ext.Error.raise({
  8068. sourceClass: 'Ext.dom.Element',
  8069. sourceMethod: 'getAlignVector',
  8070. msg: 'Attempted to align an element that doesn\'t exist'
  8071. });
  8072. }
  8073. //</debug>
  8074. alignedPos[0] -= myPos[0];
  8075. alignedPos[1] -= myPos[1];
  8076. return alignedPos;
  8077. },
  8078. /**
  8079. * Aligns this element with another element relative to the specified anchor points. If the other element is the
  8080. * document it aligns it to the viewport. The position parameter is optional, and can be specified in any one of
  8081. * the following formats:
  8082. *
  8083. * - **Blank**: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").
  8084. * - **One anchor (deprecated)**: The passed anchor position is used as the target element's anchor point.
  8085. * The element being aligned will position its top-left corner (tl) to that point. *This method has been
  8086. * deprecated in favor of the newer two anchor syntax below*.
  8087. * - **Two anchors**: If two values from the table below are passed separated by a dash, the first value is used as the
  8088. * element's anchor point, and the second value is used as the target's anchor point.
  8089. *
  8090. * In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of
  8091. * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to
  8092. * the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than
  8093. * that specified in order to enforce the viewport constraints.
  8094. * Following are all of the supported anchor positions:
  8095. *
  8096. * <pre>
  8097. * Value Description
  8098. * ----- -----------------------------
  8099. * tl The top left corner (default)
  8100. * t The center of the top edge
  8101. * tr The top right corner
  8102. * l The center of the left edge
  8103. * c In the center of the element
  8104. * r The center of the right edge
  8105. * bl The bottom left corner
  8106. * b The center of the bottom edge
  8107. * br The bottom right corner
  8108. * </pre>
  8109. *
  8110. * Example Usage:
  8111. *
  8112. * // align el to other-el using the default positioning ("tl-bl", non-constrained)
  8113. * el.alignTo("other-el");
  8114. *
  8115. * // align the top left corner of el with the top right corner of other-el (constrained to viewport)
  8116. * el.alignTo("other-el", "tr?");
  8117. *
  8118. * // align the bottom right corner of el with the center left edge of other-el
  8119. * el.alignTo("other-el", "br-l?");
  8120. *
  8121. * // align the center of el with the bottom left corner of other-el and
  8122. * // adjust the x position by -6 pixels (and the y position by 0)
  8123. * el.alignTo("other-el", "c-bl", [-6, 0]);
  8124. *
  8125. * @param {String/HTMLElement/Ext.Element} element The element to align to.
  8126. * @param {String} [position="tl-bl?"] The position to align to
  8127. * @param {Number[]} [offsets] Offset the positioning by [x, y]
  8128. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  8129. * @return {Ext.Element} this
  8130. */
  8131. alignTo: function(element, position, offsets, animate) {
  8132. var me = this;
  8133. return me.setXY(me.getAlignToXY(element, position, offsets),
  8134. me.anim && !!animate ? me.anim(animate) : false);
  8135. },
  8136. /**
  8137. * Returns the `[X, Y]` vector by which this element must be translated to make a best attempt
  8138. * to constrain within the passed constraint. Returns `false` is this element does not need to be moved.
  8139. *
  8140. * Priority is given to constraining the top and left within the constraint.
  8141. *
  8142. * The constraint may either be an existing element into which this element is to be constrained, or
  8143. * an {@link Ext.util.Region Region} into which this element is to be constrained.
  8144. *
  8145. * @param {Ext.Element/Ext.util.Region} constrainTo The Element or Region into which this element is to be constrained.
  8146. * @param {Number[]} proposedPosition A proposed `[X, Y]` position to test for validity and to produce a vector for instead
  8147. * of using this Element's current position;
  8148. * @returns {Number[]/Boolean} **If** this element *needs* to be translated, an `[X, Y]`
  8149. * vector by which this element must be translated. Otherwise, `false`.
  8150. */
  8151. getConstrainVector: function(constrainTo, proposedPosition) {
  8152. if (!(constrainTo instanceof Ext.util.Region)) {
  8153. constrainTo = Ext.get(constrainTo).getViewRegion();
  8154. }
  8155. var thisRegion = this.getRegion(),
  8156. vector = [0, 0],
  8157. shadowSize = (this.shadow && !this.shadowDisabled) ? this.shadow.getShadowSize() : undefined,
  8158. overflowed = false;
  8159. // Shift this region to occupy the proposed position
  8160. if (proposedPosition) {
  8161. thisRegion.translateBy(proposedPosition[0] - thisRegion.x, proposedPosition[1] - thisRegion.y);
  8162. }
  8163. // Reduce the constrain region to allow for shadow
  8164. if (shadowSize) {
  8165. constrainTo.adjust(shadowSize[0], -shadowSize[1], -shadowSize[2], shadowSize[3]);
  8166. }
  8167. // Constrain the X coordinate by however much this Element overflows
  8168. if (thisRegion.right > constrainTo.right) {
  8169. overflowed = true;
  8170. vector[0] = (constrainTo.right - thisRegion.right); // overflowed the right
  8171. }
  8172. if (thisRegion.left + vector[0] < constrainTo.left) {
  8173. overflowed = true;
  8174. vector[0] = (constrainTo.left - thisRegion.left); // overflowed the left
  8175. }
  8176. // Constrain the Y coordinate by however much this Element overflows
  8177. if (thisRegion.bottom > constrainTo.bottom) {
  8178. overflowed = true;
  8179. vector[1] = (constrainTo.bottom - thisRegion.bottom); // overflowed the bottom
  8180. }
  8181. if (thisRegion.top + vector[1] < constrainTo.top) {
  8182. overflowed = true;
  8183. vector[1] = (constrainTo.top - thisRegion.top); // overflowed the top
  8184. }
  8185. return overflowed ? vector : false;
  8186. },
  8187. /**
  8188. * Calculates the x, y to center this element on the screen
  8189. * @return {Number[]} The x, y values [x, y]
  8190. */
  8191. getCenterXY : function(){
  8192. return this.getAlignToXY(doc, 'c-c');
  8193. },
  8194. /**
  8195. * Centers the Element in either the viewport, or another Element.
  8196. * @param {String/HTMLElement/Ext.Element} [centerIn] The element in which to center the element.
  8197. */
  8198. center : function(centerIn){
  8199. return this.alignTo(centerIn || doc, 'c-c');
  8200. }
  8201. };
  8202. }()));
  8203. /**
  8204. * @class Ext.dom.Element
  8205. */
  8206. /* ================================
  8207. * A Note About Wrapped Animations
  8208. * ================================
  8209. * A few of the effects below implement two different animations per effect, one wrapping
  8210. * animation that performs the visual effect and a "no-op" animation on this Element where
  8211. * no attributes of the element itself actually change. The purpose for this is that the
  8212. * wrapper is required for the effect to work and so it does the actual animation work, but
  8213. * we always animate `this` so that the element's events and callbacks work as expected to
  8214. * the callers of this API.
  8215. *
  8216. * Because of this, we always want each wrap animation to complete first (we don't want to
  8217. * cut off the visual effect early). To ensure that, we arbitrarily increase the duration of
  8218. * the element's no-op animation, also ensuring that it has a decent minimum value -- on slow
  8219. * systems, too-low durations can cause race conditions between the wrap animation and the
  8220. * element animation being removed out of order. Note that in each wrap's `afteranimate`
  8221. * callback it will explicitly terminate the element animation as soon as the wrap is complete,
  8222. * so there's no real danger in making the duration too long.
  8223. *
  8224. * This applies to all effects that get wrapped, including slideIn, slideOut, switchOff and frame.
  8225. */
  8226. Ext.dom.Element.override({
  8227. /**
  8228. * Performs custom animation on this Element.
  8229. *
  8230. * The following properties may be specified in `from`, `to`, and `keyframe` objects:
  8231. *
  8232. * - `x` - The page X position in pixels.
  8233. *
  8234. * - `y` - The page Y position in pixels
  8235. *
  8236. * - `left` - The element's CSS `left` value. Units must be supplied.
  8237. *
  8238. * - `top` - The element's CSS `top` value. Units must be supplied.
  8239. *
  8240. * - `width` - The element's CSS `width` value. Units must be supplied.
  8241. *
  8242. * - `height` - The element's CSS `height` value. Units must be supplied.
  8243. *
  8244. * - `scrollLeft` - The element's `scrollLeft` value.
  8245. *
  8246. * - `scrollTop` - The element's `scrollTop` value.
  8247. *
  8248. * - `opacity` - The element's `opacity` value. This must be a value between `0` and `1`.
  8249. *
  8250. * **Be aware** that animating an Element which is being used by an Ext Component without in some way informing the
  8251. * Component about the changed element state will result in incorrect Component behaviour. This is because the
  8252. * Component will be using the old state of the element. To avoid this problem, it is now possible to directly
  8253. * animate certain properties of Components.
  8254. *
  8255. * @param {Object} config Configuration for {@link Ext.fx.Anim}.
  8256. * Note that the {@link Ext.fx.Anim#to to} config is required.
  8257. * @return {Ext.dom.Element} this
  8258. */
  8259. animate: function(config) {
  8260. var me = this,
  8261. listeners,
  8262. anim,
  8263. animId = me.dom.id || Ext.id(me.dom);
  8264. if (!Ext.fx.Manager.hasFxBlock(animId)) {
  8265. // Bit of gymnastics here to ensure our internal listeners get bound first
  8266. if (config.listeners) {
  8267. listeners = config.listeners;
  8268. delete config.listeners;
  8269. }
  8270. if (config.internalListeners) {
  8271. config.listeners = config.internalListeners;
  8272. delete config.internalListeners;
  8273. }
  8274. anim = new Ext.fx.Anim(me.anim(config));
  8275. if (listeners) {
  8276. anim.on(listeners);
  8277. }
  8278. Ext.fx.Manager.queueFx(anim);
  8279. }
  8280. return me;
  8281. },
  8282. // @private - process the passed fx configuration.
  8283. anim: function(config) {
  8284. if (!Ext.isObject(config)) {
  8285. return (config) ? {} : false;
  8286. }
  8287. var me = this,
  8288. duration = config.duration || Ext.fx.Anim.prototype.duration,
  8289. easing = config.easing || 'ease',
  8290. animConfig;
  8291. if (config.stopAnimation) {
  8292. me.stopAnimation();
  8293. }
  8294. Ext.applyIf(config, Ext.fx.Manager.getFxDefaults(me.id));
  8295. // Clear any 'paused' defaults.
  8296. Ext.fx.Manager.setFxDefaults(me.id, {
  8297. delay: 0
  8298. });
  8299. animConfig = {
  8300. // Pass the DOM reference. That's tested first so will be converted to an Ext.fx.Target fastest.
  8301. target: me.dom,
  8302. remove: config.remove,
  8303. alternate: config.alternate || false,
  8304. duration: duration,
  8305. easing: easing,
  8306. callback: config.callback,
  8307. listeners: config.listeners,
  8308. iterations: config.iterations || 1,
  8309. scope: config.scope,
  8310. block: config.block,
  8311. concurrent: config.concurrent,
  8312. delay: config.delay || 0,
  8313. paused: true,
  8314. keyframes: config.keyframes,
  8315. from: config.from || {},
  8316. to: Ext.apply({}, config)
  8317. };
  8318. Ext.apply(animConfig.to, config.to);
  8319. // Anim API properties - backward compat
  8320. delete animConfig.to.to;
  8321. delete animConfig.to.from;
  8322. delete animConfig.to.remove;
  8323. delete animConfig.to.alternate;
  8324. delete animConfig.to.keyframes;
  8325. delete animConfig.to.iterations;
  8326. delete animConfig.to.listeners;
  8327. delete animConfig.to.target;
  8328. delete animConfig.to.paused;
  8329. delete animConfig.to.callback;
  8330. delete animConfig.to.scope;
  8331. delete animConfig.to.duration;
  8332. delete animConfig.to.easing;
  8333. delete animConfig.to.concurrent;
  8334. delete animConfig.to.block;
  8335. delete animConfig.to.stopAnimation;
  8336. delete animConfig.to.delay;
  8337. return animConfig;
  8338. },
  8339. /**
  8340. * Slides the element into view. An anchor point can be optionally passed to set the point of origin for the slide
  8341. * effect. This function automatically handles wrapping the element with a fixed-size container if needed. See the
  8342. * Fx class overview for valid anchor point options. Usage:
  8343. *
  8344. * // default: slide the element in from the top
  8345. * el.slideIn();
  8346. *
  8347. * // custom: slide the element in from the right with a 2-second duration
  8348. * el.slideIn('r', { duration: 2000 });
  8349. *
  8350. * // common config options shown with default values
  8351. * el.slideIn('t', {
  8352. * easing: 'easeOut',
  8353. * duration: 500
  8354. * });
  8355. *
  8356. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
  8357. * @param {Object} options (optional) Object literal with any of the Fx config options
  8358. * @param {Boolean} options.preserveScroll Set to true if preservation of any descendant elements'
  8359. * `scrollTop` values is required. By default the DOM wrapping operation performed by `slideIn` and
  8360. * `slideOut` causes the browser to lose all scroll positions.
  8361. * @return {Ext.dom.Element} The Element
  8362. */
  8363. slideIn: function(anchor, obj, slideOut) {
  8364. var me = this,
  8365. elStyle = me.dom.style,
  8366. beforeAnim,
  8367. wrapAnim,
  8368. restoreScroll,
  8369. wrapDomParentNode;
  8370. anchor = anchor || "t";
  8371. obj = obj || {};
  8372. beforeAnim = function() {
  8373. var animScope = this,
  8374. listeners = obj.listeners,
  8375. box, originalStyles, anim, wrap;
  8376. if (!slideOut) {
  8377. me.fixDisplay();
  8378. }
  8379. box = me.getBox();
  8380. if ((anchor == 't' || anchor == 'b') && box.height === 0) {
  8381. box.height = me.dom.scrollHeight;
  8382. }
  8383. else if ((anchor == 'l' || anchor == 'r') && box.width === 0) {
  8384. box.width = me.dom.scrollWidth;
  8385. }
  8386. originalStyles = me.getStyles('width', 'height', 'left', 'right', 'top', 'bottom', 'position', 'z-index', true);
  8387. me.setSize(box.width, box.height);
  8388. // Cache all descendants' scrollTop & scrollLeft values if configured to preserve scroll.
  8389. if (obj.preserveScroll) {
  8390. restoreScroll = me.cacheScrollValues();
  8391. }
  8392. wrap = me.wrap({
  8393. id: Ext.id() + '-anim-wrap-for-' + me.id,
  8394. style: {
  8395. visibility: slideOut ? 'visible' : 'hidden'
  8396. }
  8397. });
  8398. wrapDomParentNode = wrap.dom.parentNode;
  8399. wrap.setPositioning(me.getPositioning());
  8400. if (wrap.isStyle('position', 'static')) {
  8401. wrap.position('relative');
  8402. }
  8403. me.clearPositioning('auto');
  8404. wrap.clip();
  8405. // The wrap will have reset all descendant scrollTops. Restore them if we cached them.
  8406. if (restoreScroll) {
  8407. restoreScroll();
  8408. }
  8409. // This element is temporarily positioned absolute within its wrapper.
  8410. // Restore to its default, CSS-inherited visibility setting.
  8411. // We cannot explicitly poke visibility:visible into its style because that overrides the visibility of the wrap.
  8412. me.setStyle({
  8413. visibility: '',
  8414. position: 'absolute'
  8415. });
  8416. if (slideOut) {
  8417. wrap.setSize(box.width, box.height);
  8418. }
  8419. switch (anchor) {
  8420. case 't':
  8421. anim = {
  8422. from: {
  8423. width: box.width + 'px',
  8424. height: '0px'
  8425. },
  8426. to: {
  8427. width: box.width + 'px',
  8428. height: box.height + 'px'
  8429. }
  8430. };
  8431. elStyle.bottom = '0px';
  8432. break;
  8433. case 'l':
  8434. anim = {
  8435. from: {
  8436. width: '0px',
  8437. height: box.height + 'px'
  8438. },
  8439. to: {
  8440. width: box.width + 'px',
  8441. height: box.height + 'px'
  8442. }
  8443. };
  8444. elStyle.right = '0px';
  8445. break;
  8446. case 'r':
  8447. anim = {
  8448. from: {
  8449. x: box.x + box.width,
  8450. width: '0px',
  8451. height: box.height + 'px'
  8452. },
  8453. to: {
  8454. x: box.x,
  8455. width: box.width + 'px',
  8456. height: box.height + 'px'
  8457. }
  8458. };
  8459. break;
  8460. case 'b':
  8461. anim = {
  8462. from: {
  8463. y: box.y + box.height,
  8464. width: box.width + 'px',
  8465. height: '0px'
  8466. },
  8467. to: {
  8468. y: box.y,
  8469. width: box.width + 'px',
  8470. height: box.height + 'px'
  8471. }
  8472. };
  8473. break;
  8474. case 'tl':
  8475. anim = {
  8476. from: {
  8477. x: box.x,
  8478. y: box.y,
  8479. width: '0px',
  8480. height: '0px'
  8481. },
  8482. to: {
  8483. width: box.width + 'px',
  8484. height: box.height + 'px'
  8485. }
  8486. };
  8487. elStyle.bottom = '0px';
  8488. elStyle.right = '0px';
  8489. break;
  8490. case 'bl':
  8491. anim = {
  8492. from: {
  8493. y: box.y + box.height,
  8494. width: '0px',
  8495. height: '0px'
  8496. },
  8497. to: {
  8498. y: box.y,
  8499. width: box.width + 'px',
  8500. height: box.height + 'px'
  8501. }
  8502. };
  8503. elStyle.bottom = '0px';
  8504. break;
  8505. case 'br':
  8506. anim = {
  8507. from: {
  8508. x: box.x + box.width,
  8509. y: box.y + box.height,
  8510. width: '0px',
  8511. height: '0px'
  8512. },
  8513. to: {
  8514. x: box.x,
  8515. y: box.y,
  8516. width: box.width + 'px',
  8517. height: box.height + 'px'
  8518. }
  8519. };
  8520. break;
  8521. case 'tr':
  8522. anim = {
  8523. from: {
  8524. x: box.x + box.width,
  8525. width: '0px',
  8526. height: '0px'
  8527. },
  8528. to: {
  8529. x: box.x,
  8530. width: box.width + 'px',
  8531. height: box.height + 'px'
  8532. }
  8533. };
  8534. elStyle.right = '0px';
  8535. break;
  8536. }
  8537. wrap.show();
  8538. wrapAnim = Ext.apply({}, obj);
  8539. delete wrapAnim.listeners;
  8540. wrapAnim = new Ext.fx.Anim(Ext.applyIf(wrapAnim, {
  8541. target: wrap,
  8542. duration: 500,
  8543. easing: 'ease-out',
  8544. from: slideOut ? anim.to : anim.from,
  8545. to: slideOut ? anim.from : anim.to
  8546. }));
  8547. // In the absence of a callback, this listener MUST be added first
  8548. wrapAnim.on('afteranimate', function() {
  8549. me.setStyle(originalStyles);
  8550. if (slideOut) {
  8551. if (obj.useDisplay) {
  8552. me.setDisplayed(false);
  8553. } else {
  8554. me.hide();
  8555. }
  8556. }
  8557. if (wrap.dom) {
  8558. if (wrap.dom.parentNode) {
  8559. wrap.dom.parentNode.insertBefore(me.dom, wrap.dom);
  8560. } else {
  8561. wrapDomParentNode.appendChild(me.dom);
  8562. }
  8563. wrap.remove();
  8564. }
  8565. // The unwrap will have reset all descendant scrollTops. Restore them if we cached them.
  8566. if (restoreScroll) {
  8567. restoreScroll();
  8568. }
  8569. // kill the no-op element animation created below
  8570. animScope.end();
  8571. });
  8572. // Add configured listeners after
  8573. if (listeners) {
  8574. wrapAnim.on(listeners);
  8575. }
  8576. };
  8577. me.animate({
  8578. // See "A Note About Wrapped Animations" at the top of this class:
  8579. duration: obj.duration ? Math.max(obj.duration, 500) * 2 : 1000,
  8580. listeners: {
  8581. beforeanimate: beforeAnim // kick off the wrap animation
  8582. }
  8583. });
  8584. return me;
  8585. },
  8586. /**
  8587. * Slides the element out of view. An anchor point can be optionally passed to set the end point for the slide
  8588. * effect. When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will
  8589. * still take up space in the document. The element must be removed from the DOM using the 'remove' config option if
  8590. * desired. This function automatically handles wrapping the element with a fixed-size container if needed. See the
  8591. * Fx class overview for valid anchor point options. Usage:
  8592. *
  8593. * // default: slide the element out to the top
  8594. * el.slideOut();
  8595. *
  8596. * // custom: slide the element out to the right with a 2-second duration
  8597. * el.slideOut('r', { duration: 2000 });
  8598. *
  8599. * // common config options shown with default values
  8600. * el.slideOut('t', {
  8601. * easing: 'easeOut',
  8602. * duration: 500,
  8603. * remove: false,
  8604. * useDisplay: false
  8605. * });
  8606. *
  8607. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
  8608. * @param {Object} options (optional) Object literal with any of the Fx config options
  8609. * @return {Ext.dom.Element} The Element
  8610. */
  8611. slideOut: function(anchor, o) {
  8612. return this.slideIn(anchor, o, true);
  8613. },
  8614. /**
  8615. * Fades the element out while slowly expanding it in all directions. When the effect is completed, the element will
  8616. * be hidden (visibility = 'hidden') but block elements will still take up space in the document. Usage:
  8617. *
  8618. * // default
  8619. * el.puff();
  8620. *
  8621. * // common config options shown with default values
  8622. * el.puff({
  8623. * easing: 'easeOut',
  8624. * duration: 500,
  8625. * useDisplay: false
  8626. * });
  8627. *
  8628. * @param {Object} options (optional) Object literal with any of the Fx config options
  8629. * @return {Ext.dom.Element} The Element
  8630. */
  8631. puff: function(obj) {
  8632. var me = this,
  8633. beforeAnim,
  8634. box = me.getBox(),
  8635. originalStyles = me.getStyles('width', 'height', 'left', 'right', 'top', 'bottom', 'position', 'z-index', 'font-size', 'opacity', true);
  8636. obj = Ext.applyIf(obj || {}, {
  8637. easing: 'ease-out',
  8638. duration: 500,
  8639. useDisplay: false
  8640. });
  8641. beforeAnim = function() {
  8642. me.clearOpacity();
  8643. me.show();
  8644. this.to = {
  8645. width: box.width * 2,
  8646. height: box.height * 2,
  8647. x: box.x - (box.width / 2),
  8648. y: box.y - (box.height /2),
  8649. opacity: 0,
  8650. fontSize: '200%'
  8651. };
  8652. this.on('afteranimate',function() {
  8653. if (me.dom) {
  8654. if (obj.useDisplay) {
  8655. me.setDisplayed(false);
  8656. } else {
  8657. me.hide();
  8658. }
  8659. me.setStyle(originalStyles);
  8660. obj.callback.call(obj.scope);
  8661. }
  8662. });
  8663. };
  8664. me.animate({
  8665. duration: obj.duration,
  8666. easing: obj.easing,
  8667. listeners: {
  8668. beforeanimate: {
  8669. fn: beforeAnim
  8670. }
  8671. }
  8672. });
  8673. return me;
  8674. },
  8675. /**
  8676. * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).
  8677. * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still
  8678. * take up space in the document. The element must be removed from the DOM using the 'remove' config option if
  8679. * desired. Usage:
  8680. *
  8681. * // default
  8682. * el.switchOff();
  8683. *
  8684. * // all config options shown with default values
  8685. * el.switchOff({
  8686. * easing: 'easeIn',
  8687. * duration: .3,
  8688. * remove: false,
  8689. * useDisplay: false
  8690. * });
  8691. *
  8692. * @param {Object} options (optional) Object literal with any of the Fx config options
  8693. * @return {Ext.dom.Element} The Element
  8694. */
  8695. switchOff: function(obj) {
  8696. var me = this,
  8697. beforeAnim;
  8698. obj = Ext.applyIf(obj || {}, {
  8699. easing: 'ease-in',
  8700. duration: 500,
  8701. remove: false,
  8702. useDisplay: false
  8703. });
  8704. beforeAnim = function() {
  8705. var animScope = this,
  8706. size = me.getSize(),
  8707. xy = me.getXY(),
  8708. keyframe, position;
  8709. me.clearOpacity();
  8710. me.clip();
  8711. position = me.getPositioning();
  8712. keyframe = new Ext.fx.Animator({
  8713. target: me,
  8714. duration: obj.duration,
  8715. easing: obj.easing,
  8716. keyframes: {
  8717. 33: {
  8718. opacity: 0.3
  8719. },
  8720. 66: {
  8721. height: 1,
  8722. y: xy[1] + size.height / 2
  8723. },
  8724. 100: {
  8725. width: 1,
  8726. x: xy[0] + size.width / 2
  8727. }
  8728. }
  8729. });
  8730. keyframe.on('afteranimate', function() {
  8731. if (obj.useDisplay) {
  8732. me.setDisplayed(false);
  8733. } else {
  8734. me.hide();
  8735. }
  8736. me.clearOpacity();
  8737. me.setPositioning(position);
  8738. me.setSize(size);
  8739. // kill the no-op element animation created below
  8740. animScope.end();
  8741. });
  8742. };
  8743. me.animate({
  8744. // See "A Note About Wrapped Animations" at the top of this class:
  8745. duration: (Math.max(obj.duration, 500) * 2),
  8746. listeners: {
  8747. beforeanimate: {
  8748. fn: beforeAnim
  8749. }
  8750. }
  8751. });
  8752. return me;
  8753. },
  8754. /**
  8755. * Shows a ripple of exploding, attenuating borders to draw attention to an Element. Usage:
  8756. *
  8757. * // default: a single light blue ripple
  8758. * el.frame();
  8759. *
  8760. * // custom: 3 red ripples lasting 3 seconds total
  8761. * el.frame("#ff0000", 3, { duration: 3000 });
  8762. *
  8763. * // common config options shown with default values
  8764. * el.frame("#C3DAF9", 1, {
  8765. * duration: 1000 // duration of each individual ripple.
  8766. * // Note: Easing is not configurable and will be ignored if included
  8767. * });
  8768. *
  8769. * @param {String} [color='#C3DAF9'] The hex color value for the border.
  8770. * @param {Number} [count=1] The number of ripples to display.
  8771. * @param {Object} [options] Object literal with any of the Fx config options
  8772. * @return {Ext.dom.Element} The Element
  8773. */
  8774. frame : function(color, count, obj){
  8775. var me = this,
  8776. beforeAnim;
  8777. color = color || '#C3DAF9';
  8778. count = count || 1;
  8779. obj = obj || {};
  8780. beforeAnim = function() {
  8781. me.show();
  8782. var animScope = this,
  8783. box = me.getBox(),
  8784. proxy = Ext.getBody().createChild({
  8785. id: me.id + '-anim-proxy',
  8786. style: {
  8787. position : 'absolute',
  8788. 'pointer-events': 'none',
  8789. 'z-index': 35000,
  8790. border : '0px solid ' + color
  8791. }
  8792. }),
  8793. proxyAnim;
  8794. proxyAnim = new Ext.fx.Anim({
  8795. target: proxy,
  8796. duration: obj.duration || 1000,
  8797. iterations: count,
  8798. from: {
  8799. top: box.y,
  8800. left: box.x,
  8801. borderWidth: 0,
  8802. opacity: 1,
  8803. height: box.height,
  8804. width: box.width
  8805. },
  8806. to: {
  8807. top: box.y - 20,
  8808. left: box.x - 20,
  8809. borderWidth: 10,
  8810. opacity: 0,
  8811. height: box.height + 40,
  8812. width: box.width + 40
  8813. }
  8814. });
  8815. proxyAnim.on('afteranimate', function() {
  8816. proxy.remove();
  8817. // kill the no-op element animation created below
  8818. animScope.end();
  8819. });
  8820. };
  8821. me.animate({
  8822. // See "A Note About Wrapped Animations" at the top of this class:
  8823. duration: (Math.max(obj.duration, 500) * 2) || 2000,
  8824. listeners: {
  8825. beforeanimate: {
  8826. fn: beforeAnim
  8827. }
  8828. }
  8829. });
  8830. return me;
  8831. },
  8832. /**
  8833. * Slides the element while fading it out of view. An anchor point can be optionally passed to set the ending point
  8834. * of the effect. Usage:
  8835. *
  8836. * // default: slide the element downward while fading out
  8837. * el.ghost();
  8838. *
  8839. * // custom: slide the element out to the right with a 2-second duration
  8840. * el.ghost('r', { duration: 2000 });
  8841. *
  8842. * // common config options shown with default values
  8843. * el.ghost('b', {
  8844. * easing: 'easeOut',
  8845. * duration: 500
  8846. * });
  8847. *
  8848. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b')
  8849. * @param {Object} options (optional) Object literal with any of the Fx config options
  8850. * @return {Ext.dom.Element} The Element
  8851. */
  8852. ghost: function(anchor, obj) {
  8853. var me = this,
  8854. beforeAnim;
  8855. anchor = anchor || "b";
  8856. beforeAnim = function() {
  8857. var width = me.getWidth(),
  8858. height = me.getHeight(),
  8859. xy = me.getXY(),
  8860. position = me.getPositioning(),
  8861. to = {
  8862. opacity: 0
  8863. };
  8864. switch (anchor) {
  8865. case 't':
  8866. to.y = xy[1] - height;
  8867. break;
  8868. case 'l':
  8869. to.x = xy[0] - width;
  8870. break;
  8871. case 'r':
  8872. to.x = xy[0] + width;
  8873. break;
  8874. case 'b':
  8875. to.y = xy[1] + height;
  8876. break;
  8877. case 'tl':
  8878. to.x = xy[0] - width;
  8879. to.y = xy[1] - height;
  8880. break;
  8881. case 'bl':
  8882. to.x = xy[0] - width;
  8883. to.y = xy[1] + height;
  8884. break;
  8885. case 'br':
  8886. to.x = xy[0] + width;
  8887. to.y = xy[1] + height;
  8888. break;
  8889. case 'tr':
  8890. to.x = xy[0] + width;
  8891. to.y = xy[1] - height;
  8892. break;
  8893. }
  8894. this.to = to;
  8895. this.on('afteranimate', function () {
  8896. if (me.dom) {
  8897. me.hide();
  8898. me.clearOpacity();
  8899. me.setPositioning(position);
  8900. }
  8901. });
  8902. };
  8903. me.animate(Ext.applyIf(obj || {}, {
  8904. duration: 500,
  8905. easing: 'ease-out',
  8906. listeners: {
  8907. beforeanimate: {
  8908. fn: beforeAnim
  8909. }
  8910. }
  8911. }));
  8912. return me;
  8913. },
  8914. /**
  8915. * Highlights the Element by setting a color (applies to the background-color by default, but can be changed using
  8916. * the "attr" config option) and then fading back to the original color. If no original color is available, you
  8917. * should provide the "endColor" config option which will be cleared after the animation. Usage:
  8918. *
  8919. * // default: highlight background to yellow
  8920. * el.highlight();
  8921. *
  8922. * // custom: highlight foreground text to blue for 2 seconds
  8923. * el.highlight("0000ff", { attr: 'color', duration: 2000 });
  8924. *
  8925. * // common config options shown with default values
  8926. * el.highlight("ffff9c", {
  8927. * attr: "backgroundColor", //can be any valid CSS property (attribute) that supports a color value
  8928. * endColor: (current color) or "ffffff",
  8929. * easing: 'easeIn',
  8930. * duration: 1000
  8931. * });
  8932. *
  8933. * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading #
  8934. * (defaults to yellow: 'ffff9c')
  8935. * @param {Object} options (optional) Object literal with any of the Fx config options
  8936. * @return {Ext.dom.Element} The Element
  8937. */
  8938. highlight: function(color, o) {
  8939. var me = this,
  8940. dom = me.dom,
  8941. from = {},
  8942. restore, to, attr, lns, event, fn;
  8943. o = o || {};
  8944. lns = o.listeners || {};
  8945. attr = o.attr || 'backgroundColor';
  8946. from[attr] = color || 'ffff9c';
  8947. if (!o.to) {
  8948. to = {};
  8949. to[attr] = o.endColor || me.getColor(attr, 'ffffff', '');
  8950. }
  8951. else {
  8952. to = o.to;
  8953. }
  8954. // Don't apply directly on lns, since we reference it in our own callbacks below
  8955. o.listeners = Ext.apply(Ext.apply({}, lns), {
  8956. beforeanimate: function() {
  8957. restore = dom.style[attr];
  8958. me.clearOpacity();
  8959. me.show();
  8960. event = lns.beforeanimate;
  8961. if (event) {
  8962. fn = event.fn || event;
  8963. return fn.apply(event.scope || lns.scope || window, arguments);
  8964. }
  8965. },
  8966. afteranimate: function() {
  8967. if (dom) {
  8968. dom.style[attr] = restore;
  8969. }
  8970. event = lns.afteranimate;
  8971. if (event) {
  8972. fn = event.fn || event;
  8973. fn.apply(event.scope || lns.scope || window, arguments);
  8974. }
  8975. }
  8976. });
  8977. me.animate(Ext.apply({}, o, {
  8978. duration: 1000,
  8979. easing: 'ease-in',
  8980. from: from,
  8981. to: to
  8982. }));
  8983. return me;
  8984. },
  8985. /**
  8986. * Creates a pause before any subsequent queued effects begin. If there are no effects queued after the pause it will
  8987. * have no effect. Usage:
  8988. *
  8989. * el.pause(1);
  8990. *
  8991. * @deprecated 4.0 Use the `delay` config to {@link #animate} instead.
  8992. * @param {Number} seconds The length of time to pause (in seconds)
  8993. * @return {Ext.Element} The Element
  8994. */
  8995. pause: function(ms) {
  8996. var me = this;
  8997. Ext.fx.Manager.setFxDefaults(me.id, {
  8998. delay: ms
  8999. });
  9000. return me;
  9001. },
  9002. /**
  9003. * Fade an element in (from transparent to opaque). The ending opacity can be specified using the `opacity`
  9004. * config option. Usage:
  9005. *
  9006. * // default: fade in from opacity 0 to 100%
  9007. * el.fadeIn();
  9008. *
  9009. * // custom: fade in from opacity 0 to 75% over 2 seconds
  9010. * el.fadeIn({ opacity: .75, duration: 2000});
  9011. *
  9012. * // common config options shown with default values
  9013. * el.fadeIn({
  9014. * opacity: 1, //can be any value between 0 and 1 (e.g. .5)
  9015. * easing: 'easeOut',
  9016. * duration: 500
  9017. * });
  9018. *
  9019. * @param {Object} options (optional) Object literal with any of the Fx config options
  9020. * @return {Ext.Element} The Element
  9021. */
  9022. fadeIn: function(o) {
  9023. var me = this;
  9024. me.animate(Ext.apply({}, o, {
  9025. opacity: 1,
  9026. internalListeners: {
  9027. beforeanimate: function(anim){
  9028. // restore any visibility/display that may have
  9029. // been applied by a fadeout animation
  9030. if (me.isStyle('display', 'none')) {
  9031. me.setDisplayed('');
  9032. } else {
  9033. me.show();
  9034. }
  9035. }
  9036. }
  9037. }));
  9038. return this;
  9039. },
  9040. /**
  9041. * Fade an element out (from opaque to transparent). The ending opacity can be specified using the `opacity`
  9042. * config option. Note that IE may require `useDisplay:true` in order to redisplay correctly.
  9043. * Usage:
  9044. *
  9045. * // default: fade out from the element's current opacity to 0
  9046. * el.fadeOut();
  9047. *
  9048. * // custom: fade out from the element's current opacity to 25% over 2 seconds
  9049. * el.fadeOut({ opacity: .25, duration: 2000});
  9050. *
  9051. * // common config options shown with default values
  9052. * el.fadeOut({
  9053. * opacity: 0, //can be any value between 0 and 1 (e.g. .5)
  9054. * easing: 'easeOut',
  9055. * duration: 500,
  9056. * remove: false,
  9057. * useDisplay: false
  9058. * });
  9059. *
  9060. * @param {Object} options (optional) Object literal with any of the Fx config options
  9061. * @return {Ext.Element} The Element
  9062. */
  9063. fadeOut: function(o) {
  9064. var me = this;
  9065. o = Ext.apply({
  9066. opacity: 0,
  9067. internalListeners: {
  9068. afteranimate: function(anim){
  9069. var dom = me.dom;
  9070. if (dom && anim.to.opacity === 0) {
  9071. if (o.useDisplay) {
  9072. me.setDisplayed(false);
  9073. } else {
  9074. me.hide();
  9075. }
  9076. }
  9077. }
  9078. }
  9079. }, o);
  9080. me.animate(o);
  9081. return me;
  9082. },
  9083. /**
  9084. * Animates the transition of an element's dimensions from a starting height/width to an ending height/width. This
  9085. * method is a convenience implementation of {@link #shift}. Usage:
  9086. *
  9087. * // change height and width to 100x100 pixels
  9088. * el.scale(100, 100);
  9089. *
  9090. * // common config options shown with default values. The height and width will default to
  9091. * // the element's existing values if passed as null.
  9092. * el.scale(
  9093. * [element's width],
  9094. * [element's height], {
  9095. * easing: 'easeOut',
  9096. * duration: 350
  9097. * }
  9098. * );
  9099. *
  9100. * @deprecated 4.0 Just use {@link #animate} instead.
  9101. * @param {Number} width The new width (pass undefined to keep the original width)
  9102. * @param {Number} height The new height (pass undefined to keep the original height)
  9103. * @param {Object} options (optional) Object literal with any of the Fx config options
  9104. * @return {Ext.Element} The Element
  9105. */
  9106. scale: function(w, h, o) {
  9107. this.animate(Ext.apply({}, o, {
  9108. width: w,
  9109. height: h
  9110. }));
  9111. return this;
  9112. },
  9113. /**
  9114. * Animates the transition of any combination of an element's dimensions, xy position and/or opacity. Any of these
  9115. * properties not specified in the config object will not be changed. This effect requires that at least one new
  9116. * dimension, position or opacity setting must be passed in on the config object in order for the function to have
  9117. * any effect. Usage:
  9118. *
  9119. * // slide the element horizontally to x position 200 while changing the height and opacity
  9120. * el.shift({ x: 200, height: 50, opacity: .8 });
  9121. *
  9122. * // common config options shown with default values.
  9123. * el.shift({
  9124. * width: [element's width],
  9125. * height: [element's height],
  9126. * x: [element's x position],
  9127. * y: [element's y position],
  9128. * opacity: [element's opacity],
  9129. * easing: 'easeOut',
  9130. * duration: 350
  9131. * });
  9132. *
  9133. * @deprecated 4.0 Just use {@link #animate} instead.
  9134. * @param {Object} options Object literal with any of the Fx config options
  9135. * @return {Ext.Element} The Element
  9136. */
  9137. shift: function(config) {
  9138. this.animate(config);
  9139. return this;
  9140. }
  9141. });
  9142. /**
  9143. * @class Ext.dom.Element
  9144. */
  9145. Ext.dom.Element.override({
  9146. /**
  9147. * Initializes a {@link Ext.dd.DD} drag drop object for this element.
  9148. * @param {String} group The group the DD object is member of
  9149. * @param {Object} config The DD config object
  9150. * @param {Object} overrides An object containing methods to override/implement on the DD object
  9151. * @return {Ext.dd.DD} The DD object
  9152. */
  9153. initDD : function(group, config, overrides){
  9154. var dd = new Ext.dd.DD(Ext.id(this.dom), group, config);
  9155. return Ext.apply(dd, overrides);
  9156. },
  9157. /**
  9158. * Initializes a {@link Ext.dd.DDProxy} object for this element.
  9159. * @param {String} group The group the DDProxy object is member of
  9160. * @param {Object} config The DDProxy config object
  9161. * @param {Object} overrides An object containing methods to override/implement on the DDProxy object
  9162. * @return {Ext.dd.DDProxy} The DDProxy object
  9163. */
  9164. initDDProxy : function(group, config, overrides){
  9165. var dd = new Ext.dd.DDProxy(Ext.id(this.dom), group, config);
  9166. return Ext.apply(dd, overrides);
  9167. },
  9168. /**
  9169. * Initializes a {@link Ext.dd.DDTarget} object for this element.
  9170. * @param {String} group The group the DDTarget object is member of
  9171. * @param {Object} config The DDTarget config object
  9172. * @param {Object} overrides An object containing methods to override/implement on the DDTarget object
  9173. * @return {Ext.dd.DDTarget} The DDTarget object
  9174. */
  9175. initDDTarget : function(group, config, overrides){
  9176. var dd = new Ext.dd.DDTarget(Ext.id(this.dom), group, config);
  9177. return Ext.apply(dd, overrides);
  9178. }
  9179. });
  9180. /**
  9181. * @class Ext.dom.Element
  9182. */
  9183. (function() {
  9184. var Element = Ext.dom.Element,
  9185. VISIBILITY = "visibility",
  9186. DISPLAY = "display",
  9187. NONE = "none",
  9188. HIDDEN = 'hidden',
  9189. VISIBLE = 'visible',
  9190. OFFSETS = "offsets",
  9191. ASCLASS = "asclass",
  9192. NOSIZE = 'nosize',
  9193. ORIGINALDISPLAY = 'originalDisplay',
  9194. VISMODE = 'visibilityMode',
  9195. ISVISIBLE = 'isVisible',
  9196. OFFSETCLASS = Ext.baseCSSPrefix + 'hide-offsets',
  9197. getDisplay = function(el) {
  9198. var data = (el.$cache || el.getCache()).data,
  9199. display = data[ORIGINALDISPLAY];
  9200. if (display === undefined) {
  9201. data[ORIGINALDISPLAY] = display = '';
  9202. }
  9203. return display;
  9204. },
  9205. getVisMode = function(el){
  9206. var data = (el.$cache || el.getCache()).data,
  9207. visMode = data[VISMODE];
  9208. if (visMode === undefined) {
  9209. data[VISMODE] = visMode = Element.VISIBILITY;
  9210. }
  9211. return visMode;
  9212. };
  9213. Element.override({
  9214. /**
  9215. * The element's default display mode.
  9216. */
  9217. originalDisplay : "",
  9218. visibilityMode : 1,
  9219. /**
  9220. * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
  9221. * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
  9222. * @param {Boolean} visible Whether the element is visible
  9223. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element animation config object
  9224. * @return {Ext.dom.Element} this
  9225. */
  9226. setVisible : function(visible, animate) {
  9227. var me = this,
  9228. dom = me.dom,
  9229. visMode = getVisMode(me);
  9230. // hideMode string override
  9231. if (typeof animate == 'string') {
  9232. switch (animate) {
  9233. case DISPLAY:
  9234. visMode = Element.DISPLAY;
  9235. break;
  9236. case VISIBILITY:
  9237. visMode = Element.VISIBILITY;
  9238. break;
  9239. case OFFSETS:
  9240. visMode = Element.OFFSETS;
  9241. break;
  9242. case NOSIZE:
  9243. case ASCLASS:
  9244. visMode = Element.ASCLASS;
  9245. break;
  9246. }
  9247. me.setVisibilityMode(visMode);
  9248. animate = false;
  9249. }
  9250. if (!animate || !me.anim) {
  9251. if (visMode == Element.DISPLAY) {
  9252. return me.setDisplayed(visible);
  9253. } else if (visMode == Element.OFFSETS) {
  9254. me[visible?'removeCls':'addCls'](OFFSETCLASS);
  9255. } else if (visMode == Element.VISIBILITY) {
  9256. me.fixDisplay();
  9257. // Show by clearing visibility style. Explicitly setting to "visible" overrides parent visibility setting
  9258. dom.style.visibility = visible ? '' : HIDDEN;
  9259. } else if (visMode == Element.ASCLASS) {
  9260. me[visible?'removeCls':'addCls'](me.visibilityCls || Element.visibilityCls);
  9261. }
  9262. } else {
  9263. // closure for composites
  9264. if (visible) {
  9265. me.setOpacity(0.01);
  9266. me.setVisible(true);
  9267. }
  9268. if (!Ext.isObject(animate)) {
  9269. animate = {
  9270. duration: 350,
  9271. easing: 'ease-in'
  9272. };
  9273. }
  9274. me.animate(Ext.applyIf({
  9275. callback: function() {
  9276. if (!visible) {
  9277. me.setVisible(false).setOpacity(1);
  9278. }
  9279. },
  9280. to: {
  9281. opacity: (visible) ? 1 : 0
  9282. }
  9283. }, animate));
  9284. }
  9285. (me.$cache || me.getCache()).data[ISVISIBLE] = visible;
  9286. return me;
  9287. },
  9288. /**
  9289. * @private
  9290. * Determine if the Element has a relevant height and width available based
  9291. * upon current logical visibility state
  9292. */
  9293. hasMetrics : function(){
  9294. var visMode = getVisMode(this);
  9295. return this.isVisible() || (visMode == Element.OFFSETS) || (visMode == Element.VISIBILITY);
  9296. },
  9297. /**
  9298. * Toggles the element's visibility or display, depending on visibility mode.
  9299. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element animation config object
  9300. * @return {Ext.dom.Element} this
  9301. */
  9302. toggle : function(animate){
  9303. var me = this;
  9304. me.setVisible(!me.isVisible(), me.anim(animate));
  9305. return me;
  9306. },
  9307. /**
  9308. * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
  9309. * @param {Boolean/String} value Boolean value to display the element using its default display, or a string to set the display directly.
  9310. * @return {Ext.dom.Element} this
  9311. */
  9312. setDisplayed : function(value) {
  9313. if(typeof value == "boolean"){
  9314. value = value ? getDisplay(this) : NONE;
  9315. }
  9316. this.setStyle(DISPLAY, value);
  9317. return this;
  9318. },
  9319. // private
  9320. fixDisplay : function(){
  9321. var me = this;
  9322. if (me.isStyle(DISPLAY, NONE)) {
  9323. me.setStyle(VISIBILITY, HIDDEN);
  9324. me.setStyle(DISPLAY, getDisplay(me)); // first try reverting to default
  9325. if (me.isStyle(DISPLAY, NONE)) { // if that fails, default to block
  9326. me.setStyle(DISPLAY, "block");
  9327. }
  9328. }
  9329. },
  9330. /**
  9331. * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
  9332. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  9333. * @return {Ext.dom.Element} this
  9334. */
  9335. hide : function(animate){
  9336. // hideMode override
  9337. if (typeof animate == 'string'){
  9338. this.setVisible(false, animate);
  9339. return this;
  9340. }
  9341. this.setVisible(false, this.anim(animate));
  9342. return this;
  9343. },
  9344. /**
  9345. * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
  9346. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  9347. * @return {Ext.dom.Element} this
  9348. */
  9349. show : function(animate){
  9350. // hideMode override
  9351. if (typeof animate == 'string'){
  9352. this.setVisible(true, animate);
  9353. return this;
  9354. }
  9355. this.setVisible(true, this.anim(animate));
  9356. return this;
  9357. }
  9358. });
  9359. }());
  9360. /**
  9361. * @class Ext.dom.Element
  9362. */
  9363. (function() {
  9364. var Element = Ext.dom.Element,
  9365. LEFT = "left",
  9366. RIGHT = "right",
  9367. TOP = "top",
  9368. BOTTOM = "bottom",
  9369. POSITION = "position",
  9370. STATIC = "static",
  9371. RELATIVE = "relative",
  9372. AUTO = "auto",
  9373. ZINDEX = "z-index",
  9374. BODY = 'BODY',
  9375. PADDING = 'padding',
  9376. BORDER = 'border',
  9377. SLEFT = '-left',
  9378. SRIGHT = '-right',
  9379. STOP = '-top',
  9380. SBOTTOM = '-bottom',
  9381. SWIDTH = '-width',
  9382. // special markup used throughout Ext when box wrapping elements
  9383. borders = {l: BORDER + SLEFT + SWIDTH, r: BORDER + SRIGHT + SWIDTH, t: BORDER + STOP + SWIDTH, b: BORDER + SBOTTOM + SWIDTH},
  9384. paddings = {l: PADDING + SLEFT, r: PADDING + SRIGHT, t: PADDING + STOP, b: PADDING + SBOTTOM},
  9385. paddingsTLRB = [paddings.l, paddings.r, paddings.t, paddings.b],
  9386. bordersTLRB = [borders.l, borders.r, borders.t, borders.b],
  9387. positionTopLeft = ['position', 'top', 'left'];
  9388. Element.override({
  9389. getX: function() {
  9390. return Element.getX(this.dom);
  9391. },
  9392. getY: function() {
  9393. return Element.getY(this.dom);
  9394. },
  9395. /**
  9396. * Gets the current position of the element based on page coordinates.
  9397. * Element must be part of the DOM tree to have page coordinates
  9398. * (display:none or elements not appended return false).
  9399. * @return {Number[]} The XY position of the element
  9400. */
  9401. getXY: function() {
  9402. return Element.getXY(this.dom);
  9403. },
  9404. /**
  9405. * Returns the offsets of this element from the passed element. Both element must be part
  9406. * of the DOM tree and not have display:none to have page coordinates.
  9407. * @param {String/HTMLElement/Ext.Element} element The element to get the offsets from.
  9408. * @return {Number[]} The XY page offsets (e.g. `[100, -200]`)
  9409. */
  9410. getOffsetsTo : function(el){
  9411. var o = this.getXY(),
  9412. e = Ext.fly(el, '_internal').getXY();
  9413. return [o[0] - e[0],o[1] - e[1]];
  9414. },
  9415. setX: function(x, animate) {
  9416. return this.setXY([x, this.getY()], animate);
  9417. },
  9418. setY: function(y, animate) {
  9419. return this.setXY([this.getX(), y], animate);
  9420. },
  9421. setLeft: function(left) {
  9422. this.setStyle(LEFT, this.addUnits(left));
  9423. return this;
  9424. },
  9425. setTop: function(top) {
  9426. this.setStyle(TOP, this.addUnits(top));
  9427. return this;
  9428. },
  9429. setRight: function(right) {
  9430. this.setStyle(RIGHT, this.addUnits(right));
  9431. return this;
  9432. },
  9433. setBottom: function(bottom) {
  9434. this.setStyle(BOTTOM, this.addUnits(bottom));
  9435. return this;
  9436. },
  9437. /**
  9438. * Sets the position of the element in page coordinates, regardless of how the element
  9439. * is positioned. The element must be part of the DOM tree to have page coordinates
  9440. * (`display:none` or elements not appended return false).
  9441. * @param {Number[]} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
  9442. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element
  9443. * animation config object
  9444. * @return {Ext.Element} this
  9445. */
  9446. setXY: function(pos, animate) {
  9447. var me = this;
  9448. if (!animate || !me.anim) {
  9449. Element.setXY(me.dom, pos);
  9450. }
  9451. else {
  9452. if (!Ext.isObject(animate)) {
  9453. animate = {};
  9454. }
  9455. me.animate(Ext.applyIf({ to: { x: pos[0], y: pos[1] } }, animate));
  9456. }
  9457. return me;
  9458. },
  9459. pxRe: /^\d+(?:\.\d*)?px$/i,
  9460. /**
  9461. * Returns the x-coordinate of this element reletive to its `offsetParent`.
  9462. * @return {Number} The local x-coordinate (relative to the `offsetParent`).
  9463. */
  9464. getLocalX: function() {
  9465. var me = this,
  9466. offsetParent,
  9467. x = me.getStyle(LEFT);
  9468. if (!x || x === AUTO) {
  9469. return 0;
  9470. }
  9471. if (x && me.pxRe.test(x)) {
  9472. return parseFloat(x);
  9473. }
  9474. x = me.getX();
  9475. offsetParent = me.dom.offsetParent;
  9476. if (offsetParent) {
  9477. x -= Ext.fly(offsetParent).getX();
  9478. }
  9479. return x;
  9480. },
  9481. /**
  9482. * Returns the y-coordinate of this element reletive to its `offsetParent`.
  9483. * @return {Number} The local y-coordinate (relative to the `offsetParent`).
  9484. */
  9485. getLocalY: function() {
  9486. var me = this,
  9487. offsetParent,
  9488. y = me.getStyle(TOP);
  9489. if (!y || y === AUTO) {
  9490. return 0;
  9491. }
  9492. if (y && me.pxRe.test(y)) {
  9493. return parseFloat(y);
  9494. }
  9495. y = me.getY();
  9496. offsetParent = me.dom.offsetParent;
  9497. if (offsetParent) {
  9498. y -= Ext.fly(offsetParent).getY();
  9499. }
  9500. return y;
  9501. },
  9502. getLeft: function(local) {
  9503. return local ? this.getLocalX() : this.getX();
  9504. },
  9505. getRight: function(local) {
  9506. return (local ? this.getLocalX() : this.getX()) + this.getWidth();
  9507. },
  9508. getTop: function(local) {
  9509. return local ? this.getLocalY() : this.getY();
  9510. },
  9511. getBottom: function(local) {
  9512. return (local ? this.getLocalY() : this.getY()) + this.getHeight();
  9513. },
  9514. translatePoints: function(x, y) {
  9515. var me = this,
  9516. styles = me.getStyle(positionTopLeft),
  9517. relative = styles.position == 'relative',
  9518. left = parseFloat(styles.left),
  9519. top = parseFloat(styles.top),
  9520. xy = me.getXY();
  9521. if (Ext.isArray(x)) {
  9522. y = x[1];
  9523. x = x[0];
  9524. }
  9525. if (isNaN(left)) {
  9526. left = relative ? 0 : me.dom.offsetLeft;
  9527. }
  9528. if (isNaN(top)) {
  9529. top = relative ? 0 : me.dom.offsetTop;
  9530. }
  9531. left = (typeof x == 'number') ? x - xy[0] + left : undefined;
  9532. top = (typeof y == 'number') ? y - xy[1] + top : undefined;
  9533. return {
  9534. left: left,
  9535. top: top
  9536. };
  9537. },
  9538. setBox: function(box, adjust, animate) {
  9539. var me = this,
  9540. w = box.width,
  9541. h = box.height;
  9542. if ((adjust && !me.autoBoxAdjust) && !me.isBorderBox()) {
  9543. w -= (me.getBorderWidth("lr") + me.getPadding("lr"));
  9544. h -= (me.getBorderWidth("tb") + me.getPadding("tb"));
  9545. }
  9546. me.setBounds(box.x, box.y, w, h, animate);
  9547. return me;
  9548. },
  9549. getBox: function(contentBox, local) {
  9550. var me = this,
  9551. xy,
  9552. left,
  9553. top,
  9554. paddingWidth,
  9555. bordersWidth,
  9556. l, r, t, b, w, h, bx;
  9557. if (!local) {
  9558. xy = me.getXY();
  9559. } else {
  9560. xy = me.getStyle([LEFT, TOP]);
  9561. xy = [ parseFloat(xy.left) || 0, parseFloat(xy.top) || 0];
  9562. }
  9563. w = me.getWidth();
  9564. h = me.getHeight();
  9565. if (!contentBox) {
  9566. bx = {
  9567. x: xy[0],
  9568. y: xy[1],
  9569. 0: xy[0],
  9570. 1: xy[1],
  9571. width: w,
  9572. height: h
  9573. };
  9574. } else {
  9575. paddingWidth = me.getStyle(paddingsTLRB);
  9576. bordersWidth = me.getStyle(bordersTLRB);
  9577. l = (parseFloat(bordersWidth[borders.l]) || 0) + (parseFloat(paddingWidth[paddings.l]) || 0);
  9578. r = (parseFloat(bordersWidth[borders.r]) || 0) + (parseFloat(paddingWidth[paddings.r]) || 0);
  9579. t = (parseFloat(bordersWidth[borders.t]) || 0) + (parseFloat(paddingWidth[paddings.t]) || 0);
  9580. b = (parseFloat(bordersWidth[borders.b]) || 0) + (parseFloat(paddingWidth[paddings.b]) || 0);
  9581. bx = {
  9582. x: xy[0] + l,
  9583. y: xy[1] + t,
  9584. 0: xy[0] + l,
  9585. 1: xy[1] + t,
  9586. width: w - (l + r),
  9587. height: h - (t + b)
  9588. };
  9589. }
  9590. bx.right = bx.x + bx.width;
  9591. bx.bottom = bx.y + bx.height;
  9592. return bx;
  9593. },
  9594. getPageBox: function(getRegion) {
  9595. var me = this,
  9596. el = me.dom,
  9597. isDoc = el.nodeName == BODY,
  9598. w = isDoc ? Ext.dom.AbstractElement.getViewWidth() : el.offsetWidth,
  9599. h = isDoc ? Ext.dom.AbstractElement.getViewHeight() : el.offsetHeight,
  9600. xy = me.getXY(),
  9601. t = xy[1],
  9602. r = xy[0] + w,
  9603. b = xy[1] + h,
  9604. l = xy[0];
  9605. if (getRegion) {
  9606. return new Ext.util.Region(t, r, b, l);
  9607. }
  9608. else {
  9609. return {
  9610. left: l,
  9611. top: t,
  9612. width: w,
  9613. height: h,
  9614. right: r,
  9615. bottom: b
  9616. };
  9617. }
  9618. },
  9619. /**
  9620. * Sets the position of the element in page coordinates, regardless of how the element
  9621. * is positioned. The element must be part of the DOM tree to have page coordinates
  9622. * (`display:none` or elements not appended return false).
  9623. * @param {Number} x X value for new position (coordinates are page-based)
  9624. * @param {Number} y Y value for new position (coordinates are page-based)
  9625. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element
  9626. * animation config object
  9627. * @return {Ext.dom.AbstractElement} this
  9628. */
  9629. setLocation : function(x, y, animate) {
  9630. return this.setXY([x, y], animate);
  9631. },
  9632. /**
  9633. * Sets the position of the element in page coordinates, regardless of how the element
  9634. * is positioned. The element must be part of the DOM tree to have page coordinates
  9635. * (`display:none` or elements not appended return false).
  9636. * @param {Number} x X value for new position (coordinates are page-based)
  9637. * @param {Number} y Y value for new position (coordinates are page-based)
  9638. * @param {Boolean/Object} [animate] True for the default animation, or a standard Element
  9639. * animation config object
  9640. * @return {Ext.dom.AbstractElement} this
  9641. */
  9642. moveTo : function(x, y, animate) {
  9643. return this.setXY([x, y], animate);
  9644. },
  9645. /**
  9646. * Initializes positioning on this element. If a desired position is not passed, it will make the
  9647. * the element positioned relative IF it is not already positioned.
  9648. * @param {String} [pos] Positioning to use "relative", "absolute" or "fixed"
  9649. * @param {Number} [zIndex] The zIndex to apply
  9650. * @param {Number} [x] Set the page X position
  9651. * @param {Number} [y] Set the page Y position
  9652. */
  9653. position : function(pos, zIndex, x, y) {
  9654. var me = this;
  9655. if (!pos && me.isStyle(POSITION, STATIC)) {
  9656. me.setStyle(POSITION, RELATIVE);
  9657. } else if (pos) {
  9658. me.setStyle(POSITION, pos);
  9659. }
  9660. if (zIndex) {
  9661. me.setStyle(ZINDEX, zIndex);
  9662. }
  9663. if (x || y) {
  9664. me.setXY([x || false, y || false]);
  9665. }
  9666. },
  9667. /**
  9668. * Clears positioning back to the default when the document was loaded.
  9669. * @param {String} [value=''] The value to use for the left, right, top, bottom. You could use 'auto'.
  9670. * @return {Ext.dom.AbstractElement} this
  9671. */
  9672. clearPositioning : function(value) {
  9673. value = value || '';
  9674. this.setStyle({
  9675. left : value,
  9676. right : value,
  9677. top : value,
  9678. bottom : value,
  9679. "z-index" : "",
  9680. position : STATIC
  9681. });
  9682. return this;
  9683. },
  9684. /**
  9685. * Gets an object with all CSS positioning properties. Useful along with #setPostioning to get
  9686. * snapshot before performing an update and then restoring the element.
  9687. * @return {Object}
  9688. */
  9689. getPositioning : function(){
  9690. var styles = this.getStyle([LEFT, TOP, POSITION, RIGHT, BOTTOM, ZINDEX]);
  9691. styles[RIGHT] = styles[LEFT] ? '' : styles[RIGHT];
  9692. styles[BOTTOM] = styles[TOP] ? '' : styles[BOTTOM];
  9693. return styles;
  9694. },
  9695. /**
  9696. * Set positioning with an object returned by #getPositioning.
  9697. * @param {Object} posCfg
  9698. * @return {Ext.dom.AbstractElement} this
  9699. */
  9700. setPositioning : function(pc) {
  9701. var me = this,
  9702. style = me.dom.style;
  9703. me.setStyle(pc);
  9704. if (pc.right == AUTO) {
  9705. style.right = "";
  9706. }
  9707. if (pc.bottom == AUTO) {
  9708. style.bottom = "";
  9709. }
  9710. return me;
  9711. },
  9712. /**
  9713. * Move this element relative to its current position.
  9714. * @param {String} direction Possible values are:
  9715. *
  9716. * - `"l"` (or `"left"`)
  9717. * - `"r"` (or `"right"`)
  9718. * - `"t"` (or `"top"`, or `"up"`)
  9719. * - `"b"` (or `"bottom"`, or `"down"`)
  9720. *
  9721. * @param {Number} distance How far to move the element in pixels
  9722. * @param {Boolean/Object} [animate] true for the default animation or a standard Element
  9723. * animation config object
  9724. */
  9725. move: function(direction, distance, animate) {
  9726. var me = this,
  9727. xy = me.getXY(),
  9728. x = xy[0],
  9729. y = xy[1],
  9730. left = [x - distance, y],
  9731. right = [x + distance, y],
  9732. top = [x, y - distance],
  9733. bottom = [x, y + distance],
  9734. hash = {
  9735. l: left,
  9736. left: left,
  9737. r: right,
  9738. right: right,
  9739. t: top,
  9740. top: top,
  9741. up: top,
  9742. b: bottom,
  9743. bottom: bottom,
  9744. down: bottom
  9745. };
  9746. direction = direction.toLowerCase();
  9747. me.moveTo(hash[direction][0], hash[direction][1], animate);
  9748. },
  9749. /**
  9750. * Conveniently sets left and top adding default units.
  9751. * @param {String} left The left CSS property value
  9752. * @param {String} top The top CSS property value
  9753. * @return {Ext.dom.Element} this
  9754. */
  9755. setLeftTop: function(left, top) {
  9756. var style = this.dom.style;
  9757. style.left = Element.addUnits(left);
  9758. style.top = Element.addUnits(top);
  9759. return this;
  9760. },
  9761. /**
  9762. * Returns the region of this element.
  9763. * The element must be part of the DOM tree to have a region
  9764. * (display:none or elements not appended return false).
  9765. * @return {Ext.util.Region} A Region containing "top, left, bottom, right" member data.
  9766. */
  9767. getRegion: function() {
  9768. return this.getPageBox(true);
  9769. },
  9770. /**
  9771. * Returns the **content** region of this element. That is the region within the borders and padding.
  9772. * @return {Ext.util.Region} A Region containing "top, left, bottom, right" member data.
  9773. */
  9774. getViewRegion: function() {
  9775. var me = this,
  9776. isBody = me.dom.nodeName == BODY,
  9777. scroll, pos, top, left, width, height;
  9778. // For the body we want to do some special logic
  9779. if (isBody) {
  9780. scroll = me.getScroll();
  9781. left = scroll.left;
  9782. top = scroll.top;
  9783. width = Ext.dom.AbstractElement.getViewportWidth();
  9784. height = Ext.dom.AbstractElement.getViewportHeight();
  9785. }
  9786. else {
  9787. pos = me.getXY();
  9788. left = pos[0] + me.getBorderWidth('l') + me.getPadding('l');
  9789. top = pos[1] + me.getBorderWidth('t') + me.getPadding('t');
  9790. width = me.getWidth(true);
  9791. height = me.getHeight(true);
  9792. }
  9793. return new Ext.util.Region(top, left + width - 1, top + height - 1, left);
  9794. },
  9795. /**
  9796. * Sets the element's position and size in one shot. If animation is true then width, height,
  9797. * x and y will be animated concurrently.
  9798. *
  9799. * @param {Number} x X value for new position (coordinates are page-based)
  9800. * @param {Number} y Y value for new position (coordinates are page-based)
  9801. * @param {Number/String} width The new width. This may be one of:
  9802. *
  9803. * - A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels)
  9804. * - A String used to set the CSS width style. Animation may **not** be used.
  9805. *
  9806. * @param {Number/String} height The new height. This may be one of:
  9807. *
  9808. * - A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels)
  9809. * - A String used to set the CSS height style. Animation may **not** be used.
  9810. *
  9811. * @param {Boolean/Object} [animate] true for the default animation or a standard Element
  9812. * animation config object
  9813. *
  9814. * @return {Ext.dom.AbstractElement} this
  9815. */
  9816. setBounds: function(x, y, width, height, animate) {
  9817. var me = this;
  9818. if (!animate || !me.anim) {
  9819. me.setSize(width, height);
  9820. me.setLocation(x, y);
  9821. } else {
  9822. if (!Ext.isObject(animate)) {
  9823. animate = {};
  9824. }
  9825. me.animate(Ext.applyIf({
  9826. to: {
  9827. x: x,
  9828. y: y,
  9829. width: me.adjustWidth(width),
  9830. height: me.adjustHeight(height)
  9831. }
  9832. }, animate));
  9833. }
  9834. return me;
  9835. },
  9836. /**
  9837. * Sets the element's position and size the specified region. If animation is true then width, height,
  9838. * x and y will be animated concurrently.
  9839. *
  9840. * @param {Ext.util.Region} region The region to fill
  9841. * @param {Boolean/Object} [animate] true for the default animation or a standard Element
  9842. * animation config object
  9843. * @return {Ext.dom.AbstractElement} this
  9844. */
  9845. setRegion: function(region, animate) {
  9846. return this.setBounds(region.left, region.top, region.right - region.left, region.bottom - region.top, animate);
  9847. }
  9848. });
  9849. }());
  9850. /**
  9851. * @class Ext.dom.Element
  9852. */
  9853. Ext.dom.Element.override({
  9854. /**
  9855. * Returns true if this element is scrollable.
  9856. * @return {Boolean}
  9857. */
  9858. isScrollable: function() {
  9859. var dom = this.dom;
  9860. return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth;
  9861. },
  9862. /**
  9863. * Returns the current scroll position of the element.
  9864. * @return {Object} An object containing the scroll position in the format
  9865. * `{left: (scrollLeft), top: (scrollTop)}`
  9866. */
  9867. getScroll: function() {
  9868. var d = this.dom,
  9869. doc = document,
  9870. body = doc.body,
  9871. docElement = doc.documentElement,
  9872. l,
  9873. t,
  9874. ret;
  9875. if (d == doc || d == body) {
  9876. if (Ext.isIE && Ext.isStrict) {
  9877. l = docElement.scrollLeft;
  9878. t = docElement.scrollTop;
  9879. } else {
  9880. l = window.pageXOffset;
  9881. t = window.pageYOffset;
  9882. }
  9883. ret = {
  9884. left: l || (body ? body.scrollLeft : 0),
  9885. top : t || (body ? body.scrollTop : 0)
  9886. };
  9887. } else {
  9888. ret = {
  9889. left: d.scrollLeft,
  9890. top : d.scrollTop
  9891. };
  9892. }
  9893. return ret;
  9894. },
  9895. /**
  9896. * Scrolls this element by the passed delta values, optionally animating.
  9897. *
  9898. * All of the following are equivalent:
  9899. *
  9900. * el.scrollBy(10, 10, true);
  9901. * el.scrollBy([10, 10], true);
  9902. * el.scrollBy({ x: 10, y: 10 }, true);
  9903. *
  9904. * @param {Number/Number[]/Object} deltaX Either the x delta, an Array specifying x and y deltas or
  9905. * an object with "x" and "y" properties.
  9906. * @param {Number/Boolean/Object} deltaY Either the y delta, or an animate flag or config object.
  9907. * @param {Boolean/Object} animate Animate flag/config object if the delta values were passed separately.
  9908. * @return {Ext.Element} this
  9909. */
  9910. scrollBy: function(deltaX, deltaY, animate) {
  9911. var me = this,
  9912. dom = me.dom;
  9913. // Extract args if deltas were passed as an Array.
  9914. if (deltaX.length) {
  9915. animate = deltaY;
  9916. deltaY = deltaX[1];
  9917. deltaX = deltaX[0];
  9918. } else if (typeof deltaX != 'number') { // or an object
  9919. animate = deltaY;
  9920. deltaY = deltaX.y;
  9921. deltaX = deltaX.x;
  9922. }
  9923. if (deltaX) {
  9924. me.scrollTo('left', Math.max(Math.min(dom.scrollLeft + deltaX, dom.scrollWidth - dom.clientWidth), 0), animate);
  9925. }
  9926. if (deltaY) {
  9927. me.scrollTo('top', Math.max(Math.min(dom.scrollTop + deltaY, dom.scrollHeight - dom.clientHeight), 0), animate);
  9928. }
  9929. return me;
  9930. },
  9931. /**
  9932. * Scrolls this element the specified scroll point. It does NOT do bounds checking so
  9933. * if you scroll to a weird value it will try to do it. For auto bounds checking, use #scroll.
  9934. * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
  9935. * @param {Number} value The new scroll value
  9936. * @param {Boolean/Object} [animate] true for the default animation or a standard Element
  9937. * animation config object
  9938. * @return {Ext.Element} this
  9939. */
  9940. scrollTo: function(side, value, animate) {
  9941. //check if we're scrolling top or left
  9942. var top = /top/i.test(side),
  9943. me = this,
  9944. dom = me.dom,
  9945. animCfg,
  9946. prop;
  9947. if (!animate || !me.anim) {
  9948. // just setting the value, so grab the direction
  9949. prop = 'scroll' + (top ? 'Top' : 'Left');
  9950. dom[prop] = value;
  9951. // corrects IE, other browsers will ignore
  9952. dom[prop] = value;
  9953. }
  9954. else {
  9955. animCfg = {
  9956. to: {}
  9957. };
  9958. animCfg.to['scroll' + (top ? 'Top' : 'Left')] = value;
  9959. if (Ext.isObject(animate)) {
  9960. Ext.applyIf(animCfg, animate);
  9961. }
  9962. me.animate(animCfg);
  9963. }
  9964. return me;
  9965. },
  9966. /**
  9967. * Scrolls this element into view within the passed container.
  9968. * @param {String/HTMLElement/Ext.Element} [container=document.body] The container element
  9969. * to scroll. Should be a string (id), dom node, or Ext.Element.
  9970. * @param {Boolean} [hscroll=true] False to disable horizontal scroll.
  9971. * @param {Boolean/Object} [animate] true for the default animation or a standard Element
  9972. * animation config object
  9973. * @return {Ext.dom.Element} this
  9974. */
  9975. scrollIntoView: function(container, hscroll, animate) {
  9976. container = Ext.getDom(container) || Ext.getBody().dom;
  9977. var el = this.dom,
  9978. offsets = this.getOffsetsTo(container),
  9979. // el's box
  9980. left = offsets[0] + container.scrollLeft,
  9981. top = offsets[1] + container.scrollTop,
  9982. bottom = top + el.offsetHeight,
  9983. right = left + el.offsetWidth,
  9984. // ct's box
  9985. ctClientHeight = container.clientHeight,
  9986. ctScrollTop = parseInt(container.scrollTop, 10),
  9987. ctScrollLeft = parseInt(container.scrollLeft, 10),
  9988. ctBottom = ctScrollTop + ctClientHeight,
  9989. ctRight = ctScrollLeft + container.clientWidth,
  9990. newPos;
  9991. if (el.offsetHeight > ctClientHeight || top < ctScrollTop) {
  9992. newPos = top;
  9993. } else if (bottom > ctBottom) {
  9994. newPos = bottom - ctClientHeight;
  9995. }
  9996. if (newPos != null) {
  9997. Ext.get(container).scrollTo('top', newPos, animate);
  9998. }
  9999. if (hscroll !== false) {
  10000. newPos = null;
  10001. if (el.offsetWidth > container.clientWidth || left < ctScrollLeft) {
  10002. newPos = left;
  10003. } else if (right > ctRight) {
  10004. newPos = right - container.clientWidth;
  10005. }
  10006. if (newPos != null) {
  10007. Ext.get(container).scrollTo('left', newPos, animate);
  10008. }
  10009. }
  10010. return this;
  10011. },
  10012. // @private
  10013. scrollChildIntoView: function(child, hscroll) {
  10014. Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
  10015. },
  10016. /**
  10017. * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
  10018. * within this element's scrollable range.
  10019. * @param {String} direction Possible values are:
  10020. *
  10021. * - `"l"` (or `"left"`)
  10022. * - `"r"` (or `"right"`)
  10023. * - `"t"` (or `"top"`, or `"up"`)
  10024. * - `"b"` (or `"bottom"`, or `"down"`)
  10025. *
  10026. * @param {Number} distance How far to scroll the element in pixels
  10027. * @param {Boolean/Object} [animate] true for the default animation or a standard Element
  10028. * animation config object
  10029. * @return {Boolean} Returns true if a scroll was triggered or false if the element
  10030. * was scrolled as far as it could go.
  10031. */
  10032. scroll: function(direction, distance, animate) {
  10033. if (!this.isScrollable()) {
  10034. return false;
  10035. }
  10036. var el = this.dom,
  10037. l = el.scrollLeft, t = el.scrollTop,
  10038. w = el.scrollWidth, h = el.scrollHeight,
  10039. cw = el.clientWidth, ch = el.clientHeight,
  10040. scrolled = false, v,
  10041. hash = {
  10042. l: Math.min(l + distance, w - cw),
  10043. r: v = Math.max(l - distance, 0),
  10044. t: Math.max(t - distance, 0),
  10045. b: Math.min(t + distance, h - ch)
  10046. };
  10047. hash.d = hash.b;
  10048. hash.u = hash.t;
  10049. direction = direction.substr(0, 1);
  10050. if ((v = hash[direction]) > -1) {
  10051. scrolled = true;
  10052. this.scrollTo(direction == 'l' || direction == 'r' ? 'left' : 'top', v, this.anim(animate));
  10053. }
  10054. return scrolled;
  10055. }
  10056. });
  10057. /**
  10058. * @class Ext.dom.Element
  10059. */
  10060. (function() {
  10061. var Element = Ext.dom.Element,
  10062. view = document.defaultView,
  10063. adjustDirect2DTableRe = /table-row|table-.*-group/,
  10064. INTERNAL = '_internal',
  10065. HIDDEN = 'hidden',
  10066. HEIGHT = 'height',
  10067. WIDTH = 'width',
  10068. ISCLIPPED = 'isClipped',
  10069. OVERFLOW = 'overflow',
  10070. OVERFLOWX = 'overflow-x',
  10071. OVERFLOWY = 'overflow-y',
  10072. ORIGINALCLIP = 'originalClip',
  10073. DOCORBODYRE = /#document|body/i,
  10074. // This reduces the lookup of 'me.styleHooks' by one hop in the prototype chain. It is
  10075. // the same object.
  10076. styleHooks,
  10077. edges, k, edge, borderWidth;
  10078. if (!view || !view.getComputedStyle) {
  10079. Element.prototype.getStyle = function (property, inline) {
  10080. var me = this,
  10081. dom = me.dom,
  10082. multiple = typeof property != 'string',
  10083. hooks = me.styleHooks,
  10084. prop = property,
  10085. props = prop,
  10086. len = 1,
  10087. isInline = inline,
  10088. camel, domStyle, values, hook, out, style, i;
  10089. if (multiple) {
  10090. values = {};
  10091. prop = props[0];
  10092. i = 0;
  10093. if (!(len = props.length)) {
  10094. return values;
  10095. }
  10096. }
  10097. if (!dom || dom.documentElement) {
  10098. return values || '';
  10099. }
  10100. domStyle = dom.style;
  10101. if (inline) {
  10102. style = domStyle;
  10103. } else {
  10104. style = dom.currentStyle;
  10105. // fallback to inline style if rendering context not available
  10106. if (!style) {
  10107. isInline = true;
  10108. style = domStyle;
  10109. }
  10110. }
  10111. do {
  10112. hook = hooks[prop];
  10113. if (!hook) {
  10114. hooks[prop] = hook = { name: Element.normalize(prop) };
  10115. }
  10116. if (hook.get) {
  10117. out = hook.get(dom, me, isInline, style);
  10118. } else {
  10119. camel = hook.name;
  10120. // In some cases, IE6 will throw Invalid Argument exceptions for properties
  10121. // like fontSize (/examples/tabs/tabs.html in 4.0 used to exhibit this but
  10122. // no longer does due to font style changes). There is a real cost to a try
  10123. // block, so we avoid it where possible...
  10124. if (hook.canThrow) {
  10125. try {
  10126. out = style[camel];
  10127. } catch (e) {
  10128. out = '';
  10129. }
  10130. } else {
  10131. // EXTJSIV-5657 - In IE9 quirks mode there is a chance that VML root element
  10132. // has neither `currentStyle` nor `style`. Return '' this case.
  10133. out = style ? style[camel] : '';
  10134. }
  10135. }
  10136. if (!multiple) {
  10137. return out;
  10138. }
  10139. values[prop] = out;
  10140. prop = props[++i];
  10141. } while (i < len);
  10142. return values;
  10143. };
  10144. }
  10145. Element.override({
  10146. getHeight: function(contentHeight, preciseHeight) {
  10147. var me = this,
  10148. dom = me.dom,
  10149. hidden = me.isStyle('display', 'none'),
  10150. height,
  10151. floating;
  10152. if (hidden) {
  10153. return 0;
  10154. }
  10155. height = Math.max(dom.offsetHeight, dom.clientHeight) || 0;
  10156. // IE9 Direct2D dimension rounding bug
  10157. if (Ext.supports.Direct2DBug) {
  10158. floating = me.adjustDirect2DDimension(HEIGHT);
  10159. if (preciseHeight) {
  10160. height += floating;
  10161. }
  10162. else if (floating > 0 && floating < 0.5) {
  10163. height++;
  10164. }
  10165. }
  10166. if (contentHeight) {
  10167. height -= me.getBorderWidth("tb") + me.getPadding("tb");
  10168. }
  10169. return (height < 0) ? 0 : height;
  10170. },
  10171. getWidth: function(contentWidth, preciseWidth) {
  10172. var me = this,
  10173. dom = me.dom,
  10174. hidden = me.isStyle('display', 'none'),
  10175. rect, width, floating;
  10176. if (hidden) {
  10177. return 0;
  10178. }
  10179. // Gecko will in some cases report an offsetWidth that is actually less than the width of the
  10180. // text contents, because it measures fonts with sub-pixel precision but rounds the calculated
  10181. // value down. Using getBoundingClientRect instead of offsetWidth allows us to get the precise
  10182. // subpixel measurements so we can force them to always be rounded up. See
  10183. // https://bugzilla.mozilla.org/show_bug.cgi?id=458617
  10184. // Rounding up ensures that the width includes the full width of the text contents.
  10185. if (Ext.supports.BoundingClientRect) {
  10186. rect = dom.getBoundingClientRect();
  10187. width = rect.right - rect.left;
  10188. width = preciseWidth ? width : Math.ceil(width);
  10189. } else {
  10190. width = dom.offsetWidth;
  10191. }
  10192. width = Math.max(width, dom.clientWidth) || 0;
  10193. // IE9 Direct2D dimension rounding bug
  10194. if (Ext.supports.Direct2DBug) {
  10195. // get the fractional portion of the sub-pixel precision width of the element's text contents
  10196. floating = me.adjustDirect2DDimension(WIDTH);
  10197. if (preciseWidth) {
  10198. width += floating;
  10199. }
  10200. // IE9 also measures fonts with sub-pixel precision, but unlike Gecko, instead of rounding the offsetWidth down,
  10201. // it rounds to the nearest integer. This means that in order to ensure that the width includes the full
  10202. // width of the text contents we need to increment the width by 1 only if the fractional portion is less than 0.5
  10203. else if (floating > 0 && floating < 0.5) {
  10204. width++;
  10205. }
  10206. }
  10207. if (contentWidth) {
  10208. width -= me.getBorderWidth("lr") + me.getPadding("lr");
  10209. }
  10210. return (width < 0) ? 0 : width;
  10211. },
  10212. setWidth: function(width, animate) {
  10213. var me = this;
  10214. width = me.adjustWidth(width);
  10215. if (!animate || !me.anim) {
  10216. me.dom.style.width = me.addUnits(width);
  10217. }
  10218. else {
  10219. if (!Ext.isObject(animate)) {
  10220. animate = {};
  10221. }
  10222. me.animate(Ext.applyIf({
  10223. to: {
  10224. width: width
  10225. }
  10226. }, animate));
  10227. }
  10228. return me;
  10229. },
  10230. setHeight : function(height, animate) {
  10231. var me = this;
  10232. height = me.adjustHeight(height);
  10233. if (!animate || !me.anim) {
  10234. me.dom.style.height = me.addUnits(height);
  10235. }
  10236. else {
  10237. if (!Ext.isObject(animate)) {
  10238. animate = {};
  10239. }
  10240. me.animate(Ext.applyIf({
  10241. to: {
  10242. height: height
  10243. }
  10244. }, animate));
  10245. }
  10246. return me;
  10247. },
  10248. applyStyles: function(style) {
  10249. Ext.DomHelper.applyStyles(this.dom, style);
  10250. return this;
  10251. },
  10252. setSize: function(width, height, animate) {
  10253. var me = this;
  10254. if (Ext.isObject(width)) { // in case of object from getSize()
  10255. animate = height;
  10256. height = width.height;
  10257. width = width.width;
  10258. }
  10259. width = me.adjustWidth(width);
  10260. height = me.adjustHeight(height);
  10261. if (!animate || !me.anim) {
  10262. me.dom.style.width = me.addUnits(width);
  10263. me.dom.style.height = me.addUnits(height);
  10264. }
  10265. else {
  10266. if (animate === true) {
  10267. animate = {};
  10268. }
  10269. me.animate(Ext.applyIf({
  10270. to: {
  10271. width: width,
  10272. height: height
  10273. }
  10274. }, animate));
  10275. }
  10276. return me;
  10277. },
  10278. getViewSize : function() {
  10279. var me = this,
  10280. dom = me.dom,
  10281. isDoc = DOCORBODYRE.test(dom.nodeName),
  10282. ret;
  10283. // If the body, use static methods
  10284. if (isDoc) {
  10285. ret = {
  10286. width : Element.getViewWidth(),
  10287. height : Element.getViewHeight()
  10288. };
  10289. } else {
  10290. ret = {
  10291. width : dom.clientWidth,
  10292. height : dom.clientHeight
  10293. };
  10294. }
  10295. return ret;
  10296. },
  10297. getSize: function(contentSize) {
  10298. return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
  10299. },
  10300. // TODO: Look at this
  10301. // private ==> used by Fx
  10302. adjustWidth : function(width) {
  10303. var me = this,
  10304. isNum = (typeof width == 'number');
  10305. if (isNum && me.autoBoxAdjust && !me.isBorderBox()) {
  10306. width -= (me.getBorderWidth("lr") + me.getPadding("lr"));
  10307. }
  10308. return (isNum && width < 0) ? 0 : width;
  10309. },
  10310. // private ==> used by Fx
  10311. adjustHeight : function(height) {
  10312. var me = this,
  10313. isNum = (typeof height == "number");
  10314. if (isNum && me.autoBoxAdjust && !me.isBorderBox()) {
  10315. height -= (me.getBorderWidth("tb") + me.getPadding("tb"));
  10316. }
  10317. return (isNum && height < 0) ? 0 : height;
  10318. },
  10319. /**
  10320. * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like `#fff`) and valid values
  10321. * are convert to standard 6 digit hex color.
  10322. * @param {String} attr The css attribute
  10323. * @param {String} defaultValue The default value to use when a valid color isn't found
  10324. * @param {String} [prefix] defaults to #. Use an empty string when working with
  10325. * color anims.
  10326. */
  10327. getColor : function(attr, defaultValue, prefix) {
  10328. var v = this.getStyle(attr),
  10329. color = prefix || prefix === '' ? prefix : '#',
  10330. h, len, i=0;
  10331. if (!v || (/transparent|inherit/.test(v))) {
  10332. return defaultValue;
  10333. }
  10334. if (/^r/.test(v)) {
  10335. v = v.slice(4, v.length - 1).split(',');
  10336. len = v.length;
  10337. for (; i<len; i++) {
  10338. h = parseInt(v[i], 10);
  10339. color += (h < 16 ? '0' : '') + h.toString(16);
  10340. }
  10341. } else {
  10342. v = v.replace('#', '');
  10343. color += v.length == 3 ? v.replace(/^(\w)(\w)(\w)$/, '$1$1$2$2$3$3') : v;
  10344. }
  10345. return(color.length > 5 ? color.toLowerCase() : defaultValue);
  10346. },
  10347. /**
  10348. * Set the opacity of the element
  10349. * @param {Number} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
  10350. * @param {Boolean/Object} [animate] a standard Element animation config object or `true` for
  10351. * the default animation (`{duration: 350, easing: 'easeIn'}`)
  10352. * @return {Ext.dom.Element} this
  10353. */
  10354. setOpacity: function(opacity, animate) {
  10355. var me = this;
  10356. if (!me.dom) {
  10357. return me;
  10358. }
  10359. if (!animate || !me.anim) {
  10360. me.setStyle('opacity', opacity);
  10361. }
  10362. else {
  10363. if (typeof animate != 'object') {
  10364. animate = {
  10365. duration: 350,
  10366. easing: 'ease-in'
  10367. };
  10368. }
  10369. me.animate(Ext.applyIf({
  10370. to: {
  10371. opacity: opacity
  10372. }
  10373. }, animate));
  10374. }
  10375. return me;
  10376. },
  10377. /**
  10378. * Clears any opacity settings from this element. Required in some cases for IE.
  10379. * @return {Ext.dom.Element} this
  10380. */
  10381. clearOpacity : function() {
  10382. return this.setOpacity('');
  10383. },
  10384. /**
  10385. * @private
  10386. * Returns 1 if the browser returns the subpixel dimension rounded to the lowest pixel.
  10387. * @return {Number} 0 or 1
  10388. */
  10389. adjustDirect2DDimension: function(dimension) {
  10390. var me = this,
  10391. dom = me.dom,
  10392. display = me.getStyle('display'),
  10393. inlineDisplay = dom.style.display,
  10394. inlinePosition = dom.style.position,
  10395. originIndex = dimension === WIDTH ? 0 : 1,
  10396. currentStyle = dom.currentStyle,
  10397. floating;
  10398. if (display === 'inline') {
  10399. dom.style.display = 'inline-block';
  10400. }
  10401. dom.style.position = display.match(adjustDirect2DTableRe) ? 'absolute' : 'static';
  10402. // floating will contain digits that appears after the decimal point
  10403. // if height or width are set to auto we fallback to msTransformOrigin calculation
  10404. // Use currentStyle here instead of getStyle. In some difficult to reproduce
  10405. // instances it resets the scrollWidth of the element
  10406. floating = (parseFloat(currentStyle[dimension]) || parseFloat(currentStyle.msTransformOrigin.split(' ')[originIndex]) * 2) % 1;
  10407. dom.style.position = inlinePosition;
  10408. if (display === 'inline') {
  10409. dom.style.display = inlineDisplay;
  10410. }
  10411. return floating;
  10412. },
  10413. /**
  10414. * Store the current overflow setting and clip overflow on the element - use {@link #unclip} to remove
  10415. * @return {Ext.dom.Element} this
  10416. */
  10417. clip : function() {
  10418. var me = this,
  10419. data = (me.$cache || me.getCache()).data,
  10420. style;
  10421. if (!data[ISCLIPPED]) {
  10422. data[ISCLIPPED] = true;
  10423. style = me.getStyle([OVERFLOW, OVERFLOWX, OVERFLOWY]);
  10424. data[ORIGINALCLIP] = {
  10425. o: style[OVERFLOW],
  10426. x: style[OVERFLOWX],
  10427. y: style[OVERFLOWY]
  10428. };
  10429. me.setStyle(OVERFLOW, HIDDEN);
  10430. me.setStyle(OVERFLOWX, HIDDEN);
  10431. me.setStyle(OVERFLOWY, HIDDEN);
  10432. }
  10433. return me;
  10434. },
  10435. /**
  10436. * Return clipping (overflow) to original clipping before {@link #clip} was called
  10437. * @return {Ext.dom.Element} this
  10438. */
  10439. unclip : function() {
  10440. var me = this,
  10441. data = (me.$cache || me.getCache()).data,
  10442. clip;
  10443. if (data[ISCLIPPED]) {
  10444. data[ISCLIPPED] = false;
  10445. clip = data[ORIGINALCLIP];
  10446. if (clip.o) {
  10447. me.setStyle(OVERFLOW, clip.o);
  10448. }
  10449. if (clip.x) {
  10450. me.setStyle(OVERFLOWX, clip.x);
  10451. }
  10452. if (clip.y) {
  10453. me.setStyle(OVERFLOWY, clip.y);
  10454. }
  10455. }
  10456. return me;
  10457. },
  10458. /**
  10459. * Wraps the specified element with a special 9 element markup/CSS block that renders by default as
  10460. * a gray container with a gradient background, rounded corners and a 4-way shadow.
  10461. *
  10462. * This special markup is used throughout Ext when box wrapping elements ({@link Ext.button.Button},
  10463. * {@link Ext.panel.Panel} when {@link Ext.panel.Panel#frame frame=true}, {@link Ext.window.Window}).
  10464. * The markup is of this form:
  10465. *
  10466. * Ext.dom.Element.boxMarkup =
  10467. * '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div>
  10468. * <div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div>
  10469. * <div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
  10470. *
  10471. * Example usage:
  10472. *
  10473. * // Basic box wrap
  10474. * Ext.get("foo").boxWrap();
  10475. *
  10476. * // You can also add a custom class and use CSS inheritance rules to customize the box look.
  10477. * // 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example
  10478. * // for how to create a custom box wrap style.
  10479. * Ext.get("foo").boxWrap().addCls("x-box-blue");
  10480. *
  10481. * @param {String} [class='x-box'] A base CSS class to apply to the containing wrapper element.
  10482. * Note that there are a number of CSS rules that are dependent on this name to make the overall effect work,
  10483. * so if you supply an alternate base class, make sure you also supply all of the necessary rules.
  10484. * @return {Ext.dom.Element} The outermost wrapping element of the created box structure.
  10485. */
  10486. boxWrap : function(cls) {
  10487. cls = cls || Ext.baseCSSPrefix + 'box';
  10488. var el = Ext.get(this.insertHtml("beforeBegin", "<div class='" + cls + "'>" + Ext.String.format(Element.boxMarkup, cls) + "</div>"));
  10489. Ext.DomQuery.selectNode('.' + cls + '-mc', el.dom).appendChild(this.dom);
  10490. return el;
  10491. },
  10492. /**
  10493. * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
  10494. * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
  10495. * if a height has not been set using CSS.
  10496. * @return {Number}
  10497. */
  10498. getComputedHeight : function() {
  10499. var me = this,
  10500. h = Math.max(me.dom.offsetHeight, me.dom.clientHeight);
  10501. if (!h) {
  10502. h = parseFloat(me.getStyle(HEIGHT)) || 0;
  10503. if (!me.isBorderBox()) {
  10504. h += me.getFrameWidth('tb');
  10505. }
  10506. }
  10507. return h;
  10508. },
  10509. /**
  10510. * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
  10511. * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
  10512. * if a width has not been set using CSS.
  10513. * @return {Number}
  10514. */
  10515. getComputedWidth : function() {
  10516. var me = this,
  10517. w = Math.max(me.dom.offsetWidth, me.dom.clientWidth);
  10518. if (!w) {
  10519. w = parseFloat(me.getStyle(WIDTH)) || 0;
  10520. if (!me.isBorderBox()) {
  10521. w += me.getFrameWidth('lr');
  10522. }
  10523. }
  10524. return w;
  10525. },
  10526. /**
  10527. * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
  10528. * for more information about the sides.
  10529. * @param {String} sides
  10530. * @return {Number}
  10531. */
  10532. getFrameWidth : function(sides, onlyContentBox) {
  10533. return (onlyContentBox && this.isBorderBox()) ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
  10534. },
  10535. /**
  10536. * Sets up event handlers to add and remove a css class when the mouse is over this element
  10537. * @param {String} className The class to add
  10538. * @param {Function} [testFn] A test function to execute before adding the class. The passed parameter
  10539. * will be the Element instance. If this functions returns false, the class will not be added.
  10540. * @param {Object} [scope] The scope to execute the testFn in.
  10541. * @return {Ext.dom.Element} this
  10542. */
  10543. addClsOnOver : function(className, testFn, scope) {
  10544. var me = this,
  10545. dom = me.dom,
  10546. hasTest = Ext.isFunction(testFn);
  10547. me.hover(
  10548. function() {
  10549. if (hasTest && testFn.call(scope || me, me) === false) {
  10550. return;
  10551. }
  10552. Ext.fly(dom, INTERNAL).addCls(className);
  10553. },
  10554. function() {
  10555. Ext.fly(dom, INTERNAL).removeCls(className);
  10556. }
  10557. );
  10558. return me;
  10559. },
  10560. /**
  10561. * Sets up event handlers to add and remove a css class when this element has the focus
  10562. * @param {String} className The class to add
  10563. * @param {Function} [testFn] A test function to execute before adding the class. The passed parameter
  10564. * will be the Element instance. If this functions returns false, the class will not be added.
  10565. * @param {Object} [scope] The scope to execute the testFn in.
  10566. * @return {Ext.dom.Element} this
  10567. */
  10568. addClsOnFocus : function(className, testFn, scope) {
  10569. var me = this,
  10570. dom = me.dom,
  10571. hasTest = Ext.isFunction(testFn);
  10572. me.on("focus", function() {
  10573. if (hasTest && testFn.call(scope || me, me) === false) {
  10574. return false;
  10575. }
  10576. Ext.fly(dom, INTERNAL).addCls(className);
  10577. });
  10578. me.on("blur", function() {
  10579. Ext.fly(dom, INTERNAL).removeCls(className);
  10580. });
  10581. return me;
  10582. },
  10583. /**
  10584. * Sets up event handlers to add and remove a css class when the mouse is down and then up on this element (a click effect)
  10585. * @param {String} className The class to add
  10586. * @param {Function} [testFn] A test function to execute before adding the class. The passed parameter
  10587. * will be the Element instance. If this functions returns false, the class will not be added.
  10588. * @param {Object} [scope] The scope to execute the testFn in.
  10589. * @return {Ext.dom.Element} this
  10590. */
  10591. addClsOnClick : function(className, testFn, scope) {
  10592. var me = this,
  10593. dom = me.dom,
  10594. hasTest = Ext.isFunction(testFn);
  10595. me.on("mousedown", function() {
  10596. if (hasTest && testFn.call(scope || me, me) === false) {
  10597. return false;
  10598. }
  10599. Ext.fly(dom, INTERNAL).addCls(className);
  10600. var d = Ext.getDoc(),
  10601. fn = function() {
  10602. Ext.fly(dom, INTERNAL).removeCls(className);
  10603. d.removeListener("mouseup", fn);
  10604. };
  10605. d.on("mouseup", fn);
  10606. });
  10607. return me;
  10608. },
  10609. /**
  10610. * Returns the dimensions of the element available to lay content out in.
  10611. *
  10612. * getStyleSize utilizes prefers style sizing if present, otherwise it chooses the larger of offsetHeight/clientHeight and
  10613. * offsetWidth/clientWidth. To obtain the size excluding scrollbars, use getViewSize.
  10614. *
  10615. * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
  10616. *
  10617. * @return {Object} Object describing width and height.
  10618. * @return {Number} return.width
  10619. * @return {Number} return.height
  10620. */
  10621. getStyleSize : function() {
  10622. var me = this,
  10623. d = this.dom,
  10624. isDoc = DOCORBODYRE.test(d.nodeName),
  10625. s ,
  10626. w, h;
  10627. // If the body, use static methods
  10628. if (isDoc) {
  10629. return {
  10630. width : Element.getViewWidth(),
  10631. height : Element.getViewHeight()
  10632. };
  10633. }
  10634. s = me.getStyle([HEIGHT, WIDTH], true); //seek inline
  10635. // Use Styles if they are set
  10636. if (s.width && s.width != 'auto') {
  10637. w = parseFloat(s.width);
  10638. if (me.isBorderBox()) {
  10639. w -= me.getFrameWidth('lr');
  10640. }
  10641. }
  10642. // Use Styles if they are set
  10643. if (s.height && s.height != 'auto') {
  10644. h = parseFloat(s.height);
  10645. if (me.isBorderBox()) {
  10646. h -= me.getFrameWidth('tb');
  10647. }
  10648. }
  10649. // Use getWidth/getHeight if style not set.
  10650. return {width: w || me.getWidth(true), height: h || me.getHeight(true)};
  10651. },
  10652. /**
  10653. * Enable text selection for this element (normalized across browsers)
  10654. * @return {Ext.Element} this
  10655. */
  10656. selectable : function() {
  10657. var me = this;
  10658. me.dom.unselectable = "off";
  10659. // Prevent it from bubles up and enables it to be selectable
  10660. me.on('selectstart', function (e) {
  10661. e.stopPropagation();
  10662. return true;
  10663. });
  10664. me.applyStyles("-moz-user-select: text; -khtml-user-select: text;");
  10665. me.removeCls(Ext.baseCSSPrefix + 'unselectable');
  10666. return me;
  10667. },
  10668. /**
  10669. * Disables text selection for this element (normalized across browsers)
  10670. * @return {Ext.dom.Element} this
  10671. */
  10672. unselectable : function() {
  10673. var me = this;
  10674. me.dom.unselectable = "on";
  10675. me.swallowEvent("selectstart", true);
  10676. me.applyStyles("-moz-user-select:-moz-none;-khtml-user-select:none;");
  10677. me.addCls(Ext.baseCSSPrefix + 'unselectable');
  10678. return me;
  10679. }
  10680. });
  10681. Element.prototype.styleHooks = styleHooks = Ext.dom.AbstractElement.prototype.styleHooks;
  10682. if (Ext.isIE6 || Ext.isIE7) {
  10683. styleHooks.fontSize = styleHooks['font-size'] = {
  10684. name: 'fontSize',
  10685. canThrow: true
  10686. };
  10687. styleHooks.fontStyle = styleHooks['font-style'] = {
  10688. name: 'fontStyle',
  10689. canThrow: true
  10690. };
  10691. styleHooks.fontFamily = styleHooks['font-family'] = {
  10692. name: 'fontFamily',
  10693. canThrow: true
  10694. };
  10695. }
  10696. // override getStyle for border-*-width
  10697. if (Ext.isIEQuirks || Ext.isIE && Ext.ieVersion <= 8) {
  10698. function getBorderWidth (dom, el, inline, style) {
  10699. if (style[this.styleName] == 'none') {
  10700. return '0px';
  10701. }
  10702. return style[this.name];
  10703. }
  10704. edges = ['Top','Right','Bottom','Left'];
  10705. k = edges.length;
  10706. while (k--) {
  10707. edge = edges[k];
  10708. borderWidth = 'border' + edge + 'Width';
  10709. styleHooks['border-'+edge.toLowerCase()+'-width'] = styleHooks[borderWidth] = {
  10710. name: borderWidth,
  10711. styleName: 'border' + edge + 'Style',
  10712. get: getBorderWidth
  10713. };
  10714. }
  10715. }
  10716. }());
  10717. Ext.onReady(function () {
  10718. var opacityRe = /alpha\(opacity=(.*)\)/i,
  10719. trimRe = /^\s+|\s+$/g,
  10720. hooks = Ext.dom.Element.prototype.styleHooks;
  10721. // Ext.supports flags are not populated until onReady...
  10722. hooks.opacity = {
  10723. name: 'opacity',
  10724. afterSet: function(dom, value, el) {
  10725. if (el.isLayer) {
  10726. el.onOpacitySet(value);
  10727. }
  10728. }
  10729. };
  10730. if (!Ext.supports.Opacity && Ext.isIE) {
  10731. Ext.apply(hooks.opacity, {
  10732. get: function (dom) {
  10733. var filter = dom.style.filter,
  10734. match, opacity;
  10735. if (filter.match) {
  10736. match = filter.match(opacityRe);
  10737. if (match) {
  10738. opacity = parseFloat(match[1]);
  10739. if (!isNaN(opacity)) {
  10740. return opacity ? opacity / 100 : 0;
  10741. }
  10742. }
  10743. }
  10744. return 1;
  10745. },
  10746. set: function (dom, value) {
  10747. var style = dom.style,
  10748. val = style.filter.replace(opacityRe, '').replace(trimRe, '');
  10749. style.zoom = 1; // ensure dom.hasLayout
  10750. // value can be a number or '' or null... so treat falsey as no opacity
  10751. if (typeof(value) == 'number' && value >= 0 && value < 1) {
  10752. value *= 100;
  10753. style.filter = val + (val.length ? ' ' : '') + 'alpha(opacity='+value+')';
  10754. } else {
  10755. style.filter = val;
  10756. }
  10757. }
  10758. });
  10759. }
  10760. // else there is no work around for the lack of opacity support. Should not be a
  10761. // problem given that this has been supported for a long time now...
  10762. });
  10763. /**
  10764. * @class Ext.dom.Element
  10765. */
  10766. Ext.dom.Element.override({
  10767. select: function(selector) {
  10768. return Ext.dom.Element.select(selector, false, this.dom);
  10769. }
  10770. });
  10771. /**
  10772. * This class encapsulates a *collection* of DOM elements, providing methods to filter members, or to perform collective
  10773. * actions upon the whole set.
  10774. *
  10775. * Although they are not listed, this class supports all of the methods of {@link Ext.dom.Element} and
  10776. * {@link Ext.fx.Anim}. The methods from these classes will be performed on all the elements in this collection.
  10777. *
  10778. * Example:
  10779. *
  10780. * var els = Ext.select("#some-el div.some-class");
  10781. * // or select directly from an existing element
  10782. * var el = Ext.get('some-el');
  10783. * el.select('div.some-class');
  10784. *
  10785. * els.setWidth(100); // all elements become 100 width
  10786. * els.hide(true); // all elements fade out and hide
  10787. * // or
  10788. * els.setWidth(100).hide(true);
  10789. */
  10790. Ext.define('Ext.dom.CompositeElementLite', {
  10791. alternateClassName: 'Ext.CompositeElementLite',
  10792. requires: ['Ext.dom.Element'],
  10793. statics: {
  10794. /**
  10795. * @private
  10796. * Copies all of the functions from Ext.dom.Element's prototype onto CompositeElementLite's prototype.
  10797. * This is called twice - once immediately below, and once again after additional Ext.dom.Element
  10798. * are added in Ext JS
  10799. */
  10800. importElementMethods: function() {
  10801. var name,
  10802. elementPrototype = Ext.dom.Element.prototype,
  10803. prototype = this.prototype;
  10804. for (name in elementPrototype) {
  10805. if (typeof elementPrototype[name] == 'function'){
  10806. (function(key) {
  10807. prototype[key] = prototype[key] || function() {
  10808. return this.invoke(key, arguments);
  10809. };
  10810. }).call(prototype, name);
  10811. }
  10812. }
  10813. }
  10814. },
  10815. constructor: function(elements, root) {
  10816. /**
  10817. * @property {HTMLElement[]} elements
  10818. * The Array of DOM elements which this CompositeElement encapsulates.
  10819. *
  10820. * This will not *usually* be accessed in developers' code, but developers wishing to augment the capabilities
  10821. * of the CompositeElementLite class may use it when adding methods to the class.
  10822. *
  10823. * For example to add the `nextAll` method to the class to **add** all following siblings of selected elements,
  10824. * the code would be
  10825. *
  10826. * Ext.override(Ext.dom.CompositeElementLite, {
  10827. * nextAll: function() {
  10828. * var elements = this.elements, i, l = elements.length, n, r = [], ri = -1;
  10829. *
  10830. * // Loop through all elements in this Composite, accumulating
  10831. * // an Array of all siblings.
  10832. * for (i = 0; i < l; i++) {
  10833. * for (n = elements[i].nextSibling; n; n = n.nextSibling) {
  10834. * r[++ri] = n;
  10835. * }
  10836. * }
  10837. *
  10838. * // Add all found siblings to this Composite
  10839. * return this.add(r);
  10840. * }
  10841. * });
  10842. *
  10843. * @readonly
  10844. */
  10845. this.elements = [];
  10846. this.add(elements, root);
  10847. this.el = new Ext.dom.AbstractElement.Fly();
  10848. },
  10849. /**
  10850. * @property {Boolean} isComposite
  10851. * `true` in this class to identify an object as an instantiated CompositeElement, or subclass thereof.
  10852. */
  10853. isComposite: true,
  10854. // private
  10855. getElement: function(el) {
  10856. // Set the shared flyweight dom property to the current element
  10857. return this.el.attach(el);
  10858. },
  10859. // private
  10860. transformElement: function(el) {
  10861. return Ext.getDom(el);
  10862. },
  10863. /**
  10864. * Returns the number of elements in this Composite.
  10865. * @return {Number}
  10866. */
  10867. getCount: function() {
  10868. return this.elements.length;
  10869. },
  10870. /**
  10871. * Adds elements to this Composite object.
  10872. * @param {HTMLElement[]/Ext.dom.CompositeElement} els Either an Array of DOM elements to add, or another Composite
  10873. * object who's elements should be added.
  10874. * @return {Ext.dom.CompositeElement} This Composite object.
  10875. */
  10876. add: function(els, root) {
  10877. var elements = this.elements,
  10878. i, ln;
  10879. if (!els) {
  10880. return this;
  10881. }
  10882. if (typeof els == "string") {
  10883. els = Ext.dom.Element.selectorFunction(els, root);
  10884. }
  10885. else if (els.isComposite) {
  10886. els = els.elements;
  10887. }
  10888. else if (!Ext.isIterable(els)) {
  10889. els = [els];
  10890. }
  10891. for (i = 0, ln = els.length; i < ln; ++i) {
  10892. elements.push(this.transformElement(els[i]));
  10893. }
  10894. return this;
  10895. },
  10896. invoke: function(fn, args) {
  10897. var elements = this.elements,
  10898. ln = elements.length,
  10899. element,
  10900. i;
  10901. fn = Ext.dom.Element.prototype[fn];
  10902. for (i = 0; i < ln; i++) {
  10903. element = elements[i];
  10904. if (element) {
  10905. fn.apply(this.getElement(element), args);
  10906. }
  10907. }
  10908. return this;
  10909. },
  10910. /**
  10911. * Returns a flyweight Element of the dom element object at the specified index
  10912. * @param {Number} index
  10913. * @return {Ext.dom.Element}
  10914. */
  10915. item: function(index) {
  10916. var el = this.elements[index],
  10917. out = null;
  10918. if (el) {
  10919. out = this.getElement(el);
  10920. }
  10921. return out;
  10922. },
  10923. // fixes scope with flyweight
  10924. addListener: function(eventName, handler, scope, opt) {
  10925. var els = this.elements,
  10926. len = els.length,
  10927. i, e;
  10928. for (i = 0; i < len; i++) {
  10929. e = els[i];
  10930. if (e) {
  10931. Ext.EventManager.on(e, eventName, handler, scope || e, opt);
  10932. }
  10933. }
  10934. return this;
  10935. },
  10936. /**
  10937. * Calls the passed function for each element in this composite.
  10938. * @param {Function} fn The function to call.
  10939. * @param {Ext.dom.Element} fn.el The current Element in the iteration. **This is the flyweight
  10940. * (shared) Ext.dom.Element instance, so if you require a a reference to the dom node, use el.dom.**
  10941. * @param {Ext.dom.CompositeElement} fn.c This Composite object.
  10942. * @param {Number} fn.index The zero-based index in the iteration.
  10943. * @param {Object} [scope] The scope (this reference) in which the function is executed.
  10944. * Defaults to the Element.
  10945. * @return {Ext.dom.CompositeElement} this
  10946. */
  10947. each: function(fn, scope) {
  10948. var me = this,
  10949. els = me.elements,
  10950. len = els.length,
  10951. i, e;
  10952. for (i = 0; i < len; i++) {
  10953. e = els[i];
  10954. if (e) {
  10955. e = this.getElement(e);
  10956. if (fn.call(scope || e, e, me, i) === false) {
  10957. break;
  10958. }
  10959. }
  10960. }
  10961. return me;
  10962. },
  10963. /**
  10964. * Clears this Composite and adds the elements passed.
  10965. * @param {HTMLElement[]/Ext.dom.CompositeElement} els Either an array of DOM elements, or another Composite from which
  10966. * to fill this Composite.
  10967. * @return {Ext.dom.CompositeElement} this
  10968. */
  10969. fill: function(els) {
  10970. var me = this;
  10971. me.elements = [];
  10972. me.add(els);
  10973. return me;
  10974. },
  10975. /**
  10976. * Filters this composite to only elements that match the passed selector.
  10977. * @param {String/Function} selector A string CSS selector or a comparison function. The comparison function will be
  10978. * called with the following arguments:
  10979. * @param {Ext.dom.Element} selector.el The current DOM element.
  10980. * @param {Number} selector.index The current index within the collection.
  10981. * @return {Ext.dom.CompositeElement} this
  10982. */
  10983. filter: function(selector) {
  10984. var me = this,
  10985. els = me.elements,
  10986. len = els.length,
  10987. out = [],
  10988. i = 0,
  10989. isFunc = typeof selector == 'function',
  10990. add,
  10991. el;
  10992. for (; i < len; i++) {
  10993. el = els[i];
  10994. add = false;
  10995. if (el) {
  10996. el = me.getElement(el);
  10997. if (isFunc) {
  10998. add = selector.call(el, el, me, i) !== false;
  10999. } else {
  11000. add = el.is(selector);
  11001. }
  11002. if (add) {
  11003. out.push(me.transformElement(el));
  11004. }
  11005. }
  11006. }
  11007. me.elements = out;
  11008. return me;
  11009. },
  11010. /**
  11011. * Find the index of the passed element within the composite collection.
  11012. * @param {String/HTMLElement/Ext.Element/Number} el The id of an element, or an Ext.dom.Element, or an HtmlElement
  11013. * to find within the composite collection.
  11014. * @return {Number} The index of the passed Ext.dom.Element in the composite collection, or -1 if not found.
  11015. */
  11016. indexOf: function(el) {
  11017. return Ext.Array.indexOf(this.elements, this.transformElement(el));
  11018. },
  11019. /**
  11020. * Replaces the specified element with the passed element.
  11021. * @param {String/HTMLElement/Ext.Element/Number} el The id of an element, the Element itself, the index of the
  11022. * element in this composite to replace.
  11023. * @param {String/Ext.Element} replacement The id of an element or the Element itself.
  11024. * @param {Boolean} [domReplace] True to remove and replace the element in the document too.
  11025. * @return {Ext.dom.CompositeElement} this
  11026. */
  11027. replaceElement: function(el, replacement, domReplace) {
  11028. var index = !isNaN(el) ? el : this.indexOf(el),
  11029. d;
  11030. if (index > -1) {
  11031. replacement = Ext.getDom(replacement);
  11032. if (domReplace) {
  11033. d = this.elements[index];
  11034. d.parentNode.insertBefore(replacement, d);
  11035. Ext.removeNode(d);
  11036. }
  11037. Ext.Array.splice(this.elements, index, 1, replacement);
  11038. }
  11039. return this;
  11040. },
  11041. /**
  11042. * Removes all elements.
  11043. */
  11044. clear: function() {
  11045. this.elements = [];
  11046. },
  11047. addElements: function(els, root) {
  11048. if (!els) {
  11049. return this;
  11050. }
  11051. if (typeof els == "string") {
  11052. els = Ext.dom.Element.selectorFunction(els, root);
  11053. }
  11054. var yels = this.elements,
  11055. eLen = els.length,
  11056. e;
  11057. for (e = 0; e < eLen; e++) {
  11058. yels.push(Ext.get(els[e]));
  11059. }
  11060. return this;
  11061. },
  11062. /**
  11063. * Returns the first Element
  11064. * @return {Ext.dom.Element}
  11065. */
  11066. first: function() {
  11067. return this.item(0);
  11068. },
  11069. /**
  11070. * Returns the last Element
  11071. * @return {Ext.dom.Element}
  11072. */
  11073. last: function() {
  11074. return this.item(this.getCount() - 1);
  11075. },
  11076. /**
  11077. * Returns true if this composite contains the passed element
  11078. * @param {String/HTMLElement/Ext.Element/Number} el The id of an element, or an Ext.Element, or an HtmlElement to
  11079. * find within the composite collection.
  11080. * @return {Boolean}
  11081. */
  11082. contains: function(el) {
  11083. return this.indexOf(el) != -1;
  11084. },
  11085. /**
  11086. * Removes the specified element(s).
  11087. * @param {String/HTMLElement/Ext.Element/Number} el The id of an element, the Element itself, the index of the
  11088. * element in this composite or an array of any of those.
  11089. * @param {Boolean} [removeDom] True to also remove the element from the document
  11090. * @return {Ext.dom.CompositeElement} this
  11091. */
  11092. removeElement: function(keys, removeDom) {
  11093. keys = [].concat(keys);
  11094. var me = this,
  11095. elements = me.elements,
  11096. kLen = keys.length,
  11097. val, el, k;
  11098. for (k = 0; k < kLen; k++) {
  11099. val = keys[k];
  11100. if ((el = (elements[val] || elements[val = me.indexOf(val)]))) {
  11101. if (removeDom) {
  11102. if (el.dom) {
  11103. el.remove();
  11104. } else {
  11105. Ext.removeNode(el);
  11106. }
  11107. }
  11108. Ext.Array.erase(elements, val, 1);
  11109. }
  11110. }
  11111. return me;
  11112. }
  11113. }, function() {
  11114. this.importElementMethods();
  11115. this.prototype.on = this.prototype.addListener;
  11116. if (Ext.DomQuery){
  11117. Ext.dom.Element.selectorFunction = Ext.DomQuery.select;
  11118. }
  11119. /**
  11120. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  11121. * to be applied to many related elements in one statement through the returned
  11122. * {@link Ext.dom.CompositeElement CompositeElement} or
  11123. * {@link Ext.dom.CompositeElementLite CompositeElementLite} object.
  11124. * @param {String/HTMLElement[]} selector The CSS selector or an array of elements
  11125. * @param {HTMLElement/String} [root] The root element of the query or id of the root
  11126. * @return {Ext.dom.CompositeElementLite/Ext.dom.CompositeElement}
  11127. * @member Ext.dom.Element
  11128. * @method select
  11129. * @static
  11130. * @ignore
  11131. */
  11132. Ext.dom.Element.select = function(selector, root) {
  11133. var elements;
  11134. if (typeof selector == "string") {
  11135. elements = Ext.dom.Element.selectorFunction(selector, root);
  11136. }
  11137. else if (selector.length !== undefined) {
  11138. elements = selector;
  11139. }
  11140. else {
  11141. //<debug>
  11142. throw new Error("[Ext.select] Invalid selector specified: " + selector);
  11143. //</debug>
  11144. }
  11145. return new Ext.CompositeElementLite(elements);
  11146. };
  11147. /**
  11148. * @member Ext
  11149. * @method select
  11150. * @inheritdoc Ext.dom.Element#select
  11151. * @ignore
  11152. */
  11153. Ext.select = function() {
  11154. return Ext.dom.Element.select.apply(Ext.dom.Element, arguments);
  11155. };
  11156. });
  11157. /**
  11158. * @class Ext.dom.CompositeElement
  11159. * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter
  11160. * members, or to perform collective actions upon the whole set.</p>
  11161. * <p>Although they are not listed, this class supports all of the methods of {@link Ext.dom.Element} and
  11162. * {@link Ext.fx.Anim}. The methods from these classes will be performed on all the elements in this collection.</p>
  11163. * <p>All methods return <i>this</i> and can be chained.</p>
  11164. * Usage:
  11165. <pre><code>
  11166. var els = Ext.select("#some-el div.some-class", true);
  11167. // or select directly from an existing element
  11168. var el = Ext.get('some-el');
  11169. el.select('div.some-class', true);
  11170. els.setWidth(100); // all elements become 100 width
  11171. els.hide(true); // all elements fade out and hide
  11172. // or
  11173. els.setWidth(100).hide(true);
  11174. </code></pre>
  11175. */
  11176. Ext.define('Ext.dom.CompositeElement', {
  11177. alternateClassName: 'Ext.CompositeElement',
  11178. extend: 'Ext.dom.CompositeElementLite',
  11179. // private
  11180. getElement: function(el) {
  11181. // In this case just return it, since we already have a reference to it
  11182. return el;
  11183. },
  11184. // private
  11185. transformElement: function(el) {
  11186. return Ext.get(el);
  11187. }
  11188. }, function() {
  11189. /**
  11190. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  11191. * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
  11192. * {@link Ext.CompositeElementLite CompositeElementLite} object.
  11193. * @param {String/HTMLElement[]} selector The CSS selector or an array of elements
  11194. * @param {Boolean} [unique] true to create a unique Ext.Element for each element (defaults to a shared flyweight object)
  11195. * @param {HTMLElement/String} [root] The root element of the query or id of the root
  11196. * @return {Ext.CompositeElementLite/Ext.CompositeElement}
  11197. * @member Ext.dom.Element
  11198. * @method select
  11199. * @static
  11200. */
  11201. Ext.dom.Element.select = function(selector, unique, root) {
  11202. var elements;
  11203. if (typeof selector == "string") {
  11204. elements = Ext.dom.Element.selectorFunction(selector, root);
  11205. }
  11206. else if (selector.length !== undefined) {
  11207. elements = selector;
  11208. }
  11209. else {
  11210. //<debug>
  11211. throw new Error("[Ext.select] Invalid selector specified: " + selector);
  11212. //</debug>
  11213. }
  11214. return (unique === true) ? new Ext.CompositeElement(elements) : new Ext.CompositeElementLite(elements);
  11215. };
  11216. });
  11217. /**
  11218. * Shorthand of {@link Ext.Element#method-select}.
  11219. * @member Ext
  11220. * @method select
  11221. * @inheritdoc Ext.Element#select
  11222. */
  11223. Ext.select = Ext.Element.select;