From 28f7a8179724c134e51752f20686bfd47e2d9cbd Mon Sep 17 00:00:00 2001 From: jcnunez Date: Mon, 23 Mar 2015 11:02:38 +0100 Subject: [PATCH] added focus callback to the options (same behaviour as blur) --- src/ui-ace.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/ui-ace.js b/src/ui-ace.js index a664fb1..1ea7404 100644 --- a/src/ui-ace.js +++ b/src/ui-ace.js @@ -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 @@ -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); + }; } }; @@ -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); };