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