Koha/koha-tmpl/intranet-tmpl/prog/en/includes/wysiwyg-systempreferences.inc
Julian Maurice ed7543287b Bug 20538: Remove the need of writing [% KOHA_VERSION %] everywhere
Having to write [% KOHA_VERSION %] for each url is bad because:
- It's easily forgettable when adding new <script> or <link>
- It prevents grep'ing for the full filename
- It violates the DRY principle
- If at some point we want to change the "force js and css reload"
  mechanism, it will be tedious

This patch:
- adds a Template::Toolkit plugin that generates <script> and
  <link> tags for JS and CSS files, and inserts automatically the Koha
  version in the filename
- use the new plugin to remove all occurences of [% KOHA_VERSION %]
- remove the code that was adding KOHA_VERSION as a template variable

Test plan:
1. Apply patch
2. Go to several different pages in Koha (opac and intranet) while
   checking your browser's dev tools (there should be no 404 for JS and
   CSS files, and the Koha version should appear in filenames) and the
   server logs (there should be no "File not found")
3. `git grep KOHA_VERSION` should return nothing
4. prove t/db_dependent/Koha/Template/Plugin/Asset.t

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

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

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2018-04-13 11:49:44 -03:00

63 lines
2.6 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){
if (ed.isDirty()){
wysiwyg_change(ed);
}
});
});
// Register change when TinyMCE command returns isDirty()
ed.onExecCommand.add(function(ed, cmd, ui, val) {
if (ed.isDirty()){
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>