MDL-24932 moodleemoticon tinymce: use restoreSelection() instead of custom bookmark hack

Credit goes to Mauno Korpelainen for the tip on how to sort out this IE
behaviour. Also, I moved compressed dialog.js to the revision directory to prevent
browser caching issues.
This commit is contained in:
David Mudrak
2010-11-01 19:53:53 +00:00
parent f2ca88b07f
commit 1cf2faab39
3 changed files with 5 additions and 7 deletions
@@ -40,7 +40,7 @@ $stringmanager = get_string_manager();
<head>
<title><?php print_string('moodleemoticon:desc', 'editor_tinymce'); ?></title>
<script type="text/javascript" src="../../tiny_mce_popup.js?v=3.3.9.2"></script>
<script type="text/javascript" src="js/dialog.js?v=3.3.9.2&rev=6"></script>
<script type="text/javascript" src="js/rev2/dialog.js?v=3.3.9.2"></script>
</head>
<body>
@@ -1,10 +1,6 @@
var MoodleEmoticonDialog = {
bookmark : null,
init : function() {
this.bookmark = tinyMCEPopup.editor.selection.getBookmark(1, true);
// register event handlers for the table rows
tinymce.each(tinymce.DOM.select('tr.emoticoninfo', document), function(row) {
@@ -34,9 +30,10 @@ var MoodleEmoticonDialog = {
i = 0;
for (var emoticon in emoticons) {
if (i == index) {
tinyMCEPopup.editor.selection.moveToBookmark(this.bookmark);
if (tinymce.isIE) {
tinyMCEPopup.restoreSelection();
}
tinyMCEPopup.editor.execCommand('mceInsertContent', false, emoticons[emoticon]);
this.bookmark = tinyMCEPopup.editor.selection.getBookmark(1, true);
tinyMCEPopup.close();
return;
}
@@ -0,0 +1 @@
var MoodleEmoticonDialog={init:function(){tinymce.each(tinymce.DOM.select('tr.emoticoninfo',document),function(c){tinymce.dom.Event.add(c,'mouseover',function(e){this.style.backgroundColor='white'},c);tinymce.dom.Event.add(c,'mouseout',function(e){this.style.backgroundColor='transparent'},c);tinymce.dom.Event.add(c,'click',function(e){var a=/^emoticoninfo emoticoninfo-index-([0-9]+)$/.exec(this.className);if(a.length!=2){return true}var b=a[1];MoodleEmoticonDialog.insert(b)},c)})},insert:function(a){emoticons=tinyMCEPopup.editor._emoticons;i=0;for(var b in emoticons){if(i==a){if(tinymce.isIE){tinyMCEPopup.restoreSelection()}tinyMCEPopup.editor.execCommand('mceInsertContent',false,emoticons[b]);tinyMCEPopup.close();return}i++}},highlight:function(a){a.style.backgroundColor="white"},unhighlight:function(a){a.style.backgroundColor="transparent"}};tinyMCEPopup.onInit.add(MoodleEmoticonDialog.init,MoodleEmoticonDialog);