Ticket #4740: 4740.patch

File 4740.patch, 3.9 kB (added by becky, 7 months ago)

update ondijitclick to use onkeypress for enter key in FF

  • Users/bgibson/Documents/workspace/trunk/dijit/_Widget.js

     
    387387                //      summary: 
    388388                //              Connects specified obj/event to specified method of this object 
    389389                //              and registers for disconnect() on widget destroy. 
    390                 //              Special event: "ondijitclick" triggers on a click or enter-down or space-up 
     390                //              Special event: "ondijitclick" triggers on a click or space-up, enter-down in IE 
     391                //              or enter press in FF (since often can't cancel enter onkeydown in FF) 
    391392                //              Similar to dojo.connect() but takes three arguments rather than four. 
    392393                var handles =[]; 
    393394                if(event == "ondijitclick"){ 
     
    395396                        if(!this.nodesWithKeyClick[obj.nodeName]){ 
    396397                                handles.push(dojo.connect(obj, "onkeydown", this, 
    397398                                        function(e){ 
    398                                                 if(e.keyCode == dojo.keys.ENTER){ 
     399                                                if(!dojo.isFF && e.keyCode == dojo.keys.ENTER){ 
    399400                                                        return (dojo.isString(method))? 
    400401                                                                this[method](e) : method.call(this, e); 
    401402                                                }else if(e.keyCode == dojo.keys.SPACE){ 
     
    411412                                                                this[method](e) : method.call(this, e); 
    412413                                                } 
    413414                                        })); 
     415                                if (dojo.isFF){ 
     416                                handles.push(dojo.connect(obj, "onkeypress", this, 
     417                                        function(e){ 
     418                                                if(e.keyCode == dojo.keys.ENTER){ 
     419                                                        return (dojo.isString(method))? 
     420                                                                this[method](e) : method.call(this, e); 
     421                                                } 
     422                                        })); 
     423                                } 
    414424                        } 
    415425                        event = "onclick"; 
    416426                } 
  • Users/bgibson/Documents/workspace/trunk/dijit/tests/ondijitclick.html

     
    4444                                                                w.clickCount = 0; 
    4545                                                                w.domNode.dispatchEvent(e); 
    4646                                                                t.is(1, w.clickCount); 
    47                                                         } 
     47                                                        }        
    4848                                                } 
    4949                                        }, 
    5050                                        { 
    51                                                 name: "ondijitclick fires once on an enter-key-down", 
     51                                                name: "ondijitclick fires once on an enter-key-down except in FF", 
    5252                                                runTest: function(t){ 
    5353                                                        var w = dijit.byId("widget1"); 
    5454                                                        if (dojo.isSafari){ // safari has error 
     
    6363                                                                w.domNode.focus(); 
    6464                                                                w.clickCount = 0; 
    6565                                                                w.domNode.dispatchEvent(e); 
    66                                                                 t.is(1, w.clickCount); 
     66                                                                if (!dojo.isFF){ 
     67                                                                        t.is(1,w.clickCount); 
     68                                                                }else{ 
     69                                                                        t.is(0, w.clickCount); 
     70                                                                } 
     71                                                        } 
     72                                                } 
     73                                        }, 
     74                                        { 
     75                                                name: "ondijitclick fires once on an enter-key-press in FF", 
     76                                                runTest: function(t){ 
     77                                                        var w = dijit.byId("widget1"); 
     78                                                        if (dojo.isSafari){ // safari has error 
     79                                                                this.name += " * SKIPPED *"; 
     80                                                                return; 
     81                                                        } 
     82 
     83                                                        // simulate enter down 
     84                                                        if (document.createEvent && !dojo.isSafari){ 
     85                                                                var e = document.createEvent("KeyboardEvent"); 
     86                                                                e.initKeyEvent("keypress",true,true,null,false,false,false,false,13,0); 
     87                                                                w.domNode.focus(); 
     88                                                                w.clickCount = 0; 
     89                                                                w.domNode.dispatchEvent(e); 
     90                                                                if (dojo.isFF){ 
     91                                                                        t.is(1, w.clickCount); 
     92                                                                }else{ 
     93                                                                        t.is(0, w.clickCount); 
     94                                                                } 
     95                                                        } 
     96                                                } 
     97                                        }, 
     98                                        { 
     99                                                name: "ondijitclick does not fire on a space-key-down", 
     100                                                runTest: function(t){ 
     101                                                        var w = dijit.byId("widget1"); 
     102                                                        if (dojo.isSafari){ // safari has error 
     103                                                                this.name += " * SKIPPED *"; 
     104                                                                return; 
     105                                                        } 
     106 
     107                                                        // simulate space up 
     108                                                        if (document.createEvent){ 
     109                                                                var e = document.createEvent("KeyboardEvent"); 
     110                                                                e.initKeyEvent("keydown",true,true,null,false,false,false,false,32,0); 
     111                                                                w.domNode.focus(); 
     112                                                                w.clickCount = 0; 
     113                                                                w.domNode.dispatchEvent(e); 
     114                                                                t.is(0, w.clickCount); 
    67115                                                        } 
    68116                                                } 
    69117                                        },