From 41a278b64665b9b6e0b52e0477ff870c8e370ad8 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Freire Gama Date: Fri, 6 Oct 2017 04:29:50 -0300 Subject: [PATCH 01/10] DESTROY REDACTOR WHEN SCOPE IS DESTROYED --- angular-redactor-2.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/angular-redactor-2.js b/angular-redactor-2.js index 5db78cb..8f82671 100644 --- a/angular-redactor-2.js +++ b/angular-redactor-2.js @@ -56,6 +56,10 @@ }); } }; + + scope.$on('$destroy', function() { + element.redactor('core.destroy'); + }); } }; }]); From 8275eafc9572ff146ea3f3afc977fe616486cc34 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Freire Gama Date: Fri, 8 Mar 2019 05:21:44 -0300 Subject: [PATCH 02/10] fix --- angular-redactor-3.js | 66 +++++++++++++++++++++++++++++++++++++++++++ bower.json | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 angular-redactor-3.js diff --git a/angular-redactor-3.js b/angular-redactor-3.js new file mode 100644 index 0000000..932abb9 --- /dev/null +++ b/angular-redactor-3.js @@ -0,0 +1,66 @@ +(function() { + 'use strict'; + + /** + * usage: + * + * additional options: + * redactor: hash (pass in a redactor options hash) + * + */ + + var redactorOptions = {}; + + angular.module('angular-redactor', []) + .constant('redactorOptions', redactorOptions) + .directive('redactor', ['$timeout', function($timeout) { + return { + restrict: 'A', + require: 'ngModel', + link: function(scope, element, attrs, ngModel) { + + // Expose scope var with loaded state of Redactor + scope.redactorLoaded = false; + + var updateModel = function updateModel(value) { + // $timeout to avoid $digest collision + $timeout(function() { + scope.$apply(function() { + ngModel.$setViewValue(value); + }); + }); + }, + options = { + callbacks: { + change: updateModel + } + }, + additionalOptions = attrs.redactor ? + scope.$eval(attrs.redactor) : {}, + editor; + + angular.extend(options, redactorOptions, additionalOptions); + + // put in timeout to avoid $digest collision. call render() + // to set the initial value. + $timeout(function() { + editor = $R(element[0], options); + ngModel.$render(); + }); + + ngModel.$render = function() { + if(angular.isDefined(editor)) { + $timeout(function() { + element.redactor('code.set', ngModel.$viewValue || ''); + scope.redactorLoaded = true; + }); + } + }; + + scope.$on('$destroy', function() { + element.redactor('core.destroy'); + }); + } + }; + }]); +})(); \ No newline at end of file diff --git a/bower.json b/bower.json index 36ca378..8620bb8 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-redactor", - "main": "angular-redactor.js", + "main": "angular-redactor-3.js", "version": "1.1.5", "homepage": "https://github.com/TylerGarlick/angular-redactor", "authors": [ From 326c4f9022733340842d49907224bdfa2bb72e99 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Freire Gama Date: Fri, 8 Mar 2019 06:04:05 -0300 Subject: [PATCH 03/10] support Reactor 3 --- angular-redactor-3.js | 128 ++++++++++++++++++++++++------------------ bower.json | 2 +- 2 files changed, 74 insertions(+), 56 deletions(-) diff --git a/angular-redactor-3.js b/angular-redactor-3.js index 932abb9..1bce2ce 100644 --- a/angular-redactor-3.js +++ b/angular-redactor-3.js @@ -1,66 +1,84 @@ (function() { - 'use strict'; + 'use strict'; - /** - * usage: - * - * additional options: - * redactor: hash (pass in a redactor options hash) - * - */ + /** + * usage: + * + * additional options: + * redactor: hash (pass in a redactor options hash) + * + */ - var redactorOptions = {}; + var redactorOptions = {}; - angular.module('angular-redactor', []) - .constant('redactorOptions', redactorOptions) - .directive('redactor', ['$timeout', function($timeout) { - return { - restrict: 'A', - require: 'ngModel', - link: function(scope, element, attrs, ngModel) { + angular + .module('angular-redactor', []) + .constant('redactorOptions', redactorOptions) + .directive('redactor', [ + '$timeout', + function($timeout) { + return { + restrict: 'A', + require: 'ngModel', + link: function(scope, element, attrs, ngModel) { + var randomId = + 'redactor-' + + Math.floor((1 + Math.random()) * 2e13) + .toString(16) + .substr(1) + + +new Date(), + debounce; - // Expose scope var with loaded state of Redactor - scope.redactorLoaded = false; + element.attr('id', randomId); - var updateModel = function updateModel(value) { - // $timeout to avoid $digest collision - $timeout(function() { - scope.$apply(function() { - ngModel.$setViewValue(value); - }); - }); - }, - options = { - callbacks: { - change: updateModel - } - }, - additionalOptions = attrs.redactor ? - scope.$eval(attrs.redactor) : {}, - editor; + // Expose scope var with loaded state of Redactor + scope.redactorLoaded = false; - angular.extend(options, redactorOptions, additionalOptions); + var updateModel = function updateModel(value) { + if (debounce) { + $timeout.cancel(debounce); + debounce = undefined; + } + // $timeout to avoid $digest collision + debounce = $timeout(function() { + ngModel.$setViewValue(value); + debounce = undefined; + }, 500); + }; - // put in timeout to avoid $digest collision. call render() - // to set the initial value. - $timeout(function() { - editor = $R(element[0], options); - ngModel.$render(); - }); + var options = { + callbacks: { + changed: updateModel + } + }, + additionalOptions = attrs.redactor + ? scope.$eval(attrs.redactor) + : {}, + editor; - ngModel.$render = function() { - if(angular.isDefined(editor)) { - $timeout(function() { - element.redactor('code.set', ngModel.$viewValue || ''); - scope.redactorLoaded = true; - }); - } - }; + angular.extend(options, redactorOptions, additionalOptions); - scope.$on('$destroy', function() { - element.redactor('core.destroy'); - }); - } + // put in timeout to avoid $digest collision. call render() + // to set the initial value. + $timeout(function() { + editor = $R('#' + randomId, options); + ngModel.$render(); + }); + + ngModel.$render = function() { + if (angular.isDefined(editor)) { + $timeout(function() { + editor.source.setCode(ngModel.$viewValue || ''); + scope.redactorLoaded = true; + }); + } }; - }]); -})(); \ No newline at end of file + + scope.$on('$destroy', function() { + $R('#' + randomId, 'destroy'); + }); + } + }; + } + ]); +})(); diff --git a/bower.json b/bower.json index 8620bb8..d477889 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "angular-redactor", "main": "angular-redactor-3.js", - "version": "1.1.5", + "version": "1.1.7", "homepage": "https://github.com/TylerGarlick/angular-redactor", "authors": [ "Tyler Garlick " From 008b5575345cbe0d78add91cac3dd859b5b56ed7 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Freire Gama Date: Mon, 25 Nov 2019 22:07:30 -0300 Subject: [PATCH 04/10] Update angular-redactor-3.js --- angular-redactor-3.js | 1 + 1 file changed, 1 insertion(+) diff --git a/angular-redactor-3.js b/angular-redactor-3.js index 1bce2ce..29d343b 100644 --- a/angular-redactor-3.js +++ b/angular-redactor-3.js @@ -47,6 +47,7 @@ }; var options = { + spellcheck: false, callbacks: { changed: updateModel } From 97a8a7fc40ad849d2af73ee6b9741ababaafb4a9 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Freire Gama Date: Mon, 16 Dec 2019 17:19:14 -0300 Subject: [PATCH 05/10] fix: prevent ngModel method to be fired after destroy --- angular-redactor-3.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/angular-redactor-3.js b/angular-redactor-3.js index 1bce2ce..dba3571 100644 --- a/angular-redactor-3.js +++ b/angular-redactor-3.js @@ -21,6 +21,12 @@ restrict: 'A', require: 'ngModel', link: function(scope, element, attrs, ngModel) { + var castFunction = function (fn, defaultOutput) { + Object.prototype.toString.call(fn) === '[object Function]' + ? fn + : function() {} + } + var randomId = 'redactor-' + Math.floor((1 + Math.random()) * 2e13) @@ -41,9 +47,9 @@ } // $timeout to avoid $digest collision debounce = $timeout(function() { - ngModel.$setViewValue(value); + castFunction((ngModel || {}).$setViewValue)(value); debounce = undefined; - }, 500); + }, 250); }; var options = { From 4022f71c33e0d2909fe7db043428946fccad7cdb Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Freire Gama Date: Mon, 16 Dec 2019 17:20:09 -0300 Subject: [PATCH 06/10] chore: version update --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3f30e30..2caace6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-redactor", - "version": "1.1.7", + "version": "1.1.9", "description": "Directive for redactor WYSIWYG editor", "main": "angular-redactor.js", "scripts": { From d89a3dd11acbdebb2c3ee8d64485d38e09dddd94 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Freire Gama Date: Mon, 16 Dec 2019 17:28:19 -0300 Subject: [PATCH 07/10] fix(castFunction): missing return --- angular-redactor-3.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/angular-redactor-3.js b/angular-redactor-3.js index c18190c..f20527f 100644 --- a/angular-redactor-3.js +++ b/angular-redactor-3.js @@ -22,7 +22,7 @@ require: 'ngModel', link: function(scope, element, attrs, ngModel) { var castFunction = function (fn, defaultOutput) { - Object.prototype.toString.call(fn) === '[object Function]' + return Object.prototype.toString.call(fn) === '[object Function]' ? fn : function() {} } From f0dcf7ebd75eab2b5727bc3f5b4ff4d0ba0958a9 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Freire Gama Date: Mon, 16 Dec 2019 17:29:33 -0300 Subject: [PATCH 08/10] chore: version update --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2caace6..a9f5bbc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-redactor", - "version": "1.1.9", + "version": "1.1.9.1", "description": "Directive for redactor WYSIWYG editor", "main": "angular-redactor.js", "scripts": { From 62a0dc3ba1537ca6e7e95675af360e77a12c8584 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Freire Gama Date: Mon, 16 Dec 2019 17:48:28 -0300 Subject: [PATCH 09/10] feat: add hasIn function --- angular-redactor-3.js | 29 ++++++++++++++++++++++++----- package.json | 2 +- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/angular-redactor-3.js b/angular-redactor-3.js index f20527f..be46b66 100644 --- a/angular-redactor-3.js +++ b/angular-redactor-3.js @@ -21,10 +21,27 @@ restrict: 'A', require: 'ngModel', link: function(scope, element, attrs, ngModel) { - var castFunction = function (fn, defaultOutput) { - return Object.prototype.toString.call(fn) === '[object Function]' - ? fn - : function() {} + function _get(obj, path, defaultValue, justExistence) { + if (!path) return undefined; + var tree = path.split(/(?:\[|\]|\]?\.)/i).filter(i => i !== ""); + let fullDepth = obj || {}; + while (tree.length) { + const currentDepth = tree.shift(); + if (fullDepth[currentDepth]) { + fullDepth = fullDepth[currentDepth]; + } else { + tree.splice(0); + return defaultValue; + } + } + if (justExistence) { + return typeof fullDepth !== "undefined" && fullDepth !== null; + } + return fullDepth; + } + + function _hasIn(obj, path) { + return _get(obj, path, undefined, true); } var randomId = @@ -47,7 +64,9 @@ } // $timeout to avoid $digest collision debounce = $timeout(function() { - castFunction((ngModel || {}).$setViewValue)(value); + if (_hasIn(ngModel, '$setViewValue')) { + ngModel.$setViewValue(value); + } debounce = undefined; }, 250); }; diff --git a/package.json b/package.json index a9f5bbc..ff9fec3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-redactor", - "version": "1.1.9.1", + "version": "1.1.10", "description": "Directive for redactor WYSIWYG editor", "main": "angular-redactor.js", "scripts": { From 446e473eb23359b063deb153e7c07fb9ba1f67f5 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Freire Gama Date: Mon, 16 Dec 2019 18:00:09 -0300 Subject: [PATCH 10/10] fix: omit angularjs f***** bug --- angular-redactor-3.js | 5 +++-- package.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/angular-redactor-3.js b/angular-redactor-3.js index be46b66..aae5148 100644 --- a/angular-redactor-3.js +++ b/angular-redactor-3.js @@ -60,12 +60,13 @@ var updateModel = function updateModel(value) { if (debounce) { $timeout.cancel(debounce); - debounce = undefined; } // $timeout to avoid $digest collision debounce = $timeout(function() { if (_hasIn(ngModel, '$setViewValue')) { - ngModel.$setViewValue(value); + try { + ngModel.$setViewValue(value); + } catch(e) {} } debounce = undefined; }, 250); diff --git a/package.json b/package.json index ff9fec3..ada559e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-redactor", - "version": "1.1.10", + "version": "1.1.10.1", "description": "Directive for redactor WYSIWYG editor", "main": "angular-redactor.js", "scripts": {