From 53b8df0721a34d467e4a4aa5183d32bae8364683 Mon Sep 17 00:00:00 2001 From: Aleksey Bobkov Date: Wed, 6 Jul 2016 18:27:27 -0700 Subject: [PATCH] Force rich editor to synchronize when a form is saved. --- .../formwidgets/richeditor/assets/js/build-min.js | 3 +++ .../formwidgets/richeditor/assets/js/richeditor.js | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/modules/backend/formwidgets/richeditor/assets/js/build-min.js b/modules/backend/formwidgets/richeditor/assets/js/build-min.js index 6b9a39850..9b076fcb7 100755 --- a/modules/backend/formwidgets/richeditor/assets/js/build-min.js +++ b/modules/backend/formwidgets/richeditor/assets/js/build-min.js @@ -513,6 +513,7 @@ this.$textarea.on('froalaEditor.contentChanged',this.proxy(this.onChange)) this.$textarea.on('froalaEditor.keydown',this.proxy(this.onKeydown)) this.$textarea.on('froalaEditor.html.get',this.proxy(this.onSyncContent)) this.$textarea.on('froalaEditor.html.set',this.proxy(this.onSetContent)) +this.$form.on('oc.beforeRequest',this.proxy(this.onFormBeforeRequest)) this.$textarea.froalaEditor(froalaOptions) this.editor=this.$textarea.data('froala.editor') this.$el.on('keydown','.fr-view figure',this.proxy(this.onFigureKeydown))} @@ -531,6 +532,7 @@ this.$textarea.off('froalaEditor.contentChanged',this.proxy(this.onChange)) this.$textarea.off('froalaEditor.keydown',this.proxy(this.onKeydown)) this.$textarea.off('froalaEditor.html.get',this.proxy(this.onSyncContent)) this.$textarea.off('froalaEditor.html.set',this.proxy(this.onSetContent)) +this.$form.off('oc.beforeRequest',this.proxy(this.onFormBeforeRequest)) $(window).off('resize',this.proxy(this.updateLayout)) $(window).off('oc.updateUi',this.proxy(this.updateLayout)) this.$el.off('dispose-control',this.proxy(this.dispose))} @@ -568,6 +570,7 @@ RichEditor.prototype.onFigureKeydown=function(ev){this.$textarea.trigger('figure RichEditor.prototype.onKeydown=function(ev,editor,keyEv){this.$textarea.trigger('keydown.oc.richeditor',[keyEv,this]) if(ev.isDefaultPrevented()){return false}} RichEditor.prototype.onChange=function(ev){this.$form.trigger('change')} +RichEditor.prototype.onFormBeforeRequest=function(ev){this.$textarea.val(this.$textarea.froalaEditor('html.get'))} var old=$.fn.richEditor $.fn.richEditor=function(option){var args=Array.prototype.slice.call(arguments,1),result this.each(function(){var $this=$(this) diff --git a/modules/backend/formwidgets/richeditor/assets/js/richeditor.js b/modules/backend/formwidgets/richeditor/assets/js/richeditor.js index f27c39ca5..67094e691 100755 --- a/modules/backend/formwidgets/richeditor/assets/js/richeditor.js +++ b/modules/backend/formwidgets/richeditor/assets/js/richeditor.js @@ -167,6 +167,7 @@ this.$textarea.on('froalaEditor.keydown', this.proxy(this.onKeydown)) this.$textarea.on('froalaEditor.html.get', this.proxy(this.onSyncContent)) this.$textarea.on('froalaEditor.html.set', this.proxy(this.onSetContent)) + this.$form.on('oc.beforeRequest', this.proxy(this.onFormBeforeRequest)) this.$textarea.froalaEditor(froalaOptions) @@ -199,6 +200,7 @@ this.$textarea.off('froalaEditor.keydown', this.proxy(this.onKeydown)) this.$textarea.off('froalaEditor.html.get', this.proxy(this.onSyncContent)) this.$textarea.off('froalaEditor.html.set', this.proxy(this.onSetContent)) + this.$form.off('oc.beforeRequest', this.proxy(this.onFormBeforeRequest)) $(window).off('resize', this.proxy(this.updateLayout)) $(window).off('oc.updateUi', this.proxy(this.updateLayout)) @@ -329,6 +331,14 @@ this.$form.trigger('change') } + RichEditor.prototype.onFormBeforeRequest = function(ev) { + // Instantly synchronizes HTML content. + // The onSyncContent() method (above) is involved + // into this call, so the resulting HTML is (optionally) + // beautified + this.$textarea.val(this.$textarea.froalaEditor('html.get')) + } + // RICHEDITOR PLUGIN DEFINITION // ============================