From 0e78e3f3dc7658d45c4ef4ab850f0a77909c3a2b Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 28 Jul 2014 13:29:44 +1200 Subject: [PATCH] API Let update interval of tinymce be changed or disabled --- forms/HtmlEditorConfig.php | 1 + javascript/HtmlEditorField.js | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/forms/HtmlEditorConfig.php b/forms/HtmlEditorConfig.php index 91f4eb08d..116e5f203 100644 --- a/forms/HtmlEditorConfig.php +++ b/forms/HtmlEditorConfig.php @@ -73,6 +73,7 @@ class HtmlEditorConfig { 'editor_selector' => "htmleditor", 'width' => "100%", 'auto_resize' => false, + 'update_interval' => 5000, // Ensure update of this data every 5 seconds to the underlying textarea 'theme' => "advanced", 'theme_advanced_layout_manager' => "SimpleLayout", diff --git a/javascript/HtmlEditorField.js b/javascript/HtmlEditorField.js index 5b88580e4..eb0067906 100644 --- a/javascript/HtmlEditorField.js +++ b/javascript/HtmlEditorField.js @@ -89,20 +89,22 @@ ss.editorWrappers.tinyMCE = (function() { // after an (undetected) inline change. This "blur" causes onChange // to trigger, which will change the button markup to show "alternative" styles, // effectively cancelling the original click event. - var interval; - jQuery(ed.getBody()).on('focus', function() { - interval = setInterval(function() { - // Update underlying element as necessary - var element = jQuery(ed.getElement()); - if(ed.isDirty()) { - // Set content without triggering editor content cleanup - element.val(ed.getContent({format : 'raw', no_events : 1})); - } - }, 5000); - }); - jQuery(ed.getBody()).on('blur', function() { - clearInterval(interval); - }); + if(ed.settings.update_interval) { + var interval; + jQuery(ed.getBody()).on('focus', function() { + interval = setInterval(function() { + // Update underlying element as necessary + var element = jQuery(ed.getElement()); + if(ed.isDirty()) { + // Set content without triggering editor content cleanup + element.val(ed.getContent({format : 'raw', no_events : 1})); + } + }, ed.settings.update_interval); + }); + jQuery(ed.getBody()).on('blur', function() { + clearInterval(interval); + }); + } }); this.instance.onChange.add(function(ed, l) { // Update underlying textarea on every change, so external handlers