Podświetlanie składni w edytorze XML dzięki editArea. Closes #17. Niestety dla tekstó...
[redakcja.git] / project / static / js / plugins / test / test.js
diff --git a/project/static/js/plugins/test/test.js b/project/static/js/plugins/test/test.js
new file mode 100755 (executable)
index 0000000..46e71ef
--- /dev/null
@@ -0,0 +1,110 @@
+/**\r
+ * Plugin designed for test prupose. It add a button (that manage an alert) and a select (that allow to insert tags) in the toolbar.\r
+ * This plugin also disable the "f" key in the editarea, and load a CSS and a JS file\r
+ */  \r
+var EditArea_test= {\r
+       /**\r
+        * Get called once this file is loaded (editArea still not initialized)\r
+        *\r
+        * @return nothing       \r
+        */                     \r
+       init: function(){       \r
+               //      alert("test init: "+ this._someInternalFunction(2, 3));\r
+               editArea.load_css(this.baseURL+"css/test.css");\r
+               editArea.load_script(this.baseURL+"test2.js");\r
+       }\r
+       /**\r
+        * Returns the HTML code for a specific control string or false if this plugin doesn't have that control.\r
+        * A control can be a button, select list or any other HTML item to present in the EditArea user interface.\r
+        * Language variables such as {$lang_somekey} will also be replaced with contents from\r
+        * the language packs.\r
+        * \r
+        * @param {string} ctrl_name: the name of the control to add      \r
+        * @return HTML code for a specific control or false.\r
+        * @type string or boolean\r
+        */     \r
+       ,get_control_html: function(ctrl_name){\r
+               switch(ctrl_name){\r
+                       case "test_but":\r
+                               // Control id, button img, command\r
+                               return parent.editAreaLoader.get_button_html('test_but', 'test.gif', 'test_cmd', false, this.baseURL);\r
+                       case "test_select":\r
+                               html= "<select id='test_select' onchange='javascript:editArea.execCommand(\"test_select_change\")' fileSpecific='no'>"\r
+                                       +"                      <option value='-1'>{$test_select}</option>"\r
+                                       +"                      <option value='h1'>h1</option>"\r
+                                       +"                      <option value='h2'>h2</option>"\r
+                                       +"                      <option value='h3'>h3</option>"\r
+                                       +"                      <option value='h4'>h4</option>"\r
+                                       +"                      <option value='h5'>h5</option>"\r
+                                       +"                      <option value='h6'>h6</option>"\r
+                                       +"              </select>";\r
+                               return html;\r
+               }\r
+               return false;\r
+       }\r
+       /**\r
+        * Get called once EditArea is fully loaded and initialised\r
+        *       \r
+        * @return nothing\r
+        */                     \r
+       ,onload: function(){ \r
+               alert("test load");\r
+       }\r
+       \r
+       /**\r
+        * Is called each time the user touch a keyboard key.\r
+        *       \r
+        * @param (event) e: the keydown event\r
+        * @return true - pass to next handler in chain, false - stop chain execution\r
+        * @type boolean         \r
+        */\r
+       ,onkeydown: function(e){\r
+               var str= String.fromCharCode(e.keyCode);\r
+               // desactivate the "f" character\r
+               if(str.toLowerCase()=="f"){\r
+                       return true;\r
+               }\r
+               return false;\r
+       }\r
+       \r
+       /**\r
+        * Executes a specific command, this function handles plugin commands.\r
+        *\r
+        * @param {string} cmd: the name of the command being executed\r
+        * @param {unknown} param: the parameter of the command  \r
+        * @return true - pass to next handler in chain, false - stop chain execution\r
+        * @type boolean        \r
+        */\r
+       ,execCommand: function(cmd, param){\r
+               // Handle commands\r
+               switch(cmd){\r
+                       case "test_select_change":\r
+                               var val= document.getElementById("test_select").value;\r
+                               if(val!=-1)\r
+                                       parent.editAreaLoader.insertTags(editArea.id, "<"+val+">", "</"+val+">");\r
+                               document.getElementById("test_select").options[0].selected=true; \r
+                               return false;\r
+                       case "test_cmd":\r
+                               alert("user clicked on test_cmd");\r
+                               return false;\r
+               }\r
+               // Pass to next handler in chain\r
+               return true;\r
+       }\r
+       \r
+       /**\r
+        * This is just an internal plugin method, prefix all internal methods with a _ character.\r
+        * The prefix is needed so they doesn't collide with future EditArea callback functions.\r
+        *\r
+        * @param {string} a Some arg1.\r
+        * @param {string} b Some arg2.\r
+        * @return Some return.\r
+        * @type unknown\r
+        */\r
+       ,_someInternalFunction : function(a, b) {\r
+               return a+b;\r
+       }\r
+};\r
+\r
+// Adds the plugin class to the list of available EditArea plugins\r
+editArea.add_plugin("test", EditArea_test);\r