2
0
mirror of https://github.com/devbridge/jQuery-Autocomplete.git synced 2024-12-22 19:08:55 +00:00

Add grunt. Automate version setting for configuration files.

This commit is contained in:
Tomas Kirda 2014-09-06 15:19:40 -05:00
parent 23bdea852e
commit d3577df69b
8 changed files with 128 additions and 73 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
/.idea*
/*.xml
/bower_components
/node_modules/*

View File

@ -1,24 +1,24 @@
{
"name": "devbridge-autocomplete",
"version": "1.2.11",
"homepage": "https://github.com/devbridge/jQuery-Autocomplete",
"authors": [
"Tomas Kirda"
],
"description": "Autocomplete provides suggestions while you type into the text field.",
"main": "dist/jquery.autocomplete.js",
"keywords": [
"ajax",
"autocomplete"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"spec"
],
"dependencies": {
"jquery": ">=1.7"
}
"name": "devbridge-autocomplete",
"version": "1.2.11",
"homepage": "https://github.com/devbridge/jQuery-Autocomplete",
"authors": [
"Tomas Kirda"
],
"description": "Autocomplete provides suggestions while you type into the text field.",
"main": "dist/jquery.autocomplete.js",
"keywords": [
"ajax",
"autocomplete"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"spec"
],
"dependencies": {
"jquery": ">=1.7"
}
}

View File

@ -6,7 +6,7 @@
"ajax",
"autocomplete"
],
"version": "1.2.9",
"version": "1.2.11",
"author": {
"name": "Tomas Kirda",
"url": "https://github.com/tkirda"

View File

@ -4,11 +4,10 @@
*
* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
* For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete
*
*/
/*jslint browser: true, white: true, plusplus: true */
/*global define, window, document, jQuery */
/*global define, window, document, jQuery, exports */
// Expose plugin as an AMD module if AMD loader is present:
(function (factory) {
@ -16,6 +15,9 @@
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object' && typeof require === 'function') {
// Browserify
factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
@ -138,8 +140,7 @@
suggestionSelector = '.' + that.classes.suggestion,
selected = that.classes.selected,
options = that.options,
container,
noSuggestionsContainer;
container;
// Remove autocomplete attribute to prevent native suggestions:
that.element.setAttribute('autocomplete', 'off');
@ -276,34 +277,37 @@
if (orientation == 'auto') {
var viewPortHeight = $(window).height(),
scrollTop = $(window).scrollTop(),
top_overflow = -scrollTop + offset.top - containerHeight,
bottom_overflow = scrollTop + viewPortHeight - (offset.top + height + containerHeight);
topOverflow = -scrollTop + offset.top - containerHeight,
bottomOverflow = scrollTop + viewPortHeight - (offset.top + height + containerHeight);
if (Math.max(top_overflow, bottom_overflow) === top_overflow)
orientation = 'top';
else
orientation = 'bottom';
orientation = (Math.max(topOverflow, bottomOverflow) === topOverflow)
? 'top'
: 'bottom';
}
if (orientation === 'top')
if (orientation === 'top') {
styles.top += -containerHeight;
else
} else {
styles.top += height;
}
// If container is not positioned to body,
// correct its position using offset parent offset
if(containerParent !== document.body) {
var opacity = $container.css('opacity'),
parentOffsetDiff;
if (!that.visible)
$container.css('opacity', 0).show();
if (!that.visible){
$container.css('opacity', 0).show();
}
parentOffsetDiff = $container.offsetParent().offset();
styles.top -= parentOffsetDiff.top;
styles.left -= parentOffsetDiff.left;
if (!that.visible)
if (!that.visible){
$container.css('opacity', opacity).hide();
}
}
// -2px to account for suggestions border.
@ -444,7 +448,7 @@
query = that.getQuery(value),
index;
if (that.selection) {
if (that.selection && that.currentValue !== query) {
that.selection = null;
(options.onInvalidateSelection || $.noop).call(that.element);
}
@ -611,8 +615,7 @@
noSuggestionsContainer = $(that.noSuggestionsContainer),
beforeRender = options.beforeRender,
html = '',
index,
width;
index;
if (options.triggerSelectOnValidInput) {
index = that.findSuggestionIndex(value);
@ -731,10 +734,12 @@
validateOrientation: function(orientation, fallback) {
orientation = $.trim(orientation || '').toLowerCase();
if($.inArray(orientation, ['auto', 'bottom', 'top']) === -1){
orientation = fallback;
}
return orientation
return orientation;
},
processResponse: function (result, originalQuery, cacheKey) {
@ -765,9 +770,9 @@
activeItem,
selected = that.classes.selected,
container = $(that.suggestionsContainer),
children = container.children();
children = container.find('.' + that.classes.suggestion);
container.children('.' + selected).removeClass(selected);
container.find('.' + selected).removeClass(selected);
that.selectedIndex = index;
@ -897,7 +902,7 @@
};
// Create chainable jQuery plugin:
$.fn.autocomplete = function (options, args) {
$.fn.autocomplete = $.fn.devbridgeAutocomplete = function (options, args) {
var dataKey = 'autocomplete';
// If function invoked without argument return
// instance of the first matched element:

File diff suppressed because one or more lines are too long

69
gruntfile.js Normal file
View File

@ -0,0 +1,69 @@
module.exports = function(grunt) {
var pkg = grunt.file.readJSON('package.json');
var banner = [
'/**',
'* Ajax Autocomplete for jQuery, version ' + pkg.version,
'* (c) 2014 Tomas Kirda',
'*',
'* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.',
'* For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete',
'*/'].join('\n') + '\n';
// Project configuration.
grunt.initConfig({
pkg: pkg,
uglify: {
options: {
banner: banner
},
build: {
src: 'src/jquery.autocomplete.js',
dest: 'dist/jquery.autocomplete.min.js'
}
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
// Default task(s).
grunt.registerTask('default', ['uglify']);
grunt.task.registerTask('build', 'Create release', function() {
var version = pkg.version
src = grunt.file.read('src/jquery.autocomplete.js').replace('%version%', version),
filePath = 'dist/jquery.autocomplete.js';
// Update not minimized release version:
console.log('Updating: ' + filePath);
grunt.file.write(filePath, src);
// Update plugin version:
filePath = 'devbridge-autocomplete.jquery.json';
src = grunt.file.readJSON(filePath);
if (src.version !== version){
src.version = version;
console.log('Updating: ' + filePath);
grunt.file.write(filePath, JSON.stringify(src, null, 4));
} else {
console.log('No updates for: ' + filePath);
}
// Update bower version:
filePath = 'bower.json';
src = grunt.file.readJSON(filePath);
if (src.version !== version){
src.version = version;
console.log('Updating: ' + filePath);
grunt.file.write(filePath, JSON.stringify(src, null, 4));
} else {
console.log('No updates for: ' + filePath);
}
});
};

View File

@ -8,5 +8,9 @@
"license": "MIT",
"dependencies": {
"jquery": ">=1.7"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-uglify": "^0.5.1"
}
}

View File

@ -1,10 +1,9 @@
/**
* Ajax Autocomplete for jQuery, version 1.2.11
* Ajax Autocomplete for jQuery, version %version%
* (c) 2014 Tomas Kirda
*
* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
* For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete
*
*/
/*jslint browser: true, white: true, plusplus: true */