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

Commit

Permalink
enhancement: allows disabling of debouncing
Browse files Browse the repository at this point in the history
Debouncing can be disabled by passing a false value to the debounce option. Defaults to true. Also protects a digest call.
Closes #256
Closes #257
Closes #248
  • Loading branch information
douglasg14b authored and deeg committed May 17, 2016
1 parent 0f1c5a8 commit 4f6b0f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ In addition, it supports these additional optional options
- `format` Format to get content as, i.e. 'raw' for raw HTML, or 'text' for text only. Defaults to 'html'. Documentation [here](http://www.tinymce.com/wiki.php/api4:method.tinymce.Editor.getContent)
- `trusted` When `true`, all TinyMCE content that is set to `ngModel` will be whitelisted by `$sce`
- `baseURL` This will set [baseURL property on the EditorManager](https://www.tinymce.com/docs/api/class/tinymce.editormanager/)
- `debounce` This will debounce the model update which helps with performance of editors with large text. Defaults to true.

This option is only supported when present on the `uiTinymceConfig` global injectable - this injectable needs to be an object.

Expand Down
2 changes: 1 addition & 1 deletion dist/tinymce.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions src/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ angular.module('ui.tinymce', [])
var ngModel = ctrls[0],
form = ctrls[1] || null;

var expression, options = {}, tinyInstance,
var expression, options = {
debounce: true
}, tinyInstance,
updateView = function(editor) {
var content = editor.getContent({format: options.format}).trim();
content = $sce.trustAsHtml(content);
Expand Down Expand Up @@ -79,7 +81,7 @@ angular.module('ui.tinymce', [])
ed.on('init', function() {
ngModel.$render();
ngModel.$setPristine();
ngModel.$setUntouched();
ngModel.$setUntouched();
if (form) {
form.$setPristine();
}
Expand All @@ -91,13 +93,20 @@ angular.module('ui.tinymce', [])
// - the node has changed [NodeChange]
// - an object has been resized (table, image) [ObjectResized]
ed.on('ExecCommand change NodeChange ObjectResized', function() {
if (!options.debounce) {
ed.save();
updateView(ed);
return;
}
debouncedUpdate(ed);
});

ed.on('blur', function() {
element[0].blur();
ngModel.$setTouched();
scope.$digest();
if (!$rootScope.$$phase) {
scope.$digest();
}
});

ed.on('remove', function() {
Expand Down

0 comments on commit 4f6b0f6

Please sign in to comment.