From: Michael J. Rubinsky Date: Wed, 10 Mar 2010 18:00:53 +0000 (-0500) Subject: Calling reset() now automatically calls init() if the object is not initialized. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=87b562b29191c4cf84ad0913da453af1c8caba1e;p=horde.git Calling reset() now automatically calls init() if the object is not initialized. Simplifies client code, plus add some checks to avoid doing work for nothing... --- diff --git a/horde/js/prettyautocomplete.js b/horde/js/prettyautocomplete.js index 026c9aae5..d5bccc4d8 100644 --- a/horde/js/prettyautocomplete.js +++ b/horde/js/prettyautocomplete.js @@ -29,14 +29,19 @@ var PrettyAutocompleter = Class.create({ this.p.items = element; this.p.trigger = element + 'real'; this.initialized = false; + this._enabled = true; }, /** - * Initialize the autocompleter, build the dom structure, register + * Initialize the autocompleter, build the dom structure, register * events, etc... */ init: function() { + if (this.initialized) { + return; + } + // Build the DOM structure this.buildStructure(); @@ -83,6 +88,10 @@ var PrettyAutocompleter = Class.create({ */ reset: function(existing) { + if (!this.initialized) { + this.init(); + } + // TODO: Resize the trigger field to fill the current line? // Clear any existing values if (this.selectedItems.length) { @@ -98,7 +107,7 @@ var PrettyAutocompleter = Class.create({ this.addNewItemNode(existing[i]); } } - + this._enabled = true; }, buildStructure: function() @@ -211,6 +220,10 @@ var PrettyAutocompleter = Class.create({ disable: function() { + if (!this._enabled || !this.initialized) { + return; + } + this._enabled = false; $(this.p.box).select('.hordeACItemRemove').each(function(e) {e.toggle()}); $(this.p.trigger).disable(); @@ -218,6 +231,9 @@ var PrettyAutocompleter = Class.create({ enable: function() { + if (this._enabled) { + return; + } this._enabled = true; $(this.p.box).select('.hordeACItemRemove').each(function(e) {e.toggle()}); $(this.p.trigger).enable();