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

Commit

Permalink
feat(config): always call the global onLoad handler
Browse files Browse the repository at this point in the history
  • Loading branch information
marshall007 authored and douglasduteil committed Jan 8, 2015
1 parent de4d1c6 commit c83086a
Showing 1 changed file with 20 additions and 15 deletions.
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 @@ -272,15 +274,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 @@ -297,14 +303,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

0 comments on commit c83086a

Please sign in to comment.