// Left menu
if(Modernizr.touch){
var leftcatalog = new Swiper('.menublock', {
prevButton: '.menublock .backlink a',
spaceBetween: 0,
slidesPerView: 1,
// disable touch slide
simulateTouch: false,
shortSwipes: false,
longSwipes: false,
followFinger: false,
});
// LEVEL1 BRANCH
$(document).on('click','.leftside .level1 .branch',function(e){
// GET LEVEL2 CAPTION
var caption = $(this).text();
leftcatalog.slideTo(1);
//...
// AJAX QUERY ?
mobileMenu = $('.menublock .level1');
id = $(this).data('id');
lvl = $(this).data('lvl');
if (!id) {console.log('error'); return false}
$(this).parents('.level'+lvl).nextAll().remove();
$.ajax({
url: 'index.php?route=api/menu',
type: 'get',
data: 'id=' + id,
dataType: 'json',
beforeSend: function() {
mobileMenu.parent().append('<ul class="level'+(++lvl)+' swiper-slide"><li class="backlink"><a href="#" data-gotostep="'+(--lvl)+'">Назад</a></li><li class="title"><a></a></li></ul>');
},
success: function(json) {
// Need to set timeout otherwise it wont update the total
setTimeout(function () {
column = mobileMenu.parent().children().last();
txt = '';
$.each(json, function(index, value){
txt += '<li><a href="'+value['link']+'" data-id='+value['id']+' data-lvl="'+(++lvl)+'">'+value['name']+'</a></li>'
});
column.html(column.html() + txt);
}, 100);
$('.level'+(++lvl)+' .title').text(caption);
setTimeout(function () {
leftcatalog.update();
leftcatalog.attachEvents();
}, 100);
leftcatalog.slideNext();
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
//...
e.preventDefault();
});