globals = { rootdir: '', elements: '', selectedObj: '' } globals.rootdir = ''; globals.selectedObj = new Array(); $(document).ready( function(){ $('#carousel').carousel({ interval: 7000 }) //Prevengo che la pressione dell'invio faccia il submit del form (serve nel codice sconto nel carrello) $(window).keydown(function(event){ if(event.keyCode == 13) { event.preventDefault(); return false; } }); // validate signup form on keyup and submit if( document.getElementById("contact") ){ $("#contact").validate({ rules: { nome: "required", telefono: "required", email: { required: true, email: true }, testo: "required", privacy: "required" }, messages: { nome: "Inserisci il tuo nome e cognome", telefono: "Inserisci il tuo numero di telefono", email: "Inserisci il tuo indirizzo email", testo: "Inserisci il testo del messaggio", privacy: "Devi accettare il trattamento dei dati personali" } }); } //order form if( document.getElementById("form_order") ){ $("#form_order").validate({ rules: { nome: "required", cognome: "required", indirizzo: "required", citta: "required", provincia: "required", cap: "required", nazione: "required", telefono: "required", email: { required: true, email: true } }, messages: { nome: "Inserisci il tuo nome", cognome: "Inserisci il tuo cognome", indirizzo: "Inserisci il tuo indirizzo", citta: "Inserisci la tua citta'", provincia: "Inserisci la tua provincia", cap: "Inserisci il tuo cap", nazione: "Inserisci la tua nazione", telefono: "Inserisci il tuo numero di telefono", email: "Inserisci il tuo indirizzo email" } }); } //Toggle sulla popup utente al click sul + $('#ordine>div.clickable').click( function(){ if( parseInt($('#ordine').css('top'))=='0' ){ $('#ordine').stop().animate({ 'top': -280 }); $(this).text('Mostra profilo utente'); } else{ $('#ordine').stop().animate({ 'top': 0 }); $(this).text('Nascondi profilo utente'); } }); //Al click sul + apro la popup utente $('.add').click( function(){ if( parseInt($('#ordine').css('bottom'))=='-280' ){ $('#ordine').stop().animate({ 'bottom': 0 }); $('#ordine>div.clickable').text('Mostra profilo utente'); } }); $('[data-href]').click( function(){ launch_modal( $(this).data('title'), $(this).data('href') ); }); $('#popup').on('shown.bs.modal', function(){ $(".modal-body").css( "max-height", $(window).height() - 120 ); }); $('#popup').on('hidden.bs.modal', function(){ $(this).data('modal', null); }); $(".only_digits").keyup (function (){accept_only_integer( $(this) );}); $('.fancybox').each( function(){ $(this).on('click', function(e){ e.preventDefault(); launch_modal_img( $(this).attr('href') ); }); }); setInterval( "dots_anim();", 200 ); $('table').wrap("
"); /** * Nascondo/mostro il tasto di ordine nei casi in cui c'è una combinazione da scegliere */ setInterval( function(){ if( $('#prezzo-text').text() == '...' ){ selecteds = 0; select_totali = $('select[name*=attributo_]').length; input_totali = $('input[name*=attributo_]').length; campi_totali = select_totali + input_totali; //Mostro il tasto di avanzamento solo se ho selezionato delle opzioni $('select[name*=attributo_] option:selected').each( function(){ valore = $(this).val(); if( valore != '' ){ selecteds++; } }); if( selecteds == campi_totali ){ $('#btn-order').show(); } else { $('#btn-order').hide(); } } else { $('#btn-order').show(); } }, 500 ); }); //Puntini caricamento function dots_anim(){ if( $('#dots').html()==' ' ) $('#dots').text('.'); else if( $('#dots').text()=='.' ) $('#dots').text('..'); else if( $('#dots').text()=='..' ) $('#dots').text('...'); else if( $('#dots').text()=='...' ) $('#dots').html(' '); } function getCurrentPage( url ){ page = url; re = /(.+)\/(.+)$/g; complete_url = page.replace(re,"$2"); //tolgo il parametro lang re = /(.+)&lang=[a-z]{2}/g; complete_url = complete_url.replace( re, "$1" ); complete_url = complete_url.replace( /#.*/, '' ); return complete_url; } function qty_add( el, price, q ){ thisq = parseInt( el.val() ); newq = thisq+q; if( newq > 0 && newq<1000 ){ el.val( thisq+q ); subtot = price*newq; $('#totale').html( subtot.toFixed(2).replace('.', ',')+" €" ); } } function check_form( formid ){ return false; } // Funzione per forzare valori numerici con la virgola o il punto function accept_only_integer(jSelector) { var x = jSelector.val(); var numero = x.replace(/[^0-9-'.'-',']/g,""); if( numero=='' ) numero = 1; jSelector.attr('value', numero); } //Verifica che tutti i campi dell'ordine siano stati compilati, altrimenti mostra un avviso function check_order(){ ok = true; //Check attributi $('[name*=attributo_]').each( function(){ if( $(this).is('select') ){ if( $(this).find('option:selected').val()=='' ){ ok = false; } } else{ if( $(this).val()=='' ){ ok = false; } } }); if( !ok ){ alert( "Devi compilare tutte le caratteristiche del prodotto!" ); return false; } if( !ok ){ return false; } return true; } //Verifica se i campi selezionati con il selettore "selector" sono stati compilati e ritorna true, altrimenti ritorna false function check_mandatory( selector ){ check = true; $(selector).each( function(){ if( $(this).val()=='' ) check = false; }); return check; } /** * Carica la maschera di ritaglio dato il numero di maschera (1 o 2) e il file png da sovrapporre * Specifico anche l'orientamento dell'immagine caricata (P (portrait) o L (landscape)) */ function load_mask( idx, filename_p1, filename_p2, orientation, w, h, wmask, hmask, opts ){ //Carico i vari file che fungono da maschere $('#mask'+idx).append( "
" ); $('#overlay'+idx).load( function(){ $('#uploading-overlay').hide(); //Centro la maschera caricata in mezzo al workspace $('#overlay'+idx+'_fg').css( 'left', $('#workspace'+idx).width()/2 - $('#overlay'+idx+'_fg').width()/2 + 3 ); $('#overlay'+idx+'_fg').css( 'top', ( $('#workspace'+idx).height()/2 - $('#overlay'+idx+'_fg').height()/2 ) + 2 ); img_ratio = $('#custom'+idx).width() / $('#custom'+idx).height(); if( $('#overlay'+idx+'_fg').width() < $('#overlay'+idx+'_fg').height() ){ //Se l'immagine supera in altezza la maschera, la scalo if( $('#custom'+idx).height() > h ){ w_max = $('#custom'+idx).width() / $('#custom'+idx).height() * h; } //Se l'immagine supera in larghezza la maschera, la scalo if( $('#custom'+idx).width() > w ){ w_max = w; } else{ w_max = w; } } else{ //Se l'immagine supera in larghezza la maschera, la scalo if( $('#custom'+idx).width() > w ){ w_max = w; } //Se l'immagine supera in altezza la maschera, la scalo if( $('#custom'+idx).height() > h ){ w_max = $('#custom'+idx).width() * h / $('#custom'+idx).height(); } else{ w_max = w; } } //Adattamento foto a maschera new_w = w_max; new_h = w_max/$('#custom'+idx).width() * $('#custom'+idx).height(); $('#custom'+idx).width( w_max ).attr('data-width'+idx, new_w); $('#custom'+idx).height( new_h ).attr('data-height'+idx, new_h); $('input[name=data-width'+idx+']').val( new_w ); $('input[name=data-height'+idx+']').val( new_h ); $('#custom'+idx).css('left', $('#workspace'+idx).width()/2 - $('#custom'+idx).width()/2 ); $('#custom'+idx).css('top', $('#workspace'+idx).height()/2 - $('#custom'+idx).height()/2 ); enable_image_editing( 'custom'+idx, idx ); $('input[name=width_custom'+idx+']').val( new_w ); $('input[name=width_height'+idx+']').val( new_h ); //$('input[name=width_'+id+']').val( w ); //$('input[name=height_'+id+']').val( h ); //Effetti rollover immagine $('#workspace'+idx).mouseover( function(event){ $selected = $('#'+globals.selectedObj[idx]); //Mostro gli handler del resize $selected.find('.ui-resizable-handle, .delete-btn').show(); //Ripristino colore clipart solo a quello selezionato $selected.css('border-color', '#0D7FD2'); //In primo piano $('#custom'+idx+', div[id*=maskbg_], .element').each( function(){ $(this).data('old-z', $(this).css('z-index') ); if( $selected.attr('id') == $(this).attr('id') ){ $(this).css('z-index', $(this).data('old-z')+100000 ).css('opacity', '0.8'); } else { $(this).css('z-index', $(this).data('old-z')+10000 ).css('opacity', '0.8'); } }); }); $('#workspace'+idx).mouseout( function(event){ //Nascondo gli handler del resize $('.ui-resizable-handle, .delete-btn').hide(); //Nascondo tratteggio clipart $('.element').css('border-color', 'transparent'); //Torna in secondo piano $('#custom'+idx+', div[id*=maskbg_], .element').each( function(){ $(this).css('z-index', $(this).data('old-z')).css('opacity', '1'); }); //Ripristino la profondità del livello selezionato $selected = $('#'+globals.selectedObj[idx]); $selected.css('z-index', $('#'+globals.selectedObj[idx]).data('old-z') ); }); $('#custom'+idx).mousedown( function(event){ $('#custom'+idx+', div[id*=maskbg_]').css('opacity', '0.6'); }); $('#custom'+idx).mouseup( function(event){ $('#custom'+idx+', div[id*=maskbg_]').css('opacity', '0.8'); }); //Imposto l'altezza del div contenitore, perchè essendo position:absolute l'img non copre gli spazi $('#mask'+idx).parent().height( h ); id = 'custom'+idx; init_levels( idx ); set_active( id, idx ); }); } function set_effect( effect, idx ){ id = globals.selectedObj[idx]; $('#uploading-overlay').show(); val = $('input[name='+effect+'_'+id+']').val(); //Azzero gli effetti precedenti $('.othereffects_'+id).val('0'); $('.scelta'+idx).removeClass('active'); $('input[name='+effect+'_'+id+']').val('1'); $('#effect_'+effect+'_'+idx).addClass('active'); $.get( globals.rootdir+'/imagefilter.php?filename='+$('input[name=filename_'+idx+'_'+id+']').val()+'&brightness='+$('input[name=brightness_'+id+']').val()+'&contrast='+$('input[name=contrast_'+id+']').val()+'&grayscale='+$('input[name=grayscale_'+id+']').val()+'&negate='+$('input[name=negate_'+id+']').val()+'&sepia='+$('input[name=sepia_'+id+']').val()+'&matrix='+$('input[name=matrix_'+id+']').val()+'&blu='+$('input[name=blu_'+id+']').val(), function(data){ $('#'+id+' > img').attr( 'src', data ).bind( 'load', function(){ $('#uploading-overlay').hide(); $('#'+id+' > img').unbind('load'); } ); }); } if ($.ui.resizable){ var _changeCopy = $.extend({}, $.ui.resizable.prototype._change); $.ui.resizable.prototype._change = { newChange: function(event, dx, direction, dy) { var angle = getAngle(this); var convertedAngle = parseInt(angle / 90); var axisToAngle = { "s" : 0, "w" : 1, "n" : 2, "e" : 3 }; if (typeof axisToAngle[direction] == 'undefined' || angle <= 90 || angle >= 270) { return _changeCopy[direction].call(this, event, dx, dy); } var angleToAxis = { 0 : "s", 1 : "w", 2: "n", 3: "e" }; var correctedAxis = axisToAngle[direction] + convertedAngle; correctedAxis = correctedAxis % 4; return _changeCopy[angleToAxis[correctedAxis]].call(this, event, dx, dy); }, e: function(event, dx) { return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "e"); }, w: function(event, dx) { return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "w"); }, n: function(event, dx, dy) { return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "n", dy); }, s: function(event, dx, dy) { return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "s", dy); }, se: function(event, dx, dy) { return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "se", dy); }, sw: function(event, dx, dy) { return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "sw", dy); }, ne: function(event, dx, dy) { return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "ne", dy); }, nw: function(event, dx, dy) { return $.ui.resizable.prototype._change.newChange.call(this, event, dx, "nw", dy); } }; var getAngle = function(widget){ return getRotationDegrees( widget.element ); }; } function getRotationDegrees(obj) { var matrix = obj.css("-webkit-transform") || obj.css("-moz-transform") || obj.css("-ms-transform") || obj.css("-o-transform") || obj.css("transform"); if(matrix !== 'none') { var values = matrix.split('(')[1].split(')')[0].split(','); var a = values[0]; var b = values[1]; var angle = Math.round(Math.atan2(b, a) * (180/Math.PI)); } else { var angle = 0; } return (angle < 0) ? angle +=360 : angle; } /** * Calcolo il prezzo del singolo articolo in base alle combinazioni */ function calcola_prezzo(){ idattributi = new Array(); idvalori = new Array(); //Attributi a click $('input[name*=attributo_]', '#order-form').each( function(){ v = ( $(this).attr('name') ).split('_'); idattributo = v[1]; idvalore = $(this).val(); idattributi.push( idattributo ); idvalori.push( idvalore ); }); //Attributi a select $('select[name*=attributo_]', '#order-form').each( function(){ v = ( $(this).attr('name') ).split('_'); idattributo = v[1]; idvalore = $(this).find('option:selected').val(); if( idvalore != '' ){ idattributi.push( idattributo ); idvalori.push( idvalore ); } }); //Calcolo prezzo in base alle combinazioni $.ajaxSetup({ async: false }); $.post( globals.rootdir+'/ajaxreq.php?op=get_price_by_combination', { productid: $('input[name=productid]').val(), idattributi: idattributi.toString(), idvalori: idvalori.toString() }, function(data){ if( data != '0.00' ){ v = data.split('.'); $('#prezzo-text').html( "€ "+v[0]+","+v[1] ); $('#prezzo').val( data ); } else{ $('#prezzo-text').html( '...' ); $('#prezzo').val( '0.00' ); } }); } function increment_qty( id ){ $.post( globals.rootdir+'/ajaxreq.php', { op: 'increment', id: id }, function(data){ if( data == 'ok' ){ location.href = location.href; } }); } function decrement_qty( id ){ $.post( globals.rootdir+'/ajaxreq.php', { op: 'decrement', id: id }, function(data){ if( data == 'ok' ){ location.href = location.href; } }); } function launch_modal( title, href, init_modal ){ //Lettura contenuto div if( href.substr(0,1) == '#' ){ data = $(href).html(); $('#popup').html( '