moved code up one level to eliminate the docs subdirectory
[acontent.git] / include / jscripts / tiny_mce_plugins / insert_tag / editor_plugin_src.js
1 /**\r
2  * $Id: $\r
3  *\r
4  * @author Laurel A. Williams\r
5  * @copyright Copyright © 2008, ATutor, All rights reserved.\r
6  */\r
7 \r
8 /*global tinymce*/\r
9 \r
10 "use strict";\r
11 (function () {\r
12         \r
13         // Load plugin specific language pack\r
14         tinymce.PluginManager.requireLangPack('insert_tag');\r
15         \r
16         tinymce.create('tinymce.plugins.Insert_tagPlugin', {\r
17 \r
18                 /**\r
19                  * Initializes the plugin, this will be executed after the plugin has been created.\r
20                  * This call is done before the editor instance has finished it's initialization so use the onInit event\r
21                  * of the editor instance to intercept that event.\r
22                  *\r
23                  * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.\r
24                  * @param {string} url Absolute URL to where the plugin is located.\r
25                  */\r
26                 init : function (ed, url) {\r
27                 \r
28                         /**\r
29                          * Places the cursor in the appropriate insertion point between [][/] \r
30                          * tags. It deletes the <span> with the id="remove_me", which was \r
31                          * placed between the [][/] tags, leaving the caret between \r
32                          * the tags as desired.\r
33                          */\r
34                         var placeCursor = function () {\r
35                                 ed.selection.select(ed.dom.select('span#remove_me')[0]);\r
36                                 ed.dom.remove(ed.dom.select('span#remove_me')[0]);\r
37                         };\r
38                         \r
39                         /**\r
40                          * A function which generates a function to insert the appropriate \r
41                          * tags, either [?], [code] or [tex].\r
42                          * \r
43                          * Note the slightly hacky insertion of a span with id="remove_me" \r
44                          * which is used to place the cursor in the correct insertion point.\r
45                          */\r
46                         var insertionFunction = function (insertionString) {\r
47                                 return function () {\r
48                                         if (ed.selection.isCollapsed()) {\r
49                                                 ed.selection.setContent('['+ insertionString + \r
50                                                                 ']<span id="remove_me"></span>[/' + insertionString + ']');\r
51                                                 placeCursor();\r
52                                         }\r
53                                         else {\r
54                                                 ed.selection.setContent('['+ insertionString + ']' + \r
55                                                         ed.selection.getContent() + '[/' + insertionString + ']');\r
56                                         }\r
57                                 }; \r
58                         };\r
59         \r
60                         //[?] tag \r
61                         ed.addCommand('mceInsertTermTag', insertionFunction("?"));\r
62                         ed.addButton('insert_term_tag', {\r
63                                 title : 'insert_tag.termdesc',\r
64                                 cmd : 'mceInsertTermTag',\r
65                                 image : url + '/img/term.png'\r
66                         });\r
67 \r
68                         //[code] tag - has not been added to interface because it doesn't work\r
69                         ed.addCommand('mceInsertCodeTag', insertionFunction("code"));\r
70                         ed.addButton('insert_code_tag', {\r
71                                 title : 'insert_tag.codedesc',\r
72                                 cmd : 'mceInsertCodeTag',\r
73                                 image : url + '/img/code.png'\r
74                         });\r
75 \r
76                         //[tex] tag\r
77                         ed.addCommand('mceInsertTexTag', insertionFunction("tex"));\r
78                         ed.addButton('insert_tex_tag', {\r
79                                 title : 'insert_tag.texdesc',\r
80                                 cmd : 'mceInsertTexTag',\r
81                                 image : url + '/img/tex.png'\r
82                         });\r
83 \r
84                         //[media] tag\r
85                         // a bit more complex tag, so formed inline instead of using insertionFunction\r
86                         ed.addCommand('mceInsertMediaTag', function () {\r
87                                 if (ed.selection.isCollapsed()) {\r
88                                         ed.selection.setContent('[media|640|480]http://<span id="remove_me"></span>[/media]');\r
89                                         placeCursor();\r
90                                 }\r
91                                 else {\r
92                                         ed.selection.setContent('[media|640|480]http://' + \r
93                                                         ed.selection.getContent() + '[/media]');\r
94                                         \r
95                                 }\r
96                         });\r
97                         ed.addButton('insert_media_tag', {\r
98                                 title : 'insert_tag.mediadesc',\r
99                                 cmd : 'mceInsertMediaTag',\r
100                                 image : url + '/img/media.png'\r
101                         });\r
102 \r
103                 },      \r
104                 \r
105                 \r
106                 /**\r
107                  * Returns information about the plugin as a name/value array. The\r
108                  * current keys are longname, author, authorurl, infourl and version.\r
109                  * \r
110                  * @return {Object} Name/value array containing information about the\r
111                  *         plugin.\r
112                  */\r
113                 getInfo : function () {\r
114                         return {\r
115                                 longname : 'Insert tag plugin',\r
116                                 author : 'ATutor',\r
117                                 authorurl : 'http://www.atutor.ca',\r
118                                 infourl : 'http://www.atutor.ca',\r
119                                 version : "0.9beta"\r
120                         };\r
121                 }\r
122         });\r
123 \r
124         // Register plugin\r
125         tinymce.PluginManager.add('insert_tag', tinymce.plugins.Insert_tagPlugin);\r
126 })();