Skip to content

Commit

Permalink
## Versiyon 2.0.4
Browse files Browse the repository at this point in the history
- FIX: Çalışmayan hidden property işlevsel hale getirildi.
- YENİ: Search parametresi customize edilebilir hale getirildi.
- YENİ: Servis cevabı artık sadece gelen array'e değil set edilen propertydeki arrayi alabiliyor.
- YENİ: Debounce özelliği eklendi.
  • Loading branch information
ihaveaproblem committed Mar 29, 2017
1 parent 09634be commit fb9a33c
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 90 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ highlight | true | Listelerde match eden karakterlere
arrowSelection | false | Listelerde ok tuşları ile hareket ettikten sonra `enter` tuşuna basarak sonucun seçilip seçilmeyeceğini belirtir.
arrowNavigation | true | Listelerde ok tuşları ile hareket ederken satırın highlight olup olmayacağını belirtir.
cache | false | Ajax sorgusu yapılan aramalarda sonuçların ön belleğe kaydedilip kaydedilmeyeceğiniz belirtir.

debounce | 0 | Yazmaya başladıktan sonra servisi çağırmak için gecikme süresi ayarlar (ms).
customProp | false | Çağırılan ajax servis direkt array'i direkt değil de result içerisinde dönüyorsa ilgili array set edilebilir örn : 'result' böylece plugin dönen jsonda result objesinin içerisindeki arraya set olur.
searchTerm | 'term' | Çağırılan serviste term propertysi default olarak 'term' gelmiyorsa istenilen şekilde set edilebilir.

Data Attribute |  
-------------------------- | -----
Expand Down
127 changes: 84 additions & 43 deletions dist/uxrocket.autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* UX Rocket
* jQuery based autocomplete
* @author Bilal Cinarli
* @modifier Kursad Yildirmak
* @dependency Handlebars
*/

Expand Down Expand Up @@ -37,59 +38,64 @@
arrowSelection : false,
arrowNavigation: true,
cache : false,
debounce : 0,
searchTerm : 'term',
customProp : false,

// callbacks
onReady : false,
onSearch : false,
onSelect : function(e){},
onSelect : false,
onEnter : false,
onButtonClick: false,
onClearCache : false,
onUpdate : false,
onRemove : false
},


templates = {
list : {
item: '' +
'<li class="uxr-autocomplete-list-item">' +
' <a {{#if url}}href="{{url}}"{{/if}}>' +
' {{{name}}}' +
' </a>' +
'</li>'
'<li data-id="{{id}}" class="uxr-autocomplete-list-item">' +
' <a {{#if url}}href="{{url}}"{{/if}}>' +
' {{{name}}}' +
' </a>' +
'</li>'
},
image : {
item: '' +
'<li class="uxr-autocomplete-list-item">' +
' <a {{#if url}}href="{{url}}"{{/if}}>' +
' <span class="item-image"><img src="{{image}}"/></span> ' +
' {{{name}}}' +
' </a>' +
'</li>'
'<li data-id="{{id}}" class="uxr-autocomplete-list-item">' +
' <a {{#if url}}href="{{url}}"{{/if}}>' +
' <span class="item-image"><img src="{{image}}"/></span> ' +
' {{{name}}}' +
' </a>' +
'</li>'
},
category: {
head: '' +
'<li class="uxr-autocomplete-category">' +
' <span class="uxr-autocomplete-category-head" title="{{category}}">{{category}}</span>' +
'</li>',
'<li class="uxr-autocomplete-category">' +
' <span class="uxr-autocomplete-category-head" title="{{category}}">{{category}}</span>' +
'</li>',
item: '' +
'<li class="uxr-autocomplete-list-item">' +
' <a {{#if url}}href="{{url}}"{{/if}}>' +
' {{{name}}}' +
' </a>' +
'</li>'
'<li data-id="{{id}}" class="uxr-autocomplete-list-item">' +
' <a {{#if url}}href="{{url}}"{{/if}}>' +
' {{{name}}}' +
' </a>' +
'</li>'
},
tree : {
head: '' +
'<li class="uxr-autocomplete-category">' +
' <span class="uxr-autocomplete-category-head" title="{{category}}">{{category}}</span>' +
'</li>',
'<li class="uxr-autocomplete-category">' +
' <span class="uxr-autocomplete-category-head" title="{{category}}">{{category}}</span>' +
'</li>',
item: '' +
'<li class="uxr-autocomplete-list-item">' +
' <a {{#if url}}href="{{url}}"{{/if}}>' +
' <span class="item-image"><img src="{{image}}"/></span> ' +
' {{{name}}}' +
' </a>' +
'</li>'
'<li data-id="{{id}}" class="uxr-autocomplete-list-item">' +
' <a {{#if url}}href="{{url}}"{{/if}}>' +
' <span class="item-image"><img src="{{image}}"/></span> ' +
' {{{name}}}' +
' </a>' +
'</li>'
}
},
events = {
Expand Down Expand Up @@ -152,7 +158,7 @@

i++;

this.lastTerm = null;
this.lastTerm = 'as';

this.init();
};
Expand Down Expand Up @@ -198,8 +204,8 @@

