From ea08a7fe53c916a5485078129048509c175928a5 Mon Sep 17 00:00:00 2001 From: Oleg Sulyanov Date: Tue, 16 Feb 2016 19:29:10 +0700 Subject: [PATCH] Added Redactor II support --- README.md | 6 +++++ angular-redactor-2.js | 62 +++++++++++++++++++++++++++++++++++++++++++ bower.json | 2 +- demo/app.js | 2 +- demo/index.html | 7 ++--- demo/views/main.html | 4 +-- 6 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 angular-redactor-2.js diff --git a/README.md b/README.md index 423e749..871a52f 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Angular Redactor is an angular directive for the Redactor editor. http://impera Important Changes -------------- +There is an additional file (angular-redactor-2) for Redactor II. As of version 1.1.0, there is an additional file (angular-redactor-9.x) has been added to accommodate the the 9.x version of redactor, the angular-redactor.js will support the latest version of redactor. @@ -37,6 +38,11 @@ With Options ``` +With Plugins +```html + +``` + You can pass options directly to Redactor by specifying them as the value of the `redactor` attribute. Global Options diff --git a/angular-redactor-2.js b/angular-redactor-2.js new file mode 100644 index 0000000..5db78cb --- /dev/null +++ b/angular-redactor-2.js @@ -0,0 +1,62 @@ +(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 = element.redactor(options); + ngModel.$render(); + }); + + ngModel.$render = function() { + if(angular.isDefined(editor)) { + $timeout(function() { + element.redactor('code.set', ngModel.$viewValue || ''); + scope.redactorLoaded = true; + }); + } + }; + } + }; + }]); +})(); \ No newline at end of file diff --git a/bower.json b/bower.json index 4c2a699..36ca378 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "angular-redactor", "main": "angular-redactor.js", - "version": "1.1.4", + "version": "1.1.5", "homepage": "https://github.com/TylerGarlick/angular-redactor", "authors": [ "Tyler Garlick " diff --git a/demo/app.js b/demo/app.js index 7194100..485de1a 100644 --- a/demo/app.js +++ b/demo/app.js @@ -17,5 +17,5 @@ angular.module('app') $scope.changeContent = function () { $scope.content = "

Some bogus content

" } - $scope.content = "

This is my fawesome content

"; + $scope.content = "

This is my awesome content

"; }]); \ No newline at end of file diff --git a/demo/index.html b/demo/index.html index de2af31..79ada0d 100644 --- a/demo/index.html +++ b/demo/index.html @@ -5,16 +5,17 @@ + + +
- - - + \ No newline at end of file diff --git a/demo/views/main.html b/demo/views/main.html index 147210a..97b79de 100644 --- a/demo/views/main.html +++ b/demo/views/main.html @@ -23,11 +23,11 @@

Demo

Air Option
- +
Markup
-      <textarea ng-model="content" redactor="{air: true}" cols="30" rows="10"></textarea>
+      <textarea ng-model="content" redactor="{air: true, plugins: ['source']}" cols="30" rows="10"></textarea>