var options = new Object(); function initPopup(key, t, img, selected) { url = window.location.href; splits = url.split('?'); url = splits[0]; options = { id : key, title: t, img : 'http://ruki-zhizni.ru/images/stories/votes/' + img, text : 'Мой выбор: ' + selected, url : url }; $.fancybox.open({ content: $(".vote-options"), padding: 0, closeBtn: false }); } function shareSocial(type) { updateVotesCount(options.id); if (type == 'vk') { Share.vkontakte(options); } else if (type == 'fb') { Share.facebook(options); } else { Share.odnoklassniki(options); } return false; } function updateVotesCount(id){ $.ajax({ url: '/update-voting.php', type: 'post', data: { 'id' : id, 'vote_id' : $('input[name="vote_id"]').val() }, success: function() { var li = $('.article-vote ul li:eq(' + id + ')'); var count = parseInt(li.find('.votes-count p').html()); li.find('.votes-count p').html(count + 1); $('.vote-success').show(); $('.article-vote').hide(); } }) } Share = { vkontakte: function(options) { url = 'http://vkontakte.ru/share.php?'; url += 'url=' + encodeURIComponent(options.url); url += '&title=' + encodeURIComponent(options.title); url += '&description=' + encodeURIComponent(options.text); url += '&image=' + encodeURIComponent(options.img); url += '&noparse=true'; Share.popup(url, 626); }, odnoklassniki: function(options) { url = 'http://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1'; url += '&st.comments=' + encodeURIComponent(options.text); url += '&st._surl=' + encodeURIComponent(options.url + '?vote_key=' + options.id); Share.popup(url, 626); }, facebook: function(options) { url = 'https://www.facebook.com/dialog/feed?app_id=338444046279869'; url += '&redirect_uri=https://www.facebook.com/' + '&picture=' + encodeURIComponent(options.img) + '&caption=' + encodeURIComponent(options.title) + '&description=' + encodeURIComponent(options.text); Share.popup(url, 800); }, popup: function(url, width) { window.open(url,'','toolbar=0,status=0,width=' + width + ',height=436'); $.fancybox.close(true); } };