Skip to content

Commit d355ff8

Browse files
author
Tyler Garlick
committed
small fixes from pull requests
1 parent b468de2 commit d355ff8

File tree

3 files changed

+137
-121
lines changed

3 files changed

+137
-121
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Angular Redactor is an angular directive for the Redactor editor. http://impera
77
Important Changes
88
--------------
99

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.
10+
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.
1111

1212

1313
Usage

angular-redactor-9.x.js

Lines changed: 68 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,70 @@
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-
}]);
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+
// prevent collision with the constant values on ChangeCallback
44+
if(!angular.isUndefined(redactorOptions.changeCallback)) {
45+
options.changeCallback = function() {
46+
updateModel.call(this);
47+
redactorOptions.changeCallback.call(this);
48+
}
49+
}
50+
51+
// put in timeout to avoid $digest collision. call render() to
52+
// set the initial value.
53+
$timeout(function() {
54+
editor = $_element.redactor(options);
55+
ngModel.$render();
56+
});
57+
58+
ngModel.$render = function() {
59+
if(angular.isDefined(editor)) {
60+
$timeout(function() {
61+
$_element.redactor('set', ngModel.$viewValue || '');
62+
scope.redactorLoaded = true;
63+
});
64+
}
65+
};
66+
}
67+
};
68+
}]);
6169
})();
6270

angular-redactor.js

Lines changed: 68 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,70 @@
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('insert.set', ngModel.$viewValue || '');
54-
scope.redactorLoaded = true;
55-
});
56-
}
57-
};
58-
}
59-
};
60-
}]);
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+
// prevent collision with the constant values on ChangeCallback
44+
if(!angular.isUndefined(redactorOptions.changeCallback)) {
45+
options.changeCallback = function() {
46+
updateModel.call(this);
47+
redactorOptions.changeCallback.call(this);
48+
}
49+
}
50+
51+
// put in timeout to avoid $digest collision. call render() to
52+
// set the initial value.
53+
$timeout(function() {
54+
editor = $_element.redactor(options);
55+
ngModel.$render();
56+
});
57+
58+
ngModel.$render = function() {
59+
if(angular.isDefined(editor)) {
60+
$timeout(function() {
61+
$_element.redactor('insert.set', ngModel.$viewValue || '');
62+
scope.redactorLoaded = true;
63+
});
64+
}
65+
};
66+
}
67+
};
68+
}]);
6169
})();
6270

0 commit comments

Comments
 (0)