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

Commit 015d8b1

Browse files
committed
Change format to closer match TinyMCE config
1 parent 1999e41 commit 015d8b1

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/tinymce.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ angular.module('ui.tinymce', [])
1919

2020
var expression, options, tinyInstance,
2121
updateView = function(editor) {
22-
if (options.raw === true) {
23-
ngModel.$setViewValue(editor.getContent({format: 'text'}).trim());
24-
} else {
25-
ngModel.$setViewValue(editor.getContent().trim());
26-
}
22+
ngModel.$setViewValue(editor.getContent({format: options.format}).trim());
2723
if (!$rootScope.$$phase) {
2824
scope.$apply();
2925
}
@@ -83,12 +79,15 @@ angular.module('ui.tinymce', [])
8379
updateView: updateView
8480
});
8581
}
86-
}
82+
},
83+
format: 'raw',
84+
selector: '#' + attrs.id
8785
};
8886
// extend options with initial uiTinymceConfig and options from directive attribute value
8987
angular.extend(options, uiTinymceConfig, expression);
90-
tinymce.init(options);
91-
tinymce.execCommand('mceAddEditor', false, attrs.id);
88+
$timeout(function() {
89+
tinymce.init(options);
90+
});
9291

9392
ngModel.$formatters.unshift(function(modelValue) {
9493
return modelValue || '';
@@ -97,11 +96,12 @@ angular.module('ui.tinymce', [])
9796
ngModel.$render = function() {
9897
ensureInstance();
9998

100-
var format = options.raw ? 'text' : 'raw';
101-
102-
// tinymce replaces "\r\n" to "\n", so we have to do the same on model value
99+
// tinymce replaces '\r\n' to '\n', so we have to do the same on model value
100+
// instance.getDoc() check is a guard against null value when destruction &
101+
// recreation of instances happen
103102
if (tinyInstance &&
104-
tinyInstance.getContent({format: format}).trim() !== ngModel.$viewValue.replace(/\r\n/g, '\n')
103+
tinyInstance.getDoc() &&
104+
tinyInstance.getContent({format: options.format}).trim() !== ngModel.$viewValue.replace(/\r\n/g, '\n')
105105
) {
106106
tinyInstance.setContent(ngModel.$viewValue);
107107
}
@@ -123,16 +123,19 @@ angular.module('ui.tinymce', [])
123123
}
124124
});
125125

126+
// This block is because of TinyMCE not playing well with removal and
127+
// recreation of instances, requiring instances to have different
128+
// selectors in order to render new instances properly
126129
scope.$on('$tinymce:refresh', function(e, id) {
127130
var eid = attrs.id;
128131
if (angular.isUndefined(id) || id === eid) {
129132
var parentElement = element.parent();
130133
var clonedElement = element.clone();
131134
clonedElement.removeAttr('id');
135+
clonedElement.removeAttr('style');
136+
clonedElement.removeAttr('aria-hidden');
132137
tinymce.execCommand('mceRemoveEditor', false, eid);
133-
$timeout(function() {
134-
parentElement.append($compile(clonedElement)(scope));
135-
}, 3000);
138+
parentElement.append($compile(clonedElement)(scope));
136139
}
137140
});
138141

0 commit comments

Comments
 (0)