From e0a41a6a9eb4ec09cd4dd8df2f44a64f9c4de8c7 Mon Sep 17 00:00:00 2001 From: Denis Zajchenko Date: Thu, 28 May 2015 12:49:52 +0300 Subject: [PATCH] to way binding for redactor options. You can change redactor options on the fly. --- angular-redactor-9.x.js | 14 ++++++++++++-- angular-redactor.js | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/angular-redactor-9.x.js b/angular-redactor-9.x.js index f73ffbc..7a27a93 100644 --- a/angular-redactor-9.x.js +++ b/angular-redactor-9.x.js @@ -17,6 +17,9 @@ return { restrict: 'A', require: 'ngModel', + scope: { + redactor: '=' + }, link: function(scope, element, attrs, ngModel) { // Expose scope var with loaded state of Redactor @@ -33,8 +36,7 @@ options = { changeCallback: updateModel }, - additionalOptions = attrs.redactor ? - scope.$eval(attrs.redactor) : {}, + additionalOptions = scope.redactor ? scope.redactor : {}, editor, $_element = angular.element(element); @@ -63,6 +65,14 @@ }); } }; + scope.$watch(function(){return scope.redactor}, function(newValue, oldValue){ + angular.extend(options, newValue); + $timeout(function() { + editor.redactor('core.destroy'); + editor = $_element.redactor(options); + ngModel.$render(); + }); + }); } }; }]); diff --git a/angular-redactor.js b/angular-redactor.js index e69b359..2666559 100644 --- a/angular-redactor.js +++ b/angular-redactor.js @@ -17,6 +17,9 @@ return { restrict: 'A', require: 'ngModel', + scope: { + redactor: '=' + }, link: function(scope, element, attrs, ngModel) { // Expose scope var with loaded state of Redactor @@ -33,8 +36,7 @@ options = { changeCallback: updateModel }, - additionalOptions = attrs.redactor ? - scope.$eval(attrs.redactor) : {}, + additionalOptions = scope.redactor ? scope.redactor : {}, editor, $_element = angular.element(element); @@ -65,6 +67,14 @@ }); } }; + scope.$watch(function(){return scope.redactor}, function(newValue, oldValue){ + angular.extend(options, newValue); + $timeout(function() { + editor.redactor('core.destroy'); + editor = $_element.redactor(options); + ngModel.$render(); + }); + }); } }; }]);