From 0b1d9e2d791016c7347901a9e66e6d12caeaac00 Mon Sep 17 00:00:00 2001 From: "2SIC\\2cb" Date: Thu, 6 Apr 2017 10:37:03 +0200 Subject: [PATCH 1/4] added dirty check if debounce is disabled --- src/tinymce.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/tinymce.js b/src/tinymce.js index c0291af..e8b71ab 100644 --- a/src/tinymce.js +++ b/src/tinymce.js @@ -92,14 +92,13 @@ angular.module('ui.tinymce', []) // - the editor content has been modified [change] // - the node has changed [NodeChange] // - an object has been resized (table, image) [ObjectResized] - ed.on('ExecCommand change NodeChange ObjectResized', function() { - if (!options.debounce) { - ed.save(); - updateView(ed); - return; - } - debouncedUpdate(ed); - }); + ed.on('ExecCommand change NodeChange ObjectResized', function () { + if (options.debounce) debouncedUpdate(ed); + else if (ed.isDirty()) { + ed.save(); + updateView(ed); + } + }); ed.on('blur', function() { element[0].blur(); From b1769d255386164b097edacc12b03e9df30f7c20 Mon Sep 17 00:00:00 2001 From: "2SIC\\2cb" Date: Thu, 6 Apr 2017 10:46:00 +0200 Subject: [PATCH 2/4] jshint and build --- dist/tinymce.min.js | 2 +- src/tinymce.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dist/tinymce.min.js b/dist/tinymce.min.js index cd6b161..bdb8c52 100644 --- a/dist/tinymce.min.js +++ b/dist/tinymce.min.js @@ -1 +1 @@ -angular.module("ui.tinymce",[]).value("uiTinymceConfig",{}).directive("uiTinymce",["$rootScope","$compile","$timeout","$window","$sce","uiTinymceConfig","uiTinymceService",function(a,b,c,d,e,f,g){return f=f||{},f.baseUrl&&(tinymce.baseURL=f.baseUrl),{require:["ngModel","^?form"],priority:599,link:function(h,i,j,k){function l(a){a?(m(),o&&o.getBody().setAttribute("contenteditable",!1)):(m(),o&&!o.settings.readonly&&o.getDoc()&&o.getBody().setAttribute("contenteditable",!0))}function m(){o||(o=tinymce.get(j.id))}if(d.tinymce){var n,o,p=k[0],q=k[1]||null,r={debounce:!0},s=function(b){var c=b.getContent({format:r.format}).trim();c=e.trustAsHtml(c),p.$setViewValue(c),a.$$phase||h.$digest()},t=g.getUniqueId();j.$set("id",t),n={},angular.extend(n,h.$eval(j.uiTinymce));var u=function(a){var b;return function(d){c.cancel(b),b=c(function(){return function(a){a.isDirty()&&(a.save(),s(a))}(d)},a)}}(400),v={setup:function(b){b.on("init",function(){p.$render(),p.$setPristine(),p.$setUntouched(),q&&q.$setPristine()}),b.on("ExecCommand change NodeChange ObjectResized",function(){return r.debounce?void u(b):(b.save(),void s(b))}),b.on("blur",function(){i[0].blur(),p.$setTouched(),a.$$phase||h.$digest()}),b.on("remove",function(){i.remove()}),f.setup&&f.setup(b,{updateView:s}),n.setup&&n.setup(b,{updateView:s})},format:n.format||"html",selector:"#"+j.id};angular.extend(r,f,n,v),c(function(){r.baseURL&&(tinymce.baseURL=r.baseURL);var a=tinymce.init(r);a&&"function"==typeof a.then?a.then(function(){l(h.$eval(j.ngDisabled))}):l(h.$eval(j.ngDisabled))}),p.$formatters.unshift(function(a){return a?e.trustAsHtml(a):""}),p.$parsers.unshift(function(a){return a?e.getTrustedHtml(a):""}),p.$render=function(){m();var a=p.$viewValue?e.getTrustedHtml(p.$viewValue):"";o&&o.getDoc()&&(o.setContent(a),o.fire("change"))},j.$observe("disabled",l),h.$on("$tinymce:refresh",function(a,c){var d=j.id;if(angular.isUndefined(c)||c===d){var e=i.parent(),f=i.clone();f.removeAttr("id"),f.removeAttr("style"),f.removeAttr("aria-hidden"),tinymce.execCommand("mceRemoveEditor",!1,d),e.append(b(f)(h))}}),h.$on("$destroy",function(){m(),o&&(o.remove(),o=null)})}}}}]).service("uiTinymceService",[function(){var a=function(){var a="ui-tinymce",b=0,c=function(){return b++,a+"-"+b};return{getUniqueId:c}};return new a}]); \ No newline at end of file +angular.module("ui.tinymce",[]).value("uiTinymceConfig",{}).directive("uiTinymce",["$rootScope","$compile","$timeout","$window","$sce","uiTinymceConfig","uiTinymceService",function(a,b,c,d,e,f,g){return f=f||{},f.baseUrl&&(tinymce.baseURL=f.baseUrl),{require:["ngModel","^?form"],priority:599,link:function(h,i,j,k){function l(a){a?(m(),o&&o.getBody().setAttribute("contenteditable",!1)):(m(),o&&!o.settings.readonly&&o.getDoc()&&o.getBody().setAttribute("contenteditable",!0))}function m(){o||(o=tinymce.get(j.id))}if(d.tinymce){var n,o,p=k[0],q=k[1]||null,r={debounce:!0},s=function(b){var c=b.getContent({format:r.format}).trim();c=e.trustAsHtml(c),p.$setViewValue(c),a.$$phase||h.$digest()},t=g.getUniqueId();j.$set("id",t),n={},angular.extend(n,h.$eval(j.uiTinymce));var u=function(a){var b;return function(d){c.cancel(b),b=c(function(){return function(a){a.isDirty()&&(a.save(),s(a))}(d)},a)}}(400),v={setup:function(b){b.on("init",function(){p.$render(),p.$setPristine(),p.$setUntouched(),q&&q.$setPristine()}),b.on("ExecCommand change NodeChange ObjectResized",function(){r.debounce?u(b):b.isDirty()&&(b.save(),s(b))}),b.on("blur",function(){i[0].blur(),p.$setTouched(),a.$$phase||h.$digest()}),b.on("remove",function(){i.remove()}),f.setup&&f.setup(b,{updateView:s}),n.setup&&n.setup(b,{updateView:s})},format:n.format||"html",selector:"#"+j.id};angular.extend(r,f,n,v),c(function(){r.baseURL&&(tinymce.baseURL=r.baseURL);var a=tinymce.init(r);a&&"function"==typeof a.then?a.then(function(){l(h.$eval(j.ngDisabled))}):l(h.$eval(j.ngDisabled))}),p.$formatters.unshift(function(a){return a?e.trustAsHtml(a):""}),p.$parsers.unshift(function(a){return a?e.getTrustedHtml(a):""}),p.$render=function(){m();var a=p.$viewValue?e.getTrustedHtml(p.$viewValue):"";o&&o.getDoc()&&(o.setContent(a),o.fire("change"))},j.$observe("disabled",l),h.$on("$tinymce:refresh",function(a,c){var d=j.id;if(angular.isUndefined(c)||c===d){var e=i.parent(),f=i.clone();f.removeAttr("id"),f.removeAttr("style"),f.removeAttr("aria-hidden"),tinymce.execCommand("mceRemoveEditor",!1,d),e.append(b(f)(h))}}),h.$on("$destroy",function(){m(),o&&(o.remove(),o=null)})}}}}]).service("uiTinymceService",[function(){var a=function(){var a="ui-tinymce",b=0,c=function(){return b++,a+"-"+b};return{getUniqueId:c}};return new a}]); \ No newline at end of file diff --git a/src/tinymce.js b/src/tinymce.js index e8b71ab..954da8b 100644 --- a/src/tinymce.js +++ b/src/tinymce.js @@ -49,7 +49,7 @@ angular.module('ui.tinymce', []) } } } - + // fetch a unique ID from the service var uniqueId = uiTinymceService.getUniqueId(); attrs.$set('id', uniqueId); @@ -93,7 +93,9 @@ angular.module('ui.tinymce', []) // - the node has changed [NodeChange] // - an object has been resized (table, image) [ObjectResized] ed.on('ExecCommand change NodeChange ObjectResized', function () { - if (options.debounce) debouncedUpdate(ed); + if (options.debounce) { + debouncedUpdate(ed); + } else if (ed.isDirty()) { ed.save(); updateView(ed); From 035f1c30a86973d46b6631d98f058f7ffd36ec77 Mon Sep 17 00:00:00 2001 From: "2SIC\\2cb" Date: Thu, 6 Apr 2017 10:58:14 +0200 Subject: [PATCH 3/4] switched to spaces instead of tabs --- src/tinymce.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/tinymce.js b/src/tinymce.js index 954da8b..f81ad1c 100644 --- a/src/tinymce.js +++ b/src/tinymce.js @@ -92,15 +92,15 @@ angular.module('ui.tinymce', []) // - the editor content has been modified [change] // - the node has changed [NodeChange] // - an object has been resized (table, image) [ObjectResized] - ed.on('ExecCommand change NodeChange ObjectResized', function () { - if (options.debounce) { - debouncedUpdate(ed); - } - else if (ed.isDirty()) { - ed.save(); - updateView(ed); - } - }); + ed.on('ExecCommand change NodeChange ObjectResized', function () { + if (options.debounce) { + debouncedUpdate(ed); + } + else if (ed.isDirty()) { + ed.save(); + updateView(ed); + } + }); ed.on('blur', function() { element[0].blur(); From 7d2743cfa7d65dbe6540b3f2ad3e5c51308d4bb4 Mon Sep 17 00:00:00 2001 From: "2SIC\\2cb" Date: Thu, 6 Apr 2017 10:59:42 +0200 Subject: [PATCH 4/4] switched to spaces --- src/tinymce.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tinymce.js b/src/tinymce.js index f81ad1c..9107bb7 100644 --- a/src/tinymce.js +++ b/src/tinymce.js @@ -93,13 +93,13 @@ angular.module('ui.tinymce', []) // - the node has changed [NodeChange] // - an object has been resized (table, image) [ObjectResized] ed.on('ExecCommand change NodeChange ObjectResized', function () { - if (options.debounce) { + if (options.debounce) { debouncedUpdate(ed); } else if (ed.isDirty()) { ed.save(); updateView(ed); - } + } }); ed.on('blur', function() {