|
1 | 1 | /**
|
2 | 2 | * Binds a TinyMCE widget to <textarea> elements.
|
3 | 3 | */
|
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(); |
35 | 17 | ngModel.$setViewValue(elm.val());
|
36 | 18 | if (!scope.$$phase)
|
37 | 19 | scope.$apply();
|
38 | 20 | }
|
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 | + }); |
46 | 53 | }
|
47 |
| - angular.extend(options, uiTinymceConfig, expression); |
48 |
| - setTimeout(function () { |
49 |
| - elm.tinymce(options); |
50 |
| - }); |
51 |
| - } |
52 |
| - }; |
53 |
| -}]); |
| 54 | + }; |
| 55 | + }]); |
0 commit comments