handleWrapper: function() {
this.$el.parent().is('.' + ns.wrap) ?
this.$el.parent().addClass(this.classList) :
this.$el.wrap('<span class="' + this.classList + '"></span>');
this.$el.parent().addClass(this.classList) :
this.$el.wrap('<span class="' + this.classList + '"></span>');
},

addIcon: function() {
Expand Down Expand Up @@ -255,7 +261,8 @@
bindUIActions: function() {
var _this = this;

_this.$el.on(events.keyup + ' ' + events.input, function(e) {

_this.$el.on(events.keyup + ' ' + events.input, utils.debounce(function(e) {
var val = $(this).val(),
_length = val.length;

Expand All @@ -266,7 +273,7 @@
if(_length === 0) {
_this.hideContainer();
}
});
},_this.options.debounce));

_this.$el.on(events.blur, function() {
_this.onBlur();
Expand All @@ -291,12 +298,17 @@
this.setValue(selected);
this.hideContainer();

utils.callback(this.options.onSelect(selected));
utils.callback(this.options.onSelect);
},

setValue: function(selected) {

var text = selected.text().trim();

if(this.options.hidden){
$(this.options.hidden).val(selected.data('id'));
}

if(text === '') {
text = this.lastTerm;
}
Expand All @@ -316,6 +328,8 @@
else if(e.keyCode === keys.return) {
if(this.$list.is(':visible')) {
this.select(this.$list.find('.' + utils.getClassname('highlight')));


}
}

Expand All @@ -329,6 +343,7 @@
}
},


onBlur: function() {
var _this = this;

Expand Down Expand Up @@ -383,18 +398,29 @@
else {
this.source = function() {
var fdata = _this.serializeForm();
var obj = {
type : this.options.type,
formdata: fdata
};
obj[this.options.searchTerm] = this.lastTerm;

var prop;


$.ajax({
url : source,
dataType: 'json',
type : this.options.queryType,
data : {
term : this.lastTerm,
type : this.options.type,
formdata: fdata
},
data : obj,
success : function(data) {
var items = data.itemList || data;

if(_this.options.customProp){
prop = data[_this.options.customProp];
}else{
prop = data;
}

var items = data.itemList || prop;

_this.showResults(items);
}
Expand Down Expand Up @@ -591,11 +617,26 @@

getClassname: function(which) {
return ns.prefix + ns.name + '-' + ns.classes[which];
},

debounce : function (func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}
};


ux = $.fn.autocomplete = $.fn.uxrautocomplete = $.uxrautocomplete = function(options) {
ux = $.fn.autocomplete = $.fn.uxrautocomplete = $.fn.uxitdautocomplete = $.uxrautocomplete = function(options) {
var selector = this.selector;

return this.each(function() {
Expand Down Expand Up @@ -687,7 +728,7 @@
};

// version
ux.version = '2.0.3';
ux.version = '2.0.4';

// default settings
ux.settings = defaults;
Expand Down
2 changes: 1 addition & 1 deletion dist/uxrocket.autocomplete.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fb9a33c

Please sign in to comment.