| 1 |
jQuery(document).ready(function($) { |
| 2 |
|
| 3 |
|
| 4 |
$('.maxsocial [data-popup]').on('click', function (e) { |
| 5 |
e.preventDefault(); |
| 6 |
|
| 7 |
var url = $(this).attr('href'); |
| 8 |
var data = $(this).data('popup'); |
| 9 |
|
| 10 |
var width = data.width; |
| 11 |
var height = data.height; |
| 12 |
var left = ($(window).width() - width) / 2; |
| 13 |
var top = ($(window).height() - height) / 2; |
| 14 |
|
| 15 |
var params = "toolbar=0,scrollbars=1, location=0, width=" + width + ",height=" + height + ",left=" + left + ",top=" + top; |
| 16 |
var popup = window.open(url, 'mb-social-share-window', params); |
| 17 |
|
| 18 |
var popup = window.open(url, 'mb-social-share-window', params); |
| 19 |
popup.focus(); |
| 20 |
|
| 21 |
}); |
| 22 |
|
| 23 |
function mbGetShareCount(el, data) |
| 24 |
{ |
| 25 |
var ajax_url = mb_ajax.ajaxurl; |
| 26 |
var share_url = data.share_url; |
| 27 |
var network = data.network; |
| 28 |
var collection_id = data.collection_id; |
| 29 |
var nonce = data.nonce; |
| 30 |
|
| 31 |
var block_data = { |
| 32 |
share_url: share_url, |
| 33 |
network: network, |
| 34 |
}; |
| 35 |
|
| 36 |
var data = { |
| 37 |
block_name : 'countBlock', |
| 38 |
block_action : 'ajax_get_count', |
| 39 |
action : 'mbsocial_get_count', |
| 40 |
collection_id: collection_id, |
| 41 |
block_data: block_data, |
| 42 |
}; |
| 43 |
//console.log(data); |
| 44 |
$.ajax({ |
| 45 |
type: "POST", |
| 46 |
url: ajax_url, |
| 47 |
data: data, |
| 48 |
success: function (result) { |
| 49 |
mbPutShareCount(result, el); |
| 50 |
|
| 51 |
}, |
| 52 |
}); |
| 53 |
} |
| 54 |
|
| 55 |
function mbPutShareCount(result, el) |
| 56 |
{ |
| 57 |
|
| 58 |
var resJSON = $.parseJSON(result); |
| 59 |
|
| 60 |
var data = $(el).data('onload'); |
| 61 |
var threshold = parseInt(data.count_threshold); |
| 62 |
var count = parseInt(resJSON.data.count); |
| 63 |
|
| 64 |
|
| 65 |
if (count >= threshold) |
| 66 |
{ |
| 67 |
//console.log('generate count block here'); |
| 68 |
$(el).find('.mb-label').addClass('.mb-share-count').text(count).removeClass('.mb-label'); |
| 69 |
} |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
$('.maxsocial .mb-item[data-onload]').each( function () { |
| 74 |
var collection_id = $(this).parents('.maxsocial').data('collection'); |
| 75 |
|
| 76 |
var data = $(this).data('onload'); |
| 77 |
data.collection_id = collection_id; |
| 78 |
|
| 79 |
mbGetShareCount(this, data); |
| 80 |
|
| 81 |
}); |
| 82 |
|
| 83 |
}); |
| 84 |
|