From e3c6de07ecda4dfabb88f195edccf457bc1161e6 Mon Sep 17 00:00:00 2001 From: daniellmorris Date: Wed, 3 Feb 2016 01:08:38 -0600 Subject: [PATCH 1/4] Update templates.js --- lib/client/templates.js | 59 +++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/lib/client/templates.js b/lib/client/templates.js index b7527d9..4350794 100644 --- a/lib/client/templates.js +++ b/lib/client/templates.js @@ -1,47 +1,48 @@ -Template.afSummernote.created = function () { - this.value = new ReactiveVar(this.data.value); -}; - -Template.afSummernote.rendered = function() { +Template.afSummernote.onRendered(function() { var self = this; var options = this.data.atts.settings || {}; var $editor = $(this.firstNode); - - var onblur = options.onblur; - options.onblur = function(e) { - $editor.change(); - if (typeof onblur === 'function') { - onblur.apply(this, arguments); - } - }; + this.$editor = $editor + this.onblur = options.onblur; $editor.summernote(options); - + + var value = null; this.autorun(function () { - $editor.summernote('code', self.value.get()); + var dataContext = Template.currentData(); + if (value!=dataContext.value) { + $editor.summernote('code', dataContext.value); + value = dataContext.value; + } }); $editor.closest('form').on('reset', function() { $editor.summernote('code', ''); }); -}; +}); + + +Template.afSummernote.events({ + 'summernote.blur': function(event, template) { + template.$(event.target)[0].value = template.$(event.target).summernote('code'); + template.$(event.target).change(); + var onblur = template.onblur; + if (typeof onblur === 'function') { + onblur.apply(this, arguments); + } + } +}); + +Template.afSummernote.onDestroyed(function() { + if (this.$editor){ + this.$editor.summernote('destroy'); + } +}); Template.afSummernote.helpers({ atts: function () { var self = this; - /** - * This is bit hacky but created and rendered callback sometimes - * (or always?) get empty value. This helper gets called multiple - * times so we intercept and save the value once it is not empty. - */ - Tracker.nonreactive(function () { - var t = Template.instance(); - if (t.value.get() !== self.value) { - t.value.set(self.value); - } - }); - return _.omit(this.atts, 'settings'); } -}); \ No newline at end of file +}); From 8455cf367cb676093d8946fb1a6ba606efa55d43 Mon Sep 17 00:00:00 2001 From: daniellmorris Date: Wed, 3 Feb 2016 01:11:23 -0600 Subject: [PATCH 2/4] Update templates.js Add comment explaining why we are setting the value field --- lib/client/templates.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/client/templates.js b/lib/client/templates.js index 4350794..fb7accf 100644 --- a/lib/client/templates.js +++ b/lib/client/templates.js @@ -24,8 +24,12 @@ Template.afSummernote.onRendered(function() { Template.afSummernote.events({ 'summernote.blur': function(event, template) { + // Unfortunatly there seems to be an issue where value is not updated in the + // summernote code in some cases. We are just garenteeing that this is updated before + // triggering the autform change detection template.$(event.target)[0].value = template.$(event.target).summernote('code'); template.$(event.target).change(); + var onblur = template.onblur; if (typeof onblur === 'function') { onblur.apply(this, arguments); From 8e2214a24d8412ee2d04ccd35d78bdddf7801e87 Mon Sep 17 00:00:00 2001 From: daniellmorris Date: Wed, 3 Feb 2016 03:39:37 -0600 Subject: [PATCH 3/4] Update templates.js Make so there is no error if template is added directly as a template without the use of autoform --- lib/client/templates.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/client/templates.js b/lib/client/templates.js index fb7accf..df22dac 100644 --- a/lib/client/templates.js +++ b/lib/client/templates.js @@ -1,6 +1,12 @@ Template.afSummernote.onRendered(function() { var self = this; - var options = this.data.atts.settings || {}; + var options = {}; + if (this.data && this.data.atts) { + options = this.data.atts.settings || {}; + } else { + options = this.data; + } + console.log(this); var $editor = $(this.firstNode); this.$editor = $editor this.onblur = options.onblur; From 2aa508565d15b8d85bb0a77c3aad46c0e543c1f5 Mon Sep 17 00:00:00 2001 From: daniellmorris Date: Sun, 21 Feb 2016 01:53:11 -0600 Subject: [PATCH 4/4] Added files via upload --- lib/client/templates.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/client/templates.js b/lib/client/templates.js index df22dac..1f8169a 100644 --- a/lib/client/templates.js +++ b/lib/client/templates.js @@ -6,7 +6,6 @@ Template.afSummernote.onRendered(function() { } else { options = this.data; } - console.log(this); var $editor = $(this.firstNode); this.$editor = $editor this.onblur = options.onblur;