jquery-1.2.6.js 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549
  1. (function(){
  2. /*
  3. * jQuery 1.2.6 - New Wave Javascript
  4. *
  5. * Copyright (c) 2008 John Resig (jquery.com)
  6. * Dual licensed under the MIT (MIT-LICENSE.txt)
  7. * and GPL (GPL-LICENSE.txt) licenses.
  8. *
  9. * $Date: 2009-03-17 18:35:18 $
  10. * $Rev: 5685 $
  11. */
  12. // Map over jQuery in case of overwrite
  13. var _jQuery = window.jQuery,
  14. // Map over the $ in case of overwrite
  15. _$ = window.$;
  16. var jQuery = window.jQuery = window.$ = function( selector, context ) {
  17. // The jQuery object is actually just the init constructor 'enhanced'
  18. return new jQuery.fn.init( selector, context );
  19. };
  20. // A simple way to check for HTML strings or ID strings
  21. // (both of which we optimize for)
  22. var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/,
  23. // Is it a simple selector
  24. isSimple = /^.[^:#\[\.]*$/,
  25. // Will speed up references to undefined, and allows munging its name.
  26. undefined;
  27. jQuery.fn = jQuery.prototype = {
  28. init: function( selector, context ) {
  29. // Make sure that a selection was provided
  30. selector = selector || document;
  31. // Handle $(DOMElement)
  32. if ( selector.nodeType ) {
  33. this[0] = selector;
  34. this.length = 1;
  35. return this;
  36. }
  37. // Handle HTML strings
  38. if ( typeof selector == "string" ) {
  39. // Are we dealing with HTML string or an ID?
  40. var match = quickExpr.exec( selector );
  41. // Verify a match, and that no context was specified for #id
  42. if ( match && (match[1] || !context) ) {
  43. // HANDLE: $(html) -> $(array)
  44. if ( match[1] )
  45. selector = jQuery.clean( [ match[1] ], context );
  46. // HANDLE: $("#id")
  47. else {
  48. var elem = document.getElementById( match[3] );
  49. // Make sure an element was located
  50. if ( elem ){
  51. // Handle the case where IE and Opera return items
  52. // by name instead of ID
  53. if ( elem.id != match[3] )
  54. return jQuery().find( selector );
  55. // Otherwise, we inject the element directly into the jQuery object
  56. return jQuery( elem );
  57. }
  58. selector = [];
  59. }
  60. // HANDLE: $(expr, [context])
  61. // (which is just equivalent to: $(content).find(expr)
  62. } else
  63. return jQuery( context ).find( selector );
  64. // HANDLE: $(function)
  65. // Shortcut for document ready
  66. } else if ( jQuery.isFunction( selector ) )
  67. return jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );
  68. return this.setArray(jQuery.makeArray(selector));
  69. },
  70. // The current version of jQuery being used
  71. jquery: "1.2.6",
  72. // The number of elements contained in the matched element set
  73. size: function() {
  74. return this.length;
  75. },
  76. // The number of elements contained in the matched element set
  77. length: 0,
  78. // Get the Nth element in the matched element set OR
  79. // Get the whole matched element set as a clean array
  80. get: function( num ) {
  81. return num == undefined ?
  82. // Return a 'clean' array
  83. jQuery.makeArray( this ) :
  84. // Return just the object
  85. this[ num ];
  86. },
  87. // Take an array of elements and push it onto the stack
  88. // (returning the new matched element set)
  89. pushStack: function( elems ) {
  90. // Build a new jQuery matched element set
  91. var ret = jQuery( elems );
  92. // Add the old object onto the stack (as a reference)
  93. ret.prevObject = this;
  94. // Return the newly-formed element set
  95. return ret;
  96. },
  97. // Force the current matched set of elements to become
  98. // the specified array of elements (destroying the stack in the process)
  99. // You should use pushStack() in order to do this, but maintain the stack
  100. setArray: function( elems ) {
  101. // Resetting the length to 0, then using the native Array push
  102. // is a super-fast way to populate an object with array-like properties
  103. this.length = 0;
  104. Array.prototype.push.apply( this, elems );
  105. return this;
  106. },
  107. // Execute a callback for every element in the matched set.
  108. // (You can seed the arguments with an array of args, but this is
  109. // only used internally.)
  110. each: function( callback, args ) {
  111. return jQuery.each( this, callback, args );
  112. },
  113. // Determine the position of an element within
  114. // the matched set of elements
  115. index: function( elem ) {
  116. var ret = -1;
  117. // Locate the position of the desired element
  118. return jQuery.inArray(
  119. // If it receives a jQuery object, the first element is used
  120. elem && elem.jquery ? elem[0] : elem
  121. , this );
  122. },
  123. attr: function( name, value, type ) {
  124. var options = name;
  125. // Look for the case where we're accessing a style value
  126. if ( name.constructor == String )
  127. if ( value === undefined )
  128. return this[0] && jQuery[ type || "attr" ]( this[0], name );
  129. else {
  130. options = {};
  131. options[ name ] = value;
  132. }
  133. // Check to see if we're setting style values
  134. return this.each(function(i){
  135. // Set all the styles
  136. for ( name in options )
  137. jQuery.attr(
  138. type ?
  139. this.style :
  140. this,
  141. name, jQuery.prop( this, options[ name ], type, i, name )
  142. );
  143. });
  144. },
  145. css: function( key, value ) {
  146. // ignore negative width and height values
  147. if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
  148. value = undefined;
  149. return this.attr( key, value, "curCSS" );
  150. },
  151. text: function( text ) {
  152. if ( typeof text != "object" && text != null )
  153. return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
  154. var ret = "";
  155. jQuery.each( text || this, function(){
  156. jQuery.each( this.childNodes, function(){
  157. if ( this.nodeType != 8 )
  158. ret += this.nodeType != 1 ?
  159. this.nodeValue :
  160. jQuery.fn.text( [ this ] );
  161. });
  162. });
  163. return ret;
  164. },
  165. wrapAll: function( html ) {
  166. if ( this[0] )
  167. // The elements to wrap the target around
  168. jQuery( html, this[0].ownerDocument )
  169. .clone()
  170. .insertBefore( this[0] )
  171. .map(function(){
  172. var elem = this;
  173. while ( elem.firstChild )
  174. elem = elem.firstChild;
  175. return elem;
  176. })
  177. .append(this);
  178. return this;
  179. },
  180. wrapInner: function( html ) {
  181. return this.each(function(){
  182. jQuery( this ).contents().wrapAll( html );
  183. });
  184. },
  185. wrap: function( html ) {
  186. return this.each(function(){
  187. jQuery( this ).wrapAll( html );
  188. });
  189. },
  190. append: function() {
  191. return this.domManip(arguments, true, false, function(elem){
  192. if (this.nodeType == 1)
  193. this.appendChild( elem );
  194. });
  195. },
  196. prepend: function() {
  197. return this.domManip(arguments, true, true, function(elem){
  198. if (this.nodeType == 1)
  199. this.insertBefore( elem, this.firstChild );
  200. });
  201. },
  202. before: function() {
  203. return this.domManip(arguments, false, false, function(elem){
  204. this.parentNode.insertBefore( elem, this );
  205. });
  206. },
  207. after: function() {
  208. return this.domManip(arguments, false, true, function(elem){
  209. this.parentNode.insertBefore( elem, this.nextSibling );
  210. });
  211. },
  212. end: function() {
  213. return this.prevObject || jQuery( [] );
  214. },
  215. find: function( selector ) {
  216. var elems = jQuery.map(this, function(elem){
  217. return jQuery.find( selector, elem );
  218. });
  219. return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ?
  220. jQuery.unique( elems ) :
  221. elems );
  222. },
  223. clone: function( events ) {
  224. // Do the clone
  225. var ret = this.map(function(){
  226. if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) {
  227. // IE copies events bound via attachEvent when
  228. // using cloneNode. Calling detachEvent on the
  229. // clone will also remove the events from the orignal
  230. // In order to get around this, we use innerHTML.
  231. // Unfortunately, this means some modifications to
  232. // attributes in IE that are actually only stored
  233. // as properties will not be copied (such as the
  234. // the name attribute on an input).
  235. var clone = this.cloneNode(true),
  236. container = document.createElement("div");
  237. container.appendChild(clone);
  238. return jQuery.clean([container.innerHTML])[0];
  239. } else
  240. return this.cloneNode(true);
  241. });
  242. // Need to set the expando to null on the cloned set if it exists
  243. // removeData doesn't work here, IE removes it from the original as well
  244. // this is primarily for IE but the data expando shouldn't be copied over in any browser
  245. var clone = ret.find("*").andSelf().each(function(){
  246. if ( this[ expando ] != undefined )
  247. this[ expando ] = null;
  248. });
  249. // Copy the events from the original to the clone
  250. if ( events === true )
  251. this.find("*").andSelf().each(function(i){
  252. if (this.nodeType == 3)
  253. return;
  254. var events = jQuery.data( this, "events" );
  255. for ( var type in events )
  256. for ( var handler in events[ type ] )
  257. jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
  258. });
  259. // Return the cloned set
  260. return ret;
  261. },
  262. filter: function( selector ) {
  263. return this.pushStack(
  264. jQuery.isFunction( selector ) &&
  265. jQuery.grep(this, function(elem, i){
  266. return selector.call( elem, i );
  267. }) ||
  268. jQuery.multiFilter( selector, this ) );
  269. },
  270. not: function( selector ) {
  271. if ( selector.constructor == String )
  272. // test special case where just one selector is passed in
  273. if ( isSimple.test( selector ) )
  274. return this.pushStack( jQuery.multiFilter( selector, this, true ) );
  275. else
  276. selector = jQuery.multiFilter( selector, this );
  277. var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
  278. return this.filter(function() {
  279. return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
  280. });
  281. },
  282. add: function( selector ) {
  283. return this.pushStack( jQuery.unique( jQuery.merge(
  284. this.get(),
  285. typeof selector == 'string' ?
  286. jQuery( selector ) :
  287. jQuery.makeArray( selector )
  288. )));
  289. },
  290. is: function( selector ) {
  291. return !!selector && jQuery.multiFilter( selector, this ).length > 0;
  292. },
  293. hasClass: function( selector ) {
  294. return this.is( "." + selector );
  295. },
  296. val: function( value ) {
  297. if ( value == undefined ) {
  298. if ( this.length ) {
  299. var elem = this[0];
  300. // We need to handle select boxes special
  301. if ( jQuery.nodeName( elem, "select" ) ) {
  302. var index = elem.selectedIndex,
  303. values = [],
  304. options = elem.options,
  305. one = elem.type == "select-one";
  306. // Nothing was selected
  307. if ( index < 0 )
  308. return null;
  309. // Loop through all the selected options
  310. for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
  311. var option = options[ i ];
  312. if ( option.selected ) {
  313. // Get the specifc value for the option
  314. value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value;
  315. // We don't need an array for one selects
  316. if ( one )
  317. return value;
  318. // Multi-Selects return an array
  319. values.push( value );
  320. }
  321. }
  322. return values;
  323. // Everything else, we just grab the value
  324. } else
  325. return (this[0].value || "").replace(/\r/g, "");
  326. }
  327. return undefined;
  328. }
  329. if( value.constructor == Number )
  330. value += '';
  331. return this.each(function(){
  332. if ( this.nodeType != 1 )
  333. return;
  334. if ( value.constructor == Array && /radio|checkbox/.test( this.type ) )
  335. this.checked = (jQuery.inArray(this.value, value) >= 0 ||
  336. jQuery.inArray(this.name, value) >= 0);
  337. else if ( jQuery.nodeName( this, "select" ) ) {
  338. var values = jQuery.makeArray(value);
  339. jQuery( "option", this ).each(function(){
  340. this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
  341. jQuery.inArray( this.text, values ) >= 0);
  342. });
  343. if ( !values.length )
  344. this.selectedIndex = -1;
  345. } else
  346. this.value = value;
  347. });
  348. },
  349. html: function( value ) {
  350. return value == undefined ?
  351. (this[0] ?
  352. this[0].innerHTML :
  353. null) :
  354. this.empty().append( value );
  355. },
  356. replaceWith: function( value ) {
  357. return this.after( value ).remove();
  358. },
  359. eq: function( i ) {
  360. return this.slice( i, i + 1 );
  361. },
  362. slice: function() {
  363. return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
  364. },
  365. map: function( callback ) {
  366. return this.pushStack( jQuery.map(this, function(elem, i){
  367. return callback.call( elem, i, elem );
  368. }));
  369. },
  370. andSelf: function() {
  371. return this.add( this.prevObject );
  372. },
  373. data: function( key, value ){
  374. var parts = key.split(".");
  375. parts[1] = parts[1] ? "." + parts[1] : "";
  376. if ( value === undefined ) {
  377. var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
  378. if ( data === undefined && this.length )
  379. data = jQuery.data( this[0], key );
  380. return data === undefined && parts[1] ?
  381. this.data( parts[0] ) :
  382. data;
  383. } else
  384. return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){
  385. jQuery.data( this, key, value );
  386. });
  387. },
  388. removeData: function( key ){
  389. return this.each(function(){
  390. jQuery.removeData( this, key );
  391. });
  392. },
  393. domManip: function( args, table, reverse, callback ) {
  394. var clone = this.length > 1, elems;
  395. return this.each(function(){
  396. if ( !elems ) {
  397. elems = jQuery.clean( args, this.ownerDocument );
  398. if ( reverse )
  399. elems.reverse();
  400. }
  401. var obj = this;
  402. if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )
  403. obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") );
  404. var scripts = jQuery( [] );
  405. jQuery.each(elems, function(){
  406. var elem = clone ?
  407. jQuery( this ).clone( true )[0] :
  408. this;
  409. // execute all scripts after the elements have been injected
  410. if ( jQuery.nodeName( elem, "script" ) )
  411. scripts = scripts.add( elem );
  412. else {
  413. // Remove any inner scripts for later evaluation
  414. if ( elem.nodeType == 1 )
  415. scripts = scripts.add( jQuery( "script", elem ).remove() );
  416. // Inject the elements into the document
  417. callback.call( obj, elem );
  418. }
  419. });
  420. scripts.each( evalScript );
  421. });
  422. }
  423. };
  424. // Give the init function the jQuery prototype for later instantiation
  425. jQuery.fn.init.prototype = jQuery.fn;
  426. function evalScript( i, elem ) {
  427. if ( elem.src )
  428. jQuery.ajax({
  429. url: elem.src,
  430. async: false,
  431. dataType: "script"
  432. });
  433. else
  434. jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
  435. if ( elem.parentNode )
  436. elem.parentNode.removeChild( elem );
  437. }
  438. function now(){
  439. return +new Date;
  440. }
  441. jQuery.extend = jQuery.fn.extend = function() {
  442. // copy reference to target object
  443. var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
  444. // Handle a deep copy situation
  445. if ( target.constructor == Boolean ) {
  446. deep = target;
  447. target = arguments[1] || {};
  448. // skip the boolean and the target
  449. i = 2;
  450. }
  451. // Handle case when target is a string or something (possible in deep copy)
  452. if ( typeof target != "object" && typeof target != "function" )
  453. target = {};
  454. // extend jQuery itself if only one argument is passed
  455. if ( length == i ) {
  456. target = this;
  457. --i;
  458. }
  459. for ( ; i < length; i++ )
  460. // Only deal with non-null/undefined values
  461. if ( (options = arguments[ i ]) != null )
  462. // Extend the base object
  463. for ( var name in options ) {
  464. var src = target[ name ], copy = options[ name ];
  465. // Prevent never-ending loop
  466. if ( target === copy )
  467. continue;
  468. // Recurse if we're merging object values
  469. if ( deep && copy && typeof copy == "object" && !copy.nodeType )
  470. target[ name ] = jQuery.extend( deep,
  471. // Never move original objects, clone them
  472. src || ( copy.length != null ? [ ] : { } )
  473. , copy );
  474. // Don't bring in undefined values
  475. else if ( copy !== undefined )
  476. target[ name ] = copy;
  477. }
  478. // Return the modified object
  479. return target;
  480. };
  481. var expando = "jQuery" + now(), uuid = 0, windowData = {},
  482. // exclude the following css properties to add px
  483. exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
  484. // cache defaultView
  485. defaultView = document.defaultView || {};
  486. jQuery.extend({
  487. noConflict: function( deep ) {
  488. window.$ = _$;
  489. if ( deep )
  490. window.jQuery = _jQuery;
  491. return jQuery;
  492. },
  493. // See test/unit/core.js for details concerning this function.
  494. isFunction: function( fn ) {
  495. return !!fn && typeof fn != "string" && !fn.nodeName &&
  496. fn.constructor != Array && /^[\s[]?function/.test( fn + "" );
  497. },
  498. // check if an element is in a (or is an) XML document
  499. isXMLDoc: function( elem ) {
  500. return elem.documentElement && !elem.body ||
  501. elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
  502. },
  503. // Evalulates a script in a global context
  504. globalEval: function( data ) {
  505. data = jQuery.trim( data );
  506. if ( data ) {
  507. // Inspired by code by Andrea Giammarchi
  508. // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
  509. var head = document.getElementsByTagName("head")[0] || document.documentElement,
  510. script = document.createElement("script");
  511. script.type = "text/javascript";
  512. if ( jQuery.browser.msie )
  513. script.text = data;
  514. else
  515. script.appendChild( document.createTextNode( data ) );
  516. // Use insertBefore instead of appendChild to circumvent an IE6 bug.
  517. // This arises when a base node is used (#2709).
  518. head.insertBefore( script, head.firstChild );
  519. head.removeChild( script );
  520. }
  521. },
  522. nodeName: function( elem, name ) {
  523. return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
  524. },
  525. cache: {},
  526. data: function( elem, name, data ) {
  527. elem = elem == window ?
  528. windowData :
  529. elem;
  530. var id = elem[ expando ];
  531. // Compute a unique ID for the element
  532. if ( !id )
  533. id = elem[ expando ] = ++uuid;
  534. // Only generate the data cache if we're
  535. // trying to access or manipulate it
  536. if ( name && !jQuery.cache[ id ] )
  537. jQuery.cache[ id ] = {};
  538. // Prevent overriding the named cache with undefined values
  539. if ( data !== undefined )
  540. jQuery.cache[ id ][ name ] = data;
  541. // Return the named cache data, or the ID for the element
  542. return name ?
  543. jQuery.cache[ id ][ name ] :
  544. id;
  545. },
  546. removeData: function( elem, name ) {
  547. elem = elem == window ?
  548. windowData :
  549. elem;
  550. var id = elem[ expando ];
  551. // If we want to remove a specific section of the element's data
  552. if ( name ) {
  553. if ( jQuery.cache[ id ] ) {
  554. // Remove the section of cache data
  555. delete jQuery.cache[ id ][ name ];
  556. // If we've removed all the data, remove the element's cache
  557. name = "";
  558. for ( name in jQuery.cache[ id ] )
  559. break;
  560. if ( !name )
  561. jQuery.removeData( elem );
  562. }
  563. // Otherwise, we want to remove all of the element's data
  564. } else {
  565. // Clean up the element expando
  566. try {
  567. delete elem[ expando ];
  568. } catch(e){
  569. // IE has trouble directly removing the expando
  570. // but it's ok with using removeAttribute
  571. if ( elem.removeAttribute )
  572. elem.removeAttribute( expando );
  573. }
  574. // Completely remove the data cache
  575. delete jQuery.cache[ id ];
  576. }
  577. },
  578. // args is for internal usage only
  579. each: function( object, callback, args ) {
  580. var name, i = 0, length = object.length;
  581. if ( args ) {
  582. if ( length == undefined ) {
  583. for ( name in object )
  584. if ( callback.apply( object[ name ], args ) === false )
  585. break;
  586. } else
  587. for ( ; i < length; )
  588. if ( callback.apply( object[ i++ ], args ) === false )
  589. break;
  590. // A special, fast, case for the most common use of each
  591. } else {
  592. if ( length == undefined ) {
  593. for ( name in object )
  594. if ( callback.call( object[ name ], name, object[ name ] ) === false )
  595. break;
  596. } else
  597. for ( var value = object[0];
  598. i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
  599. }
  600. return object;
  601. },
  602. prop: function( elem, value, type, i, name ) {
  603. // Handle executable functions
  604. if ( jQuery.isFunction( value ) )
  605. value = value.call( elem, i );
  606. // Handle passing in a number to a CSS property
  607. return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ?
  608. value + "px" :
  609. value;
  610. },
  611. className: {
  612. // internal only, use addClass("class")
  613. add: function( elem, classNames ) {
  614. jQuery.each((classNames || "").split(/\s+/), function(i, className){
  615. if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
  616. elem.className += (elem.className ? " " : "") + className;
  617. });
  618. },
  619. // internal only, use removeClass("class")
  620. remove: function( elem, classNames ) {
  621. if (elem.nodeType == 1)
  622. elem.className = classNames != undefined ?
  623. jQuery.grep(elem.className.split(/\s+/), function(className){
  624. return !jQuery.className.has( classNames, className );
  625. }).join(" ") :
  626. "";
  627. },
  628. // internal only, use hasClass("class")
  629. has: function( elem, className ) {
  630. return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
  631. }
  632. },
  633. // A method for quickly swapping in/out CSS properties to get correct calculations
  634. swap: function( elem, options, callback ) {
  635. var old = {};
  636. // Remember the old values, and insert the new ones
  637. for ( var name in options ) {
  638. old[ name ] = elem.style[ name ];
  639. elem.style[ name ] = options[ name ];
  640. }
  641. callback.call( elem );
  642. // Revert the old values
  643. for ( var name in options )
  644. elem.style[ name ] = old[ name ];
  645. },
  646. css: function( elem, name, force ) {
  647. if ( name == "width" || name == "height" ) {
  648. var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
  649. function getWH() {
  650. val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
  651. var padding = 0, border = 0;
  652. jQuery.each( which, function() {
  653. padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
  654. border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
  655. });
  656. val -= Math.round(padding + border);
  657. }
  658. if ( jQuery(elem).is(":visible") )
  659. getWH();
  660. else
  661. jQuery.swap( elem, props, getWH );
  662. return Math.max(0, val);
  663. }
  664. return jQuery.curCSS( elem, name, force );
  665. },
  666. curCSS: function( elem, name, force ) {
  667. var ret, style = elem.style;
  668. // A helper method for determining if an element's values are broken
  669. function color( elem ) {
  670. if ( !jQuery.browser.safari )
  671. return false;
  672. // defaultView is cached
  673. var ret = defaultView.getComputedStyle( elem, null );
  674. return !ret || ret.getPropertyValue("color") == "";
  675. }
  676. // We need to handle opacity special in IE
  677. if ( name == "opacity" && jQuery.browser.msie ) {
  678. ret = jQuery.attr( style, "opacity" );
  679. return ret == "" ?
  680. "1" :
  681. ret;
  682. }
  683. // Opera sometimes will give the wrong display answer, this fixes it, see #2037
  684. if ( jQuery.browser.opera && name == "display" ) {
  685. var save = style.outline;
  686. style.outline = "0 solid black";
  687. style.outline = save;
  688. }
  689. // Make sure we're using the right name for getting the float value
  690. if ( name.match( /float/i ) )
  691. name = styleFloat;
  692. if ( !force && style && style[ name ] )
  693. ret = style[ name ];
  694. else if ( defaultView.getComputedStyle ) {
  695. // Only "float" is needed here
  696. if ( name.match( /float/i ) )
  697. name = "float";
  698. name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
  699. var computedStyle = defaultView.getComputedStyle( elem, null );
  700. if ( computedStyle && !color( elem ) )
  701. ret = computedStyle.getPropertyValue( name );
  702. // If the element isn't reporting its values properly in Safari
  703. // then some display: none elements are involved
  704. else {
  705. var swap = [], stack = [], a = elem, i = 0;
  706. // Locate all of the parent display: none elements
  707. for ( ; a && color(a); a = a.parentNode )
  708. stack.unshift(a);
  709. // Go through and make them visible, but in reverse
  710. // (It would be better if we knew the exact display type that they had)
  711. for ( ; i < stack.length; i++ )
  712. if ( color( stack[ i ] ) ) {
  713. swap[ i ] = stack[ i ].style.display;
  714. stack[ i ].style.display = "block";
  715. }
  716. // Since we flip the display style, we have to handle that
  717. // one special, otherwise get the value
  718. ret = name == "display" && swap[ stack.length - 1 ] != null ?
  719. "none" :
  720. ( computedStyle && computedStyle.getPropertyValue( name ) ) || "";
  721. // Finally, revert the display styles back
  722. for ( i = 0; i < swap.length; i++ )
  723. if ( swap[ i ] != null )
  724. stack[ i ].style.display = swap[ i ];
  725. }
  726. // We should always get a number back from opacity
  727. if ( name == "opacity" && ret == "" )
  728. ret = "1";
  729. } else if ( elem.currentStyle ) {
  730. var camelCase = name.replace(/\-(\w)/g, function(all, letter){
  731. return letter.toUpperCase();
  732. });
  733. ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
  734. // From the awesome hack by Dean Edwards
  735. // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
  736. // If we're not dealing with a regular pixel number
  737. // but a number that has a weird ending, we need to convert it to pixels
  738. if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
  739. // Remember the original values
  740. var left = style.left, rsLeft = elem.runtimeStyle.left;
  741. // Put in the new values to get a computed value out
  742. elem.runtimeStyle.left = elem.currentStyle.left;
  743. style.left = ret || 0;
  744. ret = style.pixelLeft + "px";
  745. // Revert the changed values
  746. style.left = left;
  747. elem.runtimeStyle.left = rsLeft;
  748. }
  749. }
  750. return ret;
  751. },
  752. clean: function( elems, context ) {
  753. var ret = [];
  754. context = context || document;
  755. // !context.createElement fails in IE with an error but returns typeof 'object'
  756. if (typeof context.createElement == 'undefined')
  757. context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
  758. jQuery.each(elems, function(i, elem){
  759. if ( !elem )
  760. return;
  761. if ( elem.constructor == Number )
  762. elem += '';
  763. // Convert html string into DOM nodes
  764. if ( typeof elem == "string" ) {
  765. // Fix "XHTML"-style tags in all browsers
  766. elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
  767. return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
  768. all :
  769. front + "></" + tag + ">";
  770. });
  771. // Trim whitespace, otherwise indexOf won't work as expected
  772. var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div");
  773. var wrap =
  774. // option or optgroup
  775. !tags.indexOf("<opt") &&
  776. [ 1, "<select multiple='multiple'>", "</select>" ] ||
  777. !tags.indexOf("<leg") &&
  778. [ 1, "<fieldset>", "</fieldset>" ] ||
  779. tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
  780. [ 1, "<table>", "</table>" ] ||
  781. !tags.indexOf("<tr") &&
  782. [ 2, "<table><tbody>", "</tbody></table>" ] ||
  783. // <thead> matched above
  784. (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
  785. [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
  786. !tags.indexOf("<col") &&
  787. [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
  788. // IE can't serialize <link> and <script> tags normally
  789. jQuery.browser.msie &&
  790. [ 1, "div<div>", "</div>" ] ||
  791. [ 0, "", "" ];
  792. // Go to html and back, then peel off extra wrappers
  793. div.innerHTML = wrap[1] + elem + wrap[2];
  794. // Move to the right depth
  795. while ( wrap[0]-- )
  796. div = div.lastChild;
  797. // Remove IE's autoinserted <tbody> from table fragments
  798. if ( jQuery.browser.msie ) {
  799. // String was a <table>, *may* have spurious <tbody>
  800. var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
  801. div.firstChild && div.firstChild.childNodes :
  802. // String was a bare <thead> or <tfoot>
  803. wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
  804. div.childNodes :
  805. [];
  806. for ( var j = tbody.length - 1; j >= 0 ; --j )
  807. if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
  808. tbody[ j ].parentNode.removeChild( tbody[ j ] );
  809. // IE completely kills leading whitespace when innerHTML is used
  810. if ( /^\s/.test( elem ) )
  811. div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
  812. }
  813. elem = jQuery.makeArray( div.childNodes );
  814. }
  815. if ( elem.length === 0 && (!jQuery.nodeName( elem, "form" ) && !jQuery.nodeName( elem, "select" )) )
  816. return;
  817. if ( elem[0] == undefined || jQuery.nodeName( elem, "form" ) || elem.options )
  818. ret.push( elem );
  819. else
  820. ret = jQuery.merge( ret, elem );
  821. });
  822. return ret;
  823. },
  824. attr: function( elem, name, value ) {
  825. // don't set attributes on text and comment nodes
  826. if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
  827. return undefined;
  828. var notxml = !jQuery.isXMLDoc( elem ),
  829. // Whether we are setting (or getting)
  830. set = value !== undefined,
  831. msie = jQuery.browser.msie;
  832. // Try to normalize/fix the name
  833. name = notxml && jQuery.props[ name ] || name;
  834. // Only do all the following if this is a node (faster for style)
  835. // IE elem.getAttribute passes even for style
  836. if ( elem.tagName ) {
  837. // These attributes require special treatment
  838. var special = /href|src|style/.test( name );
  839. // Safari mis-reports the default selected property of a hidden option
  840. // Accessing the parent's selectedIndex property fixes it
  841. if ( name == "selected" && jQuery.browser.safari )
  842. elem.parentNode.selectedIndex;
  843. // If applicable, access the attribute via the DOM 0 way
  844. if ( name in elem && notxml && !special ) {
  845. if ( set ){
  846. // We can't allow the type property to be changed (since it causes problems in IE)
  847. if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
  848. throw "type property can't be changed";
  849. elem[ name ] = value;
  850. }
  851. // browsers index elements by id/name on forms, give priority to attributes.
  852. if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
  853. return elem.getAttributeNode( name ).nodeValue;
  854. return elem[ name ];
  855. }
  856. if ( msie && notxml && name == "style" )
  857. return jQuery.attr( elem.style, "cssText", value );
  858. if ( set )
  859. // convert the value to a string (all browsers do this but IE) see #1070
  860. elem.setAttribute( name, "" + value );
  861. var attr = msie && notxml && special
  862. // Some attributes require a special call on IE
  863. ? elem.getAttribute( name, 2 )
  864. : elem.getAttribute( name );
  865. // Non-existent attributes return null, we normalize to undefined
  866. return attr === null ? undefined : attr;
  867. }
  868. // elem is actually elem.style ... set the style
  869. // IE uses filters for opacity
  870. if ( msie && name == "opacity" ) {
  871. if ( set ) {
  872. // IE has trouble with opacity if it does not have layout
  873. // Force it by setting the zoom level
  874. elem.zoom = 1;
  875. // Set the alpha filter to set the opacity
  876. elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
  877. (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
  878. }
  879. return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
  880. (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
  881. "";
  882. }
  883. name = name.replace(/-([a-z])/ig, function(all, letter){
  884. return letter.toUpperCase();
  885. });
  886. if ( set )
  887. elem[ name ] = value;
  888. return elem[ name ];
  889. },
  890. trim: function( text ) {
  891. return (text || "").replace( /^\s+|\s+$/g, "" );
  892. },
  893. makeArray: function( array ) {
  894. var ret = [];
  895. if( array != null ){
  896. var i = array.length;
  897. //the window, strings and functions also have 'length'
  898. if( i == null || array.split || array.setInterval || array.call )
  899. ret[0] = array;
  900. else
  901. while( i )
  902. ret[--i] = array[i];
  903. }
  904. return ret;
  905. },
  906. inArray: function( elem, array ) {
  907. for ( var i = 0, length = array.length; i < length; i++ )
  908. // Use === because on IE, window == document
  909. if ( array[ i ] === elem )
  910. return i;
  911. return -1;
  912. },
  913. merge: function( first, second ) {
  914. // We have to loop this way because IE & Opera overwrite the length
  915. // expando of getElementsByTagName
  916. var i = 0, elem, pos = first.length;
  917. // Also, we need to make sure that the correct elements are being returned
  918. // (IE returns comment nodes in a '*' query)
  919. if ( jQuery.browser.msie ) {
  920. while ( elem = second[ i++ ] )
  921. if ( elem.nodeType != 8 )
  922. first[ pos++ ] = elem;
  923. } else
  924. while ( elem = second[ i++ ] )
  925. first[ pos++ ] = elem;
  926. return first;
  927. },
  928. unique: function( array ) {
  929. var ret = [], done = {};
  930. try {
  931. for ( var i = 0, length = array.length; i < length; i++ ) {
  932. var id = jQuery.data( array[ i ] );
  933. if ( !done[ id ] ) {
  934. done[ id ] = true;
  935. ret.push( array[ i ] );
  936. }
  937. }
  938. } catch( e ) {
  939. ret = array;
  940. }
  941. return ret;
  942. },
  943. grep: function( elems, callback, inv ) {
  944. var ret = [];
  945. // Go through the array, only saving the items
  946. // that pass the validator function
  947. for ( var i = 0, length = elems.length; i < length; i++ )
  948. if ( !inv != !callback( elems[ i ], i ) )
  949. ret.push( elems[ i ] );
  950. return ret;
  951. },
  952. map: function( elems, callback ) {
  953. var ret = [];
  954. // Go through the array, translating each of the items to their
  955. // new value (or values).
  956. for ( var i = 0, length = elems.length; i < length; i++ ) {
  957. var value = callback( elems[ i ], i );
  958. if ( value != null )
  959. ret[ ret.length ] = value;
  960. }
  961. return ret.concat.apply( [], ret );
  962. }
  963. });
  964. var userAgent = navigator.userAgent.toLowerCase();
  965. // Figure out what browser is being used
  966. jQuery.browser = {
  967. version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
  968. safari: /webkit/.test( userAgent ),
  969. opera: /opera/.test( userAgent ),
  970. msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
  971. mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
  972. };
  973. var styleFloat = jQuery.browser.msie ?
  974. "styleFloat" :
  975. "cssFloat";
  976. jQuery.extend({
  977. // Check to see if the W3C box model is being used
  978. boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",
  979. props: {
  980. "for": "htmlFor",
  981. "class": "className",
  982. "float": styleFloat,
  983. cssFloat: styleFloat,
  984. styleFloat: styleFloat,
  985. readonly: "readOnly",
  986. maxlength: "maxLength",
  987. cellspacing: "cellSpacing"
  988. }
  989. });
  990. jQuery.each({
  991. parent: function(elem){return elem.parentNode;},
  992. parents: function(elem){return jQuery.dir(elem,"parentNode");},
  993. next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
  994. prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
  995. nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
  996. prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
  997. siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
  998. children: function(elem){return jQuery.sibling(elem.firstChild);},
  999. contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
  1000. }, function(name, fn){
  1001. jQuery.fn[ name ] = function( selector ) {
  1002. var ret = jQuery.map( this, fn );
  1003. if ( selector && typeof selector == "string" )
  1004. ret = jQuery.multiFilter( selector, ret );
  1005. return this.pushStack( jQuery.unique( ret ) );
  1006. };
  1007. });
  1008. jQuery.each({
  1009. appendTo: "append",
  1010. prependTo: "prepend",
  1011. insertBefore: "before",
  1012. insertAfter: "after",
  1013. replaceAll: "replaceWith"
  1014. }, function(name, original){
  1015. jQuery.fn[ name ] = function() {
  1016. var args = arguments;
  1017. return this.each(function(){
  1018. for ( var i = 0, length = args.length; i < length; i++ )
  1019. jQuery( args[ i ] )[ original ]( this );
  1020. });
  1021. };
  1022. });
  1023. jQuery.each({
  1024. removeAttr: function( name ) {
  1025. jQuery.attr( this, name, "" );
  1026. if (this.nodeType == 1)
  1027. this.removeAttribute( name );
  1028. },
  1029. addClass: function( classNames ) {
  1030. jQuery.className.add( this, classNames );
  1031. },
  1032. removeClass: function( classNames ) {
  1033. jQuery.className.remove( this, classNames );
  1034. },
  1035. toggleClass: function( classNames ) {
  1036. jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );
  1037. },
  1038. remove: function( selector ) {
  1039. if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) {
  1040. // Prevent memory leaks
  1041. jQuery( "*", this ).add(this).each(function(){
  1042. jQuery.event.remove(this);
  1043. jQuery.removeData(this);
  1044. });
  1045. if (this.parentNode)
  1046. this.parentNode.removeChild( this );
  1047. }
  1048. },
  1049. empty: function() {
  1050. // Remove element nodes and prevent memory leaks
  1051. jQuery( ">*", this ).remove();
  1052. // Remove any remaining nodes
  1053. while ( this.firstChild )
  1054. this.removeChild( this.firstChild );
  1055. }
  1056. }, function(name, fn){
  1057. jQuery.fn[ name ] = function(){
  1058. return this.each( fn, arguments );
  1059. };
  1060. });
  1061. jQuery.each([ "Height", "Width" ], function(i, name){
  1062. var type = name.toLowerCase();
  1063. jQuery.fn[ type ] = function( size ) {
  1064. // Get window width or height
  1065. return this[0] == window ?
  1066. // Opera reports document.body.client[Width/Height] properly in both quirks and standards
  1067. jQuery.browser.opera && document.body[ "client" + name ] ||
  1068. // Safari reports inner[Width/Height] just fine (Mozilla and Opera include scroll bar widths)
  1069. jQuery.browser.safari && window[ "inner" + name ] ||
  1070. // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
  1071. document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || document.body[ "client" + name ] :
  1072. // Get document width or height
  1073. this[0] == document ?
  1074. // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
  1075. Math.max(
  1076. Math.max(document.body["scroll" + name], document.documentElement["scroll" + name]),
  1077. Math.max(document.body["offset" + name], document.documentElement["offset" + name])
  1078. ) :
  1079. // Get or set width or height on the element
  1080. size == undefined ?
  1081. // Get width or height on the element
  1082. (this.length ? jQuery.css( this[0], type ) : null) :
  1083. // Set the width or height on the element (default to pixels if value is unitless)
  1084. this.css( type, size.constructor == String ? size : size + "px" );
  1085. };
  1086. });
  1087. // Helper function used by the dimensions and offset modules
  1088. function num(elem, prop) {
  1089. return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;
  1090. }var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ?
  1091. "(?:[\\w*_-]|\\\\.)" :
  1092. "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",
  1093. quickChild = new RegExp("^>\\s*(" + chars + "+)"),
  1094. quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"),
  1095. quickClass = new RegExp("^([#.]?)(" + chars + "*)");
  1096. jQuery.extend({
  1097. expr: {
  1098. "": function(a,i,m){return m[2]=="*"||jQuery.nodeName(a,m[2]);},
  1099. "#": function(a,i,m){return a.getAttribute("id")==m[2];},
  1100. ":": {
  1101. // Position Checks
  1102. lt: function(a,i,m){return i<m[3]-0;},
  1103. gt: function(a,i,m){return i>m[3]-0;},
  1104. nth: function(a,i,m){return m[3]-0==i;},
  1105. eq: function(a,i,m){return m[3]-0==i;},
  1106. first: function(a,i){return i==0;},
  1107. last: function(a,i,m,r){return i==r.length-1;},
  1108. even: function(a,i){return i%2==0;},
  1109. odd: function(a,i){return i%2;},
  1110. // Child Checks
  1111. "first-child": function(a){return a.parentNode.getElementsByTagName("*")[0]==a;},
  1112. "last-child": function(a){return jQuery.nth(a.parentNode.lastChild,1,"previousSibling")==a;},
  1113. "only-child": function(a){return !jQuery.nth(a.parentNode.lastChild,2,"previousSibling");},
  1114. // Parent Checks
  1115. parent: function(a){return a.firstChild;},
  1116. empty: function(a){return !a.firstChild;},
  1117. // Text Check
  1118. contains: function(a,i,m){return (a.textContent||a.innerText||jQuery(a).text()||"").indexOf(m[3])>=0;},
  1119. // Visibility
  1120. visible: function(a){return "hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden";},
  1121. hidden: function(a){return "hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden";},
  1122. // Form attributes
  1123. enabled: function(a){return !a.disabled;},
  1124. disabled: function(a){return a.disabled;},
  1125. checked: function(a){return a.checked;},
  1126. selected: function(a){return a.selected||jQuery.attr(a,"selected");},
  1127. // Form elements
  1128. text: function(a){return "text"==a.type;},
  1129. radio: function(a){return "radio"==a.type;},
  1130. checkbox: function(a){return "checkbox"==a.type;},
  1131. file: function(a){return "file"==a.type;},
  1132. password: function(a){return "password"==a.type;},
  1133. submit: function(a){return "submit"==a.type;},
  1134. image: function(a){return "image"==a.type;},
  1135. reset: function(a){return "reset"==a.type;},
  1136. button: function(a){return "button"==a.type||jQuery.nodeName(a,"button");},
  1137. input: function(a){return /input|select|textarea|button/i.test(a.nodeName);},
  1138. // :has()
  1139. has: function(a,i,m){return jQuery.find(m[3],a).length;},
  1140. // :header
  1141. header: function(a){return /h\d/i.test(a.nodeName);},
  1142. // :animated
  1143. animated: function(a){return jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length;}
  1144. }
  1145. },
  1146. // The regular expressions that power the parsing engine
  1147. parse: [
  1148. // Match: [@value='test'], [@foo]
  1149. /^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,
  1150. // Match: :contains('foo')
  1151. /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,
  1152. // Match: :even, :last-child, #id, .class
  1153. new RegExp("^([:.#]*)(" + chars + "+)")
  1154. ],
  1155. multiFilter: function( expr, elems, not ) {
  1156. var old, cur = [];
  1157. while ( expr && expr != old ) {
  1158. old = expr;
  1159. var f = jQuery.filter( expr, elems, not );
  1160. expr = f.t.replace(/^\s*,\s*/, "" );
  1161. cur = not ? elems = f.r : jQuery.merge( cur, f.r );
  1162. }
  1163. return cur;
  1164. },
  1165. find: function( t, context ) {
  1166. // Quickly handle non-string expressions
  1167. if ( typeof t != "string" )
  1168. return [ t ];
  1169. // check to make sure context is a DOM element or a document
  1170. if ( context && context.nodeType != 1 && context.nodeType != 9)
  1171. return [ ];
  1172. // Set the correct context (if none is provided)
  1173. context = context || document;
  1174. // Initialize the search
  1175. var ret = [context], done = [], last, nodeName;
  1176. // Continue while a selector expression exists, and while
  1177. // we're no longer looping upon ourselves
  1178. while ( t && last != t ) {
  1179. var r = [];
  1180. last = t;
  1181. t = jQuery.trim(t);
  1182. var foundToken = false,
  1183. // An attempt at speeding up child selectors that
  1184. // point to a specific element tag
  1185. re = quickChild,
  1186. m = re.exec(t);
  1187. if ( m ) {
  1188. nodeName = m[1].toUpperCase();
  1189. // Perform our own iteration and filter
  1190. for ( var i = 0; ret[i]; i++ )
  1191. for ( var c = ret[i].firstChild; c; c = c.nextSibling )
  1192. if ( c.nodeType == 1 && (nodeName == "*" || c.nodeName.toUpperCase() == nodeName) )
  1193. r.push( c );
  1194. ret = r;
  1195. t = t.replace( re, "" );
  1196. if ( t.indexOf(" ") == 0 ) continue;
  1197. foundToken = true;
  1198. } else {
  1199. re = /^([>+~])\s*(\w*)/i;
  1200. if ( (m = re.exec(t)) != null ) {
  1201. r = [];
  1202. var merge = {};
  1203. nodeName = m[2].toUpperCase();
  1204. m = m[1];
  1205. for ( var j = 0, rl = ret.length; j < rl; j++ ) {
  1206. var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild;
  1207. for ( ; n; n = n.nextSibling )
  1208. if ( n.nodeType == 1 ) {
  1209. var id = jQuery.data(n);
  1210. if ( m == "~" && merge[id] ) break;
  1211. if (!nodeName || n.nodeName.toUpperCase() == nodeName ) {
  1212. if ( m == "~" ) merge[id] = true;
  1213. r.push( n );
  1214. }
  1215. if ( m == "+" ) break;
  1216. }
  1217. }
  1218. ret = r;
  1219. // And remove the token
  1220. t = jQuery.trim( t.replace( re, "" ) );
  1221. foundToken = true;
  1222. }
  1223. }
  1224. // See if there's still an expression, and that we haven't already
  1225. // matched a token
  1226. if ( t && !foundToken ) {
  1227. // Handle multiple expressions
  1228. if ( !t.indexOf(",") ) {
  1229. // Clean the result set
  1230. if ( context == ret[0] ) ret.shift();
  1231. // Merge the result sets
  1232. done = jQuery.merge( done, ret );
  1233. // Reset the context
  1234. r = ret = [context];
  1235. // Touch up the selector string
  1236. t = " " + t.substr(1,t.length);
  1237. } else {
  1238. // Optimize for the case nodeName#idName
  1239. var re2 = quickID;
  1240. var m = re2.exec(t);
  1241. // Re-organize the results, so that they're consistent
  1242. if ( m ) {
  1243. m = [ 0, m[2], m[3], m[1] ];
  1244. } else {
  1245. // Otherwise, do a traditional filter check for
  1246. // ID, class, and element selectors
  1247. re2 = quickClass;
  1248. m = re2.exec(t);
  1249. }
  1250. m[2] = m[2].replace(/\\/g, "");
  1251. var elem = ret[ret.length-1];
  1252. // Try to do a global search by ID, where we can
  1253. if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) {
  1254. // Optimization for HTML document case
  1255. var oid = elem.getElementById(m[2]);
  1256. // Do a quick check for the existence of the actual ID attribute
  1257. // to avoid selecting by the name attribute in IE
  1258. // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form
  1259. if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )
  1260. oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
  1261. // Do a quick check for node name (where applicable) so
  1262. // that div#foo searches will be really fast
  1263. ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
  1264. } else {
  1265. // We need to find all descendant elements
  1266. for ( var i = 0; ret[i]; i++ ) {
  1267. // Grab the tag name being searched for
  1268. var tag = m[1] == "#" && m[3] ? m[3] : m[1] != "" || m[0] == "" ? "*" : m[2];
  1269. // Handle IE7 being really dumb about <object>s
  1270. if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" )
  1271. tag = "param";
  1272. r = jQuery.merge( r, ret[i].getElementsByTagName( tag ));
  1273. }
  1274. // It's faster to filter by class and be done with it
  1275. if ( m[1] == "." )
  1276. r = jQuery.classFilter( r, m[2] );
  1277. // Same with ID filtering
  1278. if ( m[1] == "#" ) {
  1279. var tmp = [];
  1280. // Try to find the element with the ID
  1281. for ( var i = 0; r[i]; i++ )
  1282. if ( r[i].getAttribute("id") == m[2] ) {
  1283. tmp = [ r[i] ];
  1284. break;
  1285. }
  1286. r = tmp;
  1287. }
  1288. ret = r;
  1289. }
  1290. t = t.replace( re2, "" );
  1291. }
  1292. }
  1293. // If a selector string still exists
  1294. if ( t ) {
  1295. // Attempt to filter it
  1296. var val = jQuery.filter(t,r);
  1297. ret = r = val.r;
  1298. t = jQuery.trim(val.t);
  1299. }
  1300. }
  1301. // An error occurred with the selector;
  1302. // just return an empty set instead
  1303. if ( t )
  1304. ret = [];
  1305. // Remove the root context
  1306. if ( ret && context == ret[0] )
  1307. ret.shift();
  1308. // And combine the results
  1309. done = jQuery.merge( done, ret );
  1310. return done;
  1311. },
  1312. classFilter: function(r,m,not){
  1313. m = " " + m + " ";
  1314. var tmp = [];
  1315. for ( var i = 0; r[i]; i++ ) {
  1316. var pass = (" " + r[i].className + " ").indexOf( m ) >= 0;
  1317. if ( !not && pass || not && !pass )
  1318. tmp.push( r[i] );
  1319. }
  1320. return tmp;
  1321. },
  1322. filter: function(t,r,not) {
  1323. var last;
  1324. // Look for common filter expressions
  1325. while ( t && t != last ) {
  1326. last = t;
  1327. var p = jQuery.parse, m;
  1328. for ( var i = 0; p[i]; i++ ) {
  1329. m = p[i].exec( t );
  1330. if ( m ) {
  1331. // Remove what we just matched
  1332. t = t.substring( m[0].length );
  1333. m[2] = m[2].replace(/\\/g, "");
  1334. break;
  1335. }
  1336. }
  1337. if ( !m )
  1338. break;
  1339. // :not() is a special case that can be optimized by
  1340. // keeping it out of the expression list
  1341. if ( m[1] == ":" && m[2] == "not" )
  1342. // optimize if only one selector found (most common case)
  1343. r = isSimple.test( m[3] ) ?
  1344. jQuery.filter(m[3], r, true).r :
  1345. jQuery( r ).not( m[3] );
  1346. // We can get a big speed boost by filtering by class here
  1347. else if ( m[1] == "." )
  1348. r = jQuery.classFilter(r, m[2], not);
  1349. else if ( m[1] == "[" ) {
  1350. var tmp = [], type = m[3];
  1351. for ( var i = 0, rl = r.length; i < rl; i++ ) {
  1352. var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ];
  1353. if ( z == null || /href|src|selected/.test(m[2]) )
  1354. z = jQuery.attr(a,m[2]) || '';
  1355. if ( (type == "" && !!z ||
  1356. type == "=" && z == m[5] ||
  1357. type == "!=" && z != m[5] ||
  1358. type == "^=" && z && !z.indexOf(m[5]) ||
  1359. type == "$=" && z.substr(z.length - m[5].length) == m[5] ||
  1360. (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not )
  1361. tmp.push( a );
  1362. }
  1363. r = tmp;
  1364. // We can get a speed boost by handling nth-child here
  1365. } else if ( m[1] == ":" && m[2] == "nth-child" ) {
  1366. var merge = {}, tmp = [],
  1367. // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
  1368. test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
  1369. m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" ||
  1370. !/\D/.test(m[3]) && "0n+" + m[3] || m[3]),
  1371. // calculate the numbers (first)n+(last) including if they are negative
  1372. first = (test[1] + (test[2] || 1)) - 0, last = test[3] - 0;
  1373. // loop through all the elements left in the jQuery object
  1374. for ( var i = 0, rl = r.length; i < rl; i++ ) {
  1375. var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode);
  1376. if ( !merge[id] ) {
  1377. var c = 1;
  1378. for ( var n = parentNode.firstChild; n; n = n.nextSibling )
  1379. if ( n.nodeType == 1 )
  1380. n.nodeIndex = c++;
  1381. merge[id] = true;
  1382. }
  1383. var add = false;
  1384. if ( first == 0 ) {
  1385. if ( node.nodeIndex == last )
  1386. add = true;
  1387. } else if ( (node.nodeIndex - last) % first == 0 && (node.nodeIndex - last) / first >= 0 )
  1388. add = true;
  1389. if ( add ^ not )
  1390. tmp.push( node );
  1391. }
  1392. r = tmp;
  1393. // Otherwise, find the expression to execute
  1394. } else {
  1395. var fn = jQuery.expr[ m[1] ];
  1396. if ( typeof fn == "object" )
  1397. fn = fn[ m[2] ];
  1398. if ( typeof fn == "string" )
  1399. fn = eval("false||function(a,i){return " + fn + ";}");
  1400. // Execute it against the current filter
  1401. r = jQuery.grep( r, function(elem, i){
  1402. return fn(elem, i, m, r);
  1403. }, not );
  1404. }
  1405. }
  1406. // Return an array of filtered elements (r)
  1407. // and the modified expression string (t)
  1408. return { r: r, t: t };
  1409. },
  1410. dir: function( elem, dir ){
  1411. var matched = [],
  1412. cur = elem[dir];
  1413. while ( cur && cur != document ) {
  1414. if ( cur.nodeType == 1 )
  1415. matched.push( cur );
  1416. cur = cur[dir];
  1417. }
  1418. return matched;
  1419. },
  1420. nth: function(cur,result,dir,elem){
  1421. result = result || 1;
  1422. var num = 0;
  1423. for ( ; cur; cur = cur[dir] )
  1424. if ( cur.nodeType == 1 && ++num == result )
  1425. break;
  1426. return cur;
  1427. },
  1428. sibling: function( n, elem ) {
  1429. var r = [];
  1430. for ( ; n; n = n.nextSibling ) {
  1431. if ( n.nodeType == 1 && n != elem )
  1432. r.push( n );
  1433. }
  1434. return r;
  1435. }
  1436. });
  1437. /*
  1438. * A number of helper functions used for managing events.
  1439. * Many of the ideas behind this code orignated from
  1440. * Dean Edwards' addEvent library.
  1441. */
  1442. jQuery.event = {
  1443. // Bind an event to an element
  1444. // Original by Dean Edwards
  1445. add: function(elem, types, handler, data) {
  1446. if ( elem.nodeType == 3 || elem.nodeType == 8 )
  1447. return;
  1448. // For whatever reason, IE has trouble passing the window object
  1449. // around, causing it to be cloned in the process
  1450. if ( jQuery.browser.msie && elem.setInterval )
  1451. elem = window;
  1452. // Make sure that the function being executed has a unique ID
  1453. if ( !handler.guid )
  1454. handler.guid = this.guid++;
  1455. // if data is passed, bind to handler
  1456. if( data != undefined ) {
  1457. // Create temporary function pointer to original handler
  1458. var fn = handler;
  1459. // Create unique handler function, wrapped around original handler
  1460. handler = this.proxy( fn, function() {
  1461. // Pass arguments and context to original handler
  1462. return fn.apply(this, arguments);
  1463. });
  1464. // Store data in unique handler
  1465. handler.data = data;
  1466. }
  1467. // Init the element's event structure
  1468. var events = jQuery.data(elem, "events") || jQuery.data(elem, "events", {}),
  1469. handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){
  1470. // Handle the second event of a trigger and when
  1471. // an event is called after a page has unloaded
  1472. if ( typeof jQuery != "undefined" && !jQuery.event.triggered )
  1473. return jQuery.event.handle.apply(arguments.callee.elem, arguments);
  1474. });
  1475. // Add elem as a property of the handle function
  1476. // This is to prevent a memory leak with non-native
  1477. // event in IE.
  1478. handle.elem = elem;
  1479. // Handle multiple events separated by a space
  1480. // jQuery(...).bind("mouseover mouseout", fn);
  1481. jQuery.each(types.split(/\s+/), function(index, type) {
  1482. // Namespaced event handlers
  1483. var parts = type.split(".");
  1484. type = parts[0];
  1485. handler.type = parts[1];
  1486. // Get the current list of functions bound to this event
  1487. var handlers = events[type];
  1488. // Init the event handler queue
  1489. if (!handlers) {
  1490. handlers = events[type] = {};
  1491. // Check for a special event handler
  1492. // Only use addEventListener/attachEvent if the special
  1493. // events handler returns false
  1494. if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) {
  1495. // Bind the global event handler to the element
  1496. if (elem.addEventListener)
  1497. elem.addEventListener(type, handle, false);
  1498. else if (elem.attachEvent)
  1499. elem.attachEvent("on" + type, handle);
  1500. }
  1501. }
  1502. // Add the function to the element's handler list
  1503. handlers[handler.guid] = handler;
  1504. // Keep track of which events have been used, for global triggering
  1505. jQuery.event.global[type] = true;
  1506. });
  1507. // Nullify elem to prevent memory leaks in IE
  1508. elem = null;
  1509. },
  1510. guid: 1,
  1511. global: {},
  1512. // Detach an event or set of events from an element
  1513. remove: function(elem, types, handler) {
  1514. // don't do events on text and comment nodes
  1515. if ( elem.nodeType == 3 || elem.nodeType == 8 )
  1516. return;
  1517. var events = jQuery.data(elem, "events"), ret, index;
  1518. if ( events ) {
  1519. // Unbind all events for the element
  1520. if ( types == undefined || (typeof types == "string" && types.charAt(0) == ".") )
  1521. for ( var type in events )
  1522. this.remove( elem, type + (types || "") );
  1523. else {
  1524. // types is actually an event object here
  1525. if ( types.type ) {
  1526. handler = types.handler;
  1527. types = types.type;
  1528. }
  1529. // Handle multiple events seperated by a space
  1530. // jQuery(...).unbind("mouseover mouseout", fn);
  1531. jQuery.each(types.split(/\s+/), function(index, type){
  1532. // Namespaced event handlers
  1533. var parts = type.split(".");
  1534. type = parts[0];
  1535. if ( events[type] ) {
  1536. // remove the given handler for the given type
  1537. if ( handler )
  1538. delete events[type][handler.guid];
  1539. // remove all handlers for the given type
  1540. else
  1541. for ( handler in events[type] )
  1542. // Handle the removal of namespaced events
  1543. if ( !parts[1] || events[type][handler].type == parts[1] )
  1544. delete events[type][handler];
  1545. // remove generic event handler if no more handlers exist
  1546. for ( ret in events[type] ) break;
  1547. if ( !ret ) {
  1548. if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem) === false ) {
  1549. if (elem.removeEventListener)
  1550. elem.removeEventListener(type, jQuery.data(elem, "handle"), false);
  1551. else if (elem.detachEvent)
  1552. elem.detachEvent("on" + type, jQuery.data(elem, "handle"));
  1553. }
  1554. ret = null;
  1555. delete events[type];
  1556. }
  1557. }
  1558. });
  1559. }
  1560. // Remove the expando if it's no longer used
  1561. for ( ret in events ) break;
  1562. if ( !ret ) {
  1563. var handle = jQuery.data( elem, "handle" );
  1564. if ( handle ) handle.elem = null;
  1565. jQuery.removeData( elem, "events" );
  1566. jQuery.removeData( elem, "handle" );
  1567. }
  1568. }
  1569. },
  1570. trigger: function(type, data, elem, donative, extra) {
  1571. // Clone the incoming data, if any
  1572. data = jQuery.makeArray(data);
  1573. if ( type.indexOf("!") >= 0 ) {
  1574. type = type.slice(0, -1);
  1575. var exclusive = true;
  1576. }
  1577. // Handle a global trigger
  1578. if ( !elem ) {
  1579. // Only trigger if we've ever bound an event for it
  1580. if ( this.global[type] )
  1581. jQuery("*").add([window, document]).trigger(type, data);
  1582. // Handle triggering a single element
  1583. } else {
  1584. // don't do events on text and comment nodes
  1585. if ( elem.nodeType == 3 || elem.nodeType == 8 )
  1586. return undefined;
  1587. var val, ret, fn = jQuery.isFunction( elem[ type ] || null ),
  1588. // Check to see if we need to provide a fake event, or not
  1589. event = !data[0] || !data[0].preventDefault;
  1590. // Pass along a fake event
  1591. if ( event ) {
  1592. data.unshift({
  1593. type: type,
  1594. target: elem,
  1595. preventDefault: function(){},
  1596. stopPropagation: function(){},
  1597. timeStamp: now()
  1598. });
  1599. data[0][expando] = true; // no need to fix fake event
  1600. }
  1601. // Enforce the right trigger type
  1602. data[0].type = type;
  1603. if ( exclusive )
  1604. data[0].exclusive = true;
  1605. // Trigger the event, it is assumed that "handle" is a function
  1606. var handle = jQuery.data(elem, "handle");
  1607. if ( handle )
  1608. val = handle.apply( elem, data );
  1609. // Handle triggering native .onfoo handlers (and on links since we don't call .click() for links)
  1610. if ( (!fn || (jQuery.nodeName(elem, 'a') && type == "click")) && elem["on"+type] && elem["on"+type].apply( elem, data ) === false )
  1611. val = false;
  1612. // Extra functions don't get the custom event object
  1613. if ( event )
  1614. data.shift();
  1615. // Handle triggering of extra function
  1616. if ( extra && jQuery.isFunction( extra ) ) {
  1617. // call the extra function and tack the current return value on the end for possible inspection
  1618. ret = extra.apply( elem, val == null ? data : data.concat( val ) );
  1619. // if anything is returned, give it precedence and have it overwrite the previous value
  1620. if (ret !== undefined)
  1621. val = ret;
  1622. }
  1623. // Trigger the native events (except for clicks on links)
  1624. if ( fn && donative !== false && val !== false && !(jQuery.nodeName(elem, 'a') && type == "click") ) {
  1625. this.triggered = true;
  1626. try {
  1627. elem[ type ]();
  1628. // prevent IE from throwing an error for some hidden elements
  1629. } catch (e) {}
  1630. }
  1631. this.triggered = false;
  1632. }
  1633. return val;
  1634. },
  1635. handle: function(event) {
  1636. // returned undefined or false
  1637. var val, ret, namespace, all, handlers;
  1638. event = arguments[0] = jQuery.event.fix( event || window.event );
  1639. // Namespaced event handlers
  1640. namespace = event.type.split(".");
  1641. event.type = namespace[0];
  1642. namespace = namespace[1];
  1643. // Cache this now, all = true means, any handler
  1644. all = !namespace && !event.exclusive;
  1645. handlers = ( jQuery.data(this, "events") || {} )[event.type];
  1646. for ( var j in handlers ) {
  1647. var handler = handlers[j];
  1648. // Filter the functions by class
  1649. if ( all || handler.type == namespace ) {
  1650. // Pass in a reference to the handler function itself
  1651. // So that we can later remove it
  1652. event.handler = handler;
  1653. event.data = handler.data;
  1654. ret = handler.apply( this, arguments );
  1655. if ( val !== false )
  1656. val = ret;
  1657. if ( ret === false ) {
  1658. event.preventDefault();
  1659. event.stopPropagation();
  1660. }
  1661. }
  1662. }
  1663. return val;
  1664. },
  1665. fix: function(event) {
  1666. if ( event[expando] == true )
  1667. return event;
  1668. // store a copy of the original event object
  1669. // and "clone" to set read-only properties
  1670. var originalEvent = event;
  1671. event = { originalEvent: originalEvent };
  1672. var props = "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target timeStamp toElement type view wheelDelta which".split(" ");
  1673. for ( var i=props.length; i; i-- )
  1674. event[ props[i] ] = originalEvent[ props[i] ];
  1675. // Mark it as fixed
  1676. event[expando] = true;
  1677. // add preventDefault and stopPropagation since
  1678. // they will not work on the clone
  1679. event.preventDefault = function() {
  1680. // if preventDefault exists run it on the original event
  1681. if (originalEvent.preventDefault)
  1682. originalEvent.preventDefault();
  1683. // otherwise set the returnValue property of the original event to false (IE)
  1684. originalEvent.returnValue = false;
  1685. };
  1686. event.stopPropagation = function() {
  1687. // if stopPropagation exists run it on the original event
  1688. if (originalEvent.stopPropagation)
  1689. originalEvent.stopPropagation();
  1690. // otherwise set the cancelBubble property of the original event to true (IE)
  1691. originalEvent.cancelBubble = true;
  1692. };
  1693. // Fix timeStamp
  1694. event.timeStamp = event.timeStamp || now();
  1695. // Fix target property, if necessary
  1696. if ( !event.target )
  1697. event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either
  1698. // check if target is a textnode (safari)
  1699. if ( event.target.nodeType == 3 )
  1700. event.target = event.target.parentNode;
  1701. // Add relatedTarget, if necessary
  1702. if ( !event.relatedTarget && event.fromElement )
  1703. event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
  1704. // Calculate pageX/Y if missing and clientX/Y available
  1705. if ( event.pageX == null && event.clientX != null ) {
  1706. var doc = document.documentElement, body = document.body;
  1707. event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0);
  1708. event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0);
  1709. }
  1710. // Add which for key events
  1711. if ( !event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode) )
  1712. event.which = event.charCode || event.keyCode;
  1713. // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
  1714. if ( !event.metaKey && event.ctrlKey )
  1715. event.metaKey = event.ctrlKey;
  1716. // Add which for click: 1 == left; 2 == middle; 3 == right
  1717. // Note: button is not normalized, so don't use it
  1718. if ( !event.which && event.button )
  1719. event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
  1720. return event;
  1721. },
  1722. proxy: function( fn, proxy ){
  1723. // Set the guid of unique handler to the same of original handler, so it can be removed
  1724. proxy.guid = fn.guid = fn.guid || proxy.guid || this.guid++;
  1725. // So proxy can be declared as an argument
  1726. return proxy;
  1727. },
  1728. special: {
  1729. ready: {
  1730. setup: function() {
  1731. // Make sure the ready event is setup
  1732. bindReady();
  1733. return;
  1734. },
  1735. teardown: function() { return; }
  1736. },
  1737. mouseenter: {
  1738. setup: function() {
  1739. if ( jQuery.browser.msie ) return false;
  1740. jQuery(this).bind("mouseover", jQuery.event.special.mouseenter.handler);
  1741. return true;
  1742. },
  1743. teardown: function() {
  1744. if ( jQuery.browser.msie ) return false;
  1745. jQuery(this).unbind("mouseover", jQuery.event.special.mouseenter.handler);
  1746. return true;
  1747. },
  1748. handler: function(event) {
  1749. // If we actually just moused on to a sub-element, ignore it
  1750. if ( withinElement(event, this) ) return true;
  1751. // Execute the right handlers by setting the event type to mouseenter
  1752. event.type = "mouseenter";
  1753. return jQuery.event.handle.apply(this, arguments);
  1754. }
  1755. },
  1756. mouseleave: {
  1757. setup: function() {
  1758. if ( jQuery.browser.msie ) return false;
  1759. jQuery(this).bind("mouseout", jQuery.event.special.mouseleave.handler);
  1760. return true;
  1761. },
  1762. teardown: function() {
  1763. if ( jQuery.browser.msie ) return false;
  1764. jQuery(this).unbind("mouseout", jQuery.event.special.mouseleave.handler);
  1765. return true;
  1766. },
  1767. handler: function(event) {
  1768. // If we actually just moused on to a sub-element, ignore it
  1769. if ( withinElement(event, this) ) return true;
  1770. // Execute the right handlers by setting the event type to mouseleave
  1771. event.type = "mouseleave";
  1772. return jQuery.event.handle.apply(this, arguments);
  1773. }
  1774. }
  1775. }
  1776. };
  1777. jQuery.fn.extend({
  1778. bind: function( type, data, fn ) {
  1779. return type == "unload" ? this.one(type, data, fn) : this.each(function(){
  1780. jQuery.event.add( this, type, fn || data, fn && data );
  1781. });
  1782. },
  1783. one: function( type, data, fn ) {
  1784. var one = jQuery.event.proxy( fn || data, function(event) {
  1785. jQuery(this).unbind(event, one);
  1786. return (fn || data).apply( this, arguments );
  1787. });
  1788. return this.each(function(){
  1789. jQuery.event.add( this, type, one, fn && data);
  1790. });
  1791. },
  1792. unbind: function( type, fn ) {
  1793. return this.each(function(){
  1794. jQuery.event.remove( this, type, fn );
  1795. });
  1796. },
  1797. trigger: function( type, data, fn ) {
  1798. return this.each(function(){
  1799. jQuery.event.trigger( type, data, this, true, fn );
  1800. });
  1801. },
  1802. triggerHandler: function( type, data, fn ) {
  1803. return this[0] && jQuery.event.trigger( type, data, this[0], false, fn );
  1804. },
  1805. toggle: function( fn ) {
  1806. // Save reference to arguments for access in closure
  1807. var args = arguments, i = 1;
  1808. // link all the functions, so any of them can unbind this click handler
  1809. while( i < args.length )
  1810. jQuery.event.proxy( fn, args[i++] );
  1811. return this.click( jQuery.event.proxy( fn, function(event) {
  1812. // Figure out which function to execute
  1813. this.lastToggle = ( this.lastToggle || 0 ) % i;
  1814. // Make sure that clicks stop
  1815. event.preventDefault();
  1816. // and execute the function
  1817. return args[ this.lastToggle++ ].apply( this, arguments ) || false;
  1818. }));
  1819. },
  1820. hover: function(fnOver, fnOut) {
  1821. return this.bind('mouseenter', fnOver).bind('mouseleave', fnOut);
  1822. },
  1823. ready: function(fn) {
  1824. // Attach the listeners
  1825. bindReady();
  1826. // If the DOM is already ready
  1827. if ( jQuery.isReady )
  1828. // Execute the function immediately
  1829. fn.call( document, jQuery );
  1830. // Otherwise, remember the function for later
  1831. else
  1832. // Add the function to the wait list
  1833. jQuery.readyList.push( function() { return fn.call(this, jQuery); } );
  1834. return this;
  1835. }
  1836. });
  1837. jQuery.extend({
  1838. isReady: false,
  1839. readyList: [],
  1840. // Handle when the DOM is ready
  1841. ready: function() {
  1842. // Make sure that the DOM is not already loaded
  1843. if ( !jQuery.isReady ) {
  1844. // Remember that the DOM is ready
  1845. jQuery.isReady = true;
  1846. // If there are functions bound, to execute
  1847. if ( jQuery.readyList ) {
  1848. // Execute all of them
  1849. jQuery.each( jQuery.readyList, function(){
  1850. this.call( document );
  1851. });
  1852. // Reset the list of functions
  1853. jQuery.readyList = null;
  1854. }
  1855. // Trigger any bound ready events
  1856. jQuery(document).triggerHandler("ready");
  1857. }
  1858. }
  1859. });
  1860. var readyBound = false;
  1861. function bindReady(){
  1862. if ( readyBound ) return;
  1863. readyBound = true;
  1864. // Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
  1865. if ( document.addEventListener && !jQuery.browser.opera)
  1866. // Use the handy event callback
  1867. document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
  1868. // If IE is used and is not in a frame
  1869. // Continually check to see if the document is ready
  1870. if ( jQuery.browser.msie && window == top ) (function(){
  1871. if (jQuery.isReady) return;
  1872. try {
  1873. // If IE is used, use the trick by Diego Perini
  1874. // http://javascript.nwbox.com/IEContentLoaded/
  1875. document.documentElement.doScroll("left");
  1876. } catch( error ) {
  1877. setTimeout( arguments.callee, 0 );
  1878. return;
  1879. }
  1880. // and execute any waiting functions
  1881. jQuery.ready();
  1882. })();
  1883. if ( jQuery.browser.opera )
  1884. document.addEventListener( "DOMContentLoaded", function () {
  1885. if (jQuery.isReady) return;
  1886. for (var i = 0; i < document.styleSheets.length; i++)
  1887. if (document.styleSheets[i].disabled) {
  1888. setTimeout( arguments.callee, 0 );
  1889. return;
  1890. }
  1891. // and execute any waiting functions
  1892. jQuery.ready();
  1893. }, false);
  1894. if ( jQuery.browser.safari ) {
  1895. var numStyles;
  1896. (function(){
  1897. if (jQuery.isReady) return;
  1898. if ( document.readyState != "loaded" && document.readyState != "complete" ) {
  1899. setTimeout( arguments.callee, 0 );
  1900. return;
  1901. }
  1902. if ( numStyles === undefined )
  1903. numStyles = jQuery("style, link[rel=stylesheet]").length;
  1904. if ( document.styleSheets.length != numStyles ) {
  1905. setTimeout( arguments.callee, 0 );
  1906. return;
  1907. }
  1908. // and execute any waiting functions
  1909. jQuery.ready();
  1910. })();
  1911. }
  1912. // A fallback to window.onload, that will always work
  1913. jQuery.event.add( window, "load", jQuery.ready );
  1914. }
  1915. jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
  1916. "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
  1917. "submit,keydown,keypress,keyup,error").split(","), function(i, name){
  1918. // Handle event binding
  1919. jQuery.fn[name] = function(fn){
  1920. return fn ? this.bind(name, fn) : this.trigger(name);
  1921. };
  1922. });
  1923. // Checks if an event happened on an element within another element
  1924. // Used in jQuery.event.special.mouseenter and mouseleave handlers
  1925. var withinElement = function(event, elem) {
  1926. // Check if mouse(over|out) are still within the same parent element
  1927. var parent = event.relatedTarget;
  1928. // Traverse up the tree
  1929. while ( parent && parent != elem ) try { parent = parent.parentNode; } catch(error) { parent = elem; }
  1930. // Return true if we actually just moused on to a sub-element
  1931. return parent == elem;
  1932. };
  1933. // Prevent memory leaks in IE
  1934. // And prevent errors on refresh with events like mouseover in other browsers
  1935. // Window isn't included so as not to unbind existing unload events
  1936. jQuery(window).bind("unload", function() {
  1937. jQuery("*").add(document).unbind();
  1938. });
  1939. jQuery.fn.extend({
  1940. // Keep a copy of the old load
  1941. _load: jQuery.fn.load,
  1942. load: function( url, params, callback ) {
  1943. if ( typeof url != 'string' )
  1944. return this._load( url );
  1945. var off = url.indexOf(" ");
  1946. if ( off >= 0 ) {
  1947. var selector = url.slice(off, url.length);
  1948. url = url.slice(0, off);
  1949. }
  1950. callback = callback || function(){};
  1951. // Default to a GET request
  1952. var type = "GET";
  1953. // If the second parameter was provided
  1954. if ( params )
  1955. // If it's a function
  1956. if ( jQuery.isFunction( params ) ) {
  1957. // We assume that it's the callback
  1958. callback = params;
  1959. params = null;
  1960. // Otherwise, build a param string
  1961. } else {
  1962. params = jQuery.param( params );
  1963. type = "POST";
  1964. }
  1965. var self = this;
  1966. // Request the remote document
  1967. jQuery.ajax({
  1968. url: url,
  1969. type: type,
  1970. dataType: "html",
  1971. data: params,
  1972. complete: function(res, status){
  1973. // If successful, inject the HTML into all the matched elements
  1974. if ( status == "success" || status == "notmodified" )
  1975. // See if a selector was specified
  1976. self.html( selector ?
  1977. // Create a dummy div to hold the results
  1978. jQuery("<div/>")
  1979. // inject the contents of the document in, removing the scripts
  1980. // to avoid any 'Permission Denied' errors in IE
  1981. .append(res.responseText.replace(/<script(.|\s)*?\/script>/g, ""))
  1982. // Locate the specified elements
  1983. .find(selector) :
  1984. // If not, just inject the full result
  1985. res.responseText );
  1986. self.each( callback, [res.responseText, status, res] );
  1987. }
  1988. });
  1989. return this;
  1990. },
  1991. serialize: function() {
  1992. return jQuery.param(this.serializeArray());
  1993. },
  1994. serializeArray: function() {
  1995. return this.map(function(){
  1996. return jQuery.nodeName(this, "form") ?
  1997. jQuery.makeArray(this.elements) : this;
  1998. })
  1999. .filter(function(){
  2000. return this.name && !this.disabled &&
  2001. (this.checked || /select|textarea/i.test(this.nodeName) ||
  2002. /text|hidden|password/i.test(this.type));
  2003. })
  2004. .map(function(i, elem){
  2005. var val = jQuery(this).val();
  2006. return val == null ? null :
  2007. val.constructor == Array ?
  2008. jQuery.map( val, function(val, i){
  2009. return {name: elem.name, value: val};
  2010. }) :
  2011. {name: elem.name, value: val};
  2012. }).get();
  2013. }
  2014. });
  2015. // Attach a bunch of functions for handling common AJAX events
  2016. jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","), function(i,o){
  2017. jQuery.fn[o] = function(f){
  2018. return this.bind(o, f);
  2019. };
  2020. });
  2021. var jsc = now();
  2022. jQuery.extend({
  2023. get: function( url, data, callback, type ) {
  2024. // shift arguments if data argument was ommited
  2025. if ( jQuery.isFunction( data ) ) {
  2026. callback = data;
  2027. data = null;
  2028. }
  2029. return jQuery.ajax({
  2030. type: "GET",
  2031. url: url,
  2032. data: data,
  2033. success: callback,
  2034. dataType: type
  2035. });
  2036. },
  2037. getScript: function( url, callback ) {
  2038. return jQuery.get(url, null, callback, "script");
  2039. },
  2040. getJSON: function( url, data, callback ) {
  2041. return jQuery.get(url, data, callback, "json");
  2042. },
  2043. post: function( url, data, callback, type ) {
  2044. if ( jQuery.isFunction( data ) ) {
  2045. callback = data;
  2046. data = {};
  2047. }
  2048. return jQuery.ajax({
  2049. type: "POST",
  2050. url: url,
  2051. data: data,
  2052. success: callback,
  2053. dataType: type
  2054. });
  2055. },
  2056. ajaxSetup: function( settings ) {
  2057. jQuery.extend( jQuery.ajaxSettings, settings );
  2058. },
  2059. ajaxSettings: {
  2060. url: location.href,
  2061. global: true,
  2062. type: "GET",
  2063. timeout: 0,
  2064. contentType: "application/x-www-form-urlencoded",
  2065. processData: true,
  2066. async: true,
  2067. data: null,
  2068. username: null,
  2069. password: null,
  2070. accepts: {
  2071. xml: "application/xml, text/xml",
  2072. html: "text/html",
  2073. script: "text/javascript, application/javascript",
  2074. json: "application/json, text/javascript",
  2075. text: "text/plain",
  2076. _default: "*/*"
  2077. }
  2078. },
  2079. // Last-Modified header cache for next request
  2080. lastModified: {},
  2081. ajax: function( s ) {
  2082. // Extend the settings, but re-extend 's' so that it can be
  2083. // checked again later (in the test suite, specifically)
  2084. s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s));
  2085. var jsonp, jsre = /=\?(&|$)/g, status, data,
  2086. type = s.type.toUpperCase();
  2087. // convert data if not already a string
  2088. if ( s.data && s.processData && typeof s.data != "string" )
  2089. s.data = jQuery.param(s.data);
  2090. // Handle JSONP Parameter Callbacks
  2091. if ( s.dataType == "jsonp" ) {
  2092. if ( type == "GET" ) {
  2093. if ( !s.url.match(jsre) )
  2094. s.url += (s.url.match(/\?/) ? "&" : "?") + (s.jsonp || "callback") + "=?";
  2095. } else if ( !s.data || !s.data.match(jsre) )
  2096. s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?";
  2097. s.dataType = "json";
  2098. }
  2099. // Build temporary JSONP function
  2100. if ( s.dataType == "json" && (s.data && s.data.match(jsre) || s.url.match(jsre)) ) {
  2101. jsonp = "jsonp" + jsc++;
  2102. // Replace the =? sequence both in the query string and the data
  2103. if ( s.data )
  2104. s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1");
  2105. s.url = s.url.replace(jsre, "=" + jsonp + "$1");
  2106. // We need to make sure
  2107. // that a JSONP style response is executed properly
  2108. s.dataType = "script";
  2109. // Handle JSONP-style loading
  2110. window[ jsonp ] = function(tmp){
  2111. data = tmp;
  2112. success();
  2113. complete();
  2114. // Garbage collect
  2115. window[ jsonp ] = undefined;
  2116. try{ delete window[ jsonp ]; } catch(e){}
  2117. if ( head )
  2118. head.removeChild( script );
  2119. };
  2120. }
  2121. if ( s.dataType == "script" && s.cache == null )
  2122. s.cache = false;
  2123. if ( s.cache === false && type == "GET" ) {
  2124. var ts = now();
  2125. // try replacing _= if it is there
  2126. var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
  2127. // if nothing was replaced, add timestamp to the end
  2128. s.url = ret + ((ret == s.url) ? (s.url.match(/\?/) ? "&" : "?") + "_=" + ts : "");
  2129. }
  2130. // If data is available, append data to url for get requests
  2131. if ( s.data && type == "GET" ) {
  2132. s.url += (s.url.match(/\?/) ? "&" : "?") + s.data;
  2133. // IE likes to send both get and post data, prevent this
  2134. s.data = null;
  2135. }
  2136. // Watch for a new set of requests
  2137. if ( s.global && ! jQuery.active++ )
  2138. jQuery.event.trigger( "ajaxStart" );
  2139. // Matches an absolute URL, and saves the domain
  2140. var remote = /^(?:\w+:)?\/\/([^\/?#]+)/;
  2141. // If we're requesting a remote document
  2142. // and trying to load JSON or Script with a GET
  2143. if ( s.dataType == "script" && type == "GET"
  2144. && remote.test(s.url) && remote.exec(s.url)[1] != location.host ){
  2145. var head = document.getElementsByTagName("head")[0];
  2146. var script = document.createElement("script");
  2147. script.src = s.url;
  2148. if (s.scriptCharset)
  2149. script.charset = s.scriptCharset;
  2150. // Handle Script loading
  2151. if ( !jsonp ) {
  2152. var done = false;
  2153. // Attach handlers for all browsers
  2154. script.onload = script.onreadystatechange = function(){
  2155. if ( !done && (!this.readyState ||
  2156. this.readyState == "loaded" || this.readyState == "complete") ) {
  2157. done = true;
  2158. success();
  2159. complete();
  2160. head.removeChild( script );
  2161. }
  2162. };
  2163. }
  2164. head.appendChild(script);
  2165. // We handle everything using the script element injection
  2166. return undefined;
  2167. }
  2168. var requestDone = false;
  2169. // Create the request object; Microsoft failed to properly
  2170. // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available
  2171. var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  2172. // Open the socket
  2173. // Passing null username, generates a login popup on Opera (#2865)
  2174. if( s.username )
  2175. xhr.open(type, s.url, s.async, s.username, s.password);
  2176. else
  2177. xhr.open(type, s.url, s.async);
  2178. // Need an extra try/catch for cross domain requests in Firefox 3
  2179. try {
  2180. // Set the correct header, if data is being sent
  2181. if ( s.data )
  2182. xhr.setRequestHeader("Content-Type", s.contentType);
  2183. // Set the If-Modified-Since header, if ifModified mode.
  2184. if ( s.ifModified )
  2185. xhr.setRequestHeader("If-Modified-Since",
  2186. jQuery.lastModified[s.url] || "Thu, 01 Jan 1970 00:00:00 GMT" );
  2187. // Set header so the called script knows that it's an XMLHttpRequest
  2188. xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  2189. // Set the Accepts header for the server, depending on the dataType
  2190. xhr.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ?
  2191. s.accepts[ s.dataType ] + ", */*" :
  2192. s.accepts._default );
  2193. } catch(e){}
  2194. // Allow custom headers/mimetypes
  2195. if ( s.beforeSend && s.beforeSend(xhr, s) === false ) {
  2196. // cleanup active request counter
  2197. s.global && jQuery.active--;
  2198. // close opended socket
  2199. xhr.abort();
  2200. return false;
  2201. }
  2202. if ( s.global )
  2203. jQuery.event.trigger("ajaxSend", [xhr, s]);
  2204. // Wait for a response to come back
  2205. var onreadystatechange = function(isTimeout){
  2206. // The transfer is complete and the data is available, or the request timed out
  2207. if ( !requestDone && xhr && (xhr.readyState == 4 || isTimeout == "timeout") ) {
  2208. requestDone = true;
  2209. // clear poll interval
  2210. if (ival) {
  2211. clearInterval(ival);
  2212. ival = null;
  2213. }
  2214. status = isTimeout == "timeout" && "timeout" ||
  2215. !jQuery.httpSuccess( xhr ) && "error" ||
  2216. s.ifModified && jQuery.httpNotModified( xhr, s.url ) && "notmodified" ||
  2217. "success";
  2218. if ( status == "success" ) {
  2219. // Watch for, and catch, XML document parse errors
  2220. try {
  2221. // process the data (runs the xml through httpData regardless of callback)
  2222. data = jQuery.httpData( xhr, s.dataType, s.dataFilter );
  2223. } catch(e) {
  2224. status = "parsererror";
  2225. }
  2226. }
  2227. // Make sure that the request was successful or notmodified
  2228. if ( status == "success" ) {
  2229. // Cache Last-Modified header, if ifModified mode.
  2230. var modRes;
  2231. try {
  2232. modRes = xhr.getResponseHeader("Last-Modified");
  2233. } catch(e) {} // swallow exception thrown by FF if header is not available
  2234. if ( s.ifModified && modRes )
  2235. jQuery.lastModified[s.url] = modRes;
  2236. // JSONP handles its own success callback
  2237. if ( !jsonp )
  2238. success();
  2239. } else
  2240. jQuery.handleError(s, xhr, status);
  2241. // Fire the complete handlers
  2242. complete();
  2243. // Stop memory leaks
  2244. if ( s.async )
  2245. xhr = null;
  2246. }
  2247. };
  2248. if ( s.async ) {
  2249. // don't attach the handler to the request, just poll it instead
  2250. var ival = setInterval(onreadystatechange, 13);
  2251. // Timeout checker
  2252. if ( s.timeout > 0 )
  2253. setTimeout(function(){
  2254. // Check to see if the request is still happening
  2255. if ( xhr ) {
  2256. // Cancel the request
  2257. xhr.abort();
  2258. if( !requestDone )
  2259. onreadystatechange( "timeout" );
  2260. }
  2261. }, s.timeout);
  2262. }
  2263. // Send the data
  2264. try {
  2265. xhr.send(s.data);
  2266. } catch(e) {
  2267. jQuery.handleError(s, xhr, null, e);
  2268. }
  2269. // firefox 1.5 doesn't fire statechange for sync requests
  2270. if ( !s.async )
  2271. onreadystatechange();
  2272. function success(){
  2273. // If a local callback was specified, fire it and pass it the data
  2274. if ( s.success )
  2275. s.success( data, status );
  2276. // Fire the global callback
  2277. if ( s.global )
  2278. jQuery.event.trigger( "ajaxSuccess", [xhr, s] );
  2279. }
  2280. function complete(){
  2281. // Process result
  2282. if ( s.complete )
  2283. s.complete(xhr, status);
  2284. // The request was completed
  2285. if ( s.global )
  2286. jQuery.event.trigger( "ajaxComplete", [xhr, s] );
  2287. // Handle the global AJAX counter
  2288. if ( s.global && ! --jQuery.active )
  2289. jQuery.event.trigger( "ajaxStop" );
  2290. }
  2291. // return XMLHttpRequest to allow aborting the request etc.
  2292. return xhr;
  2293. },
  2294. handleError: function( s, xhr, status, e ) {
  2295. // If a local callback was specified, fire it
  2296. if ( s.error ) s.error( xhr, status, e );
  2297. // Fire the global callback
  2298. if ( s.global )
  2299. jQuery.event.trigger( "ajaxError", [xhr, s, e] );
  2300. },
  2301. // Counter for holding the number of active queries
  2302. active: 0,
  2303. // Determines if an XMLHttpRequest was successful or not
  2304. httpSuccess: function( xhr ) {
  2305. try {
  2306. // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450
  2307. return !xhr.status && location.protocol == "file:" ||
  2308. ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status == 1223 ||
  2309. jQuery.browser.safari && xhr.status == undefined;
  2310. } catch(e){}
  2311. return false;
  2312. },
  2313. // Determines if an XMLHttpRequest returns NotModified
  2314. httpNotModified: function( xhr, url ) {
  2315. try {
  2316. var xhrRes = xhr.getResponseHeader("Last-Modified");
  2317. // Firefox always returns 200. check Last-Modified date
  2318. return xhr.status == 304 || xhrRes == jQuery.lastModified[url] ||
  2319. jQuery.browser.safari && xhr.status == undefined;
  2320. } catch(e){}
  2321. return false;
  2322. },
  2323. httpData: function( xhr, type, filter ) {
  2324. var ct = xhr.getResponseHeader("content-type"),
  2325. xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0,
  2326. data = xml ? xhr.responseXML : xhr.responseText;
  2327. if ( xml && data.documentElement.tagName == "parsererror" )
  2328. throw "parsererror";
  2329. // Allow a pre-filtering function to sanitize the response
  2330. if( filter )
  2331. data = filter( data, type );
  2332. // If the type is "script", eval it in global context
  2333. if ( type == "script" )
  2334. jQuery.globalEval( data );
  2335. // Get the JavaScript object, if JSON is used.
  2336. if ( type == "json" )
  2337. data = eval("(" + data + ")");
  2338. return data;
  2339. },
  2340. // Serialize an array of form elements or a set of
  2341. // key/values into a query string
  2342. param: function( a ) {
  2343. var s = [];
  2344. // If an array was passed in, assume that it is an array
  2345. // of form elements
  2346. if ( a.constructor == Array || a.jquery )
  2347. // Serialize the form elements
  2348. jQuery.each( a, function(){
  2349. s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) );
  2350. });
  2351. // Otherwise, assume that it's an object of key/value pairs
  2352. else
  2353. // Serialize the key/values
  2354. for ( var j in a )
  2355. // If the value is an array then the key names need to be repeated
  2356. if ( a[j] && a[j].constructor == Array )
  2357. jQuery.each( a[j], function(){
  2358. s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
  2359. });
  2360. else
  2361. s.push( encodeURIComponent(j) + "=" + encodeURIComponent( jQuery.isFunction(a[j]) ? a[j]() : a[j] ) );
  2362. // Return the resulting serialization
  2363. return s.join("&").replace(/%20/g, "+");
  2364. }
  2365. });
  2366. jQuery.fn.extend({
  2367. show: function(speed,callback){
  2368. return speed ?
  2369. this.animate({
  2370. height: "show", width: "show", opacity: "show"
  2371. }, speed, callback) :
  2372. this.filter(":hidden").each(function(){
  2373. this.style.display = this.oldblock || "";
  2374. if ( jQuery.css(this,"display") == "none" ) {
  2375. var elem = jQuery("<" + this.tagName + " />").appendTo("body");
  2376. this.style.display = elem.css("display");
  2377. // handle an edge condition where css is - div { display:none; } or similar
  2378. if (this.style.display == "none")
  2379. this.style.display = "block";
  2380. elem.remove();
  2381. }
  2382. }).end();
  2383. },
  2384. hide: function(speed,callback){
  2385. return speed ?
  2386. this.animate({
  2387. height: "hide", width: "hide", opacity: "hide"
  2388. }, speed, callback) :
  2389. this.filter(":visible").each(function(){
  2390. this.oldblock = this.oldblock || jQuery.css(this,"display");
  2391. this.style.display = "none";
  2392. }).end();
  2393. },
  2394. // Save the old toggle function
  2395. _toggle: jQuery.fn.toggle,
  2396. toggle: function( fn, fn2 ){
  2397. return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
  2398. this._toggle.apply( this, arguments ) :
  2399. fn ?
  2400. this.animate({
  2401. height: "toggle", width: "toggle", opacity: "toggle"
  2402. }, fn, fn2) :
  2403. this.each(function(){
  2404. jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]();
  2405. });
  2406. },
  2407. slideDown: function(speed,callback){
  2408. return this.animate({height: "show"}, speed, callback);
  2409. },
  2410. slideUp: function(speed,callback){
  2411. return this.animate({height: "hide"}, speed, callback);
  2412. },
  2413. slideToggle: function(speed, callback){
  2414. return this.animate({height: "toggle"}, speed, callback);
  2415. },
  2416. fadeIn: function(speed, callback){
  2417. return this.animate({opacity: "show"}, speed, callback);
  2418. },
  2419. fadeOut: function(speed, callback){
  2420. return this.animate({opacity: "hide"}, speed, callback);
  2421. },
  2422. fadeTo: function(speed,to,callback){
  2423. return this.animate({opacity: to}, speed, callback);
  2424. },
  2425. animate: function( prop, speed, easing, callback ) {
  2426. var optall = jQuery.speed(speed, easing, callback);
  2427. return this[ optall.queue === false ? "each" : "queue" ](function(){
  2428. if ( this.nodeType != 1)
  2429. return false;
  2430. var opt = jQuery.extend({}, optall), p,
  2431. hidden = jQuery(this).is(":hidden"), self = this;
  2432. for ( p in prop ) {
  2433. if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
  2434. return opt.complete.call(this);
  2435. if ( p == "height" || p == "width" ) {
  2436. // Store display property
  2437. opt.display = jQuery.css(this, "display");
  2438. // Make sure that nothing sneaks out
  2439. opt.overflow = this.style.overflow;
  2440. }
  2441. }
  2442. if ( opt.overflow != null )
  2443. this.style.overflow = "hidden";
  2444. opt.curAnim = jQuery.extend({}, prop);
  2445. jQuery.each( prop, function(name, val){
  2446. var e = new jQuery.fx( self, opt, name );
  2447. if ( /toggle|show|hide/.test(val) )
  2448. e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
  2449. else {
  2450. var parts = val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
  2451. start = e.cur(true) || 0;
  2452. if ( parts ) {
  2453. var end = parseFloat(parts[2]),
  2454. unit = parts[3] || "px";
  2455. // We need to compute starting value
  2456. if ( unit != "px" ) {
  2457. self.style[ name ] = (end || 1) + unit;
  2458. start = ((end || 1) / e.cur(true)) * start;
  2459. self.style[ name ] = start + unit;
  2460. }
  2461. // If a +=/-= token was provided, we're doing a relative animation
  2462. if ( parts[1] )
  2463. end = ((parts[1] == "-=" ? -1 : 1) * end) + start;
  2464. e.custom( start, end, unit );
  2465. } else
  2466. e.custom( start, val, "" );
  2467. }
  2468. });
  2469. // For JS strict compliance
  2470. return true;
  2471. });
  2472. },
  2473. queue: function(type, fn){
  2474. if ( jQuery.isFunction(type) || ( type && type.constructor == Array )) {
  2475. fn = type;
  2476. type = "fx";
  2477. }
  2478. if ( !type || (typeof type == "string" && !fn) )
  2479. return queue( this[0], type );
  2480. return this.each(function(){
  2481. if ( fn.constructor == Array )
  2482. queue(this, type, fn);
  2483. else {
  2484. queue(this, type).push( fn );
  2485. if ( queue(this, type).length == 1 )
  2486. fn.call(this);
  2487. }
  2488. });
  2489. },
  2490. stop: function(clearQueue, gotoEnd){
  2491. var timers = jQuery.timers;
  2492. if (clearQueue)
  2493. this.queue([]);
  2494. this.each(function(){
  2495. // go in reverse order so anything added to the queue during the loop is ignored
  2496. for ( var i = timers.length - 1; i >= 0; i-- )
  2497. if ( timers[i].elem == this ) {
  2498. if (gotoEnd)
  2499. // force the next step to be the last
  2500. timers[i](true);
  2501. timers.splice(i, 1);
  2502. }
  2503. });
  2504. // start the next in the queue if the last step wasn't forced
  2505. if (!gotoEnd)
  2506. this.dequeue();
  2507. return this;
  2508. }
  2509. });
  2510. var queue = function( elem, type, array ) {
  2511. if ( elem ){
  2512. type = type || "fx";
  2513. var q = jQuery.data( elem, type + "queue" );
  2514. if ( !q || array )
  2515. q = jQuery.data( elem, type + "queue", jQuery.makeArray(array) );
  2516. }
  2517. return q;
  2518. };
  2519. jQuery.fn.dequeue = function(type){
  2520. type = type || "fx";
  2521. return this.each(function(){
  2522. var q = queue(this, type);
  2523. q.shift();
  2524. if ( q.length )
  2525. q[0].call( this );
  2526. });
  2527. };
  2528. jQuery.extend({
  2529. speed: function(speed, easing, fn) {
  2530. var opt = speed && speed.constructor == Object ? speed : {
  2531. complete: fn || !fn && easing ||
  2532. jQuery.isFunction( speed ) && speed,
  2533. duration: speed,
  2534. easing: fn && easing || easing && easing.constructor != Function && easing
  2535. };
  2536. opt.duration = (opt.duration && opt.duration.constructor == Number ?
  2537. opt.duration :
  2538. jQuery.fx.speeds[opt.duration]) || jQuery.fx.speeds.def;
  2539. // Queueing
  2540. opt.old = opt.complete;
  2541. opt.complete = function(){
  2542. if ( opt.queue !== false )
  2543. jQuery(this).dequeue();
  2544. if ( jQuery.isFunction( opt.old ) )
  2545. opt.old.call( this );
  2546. };
  2547. return opt;
  2548. },
  2549. easing: {
  2550. linear: function( p, n, firstNum, diff ) {
  2551. return firstNum + diff * p;
  2552. },
  2553. swing: function( p, n, firstNum, diff ) {
  2554. return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
  2555. }
  2556. },
  2557. timers: [],
  2558. timerId: null,
  2559. fx: function( elem, options, prop ){
  2560. this.options = options;
  2561. this.elem = elem;
  2562. this.prop = prop;
  2563. if ( !options.orig )
  2564. options.orig = {};
  2565. }
  2566. });
  2567. jQuery.fx.prototype = {
  2568. // Simple function for setting a style value
  2569. update: function(){
  2570. if ( this.options.step )
  2571. this.options.step.call( this.elem, this.now, this );
  2572. (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
  2573. // Set display property to block for height/width animations
  2574. if ( this.prop == "height" || this.prop == "width" )
  2575. this.elem.style.display = "block";
  2576. },
  2577. // Get the current size
  2578. cur: function(force){
  2579. if ( this.elem[this.prop] != null && this.elem.style[this.prop] == null )
  2580. return this.elem[ this.prop ];
  2581. var r = parseFloat(jQuery.css(this.elem, this.prop, force));
  2582. return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0;
  2583. },
  2584. // Start an animation from one number to another
  2585. custom: function(from, to, unit){
  2586. this.startTime = now();
  2587. this.start = from;
  2588. this.end = to;
  2589. this.unit = unit || this.unit || "px";
  2590. this.now = this.start;
  2591. this.pos = this.state = 0;
  2592. this.update();
  2593. var self = this;
  2594. function t(gotoEnd){
  2595. return self.step(gotoEnd);
  2596. }
  2597. t.elem = this.elem;
  2598. jQuery.timers.push(t);
  2599. if ( jQuery.timerId == null ) {
  2600. jQuery.timerId = setInterval(function(){
  2601. var timers = jQuery.timers;
  2602. for ( var i = 0; i < timers.length; i++ )
  2603. if ( !timers[i]() )
  2604. timers.splice(i--, 1);
  2605. if ( !timers.length ) {
  2606. clearInterval( jQuery.timerId );
  2607. jQuery.timerId = null;
  2608. }
  2609. }, 13);
  2610. }
  2611. },
  2612. // Simple 'show' function
  2613. show: function(){
  2614. // Remember where we started, so that we can go back to it later
  2615. this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
  2616. this.options.show = true;
  2617. // Begin the animation
  2618. this.custom(0, this.cur());
  2619. // Make sure that we start at a small width/height to avoid any
  2620. // flash of content
  2621. if ( this.prop == "width" || this.prop == "height" )
  2622. this.elem.style[this.prop] = "1px";
  2623. // Start by showing the element
  2624. jQuery(this.elem).show();
  2625. },
  2626. // Simple 'hide' function
  2627. hide: function(){
  2628. // Remember where we started, so that we can go back to it later
  2629. this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
  2630. this.options.hide = true;
  2631. // Begin the animation
  2632. this.custom(this.cur(), 0);
  2633. },
  2634. // Each step of an animation
  2635. step: function(gotoEnd){
  2636. var t = now();
  2637. if ( gotoEnd || t > this.options.duration + this.startTime ) {
  2638. this.now = this.end;
  2639. this.pos = this.state = 1;
  2640. this.update();
  2641. this.options.curAnim[ this.prop ] = true;
  2642. var done = true;
  2643. for ( var i in this.options.curAnim )
  2644. if ( this.options.curAnim[i] !== true )
  2645. done = false;
  2646. if ( done ) {
  2647. if ( this.options.display != null ) {
  2648. // Reset the overflow
  2649. this.elem.style.overflow = this.options.overflow;
  2650. // Reset the display
  2651. this.elem.style.display = this.options.display;
  2652. if ( jQuery.css(this.elem, "display") == "none" )
  2653. this.elem.style.display = "block";
  2654. }
  2655. // Hide the element if the "hide" operation was done
  2656. if ( this.options.hide )
  2657. this.elem.style.display = "none";
  2658. // Reset the properties, if the item has been hidden or shown
  2659. if ( this.options.hide || this.options.show )
  2660. for ( var p in this.options.curAnim )
  2661. jQuery.attr(this.elem.style, p, this.options.orig[p]);
  2662. }
  2663. if ( done )
  2664. // Execute the complete function
  2665. this.options.complete.call( this.elem );
  2666. return false;
  2667. } else {
  2668. var n = t - this.startTime;
  2669. this.state = n / this.options.duration;
  2670. // Perform the easing function, defaults to swing
  2671. this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration);
  2672. this.now = this.start + ((this.end - this.start) * this.pos);
  2673. // Perform the next step of the animation
  2674. this.update();
  2675. }
  2676. return true;
  2677. }
  2678. };
  2679. jQuery.extend( jQuery.fx, {
  2680. speeds:{
  2681. slow: 600,
  2682. fast: 200,
  2683. // Default speed
  2684. def: 400
  2685. },
  2686. step: {
  2687. scrollLeft: function(fx){
  2688. fx.elem.scrollLeft = fx.now;
  2689. },
  2690. scrollTop: function(fx){
  2691. fx.elem.scrollTop = fx.now;
  2692. },
  2693. opacity: function(fx){
  2694. jQuery.attr(fx.elem.style, "opacity", fx.now);
  2695. },
  2696. _default: function(fx){
  2697. fx.elem.style[ fx.prop ] = fx.now + fx.unit;
  2698. }
  2699. }
  2700. });
  2701. // The Offset Method
  2702. // Originally By Brandon Aaron, part of the Dimension Plugin
  2703. // http://jquery.com/plugins/project/dimensions
  2704. jQuery.fn.offset = function() {
  2705. var left = 0, top = 0, elem = this[0], results;
  2706. if ( elem ) with ( jQuery.browser ) {
  2707. var parent = elem.parentNode,
  2708. offsetChild = elem,
  2709. offsetParent = elem.offsetParent,
  2710. doc = elem.ownerDocument,
  2711. safari2 = safari && parseInt(version) < 522 && !/adobeair/i.test(userAgent),
  2712. css = jQuery.curCSS,
  2713. fixed = css(elem, "position") == "fixed";
  2714. // Use getBoundingClientRect if available
  2715. if ( elem.getBoundingClientRect ) {
  2716. var box = elem.getBoundingClientRect();
  2717. // Add the document scroll offsets
  2718. add(box.left + Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),
  2719. box.top + Math.max(doc.documentElement.scrollTop, doc.body.scrollTop));
  2720. // IE adds the HTML element's border, by default it is medium which is 2px
  2721. // IE 6 and 7 quirks mode the border width is overwritable by the following css html { border: 0; }
  2722. // IE 7 standards mode, the border is always 2px
  2723. // This border/offset is typically represented by the clientLeft and clientTop properties
  2724. // However, in IE6 and 7 quirks mode the clientLeft and clientTop properties are not updated when overwriting it via CSS
  2725. // Therefore this method will be off by 2px in IE while in quirksmode
  2726. add( -doc.documentElement.clientLeft, -doc.documentElement.clientTop );
  2727. // Otherwise loop through the offsetParents and parentNodes
  2728. } else {
  2729. // Initial element offsets
  2730. add( elem.offsetLeft, elem.offsetTop );
  2731. // Get parent offsets
  2732. while ( offsetParent ) {
  2733. // Add offsetParent offsets
  2734. add( offsetParent.offsetLeft, offsetParent.offsetTop );
  2735. // Mozilla and Safari > 2 does not include the border on offset parents
  2736. // However Mozilla adds the border for table or table cells
  2737. if ( mozilla && !/^t(able|d|h)$/i.test(offsetParent.tagName) || safari && !safari2 )
  2738. border( offsetParent );
  2739. // Add the document scroll offsets if position is fixed on any offsetParent
  2740. if ( !fixed && css(offsetParent, "position") == "fixed" )
  2741. fixed = true;
  2742. // Set offsetChild to previous offsetParent unless it is the body element
  2743. offsetChild = /^body$/i.test(offsetParent.tagName) ? offsetChild : offsetParent;
  2744. // Get next offsetParent
  2745. offsetParent = offsetParent.offsetParent;
  2746. }
  2747. // Get parent scroll offsets
  2748. while ( parent && parent.tagName && !/^body|html$/i.test(parent.tagName) ) {
  2749. // Remove parent scroll UNLESS that parent is inline or a table to work around Opera inline/table scrollLeft/Top bug
  2750. if ( !/^inline|table.*$/i.test(css(parent, "display")) )
  2751. // Subtract parent scroll offsets
  2752. add( -parent.scrollLeft, -parent.scrollTop );
  2753. // Mozilla does not add the border for a parent that has overflow != visible
  2754. if ( mozilla && css(parent, "overflow") != "visible" )
  2755. border( parent );
  2756. // Get next parent
  2757. parent = parent.parentNode;
  2758. }
  2759. // Safari <= 2 doubles body offsets with a fixed position element/offsetParent or absolutely positioned offsetChild
  2760. // Mozilla doubles body offsets with a non-absolutely positioned offsetChild
  2761. if ( (safari2 && (fixed || css(offsetChild, "position") == "absolute")) ||
  2762. (mozilla && css(offsetChild, "position") != "absolute") )
  2763. add( -doc.body.offsetLeft, -doc.body.offsetTop );
  2764. // Add the document scroll offsets if position is fixed
  2765. if ( fixed )
  2766. add(Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),
  2767. Math.max(doc.documentElement.scrollTop, doc.body.scrollTop));
  2768. }
  2769. // Return an object with top and left properties
  2770. results = { top: top, left: left };
  2771. }
  2772. function border(elem) {
  2773. add( jQuery.curCSS(elem, "borderLeftWidth", true), jQuery.curCSS(elem, "borderTopWidth", true) );
  2774. }
  2775. function add(l, t) {
  2776. left += parseInt(l, 10) || 0;
  2777. top += parseInt(t, 10) || 0;
  2778. }
  2779. return results;
  2780. };
  2781. jQuery.fn.extend({
  2782. position: function() {
  2783. var left = 0, top = 0, results;
  2784. if ( this[0] ) {
  2785. // Get *real* offsetParent
  2786. var offsetParent = this.offsetParent(),
  2787. // Get correct offsets
  2788. offset = this.offset(),
  2789. parentOffset = /^body|html$/i.test(offsetParent[0].tagName) ? { top: 0, left: 0 } : offsetParent.offset();
  2790. // Subtract element margins
  2791. // note: when an element has margin: auto the offsetLeft and marginLeft
  2792. // are the same in Safari causing offset.left to incorrectly be 0
  2793. offset.top -= num( this, 'marginTop' );
  2794. offset.left -= num( this, 'marginLeft' );
  2795. // Add offsetParent borders
  2796. parentOffset.top += num( offsetParent, 'borderTopWidth' );
  2797. parentOffset.left += num( offsetParent, 'borderLeftWidth' );
  2798. // Subtract the two offsets
  2799. results = {
  2800. top: offset.top - parentOffset.top,
  2801. left: offset.left - parentOffset.left
  2802. };
  2803. }
  2804. return results;
  2805. },
  2806. offsetParent: function() {
  2807. var offsetParent = this[0].offsetParent;
  2808. while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && jQuery.css(offsetParent, 'position') == 'static') )
  2809. offsetParent = offsetParent.offsetParent;
  2810. return jQuery(offsetParent);
  2811. }
  2812. });
  2813. // Create scrollLeft and scrollTop methods
  2814. jQuery.each( ['Left', 'Top'], function(i, name) {
  2815. var method = 'scroll' + name;
  2816. jQuery.fn[ method ] = function(val) {
  2817. if (!this[0]) return;
  2818. return val != undefined ?
  2819. // Set the scroll offset
  2820. this.each(function() {
  2821. this == window || this == document ?
  2822. window.scrollTo(
  2823. !i ? val : jQuery(window).scrollLeft(),
  2824. i ? val : jQuery(window).scrollTop()
  2825. ) :
  2826. this[ method ] = val;
  2827. }) :
  2828. // Return the scroll offset
  2829. this[0] == window || this[0] == document ?
  2830. self[ i ? 'pageYOffset' : 'pageXOffset' ] ||
  2831. jQuery.boxModel && document.documentElement[ method ] ||
  2832. document.body[ method ] :
  2833. this[0][ method ];
  2834. };
  2835. });
  2836. // Create innerHeight, innerWidth, outerHeight and outerWidth methods
  2837. jQuery.each([ "Height", "Width" ], function(i, name){
  2838. var tl = i ? "Left" : "Top", // top or left
  2839. br = i ? "Right" : "Bottom"; // bottom or right
  2840. // innerHeight and innerWidth
  2841. jQuery.fn["inner" + name] = function(){
  2842. return this[ name.toLowerCase() ]() +
  2843. num(this, "padding" + tl) +
  2844. num(this, "padding" + br);
  2845. };
  2846. // outerHeight and outerWidth
  2847. jQuery.fn["outer" + name] = function(margin) {
  2848. return this["inner" + name]() +
  2849. num(this, "border" + tl + "Width") +
  2850. num(this, "border" + br + "Width") +
  2851. (margin ?
  2852. num(this, "margin" + tl) + num(this, "margin" + br) : 0);
  2853. };
  2854. });})();