jQuery(window).load(function(){ //////////////////////////////////////////// // PARAMETROS QUE ME VIENES // //////////////////////////////////////////// var esteJS = jQuery('script[src*="tap.js"]'); // IDIOMA // var varIdioma = esteJS.attr('data-idioma'); // FIXED // var varFixed = esteJS.attr('data-fixed'); if(typeof varFixed === 'undefined'){ varFixed = false; } else { varFixed = true; jQuery('#tapCompartir').addClass('fixed'); } // CSS // var varCSS = esteJS.attr('data-css'); if(typeof varCSS === 'undefined'){ jQuery('head').append(''); } else { jQuery('head').append(''); } // REDES SOCIALES // var varRedes = esteJS.attr('data-redes'); var arrRedes; if(typeof varRedes === 'undefined'){ varRedes = false; } else { arrRedes = varRedes.split(','); varRedes = true; } ///////////////////////////////////////////////////////////////// // CHECK SI FONTAWESOME ESTÁ CARGADO O NO // ///////////////////////////////////////////////////////////////// var span = document.createElement('span'); span.className = 'fa'; span.style.display = 'none'; document.body.insertBefore(span, document.body.firstChild); function css(element, property) { return window.getComputedStyle(element, null).getPropertyValue(property); } // SI NO TIENE CARGADO FONTAWESOME // if (css(span, 'font-family') !== 'FontAwesome') { jQuery('head').append(''); } document.body.removeChild(span); ////////////////////////////// // GOOGLE ANALYTICS // ////////////////////////////// var tieneGA = false; function check_ga() { if (typeof ga === 'function') { console.log('Google Analytics :'+ ga); tieneGA = true; //ga('send', 'pageview'); } else { console.log('¿Seguro que Google Analytics está cargado?'); setTimeout(function(){ check_ga(); }, 500); } } check_ga(); ///////////////// // EVENTOS // ///////////////// //urlActual = encodeURIComponent(window.location.href); urlActual = window.location.href; titleActual = document.getElementsByTagName("title")[0].innerHTML; //TODO: OK - realizar el replace a nivel global sustituyendo todas las ocurrencias titleActual = titleActual.replace(/\|/g, '-'); //keyWords = $('meta[name=author]').attr("content"); /* jQuery('#tapCompartir').on('click', 'a.a-facebook', function(){ if(tieneGA){ ga('send', 'event', 'addthis', 'facebook', urlActual); } return false; }) jQuery('#tapCompartir').on('click', 'a.a-twitter', function(){ if(tieneGA){ ga('send', 'event', 'addthis', 'twitter', urlActual); } return false; }) */ jQuery('#tapCompartir').on('click', 'a', function(){ var botonActual = jQuery(this); var accion = botonActual.attr('class').replace('a-', ''); var link = botonActual.attr('href'); if(tieneGA){ ga('send', 'event', 'addthis', accion, urlActual); } ////////////////////////// // ANCHOS | ALTOS // ////////////////////////// switch(accion) { case 'twitter': var ancho = 600; var alto = 250; break; case 'pinterest': var ancho = 780; var alto = 360; break; case 'linkedin': var ancho = 1000; var alto = 560; break; case 'google': var ancho = 450; var alto = 580; break; default: var ancho = 520; var alto = 360; } /////////////////// // ACCIONES // /////////////////// switch(accion) { //////////////////// // WHATSAPP // //////////////////// case 'whatsapp': break; ///////////// // EMAIL // ///////////// case 'email': botonActual.addClass('load activo'); if(jQuery('#dm-compartir-wrapper').length == 0){ jQuery('body').append('
') } jQuery.ajax({ url: '/'+ varIdioma +'/compartir-formulario?asunto='+ titleActual +'&url='+ urlActual, dataType: 'html', success: function(html) { var div = jQuery('#formCompartir', jQuery(html)).addClass('done'); jQuery('#dm-compartir').html(div.html()); setTimeout(function(){ jQuery('#dm-compartir-wrapper').addClass('on'); botonActual.removeClass('load'); }, 500) } }); return false; break; ///////////////////////////////// // POR DEFECTO | RESTO // ///////////////////////////////// default: window.open(link, 'ventana-'+ accion, 'status=1, menubar=no, toolbar=no, width='+ ancho +', height='+ alto +', resizable=0'); return false; } //return false; }) //////////////// // IDIOMAS // //////////////// var idiFB; switch(varIdioma) { case 'eu': idiWhats = 'Whatsapp'; idiFB = 'Partekatu'; idiTW = 'Twitteatu'; idiPin = 'Pineatu'; idiIN = 'LinkedIn'; idiGPlus = 'Google+'; idiMail = 'E-posta'; break; case 'en': idiWhats = 'Whatsapp'; idiFB = 'Share'; idiTW = 'Tweet'; idiPin = 'Pin it'; idiIN = 'LinkedIn'; idiGPlus = 'Google+'; idiMail = 'E-mail'; break; case 'fr': idiWhats = 'Whatsapp'; idiFB = 'Partager'; idiTW = 'Tweet'; idiPin = 'Pin'; idiIN = 'LinkedIn'; idiGPlus = 'Google+'; idiMail = 'E-mail'; break; default: idiWhats = 'Whatsapp'; idiFB = 'Compartir'; idiTW = 'Twittear'; idiPin = 'Pinear'; idiIN = 'LinkedIn'; idiGPlus = 'Google+'; idiMail = 'E-mail'; } /////////////////// // KITA CAPA // /////////////////// jQuery('body').on('click', '#dm-compartir-inner', function(evento){ if(evento.target === this){ jQuery('#dm-compartir-wrapper').removeClass('on'); setTimeout(function(){ jQuery('#dm-compartir-wrapper').remove(); jQuery('#tapCompartir a').removeClass('load, activo'); }, 1000) } }) /////////////////////////////// // VARIABLES A PASAR // /////////////////////////////// // TWITTER // //descTwitter = jQuery('meta[name="twitter:title"]').attr("content"); //////////////////////////////////////////////////////////////// // CODIGO A INSERTAR EN EL HTML RESULTANTE // //////////////////////////////////////////////////////////////// if(varRedes){ $codigoHtml = ''; $codigoHtml += ''; jQuery('#tapCompartir').html($codigoHtml); } })