(function(){ function init(){ var footer_bar = $('#footer-bar.inst-948'); var dlg = footer_bar.closest('.uk-modal-dialog'); var meta; var google_counter = 0; var facebook_counter = 0; get_meta(function(out){ meta = out; }); function shorten_url(meta,callback){ return $.ajax({ type: "GET", url: 'process/shorten_url.php', dataType:'text', data:{ url:meta.url } }).success(function(response){ meta.shorturl = response; callback(meta); }); } function get_meta(callback){ var out = {}; if (dlg.length>0){ out.url = dlg.data('url'); out.shorturl = dlg.data('short-url'); var meta = dlg.find('.metadata'); if (meta.length>0){ out.title = meta.data('title'); out.description = meta.data('description'); out.image = meta.data('image'); } callback(out); } else { var head = $('head'); out.url = head.find('link[rel=canonical]').attr('href'); out.title = head.find('title').text(); out.description = head.find('meta[name=Description]').attr('content'); out.image = head.find('meta[property="og:image"]').attr('content'); shorten_url(out,function(out){ callback(out); }) } } function send_data_to_google(){ if (typeof(ga)!='undefined'){ setTimeout(function(){ google_counter = google_counter+1; if ((typeof(meta)=='undefined') && (google_counter<=3)){ setTimeout(function(){ send_data_to_google(); },600) } else { ga('send', { hitType: 'pageview', title: meta.title, page: meta.url.replace(Graphite.App.base_url,'') }); } },600) } } function send_data_to_facebook(){ if ((typeof(fbq)!='undefined') && (dlg.length>0)){ setTimeout(function(){ facebook_counter = facebook_counter+1; if ((typeof(meta)=='undefined') && (facebook_counter<=3)){ send_data_to_facebook(); } else { var ts = new Date().getTime(); var url = 'https://www.facebook.com/tr/?id='+fbq.pixel_id+'&ev=PageView&dl='+meta.url+'&rl=https%3A%2F%2Fwww.facebook.com%2F&if=false&ts='+ts+'&v=2.7.21&ec=0&o=30&it='+(ts+642); footer_bar.after(''); } },600) } } function bindings(){ var ux_social_icons = footer_bar.find('.ux-social-icons-30px'); ux_social_icons.on('click','a.ux-icon-facebook',function(evt){ evt.preventDefault(); var facebook_app_id = footer_bar.data('facebook-app-id'); var href = 'https://www.facebook.com/sharer/sharer.php?app_id='+facebook_app_id+'&sdk=joey&u='+encodeURIComponent(meta.shorturl)+'&display=popup&ref=plugin&src=share_button'; var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; var w = 555; var h = 540; var left = ((width / 2) - (w / 2)); var top = ((height / 2) - (h / 2)); if (width>580){ w = 555; h = 460; left = ((width / 2) - (w / 2)); top = ((height / 2) - (h / 2)); window.open(href,'_blank','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=555,height=460,top='+top+',left='+left); } else { window.open(href,'_blank'); } }) ux_social_icons.on('click','a.ux-icon-twitter',function(evt){ evt.preventDefault(); var href = 'https://twitter.com/intent/tweet?url='+encodeURIComponent(meta.shorturl)+'&text='+encodeURIComponent(meta.title); var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; var w = 555; var h = 460; var left = ((width / 2) - (w / 2)); var top = ((height / 2) - (h / 2)); if (width>540){ window.open(href,'_blank','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=555,height=460,top='+top+',left='+left); } else { window.open(href,'_blank'); } }) ux_social_icons.on('click','a.ux-icon-google-plus',function(evt){ evt.preventDefault(); var href = 'https://plus.google.com/share?url='+encodeURIComponent(meta.shorturl); var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; var w = 555; var h = 460; var left = ((width / 2) - (w / 2)); var top = ((height / 2) - (h / 2)); if (width>540){ w = 400; h = 460; left = ((width / 2) - (w / 2)); top = ((height / 2) - (h / 2)); window.open(href,'_blank','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=460,top='+top+',left='+left); } else { window.open(href,'_blank'); } }) ux_social_icons.on('click','a.ux-icon-line',function(evt){ evt.preventDefault(); var href = 'https://timeline.line.me/social-plugin/share?url='+encodeURIComponent(meta.shorturl)+'&text='+encodeURIComponent(meta.title); var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; var w = 555; var h = 505; var left = ((width / 2) - (w / 2)); var top = ((height / 2) - (h / 2)); if (width>540){ window.open(href,'_blank','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=555,height=505,top='+top+',left='+left); } else { window.open(href,'_blank'); } }) /* var button = footer_bar.find('.ux-icon-line'); button.attr('href','line://msg/text/'+encodeURIComponent(meta.title+' - '+meta.url)); */ } if (dlg.length>0){ dlg.find('.fb-comments').attr('data-href',dlg.data('url')); } bindings(); send_data_to_google(); send_data_to_facebook(); /* if (typeof(ga)!='undefined'){ setTimeout(function(){ if (typeof(meta)=='undefined'){ } else { ga('send', { hitType: 'pageview', title: meta.title, page: meta.url.replace(Graphite.App.base_url,'') }); } },600) } */ } init(); /* setTimeout(function(){ init(); },800) */ })()