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