mivita/public/js/dc-filter.js
Kevin Adametz bfa3bb1df4 08 2024
2024-08-05 12:05:24 +02:00

149 lines
4.5 KiB
JavaScript

/**
* Theme: Minton Admin Template
* Author: Coderthemes
* Nestable Component
*/
!function($) {
"use strict";
var DCFilter = function() {};
var tagId = {};
var lozadObserver;
DCFilter.prototype.update = function (e) {
var $select = e.length ? e : $(e.target);
var $val = $select.val();
$('.category-filter').each(function(){
var $this = $(this);
var $id = $this.attr('id');
var $val = $this.val();
if($val){
tagId[$id] = $val;
}else{
delete tagId[$id];
}
});
$.DCFilter.loadContent();
},
/*DCFilter.prototype.update = function (e) {
var btn = e.length ? e : $(e.target),
id = btn.data('id');
if(btn.hasClass('active')){
btn.removeClass('active');
delete tagId[id];
}else{
btn.addClass('active');
tagId[id] = id;
}
$.DCFilter.loadContent()
},*/
/*DCFilter.prototype.collapse = function () {
$('#tag_search_holder .collapse')
.on('shown.bs.collapse', function() {
Cookies.set('DCFilter-'+$(this).attr('id'), 'show');
console.log($(this).attr('id'));
})
.on('hidden.bs.collapse', function() {
Cookies.remove('DCFilter-'+$(this).attr('id'));
console.log($(this).attr('id'));
});
},*/
//init
DCFilter.prototype.init = function() {
// this.collapse();
lozadObserver = lozad('.lozad', {
threshold: 0.1,
enableAutoReload: true,
load: function(el) {
el.src = el.getAttribute("data-src");
/* el.onload = function() {
toastr["success"](el.localName.toUpperCase() + " " + el.getAttribute("data-index") + " lazy loaded.")
}*/
}
});
lozadObserver.observe();
},
DCFilter.prototype.initSearch = function(){
if(!$('#dcformfilter').length){
return;
}
$('#dcformfilter').submit(function(e){
e.preventDefault();
});
$('.category-filter').on('change', $.DCFilter.update);
$('#searchinput').keyup(function(e) {
e.preventDefault();
clearTimeout($.data(this, 'timer'));
if (e.keyCode == 13){
$.DCFilter.loadContent();
}
else{
$(this).data('timer', setTimeout($.DCFilter.loadContent, 1000));
}
});
},
//load content
DCFilter.prototype.loadContent = function(){
if(jQuery.isEmptyObject(tagId)){
tagId[0] = 0;
}
var $url = $('#dcformfilter').attr('action');
var $data = {'searchinput': $("#searchinput").val(), 'tagIds': tagId, '_token': $('meta[name=csrf-token]').attr('content'),'empty': jQuery.isEmptyObject(tagId), };
//console.log($data);
// console.log($url);
$.ajax({
headers: { 'X-CSRF-Token' : $('meta[name=csrf-token]').attr('content') },
url: $url,
type: 'POST',
cache: false,
data: $data, //see the $_token
datatype: 'html',
beforeSend: function() {
//something before send
},
success: function(data) {
console.log('success');
//console.log(data);
//success
if(data.success == true) {
$('#holder-content-files').html(data.content_files);
lozadObserver.observe();
} else {
$('#holder-content-files').html("Keine Einträge gefunden");
}
/*
$('#tag_search_holder').html(data.content_filter);
$('.tag_search_btn').on('click', $.DCFilter.update);
$.DCFilter.collapse()
*/
},
error: function(xhr,textStatus,thrownError) {
console.log(xhr);
console.log(textStatus);
console.log(thrownError);
}
});
}
//init
$.DCFilter = new DCFilter, $.DCFilter.Constructor = DCFilter
}(window.jQuery),
//initializing
function($) {
"use strict";
$.DCFilter.init();
$.DCFilter.initSearch();
}(window.jQuery);