Skip to content
This repository has been archived by the owner on Feb 18, 2018. It is now read-only.

Commit

Permalink
Merge pull request #19 from jerefrer/master
Browse files Browse the repository at this point in the history
Allows selection by hitting ENTER if neverSubmit is true
  • Loading branch information
knalli committed Aug 5, 2013
2 parents aa2b386 + ba85811 commit 44ca85e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 44 deletions.
4 changes: 2 additions & 2 deletions dist/jquery.autoSuggest.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ul.as-selections li.as-selection-item {
color: #2b3840;
font-size: 13px;
font-family: "Lucida Grande", arial, sans-serif;
text-shadow: 0 1px 1px white;
text-shadow: 0 1px 1px #fff;
background-color: #d4eaf6;
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #d4eaf6), color-stop(100%, #bfe0f1));
background: -webkit-linear-gradient(top, #d4eaf6, #bfe0f1);
Expand Down Expand Up @@ -62,7 +62,7 @@ ul.as-selections li.as-selection-item a.as-close {
font-size: 14px;
font-weight: bold;
text-shadow: 0 1px 1px white;
-webkit-transition: color 0.1s ease-in;
-webkit-transition: color .1s ease-in;
}
ul.as-selections li.as-selection-item.blur {
color: #666666;
Expand Down
45 changes: 11 additions & 34 deletions dist/jquery.autoSuggest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! jQuery AutoSuggest - v2.3.0 - 2013-03-29
/*! jQuery AutoSuggest - v2.3.0 - 2013-08-05
* URL: http://hlsolutions.github.com/jquery-autosuggest
* Copyright (c) 2013 Jan Philipp
* Licensed MIT, GPL */
Expand All @@ -22,8 +22,7 @@ Based on the 1.6er release dated in July, 2012

$ = jQuery;

/* A collection of utility functions.
*/
/* A collection of utility functions.*/


Utils = (function() {
Expand All @@ -43,7 +42,6 @@ Based on the 1.6er release dated in July, 2012

Utils.setPlaceholderEnabled = function(input, enable) {
var from, targets, to;

targets = ['placeholder', 'disabled-placeholder'];
if (enable) {
from = targets[1];
Expand All @@ -65,8 +63,7 @@ Based on the 1.6er release dated in July, 2012

})();

/* A collection of configuration resolvers.
*/
/* A collection of configuration resolvers.*/


ConfigResolver = (function() {
Expand All @@ -82,7 +79,6 @@ Based on the 1.6er release dated in July, 2012

ConfigResolver.getExtraParams = function(options) {
var obj, pair, parts, result, _i, _len, _ref;

result = options.extraParams;
if ($.isFunction(result)) {
result = result(this);
Expand Down Expand Up @@ -114,8 +110,7 @@ Based on the 1.6er release dated in July, 2012

})();

/* The SelectionControl maintains and manage any selections.
*/
/* The SelectionControl maintains and manage any selections.*/


SelectionHolder = (function() {
Expand All @@ -132,7 +127,6 @@ Based on the 1.6er release dated in July, 2012

SelectionHolder.prototype.syncToHiddenField = function() {
var item, value, _i, _len, _ref;

if (!this.hiddenField) {
return;
}
Expand Down Expand Up @@ -188,7 +182,6 @@ Based on the 1.6er release dated in July, 2012

Events.onSelectionAdd = function(scope, containerElement, detachedElement, options, item, selections) {
var element;

element = options.onSelectionAdd.call(scope, containerElement, detachedElement, options);
Utils.setPlaceholderEnabled(scope, selections.length === 0);
if ($.isFunction(options.afterSelectionAdd)) {
Expand Down Expand Up @@ -514,7 +507,6 @@ Based on the 1.6er release dated in July, 2012
pluginMethods = {
init: function(dataSource, options) {
var ajaxRequest, fetcher;

options = $.extend({}, defaults, options);
ajaxRequest = null;
if (options.remoteFilter === 'auto') {
Expand All @@ -527,10 +519,8 @@ Based on the 1.6er release dated in July, 2012
case 'string':
return function(query, callback) {
var ajaxRequestConfig, extraParams, onDone, params;

params = {};
/* ensures query is encoded
*/
/* ensures query is encoded*/

params["" + options.queryParam] = encodeURIComponent(decodeURIComponent(query));
if (options.retrieveLimit) {
Expand Down Expand Up @@ -572,7 +562,6 @@ Based on the 1.6er release dated in July, 2012

return this.each(function() {
var abortRequest, addSelection, clonePublicApi, currentSelection, element, elementId, hiddenInputField, hiddenInputFieldId, hiddenInputFieldName, i, input, inputWrapper, input_focus, interval, item, keyChange, lastKeyPressCode, lastKeyWasTab, moveResultSelection, new_value, num_count, prev, processData, processRequest, publicApi, resultsContainer, resultsList, selectionsContainer, timeout, value, _i, _j, _len, _len1, _ref, _ref1;

options.inputAttrs = $.extend(options.inputAttrs, {});
input_focus = false;
input = $(this);
Expand Down Expand Up @@ -635,7 +624,6 @@ Based on the 1.6er release dated in July, 2012
publicApi = {
add: function(data) {
var counted, item;

counted = $(selectionsContainer).find('li').length;
item = addSelection(data, "u" + counted);
if (item != null) {
Expand Down Expand Up @@ -667,7 +655,6 @@ Based on the 1.6er release dated in July, 2012

addSelection = function(data, num) {
var closeElement, item;

currentSelection.add(data[options.selectedValuesProp]);
item = $("<li class=\"as-selection-item\" id=\"as-selection-" + num + "\" data-value=\"" + (Utils.escapeQuotes(Utils.escapeHtml(data[options.selectedValuesProp]))) + "\"></li>");
item.on({
Expand Down Expand Up @@ -759,7 +746,6 @@ Based on the 1.6er release dated in July, 2012
*/

var string, _k, _results;

if (lastKeyPressCode === 46 || __indexOf.call((function() {
_results = [];
for (_k = 9; _k < 31; _k++){ _results.push(_k); }
Expand Down Expand Up @@ -790,7 +776,6 @@ Based on the 1.6er release dated in July, 2012
};
processData = function(data, query) {
var formatted, forward, matchCount, name, num, regex, resultsContainerVisible, str, text, workingData, _k, _l, _len2, _len3, _ref2;

if (!options.matchCase) {
query = query.toLowerCase();
}
Expand Down Expand Up @@ -825,7 +810,6 @@ Based on the 1.6er release dated in July, 2012
formatted.on({
click: function() {
var number, raw_data;

element = $(this);
raw_data = element.data('data');
number = raw_data.num;
Expand Down Expand Up @@ -857,8 +841,7 @@ Based on the 1.6er release dated in July, 2012
workingData = $.extend({}, data[num]);
query = query.replace(/"/g, '\\"');
regex = !options.matchCase ? new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + Utils.escapeHtml(query) + ")(?![^<>]*>)(?![^&;]+;)", "gi") : new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + Utils.escapeHtml(query) + ")(?![^<>]*>)(?![^&;]+;)", "g");
/* When this is a string, escape the value and process a regular replacement for highlighting.
*/
/* When this is a string, escape the value and process a regular replacement for highlighting.*/

if (typeof workingData[options.selectedItemProp] === 'string') {
workingData[options.selectedItemProp] = Utils.escapeHtml(workingData[options.selectedItemProp]);
Expand Down Expand Up @@ -904,7 +887,6 @@ Based on the 1.6er release dated in July, 2012
};
moveResultSelection = function(direction) {
var active, lis, start;

if (resultsContainer.find(':visible').length) {
lis = resultsContainer.find('li');
switch (direction) {
Expand Down Expand Up @@ -982,11 +964,9 @@ Based on the 1.6er release dated in July, 2012
Utils.setPlaceholderEnabled(element, currentSelection.isEmpty());
},
keydown: function(event) {
/* track the last key pressed
*/
/* track the last key pressed*/

var active, first_focus, i_input, n_data, _selection, _selections;

lastKeyPressCode = event.keyCode;
first_focus = false;
switch (event.keyCode) {
Expand Down Expand Up @@ -1041,22 +1021,21 @@ Based on the 1.6er release dated in July, 2012
break;
case 9:
case 188:
case 13:
active = resultsContainer.find('li.active:visible:first');
if (options.canGenerateNewSelections) {
lastKeyWasTab = true;
i_input = input.val().replace(/(,)/g, '');
/* Generate a new bubble with text when no suggestion selected
*/
/* Generate a new bubble with text when no suggestion selected*/

if (i_input !== '' && !currentSelection.exist(i_input) && i_input.length >= options.minChars && active.length === 0) {
if (i_input !== '' && !currentSelection.exist(i_input) && i_input.length >= options.minChars && active.length === 0 && (options.neverSubmit || event.keyCode !== 13)) {
event.preventDefault();
n_data = {};
n_data["" + options.selectedItemProp] = i_input;
n_data["" + options.selectedValuesProp] = i_input;
addSelection(n_data, "00" + (selectionsContainer.find('li').length + 1));
input.val('');
/* Cancel previous ajaxRequest when new tag is added
*/
/* Cancel previous ajaxRequest when new tag is added*/

abortRequest();
}
Expand Down Expand Up @@ -1098,7 +1077,6 @@ Based on the 1.6er release dated in July, 2012
},
add: function() {
var element, item, items, _i, _len;

items = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
element = $(this);
for (_i = 0, _len = items.length; _i < _len; _i++) {
Expand All @@ -1108,7 +1086,6 @@ Based on the 1.6er release dated in July, 2012
},
remove: function() {
var element, value, values, _i, _len;

values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
element = $(this);
for (_i = 0, _len = values.length; _i < _len; _i++) {
Expand Down
Loading

0 comments on commit 44ca85e

Please sign in to comment.