Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 3016164

Browse files
committed
Added uiTinymceConfig value to directive - originally config came from 'ui.config' module
1 parent 03db243 commit 3016164

File tree

1 file changed

+47
-45
lines changed

1 file changed

+47
-45
lines changed

src/tinymce.js

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,55 @@
11
/**
22
* Binds a TinyMCE widget to <textarea> elements.
33
*/
4-
angular.module('ui.tinymce', []).directive('uiTinymce', ['uiTinymceConfig', function (uiTinymceConfig) {
5-
uiTinymceConfig = uiTinymceConfig || {};
6-
return {
7-
require: 'ngModel',
8-
link: function (scope, elm, attrs, ngModel) {
9-
var expression,
10-
options = {
11-
// Update model on button click
12-
onchange_callback: function (inst) {
13-
if (inst.isDirty()) {
14-
inst.save();
15-
ngModel.$setViewValue(elm.val());
16-
if (!scope.$$phase)
17-
scope.$apply();
18-
}
19-
},
20-
// Update model on keypress
21-
handle_event_callback: function (e) {
22-
if (this.isDirty()) {
23-
this.save();
24-
ngModel.$setViewValue(elm.val());
25-
if (!scope.$$phase)
26-
scope.$apply();
27-
}
28-
return true; // Continue handling
29-
},
30-
// Update model when calling setContent (such as from the source editor popup)
31-
setup: function (ed) {
32-
ed.onSetContent.add(function (ed, o) {
33-
if (ed.isDirty()) {
34-
ed.save();
4+
angular.module('ui.tinymce', [])
5+
.value('uiTinymceConfig', {})
6+
.directive('uiTinymce', ['uiTinymceConfig', function (uiTinymceConfig) {
7+
uiTinymceConfig = uiTinymceConfig || {};
8+
return {
9+
require: 'ngModel',
10+
link: function (scope, elm, attrs, ngModel) {
11+
var expression,
12+
options = {
13+
// Update model on button click
14+
onchange_callback: function (inst) {
15+
if (inst.isDirty()) {
16+
inst.save();
3517
ngModel.$setViewValue(elm.val());
3618
if (!scope.$$phase)
3719
scope.$apply();
3820
}
39-
});
40-
}
41-
};
42-
if (attrs.uiTinymce) {
43-
expression = scope.$eval(attrs.uiTinymce);
44-
} else {
45-
expression = {};
21+
},
22+
// Update model on keypress
23+
handle_event_callback: function (e) {
24+
if (this.isDirty()) {
25+
this.save();
26+
ngModel.$setViewValue(elm.val());
27+
if (!scope.$$phase)
28+
scope.$apply();
29+
}
30+
return true; // Continue handling
31+
},
32+
// Update model when calling setContent (such as from the source editor popup)
33+
setup: function (ed) {
34+
ed.onSetContent.add(function (ed, o) {
35+
if (ed.isDirty()) {
36+
ed.save();
37+
ngModel.$setViewValue(elm.val());
38+
if (!scope.$$phase)
39+
scope.$apply();
40+
}
41+
});
42+
}
43+
};
44+
if (attrs.uiTinymce) {
45+
expression = scope.$eval(attrs.uiTinymce);
46+
} else {
47+
expression = {};
48+
}
49+
angular.extend(options, uiTinymceConfig, expression);
50+
setTimeout(function () {
51+
elm.tinymce(options);
52+
});
4653
}
47-
angular.extend(options, uiTinymceConfig, expression);
48-
setTimeout(function () {
49-
elm.tinymce(options);
50-
});
51-
}
52-
};
53-
}]);
54+
};
55+
}]);

0 commit comments

Comments
 (0)