tagging as ATutor 1.5.4-release
[atutor.git] / jscripts / tiny_mce / plugins / acheck / editor_plugin.js
1 /* Import plugin specific language pack */\r
2 \r
3 tinyMCE.importPluginLanguagePack('acheck', 'en'); // <- Add a comma separated list of all supported languages\r
4 \r
5 var TinyMCE_ACheckPlugin = {\r
6         getInfo : function() {\r
7                 return {\r
8                         longname : 'ACheck',\r
9                         author   : 'ATutor',\r
10                         authorurl : 'http://www.atutor.ca',\r
11                         infourl : 'http://www.atutor.ca',\r
12                         version : "1.0"\r
13                 };\r
14         },\r
15 \r
16         /**\r
17          * Gets executed when a TinyMCE editor instance is initialized.\r
18          *\r
19          * @param {TinyMCE_Control} Initialized TinyMCE editor control instance. \r
20          */\r
21         initInstance : function(inst) {\r
22                 // You can take out plugin specific parameters\r
23                 //alert("Initialization parameter:" + tinyMCE.getParam("somename_someparam", false));\r
24 \r
25                 // Register custom keyboard shortcut\r
26                 //inst.addShortcut('ctrl', 't', 'lang_somename_desc', 'mceSomeCommand');\r
27         },\r
28 \r
29         /**\r
30          * Returns the HTML code for a specific control or empty string if this plugin doesn't have that control.\r
31          * A control can be a button, select list or any other HTML item to present in the TinyMCE user interface.\r
32          * The variable {$editor_id} will be replaced with the current editor instance id and {$pluginurl} will be replaced\r
33          * with the URL of the plugin. Language variables such as {$lang_somekey} will also be replaced with contents from\r
34          * the language packs.\r
35          *\r
36          * @param {string} cn Editor control/button name to get HTML for.\r
37          * @return HTML code for a specific control or empty string.\r
38          * @type string\r
39          */\r
40         getControlHTML : function(cn) {\r
41                 switch (cn) {\r
42                         case "acheck":\r
43                                 return tinyMCE.getButtonHTML(cn, 'lang_acheck_button_desc', '{$pluginurl}/images/acheck.gif', 'mceACheck');\r
44                 }\r
45 \r
46                 return "";\r
47         },\r
48 \r
49 \r
50         /**\r
51          * Executes a specific command, this function handles plugin commands.\r
52          *\r
53          * @param {string} editor_id TinyMCE editor instance id that issued the command.\r
54          * @param {HTMLElement} element Body or root element for the editor instance.\r
55          * @param {string} command Command name to be executed.\r
56          * @param {string} user_interface True/false if a user interface should be presented.\r
57          * @param {mixed} value Custom value argument, can be anything.\r
58          * @return true/false if the command was executed by this plugin or not.\r
59          * @type\r
60          */\r
61         execCommand : function(editor_id, element, command, user_interface, value) {\r
62                 // Handle commands\r
63                 switch (command) {\r
64                         case "mceACheck":\r
65                                 var formObj = tinyMCE.selectedInstance.formElement.form;\r
66 \r
67                                 if (formObj) {\r
68                                         tinyMCE.triggerSave();\r
69 \r
70                                         // Disable all UI form elements that TinyMCE created\r
71                                         for (var i=0; i<formObj.elements.length; i++) {\r
72                                                 var elementId = formObj.elements[i].name ? formObj.elements[i].name : formObj.elements[i].id;\r
73 \r
74                                                 if (elementId.indexOf('mce_editor_') == 0)\r
75                                                         formObj.elements[i].disabled = true;\r
76                                         }\r
77 \r
78                                         // calls the JavaScript function\r
79                                         //Acheck_newWindowWithCode();\r
80                                         //alert('checking');\r
81                                         \r
82                                         var accessWin = null;\r
83                                         if (accessWin) {\r
84                                                 accessWin.close();\r
85                                         }\r
86                                         var nodeList = document.getElementsByTagName("textarea");\r
87                                         var elm = nodeList.item(0);\r
88                                         if (elm != null) {\r
89                                                 theVal = elm.value;\r
90                                         }\r
91                                         var theCode = '<html><body onLoad="document.accessform.submit();"> \n';\r
92                                         theCode += '<h1>Submitting Code for Accessibility Checking.....</h1>\n';\r
93                                         theCode += '<form action="http://checker.atrc.utoronto.ca/servlet/Checkacc" name="accessform" method="post"> \n';\r
94                                         theCode += '<input type="hidden" name="guide" value="wcag-2-0-aaa.xml" /> \n';\r
95                                         theCode += '<input type="hidden" name="type" value="form" /> \n';\r
96                                         theCode += '<textarea name="edittext">' + theVal + '</textarea>\n';\r
97                                         theCode += '<input type="submit" /></form> \n';  \r
98                                         theCode += '</body></html> \n';\r
99                                         accessWin = window.open('', 'accessWin',  '');\r
100                                         accessWin.document.writeln(theCode);\r
101                                         accessWin.document.close();\r
102                                 } else\r
103                                         alert("Error: No form element found.");\r
104 \r
105                         return true;\r
106                 }\r
107 \r
108                 // Pass to next handler in chain\r
109                 return false;\r
110         },\r
111 \r
112         /**\r
113          * Gets called ones the cursor/selection in a TinyMCE instance changes. This is useful to enable/disable\r
114          * button controls depending on where the user are and what they have selected. This method gets executed\r
115          * alot and should be as performance tuned as possible.\r
116          *\r
117          * @param {string} editor_id TinyMCE editor instance id that was changed.\r
118          * @param {HTMLNode} node Current node location, where the cursor is in the DOM tree.\r
119          * @param {int} undo_index The current undo index, if this is -1 custom undo/redo is disabled.\r
120          * @param {int} undo_levels The current undo levels, if this is -1 custom undo/redo is disabled.\r
121          * @param {boolean} visual_aid Is visual aids enabled/disabled ex: dotted lines on tables.\r
122          * @param {boolean} any_selection Is there any selection at all or is there only a cursor.\r
123          */\r
124         handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {\r
125         },\r
126 \r
127         /**\r
128          * Gets called when a TinyMCE editor instance gets filled with content on startup.\r
129          *\r
130          * @param {string} editor_id TinyMCE editor instance id that was filled with content.\r
131          * @param {HTMLElement} body HTML body element of editor instance.\r
132          * @param {HTMLDocument} doc HTML document instance.\r
133          */\r
134         setupContent : function(editor_id, body, doc) {\r
135         },\r
136 \r
137         /**\r
138          * Gets called when the contents of a TinyMCE area is modified, in other words when a undo level is\r
139          * added.\r
140          *\r
141          * @param {TinyMCE_Control} inst TinyMCE editor area control instance that got modified.\r
142          */\r
143         onChange : function(inst) {\r
144         },\r
145 \r
146         /**\r
147          * Gets called when TinyMCE handles events such as keydown, mousedown etc. TinyMCE\r
148          * doesn't listen on all types of events so custom event handling may be required for\r
149          * some purposes.\r
150          *\r
151          * @param {Event} e HTML editor event reference.\r
152          * @return true - pass to next handler in chain, false - stop chain execution\r
153          * @type boolean\r
154          */\r
155         handleEvent : function(e) {\r
156                 return true;\r
157         },\r
158 \r
159         /**\r
160          * Gets called when HTML contents is inserted or retrived from a TinyMCE editor instance.\r
161          * The type parameter contains what type of event that was performed and what format the content is in.\r
162          * Possible valuses for type is get_from_editor, insert_to_editor, get_from_editor_dom, insert_to_editor_dom.\r
163          *\r
164          * @param {string} type Cleanup event type.\r
165          * @param {mixed} content Editor contents that gets inserted/extracted can be a string or DOM element.\r
166          * @param {TinyMCE_Control} inst TinyMCE editor instance control that performes the cleanup.\r
167          * @return New content or the input content depending on action.\r
168          * @type string\r
169          */\r
170         cleanup : function(type, content, inst) {\r
171                 return content;\r
172         },\r
173 \r
174         // Private plugin internal methods\r
175 \r
176         /**\r
177          * This is just a internal plugin method, prefix all internal methods with a _ character.\r
178          * The prefix is needed so they doesn't collide with future TinyMCE callback functions.\r
179          *\r
180          * @param {string} a Some arg1.\r
181          * @param {string} b Some arg2.\r
182          * @return Some return.\r
183          * @type string\r
184          */\r
185         _someInternalFunction : function(a, b) {\r
186                 return 1;\r
187         }\r
188 };\r
189 \r
190 \r
191 tinyMCE.addPlugin("acheck", TinyMCE_ACheckPlugin);