$(document).ready(function() { function openWindowSocial(url, title, width, height) { var width = ($('body').outerWidth() > width) ? width : $('body').outerWidth(), dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left, dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top, browserWidth = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width, browserHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height, left = ((browserWidth / 2) - (width / 2)) + dualScreenLeft, top = ((browserHeight / 2) - (height / 2)) + dualScreenTop, windowParams = 'top='+top+',left='+left+',width='+width+',height='+height+',resizable=yes;menubar=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no', resultShare, newWindow; newWindow = window.open(url, title, windowParams); newWindow.focus(); } function shareVk(item) { var location = encodeURIComponent(window.location.href), title = encodeURIComponent($('meta[property="og:title"]').attr('content')), description = encodeURIComponent($('meta[property="og:description"]').attr('content')), image = encodeURIComponent(item.find('.quotations-list__img').attr('data-common-social')), url; if ( image == 'undefined' || image == '' ) { image = encodeURIComponent(item.find('.quotations-list__img').attr('src')); } url = 'http://vk.com/share.php?'; url += 'url='+location; url += '&title='+title; url += '&description='+description; url += '&image='+image; openWindowSocial(url, 'Вконтакте', 400, 300); } function shareOk(item) { var location = encodeURIComponent(window.location.href), image = encodeURIComponent(item.find('.quotations-list__img').attr('data-common-social')), title = encodeURIComponent($('meta[property="og:title"]').attr('content')), description = encodeURIComponent($('meta[property="og:description"]').attr('content')), url; if ( image || image == '' ) { image = encodeURIComponent(item.find('.quotations-list__img').attr('src')); } url = 'https://connect.ok.ru/dk?cmd=WidgetSharePreview&st.cmd=WidgetSharePreview'; url += '&st.shareUrl='+location; url += '&st.imageUrl='+image; url += '&st.title='+title; url += '&st.description='+description; openWindowSocial(url, 'Вконтакте', 400, 300); } function shareFacebook(item) { var location = encodeURIComponent(window.location.href), image = encodeURIComponent(item.find('.quotations-list__img').attr('data-common-social')), title = encodeURIComponent($('meta[property="og:title"]').attr('content')), description = encodeURIComponent($('meta[property="og:description"]').attr('content')), url; if ( image == 'undefined' || image == '' ) { image = encodeURIComponent(item.find('.quotations-list__img').attr('src')); } url = 'https://www.facebook.com/dialog/feed?app_id=1560680134228538&display=popup'; url += '&link='+location; url += '&picture='+image; openWindowSocial(url, 'Facebook', 400, 300); } function shareTwitter(item) { var location = encodeURIComponent(window.location.href), title = encodeURIComponent($('meta[property="og:title"]').attr('content')), location = encodeURIComponent(item.parents('.quotations-list').attr('data-short-address')), image = encodeURIComponent(item.find('.quotations-list__img').attr('data-twitter')), hashtags = encodeURIComponent(item.parents('.quotations-list').attr('data-social-hashtag')), url; if ( location == 'undefined' || location == '' ) { location = encodeURIComponent(window.location.href); } url = 'http://www.twitter.com/share?'; url += 'text='+title; if ( image != 'undefined' && image != '') url += '%20'+image; if ( hashtags != 'undefined' && hashtags != '' ) url += '&hashtags='+hashtags; url += '&url='+location; openWindowSocial(url, 'Twitter', 400, 300); } var quotationsSharing = '
'+ '
Вконтакте
'+ '
Одноклассники
'+ '
Facebook
'+ '
Twitter
'+ '
'; $('.quotations-list__img').wrap('
'); $('.quotations-list__item').append( quotationsSharing ); $('.quotations-list__item').hover(function() { $(this).addClass('active'); }, function() { $(this).removeClass('active'); }); $('.quotations-sharing__item_vk').on('click', function() { var item = $(this).parents('.quotations-list__item'); shareVk(item); }); $('.quotations-sharing__item_ok').on('click', function() { var item = $(this).parents('.quotations-list__item'); shareOk(item); }); $('.quotations-sharing__item_facebook').on('click', function() { var item = $(this).parents('.quotations-list__item'); shareFacebook(item); }); $('.quotations-sharing__item_twitter').on('click', function() { var item = $(this).parents('.quotations-list__item'); shareTwitter(item); }); });