Koha/koha-tmpl/intranet-tmpl/prog/en/includes/wysiwyg-systempreferences.inc
David Cook f4cf075fbe Bug 21131: Remove the TinyMCE.isDirty() check that caused unexpected behaviour
When using the WYSIWYG editor for system preferences, the editor only
updates the textarea element if the content is different from the
original content. This means if you change a system preference and
then change it back to the original content, the textarea will have
the 2nd last change you made.

This patch removes the TinyMCE.isDirty() check, which was responsible
for comparing the original and changed content. Every input/keydown/dragend
or TinyMCE command will cause the textarea element to be updated and
trigger the input event which causes the "modified" class to be added
to the element, so that the system preference can be saved.

__TEST PLAN__

_Before applying_
0. Change "UseWYSIWYGinSystemPreferences" to "Show"
1. Change "opaccredits" to "123a"
2. Click "Save all OPAC preferences"
3. Reload the page
4. Change "opaccredits" to "123"
5. Change "opaccredits" to "123a"
6. Click "Save all OPAC preferences"
7. Reload the page
8. Note that "opaccredits" says "123"

_Apply the patch_

_After applying_
1. Change "opaccredits" to "123a"
2. Change "opaccredits" to "123"
3. Click "Save all OPAC preferences"
4. Reload the page
5. Note that "opaccredits" says "123" (and not "123a")
6. Change "opaccredits" to "1234"
7. Click "Save all OPAC preferences"
8. Reload the page
9. Note that "opaccredits" says "1234"

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2018-08-09 11:11:22 +00:00

59 lines
2.5 KiB
C++

[% USE Asset %]
[% #Enable tinymce for system preferences %]
[% Asset.js("lib/tiny_mce/tiny_mce.js") %]
<script>
[%# Save TinyMCE content and trigger an event on the original element %]
function wysiwyg_change (ed){
ed.save();
var original_textarea = ed.getElement();
$(original_textarea).trigger("input");
}
tinyMCE.baseURL = "[% interface %]/lib/tiny_mce";
tinyMCE.init({
setup : function(ed) {
ed.onInit.add(function(editor){
[%-
#Ideally, it would be nice just to use the "oninput" event, which captures keyboard input, dragging, pasting, etc.
#However, it doesn't work in IE when the event listener is for an element which is "contenteditable". Since TinyMCE
#uses a "contenteditable" body element in an iframe element, it's never going to fire in IE.
#We can get around this a bit by using "onkeyup" and "ondragend".
#"ondragend" occurs after you drag content within the editor. "ondrop" is for when you drag content from outside the
#editor but it doesn't "dirty" the editor, which makes it useless, as the editor won't save unless it's dirty.
#"onpaste" is useless in this same way.
#Reference:
#https://developer.mozilla.org/en-US/docs/Web/Events/input
#https://connect.microsoft.com/IE/feedbackdetail/view/794285
-%]
tinyMCE.dom.Event.bind(editor.getBody(), 'input keyup dragend', function(e){
wysiwyg_change(ed);
});
});
// Register change when TinyMCE command returns isDirty()
ed.onExecCommand.add(function(ed, cmd, ui, val) {
wysiwyg_change(ed);
});
},
mode : "specific_textareas",
editor_selector : "mce",
theme : "advanced",
content_css : "[% interface %]/[% theme %]/css/tinymce.css",
plugins : "table,save,advhr,advlink,contextmenu,advimage",
theme_advanced_buttons1 : "bold,italic,|,cut,copy,paste,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,|,image,link,unlink,anchor,cleanup,help,code,advhr,",
theme_advanced_buttons2 : "tablecontrols,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,removeformat,|,visualaid,|,sub,sup,|,charmap|,forecolor,backcolor",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_path_location : "bottom",
theme_advanced_resizing : true,
apply_source_formatting : true
});
//]]>
</script>