cronapp-lib-js 2.8.0 → 2.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -129,7 +129,7 @@ angular.module('ui.tinymce', [])
129
129
  scope.$eval(ngAttrs.ngRemove);
130
130
  }
131
131
  });
132
-
132
+
133
133
  let getContentTimeout = undefined;
134
134
  if (ngAttrs.ngNodeChange) { ed.on('NodeChange', function () { scope.$eval(ngAttrs.ngNodeChange); }); }
135
135
  if (ngAttrs.ngCronChange) { ed.on('change', function () { scope.$eval(ngAttrs.ngCronChange); }); }
@@ -214,22 +214,38 @@ angular.module('ui.tinymce', [])
214
214
  return viewValue ? $sce.getTrustedHtml(viewValue) : '';
215
215
  });
216
216
 
217
- ngModel.$render = function() {
218
- ensureInstance();
217
+ let isTinyMCEVisible = () => {
218
+ return (tinyInstance && angular.element(tinyInstance.contentAreaContainer).is(':visible'));
219
+ }
219
220
 
220
- var viewValue = ngModel.$viewValue ?
221
- $sce.getTrustedHtml(ngModel.$viewValue) : '';
222
-
223
- // instance.getDoc() check is a guard against null value
224
- // when destruction & recreation of instances happen
225
- if (tinyInstance &&
226
- tinyInstance.getDoc()
227
- ) {
228
- tinyInstance.setContent(viewValue);
229
- // Triggering change event due to TinyMCE not firing event &
230
- // becoming out of sync for change callbacks
231
- tinyInstance.fire('change');
221
+ let whenVisible = async () => {
222
+ let promise = new Promise(resolve => {
223
+ let wait = () => (isTinyMCEVisible() && resolve()) || ($timeout(() => wait()));
224
+ wait();
225
+ });
226
+ return promise;
227
+ };
228
+
229
+ let forceContentAndWatch = (instance, value) => {
230
+ if (instance && instance.getDoc()) {
231
+ instance.setContent(value);
232
+ instance.fire('change');
233
+ instance.fire('blur');
232
234
  }
235
+
236
+ if (instance && !instance.watch) {
237
+ scope.$watch(() => isTinyMCEVisible(), () => ngModel.$render());
238
+ instance.watch = true;
239
+ }
240
+ };
241
+
242
+ let getViewValue = (model) => {
243
+ return model.$viewValue ? $sce.getTrustedHtml(model.$viewValue) : '';
244
+ }
245
+
246
+ ngModel.$render = function() {
247
+ ensureInstance();
248
+ whenVisible().then(() => forceContentAndWatch(tinyInstance, getViewValue(ngModel)))
233
249
  };
234
250
 
235
251
  attrs.$observe('disabled', toggleDisable);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cronapp-lib-js",
3
- "version": "2.8.0",
3
+ "version": "2.8.4",
4
4
  "description": "Javascript library for CronApp's projects",
5
5
  "main": "index.js",
6
6
  "scripts": {