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

Commit bdf9cf2

Browse files
committed
DRY up instance check
1 parent 7554a1d commit bdf9cf2

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/tinymce.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ angular.module('ui.tinymce', [])
8787
});
8888

8989
ngModel.$render = function() {
90-
if (!tinyInstance) {
91-
tinyInstance = tinymce.get(attrs.id);
92-
}
90+
ensureInstance();
9391

9492
var format = options.raw ? 'text' : 'raw';
9593

@@ -103,17 +101,13 @@ angular.module('ui.tinymce', [])
103101

104102
attrs.$observe('disabled', function(disabled) {
105103
if (disabled) {
106-
if (!tinyInstance) {
107-
tinyInstance = tinymce.get(attrs.id);
108-
}
104+
ensureInstance();
109105

110106
if (tinyInstance) {
111107
tinyInstance.getBody().setAttribute('contenteditable', false);
112108
}
113109
} else {
114-
if (!tinyInstance) {
115-
tinyInstance = tinymce.get(attrs.id);
116-
}
110+
ensureInstance();
117111

118112
if (tinyInstance) {
119113
tinyInstance.getBody().setAttribute('contenteditable', true);
@@ -122,12 +116,19 @@ angular.module('ui.tinymce', [])
122116
});
123117

124118
scope.$on('$destroy', function() {
125-
if (!tinyInstance) { tinyInstance = tinymce.get(attrs.id); }
119+
ensureInstance();
120+
126121
if (tinyInstance) {
127122
tinyInstance.remove();
128123
tinyInstance = null;
129124
}
130125
});
126+
127+
function ensureInstance() {
128+
if (!tinyInstance) {
129+
tinyInstance = tinymce.get(attrs.id);
130+
}
131+
}
131132
}
132133
};
133134
}]);

0 commit comments

Comments
 (0)