Skip to content

Commit d3577df

Browse files
author
Tomas Kirda
committed
Add grunt. Automate version setting for configuration files.
1 parent 23bdea8 commit d3577df

8 files changed

+128
-73
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/.idea*
55
/*.xml
66
/bower_components
7+
/node_modules/*

bower.json

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
2-
"name": "devbridge-autocomplete",
3-
"version": "1.2.11",
4-
"homepage": "https://github.com/devbridge/jQuery-Autocomplete",
5-
"authors": [
6-
"Tomas Kirda"
7-
],
8-
"description": "Autocomplete provides suggestions while you type into the text field.",
9-
"main": "dist/jquery.autocomplete.js",
10-
"keywords": [
11-
"ajax",
12-
"autocomplete"
13-
],
14-
"license": "MIT",
15-
"ignore": [
16-
"**/.*",
17-
"node_modules",
18-
"bower_components",
19-
"spec"
20-
],
21-
"dependencies": {
22-
"jquery": ">=1.7"
23-
}
24-
}
2+
"name": "devbridge-autocomplete",
3+
"version": "1.2.11",
4+
"homepage": "https://github.com/devbridge/jQuery-Autocomplete",
5+
"authors": [
6+
"Tomas Kirda"
7+
],
8+
"description": "Autocomplete provides suggestions while you type into the text field.",
9+
"main": "dist/jquery.autocomplete.js",
10+
"keywords": [
11+
"ajax",
12+
"autocomplete"
13+
],
14+
"license": "MIT",
15+
"ignore": [
16+
"**/.*",
17+
"node_modules",
18+
"bower_components",
19+
"spec"
20+
],
21+
"dependencies": {
22+
"jquery": ">=1.7"
23+
}
24+
}

