Skip to content

Commit d9b0033

Browse files
author
Steffen Dietz
committed
added dist files, used uglifyjs for minification
1 parent e10f08a commit d9b0033

File tree

2 files changed

+80
-45
lines changed

2 files changed

+80
-45
lines changed

dist/jquery.autocomplete.js

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
*/
99

1010
/*jslint browser: true, white: true, plusplus: true */
11-
/*global define, window, document, jQuery */
11+
/*global define, window, document, jQuery, exports */
1212

1313
// Expose plugin as an AMD module if AMD loader is present:
1414
(function (factory) {
1515
'use strict';
1616
if (typeof define === 'function' && define.amd) {
1717
// AMD. Register as an anonymous module.
1818
define(['jquery'], factory);
19+
} else if (typeof exports === 'object' && typeof require === 'function') {
20+
// Browserify
21+
factory(require('jquery'));
1922
} else {
2023
// Browser globals
2124
factory(jQuery);
@@ -138,8 +141,7 @@
138141
suggestionSelector = '.' + that.classes.suggestion,
139142
selected = that.classes.selected,
140143
options = that.options,
141-
container,
142-
noSuggestionsContainer;
144+
container;
143145

144146
// Remove autocomplete attribute to prevent native suggestions:
145147
that.element.setAttribute('autocomplete', 'off');
@@ -276,34 +278,37 @@
276278
if (orientation == 'auto') {
277279
var viewPortHeight = $(window).height(),
278280
scrollTop = $(window).scrollTop(),
279-
top_overflow = -scrollTop + offset.top - containerHeight,
280-
bottom_overflow = scrollTop + viewPortHeight - (offset.top + height + containerHeight);
281+
topOverflow = -scrollTop + offset.top - containerHeight,
282+
bottomOverflow = scrollTop + viewPortHeight - (offset.top + height + containerHeight);
281283

282-
if (Math.max(top_overflow, bottom_overflow) === top_overflow)
283-
orientation = 'top';
284-
else
285-
orientation = 'bottom';
284+
orientation = (Math.max(topOverflow, bottomOverflow) === topOverflow)
285+
? 'top'
286+
: 'bottom';
286287
}
287288

288-
if (orientation === 'top')
289+
if (orientation === 'top') {
289290
styles.top += -containerHeight;
290-
else
291+
} else {
291292
styles.top += height;
293+
}
292294

293295
// If container is not positioned to body,
294296
// correct its position using offset parent offset
295297
if(containerParent !== document.body) {
296298
var opacity = $container.css('opacity'),
297299
parentOffsetDiff;
298-
if (!that.visible)
299-
$container.css('opacity', 0).show();
300+
301+
if (!that.visible){
302+
$container.css('opacity', 0).show();
303+
}
300304

301305
parentOffsetDiff = $container.offsetParent().offset();
302306
styles.top -= parentOffsetDiff.top;
303307
styles.left -= parentOffsetDiff.left;
304308

305-
if (!that.visible)
309+
if (!that.visible){
306310
$container.css('opacity', opacity).hide();
311+
}
307312
}
308313

309314
// -2px to account for suggestions border.
@@ -444,7 +449,7 @@
444449
query = that.getQuery(value),
445450
index;
446451

447-
if (that.selection) {
452+
if (that.selection && that.currentValue !== query) {
448453
that.selection = null;
449454
(options.onInvalidateSelection || $.noop).call(that.element);
450455
}
@@ -588,7 +593,14 @@
588593
},
589594

590595
hide: function () {
591-
var that = this;
596+
var that = this,
597+
container = $(that.suggestionsContainer);
598+
599+
if ($.isFunction(this.options.onHide) && that.visible) {
600+
601+
this.options.onHide.call(that.element, container);
602+
}
603+
592604
that.visible = false;
593605
that.selectedIndex = -1;
594606
$(that.suggestionsContainer).hide();
@@ -597,7 +609,7 @@
597609

598610
suggest: function () {
599611
if (this.suggestions.length === 0) {
600-
this.options.showNoSuggestionNotice ? this.noSuggestions() : this.hide();
612+
this.options.showNoSuggestionNotice ? this.noSuggestions() : this.hide();
601613
return;
602614
}
603615

@@ -611,8 +623,7 @@
611623
noSuggestionsContainer = $(that.noSuggestionsContainer),
612624
beforeRender = options.beforeRender,
613625
html = '',
614-
index,
615-
width;
626+
index;
616627

617628
if (options.triggerSelectOnValidInput) {
618629
index = that.findSuggestionIndex(value);
@@ -627,7 +638,7 @@
627638
html += '<div class="' + className + '" data-index="' + i + '">' + formatResult(suggestion, value) + '</div>';
628639
});
629640

630-
this.adjustContainerWidth();
641+
this.adjustContainerWidth();
631642

632643
noSuggestionsContainer.detach();
633644
container.html(html);
@@ -731,10 +742,12 @@
731742

732743
validateOrientation: function(orientation, fallback) {
733744
orientation = $.trim(orientation || '').toLowerCase();
745+
734746
if($.inArray(orientation, ['auto', 'bottom', 'top']) === -1){
735747
orientation = fallback;
736748
}
737-
return orientation
749+
750+
return orientation;
738751
},
739752

740753
processResponse: function (result, originalQuery, cacheKey) {
@@ -897,7 +910,7 @@
897910
};
898911

899912
// Create chainable jQuery plugin:
900-
$.fn.autocomplete = function (options, args) {
913+
$.fn.autocomplete = $.fn.devbridgeAutocomplete = function (options, args) {
901914
var dataKey = 'autocomplete';
902915
// If function invoked without argument return
903916
// instance of the first matched element:

0 commit comments

Comments
 (0)