Special One-Time Offer from Tom
Only for Existing Bestseller Ranking Pro Members
Book Launch Builder:
Special Offer $497
Upgrade Me to Book Launch Builder for only $497
// These are in the OP Analytics and Tracking Area // Adds the color and sales numbers function formatRanks(element){ var bsr, sales, color, sales_str; bsr = element.text(); var url = window.location.pathname; if( url.match(/ebook/i) == null ){ computeType = 'books'; } else { computeType = 'ebooks'; } if( url.match(/uk/i) == null ){ countryType = 'us'; } else { countryType = 'uk'; //console.log(countryType); } // check for search page if( url.match(/category\-finder/i) == "category-finder" ){ console.log("Search Page"); computeType = jQuery("#brp_type").val().toLowerCase(); countryType = jQuery("#brp_market").val().toLowerCase(); } console.log("formatRanks vars: " + countryType + " - " + computeType); // Get the sales number from BSR sales = computeSalesFromBSR(bsr, computeType); if (countryType == 'uk') { sales = Math.round(sales / 10); } // Add the color if (bsr == 0) { color = "#33CC33"; } // no ranking. no sales else if (bsr > 100000) { color = "#33CC33"; } else if (bsr > 50000) { color = "#33CC33"; } else if (bsr > 10000) { color = "#33CC33"; } else if (bsr > 5500) { color = "#DDBB4C"; } else if (bsr > 3000) { color = "#DDBB4C"; } else if (bsr > 1500) { color = "#DDBB4C"; } else if (bsr > 750) { color = "#DDBB4C"; } else if (bsr > 500) { color = "#FF6600"; } else if (bsr > 350) { color = "#FF6600"; } else if (bsr > 200) { color = "#FF6600"; } else if (bsr > 100) { color = "#FF6600"; } else if (bsr > 35) { color = "#FF0000"; } else if (bsr > 20) { color = "#FF0000"; } else if (bsr > 5) { color = "#FF0000"; } else if (bsr > 1) { color = "#FF0000"; } else { color = "#FF0000"; } // Format the string if ( sales == 0 ) { sales_str = "No Book in this Ranking"; } else { sales_str = sales + " sales/mth or " + Math.round(sales/15) + " in 24hrs"; } element.attr('style',"color:" + color + ";"); element.attr('title',sales_str); element.attr('rel','tooltip'); //console.log("formatRanksCalled"); //console.log(bsr); } function computeSalesFromBSR(bsr,type){ var alpha, beta, epsilon, sales; if( bsr == 0 ){ return 0; } if (type == 'books'){ alpha = -0.33483877; // R23 beta = -0.06198923; // R24 epsilon = 3.69500221; // R22 } else { alpha = -0.34034503; // R23 beta = -0.07791303; // R24 epsilon = 3.98993694; // R22 } // Monthly sales. Added 1.08 modifier to account for 8% sales growth return Math.round(Math.pow(10,(epsilon + alpha * Math.log10(bsr) + beta * Math.pow(Math.log10(bsr),2))) * 15 * 1.08 ); } jQuery(document).ready(function() { console.log("started"); jQuery('table tbody').find('tr').each(function (i, el) { //console.log("table id = " + jQuery(this).closest('table').attr('id')); if( jQuery(this).closest('table').attr('id') == 'tablepress-53') { return false; } var $tds = jQuery(this).find('td'), one = $tds.eq(1), fifty = $tds.eq(2), hundred = $tds.eq(3); //console.log(one); formatRanks(one); formatRanks(fifty); formatRanks(hundred); }); }); // add tooltip to mouseover on BSR numbers jQuery( function() { var targets = jQuery( '[rel~=tooltip]' ), target = false, tooltip = false, title = false; targets.bind( 'mouseenter', function() { target = jQuery( this ); tip = target.attr( 'title' ); tooltip = jQuery( '
' ); if( !tip || tip == '' ) return false; target.removeAttr( 'title' ); tooltip.css( 'opacity', 0 ) .html( tip ) .appendTo( 'body' ); var init_tooltip = function() { if( jQuery( window ).width() < tooltip.outerWidth() * 1.5 ) tooltip.css( 'max-width', jQuery( window ).width() / 2 ); else tooltip.css( 'max-width', 340 ); var pos_left = target.offset().left + ( target.outerWidth() / 2 ) - ( tooltip.outerWidth() / 2 ), pos_top = target.offset().top - tooltip.outerHeight() - 20; if( pos_left < 0 ) { pos_left = target.offset().left + target.outerWidth() / 2 - 20; tooltip.addClass( 'left' ); } else tooltip.removeClass( 'left' ); if( pos_left + tooltip.outerWidth() > jQuery( window ).width() ) { pos_left = target.offset().left - tooltip.outerWidth() + target.outerWidth() / 2 + 20; tooltip.addClass( 'right' ); } else tooltip.removeClass( 'right' ); if( pos_top < 0 ) { var pos_top = target.offset().top + target.outerHeight(); tooltip.addClass( 'top' ); } else tooltip.removeClass( 'top' ); tooltip.css( { left: pos_left, top: pos_top } ) .animate( { top: '+=10', opacity: 1 }, 50 ); }; init_tooltip(); jQuery( window ).resize( init_tooltip ); var remove_tooltip = function() { tooltip.animate( { top: '-=10', opacity: 0 }, 50, function() { jQuery( this ).remove(); }); target.attr( 'title', tip ); }; target.bind( 'mouseleave', remove_tooltip ); tooltip.bind( 'click', remove_tooltip ); }); });