devbridge-autocomplete.jquery.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"ajax",
77
"autocomplete"
88
],
9-
"version": "1.2.9",
9+
"version": "1.2.11",
1010
"author": {
1111
"name": "Tomas Kirda",
1212
"url": "https://github.com/tkirda"

dist/jquery.autocomplete.js

+27-22
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44
*
55
* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
66
* For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete
7-
*
87
*/
98

109
/*jslint browser: true, white: true, plusplus: true */
11-
/*global define, window, document, jQuery */
10+
/*global define, window, document, jQuery, exports */
1211

1312
// Expose plugin as an AMD module if AMD loader is present:
1413
(function (factory) {
1514
'use strict';
1615
if (typeof define === 'function' && define.amd) {
1716
// AMD. Register as an anonymous module.
1817
define(['jquery'], factory);
18+
} else if (typeof exports === 'object' && typeof require === 'function') {
19+
// Browserify
20+
factory(require('jquery'));
1921
} else {
2022
// Browser globals
2123
factory(jQuery);
@@ -138,8 +140,7 @@
138140
suggestionSelector = '.' + that.classes.suggestion,
139141
selected = that.classes.selected,
140142
options = that.options,
141-
container,
142-
noSuggestionsContainer;
143+
container;
143144

144145
// Remove autocomplete attribute to prevent native suggestions:
145146
that.element.setAttribute('autocomplete', 'off');
@@ -276,34 +277,37 @@
276277
if (orientation == 'auto') {
277278
var viewPortHeight = $(window).height(),
278279
scrollTop = $(window).scrollTop(),
279-
top_overflow = -scrollTop + offset.top - containerHeight,
280-
bottom_overflow = scrollTop + viewPortHeight - (offset.top + height + containerHeight);
280+
topOverflow = -scrollTop + offset.top - containerHeight,
281+
bottomOverflow = scrollTop + viewPortHeight - (offset.top + height + containerHeight);
281282

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

288-
if (orientation === 'top')
288+
if (orientation === 'top') {
289289
styles.top += -containerHeight;
290-
else
290+
} else {
291291
styles.top += height;
292+
}
292293

293294
// If container is not positioned to body,
294295
// correct its position using offset parent offset
295296
if(containerParent !== document.body) {
296297
var opacity = $container.css('opacity'),
297298
parentOffsetDiff;
298-
if (!that.visible)
299-
$container.css('opacity', 0).show();
299+
300+
if (!that.visible){
301+
$container.css('opacity', 0).show();
302+
}
300303

301304
parentOffsetDiff = $container.offsetParent().offset();
302305
styles.top -= parentOffsetDiff.top;
303306
styles.left -= parentOffsetDiff.left;
304307

305-
if (!that.visible)
308+
if (!that.visible){
306309
$container.css('opacity', opacity).hide();
310+
}
307311
}
308312

309313
// -2px to account for suggestions border.
@@ -444,7 +448,7 @@
444448
query = that.getQuery(value),
445449
index;
446450

447-
if (that.selection) {
451+
if (that.selection && that.currentValue !== query) {
448452
that.selection = null;
449453
(options.onInvalidateSelection || $.noop).call(that.element);
450454
}
@@ -611,8 +615,7 @@
611615
noSuggestionsContainer = $(that.noSuggestionsContainer),
612616
beforeRender = options.beforeRender,
613617
html = '',
614-
index,
615-
width;
618+
index;
616619

617620
if (options.triggerSelectOnValidInput) {
618621
index = that.findSuggestionIndex(value);
@@ -731,10 +734,12 @@
731734

732735
validateOrientation: function(orientation, fallback) {
733736
orientation = $.trim(orientation || '').toLowerCase();
737+
734738
if($.inArray(orientation, ['auto', 'bottom', 'top']) === -1){
735739
orientation = fallback;
736740
}
737-
return orientation
741+
742+
return orientation;
738743
},
739744

740745
processResponse: function (result, originalQuery, cacheKey) {
@@ -765,9 +770,9 @@
765770
activeItem,
766771
selected = that.classes.selected,
767772
container = $(that.suggestionsContainer),
768-
children = container.children();
773+
children = container.find('.' + that.classes.suggestion);
769774

770-
container.children('.' + selected).removeClass(selected);
775+
container.find('.' + selected).removeClass(selected);
771776

772777
that.selectedIndex = index;
773778

@@ -897,7 +902,7 @@
897902
};
898903

899904
// Create chainable jQuery plugin:
900-
$.fn.autocomplete = function (options, args) {
905+
$.fn.autocomplete = $.fn.devbridgeAutocomplete = function (options, args) {
901906
var dataKey = 'autocomplete';
902907
// If function invoked without argument return
903908
// instance of the first matched element:

dist/jquery.autocomplete.min.js

+2-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gruntfile.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
module.exports = function(grunt) {
2+
3+
var pkg = grunt.file.readJSON('package.json');
4+
5+
var banner = [
6+
'/**',
7+
'* Ajax Autocomplete for jQuery, version ' + pkg.version,
8+
'* (c) 2014 Tomas Kirda',
9+
'*',
10+
'* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.',
11+
'* For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete',
12+
'*/'].join('\n') + '\n';
13+
14+
// Project configuration.
15+
grunt.initConfig({
16+
pkg: pkg,
17+
uglify: {
18+
options: {
19+
banner: banner
20+
},
21+
build: {
22+
src: 'src/jquery.autocomplete.js',
23+
dest: 'dist/jquery.autocomplete.min.js'
24+
}
25+
}
26+
});
27+
28+
// Load the plugin that provides the "uglify" task.
29+
grunt.loadNpmTasks('grunt-contrib-uglify');
30+
31+
// Default task(s).
32+
grunt.registerTask('default', ['uglify']);
33+
34+
grunt.task.registerTask('build', 'Create release', function() {
35+
var version = pkg.version
36+
src = grunt.file.read('src/jquery.autocomplete.js').replace('%version%', version),
37+
filePath = 'dist/jquery.autocomplete.js';
38+
39+
// Update not minimized release version:
40+
console.log('Updating: ' + filePath);
41+
grunt.file.write(filePath, src);
42+
43+
// Update plugin version:
44+
filePath = 'devbridge-autocomplete.jquery.json';
45+
src = grunt.file.readJSON(filePath);
46+
47+
if (src.version !== version){
48+
src.version = version;
49+
console.log('Updating: ' + filePath);
50+
grunt.file.write(filePath, JSON.stringify(src, null, 4));
51+
} else {
52+
console.log('No updates for: ' + filePath);
53+
}
54+
55+
// Update bower version:
56+
filePath = 'bower.json';
57+
src = grunt.file.readJSON(filePath);
58+
59+
if (src.version !== version){
60+
src.version = version;
61+
console.log('Updating: ' + filePath);
62+
grunt.file.write(filePath, JSON.stringify(src, null, 4));
63+
} else {
64+
console.log('No updates for: ' + filePath);
65+
}
66+
67+
68+
});
69+
};

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
"license": "MIT",
99
"dependencies": {
1010
"jquery": ">=1.7"
11+
},
12+
"devDependencies": {
13+
"grunt": "^0.4.5",
14+
"grunt-contrib-uglify": "^0.5.1"
1115
}
1216
}

src/jquery.autocomplete.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/**
2-
* Ajax Autocomplete for jQuery, version 1.2.11
2+
* Ajax Autocomplete for jQuery, version %version%
33
* (c) 2014 Tomas Kirda
44
*
55
* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
66
* For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete
7-
*
87
*/
98

109
/*jslint browser: true, white: true, plusplus: true */

0 commit comments

Comments
 (0)