Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/ui-ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ angular.module('ui.ace', [])
]);
}

// onLoad callback
if (angular.isFunction(opts.onLoad)) {
opts.onLoad(acee);
}
// onLoad callbacks
angular.forEach(opts.callbacks, function (cb) {
if (angular.isFunction(cb)) {
cb(acee);
}
});

// Basic options
if (angular.isString(opts.theme)) {
Expand Down Expand Up @@ -268,15 +270,19 @@ angular.module('ui.ace', [])
};
}

// set the options here, even if we try to watch later, if this
// line is missing things go wrong (and the tests will also fail)
setOptions(acee, session, opts);

// Listen for option updates
scope.$watch( attrs.uiAce, function(current, previous) {
var updateOptions = function (current, previous) {
if (current === previous) return;
opts = angular.extend({}, options, scope.$eval(attrs.uiAce));

opts.callbacks = [ opts.onLoad ];
if (opts.onLoad !== options.onLoad) {
// also call the global onLoad handler
opts.callbacks.unshift(options.onLoad);
}

// EVENTS

// unbind old change listener
session.removeListener('change', onChangeListener);

Expand All @@ -293,14 +299,13 @@ angular.module('ui.ace', [])
acee.on('blur', onBlurListener);

setOptions(acee, session, opts);
}, /* deep watch */ true );
};

// EVENTS
onChangeListener = listenerFactory.onChange(opts.onChange);
session.on('change', onChangeListener);
scope.$watch(attrs.uiAce, updateOptions, /* deep watch */ true);

onBlurListener = listenerFactory.onBlur(opts.onBlur);
acee.on('blur', onBlurListener);
// set the options here, even if we try to watch later, if this
// line is missing things go wrong (and the tests will also fail)
updateOptions(options);

elm.on('$destroy', function () {
acee.session.$stopWorker();
Expand Down