618a11035c156d89da83689851e876fd4f111ad3
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @fileOverview Defines the {@link CKEDITOR.dom.event} class, which
8 * represents the a native DOM event object.
12 * Represents a native DOM event object.
14 * @param {Object} domEvent A native DOM event object.
17 CKEDITOR
.dom
.event = function( domEvent
)
20 * The native DOM event object represented by this class instance.
27 CKEDITOR
.dom
.event
.prototype =
30 * Gets the key code associated to the event.
31 * @returns {Number} The key code.
33 * alert( event.getKey() ); "65" is "a" has been pressed
37 return this.$.keyCode
|| this.$.which
;
41 * Gets a number represeting the combination of the keys pressed during the
42 * event. It is the sum with the current key code and the {@link CKEDITOR.CTRL},
43 * {@link CKEDITOR.SHIFT} and {@link CKEDITOR.ALT} constants.
44 * @returns {Number} The number representing the keys combination.
46 * alert( event.getKeystroke() == 65 ); // "a" key
47 * alert( event.getKeystroke() == CKEDITOR.CTRL + 65 ); // CTRL + "a" key
48 * alert( event.getKeystroke() == CKEDITOR.CTRL + CKEDITOR.SHIFT + 65 ); // CTRL + SHIFT + "a" key
50 getKeystroke : function()
52 var keystroke
= this.getKey();
54 if ( this.$.ctrlKey
|| this.$.metaKey
)
55 keystroke
+= CKEDITOR
.CTRL
;
57 if ( this.$.shiftKey
)
58 keystroke
+= CKEDITOR
.SHIFT
;
61 keystroke
+= CKEDITOR
.ALT
;
67 * Prevents the original behavior of the event to happen. It can optionally
68 * stop propagating the event in the event chain.
69 * @param {Boolean} [stopPropagation] Stop propagating this event in the
72 * var element = CKEDITOR.document.getById( 'myElement' );
73 * element.on( 'click', function( ev )
75 * // The DOM event object is passed by the "data" property.
76 * var domEvent = ev.data;
77 * // Prevent the click to chave any effect in the element.
78 * domEvent.preventDefault();
81 preventDefault : function( stopPropagation
)
84 if ( $.preventDefault
)
87 $.returnValue
= false;
89 if ( stopPropagation
)
90 this.stopPropagation();
93 stopPropagation : function()
96 if ( $.stopPropagation
)
99 $.cancelBubble
= true;
103 * Returns the DOM node where the event was targeted to.
104 * @returns {CKEDITOR.dom.node} The target DOM node.
106 * var element = CKEDITOR.document.getById( 'myElement' );
107 * element.on( 'click', function( ev )
109 * // The DOM event object is passed by the "data" property.
110 * var domEvent = ev.data;
111 * // Add a CSS class to the event target.
112 * domEvent.getTarget().addClass( 'clicked' );
116 getTarget : function()
118 var rawNode
= this.$.target
|| this.$.srcElement
;
119 return rawNode
? new CKEDITOR
.dom
.node( rawNode
) : null;
123 // For the followind constants, we need to go over the Unicode boundaries
124 // (0x10FFFF) to avoid collision.
127 * CTRL key (0x110000).
131 CKEDITOR
.CTRL
= 0x110000;
134 * SHIFT key (0x220000).
138 CKEDITOR
.SHIFT
= 0x220000;
141 * ALT key (0x440000).
145 CKEDITOR
.ALT
= 0x440000;