Mimimum syndical pour en faire un produit zope / cmf.
[ckeditor.git] / skins / ckeditor / _source / core / focusmanager.js
diff --git a/skins/ckeditor/_source/core/focusmanager.js b/skins/ckeditor/_source/core/focusmanager.js
new file mode 100644 (file)
index 0000000..e59900d
--- /dev/null
@@ -0,0 +1,152 @@
+/*\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+/**\r
+ * @fileOverview Defines the {@link CKEDITOR.focusManager} class, which is used\r
+ *             to handle the focus on editor instances..\r
+ */\r
+\r
+/**\r
+ * Creates a focusManager class instance.\r
+ * @class Manages the focus activity in an editor instance. This class is to be\r
+ * used mainly by UI elements coders when adding interface elements that need\r
+ * to set the focus state of the editor.\r
+ * @param {CKEDITOR.editor} editor The editor instance.\r
+ * @example\r
+ * var focusManager = <b>new CKEDITOR.focusManager( editor )</b>;\r
+ * focusManager.focus();\r
+ */\r
+CKEDITOR.focusManager = function( editor )\r
+{\r
+       if ( editor.focusManager )\r
+               return editor.focusManager;\r
+\r
+       /**\r
+        * Indicates that the editor instance has focus.\r
+        * @type Boolean\r
+        * @example\r
+        * alert( CKEDITOR.instances.editor1.focusManager.hasFocus );  // e.g "true"\r
+        */\r
+       this.hasFocus = false;\r
+\r
+       /**\r
+        * Object used to hold private stuff.\r
+        * @private\r
+        */\r
+       this._ =\r
+       {\r
+               editor : editor\r
+       };\r
+\r
+       return this;\r
+};\r
+\r
+CKEDITOR.focusManager.prototype =\r
+{\r
+       /**\r
+        * Used to indicate that the editor instance has the focus.<br />\r
+        * <br />\r
+        * Note that this function will not explicitelly set the focus in the\r
+        * editor (for example, making the caret blinking on it). Use\r
+        * {@link CKEDITOR.editor#focus} for it instead.\r
+        * @example\r
+        * var editor = CKEDITOR.instances.editor1;\r
+        * <b>editor.focusManager.focus()</b>;\r
+        */\r
+       focus : function()\r
+       {\r
+               if ( this._.timer )\r
+                       clearTimeout( this._.timer );\r
+\r
+               if ( !this.hasFocus )\r
+               {\r
+                       // If another editor has the current focus, we first "blur" it. In\r
+                       // this way the events happen in a more logical sequence, like:\r
+                       //              "focus 1" > "blur 1" > "focus 2"\r
+                       // ... instead of:\r
+                       //              "focus 1" > "focus 2" > "blur 1"\r
+                       if ( CKEDITOR.currentInstance )\r
+                               CKEDITOR.currentInstance.focusManager.forceBlur();\r
+\r
+                       var editor = this._.editor;\r
+\r
+                       editor.container.getChild( 1 ).addClass( 'cke_focus' );\r
+\r
+                       this.hasFocus = true;\r
+                       editor.fire( 'focus' );\r
+               }\r
+       },\r
+\r
+       /**\r
+        * Used to indicate that the editor instance has lost the focus.<br />\r
+        * <br />\r
+        * Note that this functions acts asynchronously with a delay of 100ms to\r
+        * avoid subsequent blur/focus effects. If you want the "blur" to happen\r
+        * immediately, use the {@link #forceBlur} function instead.\r
+        * @example\r
+        * var editor = CKEDITOR.instances.editor1;\r
+        * <b>editor.focusManager.blur()</b>;\r
+        */\r
+       blur : function()\r
+       {\r
+               var focusManager = this;\r
+\r
+               if ( focusManager._.timer )\r
+                       clearTimeout( focusManager._.timer );\r
+\r
+               focusManager._.timer = setTimeout(\r
+                       function()\r
+                       {\r
+                               delete focusManager._.timer;\r
+                               focusManager.forceBlur();\r
+                       }\r
+                       , 100 );\r
+       },\r
+\r
+       /**\r
+        * Used to indicate that the editor instance has lost the focus. Unlike\r
+        * {@link #blur}, this function is synchronous, marking the instance as\r
+        * "blured" immediately.\r
+        * @example\r
+        * var editor = CKEDITOR.instances.editor1;\r
+        * <b>editor.focusManager.forceBlur()</b>;\r
+        */\r
+       forceBlur : function()\r
+       {\r
+               if ( this.hasFocus )\r
+               {\r
+                       var editor = this._.editor;\r
+\r
+                       editor.container.getChild( 1 ).removeClass( 'cke_focus' );\r
+\r
+                       this.hasFocus = false;\r
+                       editor.fire( 'blur' );\r
+               }\r
+       }\r
+};\r
+\r
+/**\r
+ * Fired when the editor instance receives the input focus.\r
+ * @name CKEDITOR.editor#focus\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor The editor instance.\r
+ * @example\r
+ * editor.on( 'focus', function( e )\r
+ *     {\r
+ *         alert( 'The editor named ' + e.editor.name + ' is now focused' );\r
+ *     });\r
+ */\r
+\r
+/**\r
+ * Fired when the editor instance loses the input focus.\r
+ * @name CKEDITOR.editor#blur\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor The editor instance.\r
+ * @example\r
+ * editor.on( 'blur', function( e )\r
+ *     {\r
+ *         alert( 'The editor named ' + e.editor.name + ' lost the focus' );\r
+ *     });\r
+ */\r