Skip to content

Commit cc193ee

Browse files
author
Tyler Garlick
committed
Merge pull request #63 from osulyanov/master
Added Redactor II support
2 parents 708eaaf + ea08a7f commit cc193ee

File tree

6 files changed

+76
-7
lines changed

6 files changed

+76
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Angular Redactor is an angular directive for the Redactor editor. http://impera
88
Important Changes
99
--------------
1010

11+
There is an additional file (angular-redactor-2) for Redactor II.
1112
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.
1213

1314

@@ -37,6 +38,11 @@ With Options
3738
<textarea ng-model="content" redactor="{buttons: ['formatting', '|', 'bold', 'italic']}" cols="30" rows="10"></textarea>
3839
```
3940

41+
With Plugins
42+
```html
43+
<textarea ng-model="content" redactor="{plugins: ['source']}" cols="30" rows="10"></textarea>
44+
```
45+
4046
You can pass options directly to Redactor by specifying them as the value of the `redactor` attribute.
4147

4248
Global Options

angular-redactor-2.js

Lines changed: 62 additions & 0 deletions
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+
callbacks: {
35+
change: updateModel
36+
}
37+
},
38+
additionalOptions = attrs.redactor ?
39+
scope.$eval(attrs.redactor) : {},
40+
editor;
41+
42+
angular.extend(options, redactorOptions, additionalOptions);
43+
44+
// put in timeout to avoid $digest collision. call render()
45+
// to set the initial value.
46+
$timeout(function() {
47+
editor = element.redactor(options);
48+
ngModel.$render();
49+
});
50+
51+
ngModel.$render = function() {
52+
if(angular.isDefined(editor)) {
53+
$timeout(function() {
54+
element.redactor('code.set', ngModel.$viewValue || '');
55+
scope.redactorLoaded = true;
56+
});
57+
}
58+
};
59+
}
60+
};
61+
}]);
62+
})();

bower.json

Lines changed: 1 addition & 1 deletion
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.1.4",
4+
"version": "1.1.5",
55
"homepage": "https://github.com/TylerGarlick/angular-redactor",
66
"authors": [
77
"Tyler Garlick <[email protected]>"

demo/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ angular.module('app')
1717
$scope.changeContent = function () {
1818
$scope.content = "<h1>Some bogus content</h1>"
1919
}
20-
$scope.content = "<p>This is my fawesome content</p>";
20+
$scope.content = "<p>This is my awesome content</p>";
2121
}]);

demo/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
66
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
77
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"/>
8+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
9+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular-route.js"></script>
810
<link rel="stylesheet" href="redactor/redactor.css"/>
911
<script src="redactor/redactor.js"></script>
12+
<script src="redactor/source.js"></script>
1013
</head>
1114
<body>
1215
<div class="container">
1316
<div ng-view></div>
1417
</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.js"></script>
18+
<script src="../angular-redactor-2.js"></script>
1819
<script src="app.js"></script>
1920
</body>
2021
</html>

demo/views/main.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ <h1>Demo</h1>
2323
<div class="panel-heading">Air Option</div>
2424
<div class="panel-body">
2525
<div class="form-group">
26-
<textarea ng-model="content" redactor="{air: true}" cols="30" rows="10"></textarea>
26+
<textarea ng-model="content" redactor="{air: true, plugins: ['source']}" cols="30" rows="10"></textarea>
2727
</div>
2828
<strong>Markup</strong>
2929
<pre>
30-
&lt;textarea ng-model="content" redactor="{air: true}" cols="30" rows="10"&gt;&lt;/textarea&gt;
30+
&lt;textarea ng-model="content" redactor="{air: true, plugins: ['source']}" cols="30" rows="10"&gt;&lt;/textarea&gt;
3131
</pre>
3232
</div>
3333
</div>

0 commit comments

Comments
 (0)