var produtos; var categorias; //function showPop(id, lista, title, img){ function showPop(i){ $.mobile.loading( "show", { text: "Carregando...", textVisible: "Carregando..." }); prod = produtos[i]; title = prod.marca+" - "+prod.produto; lista = prod.lista; classificacao = prod.classificacao; if(classificacao.length>0){ classif = classificacao.toLowerCase(); if(classif.indexOf("chalav")!=-1){ classificacao = "
Classificação: "+classificacao+""; }else{ classificacao = "
Classificação: "+classificacao+""; } } descricao = prod.descricao; if(descricao.length>0){ descricao = "
Nota: "+descricao+""; } brachaant = prod.brachaant; if(brachaant.length>0){ brachaant = "
Brachá Anterior: "+brachaant+""; } brachapos = prod.brachapos; if(brachapos.length>0){ brachapos = "
Brachá Posterior: "+brachapos+""; } id = prod.id; //alert(prod.marca); img = prod.imagem; id = id+lista; img = img.replace("/thumbs/","/reais/"); img = img.replace("/dyn_images/peq","/dyn_images/gde"); selo = ""; if(prod.selo=="1"){ selo = "
Produto com Selo de Supervisão BDK"; } closebtn = 'Close'; header = '';//

' + title + '

'; img = '
' + title + '
'; img += '
 
'; //html = '
'; //style="font-size:.8em;" html = '

'+prod.marca+"
"+prod.produto+'
'; html += ''+prod.categoria+''+classificacao+selo+brachaant+brachapos+'

'; img += html; popup = ''; // Create the popup. $( header ) .appendTo( $( popup ) .appendTo( $.mobile.activePage ) .popup() ) .toolbar() .before( closebtn ) .after( img ); // Wait with opening the popup until the popup image has been loaded in the DOM. // This ensures the popup gets the correct size and position $( ".photo", "#popup-" + id ).load(function() { // Open the popup $( "#popup-" + id ).popup( "open" ); // Clear the fallback clearTimeout( fallback ); }); // Fallback in case the browser doesn't fire a load event var fallback = setTimeout(function() { $( "#popup-" + id ).popup( "open" ); $.mobile.loading( "hide" ); }, 1000); // Set a max-height to make large images shrink to fit the screen. $( document ).on( "popupbeforeposition", ".ui-popup", function() { var image = $( this ).children( "img" ), height = image.height(), width = image.width(); // Set height and width attribute of the image $( this ).attr({ "height": height, "width": width }); // 68px: 2 * 15px for top/bottom tolerance, 38px for the header. var maxHeight = $( window ).height() - 68 + "px"; $( "img.photo", this ).css( "max-height", maxHeight ); }); // Remove the popup after it has been closed to manage DOM size $( document ).on( "popupafterclose", ".ui-popup", function() { $( this ).remove(); $('#dataProducts').listview("refresh"); $('#dataProducts').trigger("updatelayout"); }); } $(document).ready(function(){ ({ getproducts : function(){ $('#product').blur(); $('#dataProducts').focus(); product = $('#product').val(); //list = $('input[name=kosherlist]:checked', '#frmFind').val(); list = ""; if( $('#check-bka').is(':checked') ){ if(list!="") list += ","; list += "'bka'"; } if( $('#check-bdk').is(':checked') ){ if(list!="") list += ","; list += "'bdk'"; } if( $('#check-lkb').is(':checked') ){ if(list!="") list += ","; list += "'lkb'"; } if( $('#check-mekor').is(':checked') ){ if(list!="") list += ","; list += "'mekor'"; } if( $('#check-other').is(':checked') ){ if(list!="") list += ","; list += "'other'"; } html = ""; html2 = ""; if( (product.length > 2) ){ $('#dataProducts').html(html); $('#dataProducts').listview("refresh"); $('#dataProducts').trigger("updatelayout"); $('#dataCategories').html(html2); ga('send', 'pageview', "/search.php?produto="+product+"&lista="+list); $.ajax({ type: 'POST', cache: false, url: 'ajax.php', dataType: "json", data: {'product':product, 'list':list, 'action':'findproduct'}, beforeSend: function(){ $.mobile.loading( "show", { text: "Pesquisando...", textVisible: "Pesquisando..." }); }, success: function(request){ produtos = request.produtos; categorias = request.categorias; total = request.total; cat = ""; var contCat = -1; if(total==0){ html += "
  • "+request.msg+"
  • "; $("#divRodape").toolbar("option", "position", "fixed"); $("#divRodape").toolbar("refresh"); $("#divRodape").toolbar( "show" ); }else{ $.each(produtos, function ( i, val ){ prod = produtos[i]; //console.log(prod); if(cat!=prod.categoria){ contCat++; html += "
  • "+prod.categoria; html += ""+categorias[prod.categoria].qtde+"
  • "; cat = prod.categoria; } id = prod.id; lista = prod.lista; classificacao = prod.classificacao; if(classificacao.length>0){ classif = classificacao.toLowerCase(); if(classif.indexOf("chalav")!=-1){ classificacao = "
    Classificação: "+classificacao+""; }else{ classificacao = "
    Classificação: "+classificacao+""; } } descricao = prod.descricao; if(descricao.length>0){ descricao = "
    Nota: "+descricao+""; } selo = ""; if(prod.selo=="1"){ selo = "
    Produto com Selo de Supervisão BDK"; } //title = prod.marca+" - "+prod.produto; //click = "showPop(\""+id+"\", \""+lista+"\", \""+title+"\", \""+prod.imagem+"\")"; click = "showPop("+i+")"; html += "
  • "+ ""+ "
    "+prod.marca+""; if(prod.fabricante != ""){ html += " | "+ prod.fabricante + ""; } html += "
    "+ prod.produto+""+classificacao+selo+descricao+"
    "+ "
  • "; /*html += "
  • "+ ""+prod.marca+ "
    "+ prod.produto+"
    "+ "
  • ";*/ }); html2 += ""; } if(total>2){ $("#divRodape").toolbar("option", "position", "none"); $("#divRodape").toolbar("refresh"); $( "#divRodape" ).toolbar( "hide" ); } $('#dataProducts').html(html); $('#dataProducts').listview("refresh"); $('#dataProducts').trigger("updatelayout"); $("#dataCategories").html(html2); $('#dataCategories').controlgroup("refresh", true); $("#dataCategories").enhanceWithin().controlgroup("refresh"); $('#selCat').on('change', function(){ sel = $( "#selCat" ).val(); $('html, body').animate({ scrollTop: $("#category"+sel).offset().top-200 }, 1000); }); }, error: function(erro){ //$("#popupError").popup("open"); }, complete: function(){ $.mobile.loading( "hide" ); }, }); } else { //$("#popupLenght").popup("open"); } }, init : function(){ var callgetproducts = this.getproducts; $(".ui-input-clear").on("click", function() { html = ""; $('#dataProducts').html(html); $('#dataProducts').listview("refresh"); $('#dataProducts').trigger("updatelayout"); $("#dataCategories").html(html); }); $('#frmFind').on('submit', function(){ callgetproducts(); return false; }); $('#btnOK').on('click', function(){ callgetproducts(); return false; }); $('#product').focus(); } }).init(); });