// load scripts for replaced elements var isExecuteLoad = false; document.addEventListener('swup:pageView', function(e) { $( document ).trigger('inizialize'); if (isExecuteLoad) { $( document ).trigger('executeReady'); $( window ).trigger('load'); } else { $('.transition-fade').addClass('finished'); } isExecuteLoad = true; }); document.addEventListener('swup:transitionStart', function(e) { $('.transition-fade').removeClass('finished'); $(document).trigger('removeEvent'); }); document.addEventListener("swup:transitionEnd", function(e){ $('.transition-fade').addClass('finished'); }); $.fn.isInViewport = function(offset) { var $el = $(this); if (offset === undefined) offset = 50; var elementTop = $el.offset().top; var elementBottom = elementTop + ($el.outerHeight() * offset / 100); var viewportHeight = $(window).height(); var viewportToll = 15; var viewportTop = $(window).scrollTop() - viewportToll; var viewportBottom = viewportTop + viewportHeight + (viewportToll * 2.0); if (offset < 0) return elementTop < viewportBottom && elementBottom < viewportBottom; else { return elementBottom >= viewportTop && elementTop < viewportBottom && elementBottom < viewportBottom; } }; var loadScript = function (path) { var result = $.Deferred(); var script = document.createElement("script"); script.async = "async"; script.type = "text/javascript"; script.src = path; script.onload = script.onreadystatechange = function(_, isAbort) { if (!script.readyState || /loaded|complete/.test(script.readyState)) { if (isAbort) result.reject(); else result.resolve(); } }; script.onerror = function () { result.reject(); }; $("head")[0].appendChild(script); return result.promise(); } function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie.replace(/\+/g, ' ')); var ca = decodedCookie.split(';'); for(var i = 0; i ') }); $('.clm-recaptcha').each(function( index ) { recaptcha_form = $(this).closest("form"); // recupera la callback success per il recaptcha di google del form, // se non esiste mette quella di default if (recaptcha_form.data('gcallback') === undefined) gcallback = onSuccessRecaptcha; else gcallback = window[recaptcha_form.data('gcallback')]; // render il recaptcha clmrecaptchaID[index] = this.id; clmrecaptchaFunc[index] = grecaptcha.render(this.id, { 'sitekey' : '6LdCVlIUAAAAADto-Gm3B4Uf-fHfsZubURCVz5D9', 'callback' : gcallback, 'error-callback' : onErrorRecaptcha, 'size' : 'invisible' }); }); }; function adsBlocked(callback){ var testURL = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js' var myInit = { method: 'HEAD', mode: 'no-cors' }; try { var myRequest = new Request(testURL, myInit); fetch(myRequest).then(function(response) { return response; }).then(function(response) { callback(false) }).catch(function(e){ callback(true) }); } catch (e) { callback(false) }; } $(window).on("load", function() { var policyCookie = getCookie('policyCookie'); if (policyCookie == "0") { $('#cookie_third').hide(); } if (policyCookie == "") { $('.cookie-btn-erase').hide(); } var lang = getCookie('lang'); $('form input, form select, form textarea, form button').bind('focus.recaptcha', function() { loadScript("https://www.ravanini.com/js/recaptcha.js.php").then(function() { var googleRecaptcha = document.createElement("script"); googleRecaptcha.src = "https://www.google.com/recaptcha/api.js?hl="+lang+"&onload=onloadCallback&render=explicit"; googleRecaptcha.async = true; googleRecaptcha.defer = true; document.body.appendChild(googleRecaptcha); adsBlocked(function(blocked){ var exdate = new Date() var n = document.location.hostname.split("."); var e = n.slice(1).join("."); exdate.setDate(exdate.getDate() + 1) var value = 0; if (blocked) value = 1; document.cookie = "adblock=" + escape(value) + ";path=/;expires="+exdate.toGMTString(); }) }); $('form input, form select, form textarea, form button').unbind('focus.recaptcha'); }); }); lazyExecute = function(el) { $(el).lazy({ delay:-1, afterLoad: function(element) { $.event.trigger({ type: "lazyAfterLoad", time: new Date(), element : element }); $(window).trigger('resize'); }, onFinishedAll: function() { $.event.trigger({ type: "lazyComplete", time: new Date() }); $(window).trigger('resize'); } }); } $(window).on('load', function() { $('.lazy').each(function() { if ($(this).closest('.waitLazyLoad').length == 0) { lazyExecute(this); } }); }); // lunghezza calcolata al caricamento della pagina e ad ogni resize della schermata var actualWidth; $( document ).ready(function() { $(document).trigger('executeReady'); }); $( document ).on('executeReady', function() { $(document).on('change', '[type="radio"]', function() { var name = $(this).attr('name'); $('[name="'+name+'"]').removeAttr('required'); }); $("#bottom-to-top").click(function() { $("html, body").animate({ scrollTop: 0 }, "slow"); return false; }); $('[data-toggle="tooltip"]').tooltip(); $( ".table" ).each(function( index ) { if (!$(this).parent().hasClass("table-responsive")) { $(this).wrap( "
" ); } }); $('.carousel').carousel(); $('.modal').modal('hide'); $('.dropdown-submenu > a').on("click", function(e) { e.preventDefault(); var submenu = $(this); var isShow = submenu.next('.dropdown-menu').hasClass('show'); $('.dropdown-submenu .dropdown-menu').removeClass('show'); if (!isShow) { submenu.next('.dropdown-menu').addClass('show'); } e.stopPropagation(); }); $('.dropdown').on("hidden.bs.dropdown", function() { // hide any open menus when parent closes $('.dropdown-menu.show').removeClass('show'); }); //One Animated /* var is_iOS = ( /iPhone|iPad|iPod/i.test(navigator.userAgent) ); // le animazioni waypoint laterali estendono la pagina causando problemi di visualizzazione nei sistemi operativi IOS // le animazioni waypoint disabilitate if(is_iOS) { $('.animated').css("opacity", "1"); } else { */ $('.animated:not([data-delay],[data-order])').each(function() { var element = this.element; if (element === undefined) $element = $(this); else $element = $(element); var offset = $element.data('offset'); if (typeof offset === 'undefined') offset = 80; var context = window; var horizontal = false; var data_context = $element.data('context'); if (data_context !== undefined) { context = document.getElementById(data_context) horizontal = true; } $(this).waypoint(function() { var element = this.element; if (element === undefined) $element = $(this); else $element = $(element); var myAnimated = $element.data('animated'); var oneSomeAnimated = $element.data('oneanimated'); // animazione da eseguire una singola volta if (oneSomeAnimated == true) { // animazione non e' stata gia' eseguita in tal caso la esegue if (!($element.hasClass(myAnimated))) $element.toggleClass($element.data('animated')).css("opacity", "1"); // animazione da eseguire sempre } else $element.toggleClass($element.data('animated')); }, { offset: offset+'%', context: context, horizontal: horizontal, }); }); $('.animated[data-order="0"]').each(function() { var element = this.element; if (element === undefined) $element = $(this); else $element = $(element); var offset = $element.data('offset'); if (typeof offset === 'undefined') offset = 80; var context = window; var horizontal = false; var data_context = $element.data('context'); if (data_context !== undefined) { context = document.getElementById(data_context) horizontal = true; } $(this).waypoint(function() { var element = this.element; if (element === undefined) $element = $(this); else $element = $(element); if ($element.hasClass('execute')) return; var myAnimated = $element.data('animated'); var group = $element.data('group'); $element.addClass("execute").addClass($element.data('animated')).css("opacity", "1"); $('[data-group="'+group+'"]').each(function( index ) { var el = $(this); var delay = el.data('delay') * el.data('order'); setTimeout( function() { el.addClass("execute").addClass(el.data('animated')).css("opacity", "1"); }, delay, el); }); }, { offset: offset+'%', context: context, horizontal: horizontal, }); }); $('.animated[data-delay="0"]').each(function() { var element = this.element; if (element === undefined) $element = $(this); else $element = $(element); var offset = $element.data('offset'); if (typeof offset === 'undefined') offset = 80; var context = window; var horizontal = false; var data_context = $element.data('context'); if (data_context !== undefined) { context = document.getElementById(data_context) horizontal = true; } $(this).waypoint(function() { var element = this.element; if (element === undefined) $element = $(this); else $element = $(element); if ($element.hasClass('execute')) return; var myAnimated = $element.data('animated'); var group = $element.data('group'); $element.addClass("execute").addClass($element.data('animated')).css("opacity", "1"); $('[data-group="'+group+'"]').each(function( index ) { var el = $(this); var delay = el.data('delay'); setTimeout( function() { el.addClass("execute").addClass(el.data('animated')).css("opacity", "1"); }, delay, el); }); }, { offset: offset+'%', context: context, horizontal: horizontal, }); }); /* } */ // Effect input $(document).on("blur", 'form input, form textarea, form select', function(){ if($(this).val().length !== 0) { $(this).addClass('filled'); } else { $(this).removeClass('filled'); } }); }); // Inizializza l'effetto input function init_form(form_id) { $.each($('input, textarea, select', '#'+form_id),function(e){ if($(this).val().length !== 0) { $(this).addClass('filled'); } else { $(this).removeClass('filled'); } }) } var sendVirtualEvent = function(eventForce, eventItem) { if (eventForce === undefined) eventForce = ""; if (eventItem === undefined) eventItem = null; $.post({ url: "https://www.ravanini.com/admin/includes/ajax/ajax_frontend.php", data: { "type": "sendVirtualEvent", "url" : window.location.href, "lang" : getCookie('lang'), "eventForce" : eventForce, "eventItem" : eventItem, } }) .done(function(data ) { datiJSON = JSON.parse(data); if (datiJSON.event != "") { window.dataLayer.push({ event: datiJSON.event, event_name: datiJSON.event_name, item: datiJSON.item, }); } }); } WebFontConfig = { custom: { families: [ 'FontAwesome' ], urls: [ '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'] } }; (function() { var wf = document.createElement('script'); wf.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js'; wf.type = 'text/javascript'; wf.async = 'true'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(wf, s); })(); /** ESEMPIO PER UTILIZZO SLIDE // ID della slide // | $( "#slide-example" ).slide_carousel({ element : '.example-item', // elemento contenuto nel carousel breakpoint : [ // numero di elementi e righe in base alla risoluzione // >risoluzione minima // | numero di items // | | numero di righe // | | | [ 1199, 3, 1], [ 768, 2, 1], [ 0, 1, 1] ] }); ***/ $( "#slide" ).slide_carousel({ element : '.slide-item', breakpoint : [ // >risoluzione minima // | numero di items // | | numero di righe // | | | [ 0, 1, 1] ] }); $( "#slide_shop" ).slide_carousel({ element : '.shop-slide-item', // elemento contenuto nel carousel breakpoint : [ // numero di elementi e righe in base alla risoluzione // >risoluzione minima // | numero di items // | | numero di righe // | | | [ 1199, 3, 1], [ 480, 2, 1], [ 0, 1, 1] ] }); /** ESEMPIO PER L'UTILIZZO DELLE IMMAGINI ADATTATIVE // indicare la classe delle immagini $( ".img-adapter-4-3" ).imgadapter({ w_prop : 4, // proporzione per la lunghezza h_prop : 3, // proporzione per l'altezza outer_div : true, // true: non è richiusa all'interno del wrapper, false è rinchiusa all'interno del wrapper breakpoint : [ // risoluzioni in cui ricalcolare il rapporto // >min-width [ 1400], [ 1200], [ 768], [ 480], [ 0] ] }); ***/ // immagini adattative all'interno del riquadro $( ".img-adapter-in-4-3" ).imgadapter({ w_prop : 4, h_prop : 3, outer_div : false }); $( ".img-adapter-in-1-1" ).imgadapter({ w_prop : 1, h_prop : 1, outer_div : false }); // immagini adattative all'esterno del riquadro $( ".img-adapter-16-9" ).imgadapter({ w_prop : 16, h_prop : 9 }); $( ".img-adapter-4-3" ).imgadapter({ w_prop : 4, h_prop : 3 }); $( ".img-adapter-1-1" ).imgadapter(); /** ESEMPIO PER L'UTILIZZO DELLA GALLERY // indicare la gallery $( ".simple-gallery-no-slide" ).gallery({ w_prop : 4, // proporzione per la lunghezza h_prop : 3, // proporzione per l'altezza outer_div : true, // true: non è richiusa all'interno del wrapper, false è rinchiusa all'interno del wrapper breakpoint : [ // percentuali da applicare in base alla larghezza minima della pagina // >min-width // | width % // | | margin px // | | | [ 768, 33, 15], [ 480, 50, 15], [ 0, 100, 15] ] }); */ /** ESEMPIO PER L'UTILIZZO DELLA GALLERY CON SLIDE $( "#slide-gallery" ).slide_gallery({ element : '.gallery-item', w_prop : 4, // proporzione per la lunghezza h_prop : 3, // proporzione per l'altezza outer_div : true, // true: non è richiusa all'interno del wrapper, false è rinchiusa all'interno del wrapper breakpoint : [ // >risoluzione minima // | numero di items // | | numero di righe // | | | margin px // | | | | [ 1199, 3, 1, 10], [ 480, 2, 1, 10], [ 0, 1, 1, 10], ] }); **/ $( "#slide-gallery" ).slide_gallery({ element : '.gallery-item', w_prop : 1, // proporzione per la lunghezza h_prop : 1, // proporzione per l'altezza outer_div : false, // true: non è richiusa all'interno del wrapper, false è rinchiusa all'interno del wrapper breakpoint : [ // >risoluzione minima // | numero di items // | | numero di righe // | | | margin px // | | | | [ 0, 1, 1, 20], ] }); // margine applicato 15px $( ".simple-gallery-no-slide" ).gallery({ w_prop : 1, // proporzione per la lunghezza h_prop : 1, // proporzione per l'altezza outer_div : false, // true: non è richiusa all'interno del wrapper, false è rinchiusa all'interno del wrapper breakpoint : [ // percentuali da applicare in base alla larghezza minima della pagina // >min-width // | width % // | | margin px // | | | [ 992, 33, 5], [ 768, 50, 5], [ 480, 50, 15], [ 0, 100, 15] ] }); $( document ).ready(function() { $('#toggle').click(function() { $(this).toggleClass('active'); $('#overlay').toggleClass('open'); }); $(".overlay > .overlay-menu > ul > li").each(function(index){ if (index > 0) { $(this).css({'-webkit-animation-delay' : (0.15*(1+index))+'s', 'animation-delay' : (0.15*(1+index))+'s'}); } }); $(".overlay .dropdown-menu > li").each(function(index){ if (index > 0) $(this).css({'-webkit-animation-delay' : (0.15*(1+index))+'s', 'animation-delay' : (0.15*(1+index))+'s'}); else $(this).css({'-webkit-animation-delay' : '0s', 'animation-delay' : '0s'}); }); //************************************************** // LOGIN / LOGOUT //************************************************** $( '.logout' ).click(function() { $.ajax({ type: "POST", url: 'https://www.ravanini.com/admin/includes/ajax/ajax_frontend.php', data: { type: "logout" }, context: this, dataType: 'text' }) .done(function(data){ location.reload(); }); }); }); // i formati supportati dal browser var supported = { date: false, number: false, time: false, month: false, week: false }; $(window).load(function() { var lang = getCookie('lang'); // determina i formati supportati dal browser var tester = document.createElement('input'); for (var i in supported) { tester.setAttribute('type',i) tester.value = ':('; if (tester.type === i && tester.value === '') { supported[i] = true; } } $( ".cmsdate" ).each(function() { var el = $(this); if (!supported.date) { el.addClass("datepicker"); el.datepicker({ language : lang, autoclose : true, disableTouchKeyboard : true }); } }); $( ".cmsdate" ).focus(function() { var el = $(this); if (supported.date && el[0].type !== 'date') { el[0].type = 'date'; } }); $( ".cmstime" ).each(function() { var el = $(this); if (!supported.time) { el.timepicker({ showMeridian: false, defaultTime : false }); } }); $( ".cmstime" ).focus(function() { var el = $(this); if (supported.time && el[0].type !== 'time') { el[0].type = 'time'; } }); $('#shop-category-btn-bottom').click(function() { $('#shop-category-box-mb').toggleClass('open'); $(this).toggleClass('open'); }); }); // lunghezza calcolata al caricamento della pagina e ad ogni resize della schermata var lastWidth; // larghezza usata per il cambio di posizione del search_box var width_change_search_box_position = 766; // sposta il box della ricerca prima del corpo principale con risoluzione tablet e smartphone // di lato in modalità desktop function search_box_position() { if ($(window).width() < (width_change_search_box_position + 1)) actualWidth = width_change_search_box_position; else actualWidth = width_change_search_box_position + 1; if (lastWidth != actualWidth) { lastWidth = actualWidth; if (lastWidth == width_change_search_box_position) { var search_box = $('#search-box').detach(); $('#search-box-2').append(search_box).hide(); } else { var search_box = $('#search-box').detach(); $('#search-box-1').append(search_box); } } } $(window).resize(function() { search_box_position(); }); $( window ).load(function() { // visualizza il box di ricerca nel punto corretto if ($(window).width() < (width_change_search_box_position + 1)) { lastWidth = 10000; search_box_position(); } else { lastWidth = (width_change_search_box_position + 1); } $('#search-xs').on('click', function (e) { $('#search-box-2').toggle("slow"); }); }); // lunghezza calcolata al caricamento della pagina e ad ogni resize della schermata var shop_last_width; // larghezza usata per il cambio di posizione del search_box var shop_breakpoint = 766; // sposta elementi del modulo shop al passaggio da xs a sm e viceversa function shop_show_hide_element() { if ($(window).width() < (shop_breakpoint + 1)) shop_actual_width = shop_breakpoint; else shop_actual_width = shop_breakpoint + 1; if (shop_last_width != shop_actual_width) { shop_last_width = shop_actual_width; if (shop_last_width == shop_breakpoint) { $('#shop-category-box .title').removeClass("open"); $('#shop-category-box .list').hide(); var shop_category_box = $('#shop-category-box').detach(); $('#shop-category-box-mb').append(shop_category_box); } else { $('#shop-category-box .list').show(); var shop_category_box = $('#shop-category-box').detach(); $('#shop-category-box-dk').append(shop_category_box); } } } $(window).resize(function() { shop_show_hide_element(); }); $( window ).load(function() { // nasconde il menu delle categorie if ($(window).width() < (shop_breakpoint + 1)) { shop_last_width = 10000; shop_show_hide_element(); // visualizza il menu delle categorie } else { shop_last_width = (shop_breakpoint + 1); shop_show_hide_element(); } $('#shop-category-box .title').on('click', function (e) { $('#shop-category-box .list').toggle( "slow", "swing" ); if ($(this).hasClass("open")) $(this).removeClass("open"); else $(this).addClass("open"); }); }); function onShopSuccessRecaptcha(token){ actual_form.submit(); }; // funzioni CALLBACK per il carrello // esito positivo function shop_cart_positive_response(element, datiJSON, value_class_hide) { $( element.content ).hide(); $( element.content ).after('
'+datiJSON.positive_response+'
'); if (value_class_hide !== undefined) $('.'+value_class_hide).hide(); $.post('https://www.ravanini.com/admin/includes/ajax/ajax_frontend.php?module=shop&type=removeAll'); } // esito negativo function shop_cart_error_code(element, datiJSON, value_class_hide) { $('#upload_container_'+element.content.id).hide(); $('#shop-alert-ajax .modal-title .title').html("Avviso"); $('#shop-alert-ajax .modal-body p').html("Ordine non registrato!"); $('#shop-alert-ajax').modal('show'); setTimeout(function(){ $("#shop-alert").modal('hide') }, 5000); } // errore chiamata AJAX function shop_cart_failure(element, datiJSON, value_class_hide) { $('#upload_container_'+element.content.id).hide(); $('#shop-alert-ajax .modal-title .title').html("Avviso"); $('#shop-alert-ajax .modal-body p').html("Errore nell'invio. Riprovare più tardi.
Comunicare all'amministratore del sito le seguenti informazioni:
- Status: "+data.status+" "+textStatus+"
- Error: "+errorThrown+""); $('#shop-alert-ajax').modal('show'); setTimeout(function(){ $("#shop-alert").modal('hide') }, 5000); } // funzione di controllo function shop_cart_check(element) { var error = false; // controllo che le select delle quantità dei prodotti siano state tutte confermate, altrimenti eseguo il focus sulla prima quantità non confermata $('.qty').each( function(){ if ( !($(this).data('confirm')) ){ // debbo settare la classe per l'errore e spostare lo scroll $(this).addClass('confirm-error'); var firstQty = ($(this).offset().top); var body = $("html, body"); body.stop().animate({scrollTop: firstQty}, '500', 'swing'); error = true; return false; } }); return error; } // funzioni CALLBACK per il contatti del prodotto // esito positivo function shop_product_modal_positive_response(element, datiJSON, value_class_hide) { $( element.content ).hide(); $( element.content ).after('
'+datiJSON.positive_response+'
'); if (value_class_hide !== undefined) $('.'+value_class_hide).hide(); } function cartAction(element, prod_id, action) { var inputQty = $("#qty_" + prod_id); if ( action == 'update'){ inputQty.data('confirm', 1); } $.post('https://www.ravanini.com/admin/includes/ajax/ajax_frontend.php?module=shop&type=' + action, {id: prod_id, qty: inputQty.val() }) .done(function(data) { datiJSON = JSON.parse(data); console.log(datiJSON); if ( datiJSON.cartTotalItem != null ) { $('#cartTotalItem').html(' x ' + datiJSON.cartTotalItem); $('#cartTotalItemInput').val(datiJSON.cartTotalItem); } else { $('#cartTotalItem').html(''); $('#cartTotalItemInput').val(0); $('#listing').html("Il tuo carrello è vuoto"); } // aggiunto nuovo articolo nel carrello if ( datiJSON.action == 'add' ){ $('#shop_li_'+prod_id).addClass('act'); /* $('#shop-alert-add').modal('show'); setTimeout(function(){ $("#shop-alert-add").modal('hide') }, 5000); */ } // aggiornamento quantità singolo prodotto nel carrello if ( datiJSON.action == 'update' ){ if ( $('#qty_' + datiJSON.id).hasClass('confirm-error') ) $('#qty_' + datiJSON.id).removeClass('confirm-error'); $('#calculated_price_' + datiJSON.id).html(datiJSON.price.display); $('#input_price_' + datiJSON.id).val(datiJSON.price.value); $('#totals').html(datiJSON.totalPriceFormat); $('#input_totals').val(datiJSON.totalPrice); } // rimozione singolo prodotto dal carrello if ( datiJSON.action == 'remove' ){ var removingLines = true; $.each(datiJSON.item, function( index, value ) { if ( index == datiJSON.id ) removingLines = false; }); $('#totals').html(datiJSON.totalPriceFormat); $('#input_totals').val(datiJSON.totalPrice); $('#cartTotalProductInput').val(datiJSON.cartTotalProduct); if ( removingLines ) { $('#row-shop-' + datiJSON.id).hide('slow'); setTimeout(function(){ $('#row-shop-' + datiJSON.id).remove(); },1000); } if ( datiJSON.cartTotalItem == null ){ $('.shop_cart_hide').hide('slow'); setTimeout(function(){ $('.shop_cart_show').show(); }, 1000); } } // rimozione intero carrello if ( datiJSON.action == 'removeAll' ) { $('.shop_cart_hide').hide('slow'); $('.shop_cart_show').show(); setTimeout(function(){ $('.shop_cart_show').show(); }, 1000); } }) .fail(function(data) { $('#shop-alert-ajax .modal-title .title').html("TXT_SHOP_MODAL_TITLE_ALERT"); $('#shop-alert-ajax .modal-body p').html("Errore nell'invio. Riprovare più tardi.
Comunicare all'amministratore del sito le seguenti informazioni:
- Status: "+data.status+" "+textStatus+"
- Error: "+errorThrown+""); $('#shop-alert-ajax').modal('show'); setTimeout(function(){ $("#shop-alert").modal('hide') }, 5000); }); } window.query_cache = {}; $( document ).ready(function() { $('#user_id').change(function() { if ($(this).val() == 0) $('#user_id_none').prop('required', 'required'); else $('#user_id_none').removeProp('required'); }); $('.qtyminus').click(function() { var qty = $("#qty_" + $(this).data("id")); var qty_val = parseInt(qty.val()); if (qty_val > 1) qty.val(qty_val - 1); if ($(this).data("action") !== undefined) cartAction(this, $(this).data("id"), $(this).data("action")); }); $('.qtyplus').click(function() { var qty = $("#qty_" + $(this).data("id")); var qty_val = parseInt(qty.val()); qty.val(qty_val + 1); if ($(this).data("action") !== undefined) cartAction(this, $(this).data("id"), $(this).data("action")); }); $('.cart').click(function(e) { e.preventDefault(); cartAction(this, $(this).data("id"), $(this).data("action")); }); // use this hash to cache search results $('#search').typeahead({ source:function(query,process){ // if in cache use cached value, if don't wanto use cache remove this if statement /* if(query_cache[query]){ process(query_cache[query]); return; } */ if( typeof searching != "undefined") { clearTimeout(searching); process([]); } searching = setTimeout(function() { return $.getJSON( "https://www.ravanini.com/admin/includes/ajax/ajax_frontend.php?module=shop&type=typeahead", { q:query }, function(data){ // save result to cache, remove next line if you don't want to use cache //query_cache[query] = data; // only search if stop typing for 300ms aka fast typers return process(data); } ); }, 300); // 300 ms } }); });