4 * @author Laurel A. Williams
\r
5 * @copyright Copyright © 2008, ATutor, All rights reserved.
\r
13 // Load plugin specific language pack
\r
14 tinymce.PluginManager.requireLangPack('insert_tag');
\r
16 tinymce.create('tinymce.plugins.Insert_tagPlugin', {
\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
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
26 init : function (ed, url) {
\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
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
40 * A function which generates a function to insert the appropriate
\r
41 * tags, either [?], [code] or [tex].
\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
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
54 ed.selection.setContent('['+ insertionString + ']' +
\r
55 ed.selection.getContent() + '[/' + insertionString + ']');
\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
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
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
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
92 ed.selection.setContent('[media|640|480]http://' +
\r
93 ed.selection.getContent() + '[/media]');
\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
107 * Returns information about the plugin as a name/value array. The
\r
108 * current keys are longname, author, authorurl, infourl and version.
\r
110 * @return {Object} Name/value array containing information about the
\r
113 getInfo : function () {
\r
115 longname : 'Insert tag plugin',
\r
117 authorurl : 'http://www.atutor.ca',
\r
118 infourl : 'http://www.atutor.ca',
\r
119 version : "0.9beta"
\r
125 tinymce.PluginManager.add('insert_tag', tinymce.plugins.Insert_tagPlugin);
\r