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

Commit 27959bd

Browse files
committed
#143 - Fix passing in setup function breaking model.
1 parent f56bced commit 27959bd

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/tinymce.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ angular.module('ui.tinymce', [])
2121
var ngModel = ctrls[0],
2222
form = ctrls[1] || null;
2323

24-
var expression, options, tinyInstance,
24+
var expression, options = {}, tinyInstance,
2525
updateView = function(editor) {
2626
var content = editor.getContent({format: options.format}).trim();
2727
content = $sce.trustAsHtml(content);
@@ -55,7 +55,7 @@ angular.module('ui.tinymce', [])
5555

5656
angular.extend(expression, scope.$eval(attrs.uiTinymce));
5757

58-
options = {
58+
var setupOptions = {
5959
// Update model when calling setContent
6060
// (such as from the source editor popup)
6161
setup: function(ed) {
@@ -74,7 +74,7 @@ angular.module('ui.tinymce', [])
7474
});
7575

7676
// Update model on change
77-
ed.on('change', function(e) {
77+
ed.on('change', function() {
7878
ed.save();
7979
updateView(ed);
8080
});
@@ -99,12 +99,12 @@ angular.module('ui.tinymce', [])
9999
});
100100
}
101101
},
102-
format: 'raw',
102+
format: expression.format || 'raw',
103103
selector: '#' + attrs.id
104104
};
105105
// extend options with initial uiTinymceConfig and
106106
// options from directive attribute value
107-
angular.extend(options, uiTinymceConfig, expression);
107+
angular.extend(options, uiTinymceConfig, expression, setupOptions);
108108
// Wrapped in $timeout due to $tinymce:refresh implementation, requires
109109
// element to be present in DOM before instantiating editor when
110110
// re-rendering directive

test/tinymce.spec.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('uiTinymce', function () {
2323
* Asynchronously runs the compilation.
2424
*/
2525
function compile() {
26-
element = $compile('<form><textarea ui-tinymce="{foo: \'bar\', setup: setupFooBar() }" ng-model="foo"></textarea></form>')(scope);
26+
element = $compile('<form><textarea ui-tinymce="{foo: \'bar\', setup: setupFooBar }" data-ng-model="foo"></textarea></form>')(scope);
2727
angular.element(document.getElementsByTagName('body')[0]).append(element);
2828
scope.$apply();
2929
$timeout.flush();
@@ -53,10 +53,15 @@ describe('uiTinymce', function () {
5353
expect(tinymce.init.calls.mostRecent().args[0].tinymce.bar).toBe('baz');
5454
});
5555

56-
it('should execute the passed `setup` option', function() {
56+
it('should execute the passed `setup` option', function(done) {
5757
scope.setupFooBar = jasmine.createSpy('setupFooBar');
5858
compile();
59-
expect(scope.setupFooBar).toHaveBeenCalled();
59+
60+
//TODO: Get rid of timeout
61+
setTimeout(function() {
62+
expect(scope.setupFooBar).toHaveBeenCalled();
63+
done();
64+
}, 100);
6065
});
6166
});
6267

0 commit comments

Comments
 (0)