annotate examples/tutorial/geddit/static/jquery.js @ 611:236c351928a2 trunk

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