Force rich editor to synchronize when a form is saved.

This commit is contained in:
Aleksey Bobkov 2016-07-06 18:27:27 -07:00
parent 305f20e4f9
commit 53b8df0721
2 changed files with 13 additions and 0 deletions

View File

@ -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)

View File

@ -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
// ============================