jQuery(document).ready(function($){ var basic_network_list = "twitter,linkedin,facebook,pinterest,google,stumbleupon,vk,reddit,buffer,love,ok,mwp,xing,pocket,mail,print,comments,yummly"; var extended_network_list = "del,digg,weibo,flattr,tumblr,whatsapp,meneame,blogger,amazon,yahoomail,gmail,aol,newsvine,hackernews,evernote,myspace,mailru,viadeo,line,flipboard,sms,viber,telegram"; var plugin_url = essb_settings.essb3_plugin_url; var fb_value = essb_settings.essb3_facebook_total; var counter_admin = essb_settings.essb3_admin_ajax; var interal_counters_all = essb_settings.essb3_internal_counter; var button_counter_hidden = essb_settings.essb3_counter_button_min; var no_print_mail_counter = typeof(essb_settings.essb3_no_counter_mailprint) != "undefined" ? essb_settings.essb3_no_counter_mailprint : false; var force_single_ajax = typeof(essb_settings.essb3_single_ajax) != "undefined" ? essb_settings.essb3_single_ajax : false; var twitter_counter = typeof(essb_settings.twitter_counter) != "undefined" ? essb_settings.twitter_counter : ""; var google_counter = typeof(essb_settings.google_counter) != 'undefined' ? essb_settings.google_counter : ''; if (twitter_counter == "") { twitter_counter = "api"; } if (google_counter == '') google_counter = 'api'; var essb_shorten_number = function(n) { if ('number' !== typeof n) n = Number(n); var sgn = n < 0 ? '-' : '' , suffixes = ['k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'] , overflow = Math.pow(10, suffixes.length * 3 + 3) , suffix, digits; n = Math.abs(Math.round(n)); if (n < 1000) return sgn + n; if (n >= 1e100) return sgn + 'many'; if (n >= overflow) return (sgn + n).replace(/(\.\d*)?e\+?/i, 'e'); // 1e24 do { n = Math.floor(n); suffix = suffixes.shift(); digits = n % 1e6; n = n / 1000; if (n >= 1000) continue; // 1M onwards: get them in the next iteration if (n >= 10 && n < 1000 // 10k ... 999k || (n < 10 && (digits % 1000) < 100) // Xk (X000 ... X099) ) return sgn + Math.floor(n) + suffix; return (sgn + n).replace(/(\.\d).*/, '$1') + suffix; // #.#k } while (suffixes.length) return sgn + 'many'; } jQuery.fn.essb_get_counters = function(){ return this.each(function(){ // missing plugin settings - code cannot run from here if (typeof(essb_settings) == "undefined") { return; } var counter_pos = $(this).attr("data-essb-counter-pos") || ""; var post_self_count_id = $(this).attr("data-essb-postid") || ""; var url = $(this).attr("data-essb-url") || ""; var twitter_url = $(this).attr("data-essb-twitter-url") || ""; var instance_id = $(this).attr("data-essb-instance") || ""; var ajax_url = essb_settings.ajax_url; if (essb_settings.ajax_type == "light") { ajax_url = essb_settings.blog_url; } // definy the counter API var nonapi_counts_url = (counter_admin) ? ajax_url+"?action=essb_counts&nonce="+essb_settings.essb3_nonce+"&" : essb_settings.essb3_plugin_url+"/public/get-noapi-counts.php?"; var nonapi_internal_url = ajax_url+"?action=essb_counts&nonce="+essb_settings.essb3_nonce+"&"; //console.log(nonapi_internal_url); var basic_networks = basic_network_list.split(","); var extended_networks = extended_network_list.split(","); var direct_access_networks = []; var nonapi_count_networks = []; var nonapi_internal_count_networks = []; for (var i=0;i 0 && force_single_ajax) { var network_address = nonapi_internal_url + "nw="+post_network_list.join(",")+"&url="+url+"&instance="+instance_id+"&post="+post_self_count_id; //console.log(network_address); $.getJSON(network_address) .done(function(data){ for (var i=0;i parseInt($cnt)) { $css_hidden_negative = ' style="display: none;"'; } } if (counter_pos == "right") { $element.append('' + essb_shorten_number($cnt) + ''); } else if (counter_pos == "inside") { $element_inside.html('' + essb_shorten_number($cnt) + ''); } else if (counter_pos == "insidename") { $element_inside.append('' + essb_shorten_number($cnt) + ''); } else if (counter_pos == "insidehover") { $element_inside.closest("a").append('' + essb_shorten_number($cnt) + ''); // fix width of new element var current_width = $element_inside.closest("a").find('.essb_network_name').innerWidth(); $element_inside.closest("a").find('.essb_counter_insidehover').width(current_width); } else if (counter_pos == "insidebeforename") { $element_inside.prepend('' + essb_shorten_number($cnt) + ''); } else if (counter_pos == "bottom") { $element_inside.html('' + essb_shorten_number($cnt) + ''); } else if (counter_pos == "hidden") { $element.append(''); } else if (counter_pos == "topn") { $element.find("a").prepend('' + essb_shorten_number($cnt) + ''); } else { $element.prepend('' + essb_shorten_number($cnt) + ''); } } }); }; jQuery.fn.essb_update_counters = function(){ return this.each(function(){ var $group = $(this).find(".essb_links_list"); var current_button_counter_pos = $(this).attr("data-essb-counter-pos") || ""; var $total_count = $group.find('.essb_totalcount'); var $total_count_nb = $total_count.find('.essb_t_nb'); var $total_count_item = $group.find('.essb_totalcount_item'); var $total_counter_hidden = $total_count_item.attr('data-essb-hide-till') || ""; var total_text = $total_count.attr('title') || ""; var total_text_after = $total_count.attr('title_after') || ""; var total_inside_text = $total_count.attr('data-shares-text') || ""; if (typeof(total_text) == "undefined") { total_text = ""; } if (typeof(total_text_after) == "undefined") { total_text_after = ""; } if (total_text != '') $total_count.prepend(''+total_text+''); function count_total() { var total = 0; var counter_pos = current_button_counter_pos; var exist_data_counter_pos = $total_count_item.attr('data-counter-pos') || ""; // alert(exist_data_counter_pos); if (exist_data_counter_pos != '') { counter_pos = exist_data_counter_pos; } var counter_element = ""; switch (counter_pos) { case "rightm": case "right": counter_element = ".essb_counter_right"; break; case "inside": counter_element = ".essb_counter_inside"; break; case "bottom": counter_element = ".essb_counter_bottom"; break; case "insidename": counter_element = ".essb_counter_insidename"; break; case "insidebeforename": counter_element = ".essb_counter_insidebeforename"; break; case "insidehover": counter_element = ".essb_counter_insidehover"; break; case "hidden": counter_element = ".essb_counter_hidden"; break; case "topn": counter_element = '.essb_counter_topn'; break; default: counter_element = ".essb_counter"; break; } $group.find(counter_element).each(function(){ total += parseInt($(this).attr('cnt')); var value = parseInt($(this).attr('cnt')); if (!$total_count_nb) { value = essb_shorten_number(value); $(this).text(value); } //alert(shortenNumber(total)); }); if (total_inside_text != '') { $total_count_nb.html(essb_shorten_number(total) + ''+total_inside_text+'') } else { $total_count_nb.text(essb_shorten_number(total)); } // show total counter when value is reached if ($total_counter_hidden != '') { //alert(parseInt($total_counter_hidden) + " - " + total); if (parseInt($total_counter_hidden) <= total) { $total_count_item.show(); } } } setInterval(count_total, 1200); }); }; $('.essb_links.essb_counters').essb_get_counters(); $('.essb_links.essb_counters').essb_update_counters(); });