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

added focus callback to the options (same behaviour as blur) #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions src/ui-ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ angular.module('ui.ace', [])
*/
var onBlurListener;

/**
* Reference to a focus listener created by the listener factory.
* @function
* @see listenerFactory.onFocus
*/
var onFocusListener;

/**
* Calls a callback by checking its existing. The argument list
* is variable and thus this function is relying on the arguments
Expand Down Expand Up @@ -250,6 +257,20 @@ angular.module('ui.ace', [])
return function () {
executeUserCallback(callback, acee);
};
},
/**
* Creates a focus listener which propagates the editor session
* to the callback from the user option onFocus. It might be
* exchanged during runtime, if this happens the old listener
* will be unbound.
*
* @param callback callback function defined in the user options
* @see onFocusListener
*/
onFocus: function (callback) {
return function () {
executeUserCallback(callback, acee);
};
}
};

Expand Down Expand Up @@ -302,6 +323,13 @@ angular.module('ui.ace', [])
onBlurListener = listenerFactory.onBlur(opts.onBlur);
acee.on('blur', onBlurListener);

// unbind old foucs listener
acee.removeListener('focus', onFocusListener);

// bind new focus listener
onFocusListener = listenerFactory.onFocus(opts.onFocus);
acee.on('focus', onFocusListener);

setOptions(acee, session, opts);
};

Expand Down