Bug Tracker

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

special focusin event

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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>