gruene-seele/public/js/shop.js
2021-11-09 18:40:18 +01:00

58 lines
1.6 KiB
JavaScript

$(function() {
$('select').selectpicker();
$('#modals-load-content').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
if (!button.data('id')) {
return;
}
var data = {};
$.each(button.data(), function(index, value){
if(index !== 'bs.tooltip'){
data[index] = value;
}
});
console.log(data);
loadModalInner(this, data);
});
function loadModalInner(self, data){
var url = data.route,
contentType = 'application/x-www-form-urlencoded; charset=UTF-8';
$.ajax({
url: url,
data: data,
type: "POST",
dataType: "json",
cache: false,
contentType: contentType,
encode: true,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function(data) {
console.log(data);
if(data.response.modal){
$(data.response.target).find('.modal-dialog').addClass(data.response.modal);
}
$(data.response.target).find('.modal-dialog').html(data.html);
//$(data.response.target).find('.selectpicker').selectpicker('refresh');
},
error: function(xhr, status, errorThrown) {
console.log(xhr);
console.log(xhr.responseText);
console.log(errorThrown);
console.log("Sorry, there was a problem!");
}
});
return false;
}
});
function _scrollTo(to, offset) {
$('html,body').animate({scrollTop: $(to).offset().top - offset}, 800);
}