MDL-24507 tinymce moodleemoticon plugin replaces all occurrences of emoticon text...
authorDavid Mudrak <david.mudrak@gmail.com>
Wed, 27 Oct 2010 22:27:56 +0000 (22:27 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Wed, 27 Oct 2010 22:27:56 +0000 (22:27 +0000)
lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/editor_plugin.js
lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/editor_plugin_src.js

index c29fbbb..8265f2a 100644 (file)
@@ -1 +1 @@
-(function(){tinymce.create('tinymce.plugins.MoodleEmoticon',{_emoticons:{},init:function(ed,url){ed.addCommand('mceMoodleEmoticon',function(){lang=ed.getParam('language');ed.windowManager.open({file:url+'/dialog.php?lang='+lang,width:250+parseInt(ed.getLang('moodleemoticon.delta_width',0)),height:400+parseInt(ed.getLang('moodleemoticon.delta_height',0)),inline:1},{plugin_url:url,})});ed.onInit.add(function(ed){var data=ed.getContent();this._emoticons=tinymce.util.JSON.parse(ed.getParam('moodleemoticon_emoticons'));for(var emotxt in this._emoticons){data=data.replace(emotxt,this._emoticons[emotxt])}ed.setContent(data)});ed.onPreProcess.add(function(ed,o){if(o.save){tinymce.each(ed.dom.select('img.emoticon',o.node),function(image){var emoticontxt='';var matches=/^emoticon emoticon-index-([0-9]+)$/.exec(image.className);if(matches.length!=2){return true}var index=matches[1];var search=new RegExp('class="emoticon emoticon-index-'.concat(index,'"'));for(var emotxt in this._emoticons){if(search.test(this._emoticons[emotxt])){emoticontxt=emotxt;break}}if(emoticontxt){ed.dom.setOuterHTML(image,emoticontxt)}},this)}});ed.addButton('moodleemoticon',{title:'moodleemoticon.desc',cmd:'mceMoodleEmoticon',image:url+'/img/moodleemoticon.gif'})},createControl:function(n,cm){return null},getInfo:function(){return{longname:'Moodle Emoticon plugin',author:'David Mudrak',authorurl:'http://mudrak.name',infourl:'http://moodle.org',version:"1.0"}}});tinymce.PluginManager.add('moodleemoticon',tinymce.plugins.MoodleEmoticon)})();
+(function(){tinymce.create('tinymce.plugins.MoodleEmoticon',{_emoticons:{},init:function(ed,url){ed.addCommand('mceMoodleEmoticon',function(){lang=ed.getParam('language');ed.windowManager.open({file:url+'/dialog.php?lang='+lang,width:250+parseInt(ed.getLang('moodleemoticon.delta_width',0)),height:400+parseInt(ed.getLang('moodleemoticon.delta_height',0)),inline:1},{plugin_url:url,})});ed.onInit.add(function(ed){var data=ed.getContent();this._emoticons=tinymce.util.JSON.parse(ed.getParam('moodleemoticon_emoticons'));for(var emotxt in this._emoticons){search=emotxt.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,'\\$&');search=new RegExp(search,'g');data=data.replace(search,this._emoticons[emotxt])}ed.setContent(data)});ed.onPreProcess.add(function(ed,o){if(o.save){tinymce.each(ed.dom.select('img.emoticon',o.node),function(image){var emoticontxt='';var matches=/^emoticon emoticon-index-([0-9]+)$/.exec(image.className);if(matches.length!=2){return true}var index=matches[1];var search=new RegExp('class="emoticon emoticon-index-'.concat(index,'"'));for(var emotxt in this._emoticons){if(search.test(this._emoticons[emotxt])){emoticontxt=emotxt;break}}if(emoticontxt){ed.dom.setOuterHTML(image,emoticontxt)}},this)}});ed.addButton('moodleemoticon',{title:'moodleemoticon.desc',cmd:'mceMoodleEmoticon',image:url+'/img/moodleemoticon.gif'})},createControl:function(n,cm){return null},getInfo:function(){return{longname:'Moodle Emoticon plugin',author:'David Mudrak',authorurl:'http://mudrak.name',infourl:'http://moodle.org',version:"1.0"}}});tinymce.PluginManager.add('moodleemoticon',tinymce.plugins.MoodleEmoticon)})();
index c1f7954..51e3022 100644 (file)
                 var data = ed.getContent();
                 this._emoticons = tinymce.util.JSON.parse(ed.getParam('moodleemoticon_emoticons'));
                 for (var emotxt in this._emoticons) {
-                    data = data.replace(emotxt, this._emoticons[emotxt]);
+                    // escape the metacharacters so we can use it as regexp
+                    search = emotxt.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
+                    // convert to regexp
+                    search = new RegExp(search, 'g');
+                    // and replace all occurrences of it with the image
+                    data = data.replace(search, this._emoticons[emotxt]);
                 }
                 ed.setContent(data);
             });