nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jquery.event.drag-new / fire / test / key.js
1 module("Key Events");
2
3 // test each of the following events
4 $.each([
5         "keydown","keyup","keypress"
6 ],function( i, type ){
7         // test each event type
8         test( '"'+ type +'"', function(){
9                 expect( i < 2 ? 27 : 30 );
10                 
11                 // custom event properties
12                 var props = {
13                         keyCode: Math.round( Math.random() * 256 ),
14                         charCode: Math.round( Math.random() * 256 ),
15                         ctrlKey: Math.round( Math.random() ) ? true : false, 
16                         altKey: Math.round( Math.random() ) ? true : false, 
17                         shiftKey: Math.round( Math.random() ) ? true : false 
18                 },
19                 // new test element
20                 $div = $('<div/>').appendTo( document.body );
21                 // test the document too for bubbling
22                 $div.add( document ).bind( type, function( ev ){
23                         
24                         equals( ev.currentTarget, this, "event.currentTarget");
25                         equals( ev.target, $div[0], "event.target" );
26                         equals( ev.type, type, "event.type" );
27                         equals( ev.keyCode, props.keyCode, "event.keyCode" );
28                         if ( type == "keypress" ){
29                                 equals( ev.charCode, props.charCode, "event.charCode" );
30                         }
31                         equals( ev.ctrlKey, props.ctrlKey, "event.ctrlKey" );
32                         equals( ev.altKey, props.altKey, "event.altKey" );
33                         equals( ev.shiftKey, props.shiftKey, "event.shiftKey" );
34                         equals( ev.metaKey, props.metaKey, "event.metaKey" );
35                         equals( ev.bubbles, props.bubbles, "event.bubbles" );
36                 });
37                 
38                 // make sure that metaKey and ctrlKey are equal
39                 props.metaKey = props.ctrlKey;
40                 // fire the event with bubbling
41                 props.bubbles = true;
42                 $div.fire( type, props );
43                 
44                 // fire the event without bubbling
45                 props.bubbles = false;
46                 $div.fire( type, props );
47         
48                 // cleanup
49                 $( document ).unbind( type );
50                 $div.remove();
51         });
52 });