annotate examples/tutorial/geddit/static/jquery.js @ 615:0dc152d128f5

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