// application.js // global modal var modal = null; // open modal window function modalform(urlGet, urlPost, dataGet) { $.get(urlGet, dataGet, function (data) { modal = $(data).modal({ backdrop: 'static', keyboard: true, show: true }); $(modal).bind('show', function () { console.log('modal show!'); }); if(urlPost) { $(modal).find('.primary').bind('click', function () { // modal reference var that = $(this).closest('.modal'); // serialize form before disabling it var data = $(that).find('form').serialize(); // disable fields and buttons $(that).find('input,textarea').attr('disabled', true); $(that).find('.btn').toggleClass('disabled'); // show loading icon $(that).find('.status,.status img').show(); $(that).find('.status span').html(''); // post it $.post(urlPost, data, function() { }, 'json') .complete(function () { }) .success(function (data) { $(that).find('.status img').hide(); $(that).find('.status').show(); $(that).find('.status span').html(data.message); if(data.success != true) { $(that).find('.status span').addClass('error'); $(that).find('input,textarea').attr('disabled', false); $(that).find('.btn').toggleClass('disabled'); } else { $(that).find('.status span').removeClass('error'); $(that).find('.btn,.status img').hide(); $('Cerrar').appendTo('.modal-footer'); } }) .error(function (data) { $(that).find('.status img').hide(); $(that).find('input,textarea').attr('disabled', false); $(that).find('.btn').toggleClass('disabled'); $(that).find('.status').show(); $(that).find('.status span').addClass('error').html('Error enviando la solicitud'); alert('OcurriĆ³ un error enviando la solicitud.\nPor favor vuelva a intentarlo en unos minutos.\n\nDisculpe las molestias'); }); }); } }); return false; } $(document).ready(function() { // hide alert messages after 10s. $('.alert-message:not(.block-message)').delay(30000).fadeOut('slow'); $('[rel=twipsy]').twipsy(); $('.modal').modal({backdrop: 'static'}); $('.modal-footer .btn').click(function() { $('.modal .close').click(); return false; }); // adjust left height var hLeft = $('#left').css('height'); var hRight = $('#right').css('height'); if(parseInt(hRight) > parseInt(hLeft)) $('#left').css('height', hRight); $("a.link-modal").click(function() { // get title $('.modal .modal-header h3').html($(this).attr('title')); $.get($(this).attr('href'), function(res) { $('.modal .modal-body').html(res); $('.modal').modal('show'); }); return false; }); $('.modal .closebtn').live('click', function() { $(modal).modal('hide'); $(modal).remove(); return false; }); $("a[rel=popover]") .popover({ offset: 10 }) .click(function(e) { e.preventDefault() }) // first adjustment adjustSidemenuHeight(); // further adjustments $(window).resize(function () { adjustSidemenuHeight(); }); // contactinfo button $('#sidemenu-contactar a, .link-contactar').click(function() { return modalform( '/gl/json/contactform', '/gl/json/contactsend'); }); // offers button $('#sidemenu-ofertas a, .link-ofertas').click(function() { return modalform( '/gl/json/offerform', '/gl/json/offersend'); }) // demands button $('#sidemenu-demandas a, .link-demandas').click(function() { return modalform( '/gl/json/demandform', '/gl/json/demandsend'); }); // privacy policy button $('.link-privacidad').click(function() { return modalform('/gl/json/privacy', false); }); // location button $('.link-localizacion').click(function() { return modalform('/gl/json/location', false); }); bannerOpen = function() { $('#banner').stop().animate({ height: 768 }, 2000, 'easeInOutQuint' ) }; bannerClose = function() { $('#banner').stop().animate({ height: 100 }, 2000, 'easeInOutQuint' ) }; var bannerOpenTimer; $('#banner').on('mouseover', function () { if($('#banner').height() < 768) bannerOpenTimer = setTimeout(bannerOpen, 1000); }); $('#banner').on('mouseleave', function () { clearTimeout(bannerOpenTimer); bannerClose(); }); $('#banner').on('click', function () { window.location.href = $(this).attr('data-target'); }); if(navigator.userAgent.match(/iPad|iPhone|iPod/i)) { $('#banner .toggle').on('click', function () { if($('#banner').height() < 768) bannerOpen(); else bannerClose(); return false; }); } }); function adjustSidemenuHeight() { if(parseInt($('#sidemenu').height()) < parseInt($('#maincontent').height())) $('#sidemenu').height($('#maincontent').height()); else $('#maincontent').height($('#sidemenu').height()); }