$(document).ready(function () { var offsetTop; var history = window.History; var opts = { lines: 12, length: 7, width: 5, radius: 10, color: '#000', speed: 1, trail: 10, shadow: true }; // horizontal scroll function mousewheel(event, delta) { $(this).scrollLeft($(this).scrollLeft() - (delta * 60)); event.preventDefault(); }; if ($('section#home').length > 0) { $(document).mousewheel(mousewheel); } $('.resumo .texto, .biografia .texto').jScrollPane(); function updateOffset() { alto = $('nav.main:visible').length > 0 ? $('nav.main:visible').height() : $('nav.main:not(.ficha)').height(); var offset = $('.main.row-cells:visible > section').offset(); offsetTop = offset ? offset.top - alto : alto; //$('.main.row-cells:visible > section').offset().top - alto; } function navPosition() { $('nav.main').css('top', (offsetTop - $(window).scrollTop()) + 'px'); }; function parseState(state) { var offset = (state.data && state.data.offset) ? state.data.offset : 0; var hashes = state.url.split(/\//i); var hash = hashes[hashes.length - 1]; if (hash.indexOf('?') >= 0) { hashes = hash.split(/\?/i); hash = hashes[hashes.length - 1]; if (parseInt(hash)) { hash = hashes[0]; } } var scrollTo = true; if ((hash === 'peixinhos' && $('#peixinhos').is(':visible') === false) || (hash === 'pedidos-eleccion') && $('#pedidos-eleccion').is(':visible') === false) { $('nav.ficha').fadeOut(); $('.contenedor-detalle-libro').fadeOut('normal', function(){ $('nav.main:not(.ficha)').fadeIn(); $('div.main:not(.detalle-libro)').fadeIn(); updateOffset(); navPosition(); $(document).scrollTo($('#' + hash), { 'duration': 800, 'offset': offset }); $(document).mousewheel(mousewheel); }); return false; } else if (state.url.indexOf('libro') >= 0 && $('#ficha').is(':visible') === false) { $(document).scrollTo($('#home'), { 'duration': 800 }); $('nav.main').fadeOut(); $('div.main:not(.detalle-libro)').fadeOut(); $('.loading-ficha').fadeIn('normal'); //var spinner = new Spinner(opts).spin($('.loading-ficha')[0]); $('.loading-ficha').html(''); $.ajax({ url: state.url, dataType: 'html', success: function(data){ $(document).unbind('mousewheel'); //$('.contenedor-detalle-libro').html(data); $('.contenedor-detalle-libro').html(''); $('.contenedor-detalle-libro').append(innerShiv(data, false)); $('.loading-ficha').fadeOut('normal'); $('.contenedor-detalle-libro').fadeIn('normal', function(){ $('a[rel="paxinas"]').colorbox({ maxWidth: '80%', maxHeight: '80%' }); }); $('.resumo .texto, .biografia .texto').jScrollPane(); $('.main > section').css('min-width', $(window).width() + 'px'); $('nav.ficha').fadeIn('normal'); updateOffset(); navPosition(); }, error: function(jXhr, status, error){ alert(error); } }); return false; } var element = $('#' + hash); if (element.length > 0) { navigateTo(element, offset); return false; } }; function navigateTo(element, offset) { $(document).scrollTo(element, { 'duration': 800, 'offset': offset }); }; if(!navigator.geolocation) { var diana = $('span.image.diana'); diana.prev().removeClass('inline').find('input[type="text"]').width('99%'); diana.hide();$(document).unbind('mousewheel'); } updateOffset(); navPosition(); $('nav.main:not(.ficha)').show(); $(window).load(function(){ updateOffset(); navPosition(); }); $(window).resize(function(){ updateOffset(); navPosition(); $('nav.main:not(.ficha)').show(); }); $(window).scroll(navPosition); $('.main > section').css('min-width', $(window).width() + 'px'); $('a[rel="paxinas"]').colorbox({ maxWidth: '80%', maxHeight: '80%' }); $('#condicions').colorbox({ inline: true, href: function () { return $(this).attr('href'); } }); $('div.titulo:empty').each(function(){ var svg = Raphael($(this).attr('id'), 70, 500); var texto = svg.text(28, 28, $(this).attr('data-texto')); var color = '#FFF1C1'; var element = $(this); if (element.hasClass('home')) { color = '#B44C2E'; } else if (element.hasClass('narede')) { color = '#6B9BB3'; } else if (element.hasClass('contacto')) { color = '#93A373'; } texto.attr({ 'fill': color, 'font-family': 'PT Sans', 'font-size': '55px', 'font-weight': 'bold', 'text-anchor': 'end', 'width': 500 }); texto.rotate(270, 28, 28); }); $('.titulo-novas').each(function(){ var svg = Raphael($(this).attr('id'), 30, 80); var texto = svg.text(14, 0, 'NOVAS'); var color = '#FFF1C1'; texto.attr({ 'fill': color, 'font-family': 'PT Sans', 'font-size': '22px', 'font-weight': 'bold', 'text-anchor': 'end', 'width': 80 }); texto.rotate(270, 14, 0); }); if (history.enabled) { history.Adapter.bind(window, 'statechange', function(){ return parseState(history.getState());}); parseState(history.getState()); } $('body').delegate('a:not(.abrir-libro, .condicions)', 'click', function () { var device = navigator.userAgent.toLowerCase(); if (device.match(/(iphone|ipod|ipad)/)) { return true; } var offset = 0; var href = $(this).attr('href'); var title = $(this).html().replace(/(<([^>]+)>)/ig, ''); var scrollTo = true; if (href.indexOf('pedidos-eleccion') >= 0) { offset = ($('#pedidos-eleccion').width() / 2) - ($(window).width() / 2); } else if (href === 'pedido-particular') { offset = -10; } else if (href === 'home') { offset = -40; } else if (href === 'ficha') { offset = -50; } else if (href.indexOf('peixinhos') >= 0) { if ($('#peixinhos').length <= 0) { return true; } title = 'Peixiños'; } var posicionBase = href.indexOf(paths.base); var ruta = href.substring(posicionBase + paths.base.length); if (ruta && ruta.substr(-1) === '/') { href = href.substr(0, href.length - 1); } var splittedUrl = window.location.href.split(/\//ig); var actualStep = splittedUrl[splittedUrl.length-1]; if (href === actualStep) { parseState({data: { 'offset': offset, 'scrollTo': scrollTo }, url: href}); } else { history.pushState({ 'offset': offset, 'scrollTo': scrollTo }, title + ' | Editora Patasdepeixe', href); } return false; }); if ($('.mapa .contenedor-mapa').length > 0) { maps.init({ 'container': $('.mapa .contenedor-mapa')[0], 'location': {'lat': 42.7508, 'long': -9.0000}, 'zoom': 8 }); maps.loadData({ 'url': '/librerias/', 'data': {}, 'loading': $('.mapa .loading'), 'template': $('#libreriasTemplate') }); } $('form.buscador').submit(function(){ maps.locate($('input.buscar').val()); return false; }); $('.image.diana a').click(function(){ maps.locate(); return false; }); $('.pedido table td input').change(function(){ var td = $(this).parent(); var prezo = parseFloat(td.attr('data-prezo')); var total = $(this).val() * prezo; var spanTotal = td.parent().find('td .total-libro'); spanTotal.attr('data-prezo', total); spanTotal.html(total.toFixed(2).replace('.', ',')); var total_final = 0; var importe = 0; $('.total-libro').each(function(){ importe = $(this).attr('data-prezo'); total_final += parseFloat(importe ? importe : 0); }); $('.total-final').html(total_final.toFixed(2).replace('.', ',')); }); $('a#condicions').colorbox({ href: $('div#texto-condicions'), inline: true, innerWidth: '620px', onClosed: function() { $(document).mousewheel(mousewheel); }, onComplete: function(){ $.colorbox.resize(); $(document).unbind('mousewheel'); } }) $('div.message').each(function(){ $.colorbox({ href: $('div.message'), inline: true, open: true }) }); $('.external').click(function() { window.open(this.href); return false; }); $('form.formulario').validate(); });