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

Commit cff9ae2

Browse files
committed
Added ability of directive to update model on more general content changes
1 parent a2c9d44 commit cff9ae2

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/tinymce.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ angular.module('ui.tinymce', [])
99
return {
1010
require: 'ngModel',
1111
link: function (scope, elm, attrs, ngModel) {
12-
var expression, options, tinyInstance;
12+
var expression, options, tinyInstance,
13+
updateView = function () {
14+
ngModel.$setViewValue(elm.val());
15+
if (!scope.$$phase) {
16+
scope.$apply();
17+
}
18+
};
1319
// generate an ID if not present
1420
if (!attrs.id) {
1521
attrs.$set('id', 'uiTinymce' + generatedIds++);
1622
}
17-
23+
1824
if (attrs.uiTinymce) {
1925
expression = scope.$eval(attrs.uiTinymce);
2026
} else {
@@ -30,18 +36,17 @@ angular.module('ui.tinymce', [])
3036
// Update model on button click
3137
ed.on('ExecCommand', function (e) {
3238
ed.save();
33-
ngModel.$setViewValue(elm.val());
34-
if (!scope.$$phase) {
35-
scope.$apply();
36-
}
39+
updateView();
3740
});
3841
// Update model on keypress
3942
ed.on('KeyUp', function (e) {
4043
ed.save();
41-
ngModel.$setViewValue(elm.val());
42-
if (!scope.$$phase) {
43-
scope.$apply();
44-
}
44+
updateView();
45+
});
46+
// Update model on change, i.e. copy/pasted text, plugins altering content
47+
ed.on('SetContent', function (e) {
48+
ed.save();
49+
updateView();
4550
});
4651
if (expression.setup) {
4752
scope.$eval(expression.setup);

0 commit comments

Comments
 (0)