Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Commit b468de2

Browse files
author
Tyler Garlick
committed
1.1.0
Fixes issue TylerGarlick#21, TylerGarlick#22, TylerGarlick#11 Added suppport for Redactor 9.x and Redactor 10.x
1 parent c8d779a commit b468de2

7 files changed

+104
-10
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
bower_components
33
.DS_Store
44

5+
6+
demo/redactor
7+
demo/redactor9

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ angular-redactor
44
Angular Redactor is an angular directive for the Redactor editor. http://imperavi.com/redactor/
55

66

7+
Important Changes
8+
--------------
9+
10+
As of version 1.0.2, 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.
11+
12+
713
Usage
814
--------------
915

10-
1. Include the redactor libraries
16+
1. Include the redactor libraries from http://imperavi.com/redactor/ (The bower version of redactor is unsupported)
1117
2. In your angular application register angular-redactor as a dependency.
1218
3. Add the necessary html to view the editor.
1319

angular-redactor-9.x.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
(function () {
2+
'use strict';
3+
4+
/**
5+
* usage: <textarea ng-model="content" redactor></textarea>
6+
*
7+
* additional options:
8+
* redactor: hash (pass in a redactor options hash)
9+
*
10+
*/
11+
12+
var redactorOptions = {};
13+
14+
angular.module('angular-redactor', [])
15+
.constant('redactorOptions', redactorOptions)
16+
.directive('redactor', ['$timeout', function ($timeout) {
17+
return {
18+
restrict: 'A',
19+
require: 'ngModel',
20+
link: function (scope, element, attrs, ngModel) {
21+
22+
// Expose scope var with loaded state of Redactor
23+
scope.redactorLoaded = false;
24+
25+
var updateModel = function updateModel(value) {
26+
// $timeout to avoid $digest collision
27+
$timeout(function () {
28+
scope.$apply(function () {
29+
ngModel.$setViewValue(value);
30+
});
31+
});
32+
},
33+
options = {
34+
changeCallback: updateModel
35+
},
36+
additionalOptions = attrs.redactor ?
37+
scope.$eval(attrs.redactor) : {},
38+
editor,
39+
$_element = angular.element(element);
40+
41+
angular.extend(options, redactorOptions, additionalOptions);
42+
43+
// put in timeout to avoid $digest collision. call render() to
44+
// set the initial value.
45+
$timeout(function () {
46+
editor = $_element.redactor(options);
47+
ngModel.$render();
48+
});
49+
50+
ngModel.$render = function () {
51+
if (angular.isDefined(editor)) {
52+
$timeout(function() {
53+
$_element.redactor('set', ngModel.$viewValue || '');
54+
scope.redactorLoaded = true;
55+
});
56+
}
57+
};
58+
}
59+
};
60+
}]);
61+
})();
62+

angular-redactor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
ngModel.$render = function () {
5151
if (angular.isDefined(editor)) {
5252
$timeout(function() {
53-
$_element.redactor('set', ngModel.$viewValue || '');
53+
$_element.redactor('insert.set', ngModel.$viewValue || '');
5454
scope.redactorLoaded = true;
5555
});
5656
}

bower.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-redactor",
33
"main": "angular-redactor.js",
4-
"version": "1.0.1",
4+
"version": "1.1.0",
55
"homepage": "https://github.com/TylerGarlick/angular-redactor",
66
"authors": [
77
"Tyler Garlick <[email protected]>"
@@ -26,5 +26,8 @@
2626
"dependencies": {
2727
"jquery": ">=2.0.0",
2828
"angular": ">=1.2.0"
29+
},
30+
"devDependencies": {
31+
"angular-route": "~1.3.1"
2932
}
3033
}

demo/index-redactor-9.html

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html ng-app="app">
3+
<head>
4+
<title></title>
5+
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
6+
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
7+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"/>
8+
<link rel="stylesheet" href="redactor9/redactor.css"/>
9+
<script src="redactor9/redactor.js"></script>
10+
</head>
11+
<body>
12+
<div class="container">
13+
<div ng-view></div>
14+
</div>
15+
<script src="../bower_components/angular/angular.js"></script>
16+
<script src="../bower_components/angular-route/angular-route.js"></script>
17+
<script src="../angular-redactor-9.x.js"></script>
18+
<script src="app.js"></script>
19+
</body>
20+
</html>

demo/index.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<!DOCTYPE html>
22
<html ng-app="app">
33
<head>
4-
<title></title>
5-
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
6-
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
7-
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"/>
8-
<link rel="stylesheet" href="../bower_components/redactor/redactor.css"/>
9-
<script src="../bower_components/redactor/redactor.js"></script>
4+
<title></title>
5+
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
6+
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
7+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"/>
8+
<link rel="stylesheet" href="redactor/redactor.css"/>
9+
<script src="redactor/redactor.js"></script>
1010
</head>
1111
<body>
1212
<div class="container">
13-
<div ng-view></div>
13+
<div ng-view></div>
1414
</div>
1515
<script src="../bower_components/angular/angular.js"></script>
1616
<script src="../bower_components/angular-route/angular-route.js"></script>

0 commit comments

Comments
 (0)