From 59860b90d60963c67055183aba7fdfe27a931bab Mon Sep 17 00:00:00 2001 From: scyrma Date: Thu, 24 Jul 2008 07:46:28 +0000 Subject: [PATCH] MDL-14741: created a 'nolink' plugin for tinymce. --- .../plugins/moodlenolink/editor_plugin.js | 1 + .../plugins/moodlenolink/editor_plugin_src.js | 78 ++++++++++++++++++ .../plugins/moodlenolink/img/ed_nolink.gif | Bin 0 -> 181 bytes .../tiny_mce/plugins/moodlenolink/langs/en.js | 3 + 4 files changed, 82 insertions(+) create mode 100644 lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/editor_plugin.js create mode 100644 lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/editor_plugin_src.js create mode 100644 lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/img/ed_nolink.gif create mode 100644 lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/langs/en.js diff --git a/lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/editor_plugin.js b/lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/editor_plugin.js new file mode 100644 index 0000000000..601ed4eaa2 --- /dev/null +++ b/lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/editor_plugin.js @@ -0,0 +1 @@ +(function(){tinymce.PluginManager.requireLangPack('moodlenolink');tinymce.create('tinymce.plugins.moodlenolinkPlugin',{init:function(ed,url){ed.addCommand('mcemoodlenolink',function(){var n,p;n=ed.selection.getNode();p=ed.dom.getParent(n,function(t){return ed.dom.getAttrib(t,'class')=='nolink'});if(p){ed.dom.remove(p,true)}else{ed.selection.setContent(''+ed.selection.getContent()+'')}});ed.addButton('moodlenolink',{title:'moodlenolink.desc',cmd:'mcemoodlenolink',image:url+'/img/ed_nolink.gif'});ed.onNodeChange.add(function(ed,cm,n){var p,c;c=cm.get('moodlenolink');p=ed.dom.getParent(n,'SPAN');c.setActive(p&&ed.dom.hasClass(p,'nolink'));if(p&&ed.dom.hasClass(p,'nolink')||ed.selection.getContent()){c.setDisabled(false)}else{c.setDisabled(true)}})},getInfo:function(){return{longname:'moodlenolink plugin',author:'Some author',authorurl:'http://tinymce.moxiecode.com',infourl:'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/moodlenolink',version:"1.0"}}});tinymce.PluginManager.add('moodlenolink',tinymce.plugins.moodlenolinkPlugin)})(); \ No newline at end of file diff --git a/lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/editor_plugin_src.js b/lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/editor_plugin_src.js new file mode 100644 index 0000000000..2a40c6f12a --- /dev/null +++ b/lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/editor_plugin_src.js @@ -0,0 +1,78 @@ +/** + * $Id$ + */ + +(function() { + // Load plugin specific language pack + tinymce.PluginManager.requireLangPack('moodlenolink'); + + tinymce.create('tinymce.plugins.moodlenolinkPlugin', { + /** + * Initializes the plugin, this will be executed after the plugin has been created. + * This call is done before the editor instance has finished it's initialization so use the onInit event + * of the editor instance to intercept that event. + * + * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in. + * @param {string} url Absolute URL to where the plugin is located. + */ + init : function(ed, url) { + // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mcemoodlenolink'); + ed.addCommand('mcemoodlenolink', function() { + var n, p; + + n = ed.selection.getNode(); + p = ed.dom.getParent(n, function(t) { + return ed.dom.getAttrib(t, 'class') == 'nolink'; + }); + + if (p) { + ed.dom.remove(p, true); + } else { + ed.selection.setContent('' + ed.selection.getContent() + ''); + } + + }); + + // Register moodlenolink button + ed.addButton('moodlenolink', { + title : 'moodlenolink.desc', + cmd : 'mcemoodlenolink', + image : url + '/img/ed_nolink.gif' + }); + + // Add a node change handler, selects the button in the UI when a image is selected + ed.onNodeChange.add(function(ed, cm, n) { + var p, c; + c = cm.get('moodlenolink'); + p = ed.dom.getParent(n, 'SPAN'); + + c.setActive(p && ed.dom.hasClass(p, 'nolink')); + + if (p && ed.dom.hasClass(p, 'nolink') || ed.selection.getContent()) { + c.setDisabled(false); + } else { + c.setDisabled(true); + } + }); + }, + + /** + * Returns information about the plugin as a name/value array. + * The current keys are longname, author, authorurl, infourl and version. + * + * @return {Object} Name/value array containing information about the plugin. + */ + getInfo : function() { + return { + longname : 'moodlenolink plugin', + author : 'Some author', + authorurl : 'http://tinymce.moxiecode.com', + infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/moodlenolink', + version : "1.0" + }; + } + }); + + // Register plugin + tinymce.PluginManager.add('moodlenolink', tinymce.plugins.moodlenolinkPlugin); +})(); diff --git a/lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/img/ed_nolink.gif b/lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/img/ed_nolink.gif new file mode 100644 index 0000000000000000000000000000000000000000..c9b8069b690e6d5fa4187c95921d2b602ce1a924 GIT binary patch literal 181 zcmZ?wbhEHb6k-r!*vtR|91INh3=HLpiU$}NJ~J@<=izzn>G^-bg8zH>{y%l<|E*j9 zpFjWq{{8>&-~a#rulSRNk%57qK?kH0WQGGv(ub3t+N}JKQ%+e%rS(23kvP#Jk1C(r6($Cbnx5m~7j)AY7@ZP* huk9?p`~KJWc_oa@=anbub9iuQ1UI*c2r@8O0|4XsMeG0o literal 0 HcmV?d00001 diff --git a/lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/langs/en.js b/lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/langs/en.js new file mode 100644 index 0000000000..dd2167e71a --- /dev/null +++ b/lib/editor/tinymce/jscripts/tiny_mce/plugins/moodlenolink/langs/en.js @@ -0,0 +1,3 @@ +tinyMCE.addI18n('en.moodlenolink',{ + desc : 'Prevent automatic linking' +}); -- 2.39.5