colonymech / docs / www / colonyscout / internal / jeditable / js / jquery-1.1b.js @ f59acf11
History | View | Annotate | Download (55.7 KB)
1 |
/* prevent execution of jQuery if included more than once */
|
---|---|
2 |
if(typeof window.jQuery == "undefined") { |
3 |
/*
|
4 |
* jQuery 1.1b - New Wave Javascript
|
5 |
*
|
6 |
* Copyright (c) 2006 John Resig (jquery.com)
|
7 |
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
8 |
* and GPL (GPL-LICENSE.txt) licenses.
|
9 |
*
|
10 |
* $Date: 2007-01-12 20:47:50 +0200 (Fri, 12 Jan 2007) $
|
11 |
* $Rev: 94 $
|
12 |
*/
|
13 |
|
14 |
// Global undefined variable
|
15 |
window.undefined = window.undefined; |
16 |
var jQuery = function(a,c) { |
17 |
// If the context is global, return a new object
|
18 |
if ( window == this ) |
19 |
return new jQuery(a,c); |
20 |
|
21 |
// Make sure that a selection was provided
|
22 |
a = a || document; |
23 |
|
24 |
// HANDLE: $(function)
|
25 |
// Shortcut for document ready
|
26 |
// Safari reports typeof on DOM NodeLists as a function
|
27 |
if ( typeof a == "function" && !a.nodeType && a[0] == undefined ) |
28 |
return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a ); |
29 |
|
30 |
// Handle HTML strings
|
31 |
if ( typeof a == "string" ) { |
32 |
// HANDLE: $(html) -> $(array)
|
33 |
var m = /^[^<]*(<.+>)[^>]*$/.exec(a); |
34 |
if ( m )
|
35 |
a = jQuery.clean( [ m[1] ] );
|
36 |
|
37 |
// HANDLE: $(expr)
|
38 |
else
|
39 |
return new jQuery( c ).find( a ); |
40 |
} |
41 |
|
42 |
return this.setArray( |
43 |
// HANDLE: $(array)
|
44 |
a.constructor == Array && a || |
45 |
|
46 |
// HANDLE: $(arraylike)
|
47 |
// Watch for when an array-like object is passed as the selector
|
48 |
(a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) || |
49 |
|
50 |
// HANDLE: $(*)
|
51 |
[ a ] ); |
52 |
}; |
53 |
|
54 |
// Map over the $ in case of overwrite
|
55 |
if ( typeof $ != "undefined" ) |
56 |
jQuery._$ = $; |
57 |
|
58 |
// Map the jQuery namespace to the '$' one
|
59 |
var $ = jQuery; |
60 |
|
61 |
jQuery.fn = jQuery.prototype = { |
62 |
jquery: "1.1b", |
63 |
|
64 |
size: function() { |
65 |
return this.length; |
66 |
}, |
67 |
|
68 |
length: 0, |
69 |
|
70 |
get: function( num ) { |
71 |
return num == undefined ? |
72 |
|
73 |
// Return a 'clean' array
|
74 |
jQuery.makeArray( this ) :
|
75 |
|
76 |
// Return just the object
|
77 |
this[num];
|
78 |
}, |
79 |
pushStack: function( a ) { |
80 |
var ret = jQuery(this); |
81 |
ret.prevObject = this;
|
82 |
return ret.setArray( a );
|
83 |
}, |
84 |
setArray: function( a ) { |
85 |
this.length = 0; |
86 |
[].push.apply( this, a );
|
87 |
return this; |
88 |
}, |
89 |
each: function( fn, args ) { |
90 |
return jQuery.each( this, fn, args ); |
91 |
}, |
92 |
index: function( obj ) { |
93 |
var pos = -1; |
94 |
this.each(function(i){ |
95 |
if ( this == obj ) pos = i; |
96 |
}); |
97 |
return pos;
|
98 |
}, |
99 |
|
100 |
attr: function( key, value, type ) { |
101 |
var obj = key;
|
102 |
|
103 |
// Look for the case where we're accessing a style value
|
104 |
if ( key.constructor == String )
|
105 |
if ( value == undefined ) |
106 |
return jQuery[ type || "attr" ]( this[0], key ); |
107 |
else {
|
108 |
obj = {}; |
109 |
obj[ key ] = value; |
110 |
} |
111 |
|
112 |
// Check to see if we're setting style values
|
113 |
return this.each(function(){ |
114 |
// Set all the styles
|
115 |
for ( var prop in obj ) |
116 |
jQuery.attr( |
117 |
type ? this.style : this, |
118 |
prop, jQuery.prop(this, obj[prop], type)
|
119 |
); |
120 |
}); |
121 |
}, |
122 |
|
123 |
css: function( key, value ) { |
124 |
return this.attr( key, value, "curCSS" ); |
125 |
}, |
126 |
|
127 |
text: function(e) { |
128 |
var type = this.length && this[0].innerText == undefined ? |
129 |
"textContent" : "innerText"; |
130 |
|
131 |
return e == undefined ? |
132 |
jQuery.map(this, function(a){ return a[ type ]; }).join('') : |
133 |
this.each(function(){ this[ type ] = e; }); |
134 |
}, |
135 |
|
136 |
wrap: function() { |
137 |
// The elements to wrap the target around
|
138 |
var a = jQuery.clean(arguments); |
139 |
|
140 |
// Wrap each of the matched elements individually
|
141 |
return this.each(function(){ |
142 |
// Clone the structure that we're using to wrap
|
143 |
var b = a[0].cloneNode(true); |
144 |
|
145 |
// Insert it before the element to be wrapped
|
146 |
this.parentNode.insertBefore( b, this ); |
147 |
|
148 |
// Find the deepest point in the wrap structure
|
149 |
while ( b.firstChild )
|
150 |
b = b.firstChild; |
151 |
|
152 |
// Move the matched element to within the wrap structure
|
153 |
b.appendChild( this );
|
154 |
}); |
155 |
}, |
156 |
append: function() { |
157 |
return this.domManip(arguments, true, 1, function(a){ |
158 |
this.appendChild( a );
|
159 |
}); |
160 |
}, |
161 |
prepend: function() { |
162 |
return this.domManip(arguments, true, -1, function(a){ |
163 |
this.insertBefore( a, this.firstChild ); |
164 |
}); |
165 |
}, |
166 |
before: function() { |
167 |
return this.domManip(arguments, false, 1, function(a){ |
168 |
this.parentNode.insertBefore( a, this ); |
169 |
}); |
170 |
}, |
171 |
after: function() { |
172 |
return this.domManip(arguments, false, -1, function(a){ |
173 |
this.parentNode.insertBefore( a, this.nextSibling ); |
174 |
}); |
175 |
}, |
176 |
end: function() { |
177 |
return this.prevObject || jQuery([]); |
178 |
}, |
179 |
find: function(t) { |
180 |
return this.pushStack( jQuery.map( this, function(a){ |
181 |
return jQuery.find(t,a);
|
182 |
}) ); |
183 |
}, |
184 |
clone: function(deep) { |
185 |
return this.pushStack( jQuery.map( this, function(a){ |
186 |
return a.cloneNode( deep != undefined ? deep : true ); |
187 |
}) ); |
188 |
}, |
189 |
|
190 |
filter: function(t) { |
191 |
return this.pushStack( |
192 |
t.constructor == Function && |
193 |
jQuery.grep(this, function(el, index){ |
194 |
return t.apply(el, [index])
|
195 |
}) || |
196 |
|
197 |
jQuery.multiFilter(t,this) );
|
198 |
}, |
199 |
|
200 |
not: function(t) { |
201 |
return this.pushStack( |
202 |
t.constructor == String && |
203 |
jQuery.multiFilter(t,this,true) || |
204 |
|
205 |
jQuery.grep(this,function(a){ |
206 |
if ( t.constructor == Array || t.jquery )
|
207 |
return !jQuery.inArray( t, a );
|
208 |
else
|
209 |
return a != t;
|
210 |
}) ); |
211 |
}, |
212 |
|
213 |
add: function(t) { |
214 |
return this.pushStack( jQuery.merge( |
215 |
this.get(),
|
216 |
typeof t == "string" ? jQuery(t).get() : t ) |
217 |
); |
218 |
}, |
219 |
is: function(expr) { |
220 |
return expr ? jQuery.filter(expr,this).r.length > 0 : false; |
221 |
}, |
222 |
|
223 |
val: function( val ) { |
224 |
return val == undefined ? |
225 |
( this.length ? this[0].value : null ) : |
226 |
this.attr( "value", val ); |
227 |
}, |
228 |
|
229 |
html: function( val ) { |
230 |
return val == undefined ? |
231 |
( this.length ? this[0].innerHTML : null ) : |
232 |
this.empty().append( val );
|
233 |
}, |
234 |
domManip: function(args, table, dir, fn){ |
235 |
var clone = this.length > 1; |
236 |
var a = jQuery.clean(args);
|
237 |
if ( dir < 0 ) |
238 |
a.reverse(); |
239 |
|
240 |
return this.each(function(){ |
241 |
var obj = this; |
242 |
|
243 |
if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" ) |
244 |
obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody")); |
245 |
|
246 |
for ( var i = 0, al = a.length; i < al; i++ ) |
247 |
fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
|
248 |
|
249 |
}); |
250 |
} |
251 |
}; |
252 |
|
253 |
jQuery.extend = jQuery.fn.extend = function() { |
254 |
// copy reference to target object
|
255 |
var target = arguments[0], |
256 |
a = 1;
|
257 |
|
258 |
// extend jQuery itself if only one argument is passed
|
259 |
if ( arguments.length == 1 ) { |
260 |
target = this;
|
261 |
a = 0;
|
262 |
} |
263 |
var prop;
|
264 |
while (prop = arguments[a++]) |
265 |
// Extend the base object
|
266 |
for ( var i in prop ) target[i] = prop[i]; |
267 |
|
268 |
// Return the modified object
|
269 |
return target;
|
270 |
}; |
271 |
|
272 |
jQuery.extend({ |
273 |
noConflict: function() { |
274 |
if ( jQuery._$ ) |
275 |
$ = jQuery._$; |
276 |
}, |
277 |
// args is for internal usage only
|
278 |
each: function( obj, fn, args ) { |
279 |
if ( obj.length == undefined ) |
280 |
for ( var i in obj ) |
281 |
fn.apply( obj[i], args || [i, obj[i]] ); |
282 |
else
|
283 |
for ( var i = 0, ol = obj.length; i < ol; i++ ) |
284 |
if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break; |
285 |
return obj;
|
286 |
}, |
287 |
|
288 |
prop: function(elem, value, type){ |
289 |
// Handle executable functions
|
290 |
if ( value.constructor == Function )
|
291 |
return value.call( elem )
|
292 |
|
293 |
// Handle passing in a number to a CSS property
|
294 |
if ( value.constructor == Number && type == "css" ) |
295 |
return value + "px"; |
296 |
|
297 |
return value;
|
298 |
}, |
299 |
|
300 |
className: {
|
301 |
// internal only, use addClass("class")
|
302 |
add: function( elem, c ){ |
303 |
jQuery.each( c.split(/\s+/), function(i, cur){ |
304 |
if ( !jQuery.className.has( elem.className, cur ) )
|
305 |
elem.className += ( elem.className ? " " : "" ) + cur; |
306 |
}); |
307 |
}, |
308 |
|
309 |
// internal only, use removeClass("class")
|
310 |
remove: function( elem, c ){ |
311 |
elem.className = c ? |
312 |
jQuery.grep( elem.className.split(/\s+/), function(cur){ |
313 |
return !jQuery.className.has( c, cur );
|
314 |
}).join(' ') : ""; |
315 |
}, |
316 |
|
317 |
// internal only, use is(".class")
|
318 |
has: function( t, c ) { |
319 |
t = t.className || t; |
320 |
return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t ); |
321 |
} |
322 |
}, |
323 |
swap: function(e,o,f) { |
324 |
for ( var i in o ) { |
325 |
e.style["old"+i] = e.style[i];
|
326 |
e.style[i] = o[i]; |
327 |
} |
328 |
f.apply( e, [] ); |
329 |
for ( var i in o ) |
330 |
e.style[i] = e.style["old"+i];
|
331 |
}, |
332 |
|
333 |
css: function(e,p) { |
334 |
if ( p == "height" || p == "width" ) { |
335 |
var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"]; |
336 |
|
337 |
for ( var i = 0, dl = d.length; i < dl; i++ ) { |
338 |
old["padding" + d[i]] = 0; |
339 |
old["border" + d[i] + "Width"] = 0; |
340 |
} |
341 |
|
342 |
jQuery.swap( e, old, function() {
|
343 |
if (jQuery.css(e,"display") != "none") { |
344 |
oHeight = e.offsetHeight; |
345 |
oWidth = e.offsetWidth; |
346 |
} else {
|
347 |
e = jQuery(e.cloneNode(true))
|
348 |
.find(":radio").removeAttr("checked").end() |
349 |
.css({ |
350 |
visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0" |
351 |
}).appendTo(e.parentNode)[0];
|
352 |
|
353 |
var parPos = jQuery.css(e.parentNode,"position"); |
354 |
if ( parPos == "" || parPos == "static" ) |
355 |
e.parentNode.style.position = "relative";
|
356 |
|
357 |
oHeight = e.clientHeight; |
358 |
oWidth = e.clientWidth; |
359 |
|
360 |
if ( parPos == "" || parPos == "static" ) |
361 |
e.parentNode.style.position = "static";
|
362 |
|
363 |
e.parentNode.removeChild(e); |
364 |
} |
365 |
}); |
366 |
|
367 |
return p == "height" ? oHeight : oWidth; |
368 |
} |
369 |
|
370 |
return jQuery.curCSS( e, p );
|
371 |
}, |
372 |
|
373 |
curCSS: function(elem, prop, force) { |
374 |
var ret;
|
375 |
|
376 |
if (prop == 'opacity' && jQuery.browser.msie) |
377 |
return jQuery.attr(elem.style, 'opacity'); |
378 |
|
379 |
if (prop == "float" || prop == "cssFloat") |
380 |
prop = jQuery.browser.msie ? "styleFloat" : "cssFloat"; |
381 |
|
382 |
if (!force && elem.style[prop])
|
383 |
ret = elem.style[prop]; |
384 |
|
385 |
else if (document.defaultView && document.defaultView.getComputedStyle) { |
386 |
|
387 |
if (prop == "cssFloat" || prop == "styleFloat") |
388 |
prop = "float";
|
389 |
|
390 |
prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase(); |
391 |
var cur = document.defaultView.getComputedStyle(elem, null); |
392 |
|
393 |
if ( cur )
|
394 |
ret = cur.getPropertyValue(prop); |
395 |
else if ( prop == 'display' ) |
396 |
ret = 'none';
|
397 |
else
|
398 |
jQuery.swap(elem, { display: 'block' }, function() { |
399 |
var c = document.defaultView.getComputedStyle(this, ''); |
400 |
ret = c && c.getPropertyValue(prop) || '';
|
401 |
}); |
402 |
|
403 |
} else if (elem.currentStyle) { |
404 |
|
405 |
var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();}); |
406 |
ret = elem.currentStyle[prop] || elem.currentStyle[newProp]; |
407 |
|
408 |
} |
409 |
|
410 |
return ret;
|
411 |
}, |
412 |
|
413 |
clean: function(a) { |
414 |
var r = [];
|
415 |
|
416 |
for ( var i = 0, al = a.length; i < al; i++ ) { |
417 |
var arg = a[i];
|
418 |
|
419 |
// Convert html string into DOM nodes
|
420 |
if ( typeof arg == "string" ) { |
421 |
// Trim whitespace, otherwise indexOf won't work as expected
|
422 |
var s = jQuery.trim(arg), div = document.createElement("div"), tb = []; |
423 |
|
424 |
var wrap =
|
425 |
// option or optgroup
|
426 |
!s.indexOf("<opt") &&
|
427 |
[1, "<select>", "</select>"] || |
428 |
|
429 |
(!s.indexOf("<thead") || !s.indexOf("<tbody") || !s.indexOf("<tfoot")) && |
430 |
[1, "<table>", "</table>"] || |
431 |
|
432 |
!s.indexOf("<tr") &&
|
433 |
[2, "<table><tbody>", "</tbody></table>"] || |
434 |
|
435 |
// <thead> matched above
|
436 |
(!s.indexOf("<td") || !s.indexOf("<th")) && |
437 |
[3, "<table><tbody><tr>", "</tr></tbody></table>"] || |
438 |
|
439 |
[0,"",""]; |
440 |
|
441 |
// Go to html and back, then peel off extra wrappers
|
442 |
div.innerHTML = wrap[1] + s + wrap[2]; |
443 |
|
444 |
// Move to the right depth
|
445 |
while ( wrap[0]-- ) |
446 |
div = div.firstChild; |
447 |
|
448 |
// Remove IE's autoinserted <tbody> from table fragments
|
449 |
if ( jQuery.browser.msie ) {
|
450 |
|
451 |
// String was a <table>, *may* have spurious <tbody>
|
452 |
if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 ) |
453 |
tb = div.firstChild && div.firstChild.childNodes; |
454 |
|
455 |
// String was a bare <thead> or <tfoot>
|
456 |
else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 ) |
457 |
tb = div.childNodes; |
458 |
|
459 |
for ( var n = tb.length-1; n >= 0 ; --n ) |
460 |
if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length ) |
461 |
tb[n].parentNode.removeChild(tb[n]); |
462 |
|
463 |
} |
464 |
|
465 |
arg = div.childNodes; |
466 |
} |
467 |
|
468 |
if ( arg[0] == undefined ) |
469 |
r.push( arg ); |
470 |
else
|
471 |
r = jQuery.merge( r, arg ); |
472 |
|
473 |
} |
474 |
|
475 |
return r;
|
476 |
}, |
477 |
|
478 |
attr: function(elem, name, value){ |
479 |
var fix = {
|
480 |
"for": "htmlFor", |
481 |
"class": "className", |
482 |
"float": jQuery.browser.msie ? "styleFloat" : "cssFloat", |
483 |
cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat", |
484 |
innerHTML: "innerHTML", |
485 |
className: "className", |
486 |
value: "value", |
487 |
disabled: "disabled", |
488 |
checked: "checked", |
489 |
readonly: "readOnly", |
490 |
selected: "selected" |
491 |
}; |
492 |
|
493 |
// IE actually uses filters for opacity ... elem is actually elem.style
|
494 |
if ( name == "opacity" && jQuery.browser.msie && value != undefined ) { |
495 |
// IE has trouble with opacity if it does not have layout
|
496 |
// Force it by setting the zoom level
|
497 |
elem.zoom = 1;
|
498 |
|
499 |
// Set the alpha filter to set the opacity
|
500 |
return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") + |
501 |
( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" ); |
502 |
|
503 |
} else if ( name == "opacity" && jQuery.browser.msie ) |
504 |
return elem.filter ?
|
505 |
parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1; |
506 |
|
507 |
// Mozilla doesn't play well with opacity 1
|
508 |
if ( name == "opacity" && jQuery.browser.mozilla && value == 1 ) |
509 |
value = 0.9999;
|
510 |
|
511 |
// Certain attributes only work when accessed via the old DOM 0 way
|
512 |
if ( fix[name] ) {
|
513 |
if ( value != undefined ) elem[fix[name]] = value; |
514 |
return elem[fix[name]];
|
515 |
|
516 |
} else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) |
517 |
return elem.getAttributeNode(name).nodeValue;
|
518 |
|
519 |
// IE elem.getAttribute passes even for style
|
520 |
else if ( elem.tagName ) { |
521 |
if ( value != undefined ) elem.setAttribute( name, value ); |
522 |
return elem.getAttribute( name );
|
523 |
|
524 |
} else {
|
525 |
name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();}); |
526 |
if ( value != undefined ) elem[name] = value; |
527 |
return elem[name];
|
528 |
} |
529 |
}, |
530 |
trim: function(t){ |
531 |
return t.replace(/^\s+|\s+$/g, ""); |
532 |
}, |
533 |
|
534 |
makeArray: function( a ) { |
535 |
var r = [];
|
536 |
|
537 |
if ( a.constructor != Array )
|
538 |
for ( var i = 0, al = a.length; i < al; i++ ) |
539 |
r.push( a[i] ); |
540 |
else
|
541 |
r = a.slice( 0 );
|
542 |
|
543 |
return r;
|
544 |
}, |
545 |
|
546 |
inArray: function( b, a ) { |
547 |
for ( var i = 0, al = a.length; i < al; i++ ) |
548 |
if ( a[i] == b )
|
549 |
return i;
|
550 |
return -1; |
551 |
}, |
552 |
merge: function(first, second) { |
553 |
var r = [].slice.call( first, 0 ); |
554 |
|
555 |
// Now check for duplicates between the two arrays
|
556 |
// and only add the unique items
|
557 |
for ( var i = 0, sl = second.length; i < sl; i++ ) |
558 |
// Check for duplicates
|
559 |
if ( jQuery.inArray( second[i], r ) == -1 ) |
560 |
// The item is unique, add it
|
561 |
first.push( second[i] ); |
562 |
|
563 |
return first;
|
564 |
}, |
565 |
grep: function(elems, fn, inv) { |
566 |
// If a string is passed in for the function, make a function
|
567 |
// for it (a handy shortcut)
|
568 |
if ( typeof fn == "string" ) |
569 |
fn = new Function("a","i","return " + fn); |
570 |
|
571 |
var result = [];
|
572 |
|
573 |
// Go through the array, only saving the items
|
574 |
// that pass the validator function
|
575 |
for ( var i = 0, el = elems.length; i < el; i++ ) |
576 |
if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
|
577 |
result.push( elems[i] ); |
578 |
|
579 |
return result;
|
580 |
}, |
581 |
map: function(elems, fn) { |
582 |
// If a string is passed in for the function, make a function
|
583 |
// for it (a handy shortcut)
|
584 |
if ( typeof fn == "string" ) |
585 |
fn = new Function("a","return " + fn); |
586 |
|
587 |
var result = [], r = [];
|
588 |
|
589 |
// Go through the array, translating each of the items to their
|
590 |
// new value (or values).
|
591 |
for ( var i = 0, el = elems.length; i < el; i++ ) { |
592 |
var val = fn(elems[i],i);
|
593 |
|
594 |
if ( val !== null && val != undefined ) { |
595 |
if ( val.constructor != Array ) val = [val];
|
596 |
result = result.concat( val ); |
597 |
} |
598 |
} |
599 |
|
600 |
var r = result.length ? [ result[0] ] : []; |
601 |
|
602 |
check: for ( var i = 1, rl = result.length; i < rl; i++ ) { |
603 |
for ( var j = 0; j < i; j++ ) |
604 |
if ( result[i] == r[j] )
|
605 |
continue check;
|
606 |
|
607 |
r.push( result[i] ); |
608 |
} |
609 |
|
610 |
return r;
|
611 |
} |
612 |
}); |
613 |
|
614 |
/*
|
615 |
* Wheather the W3C compliant box model is being used.
|
616 |
*
|
617 |
* @property
|
618 |
* @name $.boxModel
|
619 |
* @type Boolean
|
620 |
* @cat JavaScript
|
621 |
*/
|
622 |
new function() { |
623 |
var b = navigator.userAgent.toLowerCase();
|
624 |
|
625 |
// Figure out what browser is being used
|
626 |
jQuery.browser = { |
627 |
safari: /webkit/.test(b), |
628 |
opera: /opera/.test(b), |
629 |
msie: /msie/.test(b) && !/opera/.test(b), |
630 |
mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b) |
631 |
}; |
632 |
|
633 |
// Check to see if the W3C box model is being used
|
634 |
jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
|
635 |
}; |
636 |
|
637 |
jQuery.each({ |
638 |
parent: "a.parentNode", |
639 |
parents: "jQuery.parents(a)", |
640 |
next: "jQuery.nth(a,2,'nextSibling')", |
641 |
prev: "jQuery.nth(a,2,'previousSibling')", |
642 |
siblings: "jQuery.sibling(a.parentNode.firstChild,a)", |
643 |
children: "jQuery.sibling(a.firstChild)" |
644 |
}, function(i,n){
|
645 |
jQuery.fn[ i ] = function(a) {
|
646 |
var ret = jQuery.map(this,n); |
647 |
if ( a && typeof a == "string" ) |
648 |
ret = jQuery.multiFilter(a,ret); |
649 |
return this.pushStack( ret ); |
650 |
}; |
651 |
}); |
652 |
|
653 |
jQuery.each({ |
654 |
appendTo: "append", |
655 |
prependTo: "prepend", |
656 |
insertBefore: "before", |
657 |
insertAfter: "after" |
658 |
}, function(i,n){
|
659 |
jQuery.fn[ i ] = function(){
|
660 |
var a = arguments; |
661 |
return this.each(function(){ |
662 |
for ( var j = 0, al = a.length; j < al; j++ ) |
663 |
jQuery(a[j])[n]( this );
|
664 |
}); |
665 |
}; |
666 |
}); |
667 |
|
668 |
jQuery.each( { |
669 |
removeAttr: function( key ) { |
670 |
jQuery.attr( this, key, "" ); |
671 |
this.removeAttribute( key );
|
672 |
}, |
673 |
addClass: function(c){ |
674 |
jQuery.className.add(this,c);
|
675 |
}, |
676 |
removeClass: function(c){ |
677 |
jQuery.className.remove(this,c);
|
678 |
}, |
679 |
toggleClass: function( c ){ |
680 |
jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c); |
681 |
}, |
682 |
remove: function(a){ |
683 |
if ( !a || jQuery.filter( a, [this] ).r.length ) |
684 |
this.parentNode.removeChild( this ); |
685 |
}, |
686 |
empty: function() { |
687 |
while ( this.firstChild ) |
688 |
this.removeChild( this.firstChild ); |
689 |
} |
690 |
}, function(i,n){
|
691 |
jQuery.fn[ i ] = function() {
|
692 |
return this.each( n, arguments ); |
693 |
}; |
694 |
}); |
695 |
|
696 |
jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){ |
697 |
jQuery.fn[ n ] = function(num,fn) {
|
698 |
return this.filter( ":" + n + "(" + num + ")", fn ); |
699 |
}; |
700 |
}); |
701 |
|
702 |
jQuery.each( [ "height", "width" ], function(i,n){ |
703 |
jQuery.fn[ n ] = function(h) {
|
704 |
return h == undefined ? |
705 |
( this.length ? jQuery.css( this[0], n ) : null ) : |
706 |
this.css( n, h.constructor == String ? h : h + "px" ); |
707 |
}; |
708 |
}); |
709 |
jQuery.extend({ |
710 |
expr: {
|
711 |
"": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()", |
712 |
"#": "a.getAttribute('id')==m[2]", |
713 |
":": {
|
714 |
// Position Checks
|
715 |
lt: "i<m[3]-0", |
716 |
gt: "i>m[3]-0", |
717 |
nth: "m[3]-0==i", |
718 |
eq: "m[3]-0==i", |
719 |
first: "i==0", |
720 |
last: "i==r.length-1", |
721 |
even: "i%2==0", |
722 |
odd: "i%2", |
723 |
|
724 |
// Child Checks
|
725 |
"nth-child": "jQuery.nth(a.parentNode.firstChild,m[3],'nextSibling')==a", |
726 |
"first-child": "jQuery.nth(a.parentNode.firstChild,1,'nextSibling')==a", |
727 |
"last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a", |
728 |
"only-child": "jQuery.sibling(a.parentNode.firstChild).length==1", |
729 |
|
730 |
// Parent Checks
|
731 |
parent: "a.firstChild", |
732 |
empty: "!a.firstChild", |
733 |
|
734 |
// Text Check
|
735 |
contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0", |
736 |
|
737 |
// Visibility
|
738 |
visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'", |
739 |
hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'", |
740 |
|
741 |
// Form attributes
|
742 |
enabled: "!a.disabled", |
743 |
disabled: "a.disabled", |
744 |
checked: "a.checked", |
745 |
selected: "a.selected || jQuery.attr(a, 'selected')", |
746 |
|
747 |
// Form elements
|
748 |
text: "a.type=='text'", |
749 |
radio: "a.type=='radio'", |
750 |
checkbox: "a.type=='checkbox'", |
751 |
file: "a.type=='file'", |
752 |
password: "a.type=='password'", |
753 |
submit: "a.type=='submit'", |
754 |
image: "a.type=='image'", |
755 |
reset: "a.type=='reset'", |
756 |
button: "a.type=='button'||a.nodeName=='BUTTON'", |
757 |
input: "/input|select|textarea|button/i.test(a.nodeName)" |
758 |
}, |
759 |
".": "jQuery.className.has(a,m[2])", |
760 |
"@": {
|
761 |
"=": "z==m[4]", |
762 |
"!=": "z!=m[4]", |
763 |
"^=": "z && !z.indexOf(m[4])", |
764 |
"$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]", |
765 |
"*=": "z && z.indexOf(m[4])>=0", |
766 |
"": "z", |
767 |
_resort: function(m){ |
768 |
return ["", m[1], m[3], m[2], m[5]]; |
769 |
}, |
770 |
_prefix: "z=a[m[3]]||jQuery.attr(a,m[3]);" |
771 |
}, |
772 |
"[": "jQuery.find(m[2],a).length" |
773 |
}, |
774 |
|
775 |
// The regular expressions that power the parsing engine
|
776 |
parse: [
|
777 |
// Match: [@value='test'], [@foo]
|
778 |
"\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
|
779 |
|
780 |
// Match: [div], [div p]
|
781 |
"(\\[)\\s*(.*?(\\[.*?\\])?[^[]*?)\\s*\\]",
|
782 |
|
783 |
// Match: :contains('foo')
|
784 |
"(:)S\\(\"?'?(.*?(\\(.*?\\))?[^(]*?)\"?'?\\)",
|
785 |
|
786 |
// Match: :even, :last-chlid
|
787 |
"([:.#]*)S"
|
788 |
], |
789 |
|
790 |
token: [
|
791 |
"\\.\\.|/\\.\\.", "a.parentNode", |
792 |
">|/", "jQuery.sibling(a.firstChild)", |
793 |
"\\+", "jQuery.nth(a,2,'nextSibling')", |
794 |
"~", function(a){ |
795 |
var s = jQuery.sibling(a.parentNode.firstChild);
|
796 |
return s.slice(0, jQuery.inArray(a,s)); |
797 |
} |
798 |
], |
799 |
|
800 |
multiFilter: function( expr, elems, not ) { |
801 |
var old, cur = [];
|
802 |
|
803 |
while ( expr && expr != old ) {
|
804 |
old = expr; |
805 |
var f = jQuery.filter( expr, elems, not );
|
806 |
expr = f.t.replace(/^\s*,\s*/, "" ); |
807 |
cur = not ? elems = f.r : jQuery.merge( cur, f.r ); |
808 |
} |
809 |
|
810 |
return cur;
|
811 |
}, |
812 |
find: function( t, context ) { |
813 |
// Quickly handle non-string expressions
|
814 |
if ( typeof t != "string" ) |
815 |
return [ t ];
|
816 |
|
817 |
// Make sure that the context is a DOM Element
|
818 |
if ( context && !context.nodeType )
|
819 |
context = null;
|
820 |
|
821 |
// Set the correct context (if none is provided)
|
822 |
context = context || document; |
823 |
|
824 |
// Handle the common XPath // expression
|
825 |
if ( !t.indexOf("//") ) { |
826 |
context = context.documentElement; |
827 |
t = t.substr(2,t.length);
|
828 |
|
829 |
// And the / root expression
|
830 |
} else if ( !t.indexOf("/") ) { |
831 |
context = context.documentElement; |
832 |
t = t.substr(1,t.length);
|
833 |
if ( t.indexOf("/") >= 1 ) |
834 |
t = t.substr(t.indexOf("/"),t.length);
|
835 |
} |
836 |
|
837 |
// Initialize the search
|
838 |
var ret = [context], done = [], last = null; |
839 |
|
840 |
// Continue while a selector expression exists, and while
|
841 |
// we're no longer looping upon ourselves
|
842 |
while ( t && last != t ) {
|
843 |
var r = [];
|
844 |
last = t; |
845 |
|
846 |
t = jQuery.trim(t).replace( /^\/\//i, "" ); |
847 |
|
848 |
var foundToken = false; |
849 |
|
850 |
// An attempt at speeding up child selectors that
|
851 |
// point to a specific element tag
|
852 |
var re = /^[\/>]\s*([a-z0-9*-]+)/i; |
853 |
var m = re.exec(t);
|
854 |
|
855 |
if ( m ) {
|
856 |
// Perform our own iteration and filter
|
857 |
for ( var i = 0, rl = ret.length; i < rl; i++ ) |
858 |
for ( var c = ret[i].firstChild; c; c = c.nextSibling ) |
859 |
if ( c.nodeType == 1 && ( c.nodeName == m[1].toUpperCase() || m[1] == "*" ) ) |
860 |
r.push( c ); |
861 |
|
862 |
ret = r; |
863 |
t = jQuery.trim( t.replace( re, "" ) );
|
864 |
foundToken = true;
|
865 |
} else {
|
866 |
// Look for pre-defined expression tokens
|
867 |
for ( var i = 0; i < jQuery.token.length; i += 2 ) { |
868 |
// Attempt to match each, individual, token in
|
869 |
// the specified order
|
870 |
var re = new RegExp("^(" + jQuery.token[i] + ")"); |
871 |
var m = re.exec(t);
|
872 |
|
873 |
// If the token match was found
|
874 |
if ( m ) {
|
875 |
// Map it against the token's handler
|
876 |
r = ret = jQuery.map( ret, jQuery.token[i+1].constructor == Function ?
|
877 |
jQuery.token[i+1] :
|
878 |
function(a){ return eval(jQuery.token[i+1]); }); |
879 |
|
880 |
// And remove the token
|
881 |
t = jQuery.trim( t.replace( re, "" ) );
|
882 |
foundToken = true;
|
883 |
break;
|
884 |
} |
885 |
} |
886 |
} |
887 |
|
888 |
// See if there's still an expression, and that we haven't already
|
889 |
// matched a token
|
890 |
if ( t && !foundToken ) {
|
891 |
// Handle multiple expressions
|
892 |
if ( !t.indexOf(",") ) { |
893 |
// Clean the result set
|
894 |
if ( ret[0] == context ) ret.shift(); |
895 |
|
896 |
// Merge the result sets
|
897 |
jQuery.merge( done, ret ); |
898 |
|
899 |
// Reset the context
|
900 |
r = ret = [context]; |
901 |
|
902 |
// Touch up the selector string
|
903 |
t = " " + t.substr(1,t.length); |
904 |
|
905 |
} else {
|
906 |
// Optomize for the case nodeName#idName
|
907 |
var re2 = /^([a-z0-9_-]+)(#)([a-z0-9\\*_-]*)/i; |
908 |
var m = re2.exec(t);
|
909 |
|
910 |
// Re-organize the results, so that they're consistent
|
911 |
if ( m ) {
|
912 |
m = [ 0, m[2], m[3], m[1] ]; |
913 |
|
914 |
} else {
|
915 |
// Otherwise, do a traditional filter check for
|
916 |
// ID, class, and element selectors
|
917 |
re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
|
918 |
m = re2.exec(t); |
919 |
} |
920 |
|
921 |
// Try to do a global search by ID, where we can
|
922 |
if ( m[1] == "#" && ret[ret.length-1].getElementById ) { |
923 |
// Optimization for HTML document case
|
924 |
var oid = ret[ret.length-1].getElementById(m[2]); |
925 |
|
926 |
// Do a quick check for node name (where applicable) so
|
927 |
// that div#foo searches will be really fast
|
928 |
ret = r = oid && |
929 |
(!m[3] || oid.nodeName == m[3].toUpperCase()) ? [oid] : []; |
930 |
|
931 |
} else {
|
932 |
// Pre-compile a regular expression to handle class searches
|
933 |
if ( m[1] == "." ) |
934 |
var rec = new RegExp("(^|\\s)" + m[2] + "(\\s|$)"); |
935 |
|
936 |
// We need to find all descendant elements, it is more
|
937 |
// efficient to use getAll() when we are already further down
|
938 |
// the tree - we try to recognize that here
|
939 |
for ( var i = 0, rl = ret.length; i < rl; i++ ) { |
940 |
// Grab the tag name being searched for
|
941 |
var tag = m[1] != "" || m[0] == "" ? "*" : m[2]; |
942 |
|
943 |
// Handle IE7 being really dumb about <object>s
|
944 |
if ( ret[i].nodeName.toUpperCase() == "OBJECT" && tag == "*" ) |
945 |
tag = "param";
|
946 |
|
947 |
jQuery.merge( r, |
948 |
m[1] != "" && ret.length != 1 ? |
949 |
jQuery.getAll( ret[i], [], m[1], m[2], rec ) : |
950 |
ret[i].getElementsByTagName( tag ) |
951 |
); |
952 |
} |
953 |
|
954 |
// It's faster to filter by class and be done with it
|
955 |
if ( m[1] == "." && ret.length == 1 ) |
956 |
r = jQuery.grep( r, function(e) {
|
957 |
return rec.test(e.className);
|
958 |
}); |
959 |
|
960 |
// Same with ID filtering
|
961 |
if ( m[1] == "#" && ret.length == 1 ) { |
962 |
// Remember, then wipe out, the result set
|
963 |
var tmp = r;
|
964 |
r = []; |
965 |
|
966 |
// Then try to find the element with the ID
|
967 |
for ( var i = 0, tl = tmp.length; i < tl; i++ ) |
968 |
if ( tmp[i].getAttribute("id") == m[2] ) { |
969 |
r = [ tmp[i] ]; |
970 |
break;
|
971 |
} |
972 |
} |
973 |
|
974 |
ret = r; |
975 |
} |
976 |
|
977 |
t = t.replace( re2, "" );
|
978 |
} |
979 |
|
980 |
} |
981 |
|
982 |
// If a selector string still exists
|
983 |
if ( t ) {
|
984 |
// Attempt to filter it
|
985 |
var val = jQuery.filter(t,r);
|
986 |
ret = r = val.r; |
987 |
t = jQuery.trim(val.t); |
988 |
} |
989 |
} |
990 |
|
991 |
// Remove the root context
|
992 |
if ( ret && ret[0] == context ) ret.shift(); |
993 |
|
994 |
// And combine the results
|
995 |
jQuery.merge( done, ret ); |
996 |
|
997 |
return done;
|
998 |
}, |
999 |
|
1000 |
filter: function(t,r,not) { |
1001 |
// Look for common filter expressions
|
1002 |
while ( t && /^[a-z[({<*:.#]/i.test(t) ) { |
1003 |
|
1004 |
var p = jQuery.parse;
|
1005 |
|
1006 |
for ( var i = 0, pl = p.length; i < pl; i++ ) { |
1007 |
|
1008 |
// Look for, and replace, string-like sequences
|
1009 |
// and finally build a regexp out of it
|
1010 |
var re = new RegExp( |
1011 |
"^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" ); |
1012 |
|
1013 |
var m = re.exec( t );
|
1014 |
|
1015 |
if ( m ) {
|
1016 |
// Re-organize the first match
|
1017 |
if ( jQuery.expr[ m[1] ]._resort ) |
1018 |
m = jQuery.expr[ m[1] ]._resort( m );
|
1019 |
|
1020 |
// Remove what we just matched
|
1021 |
t = t.replace( re, "" );
|
1022 |
|
1023 |
break;
|
1024 |
} |
1025 |
} |
1026 |
|
1027 |
// :not() is a special case that can be optimized by
|
1028 |
// keeping it out of the expression list
|
1029 |
if ( m[1] == ":" && m[2] == "not" ) |
1030 |
r = jQuery.filter(m[3], r, true).r; |
1031 |
|
1032 |
// Handle classes as a special case (this will help to
|
1033 |
// improve the speed, as the regexp will only be compiled once)
|
1034 |
else if ( m[1] == "." ) { |
1035 |
|
1036 |
var re = new RegExp("(^|\\s)" + m[2] + "(\\s|$)"); |
1037 |
r = jQuery.grep( r, function(e){
|
1038 |
return re.test(e.className || ''); |
1039 |
}, not); |
1040 |
|
1041 |
// Otherwise, find the expression to execute
|
1042 |
} else {
|
1043 |
var f = jQuery.expr[m[1]]; |
1044 |
if ( typeof f != "string" ) |
1045 |
f = jQuery.expr[m[1]][m[2]]; |
1046 |
|
1047 |
// Build a custom macro to enclose it
|
1048 |
eval("f = function(a,i){" +
|
1049 |
( jQuery.expr[ m[1] ]._prefix || "" ) + |
1050 |
"return " + f + "}"); |
1051 |
|
1052 |
// Execute it against the current filter
|
1053 |
r = jQuery.grep( r, f, not ); |
1054 |
} |
1055 |
} |
1056 |
|
1057 |
// Return an array of filtered elements (r)
|
1058 |
// and the modified expression string (t)
|
1059 |
return { r: r, t: t }; |
1060 |
}, |
1061 |
|
1062 |
getAll: function( o, r, token, name, re ) { |
1063 |
for ( var s = o.firstChild; s; s = s.nextSibling ) |
1064 |
if ( s.nodeType == 1 ) { |
1065 |
var add = true; |
1066 |
|
1067 |
if ( token == "." ) |
1068 |
add = s.className && re.test(s.className); |
1069 |
else if ( token == "#" ) |
1070 |
add = s.getAttribute('id') == name;
|
1071 |
|
1072 |
if ( add )
|
1073 |
r.push( s ); |
1074 |
|
1075 |
if ( token == "#" && r.length ) break; |
1076 |
|
1077 |
if ( s.firstChild )
|
1078 |
jQuery.getAll( s, r, token, name, re ); |
1079 |
} |
1080 |
|
1081 |
return r;
|
1082 |
}, |
1083 |
parents: function( elem ){ |
1084 |
var matched = [];
|
1085 |
var cur = elem.parentNode;
|
1086 |
while ( cur && cur != document ) {
|
1087 |
matched.push( cur ); |
1088 |
cur = cur.parentNode; |
1089 |
} |
1090 |
return matched;
|
1091 |
}, |
1092 |
nth: function(cur,result,dir){ |
1093 |
result = result || 1;
|
1094 |
var num = 0; |
1095 |
for ( ; cur; cur = cur[dir] ) {
|
1096 |
if ( cur.nodeType == 1 ) num++; |
1097 |
if ( num == result || result == "even" && num % 2 == 0 && num > 1 || |
1098 |
result == "odd" && num % 2 == 1 ) return cur; |
1099 |
} |
1100 |
}, |
1101 |
sibling: function( n, elem ) { |
1102 |
var r = [];
|
1103 |
|
1104 |
for ( ; n; n = n.nextSibling ) {
|
1105 |
if ( n.nodeType == 1 && (!elem || n != elem) ) |
1106 |
r.push( n ); |
1107 |
} |
1108 |
|
1109 |
return r;
|
1110 |
} |
1111 |
}); |
1112 |
/*
|
1113 |
* A number of helper functions used for managing events.
|
1114 |
* Many of the ideas behind this code orignated from
|
1115 |
* Dean Edwards' addEvent library.
|
1116 |
*/
|
1117 |
jQuery.event = { |
1118 |
|
1119 |
// Bind an event to an element
|
1120 |
// Original by Dean Edwards
|
1121 |
add: function(element, type, handler, data) { |
1122 |
// For whatever reason, IE has trouble passing the window object
|
1123 |
// around, causing it to be cloned in the process
|
1124 |
if ( jQuery.browser.msie && element.setInterval != undefined ) |
1125 |
element = window; |
1126 |
|
1127 |
// if data is passed, bind to handler
|
1128 |
if( data )
|
1129 |
handler.data = data; |
1130 |
|
1131 |
// Make sure that the function being executed has a unique ID
|
1132 |
if ( !handler.guid )
|
1133 |
handler.guid = this.guid++;
|
1134 |
|
1135 |
// Init the element's event structure
|
1136 |
if (!element.events)
|
1137 |
element.events = {}; |
1138 |
|
1139 |
// Get the current list of functions bound to this event
|
1140 |
var handlers = element.events[type];
|
1141 |
|
1142 |
// If it hasn't been initialized yet
|
1143 |
if (!handlers) {
|
1144 |
// Init the event handler queue
|
1145 |
handlers = element.events[type] = {}; |
1146 |
|
1147 |
// Remember an existing handler, if it's already there
|
1148 |
if (element["on" + type]) |
1149 |
handlers[0] = element["on" + type]; |
1150 |
} |
1151 |
|
1152 |
// Add the function to the element's handler list
|
1153 |
handlers[handler.guid] = handler; |
1154 |
|
1155 |
// And bind the global event handler to the element
|
1156 |
element["on" + type] = this.handle; |
1157 |
|
1158 |
// Remember the function in a global list (for triggering)
|
1159 |
if (!this.global[type]) |
1160 |
this.global[type] = [];
|
1161 |
this.global[type].push( element );
|
1162 |
}, |
1163 |
|
1164 |
guid: 1, |
1165 |
global: {},
|
1166 |
|
1167 |
// Detach an event or set of events from an element
|
1168 |
remove: function(element, type, handler) { |
1169 |
if (element.events)
|
1170 |
if ( type && type.type )
|
1171 |
delete element.events[ type.type ][ type.handler.guid ];
|
1172 |
else if (type && element.events[type]) |
1173 |
if ( handler )
|
1174 |
delete element.events[type][handler.guid];
|
1175 |
else
|
1176 |
for ( var i in element.events[type] ) |
1177 |
delete element.events[type][i];
|
1178 |
else
|
1179 |
for ( var j in element.events ) |
1180 |
this.remove( element, j );
|
1181 |
}, |
1182 |
|
1183 |
trigger: function(type,data,element) { |
1184 |
// Clone the incoming data, if any
|
1185 |
data = jQuery.makeArray(data || []); |
1186 |
|
1187 |
// Handle a global trigger
|
1188 |
if ( !element ) {
|
1189 |
var g = this.global[type]; |
1190 |
if ( g )
|
1191 |
for ( var i = 0, gl = g.length; i < gl; i++ ) |
1192 |
this.trigger( type, data, g[i] );
|
1193 |
|
1194 |
// Handle triggering a single element
|
1195 |
} else if ( element["on" + type] ) { |
1196 |
if ( element[ type ] && element[ type ].constructor == Function )
|
1197 |
element[ type ](); |
1198 |
else {
|
1199 |
// Pass along a fake event
|
1200 |
data.unshift( this.fix({ type: type, target: element }) ); |
1201 |
|
1202 |
// Trigger the event
|
1203 |
element["on" + type].apply( element, data );
|
1204 |
} |
1205 |
} |
1206 |
}, |
1207 |
|
1208 |
handle: function(event) { |
1209 |
if ( typeof jQuery == "undefined" ) return false; |
1210 |
|
1211 |
// Empty object is for triggered events with no data
|
1212 |
event = jQuery.event.fix( event || window.event || {} ); |
1213 |
|
1214 |
// returned undefined or false
|
1215 |
var returnValue;
|
1216 |
|
1217 |
var c = this.events[event.type]; |
1218 |
|
1219 |
var args = [].slice.call( arguments, 1 ); |
1220 |
args.unshift( event ); |
1221 |
|
1222 |
for ( var j in c ) { |
1223 |
// Pass in a reference to the handler function itself
|
1224 |
// So that we can later remove it
|
1225 |
args[0].handler = c[j];
|
1226 |
args[0].data = c[j].data;
|
1227 |
|
1228 |
if ( c[j].apply( this, args ) === false ) { |
1229 |
event.preventDefault(); |
1230 |
event.stopPropagation(); |
1231 |
returnValue = false;
|
1232 |
} |
1233 |
} |
1234 |
|
1235 |
// Clean up added properties in IE to prevent memory leak
|
1236 |
if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = event.handler = event.data = null; |
1237 |
|
1238 |
return returnValue;
|
1239 |
}, |
1240 |
|
1241 |
fix: function(event) { |
1242 |
// Fix target property, if necessary
|
1243 |
if ( !event.target && event.srcElement )
|
1244 |
event.target = event.srcElement; |
1245 |
|
1246 |
// Calculate pageX/Y if missing and clientX/Y available
|
1247 |
if ( typeof event.pageX == "undefined" && typeof event.clientX != "undefined" ) { |
1248 |
var e = document.documentElement, b = document.body;
|
1249 |
event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft); |
1250 |
event.pageY = event.clientY + (e.scrollTop || b.scrollTop); |
1251 |
} |
1252 |
|
1253 |
// check if target is a textnode (safari)
|
1254 |
if (jQuery.browser.safari && event.target.nodeType == 3) { |
1255 |
// store a copy of the original event object
|
1256 |
// and clone because target is read only
|
1257 |
var originalEvent = event;
|
1258 |
event = jQuery.extend({}, originalEvent); |
1259 |
|
1260 |
// get parentnode from textnode
|
1261 |
event.target = originalEvent.target.parentNode; |
1262 |
|
1263 |
// add preventDefault and stopPropagation since
|
1264 |
// they will not work on the clone
|
1265 |
event.preventDefault = function() { |
1266 |
return originalEvent.preventDefault();
|
1267 |
}; |
1268 |
event.stopPropagation = function() { |
1269 |
return originalEvent.stopPropagation();
|
1270 |
}; |
1271 |
} |
1272 |
|
1273 |
// fix preventDefault and stopPropagation
|
1274 |
if (!event.preventDefault)
|
1275 |
event.preventDefault = function() { |
1276 |
this.returnValue = false; |
1277 |
}; |
1278 |
|
1279 |
if (!event.stopPropagation)
|
1280 |
event.stopPropagation = function() { |
1281 |
this.cancelBubble = true; |
1282 |
}; |
1283 |
|
1284 |
return event;
|
1285 |
} |
1286 |
}; |
1287 |
|
1288 |
jQuery.fn.extend({ |
1289 |
bind: function( type, data, fn ) { |
1290 |
return this.each(function(){ |
1291 |
jQuery.event.add( this, type, fn || data, data );
|
1292 |
}); |
1293 |
}, |
1294 |
one: function( type, data, fn ) { |
1295 |
return this.each(function(){ |
1296 |
jQuery.event.add( this, type, function(event) { |
1297 |
jQuery(this).unbind(event);
|
1298 |
return (fn || data).apply( this, arguments); |
1299 |
}, data); |
1300 |
}); |
1301 |
}, |
1302 |
unbind: function( type, fn ) { |
1303 |
return this.each(function(){ |
1304 |
jQuery.event.remove( this, type, fn );
|
1305 |
}); |
1306 |
}, |
1307 |
trigger: function( type, data ) { |
1308 |
return this.each(function(){ |
1309 |
jQuery.event.trigger( type, data, this );
|
1310 |
}); |
1311 |
}, |
1312 |
toggle: function() { |
1313 |
// Save reference to arguments for access in closure
|
1314 |
var a = arguments; |
1315 |
|
1316 |
return this.click(function(e) { |
1317 |
// Figure out which function to execute
|
1318 |
this.lastToggle = this.lastToggle == 0 ? 1 : 0; |
1319 |
|
1320 |
// Make sure that clicks stop
|
1321 |
e.preventDefault(); |
1322 |
|
1323 |
// and execute the function
|
1324 |
return a[this.lastToggle].apply( this, [e] ) || false; |
1325 |
}); |
1326 |
}, |
1327 |
hover: function(f,g) { |
1328 |
|
1329 |
// A private function for handling mouse 'hovering'
|
1330 |
function handleHover(e) { |
1331 |
// Check if mouse(over|out) are still within the same parent element
|
1332 |
var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget; |
1333 |
|
1334 |
// Traverse up the tree
|
1335 |
while ( p && p != this ) try { p = p.parentNode } catch(e) { p = this; }; |
1336 |
|
1337 |
// If we actually just moused on to a sub-element, ignore it
|
1338 |
if ( p == this ) return false; |
1339 |
|
1340 |
// Execute the right function
|
1341 |
return (e.type == "mouseover" ? f : g).apply(this, [e]); |
1342 |
} |
1343 |
|
1344 |
// Bind the function to the two event listeners
|
1345 |
return this.mouseover(handleHover).mouseout(handleHover); |
1346 |
}, |
1347 |
ready: function(f) { |
1348 |
// If the DOM is already ready
|
1349 |
if ( jQuery.isReady )
|
1350 |
// Execute the function immediately
|
1351 |
f.apply( document, [jQuery] ); |
1352 |
|
1353 |
// Otherwise, remember the function for later
|
1354 |
else {
|
1355 |
// Add the function to the wait list
|
1356 |
jQuery.readyList.push( function() { return f.apply(this, [jQuery]) } ); |
1357 |
} |
1358 |
|
1359 |
return this; |
1360 |
} |
1361 |
}); |
1362 |
|
1363 |
jQuery.extend({ |
1364 |
/*
|
1365 |
* All the code that makes DOM Ready work nicely.
|
1366 |
*/
|
1367 |
isReady: false, |
1368 |
readyList: [],
|
1369 |
|
1370 |
// Handle when the DOM is ready
|
1371 |
ready: function() { |
1372 |
// Make sure that the DOM is not already loaded
|
1373 |
if ( !jQuery.isReady ) {
|
1374 |
// Remember that the DOM is ready
|
1375 |
jQuery.isReady = true;
|
1376 |
|
1377 |
// If there are functions bound, to execute
|
1378 |
if ( jQuery.readyList ) {
|
1379 |
// Execute all of them
|
1380 |
for ( var i = 0; i < jQuery.readyList.length; i++ ) |
1381 |
jQuery.readyList[i].apply( document ); |
1382 |
|
1383 |
// Reset the list of functions
|
1384 |
jQuery.readyList = null;
|
1385 |
} |
1386 |
// Remove event lisenter to avoid memory leak
|
1387 |
if ( jQuery.browser.mozilla || jQuery.browser.opera )
|
1388 |
document.removeEventListener( "DOMContentLoaded", jQuery.ready, false ); |
1389 |
} |
1390 |
} |
1391 |
}); |
1392 |
|
1393 |
new function(){ |
1394 |
|
1395 |
jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
|
1396 |
"mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
|
1397 |
"submit,keydown,keypress,keyup,error").split(","), function(i,o){ |
1398 |
|
1399 |
// Handle event binding
|
1400 |
jQuery.fn[o] = function(f){
|
1401 |
return f ? this.bind(o, f) : this.trigger(o); |
1402 |
}; |
1403 |
|
1404 |
}); |
1405 |
|
1406 |
// If Mozilla is used
|
1407 |
if ( jQuery.browser.mozilla || jQuery.browser.opera )
|
1408 |
// Use the handy event callback
|
1409 |
document.addEventListener( "DOMContentLoaded", jQuery.ready, false ); |
1410 |
|
1411 |
// If IE is used, use the excellent hack by Matthias Miller
|
1412 |
// http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
|
1413 |
else if ( jQuery.browser.msie ) { |
1414 |
|
1415 |
// Only works if you document.write() it
|
1416 |
document.write("<scr" + "ipt id=__ie_init defer=true " + |
1417 |
"src=//:><\/script>");
|
1418 |
|
1419 |
// Use the defer script hack
|
1420 |
var script = document.getElementById("__ie_init"); |
1421 |
|
1422 |
// script does not exist if jQuery is loaded dynamically
|
1423 |
if ( script )
|
1424 |
script.onreadystatechange = function() { |
1425 |
if ( this.readyState != "complete" ) return; |
1426 |
this.parentNode.removeChild( this ); |
1427 |
jQuery.ready(); |
1428 |
}; |
1429 |
|
1430 |
// Clear from memory
|
1431 |
script = null;
|
1432 |
|
1433 |
// If Safari is used
|
1434 |
} else if ( jQuery.browser.safari ) |
1435 |
// Continually check to see if the document.readyState is valid
|
1436 |
jQuery.safariTimer = setInterval(function(){
|
1437 |
// loaded and complete are both valid states
|
1438 |
if ( document.readyState == "loaded" || |
1439 |
document.readyState == "complete" ) {
|
1440 |
|
1441 |
// If either one are found, remove the timer
|
1442 |
clearInterval( jQuery.safariTimer ); |
1443 |
jQuery.safariTimer = null;
|
1444 |
|
1445 |
// and execute any waiting functions
|
1446 |
jQuery.ready(); |
1447 |
} |
1448 |
}, 10);
|
1449 |
|
1450 |
// A fallback to window.onload, that will always work
|
1451 |
jQuery.event.add( window, "load", jQuery.ready );
|
1452 |
|
1453 |
}; |
1454 |
|
1455 |
// Clean up after IE to avoid memory leaks
|
1456 |
if (jQuery.browser.msie)
|
1457 |
jQuery(window).one("unload", function() { |
1458 |
var global = jQuery.event.global;
|
1459 |
for ( var type in global ) { |
1460 |
var els = global[type], i = els.length;
|
1461 |
if ( i && type != 'unload' ) |
1462 |
do
|
1463 |
jQuery.event.remove(els[i-1], type);
|
1464 |
while (--i);
|
1465 |
} |
1466 |
}); |
1467 |
jQuery.fn.extend({ |
1468 |
|
1469 |
show: function(speed,callback){ |
1470 |
var hidden = this.filter(":hidden"); |
1471 |
speed ? |
1472 |
hidden.animate({ |
1473 |
height: "show", width: "show", opacity: "show" |
1474 |
}, speed, callback) : |
1475 |
|
1476 |
hidden.each(function(){
|
1477 |
this.style.display = this.oldblock ? this.oldblock : ""; |
1478 |
if ( jQuery.css(this,"display") == "none" ) |
1479 |
this.style.display = "block"; |
1480 |
}); |
1481 |
return this; |
1482 |
}, |
1483 |
|
1484 |
hide: function(speed,callback){ |
1485 |
var visible = this.filter(":visible"); |
1486 |
speed ? |
1487 |
visible.animate({ |
1488 |
height: "hide", width: "hide", opacity: "hide" |
1489 |
}, speed, callback) : |
1490 |
|
1491 |
visible.each(function(){
|
1492 |
this.oldblock = this.oldblock || jQuery.css(this,"display"); |
1493 |
if ( this.oldblock == "none" ) |
1494 |
this.oldblock = "block"; |
1495 |
this.style.display = "none"; |
1496 |
}); |
1497 |
return this; |
1498 |
}, |
1499 |
|
1500 |
// Save the old toggle function
|
1501 |
_toggle: jQuery.fn.toggle,
|
1502 |
toggle: function( fn, fn2 ){ |
1503 |
return fn ?
|
1504 |
this._toggle( fn, fn2 ) :
|
1505 |
this.each(function(){ |
1506 |
jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ] |
1507 |
.apply( jQuery(this), arguments ); |
1508 |
}); |
1509 |
}, |
1510 |
slideDown: function(speed,callback){ |
1511 |
return this.animate({height: "show"}, speed, callback); |
1512 |
}, |
1513 |
slideUp: function(speed,callback){ |
1514 |
return this.animate({height: "hide"}, speed, callback); |
1515 |
}, |
1516 |
slideToggle: function(speed, callback){ |
1517 |
return this.each(function(){ |
1518 |
var state = jQuery(this).is(":hidden") ? "show" : "hide"; |
1519 |
jQuery(this).animate({height: state}, speed, callback); |
1520 |
}); |
1521 |
}, |
1522 |
fadeIn: function(speed, callback){ |
1523 |
return this.animate({opacity: "show"}, speed, callback); |
1524 |
}, |
1525 |
fadeOut: function(speed, callback){ |
1526 |
return this.animate({opacity: "hide"}, speed, callback); |
1527 |
}, |
1528 |
fadeTo: function(speed,to,callback){ |
1529 |
return this.animate({opacity: to}, speed, callback); |
1530 |
}, |
1531 |
animate: function( prop, speed, easing, callback ) { |
1532 |
return this.queue(function(){ |
1533 |
|
1534 |
this.curAnim = jQuery.extend({}, prop);
|
1535 |
var opt = jQuery.speed(speed, easing, callback);
|
1536 |
|
1537 |
for ( var p in prop ) { |
1538 |
var e = new jQuery.fx( this, opt, p ); |
1539 |
if ( prop[p].constructor == Number )
|
1540 |
e.custom( e.cur(), prop[p] ); |
1541 |
else
|
1542 |
e[ prop[p] ]( prop ); |
1543 |
} |
1544 |
|
1545 |
}); |
1546 |
}, |
1547 |
queue: function(type,fn){ |
1548 |
if ( !fn ) {
|
1549 |
fn = type; |
1550 |
type = "fx";
|
1551 |
} |
1552 |
|
1553 |
return this.each(function(){ |
1554 |
if ( !this.queue ) |
1555 |
this.queue = {};
|
1556 |
|
1557 |
if ( !this.queue[type] ) |
1558 |
this.queue[type] = [];
|
1559 |
|
1560 |
this.queue[type].push( fn );
|
1561 |
|
1562 |
if ( this.queue[type].length == 1 ) |
1563 |
fn.apply(this);
|
1564 |
}); |
1565 |
} |
1566 |
|
1567 |
}); |
1568 |
|
1569 |
jQuery.extend({ |
1570 |
|
1571 |
speed: function(speed, easing, fn) { |
1572 |
var opt = speed && speed.constructor == Object ? speed : {
|
1573 |
complete: fn || !fn && easing ||
|
1574 |
speed && speed.constructor == Function && speed, |
1575 |
duration: speed,
|
1576 |
easing: fn && easing || easing && easing.constructor != Function && easing
|
1577 |
}; |
1578 |
|
1579 |
opt.duration = (opt.duration && opt.duration.constructor == Number ? |
1580 |
opt.duration : |
1581 |
{ slow: 600, fast: 200 }[opt.duration]) || 400; |
1582 |
|
1583 |
// Queueing
|
1584 |
opt.oldComplete = opt.complete; |
1585 |
opt.complete = function(){ |
1586 |
jQuery.dequeue(this, "fx"); |
1587 |
if ( opt.oldComplete && opt.oldComplete.constructor == Function )
|
1588 |
opt.oldComplete.apply( this );
|
1589 |
}; |
1590 |
|
1591 |
return opt;
|
1592 |
}, |
1593 |
|
1594 |
easing: {},
|
1595 |
|
1596 |
queue: {},
|
1597 |
|
1598 |
dequeue: function(elem,type){ |
1599 |
type = type || "fx";
|
1600 |
|
1601 |
if ( elem.queue && elem.queue[type] ) {
|
1602 |
// Remove self
|
1603 |
elem.queue[type].shift(); |
1604 |
|
1605 |
// Get next function
|
1606 |
var f = elem.queue[type][0]; |
1607 |
|
1608 |
if ( f ) f.apply( elem );
|
1609 |
} |
1610 |
}, |
1611 |
|
1612 |
/*
|
1613 |
* I originally wrote fx() as a clone of moo.fx and in the process
|
1614 |
* of making it small in size the code became illegible to sane
|
1615 |
* people. You've been warned.
|
1616 |
*/
|
1617 |
|
1618 |
fx: function( elem, options, prop ){ |
1619 |
|
1620 |
var z = this; |
1621 |
|
1622 |
// The styles
|
1623 |
var y = elem.style;
|
1624 |
|
1625 |
// Store display property
|
1626 |
var oldDisplay = jQuery.css(elem, 'display'); |
1627 |
// Set display property to block for animation
|
1628 |
y.display = "block";
|
1629 |
// Make sure that nothing sneaks out
|
1630 |
y.overflow = "hidden";
|
1631 |
|
1632 |
// Simple function for setting a style value
|
1633 |
z.a = function(){ |
1634 |
if ( options.step )
|
1635 |
options.step.apply( elem, [ z.now ] ); |
1636 |
|
1637 |
if ( prop == "opacity" ) |
1638 |
jQuery.attr(y, "opacity", z.now); // Let attr handle opacity |
1639 |
else if ( parseInt(z.now) ) // My hate for IE will never die |
1640 |
y[prop] = parseInt(z.now) + "px";
|
1641 |
}; |
1642 |
|
1643 |
// Figure out the maximum number to run to
|
1644 |
z.max = function(){ |
1645 |
return parseFloat( jQuery.css(elem,prop) );
|
1646 |
}; |
1647 |
|
1648 |
// Get the current size
|
1649 |
z.cur = function(){ |
1650 |
var r = parseFloat( jQuery.curCSS(elem, prop) );
|
1651 |
return r && r > -10000 ? r : z.max(); |
1652 |
}; |
1653 |
|
1654 |
// Start an animation from one number to another
|
1655 |
z.custom = function(from,to){ |
1656 |
z.startTime = (new Date()).getTime();
|
1657 |
z.now = from; |
1658 |
z.a(); |
1659 |
|
1660 |
z.timer = setInterval(function(){
|
1661 |
z.step(from, to); |
1662 |
}, 13);
|
1663 |
}; |
1664 |
|
1665 |
// Simple 'show' function
|
1666 |
z.show = function(){ |
1667 |
if ( !elem.orig ) elem.orig = {};
|
1668 |
|
1669 |
// Remember where we started, so that we can go back to it later
|
1670 |
elem.orig[prop] = this.cur();
|
1671 |
|
1672 |
options.show = true;
|
1673 |
|
1674 |
// Begin the animation
|
1675 |
z.custom(0, elem.orig[prop]);
|
1676 |
|
1677 |
// Stupid IE, look what you made me do
|
1678 |
if ( prop != "opacity" ) |
1679 |
y[prop] = "1px";
|
1680 |
}; |
1681 |
|
1682 |
// Simple 'hide' function
|
1683 |
z.hide = function(){ |
1684 |
if ( !elem.orig ) elem.orig = {};
|
1685 |
|
1686 |
// Remember where we started, so that we can go back to it later
|
1687 |
elem.orig[prop] = this.cur();
|
1688 |
|
1689 |
options.hide = true;
|
1690 |
|
1691 |
// Begin the animation
|
1692 |
z.custom(elem.orig[prop], 0);
|
1693 |
}; |
1694 |
|
1695 |
//Simple 'toggle' function
|
1696 |
z.toggle = function() { |
1697 |
if ( !elem.orig ) elem.orig = {};
|
1698 |
|
1699 |
// Remember where we started, so that we can go back to it later
|
1700 |
elem.orig[prop] = this.cur();
|
1701 |
|
1702 |
if(oldDisplay == 'none') { |
1703 |
options.show = true;
|
1704 |
|
1705 |
// Stupid IE, look what you made me do
|
1706 |
if ( prop != "opacity" ) |
1707 |
y[prop] = "1px";
|
1708 |
|
1709 |
// Begin the animation
|
1710 |
z.custom(0, elem.orig[prop]);
|
1711 |
} else {
|
1712 |
options.hide = true;
|
1713 |
|
1714 |
// Begin the animation
|
1715 |
z.custom(elem.orig[prop], 0);
|
1716 |
} |
1717 |
}; |
1718 |
|
1719 |
// Each step of an animation
|
1720 |
z.step = function(firstNum, lastNum){ |
1721 |
var t = (new Date()).getTime(); |
1722 |
|
1723 |
if (t > options.duration + z.startTime) {
|
1724 |
// Stop the timer
|
1725 |
clearInterval(z.timer); |
1726 |
z.timer = null;
|
1727 |
|
1728 |
z.now = lastNum; |
1729 |
z.a(); |
1730 |
|
1731 |
if (elem.curAnim) elem.curAnim[ prop ] = true; |
1732 |
|
1733 |
var done = true; |
1734 |
for ( var i in elem.curAnim ) |
1735 |
if ( elem.curAnim[i] !== true ) |
1736 |
done = false;
|
1737 |
|
1738 |
if ( done ) {
|
1739 |
// Reset the overflow
|
1740 |
y.overflow = '';
|
1741 |
|
1742 |
// Reset the display
|
1743 |
y.display = oldDisplay; |
1744 |
if (jQuery.css(elem, 'display') == 'none') |
1745 |
y.display = 'block';
|
1746 |
|
1747 |
// Hide the element if the "hide" operation was done
|
1748 |
if ( options.hide )
|
1749 |
y.display = 'none';
|
1750 |
|
1751 |
// Reset the properties, if the item has been hidden or shown
|
1752 |
if ( options.hide || options.show )
|
1753 |
for ( var p in elem.curAnim ) |
1754 |
if (p == "opacity") |
1755 |
jQuery.attr(y, p, elem.orig[p]); |
1756 |
else
|
1757 |
y[p] = '';
|
1758 |
} |
1759 |
|
1760 |
// If a callback was provided, execute it
|
1761 |
if ( done && options.complete && options.complete.constructor == Function )
|
1762 |
// Execute the complete function
|
1763 |
options.complete.apply( elem ); |
1764 |
} else {
|
1765 |
var n = t - this.startTime; |
1766 |
// Figure out where in the animation we are and set the number
|
1767 |
var p = n / options.duration;
|
1768 |
|
1769 |
// If the easing function exists, then use it
|
1770 |
z.now = options.easing && jQuery.easing[options.easing] ? |
1771 |
jQuery.easing[options.easing](p, n, firstNum, (lastNum-firstNum), options.duration) : |
1772 |
// else use default linear easing
|
1773 |
((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum; |
1774 |
|
1775 |
// Perform the next step of the animation
|
1776 |
z.a(); |
1777 |
} |
1778 |
}; |
1779 |
|
1780 |
} |
1781 |
}); |
1782 |
jQuery.fn.extend({ |
1783 |
loadIfModified: function( url, params, callback ) { |
1784 |
this.load( url, params, callback, 1 ); |
1785 |
}, |
1786 |
load: function( url, params, callback, ifModified ) { |
1787 |
if ( url.constructor == Function )
|
1788 |
return this.bind("load", url); |
1789 |
|
1790 |
callback = callback || function(){};
|
1791 |
|
1792 |
// Default to a GET request
|
1793 |
var type = "GET"; |
1794 |
|
1795 |
// If the second parameter was provided
|
1796 |
if ( params )
|
1797 |
// If it's a function
|
1798 |
if ( params.constructor == Function ) {
|
1799 |
// We assume that it's the callback
|
1800 |
callback = params; |
1801 |
params = null;
|
1802 |
|
1803 |
// Otherwise, build a param string
|
1804 |
} else {
|
1805 |
params = jQuery.param( params ); |
1806 |
type = "POST";
|
1807 |
} |
1808 |
|
1809 |
var self = this; |
1810 |
|
1811 |
// Request the remote document
|
1812 |
jQuery.ajax({ |
1813 |
url: url,
|
1814 |
type: type,
|
1815 |
data: params,
|
1816 |
ifModified: ifModified,
|
1817 |
complete: function(res, status){ |
1818 |
if ( status == "success" || !ifModified && status == "notmodified" ) |
1819 |
// Inject the HTML into all the matched elements
|
1820 |
self.attr("innerHTML", res.responseText)
|
1821 |
// Execute all the scripts inside of the newly-injected HTML
|
1822 |
.evalScripts() |
1823 |
// Execute callback
|
1824 |
.each( callback, [res.responseText, status, res] ); |
1825 |
else
|
1826 |
callback.apply( self, [res.responseText, status, res] ); |
1827 |
} |
1828 |
}); |
1829 |
return this; |
1830 |
}, |
1831 |
serialize: function() { |
1832 |
return jQuery.param( this ); |
1833 |
}, |
1834 |
evalScripts: function() { |
1835 |
return this.find('script').each(function(){ |
1836 |
if ( this.src ) |
1837 |
jQuery.getScript( this.src );
|
1838 |
else
|
1839 |
jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" ); |
1840 |
}).end(); |
1841 |
} |
1842 |
|
1843 |
}); |
1844 |
|
1845 |
// If IE is used, create a wrapper for the XMLHttpRequest object
|
1846 |
if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" ) |
1847 |
XMLHttpRequest = function(){ |
1848 |
return new ActiveXObject("Microsoft.XMLHTTP"); |
1849 |
}; |
1850 |
|
1851 |
// Attach a bunch of functions for handling common AJAX events
|
1852 |
|
1853 |
jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","), function(i,o){ |
1854 |
jQuery.fn[o] = function(f){
|
1855 |
return this.bind(o, f); |
1856 |
}; |
1857 |
}); |
1858 |
|
1859 |
jQuery.extend({ |
1860 |
get: function( url, data, callback, type, ifModified ) { |
1861 |
// shift arguments if data argument was ommited
|
1862 |
if ( data && data.constructor == Function ) {
|
1863 |
callback = data; |
1864 |
data = null;
|
1865 |
} |
1866 |
|
1867 |
return jQuery.ajax({
|
1868 |
url: url,
|
1869 |
data: data,
|
1870 |
success: callback,
|
1871 |
dataType: type,
|
1872 |
ifModified: ifModified
|
1873 |
}); |
1874 |
}, |
1875 |
getIfModified: function( url, data, callback, type ) { |
1876 |
return jQuery.get(url, data, callback, type, 1); |
1877 |
}, |
1878 |
getScript: function( url, callback ) { |
1879 |
return jQuery.get(url, null, callback, "script"); |
1880 |
}, |
1881 |
getJSON: function( url, data, callback ) { |
1882 |
return jQuery.get(url, data, callback, "json"); |
1883 |
}, |
1884 |
post: function( url, data, callback, type ) { |
1885 |
return jQuery.ajax({
|
1886 |
type: "POST", |
1887 |
url: url,
|
1888 |
data: data,
|
1889 |
success: callback,
|
1890 |
dataType: type
|
1891 |
}); |
1892 |
}, |
1893 |
|
1894 |
// timeout (ms)
|
1895 |
//timeout: 0,
|
1896 |
ajaxTimeout: function( timeout ) { |
1897 |
jQuery.ajaxSettings.timeout = timeout; |
1898 |
}, |
1899 |
ajaxSetup: function( settings ) { |
1900 |
jQuery.extend( jQuery.ajaxSettings, settings ); |
1901 |
}, |
1902 |
|
1903 |
ajaxSettings: {
|
1904 |
global: true, |
1905 |
type: "GET", |
1906 |
timeout: 0, |
1907 |
contentType: "application/x-www-form-urlencoded", |
1908 |
processData: true, |
1909 |
async: true |
1910 |
}, |
1911 |
|
1912 |
// Last-Modified header cache for next request
|
1913 |
lastModified: {},
|
1914 |
ajax: function( s ) { |
1915 |
// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
|
1916 |
s = jQuery.extend({}, jQuery.ajaxSettings, s); |
1917 |
|
1918 |
// if data available
|
1919 |
if ( s.data ) {
|
1920 |
// convert data if not already a string
|
1921 |
if (s.processData && typeof s.data != 'string') |
1922 |
s.data = jQuery.param(s.data); |
1923 |
// append data to url for get requests
|
1924 |
if( s.type.toLowerCase() == "get" ) |
1925 |
// "?" + data or "&" + data (in case there are already params)
|
1926 |
s.url += ((s.url.indexOf("?") > -1) ? "&" : "?") + s.data; |
1927 |
} |
1928 |
|
1929 |
// Watch for a new set of requests
|
1930 |
if ( s.global && ! jQuery.active++ )
|
1931 |
jQuery.event.trigger( "ajaxStart" );
|
1932 |
|
1933 |
var requestDone = false; |
1934 |
|
1935 |
// Create the request object
|
1936 |
var xml = new XMLHttpRequest(); |
1937 |
|
1938 |
// Open the socket
|
1939 |
xml.open(s.type, s.url, s.async); |
1940 |
|
1941 |
// Set the correct header, if data is being sent
|
1942 |
if ( s.data )
|
1943 |
xml.setRequestHeader("Content-Type", s.contentType);
|
1944 |
|
1945 |
// Set the If-Modified-Since header, if ifModified mode.
|
1946 |
if ( s.ifModified )
|
1947 |
xml.setRequestHeader("If-Modified-Since",
|
1948 |
jQuery.lastModified[s.url] || "Thu, 01 Jan 1970 00:00:00 GMT" );
|
1949 |
|
1950 |
// Set header so the called script knows that it's an XMLHttpRequest
|
1951 |
xml.setRequestHeader("X-Requested-With", "XMLHttpRequest"); |
1952 |
|
1953 |
// Make sure the browser sends the right content length
|
1954 |
if ( xml.overrideMimeType )
|
1955 |
xml.setRequestHeader("Connection", "close"); |
1956 |
|
1957 |
// Allow custom headers/mimetypes
|
1958 |
if( s.beforeSend )
|
1959 |
s.beforeSend(xml); |
1960 |
|
1961 |
if ( s.global )
|
1962 |
jQuery.event.trigger("ajaxSend", [xml, s]);
|
1963 |
|
1964 |
// Wait for a response to come back
|
1965 |
var onreadystatechange = function(isTimeout){ |
1966 |
// The transfer is complete and the data is available, or the request timed out
|
1967 |
if ( xml && (xml.readyState == 4 || isTimeout == "timeout") ) { |
1968 |
requestDone = true;
|
1969 |
var status;
|
1970 |
try {
|
1971 |
status = jQuery.httpSuccess( xml ) && isTimeout != "timeout" ?
|
1972 |
s.ifModified && jQuery.httpNotModified( xml, s.url ) ? "notmodified" : "success" : "error"; |
1973 |
// Make sure that the request was successful or notmodified
|
1974 |
if ( status != "error" ) { |
1975 |
// Cache Last-Modified header, if ifModified mode.
|
1976 |
var modRes;
|
1977 |
try {
|
1978 |
modRes = xml.getResponseHeader("Last-Modified");
|
1979 |
} catch(e) {} // swallow exception thrown by FF if header is not available |
1980 |
|
1981 |
if ( s.ifModified && modRes )
|
1982 |
jQuery.lastModified[s.url] = modRes; |
1983 |
|
1984 |
// process the data (runs the xml through httpData regardless of callback)
|
1985 |
var data = jQuery.httpData( xml, s.dataType );
|
1986 |
|
1987 |
// If a local callback was specified, fire it and pass it the data
|
1988 |
if ( s.success )
|
1989 |
s.success( data, status ); |
1990 |
|
1991 |
// Fire the global callback
|
1992 |
if( s.global )
|
1993 |
jQuery.event.trigger( "ajaxSuccess", [xml, s] );
|
1994 |
} else
|
1995 |
jQuery.handleError(s, xml, status); |
1996 |
} catch(e) {
|
1997 |
status = "error";
|
1998 |
jQuery.handleError(s, xml, status, e); |
1999 |
} |
2000 |
|
2001 |
// The request was completed
|
2002 |
if( s.global )
|
2003 |
jQuery.event.trigger( "ajaxComplete", [xml, s] );
|
2004 |
|
2005 |
// Handle the global AJAX counter
|
2006 |
if ( s.global && ! --jQuery.active )
|
2007 |
jQuery.event.trigger( "ajaxStop" );
|
2008 |
|
2009 |
// Process result
|
2010 |
if ( s.complete )
|
2011 |
s.complete(xml, status); |
2012 |
|
2013 |
// Stop memory leaks
|
2014 |
xml.onreadystatechange = function(){}; |
2015 |
xml = null;
|
2016 |
} |
2017 |
}; |
2018 |
xml.onreadystatechange = onreadystatechange; |
2019 |
|
2020 |
// Timeout checker
|
2021 |
if ( s.timeout > 0 ) |
2022 |
setTimeout(function(){
|
2023 |
// Check to see if the request is still happening
|
2024 |
if ( xml ) {
|
2025 |
// Cancel the request
|
2026 |
xml.abort(); |
2027 |
|
2028 |
if( !requestDone )
|
2029 |
onreadystatechange( "timeout" );
|
2030 |
} |
2031 |
}, s.timeout); |
2032 |
|
2033 |
// save non-leaking reference
|
2034 |
var xml2 = xml;
|
2035 |
|
2036 |
// Send the data
|
2037 |
try {
|
2038 |
xml2.send(s.data); |
2039 |
} catch(e) {
|
2040 |
jQuery.handleError(s, xml, null, e);
|
2041 |
} |
2042 |
|
2043 |
// firefox 1.5 doesn't fire statechange for sync requests
|
2044 |
if ( !s.async )
|
2045 |
onreadystatechange(); |
2046 |
|
2047 |
// return XMLHttpRequest to allow aborting the request etc.
|
2048 |
return xml2;
|
2049 |
}, |
2050 |
|
2051 |
handleError: function( s, xml, status, e ) { |
2052 |
// If a local callback was specified, fire it
|
2053 |
if ( s.error ) s.error( xml, status, e );
|
2054 |
|
2055 |
// Fire the global callback
|
2056 |
if ( s.global )
|
2057 |
jQuery.event.trigger( "ajaxError", [xml, s, e] );
|
2058 |
}, |
2059 |
|
2060 |
// Counter for holding the number of active queries
|
2061 |
active: 0, |
2062 |
|
2063 |
// Determines if an XMLHttpRequest was successful or not
|
2064 |
httpSuccess: function( r ) { |
2065 |
try {
|
2066 |
return !r.status && location.protocol == "file:" || |
2067 |
( r.status >= 200 && r.status < 300 ) || r.status == 304 || |
2068 |
jQuery.browser.safari && r.status == undefined;
|
2069 |
} catch(e){}
|
2070 |
return false; |
2071 |
}, |
2072 |
|
2073 |
// Determines if an XMLHttpRequest returns NotModified
|
2074 |
httpNotModified: function( xml, url ) { |
2075 |
try {
|
2076 |
var xmlRes = xml.getResponseHeader("Last-Modified"); |
2077 |
|
2078 |
// Firefox always returns 200. check Last-Modified date
|
2079 |
return xml.status == 304 || xmlRes == jQuery.lastModified[url] || |
2080 |
jQuery.browser.safari && xml.status == undefined;
|
2081 |
} catch(e){}
|
2082 |
return false; |
2083 |
}, |
2084 |
|
2085 |
/* Get the data out of an XMLHttpRequest.
|
2086 |
* Return parsed XML if content-type header is "xml" and type is "xml" or omitted,
|
2087 |
* otherwise return plain text.
|
2088 |
* (String) data - The type of data that you're expecting back,
|
2089 |
* (e.g. "xml", "html", "script")
|
2090 |
*/
|
2091 |
httpData: function( r, type ) { |
2092 |
var ct = r.getResponseHeader("content-type"); |
2093 |
var data = !type && ct && ct.indexOf("xml") >= 0; |
2094 |
data = type == "xml" || data ? r.responseXML : r.responseText;
|
2095 |
|
2096 |
// If the type is "script", eval it in global context
|
2097 |
if ( type == "script" ) |
2098 |
jQuery.globalEval( data ); |
2099 |
|
2100 |
// Get the JavaScript object, if JSON is used.
|
2101 |
if ( type == "json" ) |
2102 |
eval( "data = " + data );
|
2103 |
|
2104 |
// evaluate scripts within html
|
2105 |
if ( type == "html" ) |
2106 |
jQuery("<div>").html(data).evalScripts();
|
2107 |
|
2108 |
return data;
|
2109 |
}, |
2110 |
|
2111 |
// Serialize an array of form elements or a set of
|
2112 |
// key/values into a query string
|
2113 |
param: function( a ) { |
2114 |
var s = [];
|
2115 |
|
2116 |
// If an array was passed in, assume that it is an array
|
2117 |
// of form elements
|
2118 |
if ( a.constructor == Array || a.jquery )
|
2119 |
// Serialize the form elements
|
2120 |
for ( var i = 0; i < a.length; i++ ) |
2121 |
s.push( encodeURIComponent(a[i].name) + "=" + encodeURIComponent( a[i].value ) );
|
2122 |
|
2123 |
// Otherwise, assume that it's an object of key/value pairs
|
2124 |
else
|
2125 |
// Serialize the key/values
|
2126 |
for ( var j in a ) |
2127 |
// If the value is an array then the key names need to be repeated
|
2128 |
if ( a[j].constructor == Array )
|
2129 |
for ( var k = 0; k < a[j].length; k++ ) |
2130 |
s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j][k] ) );
|
2131 |
else
|
2132 |
s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );
|
2133 |
|
2134 |
// Return the resulting serialization
|
2135 |
return s.join("&"); |
2136 |
}, |
2137 |
|
2138 |
// evalulates a script in global context
|
2139 |
// not reliable for safari
|
2140 |
globalEval: function( data ) { |
2141 |
if ( window.execScript )
|
2142 |
window.execScript( data ); |
2143 |
else if ( jQuery.browser.safari ) |
2144 |
// safari doesn't provide a synchronous global eval
|
2145 |
window.setTimeout( data, 0 );
|
2146 |
else
|
2147 |
eval.call( window, data ); |
2148 |
} |
2149 |
|
2150 |
}); |
2151 |
} // close: if(typeof window.jQuery == "undefined") {
|