Actualiza el plugin Additionals a 3.0.2-master
This commit is contained in:
parent
3b6a41320c
commit
cfa0d58b18
164 changed files with 2027 additions and 58190 deletions
|
@ -32,3 +32,61 @@ function formatFontawesomeText(icon) {
|
|||
return icon.text;
|
||||
}
|
||||
}
|
||||
|
||||
/* exported observeLiveSearchField */
|
||||
function observeLiveSearchField(fieldId, targetId, target_url) {
|
||||
$('#'+fieldId).each(function() {
|
||||
var $this = $(this);
|
||||
$this.addClass('autocomplete');
|
||||
$this.attr('data-search-was', $this.val());
|
||||
var check = function() {
|
||||
var val = $this.val();
|
||||
if ($this.attr('data-search-was') != val){
|
||||
$this.attr('data-search-was', val);
|
||||
|
||||
var form = $('#query_form'); // grab the form wrapping the search bar.
|
||||
var formData;
|
||||
var url;
|
||||
|
||||
form.find('[name="c[]"] option').each(function(i, elem) {
|
||||
$(elem).attr('selected', true);
|
||||
});
|
||||
|
||||
if (typeof target_url === 'undefined') {
|
||||
url = form.attr('action');
|
||||
formData = form.serialize();
|
||||
} else {
|
||||
url = target_url;
|
||||
formData = { q: val };
|
||||
}
|
||||
|
||||
form.find('[name="c[]"] option').each(function(i, elem) {
|
||||
$(elem).attr('selected', false);
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'get',
|
||||
data: formData,
|
||||
success: function(data){ if(targetId) $('#'+targetId).html(data); },
|
||||
beforeSend: function(){ $this.addClass('ajax-loading'); },
|
||||
complete: function(){ $this.removeClass('ajax-loading'); }
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/* see https://stackoverflow.com/questions/1909441/how-to-delay-the-keyup-handler-until-the-user-stops-typing */
|
||||
var search_delay = function(callback) {
|
||||
var timer = 0;
|
||||
return function() {
|
||||
var context = this, args = arguments;
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(function () {
|
||||
callback.apply(context, args);
|
||||
}, 400 || 0);
|
||||
};
|
||||
};
|
||||
|
||||
$this.keyup(search_delay(check));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue