Changeset 4222
- Timestamp:
- 12/18/07 23:50:20 (1 year ago)
- Location:
- trunk/plugins/validate
- Files:
-
- 2 modified
-
lib/jquery.js (modified) (16 diffs)
-
test/events.html (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/validate/lib/jquery.js
r4188 r4222 7 7 * and GPL (GPL-LICENSE.txt) licenses. 8 8 * 9 * $Date: 2007-12-1 6 02:03:50 +0100 (Son, 16Dez 2007) $10 * $Rev: 4 171$9 * $Date: 2007-12-18 18:19:33 +0100 (Di, 18 Dez 2007) $ 10 * $Rev: 4220 $ 11 11 */ 12 12 … … 354 354 selector = jQuery.multiFilter( selector, this ); 355 355 356 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType; 356 357 return this.filter(function() { 357 return jQuery.inArray( this, selector ) < 0;358 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector; 358 359 }); 359 360 }, … … 420 421 } 421 422 423 return undefined; 422 424 } 423 425 … … 765 767 // A method for quickly swapping in/out CSS properties to get correct calculations 766 768 swap: function( elem, options, callback ) { 769 var old = {}; 767 770 // Remember the old values, and insert the new ones 768 771 for ( var name in options ) { 769 elem.style[ "old" +name ] = elem.style[ name ];772 old[ name ] = elem.style[ name ]; 770 773 elem.style[ name ] = options[ name ]; 771 774 } … … 775 778 // Revert the old values 776 779 for ( var name in options ) 777 elem.style[ name ] = elem.style[ "old" +name ];780 elem.style[ name ] = old[ name ]; 778 781 }, 779 782 780 783 css: function( elem, name, force ) { 781 784 if ( name == "width" || name == "height" ) { 782 var width, height, props = { position: "absolute", visibility: "hidden", display:"block" };785 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ]; 783 786 784 787 function getWH() { 785 width = elem.clientWidth; 786 height = elem.clientHeight; 788 val = name == "width" ? elem.offsetWidth : elem.offsetHeight; 789 var padding = 0, border = 0; 790 jQuery.each( which, function() { 791 padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0; 792 border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0; 793 }); 794 val -= Math.round(padding + border); 787 795 } 788 796 … … 791 799 else 792 800 jQuery.swap( elem, props, getWH ); 793 794 return name == "width" ? width : height;801 802 return val; 795 803 } 796 804 … … 817 825 "1" : 818 826 ret; 827 } 828 // Opera sometimes will give the wrong display answer, this fixes it, see #2037 829 if ( jQuery.browser.opera && name == "display" ) { 830 var save = elem.style.display; 831 elem.style.display = "block"; 832 elem.style.display = save; 819 833 } 820 834 … … 1911 1925 for ( ret in events[type] ) break; 1912 1926 if ( !ret ) { 1913 if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call( this,elem) === false ) {1927 if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem) === false ) { 1914 1928 if (elem.removeEventListener) 1915 1929 elem.removeEventListener(type, jQuery.data(elem, "handle"), false); … … 1973 1987 1974 1988 // Handle triggering of extra function 1975 if ( extra ) {1989 if ( extra && jQuery.isFunction( extra ) ) { 1976 1990 // call the extra function and tack the current return value on the end for possible inspection 1977 1991 var ret = extra.apply( elem, data.concat( val ) ); … … 2100 2114 ready: { 2101 2115 setup: function() { 2102 var handler = jQuery.event.special.ready.handler; 2103 2104 // Mozilla, Opera and webkit nightlies currently support this event 2105 if ( document.addEventListener ) 2106 // Use the handy event callback 2107 document.addEventListener( "DOMContentLoaded", handler, false ); 2108 2109 // If Safari or IE is used 2110 // Continually check to see if the document is ready 2111 if ((jQuery.browser.msie && window == top) || jQuery.browser.safari ) (function(){ 2112 try { 2113 // If IE is used, use the trick by Diego Perini 2114 // http://javascript.nwbox.com/IEContentLoaded/ 2115 if ( jQuery.browser.msie || document.readyState != "loaded" && document.readyState != "complete" ) 2116 document.documentElement.doScroll("left"); 2117 } catch( error ) { 2118 setTimeout( arguments.callee, 0 ); 2119 return; 2120 } 2121 2122 // and execute any waiting functions 2123 handler(); 2124 })(); 2125 2126 // A fallback to window.onload, that will always work 2127 jQuery.event.add( window, "load", handler ); 2116 // Make sure the ready event is setup 2117 bindReady(); 2118 return; 2128 2119 }, 2129 2120 2130 teardown: function() {return;}, 2131 2132 handler: function() { 2133 // Make sure that the DOM is not already loaded 2134 if ( !jQuery.isReady ) { 2135 // Remember that the DOM is ready 2136 jQuery.isReady = true; 2137 jQuery(document).triggerHandler("ready"); 2138 jQuery(document).unbind("ready"); 2139 } 2140 } 2121 teardown: function() { return; } 2141 2122 }, 2142 2123 2143 2124 mouseenter: { 2144 2125 setup: function() { 2145 if ( jQuery.browser.msie) return false;2146 jQuery(this).bind( 'mouseover', jQuery.event.special.mouseenter.handler);2126 if ( jQuery.browser.msie ) return false; 2127 jQuery(this).bind("mouseover", jQuery.event.special.mouseenter.handler); 2147 2128 return true; 2148 2129 }, 2149 2130 2150 2131 teardown: function() { 2151 if ( jQuery.browser.msie) return false;2152 jQuery(this).unbind( 'mouseover', jQuery.event.special.mouseenter.handler);2132 if ( jQuery.browser.msie ) return false; 2133 jQuery(this).unbind("mouseover", jQuery.event.special.mouseenter.handler); 2153 2134 return true; 2154 2135 }, 2155 2136 2156 2137 handler: function(event) { 2157 var args = Array.prototype.slice.call( arguments, 1 );2158 2138 // If we actually just moused on to a sub-element, ignore it 2159 2139 if ( withinElement(event, this) ) return true; 2160 2140 // Execute the right handlers by setting the event type to mouseenter 2161 event.type = 'mouseenter'; 2162 // Include the event object as the first argument 2163 args.unshift(event); 2164 var val = jQuery.event.handle.apply(this, args); 2165 return val; 2141 arguments[0].type = "mouseenter"; 2142 return jQuery.event.handle.apply(this, arguments); 2166 2143 } 2167 2144 }, … … 2169 2146 mouseleave: { 2170 2147 setup: function() { 2171 if ( jQuery.browser.msie) return false;2172 jQuery(this).bind( 'mouseout', jQuery.event.special.mouseleave.handler);2148 if ( jQuery.browser.msie ) return false; 2149 jQuery(this).bind("mouseout", jQuery.event.special.mouseleave.handler); 2173 2150 return true; 2174 2151 }, 2175 2152 2176 2153 teardown: function() { 2177 if ( jQuery.browser.msie) return false;2178 jQuery(this).unbind( 'mouseout', jQuery.event.special.mouseleave.handler);2154 if ( jQuery.browser.msie ) return false; 2155 jQuery(this).unbind("mouseout", jQuery.event.special.mouseleave.handler); 2179 2156 return true; 2180 2157 }, 2181 2158 2182 2159 handler: function(event) { 2183 var args = Array.prototype.slice.call( arguments, 1 );2184 2160 // If we actually just moused on to a sub-element, ignore it 2185 2161 if ( withinElement(event, this) ) return true; 2186 2162 // Execute the right handlers by setting the event type to mouseleave 2187 event.type = 'mouseleave'; 2188 // Include the event object as the first argument 2189 args.unshift(event); 2190 var val = jQuery.event.handle.apply(this, args); 2191 return val; 2163 arguments[0].type = "mouseleave"; 2164 return jQuery.event.handle.apply(this, arguments); 2192 2165 } 2193 2166 } … … 2247 2220 hover: function(fnOver, fnOut) { 2248 2221 return this.bind('mouseenter', fnOver).bind('mouseleave', fnOut); 2222 }, 2223 2224 ready: function(fn) { 2225 // Attach the listeners 2226 bindReady(); 2227 2228 // If the DOM is already ready 2229 if ( jQuery.isReady ) 2230 // Execute the function immediately 2231 fn.call( document, jQuery ); 2232 2233 // Otherwise, remember the function for later 2234 else 2235 // Add the function to the wait list 2236 jQuery.readyList.push( function() { return fn.call(this, jQuery); } ); 2237 2238 return this; 2249 2239 } 2250 2240 }); 2251 2241 2252 2242 jQuery.extend({ 2253 isReady: false 2243 isReady: false, 2244 readyList: [], 2245 // Handle when the DOM is ready 2246 ready: function() { 2247 // Make sure that the DOM is not already loaded 2248 if ( !jQuery.isReady ) { 2249 // Remember that the DOM is ready 2250 jQuery.isReady = true; 2251 2252 // If there are functions bound, to execute 2253 if ( jQuery.readyList ) { 2254 // Execute all of them 2255 jQuery.each( jQuery.readyList, function(){ 2256 this.apply( document ); 2257 }); 2258 2259 // Reset the list of functions 2260 jQuery.readyList = null; 2261 } 2262 2263 // Trigger any bound ready events 2264 $(document).triggerHandler("ready"); 2265 } 2266 } 2254 2267 }); 2255 2268 2256 jQuery.each( ("blur,focus,load,ready,resize,scroll,unload,click,dblclick," + 2269 var readyBound = false; 2270 2271 function bindReady(){ 2272 if ( readyBound ) return; 2273 readyBound = true; 2274 2275 // Mozilla, Opera and webkit nightlies currently support this event 2276 if ( document.addEventListener ) 2277 // Use the handy event callback 2278 document.addEventListener( "DOMContentLoaded", jQuery.ready, false ); 2279 2280 // If Safari or IE is used 2281 // Continually check to see if the document is ready 2282 if (jQuery.browser.msie || jQuery.browser.safari ) (function(){ 2283 try { 2284 // If IE is used, use the trick by Diego Perini 2285 // http://javascript.nwbox.com/IEContentLoaded/ 2286 if ( jQuery.browser.msie || document.readyState != "loaded" && document.readyState != "complete" ) 2287 document.documentElement.doScroll("left"); 2288 } catch( error ) { 2289 return setTimeout( arguments.callee, 0 ); 2290 } 2291 2292 // and execute any waiting functions 2293 jQuery.ready(); 2294 })(); 2295 2296 // A fallback to window.onload, that will always work 2297 jQuery.event.add( window, "load", jQuery.ready ); 2298 } 2299 2300 jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," + 2257 2301 "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," + 2258 2302 "submit,keydown,keypress,keyup,error").split(","), function(i, name){ … … 2434 2478 2435 2479 ajax: function( s ) { 2436 var jsonp, jsre = /= (\?|%3F)/g, status, data;2480 var jsonp, jsre = /=\?(&|$)/g, status, data; 2437 2481 2438 2482 // Extend the settings, but re-extend 's' so that it can be … … 2460 2504 // Replace the =? sequence both in the query string and the data 2461 2505 if ( s.data ) 2462 s.data = (s.data + "").replace(jsre, "=" + jsonp );2463 s.url = s.url.replace(jsre, "=" + jsonp );2506 s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1"); 2507 s.url = s.url.replace(jsre, "=" + jsonp + "$1"); 2464 2508 2465 2509 // We need to make sure … … 2475 2519 window[ jsonp ] = undefined; 2476 2520 try{ delete window[ jsonp ]; } catch(e){} 2521 if ( head ) 2522 head.removeChild( script ); 2477 2523 }; 2478 2524 } … … 3252 3298 // Mozilla doubles body offsets with a non-absolutely positioned offsetChild 3253 3299 if ( (safari2 && (fixed || jQuery.css(offsetChild, "position") == "absolute")) || 3254 (mozilla && jQuery.css(offsetChild, "position") != "absol tue") )3300 (mozilla && jQuery.css(offsetChild, "position") != "absolute") ) 3255 3301 add( -doc.body.offsetLeft, -doc.body.offsetTop ); 3256 3302 -
trunk/plugins/validate/test/events.html
r4183 r4222 11 11 <script type="text/javascript"> 12 12 $().ready(function() { 13 var current; 14 function focus(event) { 15 if (current != null) 16 return; 17 var form = $(this); 13 jQuery.event.special.focusin = { 14 setup: function() { 15 if ($.browser.msie) 16 return false; 17 this.addEventListener("focus", jQuery.event.special.focusin.handler, true); 18 }, 19 teardown: function() { 20 if ($.browser.msie) 21 return false; 22 this.removeEventListener("focus", jQuery.event.special.focusin.handler, true); 23 }, 24 handler: function(event) { 25 var args = Array.prototype.slice.call( arguments, 1 ); 26 args.unshift(jQuery.extend({}, event, { type: "focusin" })); 27 var val = jQuery.event.handle.apply(this, args); 28 return val; 29 } 30 } 31 32 function handler(event) { 18 33 var target = $(event.target); 19 if (target.is("label") && event.type != "mousedown") {20 target = $("#" + target.attr("for"));21 }22 34 if (target.is(":text, textarea")) { 23 current = target; 24 target.addClass("focus").one("blur", function() { 35 $(event.target).addClass("focus").one("blur", function() { 25 36 $(this).removeClass("focus"); 26 current = null;27 37 }); 28 38 } 29 39 } 30 $("#commentForm"). keyup(focus).mousedown(focus).click(focus).submit(function() {31 return false;32 });33 40 $("#commentForm").bind("focusin", handler); 41 $("#remove").click(function() { 42 $("#commentForm").unbind("focusin"); 43 }) 34 44 }); 35 45 </script> … … 68 78 </form> 69 79 80 <button id="remove">Remove focus handler</button> 81 70 82 </body> 71 83 </html>
