12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997 |
- /* prevent execution of jQuery if included more than once */
- if(typeof window.jQuery == "undefined") {
- /*
- * jQuery @VERSION - New Wave Javascript
- *
- * Copyright (c) 2007 John Resig (jquery.com)
- * Dual licensed under the MIT (MIT-LICENSE.txt)
- * and GPL (GPL-LICENSE.txt) licenses.
- *
- * $Date$
- * $Rev: 1173 $
- */
- // Global undefined variable
- window.undefined = window.undefined;
- /**
- * Create a new jQuery Object
- *
- * @constructor
- * @private
- * @name jQuery
- * @param String|Function|Element|Array<Element>|jQuery a selector
- * @param jQuery|Element|Array<Element> c context
- * @cat Core
- */
- var jQuery = function(a,c) {
- // If the context is global, return a new object
- if ( window == this )
- return new jQuery(a,c);
- // Make sure that a selection was provided
- a = a || document;
-
- // HANDLE: $(function)
- // Shortcut for document ready
- if ( jQuery.isFunction(a) )
- return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
-
- // Handle HTML strings
- if ( typeof a == "string" ) {
- // HANDLE: $(html) -> $(array)
- var m = /^[^<]*(<(.|\n)+>)[^>]*$/.exec(a);
- if ( m )
- a = jQuery.clean( [ m[1] ] );
-
- // HANDLE: $(expr)
- else
- return new jQuery( c ).find( a );
- }
-
- return this.setArray(
- // HANDLE: $(array)
- a.constructor == Array && a ||
- // HANDLE: $(arraylike)
- // Watch for when an array-like object is passed as the selector
- (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) ||
- // HANDLE: $(*)
- [ a ] );
- };
- // Map over the $ in case of overwrite
- if ( typeof $ != "undefined" )
- jQuery._$ = $;
-
- // Map the jQuery namespace to the '$' one
- var $ = jQuery;
- /**
- * This function accepts a string containing a CSS or
- * basic XPath selector which is then used to match a set of elements.
- *
- * The core functionality of jQuery centers around this function.
- * Everything in jQuery is based upon this, or uses this in some way.
- * The most basic use of this function is to pass in an expression
- * (usually consisting of CSS or XPath), which then finds all matching
- * elements.
- *
- * By default, $() looks for DOM elements within the context of the
- * current HTML document.
- *
- * @example $("div > p")
- * @desc Finds all p elements that are children of a div element.
- * @before <p>one</p> <div><p>two</p></div> <p>three</p>
- * @result [ <p>two</p> ]
- *
- * @example $("input:radio", document.forms[0])
- * @desc Searches for all inputs of type radio within the first form in the document
- *
- * @example $("div", xml.responseXML)
- * @desc This finds all div elements within the specified XML document.
- *
- * @name $
- * @param String expr An expression to search with
- * @param Element|jQuery context (optional) A DOM Element, Document or jQuery to use as context
- * @cat Core
- * @type jQuery
- * @see $(Element)
- * @see $(Element<Array>)
- */
-
- /**
- * Create DOM elements on-the-fly from the provided String of raw HTML.
- *
- * @example $("<div><p>Hello</p></div>").appendTo("#body")
- * @desc Creates a div element (and all of its contents) dynamically,
- * and appends it to the element with the ID of body. Internally, an
- * element is created and it's innerHTML property set to the given markup.
- * It is therefore both quite flexible and limited.
- *
- * @name $
- * @param String html A string of HTML to create on the fly.
- * @cat Core
- * @type jQuery
- * @see appendTo(String)
- */
- /**
- * Wrap jQuery functionality around a single or multiple DOM Element(s).
- *
- * This function also accepts XML Documents and Window objects
- * as valid arguments (even though they are not DOM Elements).
- *
- * @example $(document.body).background( "black" );
- * @desc Sets the background color of the page to black.
- *
- * @example $( myForm.elements ).hide()
- * @desc Hides all the input elements within a form
- *
- * @name $
- * @param Element|Array<Element> elems DOM element(s) to be encapsulated by a jQuery object.
- * @cat Core
- * @type jQuery
- */
- /**
- * A shorthand for $(document).ready(), allowing you to bind a function
- * to be executed when the DOM document has finished loading. This function
- * behaves just like $(document).ready(), in that it should be used to wrap
- * all of the other $() operations on your page. While this function is,
- * technically, chainable - there really isn't much use for chaining against it.
- * You can have as many $(document).ready events on your page as you like.
- *
- * See ready(Function) for details about the ready event.
- *
- * @example $(function(){
- * // Document is ready
- * });
- * @desc Executes the function when the DOM is ready to be used.
- *
- * @example jQuery(function($) {
- * // Your code using failsafe $ alias here...
- * });
- * @desc Uses both the shortcut for $(document).ready() and the argument
- * to write failsafe jQuery code using the $ alias, without relying on the
- * global alias.
- *
- * @name $
- * @param Function fn The function to execute when the DOM is ready.
- * @cat Core
- * @type jQuery
- * @see ready(Function)
- */
- jQuery.fn = jQuery.prototype = {
- /**
- * The current version of jQuery.
- *
- * @private
- * @property
- * @name jquery
- * @type String
- * @cat Core
- */
- jquery: "@VERSION",
- /**
- * The number of elements currently matched.
- *
- * @example $("img").length;
- * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
- * @result 2
- *
- * @property
- * @name length
- * @type Number
- * @cat Core
- */
- /**
- * The number of elements currently matched.
- *
- * @example $("img").size();
- * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
- * @result 2
- *
- * @name size
- * @type Number
- * @cat Core
- */
- size: function() {
- return this.length;
- },
-
- length: 0,
- /**
- * Access all matched elements. This serves as a backwards-compatible
- * way of accessing all matched elements (other than the jQuery object
- * itself, which is, in fact, an array of elements).
- *
- * @example $("img").get();
- * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
- * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
- * @desc Selects all images in the document and returns the DOM Elements as an Array
- *
- * @name get
- * @type Array<Element>
- * @cat Core
- */
- /**
- * Access a single matched element. num is used to access the
- * Nth element matched.
- *
- * @example $("img").get(0);
- * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
- * @result [ <img src="test1.jpg"/> ]
- * @desc Selects all images in the document and returns the first one
- *
- * @name get
- * @type Element
- * @param Number num Access the element in the Nth position.
- * @cat Core
- */
- get: function( num ) {
- return num == undefined ?
- // Return a 'clean' array
- jQuery.makeArray( this ) :
- // Return just the object
- this[num];
- },
-
- /**
- * Set the jQuery object to an array of elements, while maintaining
- * the stack.
- *
- * @example $("img").pushStack([ document.body ]);
- * @result $("img").pushStack() == [ document.body ]
- *
- * @private
- * @name pushStack
- * @type jQuery
- * @param Elements elems An array of elements
- * @cat Core
- */
- pushStack: function( a ) {
- var ret = jQuery(a);
- ret.prevObject = this;
- return ret;
- },
-
- /**
- * Set the jQuery object to an array of elements. This operation is
- * completely destructive - be sure to use .pushStack() if you wish to maintain
- * the jQuery stack.
- *
- * @example $("img").setArray([ document.body ]);
- * @result $("img").setArray() == [ document.body ]
- *
- * @private
- * @name setArray
- * @type jQuery
- * @param Elements elems An array of elements
- * @cat Core
- */
- setArray: function( a ) {
- this.length = 0;
- [].push.apply( this, a );
- return this;
- },
- /**
- * Execute a function within the context of every matched element.
- * This means that every time the passed-in function is executed
- * (which is once for every element matched) the 'this' keyword
- * points to the specific element.
- *
- * Additionally, the function, when executed, is passed a single
- * argument representing the position of the element in the matched
- * set.
- *
- * @example $("img").each(function(i){
- * this.src = "test" + i + ".jpg";
- * });
- * @before <img/><img/>
- * @result <img src="test0.jpg"/><img src="test1.jpg"/>
- * @desc Iterates over two images and sets their src property
- *
- * @name each
- * @type jQuery
- * @param Function fn A function to execute
- * @cat Core
- */
- each: function( fn, args ) {
- return jQuery.each( this, fn, args );
- },
- /**
- * Searches every matched element for the object and returns
- * the index of the element, if found, starting with zero.
- * Returns -1 if the object wasn't found.
- *
- * @example $("*").index( $('#foobar')[0] )
- * @before <div id="foobar"><b></b><span id="foo"></span></div>
- * @result 0
- * @desc Returns the index for the element with ID foobar
- *
- * @example $("*").index( $('#foo')[0] )
- * @before <div id="foobar"><b></b><span id="foo"></span></div>
- * @result 2
- * @desc Returns the index for the element with ID foo within another element
- *
- * @example $("*").index( $('#bar')[0] )
- * @before <div id="foobar"><b></b><span id="foo"></span></div>
- * @result -1
- * @desc Returns -1, as there is no element with ID bar
- *
- * @name index
- * @type Number
- * @param Element subject Object to search for
- * @cat Core
- */
- index: function( obj ) {
- var pos = -1;
- this.each(function(i){
- if ( this == obj ) pos = i;
- });
- return pos;
- },
- /**
- * Access a property on the first matched element.
- * This method makes it easy to retrieve a property value
- * from the first matched element.
- *
- * @example $("img").attr("src");
- * @before <img src="test.jpg"/>
- * @result test.jpg
- * @desc Returns the src attribute from the first image in the document.
- *
- * @name attr
- * @type Object
- * @param String name The name of the property to access.
- * @cat DOM/Attributes
- */
- /**
- * Set a key/value object as properties to all matched elements.
- *
- * This serves as the best way to set a large number of properties
- * on all matched elements.
- *
- * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
- * @before <img/>
- * @result <img src="test.jpg" alt="Test Image"/>
- * @desc Sets src and alt attributes to all images.
- *
- * @name attr
- * @type jQuery
- * @param Map properties Key/value pairs to set as object properties.
- * @cat DOM/Attributes
- */
- /**
- * Set a single property to a value, on all matched elements.
- *
- * Can compute values provided as ${formula}, see second example.
- *
- * Note that you can't set the name property of input elements in IE.
- * Use $(html) or .append(html) or .html(html) to create elements
- * on the fly including the name property.
- *
- * @example $("img").attr("src","test.jpg");
- * @before <img/>
- * @result <img src="test.jpg"/>
- * @desc Sets src attribute to all images.
- *
- * @example $("img").attr("title", "${this.src}");
- * @before <img src="test.jpg" />
- * @result <img src="test.jpg" title="test.jpg" />
- * @desc Sets title attribute from src attribute, a shortcut for attr(String,Function)
- *
- * @name attr
- * @type jQuery
- * @param String key The name of the property to set.
- * @param Object value The value to set the property to.
- * @cat DOM/Attributes
- */
-
- /**
- * Set a single property to a computed value, on all matched elements.
- *
- * Instead of a value, a function is provided, that computes the value.
- *
- * @example $("img").attr("title", function() { return this.src });
- * @before <img src="test.jpg" />
- * @result <img src="test.jpg" title="test.jpg" />
- * @desc Sets title attribute from src attribute.
- *
- * @example $("img").attr("title", function(index) { return this.title + (i + 1); });
- * @before <img title="pic" /><img title="pic" /><img title="pic" />
- * @result <img title="pic1" /><img title="pic2" /><img title="pic3" />
- * @desc Enumerate title attribute.
- *
- * @name attr
- * @type jQuery
- * @param String key The name of the property to set.
- * @param Function value A function returning the value to set.
- * Scope: Current element, argument: Index of current element
- * @cat DOM/Attributes
- */
- attr: function( key, value, type ) {
- var obj = key;
-
- // Look for the case where we're accessing a style value
- if ( key.constructor == String )
- if ( value == undefined )
- return this.length && jQuery[ type || "attr" ]( this[0], key ) || undefined;
- else {
- obj = {};
- obj[ key ] = value;
- }
-
- // Check to see if we're setting style values
- return this.each(function(index){
- // Set all the styles
- for ( var prop in obj )
- jQuery.attr(
- type ? this.style : this,
- prop, jQuery.prop(this, obj[prop], type, index, prop)
- );
- });
- },
- /**
- * Access a style property on the first matched element.
- * This method makes it easy to retrieve a style property value
- * from the first matched element.
- *
- * @example $("p").css("color");
- * @before <p style="color:red;">Test Paragraph.</p>
- * @result "red"
- * @desc Retrieves the color style of the first paragraph
- *
- * @example $("p").css("font-weight");
- * @before <p style="font-weight: bold;">Test Paragraph.</p>
- * @result "bold"
- * @desc Retrieves the font-weight style of the first paragraph.
- *
- * @name css
- * @type String
- * @param String name The name of the property to access.
- * @cat CSS
- */
- /**
- * Set a key/value object as style properties to all matched elements.
- *
- * This serves as the best way to set a large number of style properties
- * on all matched elements.
- *
- * @example $("p").css({ color: "red", background: "blue" });
- * @before <p>Test Paragraph.</p>
- * @result <p style="color:red; background:blue;">Test Paragraph.</p>
- * @desc Sets color and background styles to all p elements.
- *
- * @name css
- * @type jQuery
- * @param Map properties Key/value pairs to set as style properties.
- * @cat CSS
- */
- /**
- * Set a single style property to a value, on all matched elements.
- * If a number is provided, it is automatically converted into a pixel value.
- *
- * @example $("p").css("color","red");
- * @before <p>Test Paragraph.</p>
- * @result <p style="color:red;">Test Paragraph.</p>
- * @desc Changes the color of all paragraphs to red
- *
- * @example $("p").css("left",30);
- * @before <p>Test Paragraph.</p>
- * @result <p style="left:30px;">Test Paragraph.</p>
- * @desc Changes the left of all paragraphs to "30px"
- *
- * @name css
- * @type jQuery
- * @param String key The name of the property to set.
- * @param String|Number value The value to set the property to.
- * @cat CSS
- */
- css: function( key, value ) {
- return this.attr( key, value, "curCSS" );
- },
- /**
- * Get the text contents of all matched elements. The result is
- * a string that contains the combined text contents of all matched
- * elements. This method works on both HTML and XML documents.
- *
- * @example $("p").text();
- * @before <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p>
- * @result Test Paragraph.Paraparagraph
- * @desc Gets the concatenated text of all paragraphs
- *
- * @name text
- * @type String
- * @cat DOM/Attributes
- */
- /**
- * Set the text contents of all matched elements.
- *
- * Similar to html(), but escapes HTML (replace "<" and ">" with their
- * HTML entities).
- *
- * @example $("p").text("<b>Some</b> new text.");
- * @before <p>Test Paragraph.</p>
- * @result <p><b>Some</b> new text.</p>
- * @desc Sets the text of all paragraphs.
- *
- * @example $("p").text("<b>Some</b> new text.", true);
- * @before <p>Test Paragraph.</p>
- * @result <p>Some new text.</p>
- * @desc Sets the text of all paragraphs.
- *
- * @name text
- * @type String
- * @param String val The text value to set the contents of the element to.
- * @cat DOM/Attributes
- */
- text: function(e) {
- if ( typeof e == "string" )
- return this.empty().append( document.createTextNode( e ) );
- var t = "";
- jQuery.each( e || this, function(){
- jQuery.each( this.childNodes, function(){
- if ( this.nodeType != 8 )
- t += this.nodeType != 1 ?
- this.nodeValue : jQuery.fn.text([ this ]);
- });
- });
- return t;
- },
- /**
- * Wrap all matched elements with a structure of other elements.
- * This wrapping process is most useful for injecting additional
- * stucture into a document, without ruining the original semantic
- * qualities of a document.
- *
- * This works by going through the first element
- * provided (which is generated, on the fly, from the provided HTML)
- * and finds the deepest ancestor element within its
- * structure - it is that element that will en-wrap everything else.
- *
- * This does not work with elements that contain text. Any necessary text
- * must be added after the wrapping is done.
- *
- * @example $("p").wrap("<div class='wrap'></div>");
- * @before <p>Test Paragraph.</p>
- * @result <div class='wrap'><p>Test Paragraph.</p></div>
- *
- * @name wrap
- * @type jQuery
- * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
- * @cat DOM/Manipulation
- */
- /**
- * Wrap all matched elements with a structure of other elements.
- * This wrapping process is most useful for injecting additional
- * stucture into a document, without ruining the original semantic
- * qualities of a document.
- *
- * This works by going through the first element
- * provided and finding the deepest ancestor element within its
- * structure - it is that element that will en-wrap everything else.
- *
- * This does not work with elements that contain text. Any necessary text
- * must be added after the wrapping is done.
- *
- * @example $("p").wrap( document.getElementById('content') );
- * @before <p>Test Paragraph.</p><div id="content"></div>
- * @result <div id="content"><p>Test Paragraph.</p></div>
- *
- * @name wrap
- * @type jQuery
- * @param Element elem A DOM element that will be wrapped around the target.
- * @cat DOM/Manipulation
- */
- wrap: function() {
- // The elements to wrap the target around
- var a = jQuery.clean(arguments);
- // Wrap each of the matched elements individually
- return this.each(function(){
- // Clone the structure that we're using to wrap
- var b = a[0].cloneNode(true);
- // Insert it before the element to be wrapped
- this.parentNode.insertBefore( b, this );
- // Find the deepest point in the wrap structure
- while ( b.firstChild )
- b = b.firstChild;
- // Move the matched element to within the wrap structure
- b.appendChild( this );
- });
- },
- /**
- * Append content to the inside of every matched element.
- *
- * This operation is similar to doing an appendChild to all the
- * specified elements, adding them into the document.
- *
- * @example $("p").append("<b>Hello</b>");
- * @before <p>I would like to say: </p>
- * @result <p>I would like to say: <b>Hello</b></p>
- * @desc Appends some HTML to all paragraphs.
- *
- * @example $("p").append( $("#foo")[0] );
- * @before <p>I would like to say: </p><b id="foo">Hello</b>
- * @result <p>I would like to say: <b id="foo">Hello</b></p>
- * @desc Appends an Element to all paragraphs.
- *
- * @example $("p").append( $("b") );
- * @before <p>I would like to say: </p><b>Hello</b>
- * @result <p>I would like to say: <b>Hello</b></p>
- * @desc Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
- *
- * @name append
- * @type jQuery
- * @param <Content> content Content to append to the target
- * @cat DOM/Manipulation
- * @see prepend(<Content>)
- * @see before(<Content>)
- * @see after(<Content>)
- */
- append: function() {
- return this.domManip(arguments, true, 1, function(a){
- this.appendChild( a );
- });
- },
- /**
- * Prepend content to the inside of every matched element.
- *
- * This operation is the best way to insert elements
- * inside, at the beginning, of all matched elements.
- *
- * @example $("p").prepend("<b>Hello</b>");
- * @before <p>I would like to say: </p>
- * @result <p><b>Hello</b>I would like to say: </p>
- * @desc Prepends some HTML to all paragraphs.
- *
- * @example $("p").prepend( $("#foo")[0] );
- * @before <p>I would like to say: </p><b id="foo">Hello</b>
- * @result <p><b id="foo">Hello</b>I would like to say: </p>
- * @desc Prepends an Element to all paragraphs.
- *
- * @example $("p").prepend( $("b") );
- * @before <p>I would like to say: </p><b>Hello</b>
- * @result <p><b>Hello</b>I would like to say: </p>
- * @desc Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
- *
- * @name prepend
- * @type jQuery
- * @param <Content> content Content to prepend to the target.
- * @cat DOM/Manipulation
- * @see append(<Content>)
- * @see before(<Content>)
- * @see after(<Content>)
- */
- prepend: function() {
- return this.domManip(arguments, true, -1, function(a){
- this.insertBefore( a, this.firstChild );
- });
- },
-
- /**
- * Insert content before each of the matched elements.
- *
- * @example $("p").before("<b>Hello</b>");
- * @before <p>I would like to say: </p>
- * @result <b>Hello</b><p>I would like to say: </p>
- * @desc Inserts some HTML before all paragraphs.
- *
- * @example $("p").before( $("#foo")[0] );
- * @before <p>I would like to say: </p><b id="foo">Hello</b>
- * @result <b id="foo">Hello</b><p>I would like to say: </p>
- * @desc Inserts an Element before all paragraphs.
- *
- * @example $("p").before( $("b") );
- * @before <p>I would like to say: </p><b>Hello</b>
- * @result <b>Hello</b><p>I would like to say: </p>
- * @desc Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.
- *
- * @name before
- * @type jQuery
- * @param <Content> content Content to insert before each target.
- * @cat DOM/Manipulation
- * @see append(<Content>)
- * @see prepend(<Content>)
- * @see after(<Content>)
- */
- before: function() {
- return this.domManip(arguments, false, 1, function(a){
- this.parentNode.insertBefore( a, this );
- });
- },
- /**
- * Insert content after each of the matched elements.
- *
- * @example $("p").after("<b>Hello</b>");
- * @before <p>I would like to say: </p>
- * @result <p>I would like to say: </p><b>Hello</b>
- * @desc Inserts some HTML after all paragraphs.
- *
- * @example $("p").after( $("#foo")[0] );
- * @before <b id="foo">Hello</b><p>I would like to say: </p>
- * @result <p>I would like to say: </p><b id="foo">Hello</b>
- * @desc Inserts an Element after all paragraphs.
- *
- * @example $("p").after( $("b") );
- * @before <b>Hello</b><p>I would like to say: </p>
- * @result <p>I would like to say: </p><b>Hello</b>
- * @desc Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
- *
- * @name after
- * @type jQuery
- * @param <Content> content Content to insert after each target.
- * @cat DOM/Manipulation
- * @see append(<Content>)
- * @see prepend(<Content>)
- * @see before(<Content>)
- */
- after: function() {
- return this.domManip(arguments, false, -1, function(a){
- this.parentNode.insertBefore( a, this.nextSibling );
- });
- },
- /**
- * End the most recent 'destructive' operation, reverting the list of matched elements
- * back to its previous state. After an end operation, the list of matched elements will
- * revert to the last state of matched elements.
- *
- * If there was no destructive operation before, an empty set is returned.
- *
- * @example $("p").find("span").end();
- * @before <p><span>Hello</span>, how are you?</p>
- * @result [ <p>...</p> ]
- * @desc Selects all paragraphs, finds span elements inside these, and reverts the
- * selection back to the paragraphs.
- *
- * @name end
- * @type jQuery
- * @cat DOM/Traversing
- */
- end: function() {
- return this.prevObject || jQuery([]);
- },
- /**
- * Searches for all elements that match the specified expression.
-
- * This method is a good way to find additional descendant
- * elements with which to process.
- *
- * All searching is done using a jQuery expression. The expression can be
- * written using CSS 1-3 Selector syntax, or basic XPath.
- *
- * @example $("p").find("span");
- * @before <p><span>Hello</span>, how are you?</p>
- * @result [ <span>Hello</span> ]
- * @desc Starts with all paragraphs and searches for descendant span
- * elements, same as $("p span")
- *
- * @name find
- * @type jQuery
- * @param String expr An expression to search with.
- * @cat DOM/Traversing
- */
- find: function(t) {
- return this.pushStack( jQuery.map( this, function(a){
- return jQuery.find(t,a);
- }), t );
- },
- /**
- * Clone matched DOM Elements and select the clones.
- *
- * This is useful for moving copies of the elements to another
- * location in the DOM.
- *
- * @example $("b").clone().prependTo("p");
- * @before <b>Hello</b><p>, how are you?</p>
- * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
- * @desc Clones all b elements (and selects the clones) and prepends them to all paragraphs.
- *
- * @name clone
- * @type jQuery
- * @param Boolean deep (Optional) Set to false if you don't want to clone all descendant nodes, in addition to the element itself.
- * @cat DOM/Manipulation
- */
- clone: function(deep) {
- return this.pushStack( jQuery.map( this, function(a){
- return a.cloneNode( deep != undefined ? deep : true );
- }) );
- },
- /**
- * Removes all elements from the set of matched elements that do not
- * match the specified expression(s). This method is used to narrow down
- * the results of a search.
- *
- * Provide a comma-separated list of expressions to apply multiple filters at once.
- *
- * @example $("p").filter(".selected")
- * @before <p class="selected">Hello</p><p>How are you?</p>
- * @result [ <p class="selected">Hello</p> ]
- * @desc Selects all paragraphs and removes those without a class "selected".
- *
- * @example $("p").filter(".selected, :first")
- * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
- * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
- * @desc Selects all paragraphs and removes those without class "selected" and being the first one.
- *
- * @name filter
- * @type jQuery
- * @param String expression Expression(s) to search with.
- * @cat DOM/Traversing
- */
-
- /**
- * Removes all elements from the set of matched elements that do not
- * pass the specified filter. This method is used to narrow down
- * the results of a search.
- *
- * @example $("p").filter(function(index) {
- * return $("ol", this).length == 0;
- * })
- * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
- * @result [ <p>How are you?</p> ]
- * @desc Remove all elements that have a child ol element
- *
- * @name filter
- * @type jQuery
- * @param Function filter A function to use for filtering
- * @cat DOM/Traversing
- */
- filter: function(t) {
- return this.pushStack(
- jQuery.isFunction( t ) &&
- jQuery.grep(this, function(el, index){
- return t.apply(el, [index])
- }) ||
- jQuery.multiFilter(t,this) );
- },
- /**
- * Removes the specified Element from the set of matched elements. This
- * method is used to remove a single Element from a jQuery object.
- *
- * @example $("p").not( $("#selected")[0] )
- * @before <p>Hello</p><p id="selected">Hello Again</p>
- * @result [ <p>Hello</p> ]
- * @desc Removes the element with the ID "selected" from the set of all paragraphs.
- *
- * @name not
- * @type jQuery
- * @param Element el An element to remove from the set
- * @cat DOM/Traversing
- */
- /**
- * Removes elements matching the specified expression from the set
- * of matched elements. This method is used to remove one or more
- * elements from a jQuery object.
- *
- * @example $("p").not("#selected")
- * @before <p>Hello</p><p id="selected">Hello Again</p>
- * @result [ <p>Hello</p> ]
- * @desc Removes the element with the ID "selected" from the set of all paragraphs.
- *
- * @name not
- * @type jQuery
- * @param String expr An expression with which to remove matching elements
- * @cat DOM/Traversing
- */
- /**
- * Removes any elements inside the array of elements from the set
- * of matched elements. This method is used to remove one or more
- * elements from a jQuery object.
- *
- * @example $("p").not( $("div p.selected") )
- * @before <div><p>Hello</p><p class="selected">Hello Again</p></div>
- * @result [ <p>Hello</p> ]
- * @desc Removes all elements that match "div p.selected" from the total set of all paragraphs.
- *
- * @name not
- * @type jQuery
- * @param jQuery elems A set of elements to remove from the jQuery set of matched elements.
- * @cat DOM/Traversing
- */
- not: function(t) {
- return this.pushStack(
- t.constructor == String &&
- jQuery.multiFilter(t, this, true) ||
- jQuery.grep(this, function(a) {
- return ( t.constructor == Array || t.jquery )
- ? jQuery.inArray( a, t ) < 0
- : a != t;
- })
- );
- },
- /**
- * Adds more elements, matched by the given expression,
- * to the set of matched elements.
- *
- * @example $("p").add("span")
- * @before <p>Hello</p><span>Hello Again</span>
- * @result [ <p>Hello</p>, <span>Hello Again</span> ]
- *
- * @name add
- * @type jQuery
- * @param String expr An expression whose matched elements are added
- * @cat DOM/Traversing
- */
-
- /**
- * Adds more elements, created on the fly, to the set of
- * matched elements.
- *
- * @example $("p").add("<span>Again</span>")
- * @before <p>Hello</p>
- * @result [ <p>Hello</p>, <span>Again</span> ]
- *
- * @name add
- * @type jQuery
- * @param String html A string of HTML to create on the fly.
- * @cat DOM/Traversing
- */
- /**
- * Adds one or more Elements to the set of matched elements.
- *
- * @example $("p").add( document.getElementById("a") )
- * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
- * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
- *
- * @example $("p").add( document.forms[0].elements )
- * @before <p>Hello</p><p><form><input/><button/></form>
- * @result [ <p>Hello</p>, <input/>, <button/> ]
- *
- * @name add
- * @type jQuery
- * @param Element|Array<Element> elements One or more Elements to add
- * @cat DOM/Traversing
- */
- add: function(t) {
- return this.pushStack( jQuery.merge(
- this.get(),
- t.constructor == String ?
- jQuery(t).get() :
- t.length != undefined && (!t.nodeName || t.nodeName == "FORM") ?
- t : [t] )
- );
- },
- /**
- * Checks the current selection against an expression and returns true,
- * if at least one element of the selection fits the given expression.
- *
- * Does return false, if no element fits or the expression is not valid.
- *
- * filter(String) is used internally, therefore all rules that apply there
- * apply here, too.
- *
- * @example $("input[@type='checkbox']").parent().is("form")
- * @before <form><input type="checkbox" /></form>
- * @result true
- * @desc Returns true, because the parent of the input is a form element
- *
- * @example $("input[@type='checkbox']").parent().is("form")
- * @before <form><p><input type="checkbox" /></p></form>
- * @result false
- * @desc Returns false, because the parent of the input is a p element
- *
- * @name is
- * @type Boolean
- * @param String expr The expression with which to filter
- * @cat DOM/Traversing
- */
- is: function(expr) {
- return expr ? jQuery.filter(expr,this).r.length > 0 : false;
- },
-
- /**
- * Get the current value of the first matched element.
- *
- * @example $("input").val();
- * @before <input type="text" value="some text"/>
- * @result "some text"
- *
- * @name val
- * @type String
- * @cat DOM/Attributes
- */
-
- /**
- * Set the value of every matched element.
- *
- * @example $("input").val("test");
- * @before <input type="text" value="some text"/>
- * @result <input type="text" value="test"/>
- *
- * @name val
- * @type jQuery
- * @param String val Set the property to the specified value.
- * @cat DOM/Attributes
- */
- val: function( val ) {
- return val == undefined ?
- ( this.length ? this[0].value : null ) :
- this.attr( "value", val );
- },
-
- /**
- * Get the html contents of the first matched element.
- * This property is not available on XML documents.
- *
- * @example $("div").html();
- * @before <div><input/></div>
- * @result <input/>
- *
- * @name html
- * @type String
- * @cat DOM/Attributes
- */
-
- /**
- * Set the html contents of every matched element.
- * This property is not available on XML documents.
- *
- * @example $("div").html("<b>new stuff</b>");
- * @before <div><input/></div>
- * @result <div><b>new stuff</b></div>
- *
- * @name html
- * @type jQuery
- * @param String val Set the html contents to the specified value.
- * @cat DOM/Attributes
- */
- html: function( val ) {
- return val == undefined ?
- ( this.length ? this[0].innerHTML : null ) :
- this.empty().append( val );
- },
-
- /**
- * @private
- * @name domManip
- * @param Array args
- * @param Boolean table Insert TBODY in TABLEs if one is not found.
- * @param Number dir If dir<0, process args in reverse order.
- * @param Function fn The function doing the DOM manipulation.
- * @type jQuery
- * @cat Core
- */
- domManip: function(args, table, dir, fn){
- var clone = this.length > 1;
- var a = jQuery.clean(args);
- if ( dir < 0 )
- a.reverse();
- return this.each(function(){
- var obj = this;
- if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
- obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
- jQuery.each( a, function(){
- fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
- });
- });
- }
- };
- /**
- * Extends the jQuery object itself. Can be used to add functions into
- * the jQuery namespace and to add plugin methods (plugins).
- *
- * @example jQuery.fn.extend({
- * check: function() {
- * return this.each(function() { this.checked = true; });
- * },
- * uncheck: function() {
- * return this.each(function() { this.checked = false; });
- * }
- * });
- * $("input[@type=checkbox]").check();
- * $("input[@type=radio]").uncheck();
- * @desc Adds two plugin methods.
- *
- * @example jQuery.extend({
- * min: function(a, b) { return a < b ? a : b; },
- * max: function(a, b) { return a > b ? a : b; }
- * });
- * @desc Adds two functions into the jQuery namespace
- *
- * @name $.extend
- * @param Object prop The object that will be merged into the jQuery object
- * @type Object
- * @cat Core
- */
- /**
- * Extend one object with one or more others, returning the original,
- * modified, object. This is a great utility for simple inheritance.
- *
- * @example var settings = { validate: false, limit: 5, name: "foo" };
- * var options = { validate: true, name: "bar" };
- * jQuery.extend(settings, options);
- * @result settings == { validate: true, limit: 5, name: "bar" }
- * @desc Merge settings and options, modifying settings
- *
- * @example var defaults = { validate: false, limit: 5, name: "foo" };
- * var options = { validate: true, name: "bar" };
- * var settings = jQuery.extend({}, defaults, options);
- * @result settings == { validate: true, limit: 5, name: "bar" }
- * @desc Merge defaults and options, without modifying the defaults
- *
- * @name $.extend
- * @param Object target The object to extend
- * @param Object prop1 The object that will be merged into the first.
- * @param Object propN (optional) More objects to merge into the first
- * @type Object
- * @cat JavaScript
- */
- jQuery.extend = jQuery.fn.extend = function() {
- // copy reference to target object
- var target = arguments[0],
- a = 1;
- // extend jQuery itself if only one argument is passed
- if ( arguments.length == 1 ) {
- target = this;
- a = 0;
- }
- var prop;
- while (prop = arguments[a++])
- // Extend the base object
- for ( var i in prop ) target[i] = prop[i];
- // Return the modified object
- return target;
- };
- jQuery.extend({
- /**
- * Run this function to give control of the $ variable back
- * to whichever library first implemented it. This helps to make
- * sure that jQuery doesn't conflict with the $ object
- * of other libraries.
- *
- * By using this function, you will only be able to access jQuery
- * using the 'jQuery' variable. For example, where you used to do
- * $("div p"), you now must do jQuery("div p").
- *
- * @example jQuery.noConflict();
- * // Do something with jQuery
- * jQuery("div p").hide();
- * // Do something with another library's $()
- * $("content").style.display = 'none';
- * @desc Maps the original object that was referenced by $ back to $
- *
- * @example jQuery.noConflict();
- * (function($) {
- * $(function() {
- * // more code using $ as alias to jQuery
- * });
- * })(jQuery);
- * // other code using $ as an alias to the other library
- * @desc Reverts the $ alias and then creates and executes a
- * function to provide the $ as a jQuery alias inside the functions
- * scope. Inside the function the original $ object is not available.
- * This works well for most plugins that don't rely on any other library.
- *
- *
- * @name $.noConflict
- * @type undefined
- * @cat Core
- */
- noConflict: function() {
- if ( jQuery._$ )
- $ = jQuery._$;
- return jQuery;
- },
- // This may seem like some crazy code, but trust me when I say that this
- // is the only cross-browser way to do this. --John
- isFunction: function( fn ) {
- return !!fn && typeof fn != "string" &&
- typeof fn[0] == "undefined" && /function/i.test( fn + "" );
- },
- nodeName: function( elem, name ) {
- return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
- },
- /**
- * A generic iterator function, which can be used to seemlessly
- * iterate over both objects and arrays. This function is not the same
- * as $().each() - which is used to iterate, exclusively, over a jQuery
- * object. This function can be used to iterate over anything.
- *
- * The callback has two arguments:the key (objects) or index (arrays) as first
- * the first, and the value as the second.
- *
- * @example $.each( [0,1,2], function(i, n){
- * alert( "Item #" + i + ": " + n );
- * });
- * @desc This is an example of iterating over the items in an array,
- * accessing both the current item and its index.
- *
- * @example $.each( { name: "John", lang: "JS" }, function(i, n){
- * alert( "Name: " + i + ", Value: " + n );
- * });
- *
- * @desc This is an example of iterating over the properties in an
- * Object, accessing both the current item and its key.
- *
- * @name $.each
- * @param Object obj The object, or array, to iterate over.
- * @param Function fn The function that will be executed on every object.
- * @type Object
- * @cat JavaScript
- */
- // args is for internal usage only
- each: function( obj, fn, args ) {
- if ( obj.length == undefined )
- for ( var i in obj )
- fn.apply( obj[i], args || [i, obj[i]] );
- else
- for ( var i = 0, ol = obj.length; i < ol; i++ )
- if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
- return obj;
- },
-
- prop: function(elem, value, type, index, prop){
- // Handle executable functions
- if ( jQuery.isFunction( value ) )
- return value.call( elem, [index] );
-
- // exclude the following css properties to add px
- var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
- // Handle passing in a number to a CSS property
- if ( value.constructor == Number && type == "curCSS" && !exclude.test(prop) )
- return value + "px";
- return value;
- },
- className: {
- // internal only, use addClass("class")
- add: function( elem, c ){
- jQuery.each( c.split(/\s+/), function(i, cur){
- if ( !jQuery.className.has( elem.className, cur ) )
- elem.className += ( elem.className ? " " : "" ) + cur;
- });
- },
- // internal only, use removeClass("class")
- remove: function( elem, c ){
- elem.className = c ?
- jQuery.grep( elem.className.split(/\s+/), function(cur){
- return !jQuery.className.has( c, cur );
- }).join(" ") : "";
- },
- // internal only, use is(".class")
- has: function( t, c ) {
- t = t.className || t;
- return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t );
- }
- },
- /**
- * Swap in/out style options.
- * @private
- */
- swap: function(e,o,f) {
- for ( var i in o ) {
- e.style["old"+i] = e.style[i];
- e.style[i] = o[i];
- }
- f.apply( e, [] );
- for ( var i in o )
- e.style[i] = e.style["old"+i];
- },
- css: function(e,p) {
- if ( p == "height" || p == "width" ) {
- var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
- jQuery.each( d, function(){
- old["padding" + this] = 0;
- old["border" + this + "Width"] = 0;
- });
- jQuery.swap( e, old, function() {
- if (jQuery.css(e,"display") != "none") {
- oHeight = e.offsetHeight;
- oWidth = e.offsetWidth;
- } else {
- e = jQuery(e.cloneNode(true))
- .find(":radio").removeAttr("checked").end()
- .css({
- visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
- }).appendTo(e.parentNode)[0];
- var parPos = jQuery.css(e.parentNode,"position");
- if ( parPos == "" || parPos == "static" )
- e.parentNode.style.position = "relative";
- oHeight = e.clientHeight;
- oWidth = e.clientWidth;
- if ( parPos == "" || parPos == "static" )
- e.parentNode.style.position = "static";
- e.parentNode.removeChild(e);
- }
- });
- return p == "height" ? oHeight : oWidth;
- }
- return jQuery.curCSS( e, p );
- },
- curCSS: function(elem, prop, force) {
- var ret;
-
- if (prop == "opacity" && jQuery.browser.msie)
- return jQuery.attr(elem.style, "opacity");
-
- if (prop == "float" || prop == "cssFloat")
- prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
- if (!force && elem.style[prop])
- ret = elem.style[prop];
- else if (document.defaultView && document.defaultView.getComputedStyle) {
- if (prop == "cssFloat" || prop == "styleFloat")
- prop = "float";
- prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
- var cur = document.defaultView.getComputedStyle(elem, null);
- if ( cur )
- ret = cur.getPropertyValue(prop);
- else if ( prop == "display" )
- ret = "none";
- else
- jQuery.swap(elem, { display: "block" }, function() {
- var c = document.defaultView.getComputedStyle(this, "");
- ret = c && c.getPropertyValue(prop) || "";
- });
- } else if (elem.currentStyle) {
- var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
- ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
-
- }
- return ret;
- },
-
- clean: function(a) {
- var r = [];
- jQuery.each( a, function(i,arg){
- if ( !arg ) return;
- if ( arg.constructor == Number )
- arg = arg.toString();
-
- // Convert html string into DOM nodes
- if ( typeof arg == "string" ) {
- // Trim whitespace, otherwise indexOf won't work as expected
- var s = jQuery.trim(arg), div = document.createElement("div"), tb = [];
- var wrap =
- // option or optgroup
- !s.indexOf("<opt") &&
- [1, "<select>", "</select>"] ||
-
- (!s.indexOf("<thead") || !s.indexOf("<tbody") || !s.indexOf("<tfoot")) &&
- [1, "<table>", "</table>"] ||
-
- !s.indexOf("<tr") &&
- [2, "<table><tbody>", "</tbody></table>"] ||
-
- // <thead> matched above
- (!s.indexOf("<td") || !s.indexOf("<th")) &&
- [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
-
- [0,"",""];
- // Go to html and back, then peel off extra wrappers
- div.innerHTML = wrap[1] + s + wrap[2];
-
- // Move to the right depth
- while ( wrap[0]-- )
- div = div.firstChild;
-
- // Remove IE's autoinserted <tbody> from table fragments
- if ( jQuery.browser.msie ) {
-
- // String was a <table>, *may* have spurious <tbody>
- if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 )
- tb = div.firstChild && div.firstChild.childNodes;
-
- // String was a bare <thead> or <tfoot>
- else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
- tb = div.childNodes;
- for ( var n = tb.length-1; n >= 0 ; --n )
- if ( jQuery.nodeName(tb[n], "tbody") && !tb[n].childNodes.length )
- tb[n].parentNode.removeChild(tb[n]);
-
- }
-
- arg = div.childNodes;
- }
- if ( arg.length === 0 )
- return;
-
- if ( arg[0] == undefined )
- r.push( arg );
- else
- r = jQuery.merge( r, arg );
- });
- return r;
- },
-
- attr: function(elem, name, value){
- var fix = {
- "for": "htmlFor",
- "class": "className",
- "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
- cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
- innerHTML: "innerHTML",
- className: "className",
- value: "value",
- disabled: "disabled",
- checked: "checked",
- readonly: "readOnly",
- selected: "selected"
- };
-
- // IE actually uses filters for opacity ... elem is actually elem.style
- if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
- // IE has trouble with opacity if it does not have layout
- // Force it by setting the zoom level
- elem.zoom = 1;
- // Set the alpha filter to set the opacity
- return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
- ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
- } else if ( name == "opacity" && jQuery.browser.msie )
- return elem.filter ?
- parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
-
- // Mozilla doesn't play well with opacity 1
- if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
- value = 0.9999;
- // Certain attributes only work when accessed via the old DOM 0 way
- if ( fix[name] ) {
- if ( value != undefined ) elem[fix[name]] = value;
- return elem[fix[name]];
- } else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName(elem, "form") && (name == "action" || name == "method") )
- return elem.getAttributeNode(name).nodeValue;
- // IE elem.getAttribute passes even for style
- else if ( elem.tagName ) {
- if ( value != undefined ) elem.setAttribute( name, value );
- return elem.getAttribute( name );
- } else {
- name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
- if ( value != undefined ) elem[name] = value;
- return elem[name];
- }
- },
-
- /**
- * Remove the whitespace from the beginning and end of a string.
- *
- * @example $.trim(" hello, how are you? ");
- * @result "hello, how are you?"
- *
- * @name $.trim
- * @type String
- * @param String str The string to trim.
- * @cat JavaScript
- */
- trim: function(t){
- return t.replace(/^\s+|\s+$/g, "");
- },
- makeArray: function( a ) {
- var r = [];
- if ( a.constructor != Array )
- for ( var i = 0, al = a.length; i < al; i++ )
- r.push( a[i] );
- else
- r = a.slice( 0 );
- return r;
- },
- inArray: function( b, a ) {
- for ( var i = 0, al = a.length; i < al; i++ )
- if ( a[i] == b )
- return i;
- return -1;
- },
- /**
- * Merge two arrays together, removing all duplicates.
- *
- * The result is the altered first argument with
- * the unique elements from the second array added.
- *
- * @example $.merge( [0,1,2], [2,3,4] )
- * @result [0,1,2,3,4]
- * @desc Merges two arrays, removing the duplicate 2
- *
- * @example var array = [3,2,1];
- * $.merge( array, [4,3,2] )
- * @result array == [3,2,1,4]
- * @desc Merges two arrays, removing the duplicates 3 and 2
- *
- * @name $.merge
- * @type Array
- * @param Array first The first array to merge, the unique elements of second added.
- * @param Array second The second array to merge into the first, unaltered.
- * @cat JavaScript
- */
- merge: function(first, second) {
- var r = [].slice.call( first, 0 );
- // Now check for duplicates between the two arrays
- // and only add the unique items
- for ( var i = 0, sl = second.length; i < sl; i++ )
- // Check for duplicates
- if ( jQuery.inArray( second[i], r ) == -1 )
- // The item is unique, add it
- first.push( second[i] );
- return first;
- },
- /**
- * Filter items out of an array, by using a filter function.
- *
- * The specified function will be passed two arguments: The
- * current array item and the index of the item in the array. The
- * function must return 'true' to keep the item in the array,
- * false to remove it.
- *
- * @example $.grep( [0,1,2], function(i){
- * return i > 0;
- * });
- * @result [1, 2]
- *
- * @name $.grep
- * @type Array
- * @param Array array The Array to find items in.
- * @param Function fn The function to process each item against.
- * @param Boolean inv Invert the selection - select the opposite of the function.
- * @cat JavaScript
- */
- grep: function(elems, fn, inv) {
- // If a string is passed in for the function, make a function
- // for it (a handy shortcut)
- if ( typeof fn == "string" )
- fn = new Function("a","i","return " + fn);
- var result = [];
- // Go through the array, only saving the items
- // that pass the validator function
- for ( var i = 0, el = elems.length; i < el; i++ )
- if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
- result.push( elems[i] );
- return result;
- },
- /**
- * Translate all items in an array to another array of items.
- *
- * The translation function that is provided to this method is
- * called for each item in the array and is passed one argument:
- * The item to be translated.
- *
- * The function can then return the translated value, 'null'
- * (to remove the item), or an array of values - which will
- * be flattened into the full array.
- *
- * @example $.map( [0,1,2], function(i){
- * return i + 4;
- * });
- * @result [4, 5, 6]
- * @desc Maps the original array to a new one and adds 4 to each value.
- *
- * @example $.map( [0,1,2], function(i){
- * return i > 0 ? i + 1 : null;
- * });
- * @result [2, 3]
- * @desc Maps the original array to a new one and adds 1 to each
- * value if it is bigger then zero, otherwise it's removed-
- *
- * @example $.map( [0,1,2], function(i){
- * return [ i, i + 1 ];
- * });
- * @result [0, 1, 1, 2, 2, 3]
- * @desc Maps the original array to a new one, each element is added
- * with it's original value and the value plus one.
- *
- * @name $.map
- * @type Array
- * @param Array array The Array to translate.
- * @param Function fn The function to process each item against.
- * @cat JavaScript
- */
- map: function(elems, fn) {
- // If a string is passed in for the function, make a function
- // for it (a handy shortcut)
- if ( typeof fn == "string" )
- fn = new Function("a","return " + fn);
- var result = [], r = [];
- // Go through the array, translating each of the items to their
- // new value (or values).
- for ( var i = 0, el = elems.length; i < el; i++ ) {
- var val = fn(elems[i],i);
- if ( val !== null && val != undefined ) {
- if ( val.constructor != Array ) val = [val];
- result = result.concat( val );
- }
- }
- var r = result.length ? [ result[0] ] : [];
- check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
- for ( var j = 0; j < i; j++ )
- if ( result[i] == r[j] )
- continue check;
- r.push( result[i] );
- }
- return r;
- }
- });
- /**
- * Contains flags for the useragent, read from navigator.userAgent.
- * Available flags are: safari, opera, msie, mozilla
- *
- * This property is available before the DOM is ready, therefore you can
- * use it to add ready events only for certain browsers.
- *
- * There are situations where object detections is not reliable enough, in that
- * cases it makes sense to use browser detection. Simply try to avoid both!
- *
- * A combination of browser and object detection yields quite reliable results.
- *
- * @example $.browser.msie
- * @desc Returns true if the current useragent is some version of microsoft's internet explorer
- *
- * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
- * @desc Alerts "this is safari!" only for safari browsers
- *
- * @property
- * @name $.browser
- * @type Boolean
- * @cat JavaScript
- */
-
- /*
- * Whether the W3C compliant box model is being used.
- *
- * @property
- * @name $.boxModel
- * @type Boolean
- * @cat JavaScript
- */
- new function() {
- var b = navigator.userAgent.toLowerCase();
- // Figure out what browser is being used
- jQuery.browser = {
- safari: /webkit/.test(b),
- opera: /opera/.test(b),
- msie: /msie/.test(b) && !/opera/.test(b),
- mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
- };
- // Check to see if the W3C box model is being used
- jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
- };
- /**
- * Get a set of elements containing the unique parents of the matched
- * set of elements.
- *
- * Can be filtered with an optional expressions.
- *
- * @example $("p").parent()
- * @before <div><p>Hello</p><p>Hello</p></div>
- * @result [ <div><p>Hello</p><p>Hello</p></div> ]
- * @desc Find the parent element of each paragraph.
- *
- * @example $("p").parent(".selected")
- * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
- * @result [ <div class="selected"><p>Hello Again</p></div> ]
- * @desc Find the parent element of each paragraph with a class "selected".
- *
- * @name parent
- * @type jQuery
- * @param String expr (optional) An expression to filter the parents with
- * @cat DOM/Traversing
- */
- /**
- * Get a set of elements containing the unique ancestors of the matched
- * set of elements (except for the root element).
- *
- * Can be filtered with an optional expressions.
- *
- * @example $("span").parents()
- * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
- * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
- * @desc Find all parent elements of each span.
- *
- * @example $("span").parents("p")
- * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
- * @result [ <p><span>Hello</span></p> ]
- * @desc Find all parent elements of each span that is a paragraph.
- *
- * @name parents
- * @type jQuery
- * @param String expr (optional) An expression to filter the ancestors with
- * @cat DOM/Traversing
- */
- /**
- * Get a set of elements containing the unique next siblings of each of the
- * matched set of elements.
- *
- * It only returns the very next sibling, not all next siblings.
- *
- * Can be filtered with an optional expressions.
- *
- * @example $("p").next()
- * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
- * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
- * @desc Find the very next sibling of each paragraph.
- *
- * @example $("p").next(".selected")
- * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
- * @result [ <p class="selected">Hello Again</p> ]
- * @desc Find the very next sibling of each paragraph that has a class "selected".
- *
- * @name next
- * @type jQuery
- * @param String expr (optional) An expression to filter the next Elements with
- * @cat DOM/Traversing
- */
- /**
- * Get a set of elements containing the unique previous siblings of each of the
- * matched set of elements.
- *
- * Can be filtered with an optional expressions.
- *
- * It only returns the immediately previous sibling, not all previous siblings.
- *
- * @example $("p").prev()
- * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
- * @result [ <div><span>Hello Again</span></div> ]
- * @desc Find the very previous sibling of each paragraph.
- *
- * @example $("p").prev(".selected")
- * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
- * @result [ <div><span>Hello</span></div> ]
- * @desc Find the very previous sibling of each paragraph that has a class "selected".
- *
- * @name prev
- * @type jQuery
- * @param String expr (optional) An expression to filter the previous Elements with
- * @cat DOM/Traversing
- */
- /**
- * Get a set of elements containing all of the unique siblings of each of the
- * matched set of elements.
- *
- * Can be filtered with an optional expressions.
- *
- * @example $("div").siblings()
- * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
- * @result [ <p>Hello</p>, <p>And Again</p> ]
- * @desc Find all siblings of each div.
- *
- * @example $("div").siblings(".selected")
- * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
- * @result [ <p class="selected">Hello Again</p> ]
- * @desc Find all siblings with a class "selected" of each div.
- *
- * @name siblings
- * @type jQuery
- * @param String expr (optional) An expression to filter the sibling Elements with
- * @cat DOM/Traversing
- */
- /**
- * Get a set of elements containing all of the unique children of each of the
- * matched set of elements.
- *
- * Can be filtered with an optional expressions.
- *
- * @example $("div").children()
- * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
- * @result [ <span>Hello Again</span> ]
- * @desc Find all children of each div.
- *
- * @example $("div").children(".selected")
- * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
- * @result [ <p class="selected">Hello Again</p> ]
- * @desc Find all children with a class "selected" of each div.
- *
- * @name children
- * @type jQuery
- * @param String expr (optional) An expression to filter the child Elements with
- * @cat DOM/Traversing
- */
- jQuery.each({
- parent: "a.parentNode",
- parents: "jQuery.parents(a)",
- next: "jQuery.nth(a,2,'nextSibling')",
- prev: "jQuery.nth(a,2,'previousSibling')",
- siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
- children: "jQuery.sibling(a.firstChild)"
- }, function(i,n){
- jQuery.fn[ i ] = function(a) {
- var ret = jQuery.map(this,n);
- if ( a && typeof a == "string" )
- ret = jQuery.multiFilter(a,ret);
- return this.pushStack( ret );
- };
- });
- /**
- * Append all of the matched elements to another, specified, set of elements.
- * This operation is, essentially, the reverse of doing a regular
- * $(A).append(B), in that instead of appending B to A, you're appending
- * A to B.
- *
- * @example $("p").appendTo("#foo");
- * @before <p>I would like to say: </p><div id="foo"></div>
- * @result <div id="foo"><p>I would like to say: </p></div>
- * @desc Appends all paragraphs to the element with the ID "foo"
- *
- * @name appendTo
- * @type jQuery
- * @param <Content> content Content to append to the selected element to.
- * @cat DOM/Manipulation
- * @see append(<Content>)
- */
- /**
- * Prepend all of the matched elements to another, specified, set of elements.
- * This operation is, essentially, the reverse of doing a regular
- * $(A).prepend(B), in that instead of prepending B to A, you're prepending
- * A to B.
- *
- * @example $("p").prependTo("#foo");
- * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
- * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
- * @desc Prepends all paragraphs to the element with the ID "foo"
- *
- * @name prependTo
- * @type jQuery
- * @param <Content> content Content to prepend to the selected element to.
- * @cat DOM/Manipulation
- * @see prepend(<Content>)
- */
- /**
- * Insert all of the matched elements before another, specified, set of elements.
- * This operation is, essentially, the reverse of doing a regular
- * $(A).before(B), in that instead of inserting B before A, you're inserting
- * A before B.
- *
- * @example $("p").insertBefore("#foo");
- * @before <div id="foo">Hello</div><p>I would like to say: </p>
- * @result <p>I would like to say: </p><div id="foo">Hello</div>
- * @desc Same as $("#foo").before("p")
- *
- * @name insertBefore
- * @type jQuery
- * @param <Content> content Content to insert the selected element before.
- * @cat DOM/Manipulation
- * @see before(<Content>)
- */
- /**
- * Insert all of the matched elements after another, specified, set of elements.
- * This operation is, essentially, the reverse of doing a regular
- * $(A).after(B), in that instead of inserting B after A, you're inserting
- * A after B.
- *
- * @example $("p").insertAfter("#foo");
- * @before <p>I would like to say: </p><div id="foo">Hello</div>
- * @result <div id="foo">Hello</div><p>I would like to say: </p>
- * @desc Same as $("#foo").after("p")
- *
- * @name insertAfter
- * @type jQuery
- * @param <Content> content Content to insert the selected element after.
- * @cat DOM/Manipulation
- * @see after(<Content>)
- */
- jQuery.each({
- appendTo: "append",
- prependTo: "prepend",
- insertBefore: "before",
- insertAfter: "after"
- }, function(i,n){
- jQuery.fn[ i ] = function(){
- var a = arguments;
- return this.each(function(){
- for ( var j = 0, al = a.length; j < al; j++ )
- jQuery(a[j])[n]( this );
- });
- };
- });
- /**
- * Remove an attribute from each of the matched elements.
- *
- * @example $("input").removeAttr("disabled")
- * @before <input disabled="disabled"/>
- * @result <input/>
- *
- * @name removeAttr
- * @type jQuery
- * @param String name The name of the attribute to remove.
- * @cat DOM/Attributes
- */
- /**
- * Adds the specified class(es) to each of the set of matched elements.
- *
- * @example $("p").addClass("selected")
- * @before <p>Hello</p>
- * @result [ <p class="selected">Hello</p> ]
- *
- * @example $("p").addClass("selected highlight")
- * @before <p>Hello</p>
- * @result [ <p class="selected highlight">Hello</p> ]
- *
- * @name addClass
- * @type jQuery
- * @param String class One or more CSS classes to add to the elements
- * @cat DOM/Attributes
- * @see removeClass(String)
- */
- /**
- * Removes all or the specified class(es) from the set of matched elements.
- *
- * @example $("p").removeClass()
- * @before <p class="selected">Hello</p>
- * @result [ <p>Hello</p> ]
- *
- * @example $("p").removeClass("selected")
- * @before <p class="selected first">Hello</p>
- * @result [ <p class="first">Hello</p> ]
- *
- * @example $("p").removeClass("selected highlight")
- * @before <p class="highlight selected first">Hello</p>
- * @result [ <p class="first">Hello</p> ]
- *
- * @name removeClass
- * @type jQuery
- * @param String class (optional) One or more CSS classes to remove from the elements
- * @cat DOM/Attributes
- * @see addClass(String)
- */
- /**
- * Adds the specified class if it is not present, removes it if it is
- * present.
- *
- * @example $("p").toggleClass("selected")
- * @before <p>Hello</p><p class="selected">Hello Again</p>
- * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
- *
- * @name toggleClass
- * @type jQuery
- * @param String class A CSS class with which to toggle the elements
- * @cat DOM/Attributes
- */
- /**
- * Removes all matched elements from the DOM. This does NOT remove them from the
- * jQuery object, allowing you to use the matched elements further.
- *
- * Can be filtered with an optional expressions.
- *
- * @example $("p").remove();
- * @before <p>Hello</p> how are <p>you?</p>
- * @result how are
- *
- * @example $("p").remove(".hello");
- * @before <p class="hello">Hello</p> how are <p>you?</p>
- * @result how are <p>you?</p>
- *
- * @name remove
- * @type jQuery
- * @param String expr (optional) A jQuery expression to filter elements by.
- * @cat DOM/Manipulation
- */
- /**
- * Removes all child nodes from the set of matched elements.
- *
- * @example $("p").empty()
- * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
- * @result [ <p></p> ]
- *
- * @name empty
- * @type jQuery
- * @cat DOM/Manipulation
- */
- jQuery.each( {
- removeAttr: function( key ) {
- jQuery.attr( this, key, "" );
- this.removeAttribute( key );
- },
- addClass: function(c){
- jQuery.className.add(this,c);
- },
- removeClass: function(c){
- jQuery.className.remove(this,c);
- },
- toggleClass: function( c ){
- jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
- },
- remove: function(a){
- if ( !a || jQuery.filter( a, [this] ).r.length )
- this.parentNode.removeChild( this );
- },
- empty: function() {
- while ( this.firstChild )
- this.removeChild( this.firstChild );
- }
- }, function(i,n){
- jQuery.fn[ i ] = function() {
- return this.each( n, arguments );
- };
- });
- /**
- * Reduce the set of matched elements to a single element.
- * The position of the element in the set of matched elements
- * starts at 0 and goes to length - 1.
- *
- * @example $("p").eq(1)
- * @before <p>This is just a test.</p><p>So is this</p>
- * @result [ <p>So is this</p> ]
- *
- * @name eq
- * @type jQuery
- * @param Number pos The index of the element that you wish to limit to.
- * @cat Core
- */
- /**
- * Reduce the set of matched elements to all elements before a given position.
- * The position of the element in the set of matched elements
- * starts at 0 and goes to length - 1.
- *
- * @example $("p").lt(1)
- * @before <p>This is just a test.</p><p>So is this</p>
- * @result [ <p>This is just a test.</p> ]
- *
- * @name lt
- * @type jQuery
- * @param Number pos Reduce the set to all elements below this position.
- * @cat Core
- */
- /**
- * Reduce the set of matched elements to all elements after a given position.
- * The position of the element in the set of matched elements
- * starts at 0 and goes to length - 1.
- *
- * @example $("p").gt(0)
- * @before <p>This is just a test.</p><p>So is this</p>
- * @result [ <p>So is this</p> ]
- *
- * @name gt
- * @type jQuery
- * @param Number pos Reduce the set to all elements after this position.
- * @cat Core
- */
- /**
- * Filter the set of elements to those that contain the specified text.
- *
- * @example $("p").contains("test")
- * @before <p>This is just a test.</p><p>So is this</p>
- * @result [ <p>This is just a test.</p> ]
- *
- * @name contains
- * @type jQuery
- * @param String str The string that will be contained within the text of an element.
- * @cat DOM/Traversing
- */
- jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
- jQuery.fn[ n ] = function(num,fn) {
- return this.filter( ":" + n + "(" + num + ")", fn );
- };
- });
- /**
- * Get the current computed, pixel, width of the first matched element.
- *
- * @example $("p").width();
- * @before <p>This is just a test.</p>
- * @result 300
- *
- * @name width
- * @type String
- * @cat CSS
- */
- /**
- * Set the CSS width of every matched element. If no explicit unit
- * was specified (like 'em' or '%') then "px" is added to the width.
- *
- * @example $("p").width(20);
- * @before <p>This is just a test.</p>
- * @result <p style="width:20px;">This is just a test.</p>
- *
- * @example $("p").width("20em");
- * @before <p>This is just a test.</p>
- * @result <p style="width:20em;">This is just a test.</p>
- *
- * @name width
- * @type jQuery
- * @param String|Number val Set the CSS property to the specified value.
- * @cat CSS
- */
-
- /**
- * Get the current computed, pixel, height of the first matched element.
- *
- * @example $("p").height();
- * @before <p>This is just a test.</p>
- * @result 300
- *
- * @name height
- * @type String
- * @cat CSS
- */
- /**
- * Set the CSS width of every matched element. If no explicit unit
- * was specified (like 'em' or '%') then "px" is added to the width.
- *
- * @example $("p").height(20);
- * @before <p>This is just a test.</p>
- * @result <p style="height:20px;">This is just a test.</p>
- *
- * @example $("p").height("20em");
- * @before <p>This is just a test.</p>
- * @result <p style="height:20em;">This is just a test.</p>
- *
- * @name height
- * @type jQuery
- * @param String|Number val Set the CSS property to the specified value.
- * @cat CSS
- */
- jQuery.each( [ "height", "width" ], function(i,n){
- jQuery.fn[ n ] = function(h) {
- return h == undefined ?
- ( this.length ? jQuery.css( this[0], n ) : null ) :
- this.css( n, h.constructor == String ? h : h + "px" );
- };
- });
- jQuery.extend({
- expr: {
- "": "m[2]=='*'||jQuery.nodeName(a,m[2])",
- "#": "a.getAttribute('id')==m[2]",
- ":": {
- // Position Checks
- lt: "i<m[3]-0",
- gt: "i>m[3]-0",
- nth: "m[3]-0==i",
- eq: "m[3]-0==i",
- first: "i==0",
- last: "i==r.length-1",
- even: "i%2==0",
- odd: "i%2",
- // Child Checks
- "nth-child": "jQuery.nth(a.parentNode.firstChild,m[3],'nextSibling',a)==a",
- "first-child": "jQuery.nth(a.parentNode.firstChild,1,'nextSibling')==a",
- "last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a",
- "only-child": "jQuery.sibling(a.parentNode.firstChild).length==1",
- // Parent Checks
- parent: "a.firstChild",
- empty: "!a.firstChild",
- // Text Check
- contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
- // Visibility
- visible: 'a.type!="hidden"&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"',
- hidden: 'a.type=="hidden"||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"',
- // Form attributes
- enabled: "!a.disabled",
- disabled: "a.disabled",
- checked: "a.checked",
- selected: "a.selected||jQuery.attr(a,'selected')",
- // Form elements
- text: "a.type=='text'",
- radio: "a.type=='radio'",
- checkbox: "a.type=='checkbox'",
- file: "a.type=='file'",
- password: "a.type=='password'",
- submit: "a.type=='submit'",
- image: "a.type=='image'",
- reset: "a.type=='reset'",
- button: 'a.type=="button"||jQuery.nodeName(a,"button")',
- input: "/input|select|textarea|button/i.test(a.nodeName)"
- },
- ".": "jQuery.className.has(a,m[2])",
- "@": {
- "=": "z==m[4]",
- "!=": "z!=m[4]",
- "^=": "z&&!z.indexOf(m[4])",
- "$=": "z&&z.substr(z.length - m[4].length,m[4].length)==m[4]",
- "*=": "z&&z.indexOf(m[4])>=0",
- "": "z",
- _resort: function(m){
- return ["", m[1], m[3], m[2], m[5]];
- },
- _prefix: "z=a[m[3]]||jQuery.attr(a,m[3]);"
- },
- "[": "jQuery.find(m[2],a).length"
- },
-
- // The regular expressions that power the parsing engine
- parse: [
- // Match: [@value='test'], [@foo]
- /^\[ *(@)([a-z0-9_-]*) *([!*$^=]*) *('?"?)(.*?)\4 *\]/i,
- // Match: [div], [div p]
- /^(\[)\s*(.*?(\[.*?\])?[^[]*?)\s*\]/,
- // Match: :contains('foo')
- /^(:)([a-z0-9_-]*)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/i,
- // Match: :even, :last-chlid
- /^([:.#]*)([a-z0-9_*-]*)/i
- ],
- token: [
- /^(\/?\.\.)/, "a.parentNode",
- /^(>|\/)/, "jQuery.sibling(a.firstChild)",
- /^(\+)/, "jQuery.nth(a,2,'nextSibling')",
- /^(~)/, function(a){
- var s = jQuery.sibling(a.parentNode.firstChild);
- return s.slice(0, jQuery.inArray(a,s));
- }
- ],
- multiFilter: function( expr, elems, not ) {
- var old, cur = [];
- while ( expr && expr != old ) {
- old = expr;
- var f = jQuery.filter( expr, elems, not );
- expr = f.t.replace(/^\s*,\s*/, "" );
- cur = not ? elems = f.r : jQuery.merge( cur, f.r );
- }
- return cur;
- },
- /**
- * @name $.find
- * @type Array<Element>
- * @private
- * @cat Core
- */
- find: function( t, context ) {
- // Quickly handle non-string expressions
- if ( typeof t != "string" )
- return [ t ];
- // Make sure that the context is a DOM Element
- if ( context && !context.nodeType )
- context = null;
- // Set the correct context (if none is provided)
- context = context || document;
- // Handle the common XPath // expression
- if ( !t.indexOf("//") ) {
- context = context.documentElement;
- t = t.substr(2,t.length);
- // And the / root expression
- } else if ( !t.indexOf("/") ) {
- context = context.documentElement;
- t = t.substr(1,t.length);
- if ( t.indexOf("/") >= 1 )
- t = t.substr(t.indexOf("/"),t.length);
- }
- // Initialize the search
- var ret = [context], done = [], last = null;
- // Continue while a selector expression exists, and while
- // we're no longer looping upon ourselves
- while ( t && last != t ) {
- var r = [];
- last = t;
- t = jQuery.trim(t).replace( /^\/\//i, "" );
- var foundToken = false;
- // An attempt at speeding up child selectors that
- // point to a specific element tag
- var re = /^[\/>]\s*([a-z0-9*-]+)/i;
- var m = re.exec(t);
- if ( m ) {
- // Perform our own iteration and filter
- jQuery.each( ret, function(){
- for ( var c = this.firstChild; c; c = c.nextSibling )
- if ( c.nodeType == 1 && ( jQuery.nodeName(c, m[1]) || m[1] == "*" ) )
- r.push( c );
- });
- ret = r;
- t = t.replace( re, "" );
- if ( t.indexOf(" ") == 0 ) continue;
- foundToken = true;
- } else {
- // Look for pre-defined expression tokens
- for ( var i = 0; i < jQuery.token.length; i += 2 ) {
- // Attempt to match each, individual, token in
- // the specified order
- var re = jQuery.token[i];
- var m = re.exec(t);
- // If the token match was found
- if ( m ) {
- // Map it against the token's handler
- r = ret = jQuery.map( ret, jQuery.isFunction( jQuery.token[i+1] ) ?
- jQuery.token[i+1] :
- function(a){ return eval(jQuery.token[i+1]); });
- // And remove the token
- t = jQuery.trim( t.replace( re, "" ) );
- foundToken = true;
- break;
- }
- }
- }
- // See if there's still an expression, and that we haven't already
- // matched a token
- if ( t && !foundToken ) {
- // Handle multiple expressions
- if ( !t.indexOf(",") ) {
- // Clean the result set
- if ( ret[0] == context ) ret.shift();
- // Merge the result sets
- jQuery.merge( done, ret );
- // Reset the context
- r = ret = [context];
- // Touch up the selector string
- t = " " + t.substr(1,t.length);
- } else {
- // Optomize for the case nodeName#idName
- var re2 = /^([a-z0-9_-]+)(#)([a-z0-9\\*_-]*)/i;
- var m = re2.exec(t);
-
- // Re-organize the results, so that they're consistent
- if ( m ) {
- m = [ 0, m[2], m[3], m[1] ];
- } else {
- // Otherwise, do a traditional filter check for
- // ID, class, and element selectors
- re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
- m = re2.exec(t);
- }
- // Try to do a global search by ID, where we can
- if ( m[1] == "#" && ret[ret.length-1].getElementById ) {
- // Optimization for HTML document case
- var oid = ret[ret.length-1].getElementById(m[2]);
- // Do a quick check for node name (where applicable) so
- // that div#foo searches will be really fast
- ret = r = oid &&
- (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
- } else {
- // Pre-compile a regular expression to handle class searches
- if ( m[1] == "." )
- var rec = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
- // We need to find all descendant elements, it is more
- // efficient to use getAll() when we are already further down
- // the tree - we try to recognize that here
- jQuery.each( ret, function(){
- // Grab the tag name being searched for
- var tag = m[1] != "" || m[0] == "" ? "*" : m[2];
- // Handle IE7 being really dumb about <object>s
- if ( jQuery.nodeName(this, "object") && tag == "*" )
- tag = "param";
- jQuery.merge( r,
- m[1] != "" && ret.length != 1 ?
- jQuery.getAll( this, [], m[1], m[2], rec ) :
- this.getElementsByTagName( tag )
- );
- });
- // It's faster to filter by class and be done with it
- if ( m[1] == "." && ret.length == 1 )
- r = jQuery.grep( r, function(e) {
- return rec.test(e.className);
- });
- // Same with ID filtering
- if ( m[1] == "#" && ret.length == 1 ) {
- // Remember, then wipe out, the result set
- var tmp = r;
- r = [];
- // Then try to find the element with the ID
- jQuery.each( tmp, function(){
- if ( this.getAttribute("id") == m[2] ) {
- r = [ this ];
- return false;
- }
- });
- }
- ret = r;
- }
- t = t.replace( re2, "" );
- }
- }
- // If a selector string still exists
- if ( t ) {
- // Attempt to filter it
- var val = jQuery.filter(t,r);
- ret = r = val.r;
- t = jQuery.trim(val.t);
- }
- }
- // Remove the root context
- if ( ret && ret[0] == context ) ret.shift();
- // And combine the results
- jQuery.merge( done, ret );
- return done;
- },
- filter: function(t,r,not) {
- // Look for common filter expressions
- while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
- var p = jQuery.parse, m;
- jQuery.each( p, function(i,re){
-
- // Look for, and replace, string-like sequences
- // and finally build a regexp out of it
- m = re.exec( t );
- if ( m ) {
- // Remove what we just matched
- t = t.substring( m[0].length );
- // Re-organize the first match
- if ( jQuery.expr[ m[1] ]._resort )
- m = jQuery.expr[ m[1] ]._resort( m );
- return false;
- }
- });
- // :not() is a special case that can be optimized by
- // keeping it out of the expression list
- if ( m[1] == ":" && m[2] == "not" )
- r = jQuery.filter(m[3], r, true).r;
- // Handle classes as a special case (this will help to
- // improve the speed, as the regexp will only be compiled once)
- else if ( m[1] == "." ) {
- var re = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
- r = jQuery.grep( r, function(e){
- return re.test(e.className || "");
- }, not);
- // Otherwise, find the expression to execute
- } else {
- var f = jQuery.expr[m[1]];
- if ( typeof f != "string" )
- f = jQuery.expr[m[1]][m[2]];
- // Build a custom macro to enclose it
- eval("f = function(a,i){" +
- ( jQuery.expr[ m[1] ]._prefix || "" ) +
- "return " + f + "}");
- // Execute it against the current filter
- r = jQuery.grep( r, f, not );
- }
- }
- // Return an array of filtered elements (r)
- // and the modified expression string (t)
- return { r: r, t: t };
- },
-
- getAll: function( o, r, token, name, re ) {
- for ( var s = o.firstChild; s; s = s.nextSibling )
- if ( s.nodeType == 1 ) {
- var add = true;
- if ( token == "." )
- add = s.className && re.test(s.className);
- else if ( token == "#" )
- add = s.getAttribute("id") == name;
-
- if ( add )
- r.push( s );
- if ( token == "#" && r.length ) break;
- if ( s.firstChild )
- jQuery.getAll( s, r, token, name, re );
- }
- return r;
- },
- /**
- * All ancestors of a given element.
- *
- * @private
- * @name $.parents
- * @type Array<Element>
- * @param Element elem The element to find the ancestors of.
- * @cat DOM/Traversing
- */
- parents: function( elem ){
- var matched = [];
- var cur = elem.parentNode;
- while ( cur && cur != document ) {
- matched.push( cur );
- cur = cur.parentNode;
- }
- return matched;
- },
-
- /**
- * A handy, and fast, way to traverse in a particular direction and find
- * a specific element.
- *
- * @private
- * @name $.nth
- * @type DOMElement
- * @param DOMElement cur The element to search from.
- * @param String|Number num The Nth result to match. Can be a number or a string (like 'even' or 'odd').
- * @param String dir The direction to move in (pass in something like 'previousSibling' or 'nextSibling').
- * @cat DOM/Traversing
- */
- nth: function(cur,result,dir,elem){
- result = result || 1;
- var num = 0;
- for ( ; cur; cur = cur[dir] ) {
- if ( cur.nodeType == 1 ) num++;
- if ( num == result || result == "even" && num % 2 == 0 && num > 1 && cur == elem ||
- result == "odd" && num % 2 == 1 && cur == elem ) return cur;
- }
- },
-
- /**
- * All elements on a specified axis.
- *
- * @private
- * @name $.sibling
- * @type Array
- * @param Element elem The element to find all the siblings of (including itself).
- * @cat DOM/Traversing
- */
- sibling: function( n, elem ) {
- var r = [];
- for ( ; n; n = n.nextSibling ) {
- if ( n.nodeType == 1 && (!elem || n != elem) )
- r.push( n );
- }
- return r;
- }
- });
- /*
- * A number of helper functions used for managing events.
- * Many of the ideas behind this code orignated from
- * Dean Edwards' addEvent library.
- */
- jQuery.event = {
- // Bind an event to an element
- // Original by Dean Edwards
- add: function(element, type, handler, data) {
- // For whatever reason, IE has trouble passing the window object
- // around, causing it to be cloned in the process
- if ( jQuery.browser.msie && element.setInterval != undefined )
- element = window;
- // if data is passed, bind to handler
- if( data )
- handler.data = data;
- // Make sure that the function being executed has a unique ID
- if ( !handler.guid )
- handler.guid = this.guid++;
- // Init the element's event structure
- if (!element.events)
- element.events = {};
- // Get the current list of functions bound to this event
- var handlers = element.events[type];
- // If it hasn't been initialized yet
- if (!handlers) {
- // Init the event handler queue
- handlers = element.events[type] = {};
- // Remember an existing handler, if it's already there
- if (element["on" + type])
- handlers[0] = element["on" + type];
- }
- // Add the function to the element's handler list
- handlers[handler.guid] = handler;
- // And bind the global event handler to the element
- element["on" + type] = this.handle;
- // Remember the function in a global list (for triggering)
- if (!this.global[type])
- this.global[type] = [];
- this.global[type].push( element );
- },
- guid: 1,
- global: {},
- // Detach an event or set of events from an element
- remove: function(element, type, handler) {
- if (element.events)
- if ( type && type.type )
- delete element.events[ type.type ][ type.handler.guid ];
- else if (type && element.events[type])
- if ( handler )
- delete element.events[type][handler.guid];
- else
- for ( var i in element.events[type] )
- delete element.events[type][i];
- else
- for ( var j in element.events )
- this.remove( element, j );
- },
- trigger: function(type,data,element) {
- // Clone the incoming data, if any
- data = jQuery.makeArray(data || []);
- // Handle a global trigger
- if ( !element )
- jQuery.each( this.global[type] || [], function(){
- jQuery.event.trigger( type, data, this );
- });
- // Handle triggering a single element
- else {
- var handler = element["on" + type ], val,
- fn = jQuery.isFunction( element[ type ] );
- if ( handler ) {
- // Pass along a fake event
- data.unshift( this.fix({ type: type, target: element }) );
-
- // Trigger the event
- if ( (val = handler.apply( element, data )) !== false )
- this.triggered = true;
- }
- if ( fn && val !== false )
- element[ type ]();
- this.triggered = false;
- }
- },
- handle: function(event) {
- // Handle the second event of a trigger and when
- // an event is called after a page has unloaded
- if ( typeof jQuery == "undefined" || jQuery.event.triggered ) return;
- // Empty object is for triggered events with no data
- event = jQuery.event.fix( event || window.event || {} );
- // returned undefined or false
- var returnValue;
- var c = this.events[event.type];
- var args = [].slice.call( arguments, 1 );
- args.unshift( event );
- for ( var j in c ) {
- // Pass in a reference to the handler function itself
- // So that we can later remove it
- args[0].handler = c[j];
- args[0].data = c[j].data;
- if ( c[j].apply( this, args ) === false ) {
- event.preventDefault();
- event.stopPropagation();
- returnValue = false;
- }
- }
- // Clean up added properties in IE to prevent memory leak
- if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = event.handler = event.data = null;
- return returnValue;
- },
- fix: function(event) {
- // Fix target property, if necessary
- if ( !event.target && event.srcElement )
- event.target = event.srcElement;
- // Calculate pageX/Y if missing and clientX/Y available
- if ( event.pageX == undefined && event.clientX != undefined ) {
- var e = document.documentElement, b = document.body;
- event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft);
- event.pageY = event.clientY + (e.scrollTop || b.scrollTop);
- }
-
- // check if target is a textnode (safari)
- if (jQuery.browser.safari && event.target.nodeType == 3) {
- // store a copy of the original event object
- // and clone because target is read only
- var originalEvent = event;
- event = jQuery.extend({}, originalEvent);
-
- // get parentnode from textnode
- event.target = originalEvent.target.parentNode;
-
- // add preventDefault and stopPropagation since
- // they will not work on the clone
- event.preventDefault = function() {
- return originalEvent.preventDefault();
- };
- event.stopPropagation = function() {
- return originalEvent.stopPropagation();
- };
- }
-
- // fix preventDefault and stopPropagation
- if (!event.preventDefault)
- event.preventDefault = function() {
- this.returnValue = false;
- };
-
- if (!event.stopPropagation)
- event.stopPropagation = function() {
- this.cancelBubble = true;
- };
-
- return event;
- }
- };
- jQuery.fn.extend({
- /**
- * Binds a handler to a particular event (like click) for each matched element.
- * The event handler is passed an event object that you can use to prevent
- * default behaviour. To stop both default action and event bubbling, your handler
- * has to return false.
- *
- * In most cases, you can define your event handlers as anonymous functions
- * (see first example). In cases where that is not possible, you can pass additional
- * data as the second paramter (and the handler function as the third), see
- * second example.
- *
- * @example $("p").bind("click", function(){
- * alert( $(this).text() );
- * });
- * @before <p>Hello</p>
- * @result alert("Hello")
- *
- * @example function handler(event) {
- * alert(event.data.foo);
- * }
- * $("p").bind("click", {foo: "bar"}, handler)
- * @result alert("bar")
- * @desc Pass some additional data to the event handler.
- *
- * @example $("form").bind("submit", function() { return false; })
- * @desc Cancel a default action and prevent it from bubbling by returning false
- * from your function.
- *
- * @example $("form").bind("submit", function(event){
- * event.preventDefault();
- * });
- * @desc Cancel only the default action by using the preventDefault method.
- *
- *
- * @example $("form").bind("submit", function(event){
- * event.stopPropagation();
- * });
- * @desc Stop only an event from bubbling by using the stopPropagation method.
- *
- * @name bind
- * @type jQuery
- * @param String type An event type
- * @param Object data (optional) Additional data passed to the event handler as event.data
- * @param Function fn A function to bind to the event on each of the set of matched elements
- * @cat Events
- */
- bind: function( type, data, fn ) {
- return this.each(function(){
- jQuery.event.add( this, type, fn || data, data );
- });
- },
-
- /**
- * Binds a handler to a particular event (like click) for each matched element.
- * The handler is executed only once for each element. Otherwise, the same rules
- * as described in bind() apply.
- The event handler is passed an event object that you can use to prevent
- * default behaviour. To stop both default action and event bubbling, your handler
- * has to return false.
- *
- * In most cases, you can define your event handlers as anonymous functions
- * (see first example). In cases where that is not possible, you can pass additional
- * data as the second paramter (and the handler function as the third), see
- * second example.
- *
- * @example $("p").one("click", function(){
- * alert( $(this).text() );
- * });
- * @before <p>Hello</p>
- * @result alert("Hello")
- *
- * @name one
- * @type jQuery
- * @param String type An event type
- * @param Object data (optional) Additional data passed to the event handler as event.data
- * @param Function fn A function to bind to the event on each of the set of matched elements
- * @cat Events
- */
- one: function( type, data, fn ) {
- return this.each(function(){
- jQuery.event.add( this, type, function(event) {
- jQuery(this).unbind(event);
- return (fn || data).apply( this, arguments);
- }, data);
- });
- },
- /**
- * The opposite of bind, removes a bound event from each of the matched
- * elements.
- *
- * Without any arguments, all bound events are removed.
- *
- * If the type is provided, all bound events of that type are removed.
- *
- * If the function that was passed to bind is provided as the second argument,
- * only that specific event handler is removed.
- *
- * @example $("p").unbind()
- * @before <p onclick="alert('Hello');">Hello</p>
- * @result [ <p>Hello</p> ]
- *
- * @example $("p").unbind( "click" )
- * @before <p onclick="alert('Hello');">Hello</p>
- * @result [ <p>Hello</p> ]
- *
- * @example $("p").unbind( "click", function() { alert("Hello"); } )
- * @before <p onclick="alert('Hello');">Hello</p>
- * @result [ <p>Hello</p> ]
- *
- * @name unbind
- * @type jQuery
- * @param String type (optional) An event type
- * @param Function fn (optional) A function to unbind from the event on each of the set of matched elements
- * @cat Events
- */
- unbind: function( type, fn ) {
- return this.each(function(){
- jQuery.event.remove( this, type, fn );
- });
- },
- /**
- * Trigger a type of event on every matched element.
- *
- * @example $("p").trigger("click")
- * @before <p click="alert('hello')">Hello</p>
- * @result alert('hello')
- *
- * @name trigger
- * @type jQuery
- * @param String type An event type to trigger.
- * @cat Events
- */
- trigger: function( type, data ) {
- return this.each(function(){
- jQuery.event.trigger( type, data, this );
- });
- },
- /**
- * Toggle between two function calls every other click.
- * Whenever a matched element is clicked, the first specified function
- * is fired, when clicked again, the second is fired. All subsequent
- * clicks continue to rotate through the two functions.
- *
- * Use unbind("click") to remove.
- *
- * @example $("p").toggle(function(){
- * $(this).addClass("selected");
- * },function(){
- * $(this).removeClass("selected");
- * });
- *
- * @name toggle
- * @type jQuery
- * @param Function even The function to execute on every even click.
- * @param Function odd The function to execute on every odd click.
- * @cat Events
- */
- toggle: function() {
- // Save reference to arguments for access in closure
- var a = arguments;
- return this.click(function(e) {
- // Figure out which function to execute
- this.lastToggle = this.lastToggle == 0 ? 1 : 0;
-
- // Make sure that clicks stop
- e.preventDefault();
-
- // and execute the function
- return a[this.lastToggle].apply( this, [e] ) || false;
- });
- },
-
- /**
- * A method for simulating hovering (moving the mouse on, and off,
- * an object). This is a custom method which provides an 'in' to a
- * frequent task.
- *
- * Whenever the mouse cursor is moved over a matched
- * element, the first specified function is fired. Whenever the mouse
- * moves off of the element, the second specified function fires.
- * Additionally, checks are in place to see if the mouse is still within
- * the specified element itself (for example, an image inside of a div),
- * and if it is, it will continue to 'hover', and not move out
- * (a common error in using a mouseout event handler).
- *
- * @example $("p").hover(function(){
- * $(this).addClass("over");
- * },function(){
- * $(this).addClass("out");
- * });
- *
- * @name hover
- * @type jQuery
- * @param Function over The function to fire whenever the mouse is moved over a matched element.
- * @param Function out The function to fire whenever the mouse is moved off of a matched element.
- * @cat Events
- */
- hover: function(f,g) {
-
- // A private function for handling mouse 'hovering'
- function handleHover(e) {
- // Check if mouse(over|out) are still within the same parent element
- var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
-
- // Traverse up the tree
- while ( p && p != this ) try { p = p.parentNode } catch(e) { p = this; };
-
- // If we actually just moused on to a sub-element, ignore it
- if ( p == this ) return false;
-
- // Execute the right function
- return (e.type == "mouseover" ? f : g).apply(this, [e]);
- }
-
- // Bind the function to the two event listeners
- return this.mouseover(handleHover).mouseout(handleHover);
- },
-
- /**
- * Bind a function to be executed whenever the DOM is ready to be
- * traversed and manipulated. This is probably the most important
- * function included in the event module, as it can greatly improve
- * the response times of your web applications.
- *
- * In a nutshell, this is a solid replacement for using window.onload,
- * and attaching a function to that. By using this method, your bound Function
- * will be called the instant the DOM is ready to be read and manipulated,
- * which is exactly what 99.99% of all Javascript code needs to run.
- *
- * There is one argument passed to the ready event handler: A reference to
- * the jQuery function. You can name that argument whatever you like, and
- * can therefore stick with the $ alias without risc of naming collisions.
- *
- * Please ensure you have no code in your <body> onload event handler,
- * otherwise $(document).ready() may not fire.
- *
- * You can have as many $(document).ready events on your page as you like.
- * The functions are then executed in the order they were added.
- *
- * @example $(document).ready(function(){ Your code here... });
- *
- * @example jQuery(function($) {
- * // Your code using failsafe $ alias here...
- * });
- * @desc Uses both the shortcut for $(document).ready() and the argument
- * to write failsafe jQuery code using the $ alias, without relying on the
- * global alias.
- *
- * @name ready
- * @type jQuery
- * @param Function fn The function to be executed when the DOM is ready.
- * @cat Events
- * @see $.noConflict()
- * @see $(Function)
- */
- ready: function(f) {
- // If the DOM is already ready
- if ( jQuery.isReady )
- // Execute the function immediately
- f.apply( document, [jQuery] );
-
- // Otherwise, remember the function for later
- else {
- // Add the function to the wait list
- jQuery.readyList.push( function() { return f.apply(this, [jQuery]) } );
- }
-
- return this;
- }
- });
- jQuery.extend({
- /*
- * All the code that makes DOM Ready work nicely.
- */
- isReady: false,
- readyList: [],
-
- // Handle when the DOM is ready
- ready: function() {
- // Make sure that the DOM is not already loaded
- if ( !jQuery.isReady ) {
- // Remember that the DOM is ready
- jQuery.isReady = true;
-
- // If there are functions bound, to execute
- if ( jQuery.readyList ) {
- // Execute all of them
- jQuery.each( jQuery.readyList, function(){
- this.apply( document );
- });
-
- // Reset the list of functions
- jQuery.readyList = null;
- }
- // Remove event lisenter to avoid memory leak
- if ( jQuery.browser.mozilla || jQuery.browser.opera )
- document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
- }
- }
- });
- new function(){
- /**
- * Bind a function to the scroll event of each matched element.
- *
- * @example $("p").scroll( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onscroll="alert('Hello');">Hello</p>
- *
- * @name scroll
- * @type jQuery
- * @param Function fn A function to bind to the scroll event on each of the matched elements.
- * @cat Events
- */
- /**
- * Bind a function to the submit event of each matched element.
- *
- * @example $("#myform").submit( function() {
- * return $("input", this).val().length > 0;
- * } );
- * @before <form id="myform"><input /></form>
- * @desc Prevents the form submission when the input has no value entered.
- *
- * @name submit
- * @type jQuery
- * @param Function fn A function to bind to the submit event on each of the matched elements.
- * @cat Events
- */
- /**
- * Trigger the submit event of each matched element. This causes all of the functions
- * that have been bound to thet submit event to be executed.
- *
- * Note: This does not execute the submit method of the form element! If you need to
- * submit the form via code, you have to use the DOM method, eg. $("form")[0].submit();
- *
- * @example $("form").submit();
- * @desc Triggers all submit events registered for forms, but does not submit the form
- *
- * @name submit
- * @type jQuery
- * @cat Events
- */
- /**
- * Bind a function to the focus event of each matched element.
- *
- * @example $("p").focus( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onfocus="alert('Hello');">Hello</p>
- *
- * @name focus
- * @type jQuery
- * @param Function fn A function to bind to the focus event on each of the matched elements.
- * @cat Events
- */
- /**
- * Trigger the focus event of each matched element. This causes all of the functions
- * that have been bound to thet focus event to be executed.
- *
- * Note: This does not execute the focus method of the underlying elements! If you need to
- * focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus();
- *
- * @example $("p").focus();
- * @before <p onfocus="alert('Hello');">Hello</p>
- * @result alert('Hello');
- *
- * @name focus
- * @type jQuery
- * @cat Events
- */
- /**
- * Bind a function to the keydown event of each matched element.
- *
- * @example $("p").keydown( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onkeydown="alert('Hello');">Hello</p>
- *
- * @name keydown
- * @type jQuery
- * @param Function fn A function to bind to the keydown event on each of the matched elements.
- * @cat Events
- */
- /**
- * Bind a function to the dblclick event of each matched element.
- *
- * @example $("p").dblclick( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p ondblclick="alert('Hello');">Hello</p>
- *
- * @name dblclick
- * @type jQuery
- * @param Function fn A function to bind to the dblclick event on each of the matched elements.
- * @cat Events
- */
- /**
- * Bind a function to the keypress event of each matched element.
- *
- * @example $("p").keypress( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onkeypress="alert('Hello');">Hello</p>
- *
- * @name keypress
- * @type jQuery
- * @param Function fn A function to bind to the keypress event on each of the matched elements.
- * @cat Events
- */
- /**
- * Bind a function to the error event of each matched element.
- *
- * @example $("p").error( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onerror="alert('Hello');">Hello</p>
- *
- * @name error
- * @type jQuery
- * @param Function fn A function to bind to the error event on each of the matched elements.
- * @cat Events
- */
- /**
- * Bind a function to the blur event of each matched element.
- *
- * @example $("p").blur( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onblur="alert('Hello');">Hello</p>
- *
- * @name blur
- * @type jQuery
- * @param Function fn A function to bind to the blur event on each of the matched elements.
- * @cat Events
- */
- /**
- * Trigger the blur event of each matched element. This causes all of the functions
- * that have been bound to thet blur event to be executed.
- *
- * Note: This does not execute the blur method of the underlying elements! If you need to
- * blur an element via code, you have to use the DOM method, eg. $("#myinput")[0].blur();
- *
- * @example $("p").blur();
- * @before <p onblur="alert('Hello');">Hello</p>
- * @result alert('Hello');
- *
- * @name blur
- * @type jQuery
- * @cat Events
- */
- /**
- * Bind a function to the load event of each matched element.
- *
- * @example $("p").load( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onload="alert('Hello');">Hello</p>
- *
- * @name load
- * @type jQuery
- * @param Function fn A function to bind to the load event on each of the matched elements.
- * @cat Events
- */
- /**
- * Bind a function to the select event of each matched element.
- *
- * @example $("p").select( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onselect="alert('Hello');">Hello</p>
- *
- * @name select
- * @type jQuery
- * @param Function fn A function to bind to the select event on each of the matched elements.
- * @cat Events
- */
- /**
- * Trigger the select event of each matched element. This causes all of the functions
- * that have been bound to thet select event to be executed.
- *
- * @example $("p").select();
- * @before <p onselect="alert('Hello');">Hello</p>
- * @result alert('Hello');
- *
- * @name select
- * @type jQuery
- * @cat Events
- */
- /**
- * Bind a function to the mouseup event of each matched element.
- *
- * @example $("p").mouseup( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onmouseup="alert('Hello');">Hello</p>
- *
- * @name mouseup
- * @type jQuery
- * @param Function fn A function to bind to the mouseup event on each of the matched elements.
- * @cat Events
- */
- /**
- * Bind a function to the unload event of each matched element.
- *
- * @example $("p").unload( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onunload="alert('Hello');">Hello</p>
- *
- * @name unload
- * @type jQuery
- * @param Function fn A function to bind to the unload event on each of the matched elements.
- * @cat Events
- */
- /**
- * Bind a function to the change event of each matched element.
- *
- * @example $("p").change( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onchange="alert('Hello');">Hello</p>
- *
- * @name change
- * @type jQuery
- * @param Function fn A function to bind to the change event on each of the matched elements.
- * @cat Events
- */
- /**
- * Bind a function to the mouseout event of each matched element.
- *
- * @example $("p").mouseout( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onmouseout="alert('Hello');">Hello</p>
- *
- * @name mouseout
- * @type jQuery
- * @param Function fn A function to bind to the mouseout event on each of the matched elements.
- * @cat Events
- */
- /**
- * Bind a function to the keyup event of each matched element.
- *
- * @example $("p").keyup( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onkeyup="alert('Hello');">Hello</p>
- *
- * @name keyup
- * @type jQuery
- * @param Function fn A function to bind to the keyup event on each of the matched elements.
- * @cat Events
- */
- /**
- * Bind a function to the click event of each matched element.
- *
- * @example $("p").click( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onclick="alert('Hello');">Hello</p>
- *
- * @name click
- * @type jQuery
- * @param Function fn A function to bind to the click event on each of the matched elements.
- * @cat Events
- */
- /**
- * Trigger the click event of each matched element. This causes all of the functions
- * that have been bound to thet click event to be executed.
- *
- * @example $("p").click();
- * @before <p onclick="alert('Hello');">Hello</p>
- * @result alert('Hello');
- *
- * @name click
- * @type jQuery
- * @cat Events
- */
- /**
- * Bind a function to the resize event of each matched element.
- *
- * @example $("p").resize( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onresize="alert('Hello');">Hello</p>
- *
- * @name resize
- * @type jQuery
- * @param Function fn A function to bind to the resize event on each of the matched elements.
- * @cat Events
- */
- /**
- * Bind a function to the mousemove event of each matched element.
- *
- * @example $("p").mousemove( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onmousemove="alert('Hello');">Hello</p>
- *
- * @name mousemove
- * @type jQuery
- * @param Function fn A function to bind to the mousemove event on each of the matched elements.
- * @cat Events
- */
- /**
- * Bind a function to the mousedown event of each matched element.
- *
- * @example $("p").mousedown( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onmousedown="alert('Hello');">Hello</p>
- *
- * @name mousedown
- * @type jQuery
- * @param Function fn A function to bind to the mousedown event on each of the matched elements.
- * @cat Events
- */
-
- /**
- * Bind a function to the mouseover event of each matched element.
- *
- * @example $("p").mouseover( function() { alert("Hello"); } );
- * @before <p>Hello</p>
- * @result <p onmouseover="alert('Hello');">Hello</p>
- *
- * @name mouseover
- * @type jQuery
- * @param Function fn A function to bind to the mousedown event on each of the matched elements.
- * @cat Events
- */
- jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
- "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
- "submit,keydown,keypress,keyup,error").split(","), function(i,o){
-
- // Handle event binding
- jQuery.fn[o] = function(f){
- return f ? this.bind(o, f) : this.trigger(o);
- };
-
- });
-
- // If Mozilla is used
- if ( jQuery.browser.mozilla || jQuery.browser.opera )
- // Use the handy event callback
- document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
-
- // If IE is used, use the excellent hack by Matthias Miller
- // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
- else if ( jQuery.browser.msie ) {
-
- // Only works if you document.write() it
- document.write("<scr" + "ipt id=__ie_init defer=true " +
- "src=//:><\/script>");
-
- // Use the defer script hack
- var script = document.getElementById("__ie_init");
-
- // script does not exist if jQuery is loaded dynamically
- if ( script )
- script.onreadystatechange = function() {
- if ( this.readyState != "complete" ) return;
- this.parentNode.removeChild( this );
- jQuery.ready();
- };
-
- // Clear from memory
- script = null;
-
- // If Safari is used
- } else if ( jQuery.browser.safari )
- // Continually check to see if the document.readyState is valid
- jQuery.safariTimer = setInterval(function(){
- // loaded and complete are both valid states
- if ( document.readyState == "loaded" ||
- document.readyState == "complete" ) {
-
- // If either one are found, remove the timer
- clearInterval( jQuery.safariTimer );
- jQuery.safariTimer = null;
-
- // and execute any waiting functions
- jQuery.ready();
- }
- }, 10);
- // A fallback to window.onload, that will always work
- jQuery.event.add( window, "load", jQuery.ready );
-
- };
- // Clean up after IE to avoid memory leaks
- if (jQuery.browser.msie)
- jQuery(window).one("unload", function() {
- var global = jQuery.event.global;
- for ( var type in global ) {
- var els = global[type], i = els.length;
- if ( i && type != 'unload' )
- do
- jQuery.event.remove(els[i-1], type);
- while (--i);
- }
- });
- jQuery.fn.extend({
- /**
- * Displays each of the set of matched elements if they are hidden.
- *
- * @example $("p").show()
- * @before <p style="display: none">Hello</p>
- * @result [ <p style="display: block">Hello</p> ]
- *
- * @name show
- * @type jQuery
- * @cat Effects
- */
-
- /**
- * Show all matched elements using a graceful animation and firing an
- * optional callback after completion.
- *
- * The height, width, and opacity of each of the matched elements
- * are changed dynamically according to the specified speed.
- *
- * @example $("p").show("slow");
- *
- * @example $("p").show("slow",function(){
- * alert("Animation Done.");
- * });
- *
- * @name show
- * @type jQuery
- * @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).
- * @param Function callback (optional) A function to be executed whenever the animation completes.
- * @cat Effects
- * @see hide(String|Number,Function)
- */
- show: function(speed,callback){
- var hidden = this.filter(":hidden");
- speed ?
- hidden.animate({
- height: "show", width: "show", opacity: "show"
- }, speed, callback) :
-
- hidden.each(function(){
- this.style.display = this.oldblock ? this.oldblock : "";
- if ( jQuery.css(this,"display") == "none" )
- this.style.display = "block";
- });
- return this;
- },
-
- /**
- * Hides each of the set of matched elements if they are shown.
- *
- * @example $("p").hide()
- * @before <p>Hello</p>
- * @result [ <p style="display: none">Hello</p> ]
- *
- * @name hide
- * @type jQuery
- * @cat Effects
- */
-
- /**
- * Hide all matched elements using a graceful animation and firing an
- * optional callback after completion.
- *
- * The height, width, and opacity of each of the matched elements
- * are changed dynamically according to the specified speed.
- *
- * @example $("p").hide("slow");
- *
- * @example $("p").hide("slow",function(){
- * alert("Animation Done.");
- * });
- *
- * @name hide
- * @type jQuery
- * @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).
- * @param Function callback (optional) A function to be executed whenever the animation completes.
- * @cat Effects
- * @see show(String|Number,Function)
- */
- hide: function(speed,callback){
- var visible = this.filter(":visible");
- speed ?
- visible.animate({
- height: "hide", width: "hide", opacity: "hide"
- }, speed, callback) :
-
- visible.each(function(){
- this.oldblock = this.oldblock || jQuery.css(this,"display");
- if ( this.oldblock == "none" )
- this.oldblock = "block";
- this.style.display = "none";
- });
- return this;
- },
- // Save the old toggle function
- _toggle: jQuery.fn.toggle,
-
- /**
- * Toggles each of the set of matched elements. If they are shown,
- * toggle makes them hidden. If they are hidden, toggle
- * makes them shown.
- *
- * @example $("p").toggle()
- * @before <p>Hello</p><p style="display: none">Hello Again</p>
- * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
- *
- * @name toggle
- * @type jQuery
- * @cat Effects
- */
- toggle: function( fn, fn2 ){
- var args = arguments;
- return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
- this._toggle( fn, fn2 ) :
- this.each(function(){
- jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]
- .apply( jQuery(this), args );
- });
- },
-
- /**
- * Reveal all matched elements by adjusting their height and firing an
- * optional callback after completion.
- *
- * Only the height is adjusted for this animation, causing all matched
- * elements to be revealed in a "sliding" manner.
- *
- * @example $("p").slideDown("slow");
- *
- * @example $("p").slideDown("slow",function(){
- * alert("Animation Done.");
- * });
- *
- * @name slideDown
- * @type jQuery
- * @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).
- * @param Function callback (optional) A function to be executed whenever the animation completes.
- * @cat Effects
- * @see slideUp(String|Number,Function)
- * @see slideToggle(String|Number,Function)
- */
- slideDown: function(speed,callback){
- return this.animate({height: "show"}, speed, callback);
- },
-
- /**
- * Hide all matched elements by adjusting their height and firing an
- * optional callback after completion.
- *
- * Only the height is adjusted for this animation, causing all matched
- * elements to be hidden in a "sliding" manner.
- *
- * @example $("p").slideUp("slow");
- *
- * @example $("p").slideUp("slow",function(){
- * alert("Animation Done.");
- * });
- *
- * @name slideUp
- * @type jQuery
- * @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).
- * @param Function callback (optional) A function to be executed whenever the animation completes.
- * @cat Effects
- * @see slideDown(String|Number,Function)
- * @see slideToggle(String|Number,Function)
- */
- slideUp: function(speed,callback){
- return this.animate({height: "hide"}, speed, callback);
- },
- /**
- * Toggle the visibility of all matched elements by adjusting their height and firing an
- * optional callback after completion.
- *
- * Only the height is adjusted for this animation, causing all matched
- * elements to be hidden in a "sliding" manner.
- *
- * @example $("p").slideToggle("slow");
- *
- * @example $("p").slideToggle("slow",function(){
- * alert("Animation Done.");
- * });
- *
- * @name slideToggle
- * @type jQuery
- * @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).
- * @param Function callback (optional) A function to be executed whenever the animation completes.
- * @cat Effects
- * @see slideDown(String|Number,Function)
- * @see slideUp(String|Number,Function)
- */
- slideToggle: function(speed, callback){
- return this.each(function(){
- var state = jQuery(this).is(":hidden") ? "show" : "hide";
- jQuery(this).animate({height: state}, speed, callback);
- });
- },
-
- /**
- * Fade in all matched elements by adjusting their opacity and firing an
- * optional callback after completion.
- *
- * Only the opacity is adjusted for this animation, meaning that
- * all of the matched elements should already have some form of height
- * and width associated with them.
- *
- * @example $("p").fadeIn("slow");
- *
- * @example $("p").fadeIn("slow",function(){
- * alert("Animation Done.");
- * });
- *
- * @name fadeIn
- * @type jQuery
- * @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).
- * @param Function callback (optional) A function to be executed whenever the animation completes.
- * @cat Effects
- * @see fadeOut(String|Number,Function)
- * @see fadeTo(String|Number,Number,Function)
- */
- fadeIn: function(speed, callback){
- return this.animate({opacity: "show"}, speed, callback);
- },
-
- /**
- * Fade out all matched elements by adjusting their opacity and firing an
- * optional callback after completion.
- *
- * Only the opacity is adjusted for this animation, meaning that
- * all of the matched elements should already have some form of height
- * and width associated with them.
- *
- * @example $("p").fadeOut("slow");
- *
- * @example $("p").fadeOut("slow",function(){
- * alert("Animation Done.");
- * });
- *
- * @name fadeOut
- * @type jQuery
- * @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).
- * @param Function callback (optional) A function to be executed whenever the animation completes.
- * @cat Effects
- * @see fadeIn(String|Number,Function)
- * @see fadeTo(String|Number,Number,Function)
- */
- fadeOut: function(speed, callback){
- return this.animate({opacity: "hide"}, speed, callback);
- },
-
- /**
- * Fade the opacity of all matched elements to a specified opacity and firing an
- * optional callback after completion.
- *
- * Only the opacity is adjusted for this animation, meaning that
- * all of the matched elements should already have some form of height
- * and width associated with them.
- *
- * @example $("p").fadeTo("slow", 0.5);
- *
- * @example $("p").fadeTo("slow", 0.5, function(){
- * alert("Animation Done.");
- * });
- *
- * @name fadeTo
- * @type jQuery
- * @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).
- * @param Number opacity The opacity to fade to (a number from 0 to 1).
- * @param Function callback (optional) A function to be executed whenever the animation completes.
- * @cat Effects
- * @see fadeIn(String|Number,Function)
- * @see fadeOut(String|Number,Function)
- */
- fadeTo: function(speed,to,callback){
- return this.animate({opacity: to}, speed, callback);
- },
-
- /**
- * A function for making your own, custom, animations. The key aspect of
- * this function is the object of style properties that will be animated,
- * and to what end. Each key within the object represents a style property
- * that will also be animated (for example: "height", "top", or "opacity").
- *
- * The value associated with the key represents to what end the property
- * will be animated. If a number is provided as the value, then the style
- * property will be transitioned from its current state to that new number.
- * Oterwise if the string "hide", "show", or "toggle" is provided, a default
- * animation will be constructed for that property.
- *
- * @example $("p").animate({
- * height: 'toggle', opacity: 'toggle'
- * }, "slow");
- *
- * @example $("p").animate({
- * left: 50, opacity: 'show'
- * }, 500);
- *
- * @example $("p").animate({
- * opacity: 'show'
- * }, "slow", "easein");
- * @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).
- *
- * @name animate
- * @type jQuery
- * @param Hash params A set of style attributes that you wish to animate, and to what end.
- * @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).
- * @param String easing (optional) The name of the easing effect that you want to use (Plugin Required).
- * @param Function callback (optional) A function to be executed whenever the animation completes.
- * @cat Effects
- */
- animate: function( prop, speed, easing, callback ) {
- return this.queue(function(){
-
- this.curAnim = jQuery.extend({}, prop);
- var opt = jQuery.speed(speed, easing, callback);
-
- for ( var p in prop ) {
- var e = new jQuery.fx( this, opt, p );
- if ( prop[p].constructor == Number )
- e.custom( e.cur(), prop[p] );
- else
- e[ prop[p] ]( prop );
- }
-
- });
- },
-
- /**
- *
- * @private
- */
- queue: function(type,fn){
- if ( !fn ) {
- fn = type;
- type = "fx";
- }
-
- return this.each(function(){
- if ( !this.queue )
- this.queue = {};
-
- if ( !this.queue[type] )
- this.queue[type] = [];
-
- this.queue[type].push( fn );
-
- if ( this.queue[type].length == 1 )
- fn.apply(this);
- });
- }
- });
- jQuery.extend({
-
- speed: function(speed, easing, fn) {
- var opt = speed && speed.constructor == Object ? speed : {
- complete: fn || !fn && easing ||
- jQuery.isFunction( speed ) && speed,
- duration: speed,
- easing: fn && easing || easing && easing.constructor != Function && easing
- };
- opt.duration = (opt.duration && opt.duration.constructor == Number ?
- opt.duration :
- { slow: 600, fast: 200 }[opt.duration]) || 400;
-
- // Queueing
- opt.old = opt.complete;
- opt.complete = function(){
- jQuery.dequeue(this, "fx");
- if ( jQuery.isFunction( opt.old ) )
- opt.old.apply( this );
- };
-
- return opt;
- },
-
- easing: {},
-
- queue: {},
-
- dequeue: function(elem,type){
- type = type || "fx";
-
- if ( elem.queue && elem.queue[type] ) {
- // Remove self
- elem.queue[type].shift();
-
- // Get next function
- var f = elem.queue[type][0];
-
- if ( f ) f.apply( elem );
- }
- },
- /*
- * I originally wrote fx() as a clone of moo.fx and in the process
- * of making it small in size the code became illegible to sane
- * people. You've been warned.
- */
-
- fx: function( elem, options, prop ){
- var z = this;
- // The styles
- var y = elem.style;
-
- // Store display property
- var oldDisplay = jQuery.css(elem, "display");
- // Set display property to block for animation
- y.display = "block";
- // Make sure that nothing sneaks out
- y.overflow = "hidden";
- // Simple function for setting a style value
- z.a = function(){
- if ( options.step )
- options.step.apply( elem, [ z.now ] );
- if ( prop == "opacity" )
- jQuery.attr(y, "opacity", z.now); // Let attr handle opacity
- else if ( parseInt(z.now) ) // My hate for IE will never die
- y[prop] = parseInt(z.now) + "px";
- };
- // Figure out the maximum number to run to
- z.max = function(){
- return parseFloat( jQuery.css(elem,prop) );
- };
- // Get the current size
- z.cur = function(){
- var r = parseFloat( jQuery.curCSS(elem, prop) );
- return r && r > -10000 ? r : z.max();
- };
- // Start an animation from one number to another
- z.custom = function(from,to){
- z.startTime = (new Date()).getTime();
- z.now = from;
- z.a();
- z.timer = setInterval(function(){
- z.step(from, to);
- }, 13);
- };
- // Simple 'show' function
- z.show = function(){
- if ( !elem.orig ) elem.orig = {};
- // Remember where we started, so that we can go back to it later
- elem.orig[prop] = this.cur();
- options.show = true;
- // Begin the animation
- z.custom(0, elem.orig[prop]);
- // Stupid IE, look what you made me do
- if ( prop != "opacity" )
- y[prop] = "1px";
- };
- // Simple 'hide' function
- z.hide = function(){
- if ( !elem.orig ) elem.orig = {};
- // Remember where we started, so that we can go back to it later
- elem.orig[prop] = this.cur();
- options.hide = true;
- // Begin the animation
- z.custom(elem.orig[prop], 0);
- };
-
- //Simple 'toggle' function
- z.toggle = function() {
- if ( !elem.orig ) elem.orig = {};
- // Remember where we started, so that we can go back to it later
- elem.orig[prop] = this.cur();
- if(oldDisplay == "none") {
- options.show = true;
-
- // Stupid IE, look what you made me do
- if ( prop != "opacity" )
- y[prop] = "1px";
- // Begin the animation
- z.custom(0, elem.orig[prop]);
- } else {
- options.hide = true;
- // Begin the animation
- z.custom(elem.orig[prop], 0);
- }
- };
- // Each step of an animation
- z.step = function(firstNum, lastNum){
- var t = (new Date()).getTime();
- if (t > options.duration + z.startTime) {
- // Stop the timer
- clearInterval(z.timer);
- z.timer = null;
- z.now = lastNum;
- z.a();
- if (elem.curAnim) elem.curAnim[ prop ] = true;
- var done = true;
- for ( var i in elem.curAnim )
- if ( elem.curAnim[i] !== true )
- done = false;
- if ( done ) {
- // Reset the overflow
- y.overflow = "";
-
- // Reset the display
- y.display = oldDisplay;
- if (jQuery.css(elem, "display") == "none")
- y.display = "block";
- // Hide the element if the "hide" operation was done
- if ( options.hide )
- y.display = "none";
- // Reset the properties, if the item has been hidden or shown
- if ( options.hide || options.show )
- for ( var p in elem.curAnim )
- if (p == "opacity")
- jQuery.attr(y, p, elem.orig[p]);
- else
- y[p] = "";
- }
- // If a callback was provided, execute it
- if ( done && jQuery.isFunction( options.complete ) )
- // Execute the complete function
- options.complete.apply( elem );
- } else {
- var n = t - this.startTime;
- // Figure out where in the animation we are and set the number
- var p = n / options.duration;
-
- // If the easing function exists, then use it
- z.now = options.easing && jQuery.easing[options.easing] ?
- jQuery.easing[options.easing](p, n, firstNum, (lastNum-firstNum), options.duration) :
- // else use default linear easing
- ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
- // Perform the next step of the animation
- z.a();
- }
- };
-
- }
- });
- jQuery.fn.extend({
- /**
- * Load HTML from a remote file and inject it into the DOM, only if it's
- * been modified by the server.
- *
- * @example $("#feeds").loadIfModified("feeds.html");
- * @before <div id="feeds"></div>
- * @result <div id="feeds"><b>45</b> feeds found.</div>
- *
- * @name loadIfModified
- * @type jQuery
- * @param String url The URL of the HTML file to load.
- * @param Map params (optional) Key/value pairs that will be sent to the server.
- * @param Function callback (optional) A function to be executed whenever the data is loaded (parameters: responseText, status and response itself).
- * @cat Ajax
- */
- loadIfModified: function( url, params, callback ) {
- this.load( url, params, callback, 1 );
- },
- /**
- * Load HTML from a remote file and inject it into the DOM.
- *
- * Note: Avoid to use this to load scripts, instead use $.getScript.
- * IE strips script tags when there aren't any other characters in front of it.
- *
- * @example $("#feeds").load("feeds.html");
- * @before <div id="feeds"></div>
- * @result <div id="feeds"><b>45</b> feeds found.</div>
- *
- * @example $("#feeds").load("feeds.html",
- * {limit: 25},
- * function() { alert("The last 25 entries in the feed have been loaded"); }
- * );
- * @desc Same as above, but with an additional parameter
- * and a callback that is executed when the data was loaded.
- *
- * @name load
- * @type jQuery
- * @param String url The URL of the HTML file to load.
- * @param Object params (optional) A set of key/value pairs that will be sent as data to the server.
- * @param Function callback (optional) A function to be executed whenever the data is loaded (parameters: responseText, status and response itself).
- * @cat Ajax
- */
- load: function( url, params, callback, ifModified ) {
- if ( jQuery.isFunction( url ) )
- return this.bind("load", url);
- callback = callback || function(){};
- // Default to a GET request
- var type = "GET";
- // If the second parameter was provided
- if ( params )
- // If it's a function
- if ( jQuery.isFunction( params ) ) {
- // We assume that it's the callback
- callback = params;
- params = null;
- // Otherwise, build a param string
- } else {
- params = jQuery.param( params );
- type = "POST";
- }
- var self = this;
- // Request the remote document
- jQuery.ajax({
- url: url,
- type: type,
- data: params,
- ifModified: ifModified,
- complete: function(res, status){
- if ( status == "success" || !ifModified && status == "notmodified" )
- // Inject the HTML into all the matched elements
- self.attr("innerHTML", res.responseText)
- // Execute all the scripts inside of the newly-injected HTML
- .evalScripts()
- // Execute callback
- .each( callback, [res.responseText, status, res] );
- else
- callback.apply( self, [res.responseText, status, res] );
- }
- });
- return this;
- },
- /**
- * Serializes a set of input elements into a string of data.
- * This will serialize all given elements.
- *
- * A serialization similar to the form submit of a browser is
- * provided by the form plugin. It also takes multiple-selects
- * into account, while this method recognizes only a single option.
- *
- * @example $("input[@type=text]").serialize();
- * @before <input type='text' name='name' value='John'/>
- * <input type='text' name='location' value='Boston'/>
- * @after name=John&location=Boston
- * @desc Serialize a selection of input elements to a string
- *
- * @name serialize
- * @type String
- * @cat Ajax
- */
- serialize: function() {
- return jQuery.param( this );
- },
- /**
- * Evaluate all script tags inside this jQuery. If they have a src attribute,
- * the script is loaded, otherwise it's content is evaluated.
- *
- * @name evalScripts
- * @type jQuery
- * @private
- * @cat Ajax
- */
- evalScripts: function() {
- return this.find("script").each(function(){
- if ( this.src )
- jQuery.getScript( this.src );
- else
- jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" );
- }).end();
- }
- });
- // If IE is used, create a wrapper for the XMLHttpRequest object
- if ( !window.XMLHttpRequest )
- XMLHttpRequest = function(){
- return new ActiveXObject("Microsoft.XMLHTTP");
- };
- // Attach a bunch of functions for handling common AJAX events
- /**
- * Attach a function to be executed whenever an AJAX request begins
- * and there is none already active.
- *
- * @example $("#loading").ajaxStart(function(){
- * $(this).show();
- * });
- * @desc Show a loading message whenever an AJAX request starts
- * (and none is already active).
- *
- * @name ajaxStart
- * @type jQuery
- * @param Function callback The function to execute.
- * @cat Ajax
- */
- /**
- * Attach a function to be executed whenever all AJAX requests have ended.
- *
- * @example $("#loading").ajaxStop(function(){
- * $(this).hide();
- * });
- * @desc Hide a loading message after all the AJAX requests have stopped.
- *
- * @name ajaxStop
- * @type jQuery
- * @param Function callback The function to execute.
- * @cat Ajax
- */
- /**
- * Attach a function to be executed whenever an AJAX request completes.
- *
- * The XMLHttpRequest and settings used for that request are passed
- * as arguments to the callback.
- *
- * @example $("#msg").ajaxComplete(function(request, settings){
- * $(this).append("<li>Request Complete.</li>");
- * });
- * @desc Show a message when an AJAX request completes.
- *
- * @name ajaxComplete
- * @type jQuery
- * @param Function callback The function to execute.
- * @cat Ajax
- */
- /**
- * Attach a function to be executed whenever an AJAX request completes
- * successfully.
- *
- * The XMLHttpRequest and settings used for that request are passed
- * as arguments to the callback.
- *
- * @example $("#msg").ajaxSuccess(function(request, settings){
- * $(this).append("<li>Successful Request!</li>");
- * });
- * @desc Show a message when an AJAX request completes successfully.
- *
- * @name ajaxSuccess
- * @type jQuery
- * @param Function callback The function to execute.
- * @cat Ajax
- */
- /**
- * Attach a function to be executed whenever an AJAX request fails.
- *
- * The XMLHttpRequest and settings used for that request are passed
- * as arguments to the callback. A third argument, an exception object,
- * is passed if an exception occured while processing the request.
- *
- * @example $("#msg").ajaxError(function(request, settings){
- * $(this).append("<li>Error requesting page " + settings.url + "</li>");
- * });
- * @desc Show a message when an AJAX request fails.
- *
- * @name ajaxError
- * @type jQuery
- * @param Function callback The function to execute.
- * @cat Ajax
- */
-
- /**
- * Attach a function to be executed before an AJAX request is sent.
- *
- * The XMLHttpRequest and settings used for that request are passed
- * as arguments to the callback.
- *
- * @example $("#msg").ajaxSend(function(request, settings){
- * $(this).append("<li>Starting request at " + settings.url + "</li>");
- * });
- * @desc Show a message before an AJAX request is sent.
- *
- * @name ajaxSend
- * @type jQuery
- * @param Function callback The function to execute.
- * @cat Ajax
- */
- jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","), function(i,o){
- jQuery.fn[o] = function(f){
- return this.bind(o, f);
- };
- });
- jQuery.extend({
- /**
- * Load a remote page using an HTTP GET request.
- *
- * @example $.get("test.cgi");
- *
- * @example $.get("test.cgi", { name: "John", time: "2pm" } );
- *
- * @example $.get("test.cgi", function(data){
- * alert("Data Loaded: " + data);
- * });
- *
- * @example $.get("test.cgi",
- * { name: "John", time: "2pm" },
- * function(data){
- * alert("Data Loaded: " + data);
- * }
- * );
- *
- * @name $.get
- * @type XMLHttpRequest
- * @param String url The URL of the page to load.
- * @param Map params (optional) Key/value pairs that will be sent to the server.
- * @param Function callback (optional) A function to be executed whenever the data is loaded.
- * @cat Ajax
- */
- get: function( url, data, callback, type, ifModified ) {
- // shift arguments if data argument was ommited
- if ( jQuery.isFunction( data ) ) {
- callback = data;
- data = null;
- }
-
- return jQuery.ajax({
- url: url,
- data: data,
- success: callback,
- dataType: type,
- ifModified: ifModified
- });
- },
- /**
- * Load a remote page using an HTTP GET request, only if it hasn't
- * been modified since it was last retrieved.
- *
- * @example $.getIfModified("test.html");
- *
- * @example $.getIfModified("test.html", { name: "John", time: "2pm" } );
- *
- * @example $.getIfModified("test.cgi", function(data){
- * alert("Data Loaded: " + data);
- * });
- *
- * @example $.getifModified("test.cgi",
- * { name: "John", time: "2pm" },
- * function(data){
- * alert("Data Loaded: " + data);
- * }
- * );
- *
- * @name $.getIfModified
- * @type XMLHttpRequest
- * @param String url The URL of the page to load.
- * @param Map params (optional) Key/value pairs that will be sent to the server.
- * @param Function callback (optional) A function to be executed whenever the data is loaded.
- * @cat Ajax
- */
- getIfModified: function( url, data, callback, type ) {
- return jQuery.get(url, data, callback, type, 1);
- },
- /**
- * Loads, and executes, a remote JavaScript file using an HTTP GET request.
- *
- * Warning: Safari <= 2.0.x is unable to evalulate scripts in a global
- * context synchronously. If you load functions via getScript, make sure
- * to call them after a delay.
- *
- * @example $.getScript("test.js");
- *
- * @example $.getScript("test.js", function(){
- * alert("Script loaded and executed.");
- * });
- *
- * @name $.getScript
- * @type XMLHttpRequest
- * @param String url The URL of the page to load.
- * @param Function callback (optional) A function to be executed whenever the data is loaded.
- * @cat Ajax
- */
- getScript: function( url, callback ) {
- return jQuery.get(url, null, callback, "script");
- },
- /**
- * Load JSON data using an HTTP GET request.
- *
- * @example $.getJSON("test.js", function(json){
- * alert("JSON Data: " + json.users[3].name);
- * });
- *
- * @example $.getJSON("test.js",
- * { name: "John", time: "2pm" },
- * function(json){
- * alert("JSON Data: " + json.users[3].name);
- * }
- * );
- *
- * @name $.getJSON
- * @type XMLHttpRequest
- * @param String url The URL of the page to load.
- * @param Map params (optional) Key/value pairs that will be sent to the server.
- * @param Function callback A function to be executed whenever the data is loaded.
- * @cat Ajax
- */
- getJSON: function( url, data, callback ) {
- return jQuery.get(url, data, callback, "json");
- },
- /**
- * Load a remote page using an HTTP POST request.
- *
- * @example $.post("test.cgi");
- *
- * @example $.post("test.cgi", { name: "John", time: "2pm" } );
- *
- * @example $.post("test.cgi", function(data){
- * alert("Data Loaded: " + data);
- * });
- *
- * @example $.post("test.cgi",
- * { name: "John", time: "2pm" },
- * function(data){
- * alert("Data Loaded: " + data);
- * }
- * );
- *
- * @name $.post
- * @type XMLHttpRequest
- * @param String url The URL of the page to load.
- * @param Map params (optional) Key/value pairs that will be sent to the server.
- * @param Function callback (optional) A function to be executed whenever the data is loaded.
- * @cat Ajax
- */
- post: function( url, data, callback, type ) {
- if ( jQuery.isFunction( data ) ) {
- callback = data;
- data = {};
- }
- return jQuery.ajax({
- type: "POST",
- url: url,
- data: data,
- success: callback,
- dataType: type
- });
- },
- // timeout (ms)
- //timeout: 0,
- /**
- * Set the timeout of all AJAX requests to a specific amount of time.
- * This will make all future AJAX requests timeout after a specified amount
- * of time.
- *
- * Set to null or 0 to disable timeouts (default).
- *
- * You can manually abort requests with the XMLHttpRequest's (returned by
- * all ajax functions) abort() method.
- *
- * Deprecated. Use $.ajaxSetup instead.
- *
- * @example $.ajaxTimeout( 5000 );
- * @desc Make all AJAX requests timeout after 5 seconds.
- *
- * @name $.ajaxTimeout
- * @type undefined
- * @param Number time How long before an AJAX request times out.
- * @cat Ajax
- */
- ajaxTimeout: function( timeout ) {
- jQuery.ajaxSettings.timeout = timeout;
- },
-
- /**
- * Setup global settings for AJAX requests.
- *
- * See $.ajax for a description of all available options.
- *
- * @example $.ajaxSetup( {
- * url: "/xmlhttp/",
- * global: false,
- * type: "POST"
- * } );
- * $.ajax({ data: myData });
- * @desc Sets the defaults for AJAX requests to the url "/xmlhttp/",
- * disables global handlers and uses POST instead of GET. The following
- * AJAX requests then sends some data without having to set anything else.
- *
- * @name $.ajaxSetup
- * @type undefined
- * @param Map settings Key/value pairs to use for all AJAX requests
- * @cat Ajax
- */
- ajaxSetup: function( settings ) {
- jQuery.extend( jQuery.ajaxSettings, settings );
- },
- ajaxSettings: {
- global: true,
- type: "GET",
- timeout: 0,
- contentType: "application/x-www-form-urlencoded",
- processData: true,
- async: true,
- data: null
- },
-
- // Last-Modified header cache for next request
- lastModified: {},
- /**
- * Load a remote page using an HTTP request.
- *
- * This is jQuery's low-level AJAX implementation. See $.get, $.post etc. for
- * higher-level abstractions.
- *
- * $.ajax() returns the XMLHttpRequest that it creates. In most cases you won't
- * need that object to manipulate directly, but it is available if you need to
- * abort the request manually.
- *
- * Note: Make sure the server sends the right mimetype (eg. xml as
- * "text/xml"). Sending the wrong mimetype will get you into serious
- * trouble that jQuery can't solve.
- *
- * Supported datatypes are (see dataType option):
- *
- * "xml": Returns a XML document that can be processed via jQuery.
- *
- * "html": Returns HTML as plain text, included script tags are evaluated.
- *
- * "script": Evaluates the response as Javascript and returns it as plain text.
- *
- * "json": Evaluates the response as JSON and returns a Javascript Object
- *
- * $.ajax() takes one argument, an object of key/value pairs, that are
- * used to initalize and handle the request. These are all the key/values that can
- * be used:
- *
- * (String) url - The URL to request.
- *
- * (String) type - The type of request to make ("POST" or "GET"), default is "GET".
- *
- * (String) dataType - The type of data that you're expecting back from
- * the server. No default: If the server sends xml, the responseXML, otherwise
- * the responseText is passed to the success callback.
- *
- * (Boolean) ifModified - Allow the request to be successful only if the
- * response has changed since the last request. This is done by checking the
- * Last-Modified header. Default value is false, ignoring the header.
- *
- * (Number) timeout - Local timeout to override global timeout, eg. to give a
- * single request a longer timeout while all others timeout after 1 second.
- * See $.ajaxTimeout() for global timeouts.
- *
- * (Boolean) global - Whether to trigger global AJAX event handlers for
- * this request, default is true. Set to false to prevent that global handlers
- * like ajaxStart or ajaxStop are triggered.
- *
- * (Function) error - A function to be called if the request fails. The
- * function gets passed tree arguments: The XMLHttpRequest object, a
- * string describing the type of error that occurred and an optional
- * exception object, if one occured.
- *
- * (Function) success - A function to be called if the request succeeds. The
- * function gets passed one argument: The data returned from the server,
- * formatted according to the 'dataType' parameter.
- *
- * (Function) complete - A function to be called when the request finishes. The
- * function gets passed two arguments: The XMLHttpRequest object and a
- * string describing the type of success of the request.
- *
- * (Object|String) data - Data to be sent to the server. Converted to a query
- * string, if not already a string. Is appended to the url for GET-requests.
- * See processData option to prevent this automatic processing.
- *
- * (String) contentType - When sending data to the server, use this content-type.
- * Default is "application/x-www-form-urlencoded", which is fine for most cases.
- *
- * (Boolean) processData - By default, data passed in to the data option as an object
- * other as string will be processed and transformed into a query string, fitting to
- * the default content-type "application/x-www-form-urlencoded". If you want to send
- * DOMDocuments, set this option to false.
- *
- * (Boolean) async - By default, all requests are sent asynchronous (set to true).
- * If you need synchronous requests, set this option to false.
- *
- * (Function) beforeSend - A pre-callback to set custom headers etc., the
- * XMLHttpRequest is passed as the only argument.
- *
- * @example $.ajax({
- * type: "GET",
- * url: "test.js",
- * dataType: "script"
- * })
- * @desc Load and execute a JavaScript file.
- *
- * @example $.ajax({
- * type: "POST",
- * url: "some.php",
- * data: "name=John&location=Boston",
- * success: function(msg){
- * alert( "Data Saved: " + msg );
- * }
- * });
- * @desc Save some data to the server and notify the user once its complete.
- *
- * @example var html = $.ajax({
- * url: "some.php",
- * async: false
- * }).responseText;
- * @desc Loads data synchronously. Blocks the browser while the requests is active.
- * It is better to block user interaction with others means when synchronization is
- * necessary, instead to block the complete browser.
- *
- * @example var xmlDocument = [create xml document];
- * $.ajax({
- * url: "page.php",
- * processData: false,
- * data: xmlDocument,
- * success: handleResponse
- * });
- * @desc Sends an xml document as data to the server. By setting the processData
- * option to false, the automatic conversion of data to strings is prevented.
- *
- * @name $.ajax
- * @type XMLHttpRequest
- * @param Map properties Key/value pairs to initialize the request with.
- * @cat Ajax
- * @see ajaxSetup(Map)
- */
- ajax: function( s ) {
- // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
- s = jQuery.extend({}, jQuery.ajaxSettings, s);
- // if data available
- if ( s.data ) {
- // convert data if not already a string
- if (s.processData && typeof s.data != "string")
- s.data = jQuery.param(s.data);
- // append data to url for get requests
- if( s.type.toLowerCase() == "get" )
- // "?" + data or "&" + data (in case there are already params)
- s.url += ((s.url.indexOf("?") > -1) ? "&" : "?") + s.data;
- }
- // Watch for a new set of requests
- if ( s.global && ! jQuery.active++ )
- jQuery.event.trigger( "ajaxStart" );
- var requestDone = false;
- // Create the request object
- var xml = new XMLHttpRequest();
- // Open the socket
- xml.open(s.type, s.url, s.async);
- // Set the correct header, if data is being sent
- if ( s.data )
- xml.setRequestHeader("Content-Type", s.contentType);
- // Set the If-Modified-Since header, if ifModified mode.
- if ( s.ifModified )
- xml.setRequestHeader("If-Modified-Since",
- jQuery.lastModified[s.url] || "Thu, 01 Jan 1970 00:00:00 GMT" );
- // Set header so the called script knows that it's an XMLHttpRequest
- xml.setRequestHeader("X-Requested-With", "XMLHttpRequest");
- // Make sure the browser sends the right content length
- if ( xml.overrideMimeType )
- xml.setRequestHeader("Connection", "close");
-
- // Allow custom headers/mimetypes
- if( s.beforeSend )
- s.beforeSend(xml);
-
- if ( s.global )
- jQuery.event.trigger("ajaxSend", [xml, s]);
- // Wait for a response to come back
- var onreadystatechange = function(isTimeout){
- // The transfer is complete and the data is available, or the request timed out
- if ( xml && (xml.readyState == 4 || isTimeout == "timeout") ) {
- requestDone = true;
- var status;
- try {
- status = jQuery.httpSuccess( xml ) && isTimeout != "timeout" ?
- s.ifModified && jQuery.httpNotModified( xml, s.url ) ? "notmodified" : "success" : "error";
- // Make sure that the request was successful or notmodified
- if ( status != "error" ) {
- // Cache Last-Modified header, if ifModified mode.
- var modRes;
- try {
- modRes = xml.getResponseHeader("Last-Modified");
- } catch(e) {} // swallow exception thrown by FF if header is not available
-
- if ( s.ifModified && modRes )
- jQuery.lastModified[s.url] = modRes;
-
- // process the data (runs the xml through httpData regardless of callback)
- var data = jQuery.httpData( xml, s.dataType );
-
- // If a local callback was specified, fire it and pass it the data
- if ( s.success )
- s.success( data, status );
-
- // Fire the global callback
- if( s.global )
- jQuery.event.trigger( "ajaxSuccess", [xml, s] );
- } else
- jQuery.handleError(s, xml, status);
- } catch(e) {
- status = "error";
- jQuery.handleError(s, xml, status, e);
- }
- // The request was completed
- if( s.global )
- jQuery.event.trigger( "ajaxComplete", [xml, s] );
- // Handle the global AJAX counter
- if ( s.global && ! --jQuery.active )
- jQuery.event.trigger( "ajaxStop" );
- // Process result
- if ( s.complete )
- s.complete(xml, status);
- // Stop memory leaks
- xml.onreadystatechange = function(){};
- xml = null;
- }
- };
- xml.onreadystatechange = onreadystatechange;
- // Timeout checker
- if ( s.timeout > 0 )
- setTimeout(function(){
- // Check to see if the request is still happening
- if ( xml ) {
- // Cancel the request
- xml.abort();
- if( !requestDone )
- onreadystatechange( "timeout" );
- }
- }, s.timeout);
-
- // save non-leaking reference
- var xml2 = xml;
- // Send the data
- try {
- xml2.send(s.data);
- } catch(e) {
- jQuery.handleError(s, xml, null, e);
- }
-
- // firefox 1.5 doesn't fire statechange for sync requests
- if ( !s.async )
- onreadystatechange();
-
- // return XMLHttpRequest to allow aborting the request etc.
- return xml2;
- },
- handleError: function( s, xml, status, e ) {
- // If a local callback was specified, fire it
- if ( s.error ) s.error( xml, status, e );
- // Fire the global callback
- if ( s.global )
- jQuery.event.trigger( "ajaxError", [xml, s, e] );
- },
- // Counter for holding the number of active queries
- active: 0,
- // Determines if an XMLHttpRequest was successful or not
- httpSuccess: function( r ) {
- try {
- return !r.status && location.protocol == "file:" ||
- ( r.status >= 200 && r.status < 300 ) || r.status == 304 ||
- jQuery.browser.safari && r.status == undefined;
- } catch(e){}
- return false;
- },
- // Determines if an XMLHttpRequest returns NotModified
- httpNotModified: function( xml, url ) {
- try {
- var xmlRes = xml.getResponseHeader("Last-Modified");
- // Firefox always returns 200. check Last-Modified date
- return xml.status == 304 || xmlRes == jQuery.lastModified[url] ||
- jQuery.browser.safari && xml.status == undefined;
- } catch(e){}
- return false;
- },
- /* Get the data out of an XMLHttpRequest.
- * Return parsed XML if content-type header is "xml" and type is "xml" or omitted,
- * otherwise return plain text.
- * (String) data - The type of data that you're expecting back,
- * (e.g. "xml", "html", "script")
- */
- httpData: function( r, type ) {
- var ct = r.getResponseHeader("content-type");
- var data = !type && ct && ct.indexOf("xml") >= 0;
- data = type == "xml" || data ? r.responseXML : r.responseText;
- // If the type is "script", eval it in global context
- if ( type == "script" )
- jQuery.globalEval( data );
- // Get the JavaScript object, if JSON is used.
- if ( type == "json" )
- eval( "data = " + data );
- // evaluate scripts within html
- if ( type == "html" )
- jQuery("<div>").html(data).evalScripts();
- return data;
- },
- // Serialize an array of form elements or a set of
- // key/values into a query string
- param: function( a ) {
- var s = [];
- // If an array was passed in, assume that it is an array
- // of form elements
- if ( a.constructor == Array || a.jquery )
- // Serialize the form elements
- jQuery.each( a, function(){
- s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) );
- });
- // Otherwise, assume that it's an object of key/value pairs
- else
- // Serialize the key/values
- for ( var j in a )
- // If the value is an array then the key names need to be repeated
- if ( a[j] && a[j].constructor == Array )
- jQuery.each( a[j], function(){
- s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
- });
- else
- s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );
- // Return the resulting serialization
- return s.join("&");
- },
-
- // evalulates a script in global context
- // not reliable for safari
- globalEval: function( data ) {
- if ( window.execScript )
- window.execScript( data );
- else if ( jQuery.browser.safari )
- // safari doesn't provide a synchronous global eval
- window.setTimeout( data, 0 );
- else
- eval.call( window, data );
- }
- });
- }
|