forked from TylerGarlick/angular-redactor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-redactor.js
More file actions
54 lines (48 loc) · 1.5 KB
/
angular-redactor.js
File metadata and controls
54 lines (48 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(function () {
'use strict';
/**
* usage: <textarea ng-model="content" redactor></textarea>
*
* additional options:
* redactor: hash (pass in a redactor options hash)
*
*/
angular.module('angular-redactor', [])
.directive("redactor", ['$timeout', function ($timeout) {
return {
restrict: 'A',
require: "ngModel",
link: function (scope, element, attrs, ngModel) {
var updateModel = function updateModel(value) {
/* fix for html code view in redactor v9.2.1+ */
if(element.not(':visible')) {
scope.$apply(function () {
ngModel.$setViewValue(value);
});
}
},
options = {
changeCallback: updateModel
},
additionalOptions = attrs.redactor ?
scope.$eval(attrs.redactor) : {},
editor,
$_element = angular.element(element);
angular.extend(options, 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('set', ngModel.$viewValue || '');
});
}
};
}
};
}]);
})();