From ca7250661c626db7f8e5d1bb50cacbc20f98fc5e Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Wed, 27 Oct 2010 18:13:17 +0000 Subject: [PATCH] MDL-24507 new TinyMCE plugin moodleemoticon --- .../3.3.9.2/plugins/moodleemoticon/dialog.php | 86 +++++++++++++ .../plugins/moodleemoticon/editor_plugin.js | 1 + .../moodleemoticon/editor_plugin_src.js | 119 ++++++++++++++++++ .../moodleemoticon/img/moodleemoticon.gif | Bin 0 -> 1165 bytes .../plugins/moodleemoticon/js/dialog.js | 9 ++ 5 files changed, 215 insertions(+) create mode 100644 lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/dialog.php create mode 100644 lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/editor_plugin.js create mode 100644 lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/editor_plugin_src.js create mode 100644 lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/img/moodleemoticon.gif create mode 100644 lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/js/dialog.js diff --git a/lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/dialog.php b/lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/dialog.php new file mode 100644 index 00000000000..da0d7b4031d --- /dev/null +++ b/lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/dialog.php @@ -0,0 +1,86 @@ +. + +/** + * Displays the TinyMCE popup window to insert a Moodle emoticon + * + * @package tinymceplugin + * @subpackage moodleemoticon + * @copyright 2010 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +define('NO_MOODLE_COOKIES', true); // Session not used here +define('NO_UPGRADE_CHECK', true); // Ignore upgrade check + +require_once(dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))) . '/config.php'); + +$PAGE->set_context(get_system_context()); + +$emoticonmanager = get_emoticon_manager(); +$stringmanager = get_string_manager(); + +?> + + + + <?php print_string('moodleemoticon:desc', 'editor_tinymce'); ?> + + + + + + +get_emoticons(); +// this is tricky - we must somehow include the information about the original +// emoticon text so that we can replace the image back with it on editor save. +// so we are going to encode the index of the emoticon. this will break when the +// admin changes the mapping table while the user has the editor opened +// but I am not able to come with better solution at the moment :-/ +$index = 0; +foreach ($emoticons as $emoticon) { + $txt = $emoticon->text; + $img = $OUTPUT->render( + $emoticonmanager->prepare_renderable_emoticon($emoticon, array('class' => 'emoticon emoticon-index-'.$index++))); + if ($stringmanager->string_exists($emoticon->altidentifier, $emoticon->altcomponent)) { + $alt = get_string($emoticon->altidentifier, $emoticon->altcomponent); + } else { + $alt = ''; + } + echo html_writer::tag('tr', + html_writer::tag('td', $img, array('style' => 'width:20%;text-align:center;')) . + html_writer::tag('td', s($txt), array('style' => 'width:40%;text-align:center;font-family:monospace;')) . + html_writer::tag('td', $alt), + array( + 'onMouseOver' => 'this.style.backgroundColor="white"', + 'onMouseOut' => 'this.style.backgroundColor="transparent"', + 'onClick' => 'MoodleEmoticonDialog.insert(' . json_encode($img) . ')', + ) + ); +} + +?> +
+ +
+ +
+ + + diff --git a/lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/editor_plugin.js b/lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/editor_plugin.js new file mode 100644 index 00000000000..c29fbbbeb7b --- /dev/null +++ b/lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/editor_plugin.js @@ -0,0 +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)})(); diff --git a/lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/editor_plugin_src.js b/lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/editor_plugin_src.js new file mode 100644 index 00000000000..c1f7954a6bd --- /dev/null +++ b/lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/editor_plugin_src.js @@ -0,0 +1,119 @@ +/** + * TinyMCE plugin MoodleEmoticon - provides GUI to insert emoticon images + * + * Based on the example plugin (c) 2009 Moxiecode Systems AB + * + * @author David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +(function() { + tinymce.create('tinymce.plugins.MoodleEmoticon', { + + /** + * Holds the list of emoticons provided by emoticon_manager + * + * @private + */ + _emoticons : {}, + + /** + * 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('mceMoodleEmoticon'); + 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, // Plugin absolute URL + }); + }); + + // Add an observer to the onInit event to convert emoticon texts to images + 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); + }); + + // Add an observer to the onPreProcess event to convert emoticon images to texts + 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) { + // this is not valid emoticon image inserted via dialog + // return true so that each() does not halt + 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); + } + }); + + // Register moodleemoticon button + ed.addButton('moodleemoticon', { + title : 'moodleemoticon.desc', + cmd : 'mceMoodleEmoticon', + image : url + '/img/moodleemoticon.gif' + }); + }, + + /** + * Creates control instances based in the incomming name. This method is normally not + * needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons + * but you sometimes need to create more complex controls like listboxes, split buttons etc then this + * method can be used to create those. + * + * @param {String} n Name of the control to create. + * @param {tinymce.ControlManager} cm Control manager to use inorder to create new control. + * @return {tinymce.ui.Control} New control instance or null if no control was created. + */ + createControl : function(n, cm) { + return null; + }, + + /** + * 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 : 'Moodle Emoticon plugin', + author : 'David Mudrak', + authorurl : 'http://mudrak.name', + infourl : 'http://moodle.org', + version : "1.0" + }; + } + }); + + // Register plugin + tinymce.PluginManager.add('moodleemoticon', tinymce.plugins.MoodleEmoticon); +})(); diff --git a/lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/img/moodleemoticon.gif b/lib/editor/tinymce/tiny_mce/3.3.9.2/plugins/moodleemoticon/img/moodleemoticon.gif new file mode 100644 index 0000000000000000000000000000000000000000..c621319fd20694c2ae3030d3001ac5993054a3af GIT binary patch literal 1165 zcmciBi8tGK008ixlor!IM_4+0E3I8`-9~L5>#Jglw(A-#N~&#;IHEMNY&A^@igtn` zrlBoWQ>$Z+*6aG*BicuUmgw>vi8vBx?(27axBV0Q{12bt<3Zj&F?a|Mt-purqdsou&U(Z~9U({iBvZWd(uv$$Vs(C0 zMPYaaC;A~L>bIh>#*&CfrIhA!Qd7n0`il5Y9=W3`;rF}gE%%w-HKdjYtf9xJhg;(Z zTN%S0=f~P3`kut}cQE-+D3eb~BhO<-`%*+bq`AIues8^?KWAa!qGT{qFr2wGbatGd zB^@FOM-rw-Ql|I?!qH6G%S)m$##;e(UXVH`U``8)gyY4c$txSL;v^GE^RHuPCs?y@ z(q;sm;wj3)RI+m7((3Ds#iUo`v4rI|lMp3WRFd4%n%L4Mtx-~YkPStNxH0uRmJ;f+{0Bn0`LxLpVobW9Zslr&6n6;;uIG7YHX z^a>tOrfXFkOr31f#sL*WvpIw*vrOuASXrc3=Npt&u#SRi7(m5_H9upj0#sFu>MtOA zDyIEGv;7LzW*gPjn7YKIy=l;vpoVy$V*<@Bpl6}lN<@1P7_I|dsZR43(A_}|g<7=` z81sOhhv{n&V;Q3R6Tk()SPkGJpzFs#GGc7OP&Nj0QMekI8c|a#Kq_F&6rKktAE09Z`5Oa$02O0k75tA}F}rUW)EFj};&L^KndlOH z{1g##HJY1QLjXDm{p-IdkR=8ItM^0NYW;KHwjL{Y`n;+u*Sxajg!b_ryl*>`k{eRQ ztqJ4?9Pz$Q&e?yiyUVe;!OH$&Fy{t=0FejU&NPr5!z|=s z{&$u3hs)gT9GO8(?rw>v$2%Wvb;;+h>Cu>_mn?g3NJuOI`J