Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($) {
- $(document).ready (
- function() {
- //-----------------------------------------
- var tab = $('#stats_table');
- tab.data('hidden',true);
- tab.data('stats',true);
- tab.find('tr:not(:eq(0))').each(
- function() {
- var pos = 0;
- var green_val=230;
- var red_val = 230;
- var prev_val = -1;
- var els=$(this).find('td:gt(1):not(:last):not(.dop_stat)');
- var len =els.length;
- els.filter(function(index) {
- return index<len-2;
- })
- .each(
- function () {
- var value =parseInt($(this).html());
- pos += value;
- if (prev_val!=-1) {
- if (((value<prev_val) && (value!=0)) || ((value>prev_val) && (prev_val==0))) {
- $(this).css('background-color', 'rgb(210,'+green_val+',210)');
- green_val +=15;
- }
- if (((value>prev_val) && (prev_val!=0)) || ((value==0) && (prev_val!=0))) {
- $(this).css('background-color','rgb('+red_val+',210,210)');
- red_val +=15;
- }
- }
- prev_val =value;
- if ((value<20) && (value>0)) {
- $(this).css({color:'#c00',fontWeight:'bold'});
- $(this).parent().children(':eq(1)').css({fontWeight:600})
- }
- }
- );
- if (pos==0) {
- $(this).attr('data-zero','zero')
- $(this).hide();
- }
- }
- )
- //-----------------------------------------
- // show / hide zeros
- //-----------------------------------------
- $('#show_hide_zeros').click (
- function() {
- if (tab.data('hidden')) {
- tab.data('hidden',false);
- tab.find('tr[data-zero="zero"]').show();
- $(this).html('Hide zeros');
- } else {
- tab.data('hidden',true);
- tab.find('tr[data-zero="zero"]').hide();
- $(this).html('Show zeros');
- }
- }
- )
- var not_sorting_columns = {};
- tab.find('tr:eq(0) th').each (
- function(index) {
- if ($(this).hasClass('dop_stat')) {
- not_sorting_columns[index] = {sorter:false};
- }
- }
- )
- //-----------------------------------------
- // show / hide stats
- //-----------------------------------------
- $('#show_hide_stats').click (
- function() {
- if (tab.data('stats')) {
- tab.data('stats',false);
- tab.find('.dop_stat').hide();
- tab.find('thead tr:lt(3)').hide();
- $(this).html('Show stats');
- } else {
- tab.data('stats',true);
- tab.find('.dop_stat').show();
- tab.find('thead tr:lt(3)').show();
- $(this).html('Hide stats');
- }
- }
- )
- //-----------------------------------------
- // switch yandex/google positions
- //-----------------------------------------
- $('#yandex_google').change(
- function () {
- var proto = location.protocol;
- var hostname = location.hostname;
- var pathname = location.pathname;
- var search = location.search;
- var re=/&se=.*?($|&)/g;
- search = search.replace(re,'');
- var new_location = proto+'//'+hostname+pathname+search+'&se='+this.value;
- location.replace(new_location);
- }
- )
- //-----------------------------------------
- // sort
- //-----------------------------------------
- tab.tablesorter({
- headers: {
- 0: {sorter:false}
- }
- });
- //-----------------------------------------
- // resizing
- //-----------------------------------------
- tab.find("th").resizable({
- handles: "e",
- helper: "ui-resizable-helper",
- start: function(event, ui) {
- },
- stop: function(event, ui) {
- if ($(this).index()!=1)
- return;
- var els = tab.find('tr td:nth-child(2) .td_out_query');
- els.css('width',ui.size.width).parent().css('width',ui.size.width);
- // height must be set in order to prevent IE9 to set wrong height
- $(this).css("height", "auto");
- }
- });
- //-----------------------------------------
- // tooltips
- //-----------------------------------------
- tab.tooltip({
- items: 'td:not(:first-child):not([title^="none"])',
- show: {
- effect: "fade",
- duration: 100,
- easing: 'easeOutCirc'
- },
- hide: {
- delay: 0,
- duration: 0
- },
- content: function() {
- var element = $(this);
- return element.attr('title');
- },
- position: {
- my: "center bottom-40",
- at: "center top",
- using: function( position, feedback ) {
- $( this ).css( position );
- $( "<div>" )
- .addClass( "arrow" )
- .addClass( feedback.vertical )
- .addClass( feedback.horizontal )
- .appendTo( this );
- }
- }
- });
- //-------------------------------
- tab.find('tr:eq(0)').tooltip({
- items: 'th.dop_stat',
- show: {
- effect: "fade",
- duration: 100,
- easing: "easeOutCirc"
- },
- hide: {
- delay: 0,
- duration: 0
- },
- content: function() {
- return $(this).children('.th_title').text();
- },
- position: {
- my: "center bottom-20",
- at: "center top"
- }
- })
- //-----------------------------------------
- // extra rows in header
- //-----------------------------------------
- var spancols = tab.find('th.dop_stat').length+2-3;
- var poscols =tab.find('th').length - spancols-3-3;
- var header=tab.children('thead');
- for (var j=0; j<3; j++) {
- var tr = $('<tr/>');
- if (j==2) {
- tr.append($('<th/>').attr('colspan',spancols).attr('rowspan',3));
- }
- tr.append($('<th/>').attr('colspan',3));
- for (var i=0;i<poscols;i++) {
- tr.append($('<th/>'));
- }
- if (j==2)
- tr.append($('<th/>').attr('colspan',3).attr('rowspan',3));
- header.prepend(tr);
- }
- var head = header.get(0);
- head.rows[0].cells[1].innerHTML = 'TOP 10';
- head.rows[1].cells[0].innerHTML = 'TOP 100';
- head.rows[2].cells[0].innerHTML = 'Видимость';
- var top10;
- var top100;
- var all;
- var value;
- for (i=0; i<poscols; i++) {
- top10 = 0;
- top100 = 0;
- all = 0;
- tab.find('td:nth-child('+(spancols+3+i+1)+')').each(
- function() {
- value = parseInt($(this).html());
- if ((value>0) && (value<=10)) {
- top10++;
- }
- if ((value>0) && (value<=100)) {
- top100++;
- }
- all++;
- }
- );
- head.rows[0].cells[i+2].innerHTML = top10;
- head.rows[1].cells[i+1].innerHTML = top100;
- head.rows[2].cells[i+1].innerHTML = Math.round(top100/all*100)+' %';
- }
- }
- )
- })(jQuery)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement