jquery.js 145 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997
  1. /* prevent execution of jQuery if included more than once */
  2. if(typeof window.jQuery == "undefined") {
  3. /*
  4. * jQuery @VERSION - New Wave Javascript
  5. *
  6. * Copyright (c) 2007 John Resig (jquery.com)
  7. * Dual licensed under the MIT (MIT-LICENSE.txt)
  8. * and GPL (GPL-LICENSE.txt) licenses.
  9. *
  10. * $Date$
  11. * $Rev: 1173 $
  12. */
  13. // Global undefined variable
  14. window.undefined = window.undefined;
  15. /**
  16. * Create a new jQuery Object
  17. *
  18. * @constructor
  19. * @private
  20. * @name jQuery
  21. * @param String|Function|Element|Array<Element>|jQuery a selector
  22. * @param jQuery|Element|Array<Element> c context
  23. * @cat Core
  24. */
  25. var jQuery = function(a,c) {
  26. // If the context is global, return a new object
  27. if ( window == this )
  28. return new jQuery(a,c);
  29. // Make sure that a selection was provided
  30. a = a || document;
  31. // HANDLE: $(function)
  32. // Shortcut for document ready
  33. if ( jQuery.isFunction(a) )
  34. return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
  35. // Handle HTML strings
  36. if ( typeof a == "string" ) {
  37. // HANDLE: $(html) -> $(array)
  38. var m = /^[^<]*(<(.|\n)+>)[^>]*$/.exec(a);
  39. if ( m )
  40. a = jQuery.clean( [ m[1] ] );
  41. // HANDLE: $(expr)
  42. else
  43. return new jQuery( c ).find( a );
  44. }
  45. return this.setArray(
  46. // HANDLE: $(array)
  47. a.constructor == Array && a ||
  48. // HANDLE: $(arraylike)
  49. // Watch for when an array-like object is passed as the selector
  50. (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) ||
  51. // HANDLE: $(*)
  52. [ a ] );
  53. };
  54. // Map over the $ in case of overwrite
  55. if ( typeof $ != "undefined" )
  56. jQuery._$ = $;
  57. // Map the jQuery namespace to the '$' one
  58. var $ = jQuery;
  59. /**
  60. * This function accepts a string containing a CSS or
  61. * basic XPath selector which is then used to match a set of elements.
  62. *
  63. * The core functionality of jQuery centers around this function.
  64. * Everything in jQuery is based upon this, or uses this in some way.
  65. * The most basic use of this function is to pass in an expression
  66. * (usually consisting of CSS or XPath), which then finds all matching
  67. * elements.
  68. *
  69. * By default, $() looks for DOM elements within the context of the
  70. * current HTML document.
  71. *
  72. * @example $("div > p")
  73. * @desc Finds all p elements that are children of a div element.
  74. * @before <p>one</p> <div><p>two</p></div> <p>three</p>
  75. * @result [ <p>two</p> ]
  76. *
  77. * @example $("input:radio", document.forms[0])
  78. * @desc Searches for all inputs of type radio within the first form in the document
  79. *
  80. * @example $("div", xml.responseXML)
  81. * @desc This finds all div elements within the specified XML document.
  82. *
  83. * @name $
  84. * @param String expr An expression to search with
  85. * @param Element|jQuery context (optional) A DOM Element, Document or jQuery to use as context
  86. * @cat Core
  87. * @type jQuery
  88. * @see $(Element)
  89. * @see $(Element<Array>)
  90. */
  91. /**
  92. * Create DOM elements on-the-fly from the provided String of raw HTML.
  93. *
  94. * @example $("<div><p>Hello</p></div>").appendTo("#body")
  95. * @desc Creates a div element (and all of its contents) dynamically,
  96. * and appends it to the element with the ID of body. Internally, an
  97. * element is created and it's innerHTML property set to the given markup.
  98. * It is therefore both quite flexible and limited.
  99. *
  100. * @name $
  101. * @param String html A string of HTML to create on the fly.
  102. * @cat Core
  103. * @type jQuery
  104. * @see appendTo(String)
  105. */
  106. /**
  107. * Wrap jQuery functionality around a single or multiple DOM Element(s).
  108. *
  109. * This function also accepts XML Documents and Window objects
  110. * as valid arguments (even though they are not DOM Elements).
  111. *
  112. * @example $(document.body).background( "black" );
  113. * @desc Sets the background color of the page to black.
  114. *
  115. * @example $( myForm.elements ).hide()
  116. * @desc Hides all the input elements within a form
  117. *
  118. * @name $
  119. * @param Element|Array<Element> elems DOM element(s) to be encapsulated by a jQuery object.
  120. * @cat Core
  121. * @type jQuery
  122. */
  123. /**
  124. * A shorthand for $(document).ready(), allowing you to bind a function
  125. * to be executed when the DOM document has finished loading. This function
  126. * behaves just like $(document).ready(), in that it should be used to wrap
  127. * all of the other $() operations on your page. While this function is,
  128. * technically, chainable - there really isn't much use for chaining against it.
  129. * You can have as many $(document).ready events on your page as you like.
  130. *
  131. * See ready(Function) for details about the ready event.
  132. *
  133. * @example $(function(){
  134. * // Document is ready
  135. * });
  136. * @desc Executes the function when the DOM is ready to be used.
  137. *
  138. * @example jQuery(function($) {
  139. * // Your code using failsafe $ alias here...
  140. * });
  141. * @desc Uses both the shortcut for $(document).ready() and the argument
  142. * to write failsafe jQuery code using the $ alias, without relying on the
  143. * global alias.
  144. *
  145. * @name $
  146. * @param Function fn The function to execute when the DOM is ready.
  147. * @cat Core
  148. * @type jQuery
  149. * @see ready(Function)
  150. */
  151. jQuery.fn = jQuery.prototype = {
  152. /**
  153. * The current version of jQuery.
  154. *
  155. * @private
  156. * @property
  157. * @name jquery
  158. * @type String
  159. * @cat Core
  160. */
  161. jquery: "@VERSION",
  162. /**
  163. * The number of elements currently matched.
  164. *
  165. * @example $("img").length;
  166. * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
  167. * @result 2
  168. *
  169. * @property
  170. * @name length
  171. * @type Number
  172. * @cat Core
  173. */
  174. /**
  175. * The number of elements currently matched.
  176. *
  177. * @example $("img").size();
  178. * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
  179. * @result 2
  180. *
  181. * @name size
  182. * @type Number
  183. * @cat Core
  184. */
  185. size: function() {
  186. return this.length;
  187. },
  188. length: 0,
  189. /**
  190. * Access all matched elements. This serves as a backwards-compatible
  191. * way of accessing all matched elements (other than the jQuery object
  192. * itself, which is, in fact, an array of elements).
  193. *
  194. * @example $("img").get();
  195. * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
  196. * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
  197. * @desc Selects all images in the document and returns the DOM Elements as an Array
  198. *
  199. * @name get
  200. * @type Array<Element>
  201. * @cat Core
  202. */
  203. /**
  204. * Access a single matched element. num is used to access the
  205. * Nth element matched.
  206. *
  207. * @example $("img").get(0);
  208. * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
  209. * @result [ <img src="test1.jpg"/> ]
  210. * @desc Selects all images in the document and returns the first one
  211. *
  212. * @name get
  213. * @type Element
  214. * @param Number num Access the element in the Nth position.
  215. * @cat Core
  216. */
  217. get: function( num ) {
  218. return num == undefined ?
  219. // Return a 'clean' array
  220. jQuery.makeArray( this ) :
  221. // Return just the object
  222. this[num];
  223. },
  224. /**
  225. * Set the jQuery object to an array of elements, while maintaining
  226. * the stack.
  227. *
  228. * @example $("img").pushStack([ document.body ]);
  229. * @result $("img").pushStack() == [ document.body ]
  230. *
  231. * @private
  232. * @name pushStack
  233. * @type jQuery
  234. * @param Elements elems An array of elements
  235. * @cat Core
  236. */
  237. pushStack: function( a ) {
  238. var ret = jQuery(a);
  239. ret.prevObject = this;
  240. return ret;
  241. },
  242. /**
  243. * Set the jQuery object to an array of elements. This operation is
  244. * completely destructive - be sure to use .pushStack() if you wish to maintain
  245. * the jQuery stack.
  246. *
  247. * @example $("img").setArray([ document.body ]);
  248. * @result $("img").setArray() == [ document.body ]
  249. *
  250. * @private
  251. * @name setArray
  252. * @type jQuery
  253. * @param Elements elems An array of elements
  254. * @cat Core
  255. */
  256. setArray: function( a ) {
  257. this.length = 0;
  258. [].push.apply( this, a );
  259. return this;
  260. },
  261. /**
  262. * Execute a function within the context of every matched element.
  263. * This means that every time the passed-in function is executed
  264. * (which is once for every element matched) the 'this' keyword
  265. * points to the specific element.
  266. *
  267. * Additionally, the function, when executed, is passed a single
  268. * argument representing the position of the element in the matched
  269. * set.
  270. *
  271. * @example $("img").each(function(i){
  272. * this.src = "test" + i + ".jpg";
  273. * });
  274. * @before <img/><img/>
  275. * @result <img src="test0.jpg"/><img src="test1.jpg"/>
  276. * @desc Iterates over two images and sets their src property
  277. *
  278. * @name each
  279. * @type jQuery
  280. * @param Function fn A function to execute
  281. * @cat Core
  282. */
  283. each: function( fn, args ) {
  284. return jQuery.each( this, fn, args );
  285. },
  286. /**
  287. * Searches every matched element for the object and returns
  288. * the index of the element, if found, starting with zero.
  289. * Returns -1 if the object wasn't found.
  290. *
  291. * @example $("*").index( $('#foobar')[0] )
  292. * @before <div id="foobar"><b></b><span id="foo"></span></div>
  293. * @result 0
  294. * @desc Returns the index for the element with ID foobar
  295. *
  296. * @example $("*").index( $('#foo')[0] )
  297. * @before <div id="foobar"><b></b><span id="foo"></span></div>
  298. * @result 2
  299. * @desc Returns the index for the element with ID foo within another element
  300. *
  301. * @example $("*").index( $('#bar')[0] )
  302. * @before <div id="foobar"><b></b><span id="foo"></span></div>
  303. * @result -1
  304. * @desc Returns -1, as there is no element with ID bar
  305. *
  306. * @name index
  307. * @type Number
  308. * @param Element subject Object to search for
  309. * @cat Core
  310. */
  311. index: function( obj ) {
  312. var pos = -1;
  313. this.each(function(i){
  314. if ( this == obj ) pos = i;
  315. });
  316. return pos;
  317. },
  318. /**
  319. * Access a property on the first matched element.
  320. * This method makes it easy to retrieve a property value
  321. * from the first matched element.
  322. *
  323. * @example $("img").attr("src");
  324. * @before <img src="test.jpg"/>
  325. * @result test.jpg
  326. * @desc Returns the src attribute from the first image in the document.
  327. *
  328. * @name attr
  329. * @type Object
  330. * @param String name The name of the property to access.
  331. * @cat DOM/Attributes
  332. */
  333. /**
  334. * Set a key/value object as properties to all matched elements.
  335. *
  336. * This serves as the best way to set a large number of properties
  337. * on all matched elements.
  338. *
  339. * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
  340. * @before <img/>
  341. * @result <img src="test.jpg" alt="Test Image"/>
  342. * @desc Sets src and alt attributes to all images.
  343. *
  344. * @name attr
  345. * @type jQuery
  346. * @param Map properties Key/value pairs to set as object properties.
  347. * @cat DOM/Attributes
  348. */
  349. /**
  350. * Set a single property to a value, on all matched elements.
  351. *
  352. * Can compute values provided as ${formula}, see second example.
  353. *
  354. * Note that you can't set the name property of input elements in IE.
  355. * Use $(html) or .append(html) or .html(html) to create elements
  356. * on the fly including the name property.
  357. *
  358. * @example $("img").attr("src","test.jpg");
  359. * @before <img/>
  360. * @result <img src="test.jpg"/>
  361. * @desc Sets src attribute to all images.
  362. *
  363. * @example $("img").attr("title", "${this.src}");
  364. * @before <img src="test.jpg" />
  365. * @result <img src="test.jpg" title="test.jpg" />
  366. * @desc Sets title attribute from src attribute, a shortcut for attr(String,Function)
  367. *
  368. * @name attr
  369. * @type jQuery
  370. * @param String key The name of the property to set.
  371. * @param Object value The value to set the property to.
  372. * @cat DOM/Attributes
  373. */
  374. /**
  375. * Set a single property to a computed value, on all matched elements.
  376. *
  377. * Instead of a value, a function is provided, that computes the value.
  378. *
  379. * @example $("img").attr("title", function() { return this.src });
  380. * @before <img src="test.jpg" />
  381. * @result <img src="test.jpg" title="test.jpg" />
  382. * @desc Sets title attribute from src attribute.
  383. *
  384. * @example $("img").attr("title", function(index) { return this.title + (i + 1); });
  385. * @before <img title="pic" /><img title="pic" /><img title="pic" />
  386. * @result <img title="pic1" /><img title="pic2" /><img title="pic3" />
  387. * @desc Enumerate title attribute.
  388. *
  389. * @name attr
  390. * @type jQuery
  391. * @param String key The name of the property to set.
  392. * @param Function value A function returning the value to set.
  393. * Scope: Current element, argument: Index of current element
  394. * @cat DOM/Attributes
  395. */
  396. attr: function( key, value, type ) {
  397. var obj = key;
  398. // Look for the case where we're accessing a style value
  399. if ( key.constructor == String )
  400. if ( value == undefined )
  401. return this.length && jQuery[ type || "attr" ]( this[0], key ) || undefined;
  402. else {
  403. obj = {};
  404. obj[ key ] = value;
  405. }
  406. // Check to see if we're setting style values
  407. return this.each(function(index){
  408. // Set all the styles
  409. for ( var prop in obj )
  410. jQuery.attr(
  411. type ? this.style : this,
  412. prop, jQuery.prop(this, obj[prop], type, index, prop)
  413. );
  414. });
  415. },
  416. /**
  417. * Access a style property on the first matched element.
  418. * This method makes it easy to retrieve a style property value
  419. * from the first matched element.
  420. *
  421. * @example $("p").css("color");
  422. * @before <p style="color:red;">Test Paragraph.</p>
  423. * @result "red"
  424. * @desc Retrieves the color style of the first paragraph
  425. *
  426. * @example $("p").css("font-weight");
  427. * @before <p style="font-weight: bold;">Test Paragraph.</p>
  428. * @result "bold"
  429. * @desc Retrieves the font-weight style of the first paragraph.
  430. *
  431. * @name css
  432. * @type String
  433. * @param String name The name of the property to access.
  434. * @cat CSS
  435. */
  436. /**
  437. * Set a key/value object as style properties to all matched elements.
  438. *
  439. * This serves as the best way to set a large number of style properties
  440. * on all matched elements.
  441. *
  442. * @example $("p").css({ color: "red", background: "blue" });
  443. * @before <p>Test Paragraph.</p>
  444. * @result <p style="color:red; background:blue;">Test Paragraph.</p>
  445. * @desc Sets color and background styles to all p elements.
  446. *
  447. * @name css
  448. * @type jQuery
  449. * @param Map properties Key/value pairs to set as style properties.
  450. * @cat CSS
  451. */
  452. /**
  453. * Set a single style property to a value, on all matched elements.
  454. * If a number is provided, it is automatically converted into a pixel value.
  455. *
  456. * @example $("p").css("color","red");
  457. * @before <p>Test Paragraph.</p>
  458. * @result <p style="color:red;">Test Paragraph.</p>
  459. * @desc Changes the color of all paragraphs to red
  460. *
  461. * @example $("p").css("left",30);
  462. * @before <p>Test Paragraph.</p>
  463. * @result <p style="left:30px;">Test Paragraph.</p>
  464. * @desc Changes the left of all paragraphs to "30px"
  465. *
  466. * @name css
  467. * @type jQuery
  468. * @param String key The name of the property to set.
  469. * @param String|Number value The value to set the property to.
  470. * @cat CSS
  471. */
  472. css: function( key, value ) {
  473. return this.attr( key, value, "curCSS" );
  474. },
  475. /**
  476. * Get the text contents of all matched elements. The result is
  477. * a string that contains the combined text contents of all matched
  478. * elements. This method works on both HTML and XML documents.
  479. *
  480. * @example $("p").text();
  481. * @before <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p>
  482. * @result Test Paragraph.Paraparagraph
  483. * @desc Gets the concatenated text of all paragraphs
  484. *
  485. * @name text
  486. * @type String
  487. * @cat DOM/Attributes
  488. */
  489. /**
  490. * Set the text contents of all matched elements.
  491. *
  492. * Similar to html(), but escapes HTML (replace "<" and ">" with their
  493. * HTML entities).
  494. *
  495. * @example $("p").text("<b>Some</b> new text.");
  496. * @before <p>Test Paragraph.</p>
  497. * @result <p>&lt;b&gt;Some&lt;/b&gt; new text.</p>
  498. * @desc Sets the text of all paragraphs.
  499. *
  500. * @example $("p").text("<b>Some</b> new text.", true);
  501. * @before <p>Test Paragraph.</p>
  502. * @result <p>Some new text.</p>
  503. * @desc Sets the text of all paragraphs.
  504. *
  505. * @name text
  506. * @type String
  507. * @param String val The text value to set the contents of the element to.
  508. * @cat DOM/Attributes
  509. */
  510. text: function(e) {
  511. if ( typeof e == "string" )
  512. return this.empty().append( document.createTextNode( e ) );
  513. var t = "";
  514. jQuery.each( e || this, function(){
  515. jQuery.each( this.childNodes, function(){
  516. if ( this.nodeType != 8 )
  517. t += this.nodeType != 1 ?
  518. this.nodeValue : jQuery.fn.text([ this ]);
  519. });
  520. });
  521. return t;
  522. },
  523. /**
  524. * Wrap all matched elements with a structure of other elements.
  525. * This wrapping process is most useful for injecting additional
  526. * stucture into a document, without ruining the original semantic
  527. * qualities of a document.
  528. *
  529. * This works by going through the first element
  530. * provided (which is generated, on the fly, from the provided HTML)
  531. * and finds the deepest ancestor element within its
  532. * structure - it is that element that will en-wrap everything else.
  533. *
  534. * This does not work with elements that contain text. Any necessary text
  535. * must be added after the wrapping is done.
  536. *
  537. * @example $("p").wrap("<div class='wrap'></div>");
  538. * @before <p>Test Paragraph.</p>
  539. * @result <div class='wrap'><p>Test Paragraph.</p></div>
  540. *
  541. * @name wrap
  542. * @type jQuery
  543. * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
  544. * @cat DOM/Manipulation
  545. */
  546. /**
  547. * Wrap all matched elements with a structure of other elements.
  548. * This wrapping process is most useful for injecting additional
  549. * stucture into a document, without ruining the original semantic
  550. * qualities of a document.
  551. *
  552. * This works by going through the first element
  553. * provided and finding the deepest ancestor element within its
  554. * structure - it is that element that will en-wrap everything else.
  555. *
  556. * This does not work with elements that contain text. Any necessary text
  557. * must be added after the wrapping is done.
  558. *
  559. * @example $("p").wrap( document.getElementById('content') );
  560. * @before <p>Test Paragraph.</p><div id="content"></div>
  561. * @result <div id="content"><p>Test Paragraph.</p></div>
  562. *
  563. * @name wrap
  564. * @type jQuery
  565. * @param Element elem A DOM element that will be wrapped around the target.
  566. * @cat DOM/Manipulation
  567. */
  568. wrap: function() {
  569. // The elements to wrap the target around
  570. var a = jQuery.clean(arguments);
  571. // Wrap each of the matched elements individually
  572. return this.each(function(){
  573. // Clone the structure that we're using to wrap
  574. var b = a[0].cloneNode(true);
  575. // Insert it before the element to be wrapped
  576. this.parentNode.insertBefore( b, this );
  577. // Find the deepest point in the wrap structure
  578. while ( b.firstChild )
  579. b = b.firstChild;
  580. // Move the matched element to within the wrap structure
  581. b.appendChild( this );
  582. });
  583. },
  584. /**
  585. * Append content to the inside of every matched element.
  586. *
  587. * This operation is similar to doing an appendChild to all the
  588. * specified elements, adding them into the document.
  589. *
  590. * @example $("p").append("<b>Hello</b>");
  591. * @before <p>I would like to say: </p>
  592. * @result <p>I would like to say: <b>Hello</b></p>
  593. * @desc Appends some HTML to all paragraphs.
  594. *
  595. * @example $("p").append( $("#foo")[0] );
  596. * @before <p>I would like to say: </p><b id="foo">Hello</b>
  597. * @result <p>I would like to say: <b id="foo">Hello</b></p>
  598. * @desc Appends an Element to all paragraphs.
  599. *
  600. * @example $("p").append( $("b") );
  601. * @before <p>I would like to say: </p><b>Hello</b>
  602. * @result <p>I would like to say: <b>Hello</b></p>
  603. * @desc Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
  604. *
  605. * @name append
  606. * @type jQuery
  607. * @param <Content> content Content to append to the target
  608. * @cat DOM/Manipulation
  609. * @see prepend(<Content>)
  610. * @see before(<Content>)
  611. * @see after(<Content>)
  612. */
  613. append: function() {
  614. return this.domManip(arguments, true, 1, function(a){
  615. this.appendChild( a );
  616. });
  617. },
  618. /**
  619. * Prepend content to the inside of every matched element.
  620. *
  621. * This operation is the best way to insert elements
  622. * inside, at the beginning, of all matched elements.
  623. *
  624. * @example $("p").prepend("<b>Hello</b>");
  625. * @before <p>I would like to say: </p>
  626. * @result <p><b>Hello</b>I would like to say: </p>
  627. * @desc Prepends some HTML to all paragraphs.
  628. *
  629. * @example $("p").prepend( $("#foo")[0] );
  630. * @before <p>I would like to say: </p><b id="foo">Hello</b>
  631. * @result <p><b id="foo">Hello</b>I would like to say: </p>
  632. * @desc Prepends an Element to all paragraphs.
  633. *
  634. * @example $("p").prepend( $("b") );
  635. * @before <p>I would like to say: </p><b>Hello</b>
  636. * @result <p><b>Hello</b>I would like to say: </p>
  637. * @desc Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
  638. *
  639. * @name prepend
  640. * @type jQuery
  641. * @param <Content> content Content to prepend to the target.
  642. * @cat DOM/Manipulation
  643. * @see append(<Content>)
  644. * @see before(<Content>)
  645. * @see after(<Content>)
  646. */
  647. prepend: function() {
  648. return this.domManip(arguments, true, -1, function(a){
  649. this.insertBefore( a, this.firstChild );
  650. });
  651. },
  652. /**
  653. * Insert content before each of the matched elements.
  654. *
  655. * @example $("p").before("<b>Hello</b>");
  656. * @before <p>I would like to say: </p>
  657. * @result <b>Hello</b><p>I would like to say: </p>
  658. * @desc Inserts some HTML before all paragraphs.
  659. *
  660. * @example $("p").before( $("#foo")[0] );
  661. * @before <p>I would like to say: </p><b id="foo">Hello</b>
  662. * @result <b id="foo">Hello</b><p>I would like to say: </p>
  663. * @desc Inserts an Element before all paragraphs.
  664. *
  665. * @example $("p").before( $("b") );
  666. * @before <p>I would like to say: </p><b>Hello</b>
  667. * @result <b>Hello</b><p>I would like to say: </p>
  668. * @desc Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.
  669. *
  670. * @name before
  671. * @type jQuery
  672. * @param <Content> content Content to insert before each target.
  673. * @cat DOM/Manipulation
  674. * @see append(<Content>)
  675. * @see prepend(<Content>)
  676. * @see after(<Content>)
  677. */
  678. before: function() {
  679. return this.domManip(arguments, false, 1, function(a){
  680. this.parentNode.insertBefore( a, this );
  681. });
  682. },
  683. /**
  684. * Insert content after each of the matched elements.
  685. *
  686. * @example $("p").after("<b>Hello</b>");
  687. * @before <p>I would like to say: </p>
  688. * @result <p>I would like to say: </p><b>Hello</b>
  689. * @desc Inserts some HTML after all paragraphs.
  690. *
  691. * @example $("p").after( $("#foo")[0] );
  692. * @before <b id="foo">Hello</b><p>I would like to say: </p>
  693. * @result <p>I would like to say: </p><b id="foo">Hello</b>
  694. * @desc Inserts an Element after all paragraphs.
  695. *
  696. * @example $("p").after( $("b") );
  697. * @before <b>Hello</b><p>I would like to say: </p>
  698. * @result <p>I would like to say: </p><b>Hello</b>
  699. * @desc Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
  700. *
  701. * @name after
  702. * @type jQuery
  703. * @param <Content> content Content to insert after each target.
  704. * @cat DOM/Manipulation
  705. * @see append(<Content>)
  706. * @see prepend(<Content>)
  707. * @see before(<Content>)
  708. */
  709. after: function() {
  710. return this.domManip(arguments, false, -1, function(a){
  711. this.parentNode.insertBefore( a, this.nextSibling );
  712. });
  713. },
  714. /**
  715. * End the most recent 'destructive' operation, reverting the list of matched elements
  716. * back to its previous state. After an end operation, the list of matched elements will
  717. * revert to the last state of matched elements.
  718. *
  719. * If there was no destructive operation before, an empty set is returned.
  720. *
  721. * @example $("p").find("span").end();
  722. * @before <p><span>Hello</span>, how are you?</p>
  723. * @result [ <p>...</p> ]
  724. * @desc Selects all paragraphs, finds span elements inside these, and reverts the
  725. * selection back to the paragraphs.
  726. *
  727. * @name end
  728. * @type jQuery
  729. * @cat DOM/Traversing
  730. */
  731. end: function() {
  732. return this.prevObject || jQuery([]);
  733. },
  734. /**
  735. * Searches for all elements that match the specified expression.
  736. * This method is a good way to find additional descendant
  737. * elements with which to process.
  738. *
  739. * All searching is done using a jQuery expression. The expression can be
  740. * written using CSS 1-3 Selector syntax, or basic XPath.
  741. *
  742. * @example $("p").find("span");
  743. * @before <p><span>Hello</span>, how are you?</p>
  744. * @result [ <span>Hello</span> ]
  745. * @desc Starts with all paragraphs and searches for descendant span
  746. * elements, same as $("p span")
  747. *
  748. * @name find
  749. * @type jQuery
  750. * @param String expr An expression to search with.
  751. * @cat DOM/Traversing
  752. */
  753. find: function(t) {
  754. return this.pushStack( jQuery.map( this, function(a){
  755. return jQuery.find(t,a);
  756. }), t );
  757. },
  758. /**
  759. * Clone matched DOM Elements and select the clones.
  760. *
  761. * This is useful for moving copies of the elements to another
  762. * location in the DOM.
  763. *
  764. * @example $("b").clone().prependTo("p");
  765. * @before <b>Hello</b><p>, how are you?</p>
  766. * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
  767. * @desc Clones all b elements (and selects the clones) and prepends them to all paragraphs.
  768. *
  769. * @name clone
  770. * @type jQuery
  771. * @param Boolean deep (Optional) Set to false if you don't want to clone all descendant nodes, in addition to the element itself.
  772. * @cat DOM/Manipulation
  773. */
  774. clone: function(deep) {
  775. return this.pushStack( jQuery.map( this, function(a){
  776. return a.cloneNode( deep != undefined ? deep : true );
  777. }) );
  778. },
  779. /**
  780. * Removes all elements from the set of matched elements that do not
  781. * match the specified expression(s). This method is used to narrow down
  782. * the results of a search.
  783. *
  784. * Provide a comma-separated list of expressions to apply multiple filters at once.
  785. *
  786. * @example $("p").filter(".selected")
  787. * @before <p class="selected">Hello</p><p>How are you?</p>
  788. * @result [ <p class="selected">Hello</p> ]
  789. * @desc Selects all paragraphs and removes those without a class "selected".
  790. *
  791. * @example $("p").filter(".selected, :first")
  792. * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
  793. * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
  794. * @desc Selects all paragraphs and removes those without class "selected" and being the first one.
  795. *
  796. * @name filter
  797. * @type jQuery
  798. * @param String expression Expression(s) to search with.
  799. * @cat DOM/Traversing
  800. */
  801. /**
  802. * Removes all elements from the set of matched elements that do not
  803. * pass the specified filter. This method is used to narrow down
  804. * the results of a search.
  805. *
  806. * @example $("p").filter(function(index) {
  807. * return $("ol", this).length == 0;
  808. * })
  809. * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
  810. * @result [ <p>How are you?</p> ]
  811. * @desc Remove all elements that have a child ol element
  812. *
  813. * @name filter
  814. * @type jQuery
  815. * @param Function filter A function to use for filtering
  816. * @cat DOM/Traversing
  817. */
  818. filter: function(t) {
  819. return this.pushStack(
  820. jQuery.isFunction( t ) &&
  821. jQuery.grep(this, function(el, index){
  822. return t.apply(el, [index])
  823. }) ||
  824. jQuery.multiFilter(t,this) );
  825. },
  826. /**
  827. * Removes the specified Element from the set of matched elements. This
  828. * method is used to remove a single Element from a jQuery object.
  829. *
  830. * @example $("p").not( $("#selected")[0] )
  831. * @before <p>Hello</p><p id="selected">Hello Again</p>
  832. * @result [ <p>Hello</p> ]
  833. * @desc Removes the element with the ID "selected" from the set of all paragraphs.
  834. *
  835. * @name not
  836. * @type jQuery
  837. * @param Element el An element to remove from the set
  838. * @cat DOM/Traversing
  839. */
  840. /**
  841. * Removes elements matching the specified expression from the set
  842. * of matched elements. This method is used to remove one or more
  843. * elements from a jQuery object.
  844. *
  845. * @example $("p").not("#selected")
  846. * @before <p>Hello</p><p id="selected">Hello Again</p>
  847. * @result [ <p>Hello</p> ]
  848. * @desc Removes the element with the ID "selected" from the set of all paragraphs.
  849. *
  850. * @name not
  851. * @type jQuery
  852. * @param String expr An expression with which to remove matching elements
  853. * @cat DOM/Traversing
  854. */
  855. /**
  856. * Removes any elements inside the array of elements from the set
  857. * of matched elements. This method is used to remove one or more
  858. * elements from a jQuery object.
  859. *
  860. * @example $("p").not( $("div p.selected") )
  861. * @before <div><p>Hello</p><p class="selected">Hello Again</p></div>
  862. * @result [ <p>Hello</p> ]
  863. * @desc Removes all elements that match "div p.selected" from the total set of all paragraphs.
  864. *
  865. * @name not
  866. * @type jQuery
  867. * @param jQuery elems A set of elements to remove from the jQuery set of matched elements.
  868. * @cat DOM/Traversing
  869. */
  870. not: function(t) {
  871. return this.pushStack(
  872. t.constructor == String &&
  873. jQuery.multiFilter(t, this, true) ||
  874. jQuery.grep(this, function(a) {
  875. return ( t.constructor == Array || t.jquery )
  876. ? jQuery.inArray( a, t ) < 0
  877. : a != t;
  878. })
  879. );
  880. },
  881. /**
  882. * Adds more elements, matched by the given expression,
  883. * to the set of matched elements.
  884. *
  885. * @example $("p").add("span")
  886. * @before <p>Hello</p><span>Hello Again</span>
  887. * @result [ <p>Hello</p>, <span>Hello Again</span> ]
  888. *
  889. * @name add
  890. * @type jQuery
  891. * @param String expr An expression whose matched elements are added
  892. * @cat DOM/Traversing
  893. */
  894. /**
  895. * Adds more elements, created on the fly, to the set of
  896. * matched elements.
  897. *
  898. * @example $("p").add("<span>Again</span>")
  899. * @before <p>Hello</p>
  900. * @result [ <p>Hello</p>, <span>Again</span> ]
  901. *
  902. * @name add
  903. * @type jQuery
  904. * @param String html A string of HTML to create on the fly.
  905. * @cat DOM/Traversing
  906. */
  907. /**
  908. * Adds one or more Elements to the set of matched elements.
  909. *
  910. * @example $("p").add( document.getElementById("a") )
  911. * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
  912. * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
  913. *
  914. * @example $("p").add( document.forms[0].elements )
  915. * @before <p>Hello</p><p><form><input/><button/></form>
  916. * @result [ <p>Hello</p>, <input/>, <button/> ]
  917. *
  918. * @name add
  919. * @type jQuery
  920. * @param Element|Array<Element> elements One or more Elements to add
  921. * @cat DOM/Traversing
  922. */
  923. add: function(t) {
  924. return this.pushStack( jQuery.merge(
  925. this.get(),
  926. t.constructor == String ?
  927. jQuery(t).get() :
  928. t.length != undefined && (!t.nodeName || t.nodeName == "FORM") ?
  929. t : [t] )
  930. );
  931. },
  932. /**
  933. * Checks the current selection against an expression and returns true,
  934. * if at least one element of the selection fits the given expression.
  935. *
  936. * Does return false, if no element fits or the expression is not valid.
  937. *
  938. * filter(String) is used internally, therefore all rules that apply there
  939. * apply here, too.
  940. *
  941. * @example $("input[@type='checkbox']").parent().is("form")
  942. * @before <form><input type="checkbox" /></form>
  943. * @result true
  944. * @desc Returns true, because the parent of the input is a form element
  945. *
  946. * @example $("input[@type='checkbox']").parent().is("form")
  947. * @before <form><p><input type="checkbox" /></p></form>
  948. * @result false
  949. * @desc Returns false, because the parent of the input is a p element
  950. *
  951. * @name is
  952. * @type Boolean
  953. * @param String expr The expression with which to filter
  954. * @cat DOM/Traversing
  955. */
  956. is: function(expr) {
  957. return expr ? jQuery.filter(expr,this).r.length > 0 : false;
  958. },
  959. /**
  960. * Get the current value of the first matched element.
  961. *
  962. * @example $("input").val();
  963. * @before <input type="text" value="some text"/>
  964. * @result "some text"
  965. *
  966. * @name val
  967. * @type String
  968. * @cat DOM/Attributes
  969. */
  970. /**
  971. * Set the value of every matched element.
  972. *
  973. * @example $("input").val("test");
  974. * @before <input type="text" value="some text"/>
  975. * @result <input type="text" value="test"/>
  976. *
  977. * @name val
  978. * @type jQuery
  979. * @param String val Set the property to the specified value.
  980. * @cat DOM/Attributes
  981. */
  982. val: function( val ) {
  983. return val == undefined ?
  984. ( this.length ? this[0].value : null ) :
  985. this.attr( "value", val );
  986. },
  987. /**
  988. * Get the html contents of the first matched element.
  989. * This property is not available on XML documents.
  990. *
  991. * @example $("div").html();
  992. * @before <div><input/></div>
  993. * @result <input/>
  994. *
  995. * @name html
  996. * @type String
  997. * @cat DOM/Attributes
  998. */
  999. /**
  1000. * Set the html contents of every matched element.
  1001. * This property is not available on XML documents.
  1002. *
  1003. * @example $("div").html("<b>new stuff</b>");
  1004. * @before <div><input/></div>
  1005. * @result <div><b>new stuff</b></div>
  1006. *
  1007. * @name html
  1008. * @type jQuery
  1009. * @param String val Set the html contents to the specified value.
  1010. * @cat DOM/Attributes
  1011. */
  1012. html: function( val ) {
  1013. return val == undefined ?
  1014. ( this.length ? this[0].innerHTML : null ) :
  1015. this.empty().append( val );
  1016. },
  1017. /**
  1018. * @private
  1019. * @name domManip
  1020. * @param Array args
  1021. * @param Boolean table Insert TBODY in TABLEs if one is not found.
  1022. * @param Number dir If dir<0, process args in reverse order.
  1023. * @param Function fn The function doing the DOM manipulation.
  1024. * @type jQuery
  1025. * @cat Core
  1026. */
  1027. domManip: function(args, table, dir, fn){
  1028. var clone = this.length > 1;
  1029. var a = jQuery.clean(args);
  1030. if ( dir < 0 )
  1031. a.reverse();
  1032. return this.each(function(){
  1033. var obj = this;
  1034. if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
  1035. obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
  1036. jQuery.each( a, function(){
  1037. fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
  1038. });
  1039. });
  1040. }
  1041. };
  1042. /**
  1043. * Extends the jQuery object itself. Can be used to add functions into
  1044. * the jQuery namespace and to add plugin methods (plugins).
  1045. *
  1046. * @example jQuery.fn.extend({
  1047. * check: function() {
  1048. * return this.each(function() { this.checked = true; });
  1049. * },
  1050. * uncheck: function() {
  1051. * return this.each(function() { this.checked = false; });
  1052. * }
  1053. * });
  1054. * $("input[@type=checkbox]").check();
  1055. * $("input[@type=radio]").uncheck();
  1056. * @desc Adds two plugin methods.
  1057. *
  1058. * @example jQuery.extend({
  1059. * min: function(a, b) { return a < b ? a : b; },
  1060. * max: function(a, b) { return a > b ? a : b; }
  1061. * });
  1062. * @desc Adds two functions into the jQuery namespace
  1063. *
  1064. * @name $.extend
  1065. * @param Object prop The object that will be merged into the jQuery object
  1066. * @type Object
  1067. * @cat Core
  1068. */
  1069. /**
  1070. * Extend one object with one or more others, returning the original,
  1071. * modified, object. This is a great utility for simple inheritance.
  1072. *
  1073. * @example var settings = { validate: false, limit: 5, name: "foo" };
  1074. * var options = { validate: true, name: "bar" };
  1075. * jQuery.extend(settings, options);
  1076. * @result settings == { validate: true, limit: 5, name: "bar" }
  1077. * @desc Merge settings and options, modifying settings
  1078. *
  1079. * @example var defaults = { validate: false, limit: 5, name: "foo" };
  1080. * var options = { validate: true, name: "bar" };
  1081. * var settings = jQuery.extend({}, defaults, options);
  1082. * @result settings == { validate: true, limit: 5, name: "bar" }
  1083. * @desc Merge defaults and options, without modifying the defaults
  1084. *
  1085. * @name $.extend
  1086. * @param Object target The object to extend
  1087. * @param Object prop1 The object that will be merged into the first.
  1088. * @param Object propN (optional) More objects to merge into the first
  1089. * @type Object
  1090. * @cat JavaScript
  1091. */
  1092. jQuery.extend = jQuery.fn.extend = function() {
  1093. // copy reference to target object
  1094. var target = arguments[0],
  1095. a = 1;
  1096. // extend jQuery itself if only one argument is passed
  1097. if ( arguments.length == 1 ) {
  1098. target = this;
  1099. a = 0;
  1100. }
  1101. var prop;
  1102. while (prop = arguments[a++])
  1103. // Extend the base object
  1104. for ( var i in prop ) target[i] = prop[i];
  1105. // Return the modified object
  1106. return target;
  1107. };
  1108. jQuery.extend({
  1109. /**
  1110. * Run this function to give control of the $ variable back
  1111. * to whichever library first implemented it. This helps to make
  1112. * sure that jQuery doesn't conflict with the $ object
  1113. * of other libraries.
  1114. *
  1115. * By using this function, you will only be able to access jQuery
  1116. * using the 'jQuery' variable. For example, where you used to do
  1117. * $("div p"), you now must do jQuery("div p").
  1118. *
  1119. * @example jQuery.noConflict();
  1120. * // Do something with jQuery
  1121. * jQuery("div p").hide();
  1122. * // Do something with another library's $()
  1123. * $("content").style.display = 'none';
  1124. * @desc Maps the original object that was referenced by $ back to $
  1125. *
  1126. * @example jQuery.noConflict();
  1127. * (function($) {
  1128. * $(function() {
  1129. * // more code using $ as alias to jQuery
  1130. * });
  1131. * })(jQuery);
  1132. * // other code using $ as an alias to the other library
  1133. * @desc Reverts the $ alias and then creates and executes a
  1134. * function to provide the $ as a jQuery alias inside the functions
  1135. * scope. Inside the function the original $ object is not available.
  1136. * This works well for most plugins that don't rely on any other library.
  1137. *
  1138. *
  1139. * @name $.noConflict
  1140. * @type undefined
  1141. * @cat Core
  1142. */
  1143. noConflict: function() {
  1144. if ( jQuery._$ )
  1145. $ = jQuery._$;
  1146. return jQuery;
  1147. },
  1148. // This may seem like some crazy code, but trust me when I say that this
  1149. // is the only cross-browser way to do this. --John
  1150. isFunction: function( fn ) {
  1151. return !!fn && typeof fn != "string" &&
  1152. typeof fn[0] == "undefined" && /function/i.test( fn + "" );
  1153. },
  1154. nodeName: function( elem, name ) {
  1155. return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
  1156. },
  1157. /**
  1158. * A generic iterator function, which can be used to seemlessly
  1159. * iterate over both objects and arrays. This function is not the same
  1160. * as $().each() - which is used to iterate, exclusively, over a jQuery
  1161. * object. This function can be used to iterate over anything.
  1162. *
  1163. * The callback has two arguments:the key (objects) or index (arrays) as first
  1164. * the first, and the value as the second.
  1165. *
  1166. * @example $.each( [0,1,2], function(i, n){
  1167. * alert( "Item #" + i + ": " + n );
  1168. * });
  1169. * @desc This is an example of iterating over the items in an array,
  1170. * accessing both the current item and its index.
  1171. *
  1172. * @example $.each( { name: "John", lang: "JS" }, function(i, n){
  1173. * alert( "Name: " + i + ", Value: " + n );
  1174. * });
  1175. *
  1176. * @desc This is an example of iterating over the properties in an
  1177. * Object, accessing both the current item and its key.
  1178. *
  1179. * @name $.each
  1180. * @param Object obj The object, or array, to iterate over.
  1181. * @param Function fn The function that will be executed on every object.
  1182. * @type Object
  1183. * @cat JavaScript
  1184. */
  1185. // args is for internal usage only
  1186. each: function( obj, fn, args ) {
  1187. if ( obj.length == undefined )
  1188. for ( var i in obj )
  1189. fn.apply( obj[i], args || [i, obj[i]] );
  1190. else
  1191. for ( var i = 0, ol = obj.length; i < ol; i++ )
  1192. if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
  1193. return obj;
  1194. },
  1195. prop: function(elem, value, type, index, prop){
  1196. // Handle executable functions
  1197. if ( jQuery.isFunction( value ) )
  1198. return value.call( elem, [index] );
  1199. // exclude the following css properties to add px
  1200. var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
  1201. // Handle passing in a number to a CSS property
  1202. if ( value.constructor == Number && type == "curCSS" && !exclude.test(prop) )
  1203. return value + "px";
  1204. return value;
  1205. },
  1206. className: {
  1207. // internal only, use addClass("class")
  1208. add: function( elem, c ){
  1209. jQuery.each( c.split(/\s+/), function(i, cur){
  1210. if ( !jQuery.className.has( elem.className, cur ) )
  1211. elem.className += ( elem.className ? " " : "" ) + cur;
  1212. });
  1213. },
  1214. // internal only, use removeClass("class")
  1215. remove: function( elem, c ){
  1216. elem.className = c ?
  1217. jQuery.grep( elem.className.split(/\s+/), function(cur){
  1218. return !jQuery.className.has( c, cur );
  1219. }).join(" ") : "";
  1220. },
  1221. // internal only, use is(".class")
  1222. has: function( t, c ) {
  1223. t = t.className || t;
  1224. return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t );
  1225. }
  1226. },
  1227. /**
  1228. * Swap in/out style options.
  1229. * @private
  1230. */
  1231. swap: function(e,o,f) {
  1232. for ( var i in o ) {
  1233. e.style["old"+i] = e.style[i];
  1234. e.style[i] = o[i];
  1235. }
  1236. f.apply( e, [] );
  1237. for ( var i in o )
  1238. e.style[i] = e.style["old"+i];
  1239. },
  1240. css: function(e,p) {
  1241. if ( p == "height" || p == "width" ) {
  1242. var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
  1243. jQuery.each( d, function(){
  1244. old["padding" + this] = 0;
  1245. old["border" + this + "Width"] = 0;
  1246. });
  1247. jQuery.swap( e, old, function() {
  1248. if (jQuery.css(e,"display") != "none") {
  1249. oHeight = e.offsetHeight;
  1250. oWidth = e.offsetWidth;
  1251. } else {
  1252. e = jQuery(e.cloneNode(true))
  1253. .find(":radio").removeAttr("checked").end()
  1254. .css({
  1255. visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
  1256. }).appendTo(e.parentNode)[0];
  1257. var parPos = jQuery.css(e.parentNode,"position");
  1258. if ( parPos == "" || parPos == "static" )
  1259. e.parentNode.style.position = "relative";
  1260. oHeight = e.clientHeight;
  1261. oWidth = e.clientWidth;
  1262. if ( parPos == "" || parPos == "static" )
  1263. e.parentNode.style.position = "static";
  1264. e.parentNode.removeChild(e);
  1265. }
  1266. });
  1267. return p == "height" ? oHeight : oWidth;
  1268. }
  1269. return jQuery.curCSS( e, p );
  1270. },
  1271. curCSS: function(elem, prop, force) {
  1272. var ret;
  1273. if (prop == "opacity" && jQuery.browser.msie)
  1274. return jQuery.attr(elem.style, "opacity");
  1275. if (prop == "float" || prop == "cssFloat")
  1276. prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
  1277. if (!force && elem.style[prop])
  1278. ret = elem.style[prop];
  1279. else if (document.defaultView && document.defaultView.getComputedStyle) {
  1280. if (prop == "cssFloat" || prop == "styleFloat")
  1281. prop = "float";
  1282. prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
  1283. var cur = document.defaultView.getComputedStyle(elem, null);
  1284. if ( cur )
  1285. ret = cur.getPropertyValue(prop);
  1286. else if ( prop == "display" )
  1287. ret = "none";
  1288. else
  1289. jQuery.swap(elem, { display: "block" }, function() {
  1290. var c = document.defaultView.getComputedStyle(this, "");
  1291. ret = c && c.getPropertyValue(prop) || "";
  1292. });
  1293. } else if (elem.currentStyle) {
  1294. var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
  1295. ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
  1296. }
  1297. return ret;
  1298. },
  1299. clean: function(a) {
  1300. var r = [];
  1301. jQuery.each( a, function(i,arg){
  1302. if ( !arg ) return;
  1303. if ( arg.constructor == Number )
  1304. arg = arg.toString();
  1305. // Convert html string into DOM nodes
  1306. if ( typeof arg == "string" ) {
  1307. // Trim whitespace, otherwise indexOf won't work as expected
  1308. var s = jQuery.trim(arg), div = document.createElement("div"), tb = [];
  1309. var wrap =
  1310. // option or optgroup
  1311. !s.indexOf("<opt") &&
  1312. [1, "<select>", "</select>"] ||
  1313. (!s.indexOf("<thead") || !s.indexOf("<tbody") || !s.indexOf("<tfoot")) &&
  1314. [1, "<table>", "</table>"] ||
  1315. !s.indexOf("<tr") &&
  1316. [2, "<table><tbody>", "</tbody></table>"] ||
  1317. // <thead> matched above
  1318. (!s.indexOf("<td") || !s.indexOf("<th")) &&
  1319. [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
  1320. [0,"",""];
  1321. // Go to html and back, then peel off extra wrappers
  1322. div.innerHTML = wrap[1] + s + wrap[2];
  1323. // Move to the right depth
  1324. while ( wrap[0]-- )
  1325. div = div.firstChild;
  1326. // Remove IE's autoinserted <tbody> from table fragments
  1327. if ( jQuery.browser.msie ) {
  1328. // String was a <table>, *may* have spurious <tbody>
  1329. if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 )
  1330. tb = div.firstChild && div.firstChild.childNodes;
  1331. // String was a bare <thead> or <tfoot>
  1332. else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
  1333. tb = div.childNodes;
  1334. for ( var n = tb.length-1; n >= 0 ; --n )
  1335. if ( jQuery.nodeName(tb[n], "tbody") && !tb[n].childNodes.length )
  1336. tb[n].parentNode.removeChild(tb[n]);
  1337. }
  1338. arg = div.childNodes;
  1339. }
  1340. if ( arg.length === 0 )
  1341. return;
  1342. if ( arg[0] == undefined )
  1343. r.push( arg );
  1344. else
  1345. r = jQuery.merge( r, arg );
  1346. });
  1347. return r;
  1348. },
  1349. attr: function(elem, name, value){
  1350. var fix = {
  1351. "for": "htmlFor",
  1352. "class": "className",
  1353. "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
  1354. cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
  1355. innerHTML: "innerHTML",
  1356. className: "className",
  1357. value: "value",
  1358. disabled: "disabled",
  1359. checked: "checked",
  1360. readonly: "readOnly",
  1361. selected: "selected"
  1362. };
  1363. // IE actually uses filters for opacity ... elem is actually elem.style
  1364. if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
  1365. // IE has trouble with opacity if it does not have layout
  1366. // Force it by setting the zoom level
  1367. elem.zoom = 1;
  1368. // Set the alpha filter to set the opacity
  1369. return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
  1370. ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
  1371. } else if ( name == "opacity" && jQuery.browser.msie )
  1372. return elem.filter ?
  1373. parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
  1374. // Mozilla doesn't play well with opacity 1
  1375. if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
  1376. value = 0.9999;
  1377. // Certain attributes only work when accessed via the old DOM 0 way
  1378. if ( fix[name] ) {
  1379. if ( value != undefined ) elem[fix[name]] = value;
  1380. return elem[fix[name]];
  1381. } else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName(elem, "form") && (name == "action" || name == "method") )
  1382. return elem.getAttributeNode(name).nodeValue;
  1383. // IE elem.getAttribute passes even for style
  1384. else if ( elem.tagName ) {
  1385. if ( value != undefined ) elem.setAttribute( name, value );
  1386. return elem.getAttribute( name );
  1387. } else {
  1388. name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
  1389. if ( value != undefined ) elem[name] = value;
  1390. return elem[name];
  1391. }
  1392. },
  1393. /**
  1394. * Remove the whitespace from the beginning and end of a string.
  1395. *
  1396. * @example $.trim(" hello, how are you? ");
  1397. * @result "hello, how are you?"
  1398. *
  1399. * @name $.trim
  1400. * @type String
  1401. * @param String str The string to trim.
  1402. * @cat JavaScript
  1403. */
  1404. trim: function(t){
  1405. return t.replace(/^\s+|\s+$/g, "");
  1406. },
  1407. makeArray: function( a ) {
  1408. var r = [];
  1409. if ( a.constructor != Array )
  1410. for ( var i = 0, al = a.length; i < al; i++ )
  1411. r.push( a[i] );
  1412. else
  1413. r = a.slice( 0 );
  1414. return r;
  1415. },
  1416. inArray: function( b, a ) {
  1417. for ( var i = 0, al = a.length; i < al; i++ )
  1418. if ( a[i] == b )
  1419. return i;
  1420. return -1;
  1421. },
  1422. /**
  1423. * Merge two arrays together, removing all duplicates.
  1424. *
  1425. * The result is the altered first argument with
  1426. * the unique elements from the second array added.
  1427. *
  1428. * @example $.merge( [0,1,2], [2,3,4] )
  1429. * @result [0,1,2,3,4]
  1430. * @desc Merges two arrays, removing the duplicate 2
  1431. *
  1432. * @example var array = [3,2,1];
  1433. * $.merge( array, [4,3,2] )
  1434. * @result array == [3,2,1,4]
  1435. * @desc Merges two arrays, removing the duplicates 3 and 2
  1436. *
  1437. * @name $.merge
  1438. * @type Array
  1439. * @param Array first The first array to merge, the unique elements of second added.
  1440. * @param Array second The second array to merge into the first, unaltered.
  1441. * @cat JavaScript
  1442. */
  1443. merge: function(first, second) {
  1444. var r = [].slice.call( first, 0 );
  1445. // Now check for duplicates between the two arrays
  1446. // and only add the unique items
  1447. for ( var i = 0, sl = second.length; i < sl; i++ )
  1448. // Check for duplicates
  1449. if ( jQuery.inArray( second[i], r ) == -1 )
  1450. // The item is unique, add it
  1451. first.push( second[i] );
  1452. return first;
  1453. },
  1454. /**
  1455. * Filter items out of an array, by using a filter function.
  1456. *
  1457. * The specified function will be passed two arguments: The
  1458. * current array item and the index of the item in the array. The
  1459. * function must return 'true' to keep the item in the array,
  1460. * false to remove it.
  1461. *
  1462. * @example $.grep( [0,1,2], function(i){
  1463. * return i > 0;
  1464. * });
  1465. * @result [1, 2]
  1466. *
  1467. * @name $.grep
  1468. * @type Array
  1469. * @param Array array The Array to find items in.
  1470. * @param Function fn The function to process each item against.
  1471. * @param Boolean inv Invert the selection - select the opposite of the function.
  1472. * @cat JavaScript
  1473. */
  1474. grep: function(elems, fn, inv) {
  1475. // If a string is passed in for the function, make a function
  1476. // for it (a handy shortcut)
  1477. if ( typeof fn == "string" )
  1478. fn = new Function("a","i","return " + fn);
  1479. var result = [];
  1480. // Go through the array, only saving the items
  1481. // that pass the validator function
  1482. for ( var i = 0, el = elems.length; i < el; i++ )
  1483. if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
  1484. result.push( elems[i] );
  1485. return result;
  1486. },
  1487. /**
  1488. * Translate all items in an array to another array of items.
  1489. *
  1490. * The translation function that is provided to this method is
  1491. * called for each item in the array and is passed one argument:
  1492. * The item to be translated.
  1493. *
  1494. * The function can then return the translated value, 'null'
  1495. * (to remove the item), or an array of values - which will
  1496. * be flattened into the full array.
  1497. *
  1498. * @example $.map( [0,1,2], function(i){
  1499. * return i + 4;
  1500. * });
  1501. * @result [4, 5, 6]
  1502. * @desc Maps the original array to a new one and adds 4 to each value.
  1503. *
  1504. * @example $.map( [0,1,2], function(i){
  1505. * return i > 0 ? i + 1 : null;
  1506. * });
  1507. * @result [2, 3]
  1508. * @desc Maps the original array to a new one and adds 1 to each
  1509. * value if it is bigger then zero, otherwise it's removed-
  1510. *
  1511. * @example $.map( [0,1,2], function(i){
  1512. * return [ i, i + 1 ];
  1513. * });
  1514. * @result [0, 1, 1, 2, 2, 3]
  1515. * @desc Maps the original array to a new one, each element is added
  1516. * with it's original value and the value plus one.
  1517. *
  1518. * @name $.map
  1519. * @type Array
  1520. * @param Array array The Array to translate.
  1521. * @param Function fn The function to process each item against.
  1522. * @cat JavaScript
  1523. */
  1524. map: function(elems, fn) {
  1525. // If a string is passed in for the function, make a function
  1526. // for it (a handy shortcut)
  1527. if ( typeof fn == "string" )
  1528. fn = new Function("a","return " + fn);
  1529. var result = [], r = [];
  1530. // Go through the array, translating each of the items to their
  1531. // new value (or values).
  1532. for ( var i = 0, el = elems.length; i < el; i++ ) {
  1533. var val = fn(elems[i],i);
  1534. if ( val !== null && val != undefined ) {
  1535. if ( val.constructor != Array ) val = [val];
  1536. result = result.concat( val );
  1537. }
  1538. }
  1539. var r = result.length ? [ result[0] ] : [];
  1540. check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
  1541. for ( var j = 0; j < i; j++ )
  1542. if ( result[i] == r[j] )
  1543. continue check;
  1544. r.push( result[i] );
  1545. }
  1546. return r;
  1547. }
  1548. });
  1549. /**
  1550. * Contains flags for the useragent, read from navigator.userAgent.
  1551. * Available flags are: safari, opera, msie, mozilla
  1552. *
  1553. * This property is available before the DOM is ready, therefore you can
  1554. * use it to add ready events only for certain browsers.
  1555. *
  1556. * There are situations where object detections is not reliable enough, in that
  1557. * cases it makes sense to use browser detection. Simply try to avoid both!
  1558. *
  1559. * A combination of browser and object detection yields quite reliable results.
  1560. *
  1561. * @example $.browser.msie
  1562. * @desc Returns true if the current useragent is some version of microsoft's internet explorer
  1563. *
  1564. * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
  1565. * @desc Alerts "this is safari!" only for safari browsers
  1566. *
  1567. * @property
  1568. * @name $.browser
  1569. * @type Boolean
  1570. * @cat JavaScript
  1571. */
  1572. /*
  1573. * Whether the W3C compliant box model is being used.
  1574. *
  1575. * @property
  1576. * @name $.boxModel
  1577. * @type Boolean
  1578. * @cat JavaScript
  1579. */
  1580. new function() {
  1581. var b = navigator.userAgent.toLowerCase();
  1582. // Figure out what browser is being used
  1583. jQuery.browser = {
  1584. safari: /webkit/.test(b),
  1585. opera: /opera/.test(b),
  1586. msie: /msie/.test(b) && !/opera/.test(b),
  1587. mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
  1588. };
  1589. // Check to see if the W3C box model is being used
  1590. jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
  1591. };
  1592. /**
  1593. * Get a set of elements containing the unique parents of the matched
  1594. * set of elements.
  1595. *
  1596. * Can be filtered with an optional expressions.
  1597. *
  1598. * @example $("p").parent()
  1599. * @before <div><p>Hello</p><p>Hello</p></div>
  1600. * @result [ <div><p>Hello</p><p>Hello</p></div> ]
  1601. * @desc Find the parent element of each paragraph.
  1602. *
  1603. * @example $("p").parent(".selected")
  1604. * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
  1605. * @result [ <div class="selected"><p>Hello Again</p></div> ]
  1606. * @desc Find the parent element of each paragraph with a class "selected".
  1607. *
  1608. * @name parent
  1609. * @type jQuery
  1610. * @param String expr (optional) An expression to filter the parents with
  1611. * @cat DOM/Traversing
  1612. */
  1613. /**
  1614. * Get a set of elements containing the unique ancestors of the matched
  1615. * set of elements (except for the root element).
  1616. *
  1617. * Can be filtered with an optional expressions.
  1618. *
  1619. * @example $("span").parents()
  1620. * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
  1621. * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
  1622. * @desc Find all parent elements of each span.
  1623. *
  1624. * @example $("span").parents("p")
  1625. * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
  1626. * @result [ <p><span>Hello</span></p> ]
  1627. * @desc Find all parent elements of each span that is a paragraph.
  1628. *
  1629. * @name parents
  1630. * @type jQuery
  1631. * @param String expr (optional) An expression to filter the ancestors with
  1632. * @cat DOM/Traversing
  1633. */
  1634. /**
  1635. * Get a set of elements containing the unique next siblings of each of the
  1636. * matched set of elements.
  1637. *
  1638. * It only returns the very next sibling, not all next siblings.
  1639. *
  1640. * Can be filtered with an optional expressions.
  1641. *
  1642. * @example $("p").next()
  1643. * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
  1644. * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
  1645. * @desc Find the very next sibling of each paragraph.
  1646. *
  1647. * @example $("p").next(".selected")
  1648. * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
  1649. * @result [ <p class="selected">Hello Again</p> ]
  1650. * @desc Find the very next sibling of each paragraph that has a class "selected".
  1651. *
  1652. * @name next
  1653. * @type jQuery
  1654. * @param String expr (optional) An expression to filter the next Elements with
  1655. * @cat DOM/Traversing
  1656. */
  1657. /**
  1658. * Get a set of elements containing the unique previous siblings of each of the
  1659. * matched set of elements.
  1660. *
  1661. * Can be filtered with an optional expressions.
  1662. *
  1663. * It only returns the immediately previous sibling, not all previous siblings.
  1664. *
  1665. * @example $("p").prev()
  1666. * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
  1667. * @result [ <div><span>Hello Again</span></div> ]
  1668. * @desc Find the very previous sibling of each paragraph.
  1669. *
  1670. * @example $("p").prev(".selected")
  1671. * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
  1672. * @result [ <div><span>Hello</span></div> ]
  1673. * @desc Find the very previous sibling of each paragraph that has a class "selected".
  1674. *
  1675. * @name prev
  1676. * @type jQuery
  1677. * @param String expr (optional) An expression to filter the previous Elements with
  1678. * @cat DOM/Traversing
  1679. */
  1680. /**
  1681. * Get a set of elements containing all of the unique siblings of each of the
  1682. * matched set of elements.
  1683. *
  1684. * Can be filtered with an optional expressions.
  1685. *
  1686. * @example $("div").siblings()
  1687. * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
  1688. * @result [ <p>Hello</p>, <p>And Again</p> ]
  1689. * @desc Find all siblings of each div.
  1690. *
  1691. * @example $("div").siblings(".selected")
  1692. * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
  1693. * @result [ <p class="selected">Hello Again</p> ]
  1694. * @desc Find all siblings with a class "selected" of each div.
  1695. *
  1696. * @name siblings
  1697. * @type jQuery
  1698. * @param String expr (optional) An expression to filter the sibling Elements with
  1699. * @cat DOM/Traversing
  1700. */
  1701. /**
  1702. * Get a set of elements containing all of the unique children of each of the
  1703. * matched set of elements.
  1704. *
  1705. * Can be filtered with an optional expressions.
  1706. *
  1707. * @example $("div").children()
  1708. * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
  1709. * @result [ <span>Hello Again</span> ]
  1710. * @desc Find all children of each div.
  1711. *
  1712. * @example $("div").children(".selected")
  1713. * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
  1714. * @result [ <p class="selected">Hello Again</p> ]
  1715. * @desc Find all children with a class "selected" of each div.
  1716. *
  1717. * @name children
  1718. * @type jQuery
  1719. * @param String expr (optional) An expression to filter the child Elements with
  1720. * @cat DOM/Traversing
  1721. */
  1722. jQuery.each({
  1723. parent: "a.parentNode",
  1724. parents: "jQuery.parents(a)",
  1725. next: "jQuery.nth(a,2,'nextSibling')",
  1726. prev: "jQuery.nth(a,2,'previousSibling')",
  1727. siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
  1728. children: "jQuery.sibling(a.firstChild)"
  1729. }, function(i,n){
  1730. jQuery.fn[ i ] = function(a) {
  1731. var ret = jQuery.map(this,n);
  1732. if ( a && typeof a == "string" )
  1733. ret = jQuery.multiFilter(a,ret);
  1734. return this.pushStack( ret );
  1735. };
  1736. });
  1737. /**
  1738. * Append all of the matched elements to another, specified, set of elements.
  1739. * This operation is, essentially, the reverse of doing a regular
  1740. * $(A).append(B), in that instead of appending B to A, you're appending
  1741. * A to B.
  1742. *
  1743. * @example $("p").appendTo("#foo");
  1744. * @before <p>I would like to say: </p><div id="foo"></div>
  1745. * @result <div id="foo"><p>I would like to say: </p></div>
  1746. * @desc Appends all paragraphs to the element with the ID "foo"
  1747. *
  1748. * @name appendTo
  1749. * @type jQuery
  1750. * @param <Content> content Content to append to the selected element to.
  1751. * @cat DOM/Manipulation
  1752. * @see append(<Content>)
  1753. */
  1754. /**
  1755. * Prepend all of the matched elements to another, specified, set of elements.
  1756. * This operation is, essentially, the reverse of doing a regular
  1757. * $(A).prepend(B), in that instead of prepending B to A, you're prepending
  1758. * A to B.
  1759. *
  1760. * @example $("p").prependTo("#foo");
  1761. * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
  1762. * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
  1763. * @desc Prepends all paragraphs to the element with the ID "foo"
  1764. *
  1765. * @name prependTo
  1766. * @type jQuery
  1767. * @param <Content> content Content to prepend to the selected element to.
  1768. * @cat DOM/Manipulation
  1769. * @see prepend(<Content>)
  1770. */
  1771. /**
  1772. * Insert all of the matched elements before another, specified, set of elements.
  1773. * This operation is, essentially, the reverse of doing a regular
  1774. * $(A).before(B), in that instead of inserting B before A, you're inserting
  1775. * A before B.
  1776. *
  1777. * @example $("p").insertBefore("#foo");
  1778. * @before <div id="foo">Hello</div><p>I would like to say: </p>
  1779. * @result <p>I would like to say: </p><div id="foo">Hello</div>
  1780. * @desc Same as $("#foo").before("p")
  1781. *
  1782. * @name insertBefore
  1783. * @type jQuery
  1784. * @param <Content> content Content to insert the selected element before.
  1785. * @cat DOM/Manipulation
  1786. * @see before(<Content>)
  1787. */
  1788. /**
  1789. * Insert all of the matched elements after another, specified, set of elements.
  1790. * This operation is, essentially, the reverse of doing a regular
  1791. * $(A).after(B), in that instead of inserting B after A, you're inserting
  1792. * A after B.
  1793. *
  1794. * @example $("p").insertAfter("#foo");
  1795. * @before <p>I would like to say: </p><div id="foo">Hello</div>
  1796. * @result <div id="foo">Hello</div><p>I would like to say: </p>
  1797. * @desc Same as $("#foo").after("p")
  1798. *
  1799. * @name insertAfter
  1800. * @type jQuery
  1801. * @param <Content> content Content to insert the selected element after.
  1802. * @cat DOM/Manipulation
  1803. * @see after(<Content>)
  1804. */
  1805. jQuery.each({
  1806. appendTo: "append",
  1807. prependTo: "prepend",
  1808. insertBefore: "before",
  1809. insertAfter: "after"
  1810. }, function(i,n){
  1811. jQuery.fn[ i ] = function(){
  1812. var a = arguments;
  1813. return this.each(function(){
  1814. for ( var j = 0, al = a.length; j < al; j++ )
  1815. jQuery(a[j])[n]( this );
  1816. });
  1817. };
  1818. });
  1819. /**
  1820. * Remove an attribute from each of the matched elements.
  1821. *
  1822. * @example $("input").removeAttr("disabled")
  1823. * @before <input disabled="disabled"/>
  1824. * @result <input/>
  1825. *
  1826. * @name removeAttr
  1827. * @type jQuery
  1828. * @param String name The name of the attribute to remove.
  1829. * @cat DOM/Attributes
  1830. */
  1831. /**
  1832. * Adds the specified class(es) to each of the set of matched elements.
  1833. *
  1834. * @example $("p").addClass("selected")
  1835. * @before <p>Hello</p>
  1836. * @result [ <p class="selected">Hello</p> ]
  1837. *
  1838. * @example $("p").addClass("selected highlight")
  1839. * @before <p>Hello</p>
  1840. * @result [ <p class="selected highlight">Hello</p> ]
  1841. *
  1842. * @name addClass
  1843. * @type jQuery
  1844. * @param String class One or more CSS classes to add to the elements
  1845. * @cat DOM/Attributes
  1846. * @see removeClass(String)
  1847. */
  1848. /**
  1849. * Removes all or the specified class(es) from the set of matched elements.
  1850. *
  1851. * @example $("p").removeClass()
  1852. * @before <p class="selected">Hello</p>
  1853. * @result [ <p>Hello</p> ]
  1854. *
  1855. * @example $("p").removeClass("selected")
  1856. * @before <p class="selected first">Hello</p>
  1857. * @result [ <p class="first">Hello</p> ]
  1858. *
  1859. * @example $("p").removeClass("selected highlight")
  1860. * @before <p class="highlight selected first">Hello</p>
  1861. * @result [ <p class="first">Hello</p> ]
  1862. *
  1863. * @name removeClass
  1864. * @type jQuery
  1865. * @param String class (optional) One or more CSS classes to remove from the elements
  1866. * @cat DOM/Attributes
  1867. * @see addClass(String)
  1868. */
  1869. /**
  1870. * Adds the specified class if it is not present, removes it if it is
  1871. * present.
  1872. *
  1873. * @example $("p").toggleClass("selected")
  1874. * @before <p>Hello</p><p class="selected">Hello Again</p>
  1875. * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
  1876. *
  1877. * @name toggleClass
  1878. * @type jQuery
  1879. * @param String class A CSS class with which to toggle the elements
  1880. * @cat DOM/Attributes
  1881. */
  1882. /**
  1883. * Removes all matched elements from the DOM. This does NOT remove them from the
  1884. * jQuery object, allowing you to use the matched elements further.
  1885. *
  1886. * Can be filtered with an optional expressions.
  1887. *
  1888. * @example $("p").remove();
  1889. * @before <p>Hello</p> how are <p>you?</p>
  1890. * @result how are
  1891. *
  1892. * @example $("p").remove(".hello");
  1893. * @before <p class="hello">Hello</p> how are <p>you?</p>
  1894. * @result how are <p>you?</p>
  1895. *
  1896. * @name remove
  1897. * @type jQuery
  1898. * @param String expr (optional) A jQuery expression to filter elements by.
  1899. * @cat DOM/Manipulation
  1900. */
  1901. /**
  1902. * Removes all child nodes from the set of matched elements.
  1903. *
  1904. * @example $("p").empty()
  1905. * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
  1906. * @result [ <p></p> ]
  1907. *
  1908. * @name empty
  1909. * @type jQuery
  1910. * @cat DOM/Manipulation
  1911. */
  1912. jQuery.each( {
  1913. removeAttr: function( key ) {
  1914. jQuery.attr( this, key, "" );
  1915. this.removeAttribute( key );
  1916. },
  1917. addClass: function(c){
  1918. jQuery.className.add(this,c);
  1919. },
  1920. removeClass: function(c){
  1921. jQuery.className.remove(this,c);
  1922. },
  1923. toggleClass: function( c ){
  1924. jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
  1925. },
  1926. remove: function(a){
  1927. if ( !a || jQuery.filter( a, [this] ).r.length )
  1928. this.parentNode.removeChild( this );
  1929. },
  1930. empty: function() {
  1931. while ( this.firstChild )
  1932. this.removeChild( this.firstChild );
  1933. }
  1934. }, function(i,n){
  1935. jQuery.fn[ i ] = function() {
  1936. return this.each( n, arguments );
  1937. };
  1938. });
  1939. /**
  1940. * Reduce the set of matched elements to a single element.
  1941. * The position of the element in the set of matched elements
  1942. * starts at 0 and goes to length - 1.
  1943. *
  1944. * @example $("p").eq(1)
  1945. * @before <p>This is just a test.</p><p>So is this</p>
  1946. * @result [ <p>So is this</p> ]
  1947. *
  1948. * @name eq
  1949. * @type jQuery
  1950. * @param Number pos The index of the element that you wish to limit to.
  1951. * @cat Core
  1952. */
  1953. /**
  1954. * Reduce the set of matched elements to all elements before a given position.
  1955. * The position of the element in the set of matched elements
  1956. * starts at 0 and goes to length - 1.
  1957. *
  1958. * @example $("p").lt(1)
  1959. * @before <p>This is just a test.</p><p>So is this</p>
  1960. * @result [ <p>This is just a test.</p> ]
  1961. *
  1962. * @name lt
  1963. * @type jQuery
  1964. * @param Number pos Reduce the set to all elements below this position.
  1965. * @cat Core
  1966. */
  1967. /**
  1968. * Reduce the set of matched elements to all elements after a given position.
  1969. * The position of the element in the set of matched elements
  1970. * starts at 0 and goes to length - 1.
  1971. *
  1972. * @example $("p").gt(0)
  1973. * @before <p>This is just a test.</p><p>So is this</p>
  1974. * @result [ <p>So is this</p> ]
  1975. *
  1976. * @name gt
  1977. * @type jQuery
  1978. * @param Number pos Reduce the set to all elements after this position.
  1979. * @cat Core
  1980. */
  1981. /**
  1982. * Filter the set of elements to those that contain the specified text.
  1983. *
  1984. * @example $("p").contains("test")
  1985. * @before <p>This is just a test.</p><p>So is this</p>
  1986. * @result [ <p>This is just a test.</p> ]
  1987. *
  1988. * @name contains
  1989. * @type jQuery
  1990. * @param String str The string that will be contained within the text of an element.
  1991. * @cat DOM/Traversing
  1992. */
  1993. jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
  1994. jQuery.fn[ n ] = function(num,fn) {
  1995. return this.filter( ":" + n + "(" + num + ")", fn );
  1996. };
  1997. });
  1998. /**
  1999. * Get the current computed, pixel, width of the first matched element.
  2000. *
  2001. * @example $("p").width();
  2002. * @before <p>This is just a test.</p>
  2003. * @result 300
  2004. *
  2005. * @name width
  2006. * @type String
  2007. * @cat CSS
  2008. */
  2009. /**
  2010. * Set the CSS width of every matched element. If no explicit unit
  2011. * was specified (like 'em' or '%') then "px" is added to the width.
  2012. *
  2013. * @example $("p").width(20);
  2014. * @before <p>This is just a test.</p>
  2015. * @result <p style="width:20px;">This is just a test.</p>
  2016. *
  2017. * @example $("p").width("20em");
  2018. * @before <p>This is just a test.</p>
  2019. * @result <p style="width:20em;">This is just a test.</p>
  2020. *
  2021. * @name width
  2022. * @type jQuery
  2023. * @param String|Number val Set the CSS property to the specified value.
  2024. * @cat CSS
  2025. */
  2026. /**
  2027. * Get the current computed, pixel, height of the first matched element.
  2028. *
  2029. * @example $("p").height();
  2030. * @before <p>This is just a test.</p>
  2031. * @result 300
  2032. *
  2033. * @name height
  2034. * @type String
  2035. * @cat CSS
  2036. */
  2037. /**
  2038. * Set the CSS width of every matched element. If no explicit unit
  2039. * was specified (like 'em' or '%') then "px" is added to the width.
  2040. *
  2041. * @example $("p").height(20);
  2042. * @before <p>This is just a test.</p>
  2043. * @result <p style="height:20px;">This is just a test.</p>
  2044. *
  2045. * @example $("p").height("20em");
  2046. * @before <p>This is just a test.</p>
  2047. * @result <p style="height:20em;">This is just a test.</p>
  2048. *
  2049. * @name height
  2050. * @type jQuery
  2051. * @param String|Number val Set the CSS property to the specified value.
  2052. * @cat CSS
  2053. */
  2054. jQuery.each( [ "height", "width" ], function(i,n){
  2055. jQuery.fn[ n ] = function(h) {
  2056. return h == undefined ?
  2057. ( this.length ? jQuery.css( this[0], n ) : null ) :
  2058. this.css( n, h.constructor == String ? h : h + "px" );
  2059. };
  2060. });
  2061. jQuery.extend({
  2062. expr: {
  2063. "": "m[2]=='*'||jQuery.nodeName(a,m[2])",
  2064. "#": "a.getAttribute('id')==m[2]",
  2065. ":": {
  2066. // Position Checks
  2067. lt: "i<m[3]-0",
  2068. gt: "i>m[3]-0",
  2069. nth: "m[3]-0==i",
  2070. eq: "m[3]-0==i",
  2071. first: "i==0",
  2072. last: "i==r.length-1",
  2073. even: "i%2==0",
  2074. odd: "i%2",
  2075. // Child Checks
  2076. "nth-child": "jQuery.nth(a.parentNode.firstChild,m[3],'nextSibling',a)==a",
  2077. "first-child": "jQuery.nth(a.parentNode.firstChild,1,'nextSibling')==a",
  2078. "last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a",
  2079. "only-child": "jQuery.sibling(a.parentNode.firstChild).length==1",
  2080. // Parent Checks
  2081. parent: "a.firstChild",
  2082. empty: "!a.firstChild",
  2083. // Text Check
  2084. contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
  2085. // Visibility
  2086. visible: 'a.type!="hidden"&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"',
  2087. hidden: 'a.type=="hidden"||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"',
  2088. // Form attributes
  2089. enabled: "!a.disabled",
  2090. disabled: "a.disabled",
  2091. checked: "a.checked",
  2092. selected: "a.selected||jQuery.attr(a,'selected')",
  2093. // Form elements
  2094. text: "a.type=='text'",
  2095. radio: "a.type=='radio'",
  2096. checkbox: "a.type=='checkbox'",
  2097. file: "a.type=='file'",
  2098. password: "a.type=='password'",
  2099. submit: "a.type=='submit'",
  2100. image: "a.type=='image'",
  2101. reset: "a.type=='reset'",
  2102. button: 'a.type=="button"||jQuery.nodeName(a,"button")',
  2103. input: "/input|select|textarea|button/i.test(a.nodeName)"
  2104. },
  2105. ".": "jQuery.className.has(a,m[2])",
  2106. "@": {
  2107. "=": "z==m[4]",
  2108. "!=": "z!=m[4]",
  2109. "^=": "z&&!z.indexOf(m[4])",
  2110. "$=": "z&&z.substr(z.length - m[4].length,m[4].length)==m[4]",
  2111. "*=": "z&&z.indexOf(m[4])>=0",
  2112. "": "z",
  2113. _resort: function(m){
  2114. return ["", m[1], m[3], m[2], m[5]];
  2115. },
  2116. _prefix: "z=a[m[3]]||jQuery.attr(a,m[3]);"
  2117. },
  2118. "[": "jQuery.find(m[2],a).length"
  2119. },
  2120. // The regular expressions that power the parsing engine
  2121. parse: [
  2122. // Match: [@value='test'], [@foo]
  2123. /^\[ *(@)([a-z0-9_-]*) *([!*$^=]*) *('?"?)(.*?)\4 *\]/i,
  2124. // Match: [div], [div p]
  2125. /^(\[)\s*(.*?(\[.*?\])?[^[]*?)\s*\]/,
  2126. // Match: :contains('foo')
  2127. /^(:)([a-z0-9_-]*)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/i,
  2128. // Match: :even, :last-chlid
  2129. /^([:.#]*)([a-z0-9_*-]*)/i
  2130. ],
  2131. token: [
  2132. /^(\/?\.\.)/, "a.parentNode",
  2133. /^(>|\/)/, "jQuery.sibling(a.firstChild)",
  2134. /^(\+)/, "jQuery.nth(a,2,'nextSibling')",
  2135. /^(~)/, function(a){
  2136. var s = jQuery.sibling(a.parentNode.firstChild);
  2137. return s.slice(0, jQuery.inArray(a,s));
  2138. }
  2139. ],
  2140. multiFilter: function( expr, elems, not ) {
  2141. var old, cur = [];
  2142. while ( expr && expr != old ) {
  2143. old = expr;
  2144. var f = jQuery.filter( expr, elems, not );
  2145. expr = f.t.replace(/^\s*,\s*/, "" );
  2146. cur = not ? elems = f.r : jQuery.merge( cur, f.r );
  2147. }
  2148. return cur;
  2149. },
  2150. /**
  2151. * @name $.find
  2152. * @type Array<Element>
  2153. * @private
  2154. * @cat Core
  2155. */
  2156. find: function( t, context ) {
  2157. // Quickly handle non-string expressions
  2158. if ( typeof t != "string" )
  2159. return [ t ];
  2160. // Make sure that the context is a DOM Element
  2161. if ( context && !context.nodeType )
  2162. context = null;
  2163. // Set the correct context (if none is provided)
  2164. context = context || document;
  2165. // Handle the common XPath // expression
  2166. if ( !t.indexOf("//") ) {
  2167. context = context.documentElement;
  2168. t = t.substr(2,t.length);
  2169. // And the / root expression
  2170. } else if ( !t.indexOf("/") ) {
  2171. context = context.documentElement;
  2172. t = t.substr(1,t.length);
  2173. if ( t.indexOf("/") >= 1 )
  2174. t = t.substr(t.indexOf("/"),t.length);
  2175. }
  2176. // Initialize the search
  2177. var ret = [context], done = [], last = null;
  2178. // Continue while a selector expression exists, and while
  2179. // we're no longer looping upon ourselves
  2180. while ( t && last != t ) {
  2181. var r = [];
  2182. last = t;
  2183. t = jQuery.trim(t).replace( /^\/\//i, "" );
  2184. var foundToken = false;
  2185. // An attempt at speeding up child selectors that
  2186. // point to a specific element tag
  2187. var re = /^[\/>]\s*([a-z0-9*-]+)/i;
  2188. var m = re.exec(t);
  2189. if ( m ) {
  2190. // Perform our own iteration and filter
  2191. jQuery.each( ret, function(){
  2192. for ( var c = this.firstChild; c; c = c.nextSibling )
  2193. if ( c.nodeType == 1 && ( jQuery.nodeName(c, m[1]) || m[1] == "*" ) )
  2194. r.push( c );
  2195. });
  2196. ret = r;
  2197. t = t.replace( re, "" );
  2198. if ( t.indexOf(" ") == 0 ) continue;
  2199. foundToken = true;
  2200. } else {
  2201. // Look for pre-defined expression tokens
  2202. for ( var i = 0; i < jQuery.token.length; i += 2 ) {
  2203. // Attempt to match each, individual, token in
  2204. // the specified order
  2205. var re = jQuery.token[i];
  2206. var m = re.exec(t);
  2207. // If the token match was found
  2208. if ( m ) {
  2209. // Map it against the token's handler
  2210. r = ret = jQuery.map( ret, jQuery.isFunction( jQuery.token[i+1] ) ?
  2211. jQuery.token[i+1] :
  2212. function(a){ return eval(jQuery.token[i+1]); });
  2213. // And remove the token
  2214. t = jQuery.trim( t.replace( re, "" ) );
  2215. foundToken = true;
  2216. break;
  2217. }
  2218. }
  2219. }
  2220. // See if there's still an expression, and that we haven't already
  2221. // matched a token
  2222. if ( t && !foundToken ) {
  2223. // Handle multiple expressions
  2224. if ( !t.indexOf(",") ) {
  2225. // Clean the result set
  2226. if ( ret[0] == context ) ret.shift();
  2227. // Merge the result sets
  2228. jQuery.merge( done, ret );
  2229. // Reset the context
  2230. r = ret = [context];
  2231. // Touch up the selector string
  2232. t = " " + t.substr(1,t.length);
  2233. } else {
  2234. // Optomize for the case nodeName#idName
  2235. var re2 = /^([a-z0-9_-]+)(#)([a-z0-9\\*_-]*)/i;
  2236. var m = re2.exec(t);
  2237. // Re-organize the results, so that they're consistent
  2238. if ( m ) {
  2239. m = [ 0, m[2], m[3], m[1] ];
  2240. } else {
  2241. // Otherwise, do a traditional filter check for
  2242. // ID, class, and element selectors
  2243. re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
  2244. m = re2.exec(t);
  2245. }
  2246. // Try to do a global search by ID, where we can
  2247. if ( m[1] == "#" && ret[ret.length-1].getElementById ) {
  2248. // Optimization for HTML document case
  2249. var oid = ret[ret.length-1].getElementById(m[2]);
  2250. // Do a quick check for node name (where applicable) so
  2251. // that div#foo searches will be really fast
  2252. ret = r = oid &&
  2253. (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
  2254. } else {
  2255. // Pre-compile a regular expression to handle class searches
  2256. if ( m[1] == "." )
  2257. var rec = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
  2258. // We need to find all descendant elements, it is more
  2259. // efficient to use getAll() when we are already further down
  2260. // the tree - we try to recognize that here
  2261. jQuery.each( ret, function(){
  2262. // Grab the tag name being searched for
  2263. var tag = m[1] != "" || m[0] == "" ? "*" : m[2];
  2264. // Handle IE7 being really dumb about <object>s
  2265. if ( jQuery.nodeName(this, "object") && tag == "*" )
  2266. tag = "param";
  2267. jQuery.merge( r,
  2268. m[1] != "" && ret.length != 1 ?
  2269. jQuery.getAll( this, [], m[1], m[2], rec ) :
  2270. this.getElementsByTagName( tag )
  2271. );
  2272. });
  2273. // It's faster to filter by class and be done with it
  2274. if ( m[1] == "." && ret.length == 1 )
  2275. r = jQuery.grep( r, function(e) {
  2276. return rec.test(e.className);
  2277. });
  2278. // Same with ID filtering
  2279. if ( m[1] == "#" && ret.length == 1 ) {
  2280. // Remember, then wipe out, the result set
  2281. var tmp = r;
  2282. r = [];
  2283. // Then try to find the element with the ID
  2284. jQuery.each( tmp, function(){
  2285. if ( this.getAttribute("id") == m[2] ) {
  2286. r = [ this ];
  2287. return false;
  2288. }
  2289. });
  2290. }
  2291. ret = r;
  2292. }
  2293. t = t.replace( re2, "" );
  2294. }
  2295. }
  2296. // If a selector string still exists
  2297. if ( t ) {
  2298. // Attempt to filter it
  2299. var val = jQuery.filter(t,r);
  2300. ret = r = val.r;
  2301. t = jQuery.trim(val.t);
  2302. }
  2303. }
  2304. // Remove the root context
  2305. if ( ret && ret[0] == context ) ret.shift();
  2306. // And combine the results
  2307. jQuery.merge( done, ret );
  2308. return done;
  2309. },
  2310. filter: function(t,r,not) {
  2311. // Look for common filter expressions
  2312. while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
  2313. var p = jQuery.parse, m;
  2314. jQuery.each( p, function(i,re){
  2315. // Look for, and replace, string-like sequences
  2316. // and finally build a regexp out of it
  2317. m = re.exec( t );
  2318. if ( m ) {
  2319. // Remove what we just matched
  2320. t = t.substring( m[0].length );
  2321. // Re-organize the first match
  2322. if ( jQuery.expr[ m[1] ]._resort )
  2323. m = jQuery.expr[ m[1] ]._resort( m );
  2324. return false;
  2325. }
  2326. });
  2327. // :not() is a special case that can be optimized by
  2328. // keeping it out of the expression list
  2329. if ( m[1] == ":" && m[2] == "not" )
  2330. r = jQuery.filter(m[3], r, true).r;
  2331. // Handle classes as a special case (this will help to
  2332. // improve the speed, as the regexp will only be compiled once)
  2333. else if ( m[1] == "." ) {
  2334. var re = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
  2335. r = jQuery.grep( r, function(e){
  2336. return re.test(e.className || "");
  2337. }, not);
  2338. // Otherwise, find the expression to execute
  2339. } else {
  2340. var f = jQuery.expr[m[1]];
  2341. if ( typeof f != "string" )
  2342. f = jQuery.expr[m[1]][m[2]];
  2343. // Build a custom macro to enclose it
  2344. eval("f = function(a,i){" +
  2345. ( jQuery.expr[ m[1] ]._prefix || "" ) +
  2346. "return " + f + "}");
  2347. // Execute it against the current filter
  2348. r = jQuery.grep( r, f, not );
  2349. }
  2350. }
  2351. // Return an array of filtered elements (r)
  2352. // and the modified expression string (t)
  2353. return { r: r, t: t };
  2354. },
  2355. getAll: function( o, r, token, name, re ) {
  2356. for ( var s = o.firstChild; s; s = s.nextSibling )
  2357. if ( s.nodeType == 1 ) {
  2358. var add = true;
  2359. if ( token == "." )
  2360. add = s.className && re.test(s.className);
  2361. else if ( token == "#" )
  2362. add = s.getAttribute("id") == name;
  2363. if ( add )
  2364. r.push( s );
  2365. if ( token == "#" && r.length ) break;
  2366. if ( s.firstChild )
  2367. jQuery.getAll( s, r, token, name, re );
  2368. }
  2369. return r;
  2370. },
  2371. /**
  2372. * All ancestors of a given element.
  2373. *
  2374. * @private
  2375. * @name $.parents
  2376. * @type Array<Element>
  2377. * @param Element elem The element to find the ancestors of.
  2378. * @cat DOM/Traversing
  2379. */
  2380. parents: function( elem ){
  2381. var matched = [];
  2382. var cur = elem.parentNode;
  2383. while ( cur && cur != document ) {
  2384. matched.push( cur );
  2385. cur = cur.parentNode;
  2386. }
  2387. return matched;
  2388. },
  2389. /**
  2390. * A handy, and fast, way to traverse in a particular direction and find
  2391. * a specific element.
  2392. *
  2393. * @private
  2394. * @name $.nth
  2395. * @type DOMElement
  2396. * @param DOMElement cur The element to search from.
  2397. * @param String|Number num The Nth result to match. Can be a number or a string (like 'even' or 'odd').
  2398. * @param String dir The direction to move in (pass in something like 'previousSibling' or 'nextSibling').
  2399. * @cat DOM/Traversing
  2400. */
  2401. nth: function(cur,result,dir,elem){
  2402. result = result || 1;
  2403. var num = 0;
  2404. for ( ; cur; cur = cur[dir] ) {
  2405. if ( cur.nodeType == 1 ) num++;
  2406. if ( num == result || result == "even" && num % 2 == 0 && num > 1 && cur == elem ||
  2407. result == "odd" && num % 2 == 1 && cur == elem ) return cur;
  2408. }
  2409. },
  2410. /**
  2411. * All elements on a specified axis.
  2412. *
  2413. * @private
  2414. * @name $.sibling
  2415. * @type Array
  2416. * @param Element elem The element to find all the siblings of (including itself).
  2417. * @cat DOM/Traversing
  2418. */
  2419. sibling: function( n, elem ) {
  2420. var r = [];
  2421. for ( ; n; n = n.nextSibling ) {
  2422. if ( n.nodeType == 1 && (!elem || n != elem) )
  2423. r.push( n );
  2424. }
  2425. return r;
  2426. }
  2427. });
  2428. /*
  2429. * A number of helper functions used for managing events.
  2430. * Many of the ideas behind this code orignated from
  2431. * Dean Edwards' addEvent library.
  2432. */
  2433. jQuery.event = {
  2434. // Bind an event to an element
  2435. // Original by Dean Edwards
  2436. add: function(element, type, handler, data) {
  2437. // For whatever reason, IE has trouble passing the window object
  2438. // around, causing it to be cloned in the process
  2439. if ( jQuery.browser.msie && element.setInterval != undefined )
  2440. element = window;
  2441. // if data is passed, bind to handler
  2442. if( data )
  2443. handler.data = data;
  2444. // Make sure that the function being executed has a unique ID
  2445. if ( !handler.guid )
  2446. handler.guid = this.guid++;
  2447. // Init the element's event structure
  2448. if (!element.events)
  2449. element.events = {};
  2450. // Get the current list of functions bound to this event
  2451. var handlers = element.events[type];
  2452. // If it hasn't been initialized yet
  2453. if (!handlers) {
  2454. // Init the event handler queue
  2455. handlers = element.events[type] = {};
  2456. // Remember an existing handler, if it's already there
  2457. if (element["on" + type])
  2458. handlers[0] = element["on" + type];
  2459. }
  2460. // Add the function to the element's handler list
  2461. handlers[handler.guid] = handler;
  2462. // And bind the global event handler to the element
  2463. element["on" + type] = this.handle;
  2464. // Remember the function in a global list (for triggering)
  2465. if (!this.global[type])
  2466. this.global[type] = [];
  2467. this.global[type].push( element );
  2468. },
  2469. guid: 1,
  2470. global: {},
  2471. // Detach an event or set of events from an element
  2472. remove: function(element, type, handler) {
  2473. if (element.events)
  2474. if ( type && type.type )
  2475. delete element.events[ type.type ][ type.handler.guid ];
  2476. else if (type && element.events[type])
  2477. if ( handler )
  2478. delete element.events[type][handler.guid];
  2479. else
  2480. for ( var i in element.events[type] )
  2481. delete element.events[type][i];
  2482. else
  2483. for ( var j in element.events )
  2484. this.remove( element, j );
  2485. },
  2486. trigger: function(type,data,element) {
  2487. // Clone the incoming data, if any
  2488. data = jQuery.makeArray(data || []);
  2489. // Handle a global trigger
  2490. if ( !element )
  2491. jQuery.each( this.global[type] || [], function(){
  2492. jQuery.event.trigger( type, data, this );
  2493. });
  2494. // Handle triggering a single element
  2495. else {
  2496. var handler = element["on" + type ], val,
  2497. fn = jQuery.isFunction( element[ type ] );
  2498. if ( handler ) {
  2499. // Pass along a fake event
  2500. data.unshift( this.fix({ type: type, target: element }) );
  2501. // Trigger the event
  2502. if ( (val = handler.apply( element, data )) !== false )
  2503. this.triggered = true;
  2504. }
  2505. if ( fn && val !== false )
  2506. element[ type ]();
  2507. this.triggered = false;
  2508. }
  2509. },
  2510. handle: function(event) {
  2511. // Handle the second event of a trigger and when
  2512. // an event is called after a page has unloaded
  2513. if ( typeof jQuery == "undefined" || jQuery.event.triggered ) return;
  2514. // Empty object is for triggered events with no data
  2515. event = jQuery.event.fix( event || window.event || {} );
  2516. // returned undefined or false
  2517. var returnValue;
  2518. var c = this.events[event.type];
  2519. var args = [].slice.call( arguments, 1 );
  2520. args.unshift( event );
  2521. for ( var j in c ) {
  2522. // Pass in a reference to the handler function itself
  2523. // So that we can later remove it
  2524. args[0].handler = c[j];
  2525. args[0].data = c[j].data;
  2526. if ( c[j].apply( this, args ) === false ) {
  2527. event.preventDefault();
  2528. event.stopPropagation();
  2529. returnValue = false;
  2530. }
  2531. }
  2532. // Clean up added properties in IE to prevent memory leak
  2533. if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = event.handler = event.data = null;
  2534. return returnValue;
  2535. },
  2536. fix: function(event) {
  2537. // Fix target property, if necessary
  2538. if ( !event.target && event.srcElement )
  2539. event.target = event.srcElement;
  2540. // Calculate pageX/Y if missing and clientX/Y available
  2541. if ( event.pageX == undefined && event.clientX != undefined ) {
  2542. var e = document.documentElement, b = document.body;
  2543. event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft);
  2544. event.pageY = event.clientY + (e.scrollTop || b.scrollTop);
  2545. }
  2546. // check if target is a textnode (safari)
  2547. if (jQuery.browser.safari && event.target.nodeType == 3) {
  2548. // store a copy of the original event object
  2549. // and clone because target is read only
  2550. var originalEvent = event;
  2551. event = jQuery.extend({}, originalEvent);
  2552. // get parentnode from textnode
  2553. event.target = originalEvent.target.parentNode;
  2554. // add preventDefault and stopPropagation since
  2555. // they will not work on the clone
  2556. event.preventDefault = function() {
  2557. return originalEvent.preventDefault();
  2558. };
  2559. event.stopPropagation = function() {
  2560. return originalEvent.stopPropagation();
  2561. };
  2562. }
  2563. // fix preventDefault and stopPropagation
  2564. if (!event.preventDefault)
  2565. event.preventDefault = function() {
  2566. this.returnValue = false;
  2567. };
  2568. if (!event.stopPropagation)
  2569. event.stopPropagation = function() {
  2570. this.cancelBubble = true;
  2571. };
  2572. return event;
  2573. }
  2574. };
  2575. jQuery.fn.extend({
  2576. /**
  2577. * Binds a handler to a particular event (like click) for each matched element.
  2578. * The event handler is passed an event object that you can use to prevent
  2579. * default behaviour. To stop both default action and event bubbling, your handler
  2580. * has to return false.
  2581. *
  2582. * In most cases, you can define your event handlers as anonymous functions
  2583. * (see first example). In cases where that is not possible, you can pass additional
  2584. * data as the second paramter (and the handler function as the third), see
  2585. * second example.
  2586. *
  2587. * @example $("p").bind("click", function(){
  2588. * alert( $(this).text() );
  2589. * });
  2590. * @before <p>Hello</p>
  2591. * @result alert("Hello")
  2592. *
  2593. * @example function handler(event) {
  2594. * alert(event.data.foo);
  2595. * }
  2596. * $("p").bind("click", {foo: "bar"}, handler)
  2597. * @result alert("bar")
  2598. * @desc Pass some additional data to the event handler.
  2599. *
  2600. * @example $("form").bind("submit", function() { return false; })
  2601. * @desc Cancel a default action and prevent it from bubbling by returning false
  2602. * from your function.
  2603. *
  2604. * @example $("form").bind("submit", function(event){
  2605. * event.preventDefault();
  2606. * });
  2607. * @desc Cancel only the default action by using the preventDefault method.
  2608. *
  2609. *
  2610. * @example $("form").bind("submit", function(event){
  2611. * event.stopPropagation();
  2612. * });
  2613. * @desc Stop only an event from bubbling by using the stopPropagation method.
  2614. *
  2615. * @name bind
  2616. * @type jQuery
  2617. * @param String type An event type
  2618. * @param Object data (optional) Additional data passed to the event handler as event.data
  2619. * @param Function fn A function to bind to the event on each of the set of matched elements
  2620. * @cat Events
  2621. */
  2622. bind: function( type, data, fn ) {
  2623. return this.each(function(){
  2624. jQuery.event.add( this, type, fn || data, data );
  2625. });
  2626. },
  2627. /**
  2628. * Binds a handler to a particular event (like click) for each matched element.
  2629. * The handler is executed only once for each element. Otherwise, the same rules
  2630. * as described in bind() apply.
  2631. The event handler is passed an event object that you can use to prevent
  2632. * default behaviour. To stop both default action and event bubbling, your handler
  2633. * has to return false.
  2634. *
  2635. * In most cases, you can define your event handlers as anonymous functions
  2636. * (see first example). In cases where that is not possible, you can pass additional
  2637. * data as the second paramter (and the handler function as the third), see
  2638. * second example.
  2639. *
  2640. * @example $("p").one("click", function(){
  2641. * alert( $(this).text() );
  2642. * });
  2643. * @before <p>Hello</p>
  2644. * @result alert("Hello")
  2645. *
  2646. * @name one
  2647. * @type jQuery
  2648. * @param String type An event type
  2649. * @param Object data (optional) Additional data passed to the event handler as event.data
  2650. * @param Function fn A function to bind to the event on each of the set of matched elements
  2651. * @cat Events
  2652. */
  2653. one: function( type, data, fn ) {
  2654. return this.each(function(){
  2655. jQuery.event.add( this, type, function(event) {
  2656. jQuery(this).unbind(event);
  2657. return (fn || data).apply( this, arguments);
  2658. }, data);
  2659. });
  2660. },
  2661. /**
  2662. * The opposite of bind, removes a bound event from each of the matched
  2663. * elements.
  2664. *
  2665. * Without any arguments, all bound events are removed.
  2666. *
  2667. * If the type is provided, all bound events of that type are removed.
  2668. *
  2669. * If the function that was passed to bind is provided as the second argument,
  2670. * only that specific event handler is removed.
  2671. *
  2672. * @example $("p").unbind()
  2673. * @before <p onclick="alert('Hello');">Hello</p>
  2674. * @result [ <p>Hello</p> ]
  2675. *
  2676. * @example $("p").unbind( "click" )
  2677. * @before <p onclick="alert('Hello');">Hello</p>
  2678. * @result [ <p>Hello</p> ]
  2679. *
  2680. * @example $("p").unbind( "click", function() { alert("Hello"); } )
  2681. * @before <p onclick="alert('Hello');">Hello</p>
  2682. * @result [ <p>Hello</p> ]
  2683. *
  2684. * @name unbind
  2685. * @type jQuery
  2686. * @param String type (optional) An event type
  2687. * @param Function fn (optional) A function to unbind from the event on each of the set of matched elements
  2688. * @cat Events
  2689. */
  2690. unbind: function( type, fn ) {
  2691. return this.each(function(){
  2692. jQuery.event.remove( this, type, fn );
  2693. });
  2694. },
  2695. /**
  2696. * Trigger a type of event on every matched element.
  2697. *
  2698. * @example $("p").trigger("click")
  2699. * @before <p click="alert('hello')">Hello</p>
  2700. * @result alert('hello')
  2701. *
  2702. * @name trigger
  2703. * @type jQuery
  2704. * @param String type An event type to trigger.
  2705. * @cat Events
  2706. */
  2707. trigger: function( type, data ) {
  2708. return this.each(function(){
  2709. jQuery.event.trigger( type, data, this );
  2710. });
  2711. },
  2712. /**
  2713. * Toggle between two function calls every other click.
  2714. * Whenever a matched element is clicked, the first specified function
  2715. * is fired, when clicked again, the second is fired. All subsequent
  2716. * clicks continue to rotate through the two functions.
  2717. *
  2718. * Use unbind("click") to remove.
  2719. *
  2720. * @example $("p").toggle(function(){
  2721. * $(this).addClass("selected");
  2722. * },function(){
  2723. * $(this).removeClass("selected");
  2724. * });
  2725. *
  2726. * @name toggle
  2727. * @type jQuery
  2728. * @param Function even The function to execute on every even click.
  2729. * @param Function odd The function to execute on every odd click.
  2730. * @cat Events
  2731. */
  2732. toggle: function() {
  2733. // Save reference to arguments for access in closure
  2734. var a = arguments;
  2735. return this.click(function(e) {
  2736. // Figure out which function to execute
  2737. this.lastToggle = this.lastToggle == 0 ? 1 : 0;
  2738. // Make sure that clicks stop
  2739. e.preventDefault();
  2740. // and execute the function
  2741. return a[this.lastToggle].apply( this, [e] ) || false;
  2742. });
  2743. },
  2744. /**
  2745. * A method for simulating hovering (moving the mouse on, and off,
  2746. * an object). This is a custom method which provides an 'in' to a
  2747. * frequent task.
  2748. *
  2749. * Whenever the mouse cursor is moved over a matched
  2750. * element, the first specified function is fired. Whenever the mouse
  2751. * moves off of the element, the second specified function fires.
  2752. * Additionally, checks are in place to see if the mouse is still within
  2753. * the specified element itself (for example, an image inside of a div),
  2754. * and if it is, it will continue to 'hover', and not move out
  2755. * (a common error in using a mouseout event handler).
  2756. *
  2757. * @example $("p").hover(function(){
  2758. * $(this).addClass("over");
  2759. * },function(){
  2760. * $(this).addClass("out");
  2761. * });
  2762. *
  2763. * @name hover
  2764. * @type jQuery
  2765. * @param Function over The function to fire whenever the mouse is moved over a matched element.
  2766. * @param Function out The function to fire whenever the mouse is moved off of a matched element.
  2767. * @cat Events
  2768. */
  2769. hover: function(f,g) {
  2770. // A private function for handling mouse 'hovering'
  2771. function handleHover(e) {
  2772. // Check if mouse(over|out) are still within the same parent element
  2773. var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
  2774. // Traverse up the tree
  2775. while ( p && p != this ) try { p = p.parentNode } catch(e) { p = this; };
  2776. // If we actually just moused on to a sub-element, ignore it
  2777. if ( p == this ) return false;
  2778. // Execute the right function
  2779. return (e.type == "mouseover" ? f : g).apply(this, [e]);
  2780. }
  2781. // Bind the function to the two event listeners
  2782. return this.mouseover(handleHover).mouseout(handleHover);
  2783. },
  2784. /**
  2785. * Bind a function to be executed whenever the DOM is ready to be
  2786. * traversed and manipulated. This is probably the most important
  2787. * function included in the event module, as it can greatly improve
  2788. * the response times of your web applications.
  2789. *
  2790. * In a nutshell, this is a solid replacement for using window.onload,
  2791. * and attaching a function to that. By using this method, your bound Function
  2792. * will be called the instant the DOM is ready to be read and manipulated,
  2793. * which is exactly what 99.99% of all Javascript code needs to run.
  2794. *
  2795. * There is one argument passed to the ready event handler: A reference to
  2796. * the jQuery function. You can name that argument whatever you like, and
  2797. * can therefore stick with the $ alias without risc of naming collisions.
  2798. *
  2799. * Please ensure you have no code in your &lt;body&gt; onload event handler,
  2800. * otherwise $(document).ready() may not fire.
  2801. *
  2802. * You can have as many $(document).ready events on your page as you like.
  2803. * The functions are then executed in the order they were added.
  2804. *
  2805. * @example $(document).ready(function(){ Your code here... });
  2806. *
  2807. * @example jQuery(function($) {
  2808. * // Your code using failsafe $ alias here...
  2809. * });
  2810. * @desc Uses both the shortcut for $(document).ready() and the argument
  2811. * to write failsafe jQuery code using the $ alias, without relying on the
  2812. * global alias.
  2813. *
  2814. * @name ready
  2815. * @type jQuery
  2816. * @param Function fn The function to be executed when the DOM is ready.
  2817. * @cat Events
  2818. * @see $.noConflict()
  2819. * @see $(Function)
  2820. */
  2821. ready: function(f) {
  2822. // If the DOM is already ready
  2823. if ( jQuery.isReady )
  2824. // Execute the function immediately
  2825. f.apply( document, [jQuery] );
  2826. // Otherwise, remember the function for later
  2827. else {
  2828. // Add the function to the wait list
  2829. jQuery.readyList.push( function() { return f.apply(this, [jQuery]) } );
  2830. }
  2831. return this;
  2832. }
  2833. });
  2834. jQuery.extend({
  2835. /*
  2836. * All the code that makes DOM Ready work nicely.
  2837. */
  2838. isReady: false,
  2839. readyList: [],
  2840. // Handle when the DOM is ready
  2841. ready: function() {
  2842. // Make sure that the DOM is not already loaded
  2843. if ( !jQuery.isReady ) {
  2844. // Remember that the DOM is ready
  2845. jQuery.isReady = true;
  2846. // If there are functions bound, to execute
  2847. if ( jQuery.readyList ) {
  2848. // Execute all of them
  2849. jQuery.each( jQuery.readyList, function(){
  2850. this.apply( document );
  2851. });
  2852. // Reset the list of functions
  2853. jQuery.readyList = null;
  2854. }
  2855. // Remove event lisenter to avoid memory leak
  2856. if ( jQuery.browser.mozilla || jQuery.browser.opera )
  2857. document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
  2858. }
  2859. }
  2860. });
  2861. new function(){
  2862. /**
  2863. * Bind a function to the scroll event of each matched element.
  2864. *
  2865. * @example $("p").scroll( function() { alert("Hello"); } );
  2866. * @before <p>Hello</p>
  2867. * @result <p onscroll="alert('Hello');">Hello</p>
  2868. *
  2869. * @name scroll
  2870. * @type jQuery
  2871. * @param Function fn A function to bind to the scroll event on each of the matched elements.
  2872. * @cat Events
  2873. */
  2874. /**
  2875. * Bind a function to the submit event of each matched element.
  2876. *
  2877. * @example $("#myform").submit( function() {
  2878. * return $("input", this).val().length > 0;
  2879. * } );
  2880. * @before <form id="myform"><input /></form>
  2881. * @desc Prevents the form submission when the input has no value entered.
  2882. *
  2883. * @name submit
  2884. * @type jQuery
  2885. * @param Function fn A function to bind to the submit event on each of the matched elements.
  2886. * @cat Events
  2887. */
  2888. /**
  2889. * Trigger the submit event of each matched element. This causes all of the functions
  2890. * that have been bound to thet submit event to be executed.
  2891. *
  2892. * Note: This does not execute the submit method of the form element! If you need to
  2893. * submit the form via code, you have to use the DOM method, eg. $("form")[0].submit();
  2894. *
  2895. * @example $("form").submit();
  2896. * @desc Triggers all submit events registered for forms, but does not submit the form
  2897. *
  2898. * @name submit
  2899. * @type jQuery
  2900. * @cat Events
  2901. */
  2902. /**
  2903. * Bind a function to the focus event of each matched element.
  2904. *
  2905. * @example $("p").focus( function() { alert("Hello"); } );
  2906. * @before <p>Hello</p>
  2907. * @result <p onfocus="alert('Hello');">Hello</p>
  2908. *
  2909. * @name focus
  2910. * @type jQuery
  2911. * @param Function fn A function to bind to the focus event on each of the matched elements.
  2912. * @cat Events
  2913. */
  2914. /**
  2915. * Trigger the focus event of each matched element. This causes all of the functions
  2916. * that have been bound to thet focus event to be executed.
  2917. *
  2918. * Note: This does not execute the focus method of the underlying elements! If you need to
  2919. * focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus();
  2920. *
  2921. * @example $("p").focus();
  2922. * @before <p onfocus="alert('Hello');">Hello</p>
  2923. * @result alert('Hello');
  2924. *
  2925. * @name focus
  2926. * @type jQuery
  2927. * @cat Events
  2928. */
  2929. /**
  2930. * Bind a function to the keydown event of each matched element.
  2931. *
  2932. * @example $("p").keydown( function() { alert("Hello"); } );
  2933. * @before <p>Hello</p>
  2934. * @result <p onkeydown="alert('Hello');">Hello</p>
  2935. *
  2936. * @name keydown
  2937. * @type jQuery
  2938. * @param Function fn A function to bind to the keydown event on each of the matched elements.
  2939. * @cat Events
  2940. */
  2941. /**
  2942. * Bind a function to the dblclick event of each matched element.
  2943. *
  2944. * @example $("p").dblclick( function() { alert("Hello"); } );
  2945. * @before <p>Hello</p>
  2946. * @result <p ondblclick="alert('Hello');">Hello</p>
  2947. *
  2948. * @name dblclick
  2949. * @type jQuery
  2950. * @param Function fn A function to bind to the dblclick event on each of the matched elements.
  2951. * @cat Events
  2952. */
  2953. /**
  2954. * Bind a function to the keypress event of each matched element.
  2955. *
  2956. * @example $("p").keypress( function() { alert("Hello"); } );
  2957. * @before <p>Hello</p>
  2958. * @result <p onkeypress="alert('Hello');">Hello</p>
  2959. *
  2960. * @name keypress
  2961. * @type jQuery
  2962. * @param Function fn A function to bind to the keypress event on each of the matched elements.
  2963. * @cat Events
  2964. */
  2965. /**
  2966. * Bind a function to the error event of each matched element.
  2967. *
  2968. * @example $("p").error( function() { alert("Hello"); } );
  2969. * @before <p>Hello</p>
  2970. * @result <p onerror="alert('Hello');">Hello</p>
  2971. *
  2972. * @name error
  2973. * @type jQuery
  2974. * @param Function fn A function to bind to the error event on each of the matched elements.
  2975. * @cat Events
  2976. */
  2977. /**
  2978. * Bind a function to the blur event of each matched element.
  2979. *
  2980. * @example $("p").blur( function() { alert("Hello"); } );
  2981. * @before <p>Hello</p>
  2982. * @result <p onblur="alert('Hello');">Hello</p>
  2983. *
  2984. * @name blur
  2985. * @type jQuery
  2986. * @param Function fn A function to bind to the blur event on each of the matched elements.
  2987. * @cat Events
  2988. */
  2989. /**
  2990. * Trigger the blur event of each matched element. This causes all of the functions
  2991. * that have been bound to thet blur event to be executed.
  2992. *
  2993. * Note: This does not execute the blur method of the underlying elements! If you need to
  2994. * blur an element via code, you have to use the DOM method, eg. $("#myinput")[0].blur();
  2995. *
  2996. * @example $("p").blur();
  2997. * @before <p onblur="alert('Hello');">Hello</p>
  2998. * @result alert('Hello');
  2999. *
  3000. * @name blur
  3001. * @type jQuery
  3002. * @cat Events
  3003. */
  3004. /**
  3005. * Bind a function to the load event of each matched element.
  3006. *
  3007. * @example $("p").load( function() { alert("Hello"); } );
  3008. * @before <p>Hello</p>
  3009. * @result <p onload="alert('Hello');">Hello</p>
  3010. *
  3011. * @name load
  3012. * @type jQuery
  3013. * @param Function fn A function to bind to the load event on each of the matched elements.
  3014. * @cat Events
  3015. */
  3016. /**
  3017. * Bind a function to the select event of each matched element.
  3018. *
  3019. * @example $("p").select( function() { alert("Hello"); } );
  3020. * @before <p>Hello</p>
  3021. * @result <p onselect="alert('Hello');">Hello</p>
  3022. *
  3023. * @name select
  3024. * @type jQuery
  3025. * @param Function fn A function to bind to the select event on each of the matched elements.
  3026. * @cat Events
  3027. */
  3028. /**
  3029. * Trigger the select event of each matched element. This causes all of the functions
  3030. * that have been bound to thet select event to be executed.
  3031. *
  3032. * @example $("p").select();
  3033. * @before <p onselect="alert('Hello');">Hello</p>
  3034. * @result alert('Hello');
  3035. *
  3036. * @name select
  3037. * @type jQuery
  3038. * @cat Events
  3039. */
  3040. /**
  3041. * Bind a function to the mouseup event of each matched element.
  3042. *
  3043. * @example $("p").mouseup( function() { alert("Hello"); } );
  3044. * @before <p>Hello</p>
  3045. * @result <p onmouseup="alert('Hello');">Hello</p>
  3046. *
  3047. * @name mouseup
  3048. * @type jQuery
  3049. * @param Function fn A function to bind to the mouseup event on each of the matched elements.
  3050. * @cat Events
  3051. */
  3052. /**
  3053. * Bind a function to the unload event of each matched element.
  3054. *
  3055. * @example $("p").unload( function() { alert("Hello"); } );
  3056. * @before <p>Hello</p>
  3057. * @result <p onunload="alert('Hello');">Hello</p>
  3058. *
  3059. * @name unload
  3060. * @type jQuery
  3061. * @param Function fn A function to bind to the unload event on each of the matched elements.
  3062. * @cat Events
  3063. */
  3064. /**
  3065. * Bind a function to the change event of each matched element.
  3066. *
  3067. * @example $("p").change( function() { alert("Hello"); } );
  3068. * @before <p>Hello</p>
  3069. * @result <p onchange="alert('Hello');">Hello</p>
  3070. *
  3071. * @name change
  3072. * @type jQuery
  3073. * @param Function fn A function to bind to the change event on each of the matched elements.
  3074. * @cat Events
  3075. */
  3076. /**
  3077. * Bind a function to the mouseout event of each matched element.
  3078. *
  3079. * @example $("p").mouseout( function() { alert("Hello"); } );
  3080. * @before <p>Hello</p>
  3081. * @result <p onmouseout="alert('Hello');">Hello</p>
  3082. *
  3083. * @name mouseout
  3084. * @type jQuery
  3085. * @param Function fn A function to bind to the mouseout event on each of the matched elements.
  3086. * @cat Events
  3087. */
  3088. /**
  3089. * Bind a function to the keyup event of each matched element.
  3090. *
  3091. * @example $("p").keyup( function() { alert("Hello"); } );
  3092. * @before <p>Hello</p>
  3093. * @result <p onkeyup="alert('Hello');">Hello</p>
  3094. *
  3095. * @name keyup
  3096. * @type jQuery
  3097. * @param Function fn A function to bind to the keyup event on each of the matched elements.
  3098. * @cat Events
  3099. */
  3100. /**
  3101. * Bind a function to the click event of each matched element.
  3102. *
  3103. * @example $("p").click( function() { alert("Hello"); } );
  3104. * @before <p>Hello</p>
  3105. * @result <p onclick="alert('Hello');">Hello</p>
  3106. *
  3107. * @name click
  3108. * @type jQuery
  3109. * @param Function fn A function to bind to the click event on each of the matched elements.
  3110. * @cat Events
  3111. */
  3112. /**
  3113. * Trigger the click event of each matched element. This causes all of the functions
  3114. * that have been bound to thet click event to be executed.
  3115. *
  3116. * @example $("p").click();
  3117. * @before <p onclick="alert('Hello');">Hello</p>
  3118. * @result alert('Hello');
  3119. *
  3120. * @name click
  3121. * @type jQuery
  3122. * @cat Events
  3123. */
  3124. /**
  3125. * Bind a function to the resize event of each matched element.
  3126. *
  3127. * @example $("p").resize( function() { alert("Hello"); } );
  3128. * @before <p>Hello</p>
  3129. * @result <p onresize="alert('Hello');">Hello</p>
  3130. *
  3131. * @name resize
  3132. * @type jQuery
  3133. * @param Function fn A function to bind to the resize event on each of the matched elements.
  3134. * @cat Events
  3135. */
  3136. /**
  3137. * Bind a function to the mousemove event of each matched element.
  3138. *
  3139. * @example $("p").mousemove( function() { alert("Hello"); } );
  3140. * @before <p>Hello</p>
  3141. * @result <p onmousemove="alert('Hello');">Hello</p>
  3142. *
  3143. * @name mousemove
  3144. * @type jQuery
  3145. * @param Function fn A function to bind to the mousemove event on each of the matched elements.
  3146. * @cat Events
  3147. */
  3148. /**
  3149. * Bind a function to the mousedown event of each matched element.
  3150. *
  3151. * @example $("p").mousedown( function() { alert("Hello"); } );
  3152. * @before <p>Hello</p>
  3153. * @result <p onmousedown="alert('Hello');">Hello</p>
  3154. *
  3155. * @name mousedown
  3156. * @type jQuery
  3157. * @param Function fn A function to bind to the mousedown event on each of the matched elements.
  3158. * @cat Events
  3159. */
  3160. /**
  3161. * Bind a function to the mouseover event of each matched element.
  3162. *
  3163. * @example $("p").mouseover( function() { alert("Hello"); } );
  3164. * @before <p>Hello</p>
  3165. * @result <p onmouseover="alert('Hello');">Hello</p>
  3166. *
  3167. * @name mouseover
  3168. * @type jQuery
  3169. * @param Function fn A function to bind to the mousedown event on each of the matched elements.
  3170. * @cat Events
  3171. */
  3172. jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
  3173. "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
  3174. "submit,keydown,keypress,keyup,error").split(","), function(i,o){
  3175. // Handle event binding
  3176. jQuery.fn[o] = function(f){
  3177. return f ? this.bind(o, f) : this.trigger(o);
  3178. };
  3179. });
  3180. // If Mozilla is used
  3181. if ( jQuery.browser.mozilla || jQuery.browser.opera )
  3182. // Use the handy event callback
  3183. document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
  3184. // If IE is used, use the excellent hack by Matthias Miller
  3185. // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
  3186. else if ( jQuery.browser.msie ) {
  3187. // Only works if you document.write() it
  3188. document.write("<scr" + "ipt id=__ie_init defer=true " +
  3189. "src=//:><\/script>");
  3190. // Use the defer script hack
  3191. var script = document.getElementById("__ie_init");
  3192. // script does not exist if jQuery is loaded dynamically
  3193. if ( script )
  3194. script.onreadystatechange = function() {
  3195. if ( this.readyState != "complete" ) return;
  3196. this.parentNode.removeChild( this );
  3197. jQuery.ready();
  3198. };
  3199. // Clear from memory
  3200. script = null;
  3201. // If Safari is used
  3202. } else if ( jQuery.browser.safari )
  3203. // Continually check to see if the document.readyState is valid
  3204. jQuery.safariTimer = setInterval(function(){
  3205. // loaded and complete are both valid states
  3206. if ( document.readyState == "loaded" ||
  3207. document.readyState == "complete" ) {
  3208. // If either one are found, remove the timer
  3209. clearInterval( jQuery.safariTimer );
  3210. jQuery.safariTimer = null;
  3211. // and execute any waiting functions
  3212. jQuery.ready();
  3213. }
  3214. }, 10);
  3215. // A fallback to window.onload, that will always work
  3216. jQuery.event.add( window, "load", jQuery.ready );
  3217. };
  3218. // Clean up after IE to avoid memory leaks
  3219. if (jQuery.browser.msie)
  3220. jQuery(window).one("unload", function() {
  3221. var global = jQuery.event.global;
  3222. for ( var type in global ) {
  3223. var els = global[type], i = els.length;
  3224. if ( i && type != 'unload' )
  3225. do
  3226. jQuery.event.remove(els[i-1], type);
  3227. while (--i);
  3228. }
  3229. });
  3230. jQuery.fn.extend({
  3231. /**
  3232. * Displays each of the set of matched elements if they are hidden.
  3233. *
  3234. * @example $("p").show()
  3235. * @before <p style="display: none">Hello</p>
  3236. * @result [ <p style="display: block">Hello</p> ]
  3237. *
  3238. * @name show
  3239. * @type jQuery
  3240. * @cat Effects
  3241. */
  3242. /**
  3243. * Show all matched elements using a graceful animation and firing an
  3244. * optional callback after completion.
  3245. *
  3246. * The height, width, and opacity of each of the matched elements
  3247. * are changed dynamically according to the specified speed.
  3248. *
  3249. * @example $("p").show("slow");
  3250. *
  3251. * @example $("p").show("slow",function(){
  3252. * alert("Animation Done.");
  3253. * });
  3254. *
  3255. * @name show
  3256. * @type jQuery
  3257. * @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
  3258. * @param Function callback (optional) A function to be executed whenever the animation completes.
  3259. * @cat Effects
  3260. * @see hide(String|Number,Function)
  3261. */
  3262. show: function(speed,callback){
  3263. var hidden = this.filter(":hidden");
  3264. speed ?
  3265. hidden.animate({
  3266. height: "show", width: "show", opacity: "show"
  3267. }, speed, callback) :
  3268. hidden.each(function(){
  3269. this.style.display = this.oldblock ? this.oldblock : "";
  3270. if ( jQuery.css(this,"display") == "none" )
  3271. this.style.display = "block";
  3272. });
  3273. return this;
  3274. },
  3275. /**
  3276. * Hides each of the set of matched elements if they are shown.
  3277. *
  3278. * @example $("p").hide()
  3279. * @before <p>Hello</p>
  3280. * @result [ <p style="display: none">Hello</p> ]
  3281. *
  3282. * @name hide
  3283. * @type jQuery
  3284. * @cat Effects
  3285. */
  3286. /**
  3287. * Hide all matched elements using a graceful animation and firing an
  3288. * optional callback after completion.
  3289. *
  3290. * The height, width, and opacity of each of the matched elements
  3291. * are changed dynamically according to the specified speed.
  3292. *
  3293. * @example $("p").hide("slow");
  3294. *
  3295. * @example $("p").hide("slow",function(){
  3296. * alert("Animation Done.");
  3297. * });
  3298. *
  3299. * @name hide
  3300. * @type jQuery
  3301. * @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
  3302. * @param Function callback (optional) A function to be executed whenever the animation completes.
  3303. * @cat Effects
  3304. * @see show(String|Number,Function)
  3305. */
  3306. hide: function(speed,callback){
  3307. var visible = this.filter(":visible");
  3308. speed ?
  3309. visible.animate({
  3310. height: "hide", width: "hide", opacity: "hide"
  3311. }, speed, callback) :
  3312. visible.each(function(){
  3313. this.oldblock = this.oldblock || jQuery.css(this,"display");
  3314. if ( this.oldblock == "none" )
  3315. this.oldblock = "block";
  3316. this.style.display = "none";
  3317. });
  3318. return this;
  3319. },
  3320. // Save the old toggle function
  3321. _toggle: jQuery.fn.toggle,
  3322. /**
  3323. * Toggles each of the set of matched elements. If they are shown,
  3324. * toggle makes them hidden. If they are hidden, toggle
  3325. * makes them shown.
  3326. *
  3327. * @example $("p").toggle()
  3328. * @before <p>Hello</p><p style="display: none">Hello Again</p>
  3329. * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
  3330. *
  3331. * @name toggle
  3332. * @type jQuery
  3333. * @cat Effects
  3334. */
  3335. toggle: function( fn, fn2 ){
  3336. var args = arguments;
  3337. return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
  3338. this._toggle( fn, fn2 ) :
  3339. this.each(function(){
  3340. jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]
  3341. .apply( jQuery(this), args );
  3342. });
  3343. },
  3344. /**
  3345. * Reveal all matched elements by adjusting their height and firing an
  3346. * optional callback after completion.
  3347. *
  3348. * Only the height is adjusted for this animation, causing all matched
  3349. * elements to be revealed in a "sliding" manner.
  3350. *
  3351. * @example $("p").slideDown("slow");
  3352. *
  3353. * @example $("p").slideDown("slow",function(){
  3354. * alert("Animation Done.");
  3355. * });
  3356. *
  3357. * @name slideDown
  3358. * @type jQuery
  3359. * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
  3360. * @param Function callback (optional) A function to be executed whenever the animation completes.
  3361. * @cat Effects
  3362. * @see slideUp(String|Number,Function)
  3363. * @see slideToggle(String|Number,Function)
  3364. */
  3365. slideDown: function(speed,callback){
  3366. return this.animate({height: "show"}, speed, callback);
  3367. },
  3368. /**
  3369. * Hide all matched elements by adjusting their height and firing an
  3370. * optional callback after completion.
  3371. *
  3372. * Only the height is adjusted for this animation, causing all matched
  3373. * elements to be hidden in a "sliding" manner.
  3374. *
  3375. * @example $("p").slideUp("slow");
  3376. *
  3377. * @example $("p").slideUp("slow",function(){
  3378. * alert("Animation Done.");
  3379. * });
  3380. *
  3381. * @name slideUp
  3382. * @type jQuery
  3383. * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
  3384. * @param Function callback (optional) A function to be executed whenever the animation completes.
  3385. * @cat Effects
  3386. * @see slideDown(String|Number,Function)
  3387. * @see slideToggle(String|Number,Function)
  3388. */
  3389. slideUp: function(speed,callback){
  3390. return this.animate({height: "hide"}, speed, callback);
  3391. },
  3392. /**
  3393. * Toggle the visibility of all matched elements by adjusting their height and firing an
  3394. * optional callback after completion.
  3395. *
  3396. * Only the height is adjusted for this animation, causing all matched
  3397. * elements to be hidden in a "sliding" manner.
  3398. *
  3399. * @example $("p").slideToggle("slow");
  3400. *
  3401. * @example $("p").slideToggle("slow",function(){
  3402. * alert("Animation Done.");
  3403. * });
  3404. *
  3405. * @name slideToggle
  3406. * @type jQuery
  3407. * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
  3408. * @param Function callback (optional) A function to be executed whenever the animation completes.
  3409. * @cat Effects
  3410. * @see slideDown(String|Number,Function)
  3411. * @see slideUp(String|Number,Function)
  3412. */
  3413. slideToggle: function(speed, callback){
  3414. return this.each(function(){
  3415. var state = jQuery(this).is(":hidden") ? "show" : "hide";
  3416. jQuery(this).animate({height: state}, speed, callback);
  3417. });
  3418. },
  3419. /**
  3420. * Fade in all matched elements by adjusting their opacity and firing an
  3421. * optional callback after completion.
  3422. *
  3423. * Only the opacity is adjusted for this animation, meaning that
  3424. * all of the matched elements should already have some form of height
  3425. * and width associated with them.
  3426. *
  3427. * @example $("p").fadeIn("slow");
  3428. *
  3429. * @example $("p").fadeIn("slow",function(){
  3430. * alert("Animation Done.");
  3431. * });
  3432. *
  3433. * @name fadeIn
  3434. * @type jQuery
  3435. * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
  3436. * @param Function callback (optional) A function to be executed whenever the animation completes.
  3437. * @cat Effects
  3438. * @see fadeOut(String|Number,Function)
  3439. * @see fadeTo(String|Number,Number,Function)
  3440. */
  3441. fadeIn: function(speed, callback){
  3442. return this.animate({opacity: "show"}, speed, callback);
  3443. },
  3444. /**
  3445. * Fade out all matched elements by adjusting their opacity and firing an
  3446. * optional callback after completion.
  3447. *
  3448. * Only the opacity is adjusted for this animation, meaning that
  3449. * all of the matched elements should already have some form of height
  3450. * and width associated with them.
  3451. *
  3452. * @example $("p").fadeOut("slow");
  3453. *
  3454. * @example $("p").fadeOut("slow",function(){
  3455. * alert("Animation Done.");
  3456. * });
  3457. *
  3458. * @name fadeOut
  3459. * @type jQuery
  3460. * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
  3461. * @param Function callback (optional) A function to be executed whenever the animation completes.
  3462. * @cat Effects
  3463. * @see fadeIn(String|Number,Function)
  3464. * @see fadeTo(String|Number,Number,Function)
  3465. */
  3466. fadeOut: function(speed, callback){
  3467. return this.animate({opacity: "hide"}, speed, callback);
  3468. },
  3469. /**
  3470. * Fade the opacity of all matched elements to a specified opacity and firing an
  3471. * optional callback after completion.
  3472. *
  3473. * Only the opacity is adjusted for this animation, meaning that
  3474. * all of the matched elements should already have some form of height
  3475. * and width associated with them.
  3476. *
  3477. * @example $("p").fadeTo("slow", 0.5);
  3478. *
  3479. * @example $("p").fadeTo("slow", 0.5, function(){
  3480. * alert("Animation Done.");
  3481. * });
  3482. *
  3483. * @name fadeTo
  3484. * @type jQuery
  3485. * @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
  3486. * @param Number opacity The opacity to fade to (a number from 0 to 1).
  3487. * @param Function callback (optional) A function to be executed whenever the animation completes.
  3488. * @cat Effects
  3489. * @see fadeIn(String|Number,Function)
  3490. * @see fadeOut(String|Number,Function)
  3491. */
  3492. fadeTo: function(speed,to,callback){
  3493. return this.animate({opacity: to}, speed, callback);
  3494. },
  3495. /**
  3496. * A function for making your own, custom, animations. The key aspect of
  3497. * this function is the object of style properties that will be animated,
  3498. * and to what end. Each key within the object represents a style property
  3499. * that will also be animated (for example: "height", "top", or "opacity").
  3500. *
  3501. * The value associated with the key represents to what end the property
  3502. * will be animated. If a number is provided as the value, then the style
  3503. * property will be transitioned from its current state to that new number.
  3504. * Oterwise if the string "hide", "show", or "toggle" is provided, a default
  3505. * animation will be constructed for that property.
  3506. *
  3507. * @example $("p").animate({
  3508. * height: 'toggle', opacity: 'toggle'
  3509. * }, "slow");
  3510. *
  3511. * @example $("p").animate({
  3512. * left: 50, opacity: 'show'
  3513. * }, 500);
  3514. *
  3515. * @example $("p").animate({
  3516. * opacity: 'show'
  3517. * }, "slow", "easein");
  3518. * @desc An example of using an 'easing' function to provide a different style of animation. This will only work if you have a plugin that provides this easing function (Only 'linear' is provided by default, with jQuery).
  3519. *
  3520. * @name animate
  3521. * @type jQuery
  3522. * @param Hash params A set of style attributes that you wish to animate, and to what end.
  3523. * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
  3524. * @param String easing (optional) The name of the easing effect that you want to use (Plugin Required).
  3525. * @param Function callback (optional) A function to be executed whenever the animation completes.
  3526. * @cat Effects
  3527. */
  3528. animate: function( prop, speed, easing, callback ) {
  3529. return this.queue(function(){
  3530. this.curAnim = jQuery.extend({}, prop);
  3531. var opt = jQuery.speed(speed, easing, callback);
  3532. for ( var p in prop ) {
  3533. var e = new jQuery.fx( this, opt, p );
  3534. if ( prop[p].constructor == Number )
  3535. e.custom( e.cur(), prop[p] );
  3536. else
  3537. e[ prop[p] ]( prop );
  3538. }
  3539. });
  3540. },
  3541. /**
  3542. *
  3543. * @private
  3544. */
  3545. queue: function(type,fn){
  3546. if ( !fn ) {
  3547. fn = type;
  3548. type = "fx";
  3549. }
  3550. return this.each(function(){
  3551. if ( !this.queue )
  3552. this.queue = {};
  3553. if ( !this.queue[type] )
  3554. this.queue[type] = [];
  3555. this.queue[type].push( fn );
  3556. if ( this.queue[type].length == 1 )
  3557. fn.apply(this);
  3558. });
  3559. }
  3560. });
  3561. jQuery.extend({
  3562. speed: function(speed, easing, fn) {
  3563. var opt = speed && speed.constructor == Object ? speed : {
  3564. complete: fn || !fn && easing ||
  3565. jQuery.isFunction( speed ) && speed,
  3566. duration: speed,
  3567. easing: fn && easing || easing && easing.constructor != Function && easing
  3568. };
  3569. opt.duration = (opt.duration && opt.duration.constructor == Number ?
  3570. opt.duration :
  3571. { slow: 600, fast: 200 }[opt.duration]) || 400;
  3572. // Queueing
  3573. opt.old = opt.complete;
  3574. opt.complete = function(){
  3575. jQuery.dequeue(this, "fx");
  3576. if ( jQuery.isFunction( opt.old ) )
  3577. opt.old.apply( this );
  3578. };
  3579. return opt;
  3580. },
  3581. easing: {},
  3582. queue: {},
  3583. dequeue: function(elem,type){
  3584. type = type || "fx";
  3585. if ( elem.queue && elem.queue[type] ) {
  3586. // Remove self
  3587. elem.queue[type].shift();
  3588. // Get next function
  3589. var f = elem.queue[type][0];
  3590. if ( f ) f.apply( elem );
  3591. }
  3592. },
  3593. /*
  3594. * I originally wrote fx() as a clone of moo.fx and in the process
  3595. * of making it small in size the code became illegible to sane
  3596. * people. You've been warned.
  3597. */
  3598. fx: function( elem, options, prop ){
  3599. var z = this;
  3600. // The styles
  3601. var y = elem.style;
  3602. // Store display property
  3603. var oldDisplay = jQuery.css(elem, "display");
  3604. // Set display property to block for animation
  3605. y.display = "block";
  3606. // Make sure that nothing sneaks out
  3607. y.overflow = "hidden";
  3608. // Simple function for setting a style value
  3609. z.a = function(){
  3610. if ( options.step )
  3611. options.step.apply( elem, [ z.now ] );
  3612. if ( prop == "opacity" )
  3613. jQuery.attr(y, "opacity", z.now); // Let attr handle opacity
  3614. else if ( parseInt(z.now) ) // My hate for IE will never die
  3615. y[prop] = parseInt(z.now) + "px";
  3616. };
  3617. // Figure out the maximum number to run to
  3618. z.max = function(){
  3619. return parseFloat( jQuery.css(elem,prop) );
  3620. };
  3621. // Get the current size
  3622. z.cur = function(){
  3623. var r = parseFloat( jQuery.curCSS(elem, prop) );
  3624. return r && r > -10000 ? r : z.max();
  3625. };
  3626. // Start an animation from one number to another
  3627. z.custom = function(from,to){
  3628. z.startTime = (new Date()).getTime();
  3629. z.now = from;
  3630. z.a();
  3631. z.timer = setInterval(function(){
  3632. z.step(from, to);
  3633. }, 13);
  3634. };
  3635. // Simple 'show' function
  3636. z.show = function(){
  3637. if ( !elem.orig ) elem.orig = {};
  3638. // Remember where we started, so that we can go back to it later
  3639. elem.orig[prop] = this.cur();
  3640. options.show = true;
  3641. // Begin the animation
  3642. z.custom(0, elem.orig[prop]);
  3643. // Stupid IE, look what you made me do
  3644. if ( prop != "opacity" )
  3645. y[prop] = "1px";
  3646. };
  3647. // Simple 'hide' function
  3648. z.hide = function(){
  3649. if ( !elem.orig ) elem.orig = {};
  3650. // Remember where we started, so that we can go back to it later
  3651. elem.orig[prop] = this.cur();
  3652. options.hide = true;
  3653. // Begin the animation
  3654. z.custom(elem.orig[prop], 0);
  3655. };
  3656. //Simple 'toggle' function
  3657. z.toggle = function() {
  3658. if ( !elem.orig ) elem.orig = {};
  3659. // Remember where we started, so that we can go back to it later
  3660. elem.orig[prop] = this.cur();
  3661. if(oldDisplay == "none") {
  3662. options.show = true;
  3663. // Stupid IE, look what you made me do
  3664. if ( prop != "opacity" )
  3665. y[prop] = "1px";
  3666. // Begin the animation
  3667. z.custom(0, elem.orig[prop]);
  3668. } else {
  3669. options.hide = true;
  3670. // Begin the animation
  3671. z.custom(elem.orig[prop], 0);
  3672. }
  3673. };
  3674. // Each step of an animation
  3675. z.step = function(firstNum, lastNum){
  3676. var t = (new Date()).getTime();
  3677. if (t > options.duration + z.startTime) {
  3678. // Stop the timer
  3679. clearInterval(z.timer);
  3680. z.timer = null;
  3681. z.now = lastNum;
  3682. z.a();
  3683. if (elem.curAnim) elem.curAnim[ prop ] = true;
  3684. var done = true;
  3685. for ( var i in elem.curAnim )
  3686. if ( elem.curAnim[i] !== true )
  3687. done = false;
  3688. if ( done ) {
  3689. // Reset the overflow
  3690. y.overflow = "";
  3691. // Reset the display
  3692. y.display = oldDisplay;
  3693. if (jQuery.css(elem, "display") == "none")
  3694. y.display = "block";
  3695. // Hide the element if the "hide" operation was done
  3696. if ( options.hide )
  3697. y.display = "none";
  3698. // Reset the properties, if the item has been hidden or shown
  3699. if ( options.hide || options.show )
  3700. for ( var p in elem.curAnim )
  3701. if (p == "opacity")
  3702. jQuery.attr(y, p, elem.orig[p]);
  3703. else
  3704. y[p] = "";
  3705. }
  3706. // If a callback was provided, execute it
  3707. if ( done && jQuery.isFunction( options.complete ) )
  3708. // Execute the complete function
  3709. options.complete.apply( elem );
  3710. } else {
  3711. var n = t - this.startTime;
  3712. // Figure out where in the animation we are and set the number
  3713. var p = n / options.duration;
  3714. // If the easing function exists, then use it
  3715. z.now = options.easing && jQuery.easing[options.easing] ?
  3716. jQuery.easing[options.easing](p, n, firstNum, (lastNum-firstNum), options.duration) :
  3717. // else use default linear easing
  3718. ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
  3719. // Perform the next step of the animation
  3720. z.a();
  3721. }
  3722. };
  3723. }
  3724. });
  3725. jQuery.fn.extend({
  3726. /**
  3727. * Load HTML from a remote file and inject it into the DOM, only if it's
  3728. * been modified by the server.
  3729. *
  3730. * @example $("#feeds").loadIfModified("feeds.html");
  3731. * @before <div id="feeds"></div>
  3732. * @result <div id="feeds"><b>45</b> feeds found.</div>
  3733. *
  3734. * @name loadIfModified
  3735. * @type jQuery
  3736. * @param String url The URL of the HTML file to load.
  3737. * @param Map params (optional) Key/value pairs that will be sent to the server.
  3738. * @param Function callback (optional) A function to be executed whenever the data is loaded (parameters: responseText, status and response itself).
  3739. * @cat Ajax
  3740. */
  3741. loadIfModified: function( url, params, callback ) {
  3742. this.load( url, params, callback, 1 );
  3743. },
  3744. /**
  3745. * Load HTML from a remote file and inject it into the DOM.
  3746. *
  3747. * Note: Avoid to use this to load scripts, instead use $.getScript.
  3748. * IE strips script tags when there aren't any other characters in front of it.
  3749. *
  3750. * @example $("#feeds").load("feeds.html");
  3751. * @before <div id="feeds"></div>
  3752. * @result <div id="feeds"><b>45</b> feeds found.</div>
  3753. *
  3754. * @example $("#feeds").load("feeds.html",
  3755. * {limit: 25},
  3756. * function() { alert("The last 25 entries in the feed have been loaded"); }
  3757. * );
  3758. * @desc Same as above, but with an additional parameter
  3759. * and a callback that is executed when the data was loaded.
  3760. *
  3761. * @name load
  3762. * @type jQuery
  3763. * @param String url The URL of the HTML file to load.
  3764. * @param Object params (optional) A set of key/value pairs that will be sent as data to the server.
  3765. * @param Function callback (optional) A function to be executed whenever the data is loaded (parameters: responseText, status and response itself).
  3766. * @cat Ajax
  3767. */
  3768. load: function( url, params, callback, ifModified ) {
  3769. if ( jQuery.isFunction( url ) )
  3770. return this.bind("load", url);
  3771. callback = callback || function(){};
  3772. // Default to a GET request
  3773. var type = "GET";
  3774. // If the second parameter was provided
  3775. if ( params )
  3776. // If it's a function
  3777. if ( jQuery.isFunction( params ) ) {
  3778. // We assume that it's the callback
  3779. callback = params;
  3780. params = null;
  3781. // Otherwise, build a param string
  3782. } else {
  3783. params = jQuery.param( params );
  3784. type = "POST";
  3785. }
  3786. var self = this;
  3787. // Request the remote document
  3788. jQuery.ajax({
  3789. url: url,
  3790. type: type,
  3791. data: params,
  3792. ifModified: ifModified,
  3793. complete: function(res, status){
  3794. if ( status == "success" || !ifModified && status == "notmodified" )
  3795. // Inject the HTML into all the matched elements
  3796. self.attr("innerHTML", res.responseText)
  3797. // Execute all the scripts inside of the newly-injected HTML
  3798. .evalScripts()
  3799. // Execute callback
  3800. .each( callback, [res.responseText, status, res] );
  3801. else
  3802. callback.apply( self, [res.responseText, status, res] );
  3803. }
  3804. });
  3805. return this;
  3806. },
  3807. /**
  3808. * Serializes a set of input elements into a string of data.
  3809. * This will serialize all given elements.
  3810. *
  3811. * A serialization similar to the form submit of a browser is
  3812. * provided by the form plugin. It also takes multiple-selects
  3813. * into account, while this method recognizes only a single option.
  3814. *
  3815. * @example $("input[@type=text]").serialize();
  3816. * @before <input type='text' name='name' value='John'/>
  3817. * <input type='text' name='location' value='Boston'/>
  3818. * @after name=John&location=Boston
  3819. * @desc Serialize a selection of input elements to a string
  3820. *
  3821. * @name serialize
  3822. * @type String
  3823. * @cat Ajax
  3824. */
  3825. serialize: function() {
  3826. return jQuery.param( this );
  3827. },
  3828. /**
  3829. * Evaluate all script tags inside this jQuery. If they have a src attribute,
  3830. * the script is loaded, otherwise it's content is evaluated.
  3831. *
  3832. * @name evalScripts
  3833. * @type jQuery
  3834. * @private
  3835. * @cat Ajax
  3836. */
  3837. evalScripts: function() {
  3838. return this.find("script").each(function(){
  3839. if ( this.src )
  3840. jQuery.getScript( this.src );
  3841. else
  3842. jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" );
  3843. }).end();
  3844. }
  3845. });
  3846. // If IE is used, create a wrapper for the XMLHttpRequest object
  3847. if ( !window.XMLHttpRequest )
  3848. XMLHttpRequest = function(){
  3849. return new ActiveXObject("Microsoft.XMLHTTP");
  3850. };
  3851. // Attach a bunch of functions for handling common AJAX events
  3852. /**
  3853. * Attach a function to be executed whenever an AJAX request begins
  3854. * and there is none already active.
  3855. *
  3856. * @example $("#loading").ajaxStart(function(){
  3857. * $(this).show();
  3858. * });
  3859. * @desc Show a loading message whenever an AJAX request starts
  3860. * (and none is already active).
  3861. *
  3862. * @name ajaxStart
  3863. * @type jQuery
  3864. * @param Function callback The function to execute.
  3865. * @cat Ajax
  3866. */
  3867. /**
  3868. * Attach a function to be executed whenever all AJAX requests have ended.
  3869. *
  3870. * @example $("#loading").ajaxStop(function(){
  3871. * $(this).hide();
  3872. * });
  3873. * @desc Hide a loading message after all the AJAX requests have stopped.
  3874. *
  3875. * @name ajaxStop
  3876. * @type jQuery
  3877. * @param Function callback The function to execute.
  3878. * @cat Ajax
  3879. */
  3880. /**
  3881. * Attach a function to be executed whenever an AJAX request completes.
  3882. *
  3883. * The XMLHttpRequest and settings used for that request are passed
  3884. * as arguments to the callback.
  3885. *
  3886. * @example $("#msg").ajaxComplete(function(request, settings){
  3887. * $(this).append("<li>Request Complete.</li>");
  3888. * });
  3889. * @desc Show a message when an AJAX request completes.
  3890. *
  3891. * @name ajaxComplete
  3892. * @type jQuery
  3893. * @param Function callback The function to execute.
  3894. * @cat Ajax
  3895. */
  3896. /**
  3897. * Attach a function to be executed whenever an AJAX request completes
  3898. * successfully.
  3899. *
  3900. * The XMLHttpRequest and settings used for that request are passed
  3901. * as arguments to the callback.
  3902. *
  3903. * @example $("#msg").ajaxSuccess(function(request, settings){
  3904. * $(this).append("<li>Successful Request!</li>");
  3905. * });
  3906. * @desc Show a message when an AJAX request completes successfully.
  3907. *
  3908. * @name ajaxSuccess
  3909. * @type jQuery
  3910. * @param Function callback The function to execute.
  3911. * @cat Ajax
  3912. */
  3913. /**
  3914. * Attach a function to be executed whenever an AJAX request fails.
  3915. *
  3916. * The XMLHttpRequest and settings used for that request are passed
  3917. * as arguments to the callback. A third argument, an exception object,
  3918. * is passed if an exception occured while processing the request.
  3919. *
  3920. * @example $("#msg").ajaxError(function(request, settings){
  3921. * $(this).append("<li>Error requesting page " + settings.url + "</li>");
  3922. * });
  3923. * @desc Show a message when an AJAX request fails.
  3924. *
  3925. * @name ajaxError
  3926. * @type jQuery
  3927. * @param Function callback The function to execute.
  3928. * @cat Ajax
  3929. */
  3930. /**
  3931. * Attach a function to be executed before an AJAX request is sent.
  3932. *
  3933. * The XMLHttpRequest and settings used for that request are passed
  3934. * as arguments to the callback.
  3935. *
  3936. * @example $("#msg").ajaxSend(function(request, settings){
  3937. * $(this).append("<li>Starting request at " + settings.url + "</li>");
  3938. * });
  3939. * @desc Show a message before an AJAX request is sent.
  3940. *
  3941. * @name ajaxSend
  3942. * @type jQuery
  3943. * @param Function callback The function to execute.
  3944. * @cat Ajax
  3945. */
  3946. jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","), function(i,o){
  3947. jQuery.fn[o] = function(f){
  3948. return this.bind(o, f);
  3949. };
  3950. });
  3951. jQuery.extend({
  3952. /**
  3953. * Load a remote page using an HTTP GET request.
  3954. *
  3955. * @example $.get("test.cgi");
  3956. *
  3957. * @example $.get("test.cgi", { name: "John", time: "2pm" } );
  3958. *
  3959. * @example $.get("test.cgi", function(data){
  3960. * alert("Data Loaded: " + data);
  3961. * });
  3962. *
  3963. * @example $.get("test.cgi",
  3964. * { name: "John", time: "2pm" },
  3965. * function(data){
  3966. * alert("Data Loaded: " + data);
  3967. * }
  3968. * );
  3969. *
  3970. * @name $.get
  3971. * @type XMLHttpRequest
  3972. * @param String url The URL of the page to load.
  3973. * @param Map params (optional) Key/value pairs that will be sent to the server.
  3974. * @param Function callback (optional) A function to be executed whenever the data is loaded.
  3975. * @cat Ajax
  3976. */
  3977. get: function( url, data, callback, type, ifModified ) {
  3978. // shift arguments if data argument was ommited
  3979. if ( jQuery.isFunction( data ) ) {
  3980. callback = data;
  3981. data = null;
  3982. }
  3983. return jQuery.ajax({
  3984. url: url,
  3985. data: data,
  3986. success: callback,
  3987. dataType: type,
  3988. ifModified: ifModified
  3989. });
  3990. },
  3991. /**
  3992. * Load a remote page using an HTTP GET request, only if it hasn't
  3993. * been modified since it was last retrieved.
  3994. *
  3995. * @example $.getIfModified("test.html");
  3996. *
  3997. * @example $.getIfModified("test.html", { name: "John", time: "2pm" } );
  3998. *
  3999. * @example $.getIfModified("test.cgi", function(data){
  4000. * alert("Data Loaded: " + data);
  4001. * });
  4002. *
  4003. * @example $.getifModified("test.cgi",
  4004. * { name: "John", time: "2pm" },
  4005. * function(data){
  4006. * alert("Data Loaded: " + data);
  4007. * }
  4008. * );
  4009. *
  4010. * @name $.getIfModified
  4011. * @type XMLHttpRequest
  4012. * @param String url The URL of the page to load.
  4013. * @param Map params (optional) Key/value pairs that will be sent to the server.
  4014. * @param Function callback (optional) A function to be executed whenever the data is loaded.
  4015. * @cat Ajax
  4016. */
  4017. getIfModified: function( url, data, callback, type ) {
  4018. return jQuery.get(url, data, callback, type, 1);
  4019. },
  4020. /**
  4021. * Loads, and executes, a remote JavaScript file using an HTTP GET request.
  4022. *
  4023. * Warning: Safari <= 2.0.x is unable to evalulate scripts in a global
  4024. * context synchronously. If you load functions via getScript, make sure
  4025. * to call them after a delay.
  4026. *
  4027. * @example $.getScript("test.js");
  4028. *
  4029. * @example $.getScript("test.js", function(){
  4030. * alert("Script loaded and executed.");
  4031. * });
  4032. *
  4033. * @name $.getScript
  4034. * @type XMLHttpRequest
  4035. * @param String url The URL of the page to load.
  4036. * @param Function callback (optional) A function to be executed whenever the data is loaded.
  4037. * @cat Ajax
  4038. */
  4039. getScript: function( url, callback ) {
  4040. return jQuery.get(url, null, callback, "script");
  4041. },
  4042. /**
  4043. * Load JSON data using an HTTP GET request.
  4044. *
  4045. * @example $.getJSON("test.js", function(json){
  4046. * alert("JSON Data: " + json.users[3].name);
  4047. * });
  4048. *
  4049. * @example $.getJSON("test.js",
  4050. * { name: "John", time: "2pm" },
  4051. * function(json){
  4052. * alert("JSON Data: " + json.users[3].name);
  4053. * }
  4054. * );
  4055. *
  4056. * @name $.getJSON
  4057. * @type XMLHttpRequest
  4058. * @param String url The URL of the page to load.
  4059. * @param Map params (optional) Key/value pairs that will be sent to the server.
  4060. * @param Function callback A function to be executed whenever the data is loaded.
  4061. * @cat Ajax
  4062. */
  4063. getJSON: function( url, data, callback ) {
  4064. return jQuery.get(url, data, callback, "json");
  4065. },
  4066. /**
  4067. * Load a remote page using an HTTP POST request.
  4068. *
  4069. * @example $.post("test.cgi");
  4070. *
  4071. * @example $.post("test.cgi", { name: "John", time: "2pm" } );
  4072. *
  4073. * @example $.post("test.cgi", function(data){
  4074. * alert("Data Loaded: " + data);
  4075. * });
  4076. *
  4077. * @example $.post("test.cgi",
  4078. * { name: "John", time: "2pm" },
  4079. * function(data){
  4080. * alert("Data Loaded: " + data);
  4081. * }
  4082. * );
  4083. *
  4084. * @name $.post
  4085. * @type XMLHttpRequest
  4086. * @param String url The URL of the page to load.
  4087. * @param Map params (optional) Key/value pairs that will be sent to the server.
  4088. * @param Function callback (optional) A function to be executed whenever the data is loaded.
  4089. * @cat Ajax
  4090. */
  4091. post: function( url, data, callback, type ) {
  4092. if ( jQuery.isFunction( data ) ) {
  4093. callback = data;
  4094. data = {};
  4095. }
  4096. return jQuery.ajax({
  4097. type: "POST",
  4098. url: url,
  4099. data: data,
  4100. success: callback,
  4101. dataType: type
  4102. });
  4103. },
  4104. // timeout (ms)
  4105. //timeout: 0,
  4106. /**
  4107. * Set the timeout of all AJAX requests to a specific amount of time.
  4108. * This will make all future AJAX requests timeout after a specified amount
  4109. * of time.
  4110. *
  4111. * Set to null or 0 to disable timeouts (default).
  4112. *
  4113. * You can manually abort requests with the XMLHttpRequest's (returned by
  4114. * all ajax functions) abort() method.
  4115. *
  4116. * Deprecated. Use $.ajaxSetup instead.
  4117. *
  4118. * @example $.ajaxTimeout( 5000 );
  4119. * @desc Make all AJAX requests timeout after 5 seconds.
  4120. *
  4121. * @name $.ajaxTimeout
  4122. * @type undefined
  4123. * @param Number time How long before an AJAX request times out.
  4124. * @cat Ajax
  4125. */
  4126. ajaxTimeout: function( timeout ) {
  4127. jQuery.ajaxSettings.timeout = timeout;
  4128. },
  4129. /**
  4130. * Setup global settings for AJAX requests.
  4131. *
  4132. * See $.ajax for a description of all available options.
  4133. *
  4134. * @example $.ajaxSetup( {
  4135. * url: "/xmlhttp/",
  4136. * global: false,
  4137. * type: "POST"
  4138. * } );
  4139. * $.ajax({ data: myData });
  4140. * @desc Sets the defaults for AJAX requests to the url "/xmlhttp/",
  4141. * disables global handlers and uses POST instead of GET. The following
  4142. * AJAX requests then sends some data without having to set anything else.
  4143. *
  4144. * @name $.ajaxSetup
  4145. * @type undefined
  4146. * @param Map settings Key/value pairs to use for all AJAX requests
  4147. * @cat Ajax
  4148. */
  4149. ajaxSetup: function( settings ) {
  4150. jQuery.extend( jQuery.ajaxSettings, settings );
  4151. },
  4152. ajaxSettings: {
  4153. global: true,
  4154. type: "GET",
  4155. timeout: 0,
  4156. contentType: "application/x-www-form-urlencoded",
  4157. processData: true,
  4158. async: true,
  4159. data: null
  4160. },
  4161. // Last-Modified header cache for next request
  4162. lastModified: {},
  4163. /**
  4164. * Load a remote page using an HTTP request.
  4165. *
  4166. * This is jQuery's low-level AJAX implementation. See $.get, $.post etc. for
  4167. * higher-level abstractions.
  4168. *
  4169. * $.ajax() returns the XMLHttpRequest that it creates. In most cases you won't
  4170. * need that object to manipulate directly, but it is available if you need to
  4171. * abort the request manually.
  4172. *
  4173. * Note: Make sure the server sends the right mimetype (eg. xml as
  4174. * "text/xml"). Sending the wrong mimetype will get you into serious
  4175. * trouble that jQuery can't solve.
  4176. *
  4177. * Supported datatypes are (see dataType option):
  4178. *
  4179. * "xml": Returns a XML document that can be processed via jQuery.
  4180. *
  4181. * "html": Returns HTML as plain text, included script tags are evaluated.
  4182. *
  4183. * "script": Evaluates the response as Javascript and returns it as plain text.
  4184. *
  4185. * "json": Evaluates the response as JSON and returns a Javascript Object
  4186. *
  4187. * $.ajax() takes one argument, an object of key/value pairs, that are
  4188. * used to initalize and handle the request. These are all the key/values that can
  4189. * be used:
  4190. *
  4191. * (String) url - The URL to request.
  4192. *
  4193. * (String) type - The type of request to make ("POST" or "GET"), default is "GET".
  4194. *
  4195. * (String) dataType - The type of data that you're expecting back from
  4196. * the server. No default: If the server sends xml, the responseXML, otherwise
  4197. * the responseText is passed to the success callback.
  4198. *
  4199. * (Boolean) ifModified - Allow the request to be successful only if the
  4200. * response has changed since the last request. This is done by checking the
  4201. * Last-Modified header. Default value is false, ignoring the header.
  4202. *
  4203. * (Number) timeout - Local timeout to override global timeout, eg. to give a
  4204. * single request a longer timeout while all others timeout after 1 second.
  4205. * See $.ajaxTimeout() for global timeouts.
  4206. *
  4207. * (Boolean) global - Whether to trigger global AJAX event handlers for
  4208. * this request, default is true. Set to false to prevent that global handlers
  4209. * like ajaxStart or ajaxStop are triggered.
  4210. *
  4211. * (Function) error - A function to be called if the request fails. The
  4212. * function gets passed tree arguments: The XMLHttpRequest object, a
  4213. * string describing the type of error that occurred and an optional
  4214. * exception object, if one occured.
  4215. *
  4216. * (Function) success - A function to be called if the request succeeds. The
  4217. * function gets passed one argument: The data returned from the server,
  4218. * formatted according to the 'dataType' parameter.
  4219. *
  4220. * (Function) complete - A function to be called when the request finishes. The
  4221. * function gets passed two arguments: The XMLHttpRequest object and a
  4222. * string describing the type of success of the request.
  4223. *
  4224. * (Object|String) data - Data to be sent to the server. Converted to a query
  4225. * string, if not already a string. Is appended to the url for GET-requests.
  4226. * See processData option to prevent this automatic processing.
  4227. *
  4228. * (String) contentType - When sending data to the server, use this content-type.
  4229. * Default is "application/x-www-form-urlencoded", which is fine for most cases.
  4230. *
  4231. * (Boolean) processData - By default, data passed in to the data option as an object
  4232. * other as string will be processed and transformed into a query string, fitting to
  4233. * the default content-type "application/x-www-form-urlencoded". If you want to send
  4234. * DOMDocuments, set this option to false.
  4235. *
  4236. * (Boolean) async - By default, all requests are sent asynchronous (set to true).
  4237. * If you need synchronous requests, set this option to false.
  4238. *
  4239. * (Function) beforeSend - A pre-callback to set custom headers etc., the
  4240. * XMLHttpRequest is passed as the only argument.
  4241. *
  4242. * @example $.ajax({
  4243. * type: "GET",
  4244. * url: "test.js",
  4245. * dataType: "script"
  4246. * })
  4247. * @desc Load and execute a JavaScript file.
  4248. *
  4249. * @example $.ajax({
  4250. * type: "POST",
  4251. * url: "some.php",
  4252. * data: "name=John&location=Boston",
  4253. * success: function(msg){
  4254. * alert( "Data Saved: " + msg );
  4255. * }
  4256. * });
  4257. * @desc Save some data to the server and notify the user once its complete.
  4258. *
  4259. * @example var html = $.ajax({
  4260. * url: "some.php",
  4261. * async: false
  4262. * }).responseText;
  4263. * @desc Loads data synchronously. Blocks the browser while the requests is active.
  4264. * It is better to block user interaction with others means when synchronization is
  4265. * necessary, instead to block the complete browser.
  4266. *
  4267. * @example var xmlDocument = [create xml document];
  4268. * $.ajax({
  4269. * url: "page.php",
  4270. * processData: false,
  4271. * data: xmlDocument,
  4272. * success: handleResponse
  4273. * });
  4274. * @desc Sends an xml document as data to the server. By setting the processData
  4275. * option to false, the automatic conversion of data to strings is prevented.
  4276. *
  4277. * @name $.ajax
  4278. * @type XMLHttpRequest
  4279. * @param Map properties Key/value pairs to initialize the request with.
  4280. * @cat Ajax
  4281. * @see ajaxSetup(Map)
  4282. */
  4283. ajax: function( s ) {
  4284. // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
  4285. s = jQuery.extend({}, jQuery.ajaxSettings, s);
  4286. // if data available
  4287. if ( s.data ) {
  4288. // convert data if not already a string
  4289. if (s.processData && typeof s.data != "string")
  4290. s.data = jQuery.param(s.data);
  4291. // append data to url for get requests
  4292. if( s.type.toLowerCase() == "get" )
  4293. // "?" + data or "&" + data (in case there are already params)
  4294. s.url += ((s.url.indexOf("?") > -1) ? "&" : "?") + s.data;
  4295. }
  4296. // Watch for a new set of requests
  4297. if ( s.global && ! jQuery.active++ )
  4298. jQuery.event.trigger( "ajaxStart" );
  4299. var requestDone = false;
  4300. // Create the request object
  4301. var xml = new XMLHttpRequest();
  4302. // Open the socket
  4303. xml.open(s.type, s.url, s.async);
  4304. // Set the correct header, if data is being sent
  4305. if ( s.data )
  4306. xml.setRequestHeader("Content-Type", s.contentType);
  4307. // Set the If-Modified-Since header, if ifModified mode.
  4308. if ( s.ifModified )
  4309. xml.setRequestHeader("If-Modified-Since",
  4310. jQuery.lastModified[s.url] || "Thu, 01 Jan 1970 00:00:00 GMT" );
  4311. // Set header so the called script knows that it's an XMLHttpRequest
  4312. xml.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  4313. // Make sure the browser sends the right content length
  4314. if ( xml.overrideMimeType )
  4315. xml.setRequestHeader("Connection", "close");
  4316. // Allow custom headers/mimetypes
  4317. if( s.beforeSend )
  4318. s.beforeSend(xml);
  4319. if ( s.global )
  4320. jQuery.event.trigger("ajaxSend", [xml, s]);
  4321. // Wait for a response to come back
  4322. var onreadystatechange = function(isTimeout){
  4323. // The transfer is complete and the data is available, or the request timed out
  4324. if ( xml && (xml.readyState == 4 || isTimeout == "timeout") ) {
  4325. requestDone = true;
  4326. var status;
  4327. try {
  4328. status = jQuery.httpSuccess( xml ) && isTimeout != "timeout" ?
  4329. s.ifModified && jQuery.httpNotModified( xml, s.url ) ? "notmodified" : "success" : "error";
  4330. // Make sure that the request was successful or notmodified
  4331. if ( status != "error" ) {
  4332. // Cache Last-Modified header, if ifModified mode.
  4333. var modRes;
  4334. try {
  4335. modRes = xml.getResponseHeader("Last-Modified");
  4336. } catch(e) {} // swallow exception thrown by FF if header is not available
  4337. if ( s.ifModified && modRes )
  4338. jQuery.lastModified[s.url] = modRes;
  4339. // process the data (runs the xml through httpData regardless of callback)
  4340. var data = jQuery.httpData( xml, s.dataType );
  4341. // If a local callback was specified, fire it and pass it the data
  4342. if ( s.success )
  4343. s.success( data, status );
  4344. // Fire the global callback
  4345. if( s.global )
  4346. jQuery.event.trigger( "ajaxSuccess", [xml, s] );
  4347. } else
  4348. jQuery.handleError(s, xml, status);
  4349. } catch(e) {
  4350. status = "error";
  4351. jQuery.handleError(s, xml, status, e);
  4352. }
  4353. // The request was completed
  4354. if( s.global )
  4355. jQuery.event.trigger( "ajaxComplete", [xml, s] );
  4356. // Handle the global AJAX counter
  4357. if ( s.global && ! --jQuery.active )
  4358. jQuery.event.trigger( "ajaxStop" );
  4359. // Process result
  4360. if ( s.complete )
  4361. s.complete(xml, status);
  4362. // Stop memory leaks
  4363. xml.onreadystatechange = function(){};
  4364. xml = null;
  4365. }
  4366. };
  4367. xml.onreadystatechange = onreadystatechange;
  4368. // Timeout checker
  4369. if ( s.timeout > 0 )
  4370. setTimeout(function(){
  4371. // Check to see if the request is still happening
  4372. if ( xml ) {
  4373. // Cancel the request
  4374. xml.abort();
  4375. if( !requestDone )
  4376. onreadystatechange( "timeout" );
  4377. }
  4378. }, s.timeout);
  4379. // save non-leaking reference
  4380. var xml2 = xml;
  4381. // Send the data
  4382. try {
  4383. xml2.send(s.data);
  4384. } catch(e) {
  4385. jQuery.handleError(s, xml, null, e);
  4386. }
  4387. // firefox 1.5 doesn't fire statechange for sync requests
  4388. if ( !s.async )
  4389. onreadystatechange();
  4390. // return XMLHttpRequest to allow aborting the request etc.
  4391. return xml2;
  4392. },
  4393. handleError: function( s, xml, status, e ) {
  4394. // If a local callback was specified, fire it
  4395. if ( s.error ) s.error( xml, status, e );
  4396. // Fire the global callback
  4397. if ( s.global )
  4398. jQuery.event.trigger( "ajaxError", [xml, s, e] );
  4399. },
  4400. // Counter for holding the number of active queries
  4401. active: 0,
  4402. // Determines if an XMLHttpRequest was successful or not
  4403. httpSuccess: function( r ) {
  4404. try {
  4405. return !r.status && location.protocol == "file:" ||
  4406. ( r.status >= 200 && r.status < 300 ) || r.status == 304 ||
  4407. jQuery.browser.safari && r.status == undefined;
  4408. } catch(e){}
  4409. return false;
  4410. },
  4411. // Determines if an XMLHttpRequest returns NotModified
  4412. httpNotModified: function( xml, url ) {
  4413. try {
  4414. var xmlRes = xml.getResponseHeader("Last-Modified");
  4415. // Firefox always returns 200. check Last-Modified date
  4416. return xml.status == 304 || xmlRes == jQuery.lastModified[url] ||
  4417. jQuery.browser.safari && xml.status == undefined;
  4418. } catch(e){}
  4419. return false;
  4420. },
  4421. /* Get the data out of an XMLHttpRequest.
  4422. * Return parsed XML if content-type header is "xml" and type is "xml" or omitted,
  4423. * otherwise return plain text.
  4424. * (String) data - The type of data that you're expecting back,
  4425. * (e.g. "xml", "html", "script")
  4426. */
  4427. httpData: function( r, type ) {
  4428. var ct = r.getResponseHeader("content-type");
  4429. var data = !type && ct && ct.indexOf("xml") >= 0;
  4430. data = type == "xml" || data ? r.responseXML : r.responseText;
  4431. // If the type is "script", eval it in global context
  4432. if ( type == "script" )
  4433. jQuery.globalEval( data );
  4434. // Get the JavaScript object, if JSON is used.
  4435. if ( type == "json" )
  4436. eval( "data = " + data );
  4437. // evaluate scripts within html
  4438. if ( type == "html" )
  4439. jQuery("<div>").html(data).evalScripts();
  4440. return data;
  4441. },
  4442. // Serialize an array of form elements or a set of
  4443. // key/values into a query string
  4444. param: function( a ) {
  4445. var s = [];
  4446. // If an array was passed in, assume that it is an array
  4447. // of form elements
  4448. if ( a.constructor == Array || a.jquery )
  4449. // Serialize the form elements
  4450. jQuery.each( a, function(){
  4451. s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) );
  4452. });
  4453. // Otherwise, assume that it's an object of key/value pairs
  4454. else
  4455. // Serialize the key/values
  4456. for ( var j in a )
  4457. // If the value is an array then the key names need to be repeated
  4458. if ( a[j] && a[j].constructor == Array )
  4459. jQuery.each( a[j], function(){
  4460. s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
  4461. });
  4462. else
  4463. s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );
  4464. // Return the resulting serialization
  4465. return s.join("&");
  4466. },
  4467. // evalulates a script in global context
  4468. // not reliable for safari
  4469. globalEval: function( data ) {
  4470. if ( window.execScript )
  4471. window.execScript( data );
  4472. else if ( jQuery.browser.safari )
  4473. // safari doesn't provide a synchronous global eval
  4474. window.setTimeout( data, 0 );
  4475. else
  4476. eval.call( window, data );
  4477. }
  4478. });
  4479. }