jquery-autocomplete
Advanced tools
Comparing version 1.2.1 to 1.2.6
{ | ||
"name": "autocompletelikegoogle", | ||
"version": "1.2.1", | ||
"version": "1.2.6", | ||
"title": "Autocomplete like Google", | ||
@@ -5,0 +5,0 @@ "description": "Simple autocomplete like Google", |
{ | ||
"name":"autocompletelikegoogle", | ||
"version":"1.2.1", | ||
"version":"1.2.6", | ||
"main": [ | ||
@@ -5,0 +5,0 @@ "jquery.autocomplete.js", |
@@ -0,0 +0,0 @@ var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; |
/** | ||
* @preserve jQuery Autocomplete plugin v1.2.1 | ||
* @preserve jQuery Autocomplete plugin v1.2.6 | ||
* @homepage http://xdsoft.net/jqplugins/autocomplete/ | ||
* @license MIT - MIT-LICENSE.txt | ||
* (c) 2014, Chupurnov Valeriy <chupurnov@gmail.com> | ||
@@ -25,6 +26,5 @@ */ | ||
defaultSetting = {}, | ||
currentInput = false, | ||
//currentInput = false, | ||
ctrlDown = false, | ||
shiftDown = false, | ||
interval_for_visibility, | ||
publics = {}, | ||
@@ -119,3 +119,3 @@ accent_map = { | ||
for (property in currentStyle) { | ||
if (currentStyle.hasOwnProperty(property)) { | ||
if (Object.prototype.hasOwnProperty.call(currentStyle, property)) { | ||
if (/width|height|margin.|padding.|border.+W/.test(property) && style[property] !== 'auto') { | ||
@@ -237,3 +237,4 @@ style[property] = getPixelSize(element, currentStyle, property, fontSize) + 'px'; | ||
var undefinedVar; | ||
return safe_call.call( this, (isset(this.source[source])&&this.source[source].hasOwnProperty(callbackName))?this.source[source][callbackName]:undefinedVar,args, function(){ | ||
return safe_call.call( this, (isset(this.source[source])&& | ||
Object.prototype.hasOwnProperty.call(this.source[source], callbackName)) ? this.source[source][callbackName] : undefinedVar, args, function(){ | ||
return safe_call.call(this, | ||
@@ -244,3 +245,3 @@ isset(this[callbackName][source])? | ||
this[callbackName][0]:( | ||
this.hasOwnProperty(callbackName)? | ||
Object.prototype.hasOwnProperty.call(this, callbackName)? | ||
this[callbackName]: | ||
@@ -279,3 +280,6 @@ undefinedVar | ||
function loadRemote( url,sourceObject,done,debug ){ | ||
$.ajax($.extend(true,{ | ||
if (sourceObject.xhr) { | ||
sourceObject.xhr.abort(); | ||
} | ||
sourceObject.xhr = $.ajax($.extend(true,{ | ||
url : url, | ||
@@ -340,13 +344,21 @@ type : 'GET' , | ||
} else if ($.isFunction(options.source[source])) { | ||
options.source[source].apply(options,[query,function(items){ | ||
if (!datasource[source]) { | ||
datasource[source] = []; | ||
} | ||
if (items && $.isArray(items)) { | ||
datasource[source] = datasource[source].concat(items); | ||
} | ||
safe_call.call(options,callback,[query]); | ||
}, datasource,source]); | ||
(function (source) { | ||
options.source[source].apply(options,[query, function(items){ | ||
if (!datasource[source]) { | ||
datasource[source] = []; | ||
} | ||
if (items && $.isArray(items)) { | ||
switch (options.appendMethod) { | ||
case 'replace': | ||
datasource[source] = items; | ||
break; | ||
default: | ||
datasource[source] = datasource[source].concat(items); | ||
} | ||
} | ||
safe_call.call(options,callback,[query]); | ||
}, datasource,source]); | ||
}(source)); | ||
} else { | ||
@@ -425,3 +437,3 @@ switch (options.source[source].type) { | ||
){ | ||
return dataset[$div.data('source')][$div.data('pid')] | ||
return dataset[$div.data('source')][$div.data('pid')]; | ||
} | ||
@@ -449,2 +461,3 @@ return false; | ||
defaultSetting = { | ||
minLength: 0, | ||
valueKey: 'value', | ||
@@ -463,3 +476,3 @@ titleKey: 'title', | ||
debug: true, | ||
openOnFocus: true, | ||
openOnFocus: false, | ||
closeOnBlur: true, | ||
@@ -499,10 +512,10 @@ | ||
var results = [],value = '',i; | ||
for (i = 0;i < items.length;i += 1) { | ||
value = __safe.call(this,'getValue',source,[items[i],source]); | ||
if( __safe.call(this,'equal',source,[value,query,source],false) ){ | ||
return items[i]; | ||
} | ||
if (items) { | ||
for (i = 0;i < items.length;i += 1) { | ||
value = __safe.call(this,'getValue',source,[items[i],source]); | ||
if (__safe.call(this, 'equal', source, [value,query,source], false)) { | ||
return items[i]; | ||
} | ||
} | ||
} | ||
return false; | ||
@@ -526,6 +539,8 @@ } | ||
var results = [], value = '',i; | ||
for (i = 0;i < items.length;i += 1) { | ||
value = isset(items[i][this.get('valueKey', source)]) ? items[i][this.get('valueKey', source)] : items[i].toString(); | ||
if (__safe.call(this, 'valid', source, [value, query])) { | ||
results.push(items[i]); | ||
if (items) { | ||
for (i = 0;i < items.length;i += 1) { | ||
value = isset(items[i][this.get('valueKey', source)]) ? items[i][this.get('valueKey', source)] : items[i].toString(); | ||
if (__safe.call(this, 'valid', source, [value, query])) { | ||
results.push(items[i]); | ||
} | ||
} | ||
@@ -541,4 +556,4 @@ } | ||
getValue:[ | ||
function ( item,source ){ | ||
getValue: [ | ||
function (item, source) { | ||
return isset(item[this.get('valueKey',source)])?item[this.get('valueKey',source)]:item.toString(); | ||
@@ -548,4 +563,4 @@ } | ||
getTitle:[ | ||
function ( item,source ){ | ||
getTitle: [ | ||
function (item, source) { | ||
return isset(item[this.get('titleKey',source)])?item[this.get('titleKey',source)]:item.toString(); | ||
@@ -555,6 +570,6 @@ } | ||
render:[ | ||
render: [ | ||
function (item, source, pid, query) { | ||
var value = isset(item[this.get('valueKey', source)]) ? item[this.get('valueKey', source)] : item.toString(), | ||
title = (isset(item[this.get('titleKey', source)]) ? item[this.get('titleKey', source)] : value) + '', | ||
var value = __safe.call(this, "getValue", source, [item, source], defaultSetting.getValue[0].call(this, item, source)), | ||
title = __safe.call(this, "getTitle", source, [item, source], defaultSetting.getTitle[0].call(this, item, source)), | ||
_value = '', | ||
@@ -597,4 +612,6 @@ _query = '', | ||
], | ||
source:[] | ||
appendMethod: 'concat', // supported merge and replace | ||
source:[], | ||
afterSelected: function() { | ||
} | ||
}; | ||
@@ -610,2 +627,3 @@ function init( that,options ){ | ||
timer1 = 0, | ||
intervalForVisibility, | ||
dataset = [], | ||
@@ -658,2 +676,5 @@ iOpen = false, | ||
var xDown = null; | ||
var yDown = null; | ||
var isSwipe = false; | ||
$dropdown | ||
@@ -666,3 +687,3 @@ .on('mousemove','div',function(){ | ||
}) | ||
.on('mousedown','div',function(){ | ||
.on('mousedown','div',function(e){ | ||
$dropdown.find('div').removeClass('active'); | ||
@@ -672,22 +693,68 @@ $(this).addClass('active'); | ||
}) | ||
.on('touchstart','div',function(e){ | ||
xDown = e.originalEvent.touches[0].clientX; | ||
yDown = e.originalEvent.touches[0].clientY; | ||
}) | ||
.on('touchend','div',function(e){ | ||
if(isSwipe === false) { | ||
$dropdown.find('div').removeClass('active'); | ||
$(this).addClass('active'); | ||
$input.trigger('pick.xdsoft'); | ||
} | ||
isSwipe = false; | ||
}) | ||
.on('touchmove','div',function(e){ | ||
if ( ! xDown || ! yDown ) { | ||
return; | ||
} | ||
var xUp = e.originalEvent.touches[0].clientX; | ||
var yUp = e.originalEvent.touches[0].clientY; | ||
var xDiff = xDown - xUp; | ||
var yDiff = yDown - yUp; | ||
if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) { | ||
if ( xDiff > 0 ) { | ||
isSwipe = 'left'; | ||
} else { | ||
isSwipe = 'right'; | ||
} | ||
} else { | ||
if ( yDiff > 0 ) { | ||
isSwipe = 'top'; | ||
} else { | ||
isSwipe = 'bottm'; | ||
} | ||
} | ||
xDown = null; | ||
yDown = null; | ||
}); | ||
function manageData(){ | ||
if( $input.val()!=currentValue ){ | ||
if ($input.val()!=currentValue){ | ||
currentValue = $input.val(); | ||
}else | ||
} else { | ||
return; | ||
} | ||
if (currentValue.length < options.minLength) { | ||
$input.trigger('close.xdsoft'); | ||
return; | ||
} | ||
collectData.call(options,currentValue,dataset,function( query ){ | ||
if( query != currentValue ) | ||
if (query != currentValue) { | ||
return; | ||
} | ||
var right; | ||
processData.call(options,dataset,query); | ||
processData.call(options, dataset,query); | ||
$input.trigger('updateContent.xdsoft'); | ||
if( options.showHint && currentValue.length && currentValue.length<=$input.prop('size') && (right = findRight.call(options,dataset,currentValue)) ){ | ||
if (options.showHint && currentValue.length && currentValue.length<=$input.prop('size') && (right = findRight.call(options,dataset,currentValue))) { | ||
var title = __safe.call(options,'getTitle',right.source,[right.right,right.source]); | ||
title = /*'<span>'+*/query+/*'</span>'+*/title.substr(query.length); | ||
$hint.val( title ); | ||
}else{ | ||
title = query + title.substr(query.length); | ||
$hint.val(title); | ||
} else { | ||
$hint.val(''); | ||
@@ -699,4 +766,5 @@ } | ||
} | ||
function manageKey (event) { | ||
var key = event.which,right; | ||
var key = event.keyCode, right; | ||
@@ -795,11 +863,9 @@ switch( key ){ | ||
$input | ||
.trigger('timepick.xdsoft',_value) | ||
$input.trigger('timepick.xdsoft',_value); | ||
currentSelect = currentValue = $input.val(); | ||
$input | ||
.trigger('close.xdsoft'); | ||
$input.trigger('close.xdsoft'); | ||
currentInput = false; | ||
//currentInput = false; | ||
@@ -812,2 +878,5 @@ active = $dropdown.find('div.active').eq(0); | ||
$input.trigger('selected.xdsoft',[getItem(active,dataset)]); | ||
if (options.afterSelected) | ||
options.afterSelected(); | ||
}) | ||
@@ -831,3 +900,3 @@ .on('timepick.xdsoft', function( event,_value ){ | ||
}) | ||
.on('keydown.xdsoft keypress.xdsoft input.xdsoft cut.xdsoft paste.xdsoft', function( event ){ | ||
.on('keydown.xdsoft input.xdsoft cut.xdsoft paste.xdsoft', function( event ){ | ||
var ret = manageKey(event); | ||
@@ -839,6 +908,2 @@ | ||
if (!iOpen) { | ||
$input.trigger('open.xdsoft'); | ||
} | ||
setTimeout(function(){ | ||
@@ -849,2 +914,5 @@ manageData(); | ||
manageData(); | ||
}) | ||
.on('change.xdsoft', function( event ){ | ||
currentValue = $input.val(); | ||
}); | ||
@@ -888,3 +956,3 @@ | ||
left:$input.position().left, | ||
top:$input.position().top+parseInt($input.css('marginTop'))+parseInt($input[0].offsetHeight), | ||
top:$input.position().top + parseInt($input.css('marginTop'))+parseInt($input[0].offsetHeight), | ||
marginLeft:$input.css('marginLeft'), | ||
@@ -895,3 +963,3 @@ marginRight:$input.css('marginRight'), | ||
if( options.showHint ){ | ||
if (options.showHint) { | ||
var style = getComputedStyle($input[0], ""); | ||
@@ -927,5 +995,5 @@ | ||
fontVariant:style.fontVariant, | ||
fontStyle:style.fontStyle, | ||
fontSize:style.fontSize, | ||
fontWeight:style.fontWeight, | ||
fontStyle:$input.css('fontStyle'), | ||
fontSize:$input.css('fontSize'), | ||
fontWeight:$input.css('fontWeight'), | ||
flex:style.flex, | ||
@@ -938,3 +1006,3 @@ justifyContent:style.justifyContent, | ||
$input.css('font-size',style.fontSize)// fix bug with em font size | ||
$input.css('font-size',$input.css('fontSize'))// fix bug with em font size | ||
@@ -953,2 +1021,3 @@ $hint.innerHeight($input.innerHeight()); | ||
if( olderBackground!==false ){ | ||
@@ -960,8 +1029,12 @@ $hint.css('background',olderBackground); | ||
$input | ||
.css('background','transparent') | ||
try{ | ||
$input[0].style.setProperty('background', 'transparent', 'important'); | ||
} catch(e) { | ||
$input.css('background','transparent') | ||
} | ||
$box | ||
.append($hint); | ||
} | ||
},options.timeoutUpdate||1); | ||
}, options.timeoutUpdate||1); | ||
}); | ||
@@ -973,7 +1046,7 @@ | ||
} else { | ||
interval_for_visibility = setInterval(function () { | ||
intervalForVisibility = setInterval(function () { | ||
if ($input.is(':visible')) { | ||
$input | ||
.trigger('updateHelperPosition.xdsoft'); | ||
clearInterval(interval_for_visibility); | ||
clearInterval(intervalForVisibility); | ||
} | ||
@@ -993,17 +1066,19 @@ },100); | ||
.on('close.xdsoft',function(){ | ||
if( !iOpen ) | ||
if (!iOpen) { | ||
return; | ||
} | ||
$dropdown | ||
.hide(); | ||
$hint | ||
.empty(); | ||
.val(''); | ||
if( !options.autoselect ) | ||
if (!options.autoselect) { | ||
$input.val(currentValue); | ||
} | ||
iOpen = false; | ||
currentInput = false; | ||
//currentInput = false; | ||
}) | ||
@@ -1016,5 +1091,5 @@ | ||
if (out.length) { | ||
$dropdown.show() | ||
$input.trigger('open.xdsoft'); | ||
} else { | ||
$dropdown.hide() | ||
$input.trigger('close.xdsoft'); | ||
return; | ||
@@ -1048,7 +1123,7 @@ } | ||
$dropdown | ||
.show() | ||
.show(); | ||
iOpen = true; | ||
currentInput = $input; | ||
//currentInput = $input; | ||
}) | ||
@@ -1060,3 +1135,4 @@ .on('destroy.xdsoft',function(){ | ||
clearTimeout(timer1); | ||
currentInput = false; | ||
clearTimeout(intervalForVisibility); | ||
//currentInput = false; | ||
$input.data('xdsoft_autocomplete',null); | ||
@@ -1128,2 +1204,2 @@ $input | ||
}; | ||
}(jQuery)); | ||
}(jQuery)); |
{ | ||
"name": "jquery-autocomplete", | ||
"version": "1.2.1", | ||
"version": "1.2.6", | ||
"description": "Simple autocomplete like Google", | ||
@@ -29,3 +29,3 @@ "main": "jquery.autocomplete.js", | ||
}, | ||
"homepage": "https://github.com/xdan/autocomplete" | ||
"homepage": "https://xdsoft.net" | ||
} |
Sorry, the diff of this file is not supported yet
164084
16
1642