+++ /dev/null
-/*\r
- * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
- * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
- *\r
- * == BEGIN LICENSE ==\r
- *\r
- * Licensed under the terms of any of the following licenses at your\r
- * choice:\r
- *\r
- * - GNU General Public License Version 2 or later (the "GPL")\r
- * http://www.gnu.org/licenses/gpl.html\r
- *\r
- * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
- * http://www.gnu.org/licenses/lgpl.html\r
- *\r
- * - Mozilla Public License Version 1.1 or later (the "MPL")\r
- * http://www.mozilla.org/MPL/MPL-1.1.html\r
- *\r
- * == END LICENSE ==\r
- *\r
- * Control keyboard keystroke combinations.\r
- */\r
-\r
-var FCKKeystrokeHandler = function( cancelCtrlDefaults )\r
-{\r
- this.Keystrokes = new Object() ;\r
- this.CancelCtrlDefaults = ( cancelCtrlDefaults !== false ) ;\r
-}\r
-\r
-/*\r
- * Listen to keystroke events in an element or DOM document object.\r
- * @target: The element or document to listen to keystroke events.\r
- */\r
-FCKKeystrokeHandler.prototype.AttachToElement = function( target )\r
-{\r
- // For newer browsers, it is enough to listen to the keydown event only.\r
- // Some browsers instead, don't cancel key events in the keydown, but in the\r
- // keypress. So we must do a longer trip in those cases.\r
- FCKTools.AddEventListenerEx( target, 'keydown', _FCKKeystrokeHandler_OnKeyDown, this ) ;\r
- if ( FCKBrowserInfo.IsGecko10 || FCKBrowserInfo.IsOpera || ( FCKBrowserInfo.IsGecko && FCKBrowserInfo.IsMac ) )\r
- FCKTools.AddEventListenerEx( target, 'keypress', _FCKKeystrokeHandler_OnKeyPress, this ) ;\r
-}\r
-\r
-/*\r
- * Sets a list of keystrokes. It can receive either a single array or "n"\r
- * arguments, each one being an array of 1 or 2 elemenst. The first element\r
- * is the keystroke combination, and the second is the value to assign to it.\r
- * If the second element is missing, the keystroke definition is removed.\r
- */\r
-FCKKeystrokeHandler.prototype.SetKeystrokes = function()\r
-{\r
- // Look through the arguments.\r
- for ( var i = 0 ; i < arguments.length ; i++ )\r
- {\r
- var keyDef = arguments[i] ;\r
-\r
- // If the configuration for the keystrokes is missing some element or has any extra comma\r
- // this item won't be valid, so skip it and keep on processing.\r
- if ( !keyDef )\r
- continue ;\r
-\r
- if ( typeof( keyDef[0] ) == 'object' ) // It is an array with arrays defining the keystrokes.\r
- this.SetKeystrokes.apply( this, keyDef ) ;\r
- else\r
- {\r
- if ( keyDef.length == 1 ) // If it has only one element, remove the keystroke.\r
- delete this.Keystrokes[ keyDef[0] ] ;\r
- else // Otherwise add it.\r
- this.Keystrokes[ keyDef[0] ] = keyDef[1] === true ? true : keyDef ;\r
- }\r
- }\r
-}\r
-\r
-function _FCKKeystrokeHandler_OnKeyDown( ev, keystrokeHandler )\r
-{\r
- // Get the key code.\r
- var keystroke = ev.keyCode || ev.which ;\r
-\r
- // Combine it with the CTRL, SHIFT and ALT states.\r
- var keyModifiers = 0 ;\r
-\r
- if ( ev.ctrlKey || ev.metaKey )\r
- keyModifiers += CTRL ;\r
-\r
- if ( ev.shiftKey )\r
- keyModifiers += SHIFT ;\r
-\r
- if ( ev.altKey )\r
- keyModifiers += ALT ;\r
-\r
- var keyCombination = keystroke + keyModifiers ;\r
-\r
- var cancelIt = keystrokeHandler._CancelIt = false ;\r
-\r
- // Look for its definition availability.\r
- var keystrokeValue = keystrokeHandler.Keystrokes[ keyCombination ] ;\r
-\r
-// FCKDebug.Output( 'KeyDown: ' + keyCombination + ' - Value: ' + keystrokeValue ) ;\r
-\r
- // If the keystroke is defined\r
- if ( keystrokeValue )\r
- {\r
- // If the keystroke has been explicitly set to "true" OR calling the\r
- // "OnKeystroke" event, it doesn't return "true", the default behavior\r
- // must be preserved.\r
- if ( keystrokeValue === true || !( keystrokeHandler.OnKeystroke && keystrokeHandler.OnKeystroke.apply( keystrokeHandler, keystrokeValue ) ) )\r
- return true ;\r
-\r
- cancelIt = true ;\r
- }\r
-\r
- // By default, it will cancel all combinations with the CTRL key only (except positioning keys).\r
- if ( cancelIt || ( keystrokeHandler.CancelCtrlDefaults && keyModifiers == CTRL && ( keystroke < 33 || keystroke > 40 ) ) )\r
- {\r
- keystrokeHandler._CancelIt = true ;\r
-\r
- if ( ev.preventDefault )\r
- return ev.preventDefault() ;\r
-\r
- ev.returnValue = false ;\r
- ev.cancelBubble = true ;\r
- return false ;\r
- }\r
-\r
- return true ;\r
-}\r
-\r
-function _FCKKeystrokeHandler_OnKeyPress( ev, keystrokeHandler )\r
-{\r
- if ( keystrokeHandler._CancelIt )\r
- {\r
-// FCKDebug.Output( 'KeyPress Cancel', 'Red') ;\r
-\r
- if ( ev.preventDefault )\r
- return ev.preventDefault() ;\r
-\r
- return false ;\r
- }\r
-\r
- return true ;\r
-}\r