Bug Tracker

Changeset 4222

Show
Ignore:
Timestamp:
12/18/07 23:50:20 (1 year ago)
Author:
joern.zaefferer
Message:

special focusin event

Location:
trunk/plugins/validate
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/validate/lib/jquery.js

    r4188 r4222  
    77 * and GPL (GPL-LICENSE.txt) licenses. 
    88 * 
    9  * $Date: 2007-12-16 02:03:50 +0100 (Son, 16 Dez 2007) $ 
    10  * $Rev: 4171 $ 
     9 * $Date: 2007-12-18 18:19:33 +0100 (Di, 18 Dez 2007) $ 
     10 * $Rev: 4220 $ 
    1111 */ 
    1212 
     
    354354                selector = jQuery.multiFilter( selector, this ); 
    355355 
     356        var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType; 
    356357        return this.filter(function() { 
    357             return jQuery.inArray( this, selector ) < 0; 
     358            return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector; 
    358359        }); 
    359360    }, 
     
    420421            } 
    421422 
     423            return undefined; 
    422424        } 
    423425 
     
    765767    // A method for quickly swapping in/out CSS properties to get correct calculations 
    766768    swap: function( elem, options, callback ) { 
     769        var old = {}; 
    767770        // Remember the old values, and insert the new ones 
    768771        for ( var name in options ) { 
    769             elem.style[ "old" + name ] = elem.style[ name ]; 
     772            old[ name ] = elem.style[ name ]; 
    770773            elem.style[ name ] = options[ name ]; 
    771774        } 
     
    775778        // Revert the old values 
    776779        for ( var name in options ) 
    777             elem.style[ name ] = elem.style[ "old" + name ]; 
     780            elem.style[ name ] = old[ name ]; 
    778781    }, 
    779782 
    780783    css: function( elem, name, force ) { 
    781784        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" ]; 
    783786         
    784787            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); 
    787795            } 
    788796         
     
    791799            else 
    792800                jQuery.swap( elem, props, getWH ); 
    793  
    794             return name == "width" ? width : height; 
     801             
     802            return val; 
    795803        } 
    796804         
     
    817825                "1" : 
    818826                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; 
    819833        } 
    820834         
     
    19111925                        for ( ret in events[type] ) break; 
    19121926                        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 ) { 
    19141928                                if (elem.removeEventListener) 
    19151929                                    elem.removeEventListener(type, jQuery.data(elem, "handle"), false); 
     
    19731987 
    19741988            // Handle triggering of extra function 
    1975             if ( extra ) { 
     1989            if ( extra && jQuery.isFunction( extra ) ) { 
    19761990                // call the extra function and tack the current return value on the end for possible inspection 
    19771991                var ret = extra.apply( elem, data.concat( val ) ); 
     
    21002114        ready: { 
    21012115            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; 
    21282119            }, 
    21292120             
    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; } 
    21412122        }, 
    21422123         
    21432124        mouseenter: { 
    21442125            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); 
    21472128                return true; 
    21482129            }, 
    21492130         
    21502131            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); 
    21532134                return true; 
    21542135            }, 
    21552136             
    21562137            handler: function(event) { 
    2157                 var args = Array.prototype.slice.call( arguments, 1 ); 
    21582138                // If we actually just moused on to a sub-element, ignore it 
    21592139                if ( withinElement(event, this) ) return true; 
    21602140                // 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); 
    21662143            } 
    21672144        }, 
     
    21692146        mouseleave: { 
    21702147            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); 
    21732150                return true; 
    21742151            }, 
    21752152         
    21762153            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); 
    21792156                return true; 
    21802157            }, 
    21812158             
    21822159            handler: function(event) { 
    2183                 var args = Array.prototype.slice.call( arguments, 1 ); 
    21842160                // If we actually just moused on to a sub-element, ignore it 
    21852161                if ( withinElement(event, this) ) return true; 
    21862162                // 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); 
    21922165            } 
    21932166        } 
     
    22472220    hover: function(fnOver, fnOut) { 
    22482221        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; 
    22492239    } 
    22502240}); 
    22512241 
    22522242jQuery.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    } 
    22542267}); 
    22552268 
    2256 jQuery.each( ("blur,focus,load,ready,resize,scroll,unload,click,dblclick," + 
     2269var readyBound = false; 
     2270 
     2271function 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 
     2300jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," + 
    22572301    "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +  
    22582302    "submit,keydown,keypress,keyup,error").split(","), function(i, name){ 
     
    24342478 
    24352479    ajax: function( s ) { 
    2436         var jsonp, jsre = /=(\?|%3F)/g, status, data; 
     2480        var jsonp, jsre = /=\?(&|$)/g, status, data; 
    24372481 
    24382482        // Extend the settings, but re-extend 's' so that it can be 
     
    24602504            // Replace the =? sequence both in the query string and the data 
    24612505            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"); 
    24642508 
    24652509            // We need to make sure 
     
    24752519                window[ jsonp ] = undefined; 
    24762520                try{ delete window[ jsonp ]; } catch(e){} 
     2521                if ( head ) 
     2522                    head.removeChild( script ); 
    24772523            }; 
    24782524        } 
     
    32523298            // Mozilla doubles body offsets with a non-absolutely positioned offsetChild 
    32533299            if ( (safari2 && (fixed || jQuery.css(offsetChild, "position") == "absolute")) ||  
    3254                 (mozilla && jQuery.css(offsetChild, "position") != "absoltue") ) 
     3300                (mozilla && jQuery.css(offsetChild, "position") != "absolute") ) 
    32553301                    add( -doc.body.offsetLeft, -doc.body.offsetTop ); 
    32563302             
  • trunk/plugins/validate/test/events.html

    r4183 r4222  
    1111<script type="text/javascript"> 
    1212$().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) { 
    1833        var target = $(event.target); 
    19         if (target.is("label") && event.type != "mousedown") { 
    20             target = $("#" + target.attr("for")); 
    21         } 
    2234        if (target.is(":text, textarea")) { 
    23             current = target; 
    24             target.addClass("focus").one("blur", function() { 
     35            $(event.target).addClass("focus").one("blur", function() { 
    2536                $(this).removeClass("focus"); 
    26                 current = null; 
    2737            }); 
    2838        } 
    2939    } 
    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    }) 
    3444}); 
    3545</script> 
     
    6878</form> 
    6979 
     80<button id="remove">Remove focus handler</button> 
     81 
    7082</body> 
    7183</html>