Bug Tracker

Changeset 4183

Show
Ignore:
Timestamp:
12/16/07 16:40:56 (1 year ago)
Author:
joern.zaefferer
Message:

nearly perfect focus-event-delegation

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/validate/test/events.html

    r4090 r4183  
    1010 
    1111<script type="text/javascript"> 
     12$().ready(function() { 
     13    var current; 
     14    function focus(event) { 
     15        if (current != null) 
     16            return; 
     17        var form = $(this); 
     18        var target = $(event.target); 
     19        if (target.is("label") && event.type != "mousedown") { 
     20            target = $("#" + target.attr("for")); 
     21        } 
     22        if (target.is(":text, textarea")) { 
     23            current = target; 
     24            target.addClass("focus").one("blur", function() { 
     25                $(this).removeClass("focus"); 
     26                current = null; 
     27            }); 
     28        } 
     29    } 
     30    $("#commentForm").keyup(focus).mousedown(focus).click(focus).submit(function() { 
     31        return false; 
     32    }); 
    1233 
    13 $().ready(function() { 
    14     function handle(event) { 
    15         console.log("this", this, "type", event.type, "target", event.target); 
    16     } 
    17     $("#commentForm").keyup(handle).blur(handle).change(handle).focus(handle).mouseup(handle); 
    18     //$(":input").change(handle).blur(handle).keyup(handle).focus(handle).bind("input", handle); 
    1934}); 
    2035</script> 
     
    2237<style type="text/css"> 
    2338#commentForm { width: 500px; } 
    24 #commentForm label { width: 250px; } 
     39#commentForm label { width: 250px; display: block; float: left; } 
    2540#commentForm label.error, #commentForm input.submit { margin-left: 253px; } 
    26      
    27 #signupForm { width: 670px; } 
    28 #signupForm label.error { 
    29     margin-left: 10px; 
    30     width: auto; 
    31     display: inline; 
    32 } 
    33 #newsletter_topics label.error { 
    34     display: none; 
    35     margin-left: 103px; 
    36 } 
     41.focus { background-color: red; } 
    3742</style> 
    3843 
    3944</head> 
    4045<body> 
    41  
    4246<form class="cmxform" id="commentForm" method="get" action=""> 
    4347    <fieldset>