From b28bed9bb5ee9271243448c365ed5654e271f454 Mon Sep 17 00:00:00 2001 From: "Amir E. Aharoni" Date: Tue, 23 Apr 2013 22:43:14 +0300 Subject: [PATCH 1/3] Add an afterShowing hook A hook that can optionally run after the ULS menu is shown. There are things that cannot be done in ready(), because the style may not have been initialized yet. --- src/jquery.uls.core.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/jquery.uls.core.js b/src/jquery.uls.core.js index 6352239..bd175c1 100644 --- a/src/jquery.uls.core.js +++ b/src/jquery.uls.core.js @@ -120,6 +120,12 @@ } }, + afterShowing: function () { + if ( this.options.afterShowing ) { + this.options.afterShowing.call( this ); + } + }, + /** * Calculate the position of ULS * Returns an object with top and left properties. @@ -152,9 +158,11 @@ if ( !this.initialized ) { $( 'body' ).prepend( this.$menu ); this.i18n(); + // Initialize with a full search. // This happens on first time click of uls trigger. this.defaultSearch(); + this.initialized = true; } @@ -164,6 +172,8 @@ this.$menu.show(); this.shown = true; + this.afterShowing(); + if ( !this.isMobile() ) { this.$languageFilter.focus(); } From a568b3244e07f7e72d24426136fb65b8446931db Mon Sep 17 00:00:00 2001 From: "Amir E. Aharoni" Date: Thu, 25 Apr 2013 13:29:25 +0300 Subject: [PATCH 2/3] Rename the hook to "visible" and add documentation --- src/jquery.uls.core.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/jquery.uls.core.js b/src/jquery.uls.core.js index bd175c1..5546155 100644 --- a/src/jquery.uls.core.js +++ b/src/jquery.uls.core.js @@ -114,15 +114,26 @@ ULS.prototype = { constructor: ULS, + // A "hook" that runs after the ULS constructor. + // At this point it is not guaranteed that the ULS has its dimensions + // and that the languages lists are initialized. + // + // To use it, pass a function as the onReady parameter + // in the options when initializing ULS. ready: function () { if ( this.options.onReady ) { this.options.onReady.call( this ); } }, - afterShowing: function () { - if ( this.options.afterShowing ) { - this.options.afterShowing.call( this ); + // A "hook" that runs after the ULS panel becomes visible + // by using the show method. + // + // To use it, pass a function as the onVisible parameter + // in the options when initializing ULS. + visible: function () { + if ( this.options.onVisible ) { + this.options.onVisible.call( this ); } }, @@ -166,17 +177,17 @@ this.initialized = true; } - // hide any other ULS visible + // hide any other visible ULS $( '.uls-menu' ).hide(); this.$menu.show(); this.shown = true; - this.afterShowing(); - if ( !this.isMobile() ) { this.$languageFilter.focus(); } + + this.visible(); }, i18n: function () { From 6309d1889bf03a6898be1a901e5f71f4d577f2a0 Mon Sep 17 00:00:00 2001 From: "Amir E. Aharoni" Date: Thu, 25 Apr 2013 14:48:37 +0300 Subject: [PATCH 3/3] Comments format --- src/jquery.uls.core.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/jquery.uls.core.js b/src/jquery.uls.core.js index 5546155..7490682 100644 --- a/src/jquery.uls.core.js +++ b/src/jquery.uls.core.js @@ -114,23 +114,27 @@ ULS.prototype = { constructor: ULS, - // A "hook" that runs after the ULS constructor. - // At this point it is not guaranteed that the ULS has its dimensions - // and that the languages lists are initialized. - // - // To use it, pass a function as the onReady parameter - // in the options when initializing ULS. + /** + * A "hook" that runs after the ULS constructor. + * At this point it is not guaranteed that the ULS has its dimensions + * and that the languages lists are initialized. + * + * To use it, pass a function as the onReady parameter + * in the options when initializing ULS. + */ ready: function () { if ( this.options.onReady ) { this.options.onReady.call( this ); } }, - // A "hook" that runs after the ULS panel becomes visible - // by using the show method. - // - // To use it, pass a function as the onVisible parameter - // in the options when initializing ULS. + /** + * A "hook" that runs after the ULS panel becomes visible + * by using the show method. + * + * To use it, pass a function as the onVisible parameter + * in the options when initializing ULS. + */ visible: function () { if ( this.options.onVisible ) { this.options.onVisible.call( this );