English
Personal tools
Namespaces

Variants
Actions

MediaWiki:Common.js

From Tanki Online Wiki
(Difference between revisions)
Jump to: navigation, search
Line 720: Line 720:
  
 
/*============================================================================================*/
 
/*============================================================================================*/
 +
 +
$(".linkElem").on('click', function(){ window.open($(this).data("url"),"_blank"); });
 +
 
/*jQuery(document).ready() ends here*/
 
/*jQuery(document).ready() ends here*/
 
});
 
});

Revision as of 07:24, 11 January 2018

function getRandomKey(obj){
  var keys = Object.keys(obj);
  return keys[Math.floor(Math.random()*keys.length)];
};

function getRandomVal(obj){
  return obj[getRandomKey(obj)];
};

function getSplitNumber(num) {
  return num.toString().replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
}

/*============================================================================================*/
/*============================================================================================*/
/*============================================================================================*/
/*Using jQuery from here*/

jQuery.noConflict();

jQuery(document).ready(function($) {
/*============================================================================================*/
//TOP button

  $('<div id="toTop-button"><div></div>Top</div>').appendTo($('#mw-panel'));
  $(function() {
    $(window).scroll(function() {
      if($(this).scrollTop() > 667) {
        $('#toTop-button').fadeIn(300);	
      } else {
        $('#toTop-button').fadeOut(100);
      }
    });
    $('#toTop-button').click(function() {
      $('body,html').animate({ scrollTop:0 }, 400);
    });	
  });
/*============================================================================================*/
//Giveaway results

if ($("#GiveawayResults").length) {
  function loadGiveawayResults(storages, eventName){
    var cur = 1;
    var tryLoad = function() {
      $.ajax({type: 'get', timeout: 5000, url: storages[cur],
        error: function(x, textStatus, m) {
          if (textStatus == "timeout" || textStatus == "error") {
            if(++cur < storages.length) {
              tryLoad();
            } else {
              $('<p>Couldn' + "'" + 't load results. The service is temporarily unavailable. Try to refresh the page, come back later or search in the original <a rel="nofollow" class="external text" href="' + makeLink(prefixes, info, eventName, "googleDoc") + '">spreadsheet</a>.</p>').insertAfter("#GiveawayResults");
            }
          }
        },
        success: function(json){
          info[eventName].data = json;
          disableEnableForm(true);
        }
      });
    }
    tryLoad();
  }
  
  function makeLink(prefixes, info, eventName, type) {
    if (!info || !info[eventName]) return false;
    switch(type) {
      case "myjson":
      case "jsonblob":
        return prefixes[type] + info[eventName]["storages"][type]; break;
      case "wiki":
        return prefixes["wiki"][_LANG_] + info[eventName]["storages"]["wiki"][_LANG_]; break;
      case "googleDoc":
        return prefixes["googleDoc"].replace("{DOC_ID}", info[eventName]["google"]["docID"]).replace("{SHEET_ID}", info[eventName]["google"]["sheetID"]); break;
      case "googleDirectJson":
        return prefixes["googleDirectJson"].replace("{DOC_ID}", info[eventName]["google"]["docID"]).replace("{SHEET_TRUE_ID}", info[eventName]["google"]["sheetTrueID"]); break;
      default: return false;
    }
  }
  function getStorageLinks(prefixes, info, eventName) {
    return [
      makeLink(prefixes, info, eventName, "googleDirectJson"),
      makeLink(prefixes, info, eventName, "wiki"),
      makeLink(prefixes, info, eventName, "myjson"),
      makeLink(prefixes, info, eventName, "jsonblob")
    ]
  }
  
  function getResult() {
    var nick = prepare($("#TankerNickname").val());
    if (nick == "") {
      $("#TankerNickname").val("");
      return;
    }
    var dict = info[getSelectedOption("GiveawaysDropdown")]["data"][getSelectedOption("ClusterDropdown")];
    
    for (user in dict) {
      if (prepare(user) == nick) {
        $("#TankerNickname").toggleClass("grey-gradient", false).toggleClass("green-gradient", true);
        $("#TankerNickname").val(dict[user]);
        $("#TankerNickname").click(clearInput);
        return;
      }
    }
    $("#TankerNickname").toggleClass("grey-gradient", false).toggleClass("red-gradient", true);
    $("#TankerNickname").val("Nickname not found");
    $("#TankerNickname").click(clearInput);
  }
  
  function GiveawaysDropdownChanged() {
    var eventName = getSelectedOption("GiveawaysDropdown");
    if (info[eventName].data == null) {
      disableEnableForm(false);
      loadGiveawayResults(getStorageLinks(prefixes, info, eventName), eventName);
    }
  }
  
  function clearInputOnDropdownChange(){
    if ($("#TankerNickname").hasClass("red-gradient") || $("#TankerNickname").hasClass("green-gradient")) {
      clearInput();
    }
  }
  
  function disableEnableForm(mode) {
    if (mode) {
      $(".wiki-control").prop('disabled', false).css("background-color", "");
      $('#GetResult').val('Show result');
    } else {
      $(".wiki-control").prop('disabled', true).css("background-color", "#aaa");
      $('#GetResult').val('Loading...');
    }
  }
  
  function getSelectedOption(id) {
    return $("#" + id + " option:selected").val();
  }
  
  function clearInput() {
    $("#TankerNickname").toggleClass("green-gradient", false).toggleClass("red-gradient", false).toggleClass("grey-gradient", true)
    $("#TankerNickname").val("");
    //$("#TankerNickname").unbind();
  }
  
  function prepare(str) {
    return $.trim(str).toLowerCase();
  }
  //================================================
  var _LANG_ = "en";
  var GiveawayInfoLink = "https://en.tankiwiki.com/images/0/04/GiveawayInfo.json";
  var prefixes;
  var info;
  $.getJSON(GiveawayInfoLink, function(json) {
    prefixes = json["prefixes"];
    info = json["data"];
    
    var select = document.createElement("select");
    select.id = "ClusterDropdown";
    select.className = "wiki-control grey-gradient";
    select.disabled = true;
    
    var select = document.createElement("select");
    select.id = "GiveawaysDropdown";
    select.className = "wiki-control grey-gradient";
    select.disabled = true;
  
    var textbox = document.createElement("input");
    textbox.type = "text";
    textbox.disabled = true;
    textbox.maxLength = 20;
    textbox.placeholder = "Enter your nickname...";
    textbox.className = "wiki-control grey-gradient";
    textbox.id = "TankerNickname";
  
    var resultbutton = document.createElement("input");
    resultbutton.type = "button";
    resultbutton.disabled = true;
    resultbutton.className = "wiki-control grey-gradient";
    resultbutton.id = "GetResult";
    resultbutton.value = "Loading...";
    
    $("#GiveawayResults").append($('<select id="ClusterDropdown" class="wiki-control grey-gradient" disabled=true><option value="EU" selected>Europe</option><option value="LATAM">Latin America</option></select>').css("background-color", "#aaa"))
      .append(" ").append($(select).css("background-color", "#aaa"))
      .append(" ").append($(textbox).css("background-color", "#aaa"))
      .append(" ").append($(resultbutton).css("background-color", "#aaa"));
    
    $("#GetResult").click(getResult);
    $("#GiveawaysDropdown").change(clearInputOnDropdownChange);
    $("#ClusterDropdown").change(clearInputOnDropdownChange);
    $("#GiveawaysDropdown").change(GiveawaysDropdownChanged);
    
    $("#TankerNickname").on("keyup", function(event) {
      if(event.keyCode == 13) {
        $("#GetResult").click();
      }
    });
    
    $.each(info, function(eventName) {
      var option = document.createElement("option");
      option.value = eventName;
      option.innerText = info[eventName]["name"][_LANG_];
      option.selected = info[eventName].selected;
      option.disabled = info[eventName].disabled;
      if (info[eventName].selected) {
        loadGiveawayResults(getStorageLinks(prefixes, info, eventName), eventName);
      }
      $("#GiveawaysDropdown").append($(option));
    });
  });
}

/*====================================================================================*/
//Homepage turrets/hulls dropdown lists

if($("#HomepageDropdowns").length)
{
  var ddl = $(".drop-down-list");
  $(document).on('click', '.drop-down-block', function() {
    for(var i = 0; i < ddl.length; i++)
    {
      if(ddl[i] == ($(this).next().find('.drop-down-list'))[0])
      {
        $(ddl[i]).parent().prev().toggleClass("rotate180");
        $(ddl[i]).slideToggle();
      }
      else
      {
        $(ddl[i]).parent().prev().toggleClass("rotate180", false);
        $(ddl[i]).hide();
      }
    }
  });

  $(document).click(function(event){ 
    if(!$(event.target).hasClass('drop-down-list') && !$(event.target).parent().hasClass('drop-down-list') && !$(event.target).parent().parent().hasClass('drop-down-list') && !$(event.target).parent().hasClass('drop-down-block') && !$(event.target).hasClass('drop-down-block') && !$(event.target).hasClass('drop-down-list-wrapper')) 
    {
      for(var j = 0; j < ddl.length; j++)
      {
        if($(ddl[j]).is(":visible")) 
        {
          $(ddl[j]).parent().prev().toggleClass("rotate180", false);
          $(ddl[j]).slideUp("fast");
        }
      }
    }     
  });
}

/*============================================================================================*/
/*============================================================================================*/

if ($(".mapScreenshotsCarousel").length) {
  $('.mapScreenshotsCarousel .carouselContainer').remove();

  $.each($(".mapScreenshotsCarousel .open"), function(k,v) {
    $($(v).children()).detach().insertAfter($(v));
  });
}

/*============================================================================================*/
/*============================================================================================*/

function showModal(type, content) {
  if(!content || !type) return false;
  var modalSize;
  switch(type){
    case "TankPreview": 
      modalSize = "l";
      break;
    case "YouTube": 
      modalSize = "m";
      break;
    default:
      return false;
  }

  var modal = $('<div class="modal size-' + modalSize + '"></div>');
  var closeButton = $('<div class="modal-close">&#215;</div>');
  closeButton.appendTo(modal);
  var modalBg = $('<div class="modal-bg"></div>');
  modal.appendTo('body');
  modalBg.appendTo('body');
  modal.css("margin-left", -modal.outerWidth()/2).css("margin-top", -modal.outerHeight()/2);
  modalBg.css("opacity", "0.5").css("background-color", "#000");
  
  if(type == "TankPreview"){
    $(TankPreview.getViewer(content)).appendTo(modal);
    $(TankPreview.getMenu()).appendTo(modal);
    fillDropdown("hullType");
    fillDropdown("turretType");
    $("#hullType").on("change", onTypeChanged);
    $("#turretType").on("change", onTypeChanged);
    $(".TankPreview-select").on("change", onSelectedChanged);
  }
  if(type == "YouTube"){
    var iframe = $('<iframe width="100%" height="100%" src="https://www.youtube.com/embed/'
                + content + '" frameborder="0" allowfullscreen></iframe>');
    iframe.appendTo(modal);
  }
  
  closeButton.on('click', function() {
    $(".modal").fadeOut(350, function(){
      $(".modal").detach();
      $(".modal-bg").detach();
    });
  });
  
  $(document).mouseup(function(e) {
    if (!$(e.target).closest(".modal").length) {
      $(".modal").fadeOut(350, function(){
        $(".modal").detach();
        $(".modal-bg").detach();
      });
    }
  });
}

/*============================================================================================*/
//Paint preview in modal window

if($(".showPaint") != null) { if($(".showPaint").length)
{
  var $this;
  var viewer_data;
  $.getJSON('https://en.tankiwiki.com/images/6/66/Tank_parts_resources.json',function(data){  
    viewer_data = data;
  });

  $('.showPaint').on('click', function () {
    $this = $(this);
    var tank = getRandomTank();
    if(tank) { 
      tank["paintType"] = $this.data('paintType');
      tank["paintModel"] = $this.data('paintModel');
      showModal("TankPreview", tank);
    }
  });

  function getRandomTank(){
    if(!viewer_data) return false;
    var random_tank = {
      "paintType": {},
      "paintModel": {},
      "hullType": {},
      "hullModel": {},
      "turretType": {},
      "turretModel": {}
    };
    random_tank["hullType"] = getRandomKey(viewer_data["hulls"]);
    random_tank["turretType"] = getRandomKey(viewer_data["turrets"]);
    random_tank["hullModel"] = getRandomKey(viewer_data["hulls"][random_tank["hullType"]]);
    random_tank["turretModel"] = getRandomKey(viewer_data["turrets"][random_tank["turretType"]]);
    return random_tank;
  }

  function getFileSource(path, callback){
    jQuery.ajax({
      type: 'GET',
      url: "https://ru.tankiwiki.com/" + path,
      success: callback("https://ru.tankiwiki.com/" + path),
      error: callback("https://en.tankiwiki.com/" + path)
    });
  }
  function cb(link){
    return link;
  }

  var TankPreview = {
    "viewer": null,
    getMenu: function(){
      return '<div style="float:right;width:27%"><div style="margin:5px 0"><div class="type-label">Hull: </div><select class="TankPreview-select select-parent wiki-control grey-gradient" size="1" id="hullType" name="hullType" data-category="hulls" data-child="hullModel"><option disabled selected value="stub">Model</option></select>&nbsp;<select class="TankPreview-select select-child wiki-control grey-gradient" style="background-color:#aaa" disabled size="1" id="hullModel" name="hullModel" data-parent="hullType"><option disabled selected value="stub">Grade</option></select></div><div style="margin:5px 0"><div class="type-label">Turret: </div><select class="TankPreview-select select-parent wiki-control grey-gradient" size="1" id="turretType" name="turretType" data-category="turrets" data-child="turretModel"><option disabled selected value="stub">Model</option></select>&nbsp;<select class="TankPreview-select select-child wiki-control grey-gradient" style="background-color:#aaa" disabled size="1" id="turretModel" name="turretModel" data-parent="turretType"><option disabled selected value="stub">Grade</option></select></div><div style="text-align:center;margin:10px 0px"><input style="background-color:#aaa" type="button" class="wiki-control grey-gradient" id="showTank" value="Show"></div></div>';
    },
    getViewer: function(tank){
      if(TankPreview.viewer == null){
          var viewer = document.createElement("object");
          viewer.type = "application/x-shockwave-flash";
          viewer.id = "TankPreview";
          viewer.data = "https://ru.tankiwiki.com/images/2/24/Tank_viewer.swf";
          viewer.width = "73%";
          viewer.height = "100%";
          viewer.style.float = "left";
          var param1 = document.createElement("param");
          var param2 = document.createElement("param");
          var param3 = document.createElement("param");
          var param4 = document.createElement("param");
          param1.name = "menu";
          param1.value = "false";
          param2.name = "seamlesstabbing";
          param2.value = "false";
          param3.name = "wmode";
          param3.value = "transparent";
          param4.name = "flashvars";
          param4.value = "";
          
          viewer.appendChild(param1);
          viewer.appendChild(param2);
          viewer.appendChild(param3);
          viewer.appendChild(param4);
          TankPreview.viewer = viewer;
      }
      
      var dir = "https://ru.tankiwiki.com/";
      var obj = TankPreview.viewer;
      
      var hullItems = viewer_data["hulls"][tank["hullType"]][tank["hullModel"]];
      var turretItems = viewer_data["turrets"][tank["turretType"]][tank["turretModel"]];
      var paintItems = viewer_data["paints"][tank["paintType"]][tank["paintModel"]];
      var itemsXml = "itemsXml=<response>" + 
      "<hull_model>" + dir + hullItems["model"] + "</hull_model>" + 
      "<hull_details>" + dir + hullItems["details"] + "</hull_details>" + 
      "<hull_details_alpha>" + dir + hullItems["alpha"] + "</hull_details_alpha>" + 
      "<hull_lightmap>" + dir + hullItems["lightmap"] + "</hull_lightmap>" + 
      "<turret_model>" + dir + turretItems["model"] + "</turret_model>" + 
      "<turret_details>" + dir + turretItems["details"] + "</turret_details>" + 
      "<turret_details_alpha>" + dir + turretItems["alpha"] + "</turret_details_alpha>" + 
      "<turret_lightmap>" + dir + turretItems["lightmap"] + "</turret_lightmap>" + 
      "<paint_texture>" + dir + paintItems["texture"] + "</paint_texture>" +  
      "</response>";
      $(obj).find("param[name='flashvars']").attr('value', itemsXml);
      return obj;
    }
  };
  
  function fillDropdown(id){
    var _select = $("#"+id);
    _select.empty();
    var keys;
    
    if(_select.hasClass("select-parent")){
      _select.append($('<option disabled selected value="stub">Model</option>'));
      keys = Object.keys(viewer_data[_select.data("category")]);
    }
    if(_select.hasClass("select-child")){
      _select.append($('<option disabled selected value="stub">Grade</option>'));
      var _parent = $("#" + _select.data("parent"));
      var key = _parent.find("option:selected").val();
      keys = Object.keys(viewer_data[_parent.data("category")][key]);
    }
    
    $.each(keys, function(index, value) {
      _select.append($("<option />").val(value).text(value));
    });
  }
  
  function onTypeChanged(){
    fillDropdown($(this).data("child"));
    $("#" + $(this).data("child")).removeAttr("disabled").css("background-color", "");
  }
  
  function onSelectedChanged(){
    var flag = false;
    $(".TankPreview-select").each(function(i, el){flag = flag || ($(el).children(":selected").val() == "stub");});
    if(flag){
      $("#showTank").css("background-color", "#aaa").attr("disabled", "disabled");
      $("#showTank").off("click");
    } else {
      $("#showTank").css("background-color", "").removeAttr("disabled");
      $("#showTank").on("click", showTank);
    }
  }

  function showTank(){
    var tank = {
      "paintType": $this.data('paintType'),
      "paintModel": $this.data('paintModel'),
      "hullType": $("#hullType option:selected").val(),
      "hullModel": $("#hullModel option:selected").val(),
      "turretType": $("#turretType option:selected").val(),
      "turretModel": $("#turretModel option:selected").val()
    };
    $("#TankPreview").remove();
    $(".modal").append($(TankPreview.getViewer(tank))[0].outerHTML);
  }
}}

/*============================================================================================*/
//PrettySpoiler

if ($(".pretty-spoiler").length) {

  var texts = { OPEN: "Reveal hidden contents", CLOSE: "Hide contents" };
  
  $('.pretty-spoiler > .title').click(function() {
    var content = $(this).next('div');
    changeTitleState($(this), content.is(":visible"));
    content.slideToggle(300);
  });

  function changeTitleState(elem, state) {
    if(state){
      elem.css("background-color", "rgba(255,255,255,0.1)");
      elem.prop('title', texts.OPEN);
    } else {
      elem.css("background-color", "rgba(255,255,255,0.3)");
      elem.prop('title', texts.CLOSE);
    }
    elem.children('.title-arrow').toggleClass('rotate180');
  }
}

/*============================================================================================*/
/*Upgrades calculator*/

if($('.item-upgrades-block').length){
  
  var isMouseDown = false;

  $('.item-upgrades-block').each(function(k,v){
    $(this).append('<span class="calc-mode bg-dark"><input id="calc-cb_' + k + '" type="checkbox"><label for="calc-cb_' + k + '">Calculator mode</label><span class="discounts hidden"><label for="calc-discount-step_' + k + '"> Upgrade discount: </label><input type="number" pattern="[0-9]{1,2}" value="0" min="0" max="95" step="5" class="step" id="calc-discount-step_' + k + '" ">% <label for="calc-discount-speed_' + k + '"> Speed-up discount: </label><input type="number" pattern="[0-9]{1,2}" value="0" min="0" max="95" step="5" class="speed" id="calc-discount-speed_' + k + '" ">% <button class="wiki-control grey-gradient reset" >Reset</button></span></span>');
    setInitial($(this).find('.item-upgrades-table'));
  });
  
  $(".item-upgrades-block input[type='checkbox']").change(function() {
    var parent = $(this).parents('.item-upgrades-block');
    var table = parent.find('.item-upgrades-table');
    var inputs = parent.find('input[type="number"], input[type="text"]');
    if(this.checked) {
      parent.find('.discounts').show();
      parent.find('.reset').on('click', function(){ reset(parent, table, 'soft'); });
      inputs.on('change keyup input', function(){ 
        $(this).focus();
        applyDiscount(this, parent);
        $(this).focus();
      });
      table.find('.sum').show();
      
      $(['speed','delay','step']).each(function(k,v){
        var n = k + 1;
        table.find("tr:not(.nocalc) td:nth-last-child(" + n + ")").on('mousedown', function(event){ 
          if(event.which == 1 || event.which == undefined) calculate(this, parent, v);
          if(event.which == 1) isMouseDown = true;
          return false;
        }).trigger('mousedown').on('mouseover', function(){
          if(isMouseDown) calculate(this, parent, v);
          return false;
        });
      });
      refreshSumAll(table);

    } else {
      parent.find('.reset').off('click');
      inputs.off('change');
      reset(parent, table, 'hard');
      table.find('.sum').hide();
      parent.find('.discounts').hide();
    }
  });

  function calculate(_this, parent, type) {
    var $this = $(_this);
    $this.toggleClass("highlighted");
    switch(type){
      case 'step':
        var value = parseInt($this.text());
        var td = parent.find('td.step');
        if ($this.hasClass("highlighted")) { td.text(parseInt(td.text()) + value); } 
        else { td.text(parseInt(td.text()) - value); }
        refreshSumAll(parent);
        break;
      case 'speed':
        var value = parseInt($this.text());
        var td = parent.find('td.speed');
        if ($this.hasClass("highlighted")) { td.text(parseInt(td.text()) + value); } 
        else { td.text(parseInt(td.text()) - value); }
        refreshSumAll(parent);
        break;
      case 'delay':
        var td = parent.find('td.delay');
        if ($this.hasClass("highlighted")) { 
          td.text(getDelay(getMinutes(td.text()) + getMinutes($this.text()))); 
        } else { 
          td.text(getDelay(getMinutes(td.text()) - getMinutes($this.text())));
        }
        break;
    }
    return false;
  };
    
  function applyDiscount(_this, parent) {
    var $this = $(_this);
    var _val = $this.val();
    if(parseInt(_val) > 95) $this.val(95);
    if(parseInt(_val.split('')[0]) == 0 && _val.length > 1) $this.val(_val.split('')[1]);
    if(parseInt(_val) < 0 || isNaN(parseInt(_val))) $this.val(0);

    $this.prop('disabled', true);
    var type, tdSum;
    if ($this.hasClass('step')) {
      type = 3;
      tdSum = parent.find('td.step');
    } else if ($this.hasClass('speed')) {
      type = 1;
      tdSum = parent.find('td.speed');
    } else return;

    var cells = parent.find('tr:not(.nocalc) td:nth-last-child(' + type + ')');
    var discount = parseFloat(((100 - parseInt($this.val())) / 100).toFixed(2));
    var sum = 0;
    cells.each(function(){
      var cur = $(this);
      var initialValue = parseInt(cur.data('initial'));
      var newValue = Math.floor(initialValue * discount);
      cur.text(newValue);
      if(cur.hasClass('highlighted')) sum += newValue;
    });
    tdSum.text(sum);
    refreshSumAll(parent);
    $this.prop('disabled', false);
  }
    
  function reset(parent, table, type){
    var cells = getCells(table);
    if(type == 'hard'){
      cells.off('mousedown mouseover');
    }
    parent.find('.discounts input[type="number"]').val('0').text('');
    table.find('td.step').text('0');
    table.find('td.delay').text('0');
    table.find('td.speed').text('0');
    table.find('td.sumAll').text('0');
    cells.each(function(){
      $(this).removeClass('highlighted');
      $(this).text($(this).data('initial'));
    });
  }  
  
  function getCells(table){
    return table.find("tr:not(.nocalc) td:nth-last-child(3),"
                      + "tr:not(.nocalc) td:nth-last-child(2), "
                      + "tr:not(.nocalc) td:nth-last-child(1)"
                     );
  }
  
  function setInitial(table){
    getCells(table).each(function(){
      $(this).data('initial', $(this).text());
    });
  }

  function refreshSumAll(table){
    table.find('td.sumAll').html(
      parseInt(table.find('td.step').text()) + 
      parseInt(table.find('td.speed').text())
    );
  }
  
  function getMinutes(s){
    var res = 0;
    $(s.split(' ')).each(function(){
      if(this.indexOf('d') != -1) {
        res += 24 * 60 * parseInt(this);
      }
      if(this.indexOf('h') != -1) {
        res += 60 * parseInt(this);
      }
      if(this.indexOf('m') != -1) {
        res += parseInt(this);
      }
    });
    return res;
  }

  function getDelay(time){
    if(time == 0) {
      return 0;
    }
    if(time < 60) {
      return time + 'm';
    }
    if (time >= 60 && time < 1440) {
      var minutes = time % 60;
      var hours = (time - minutes) / 60;
      if (minutes != 0) {
        return hours + 'h ' + minutes + 'm';
      } else {
        return hours + 'h';
      }
    }
    if (time >= 1440) {
      var minutes = time % 60;
      var t = (time - minutes) / 60;
      var hours = t % 24;
      var days = (t - hours) / 24;
      if (minutes != 0 && hours != 0) {
        return days + 'd ' + hours + 'h ' + minutes + 'm';
      }
      if (minutes != 0 && hours == 0) {
        return days + 'd ' + minutes + 'm';
      }
      if (minutes == 0 && hours != 0) {
        return days + 'd ' + hours + 'h';
      }
      if (minutes == 0 && hours == 0) {
        return days + 'd';
      }
    }
  }
  $(document).mouseup(function () {
    isMouseDown = false;
  });
}

/*====================================================================================*/
//RndTxt Template

if ($('#RandomTextContainer').length) {
  var facts = $('#RandomTextContainer > div').toArray();
  $(getRandomVal(facts)).show();
  $('#RandomTextRefresher').click(function () {
    $(facts).hide();
    $(getRandomVal(facts)).show();
  })
}

/*====================================================================================*/
//Rank limits embedded iframe

if($("#RankLimits").length)
{
  $("#RankLimits").append("<iframe frameborder='0' style='width:844px;height:758px;' scrolling='no' src='https://docs.google.com/spreadsheets/d/1YK7-kS6MpvT23HDycI79zdFn3lCphG8iwrl-w_HPosY/pubhtml?gid=1621919985&single=true&widget=false&chrome=false&headers=false'></iframe>");
}

/*============================================================================================*/

$(".linkElem").on('click', function(){ window.open($(this).data("url"),"_blank"); });

/*jQuery(document).ready() ends here*/
});