jQuery(document).ready(function($){
$(document).foundation();
//Check to see if the window is top if not then display button
jQuery(window).scroll(function(){
if (jQuery(this).scrollTop() > 100) {
jQuery('.scrollToTop').fadeIn();
} else {
jQuery('.scrollToTop').fadeOut();
}
});
//Click event to scroll to top
jQuery('.scrollToTop').click(function(){
jQuery('html, body').animate({scrollTop : 0},800);
return false;
});
jQuery(document).on('click', '.social_share', function(){
Share.go(this);
return false;
});
});
Share = {
/**
* Показать пользователю дилог шаринга в сооветствии с опциями
* Метод для использования в inline-js в ссылках
* При блокировке всплывающего окна подставит нужный адрес и ползволит браузеру перейти по нему
*
* @example like+
*
* @param Object _element - элемент DOM, для которого
* @param Object _options - опции, все необязательны
*/
go: function(_element, _options) {
var
self = Share,
options = jQuery.extend(
{
type: 'vk', // тип соцсети
url: location.href, // какую ссылку шарим
count_url: location.href, // для какой ссылки крутим счётчик
title: document.title, // заголовок шаринга
image: '', // картинка шаринга
text: '', // текст шаринга
},
jQuery(_element).data(), // Если параметры заданы в data, то читаем их
_options // Параметры из вызова метода имеют наивысший приоритет
);
if (self.popup(link = self[options.type](options)) === null) {
// Если не удалось открыть попап
if ( jQuery(_element).is('a') ) {
// Если это , то подставляем адрес и просим браузер продолжить переход по ссылке
jQuery(_element).prop('href', link);
return true;
}
else {
// Если это не , то пытаемся перейти по адресу
location.href = link;
return false;
}
}
else {
// Попап успешно открыт, просим браузер не продолжать обработку
return false;
}
},
// ВКонтакте
vk: function(_options) {
var options = jQuery.extend({
url: location.href,
title: document.title,
image: '',
text: '',
}, _options);
return 'http://web.archive.orghttp://vkontakte.ru/share.php?'
+ 'url=' + encodeURIComponent(options.url)
+ '&title=' + encodeURIComponent(options.title)
+ '&description=' + encodeURIComponent(options.text)
+ '&image=' + encodeURIComponent(options.image)
+ '&noparse=true';
},
// Одноклассники
ok: function(_options) {
var options = jQuery.extend({
url: location.href,
text: '',
}, _options);
return 'http://web.archive.orghttp://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1'
+ '&st.comments=' + encodeURIComponent(options.text)
+ '&st._surl=' + encodeURIComponent(options.url);
},
// Facebook
fb: function(_options) {
var options = jQuery.extend({
url: location.href,
title: document.title,
image: '',
text: '',
}, _options);
return 'http://web.archive.orghttp://www.facebook.com/sharer.php?s=100'
+ '&p[title]=' + encodeURIComponent(options.title)
+ '&p[summary]=' + encodeURIComponent(options.text)
+ '&p[url]=' + encodeURIComponent(options.url)
+ '&p[images][0]=' + encodeURIComponent(options.image);
},
// Живой Журнал
lj: function(_options) {
var options = jQuery.extend({
url: location.href,
title: document.title,
text: '',
}, _options);
return 'http://web.archive.orghttp://livejournal.com/update.bml?'
+ 'subject=' + encodeURIComponent(options.title)
+ '&event=' + encodeURIComponent(options.text + '
' + options.title + '')
+ '&transform=1';
},
// Твиттер
tw: function(_options) {
var options = jQuery.extend({
url: location.href,
count_url: location.href,
title: document.title,
}, _options);
return 'http://web.archive.orghttp://twitter.com/share?'
+ 'text=' + encodeURIComponent(options.title)
+ '&url=' + encodeURIComponent(options.url)
+ '&counturl=' + encodeURIComponent(options.count_url);
},
// Mail.Ru
mr: function(_options) {
var options = jQuery.extend({
url: location.href,
title: document.title,
image: '',
text: '',
}, _options);
return 'http://web.archive.orghttp://connect.mail.ru/share?'
+ 'url=' + encodeURIComponent(options.url)
+ '&title=' + encodeURIComponent(options.title)
+ '&description=' + encodeURIComponent(options.text)
+ '&imageurl=' + encodeURIComponent(options.image);
},
// Google+
gg: function (_options) {
var options = jQuery.extend({
url: location.href
}, _options);
return 'http://web.archive.orghttps://plus.google.com/share?url='
+ encodeURIComponent(options.url);
},
// Открыть окно шаринга
popup: function(url) {
return window.open(url,'','toolbar=0,status=0,scrollbars=1,width=626,height=436');
}
}
/*
playback timings (ms):
LoadShardBlock: 149.013 (3)
esindex: 0.008
captures_list: 168.712
CDXLines.iter: 12.192 (3)
PetaboxLoader3.datanode: 191.338 (4)
exclusion.robots: 0.305
exclusion.robots.policy: 0.292
RedisCDXSource: 4.29
PetaboxLoader3.resolve: 34.43
load_resource: 81.283
*/