Difference between revisions of "MediaWiki:Common.js"

From Observer GigaFlow Support | VIAVI Solutions Inc.
Jump to: navigation, search
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
+
GAMES
 +
MOVIES
 +
TV
 +
VIDEO
 +
WIKIS
 +
Search
  
$(function () {
+
START A WIKI
 +
Clash of Clans Wiki Editing MediaWiki:Common.js/AttackStrategies.js Need help editing?Notifications
 +
You do not have permission to edit this page, for the following reasons:
  
  var myElement = document.getElementById('calculator');
+
You are not allowed to execute the action you have requested.
  myElement.innerHTML = 'any HTML';
+
This page provides interface text for the software, and is protected to prevent abuse.
 +
Please log in to edit this wiki.
 +
Joining Clash of Clans Wiki is free, and it only takes a minute.
 +
We hope that you sign in, and become a member of the community!
  
}());
+
Click here to log in or create an account
 +
You can view and copy the source of this page:
  
$(function () {
 
  $('#calculator').html('any HTML');
 
}());
 
  
 +
function timeStamp_AttackStrategies_js() {
 +
  return "2014.07.20 00:47 (UTC-7)";
 +
}
  
$(function () {
+
window.onload = function() {
  $('#mw-mywiki-example').html('<div align="center">
+
  attackStrategyReset();
            <table width="80%" border="4">
+
};
                <tr><td colspan="2" align="center">Server Requirements</td></tr>
+
                <tr><td>Devices</td><td><input type="range" id="devices" value="10" min="10" max="1000" step="10" onchange="printSliderValue()" oninput="printSliderValue()"><input id="devicesvalue" type="text" size="5"></td></tr>
+
                <tr><td>Max Flows/second</td><td><input type="range" id="flows" value="1000" min="1000" max="50000" step="1000" onchange="printSliderValue()" oninput="printSliderValue()"><input id="flowsvalue" type="text" size="4"></td></tr>
+
            </table>
+
        </div>
+
        <div align="center">
+
            <table width="80%" border="4">
+
                <tr><td colspan="2" align="center">IO</td></tr>
+
                <tr><td><table ><thead><tr><th>Type</th><th>Requirement</th><th>Calculation</th></tr></thead>
+
                            <tr><td>Write MB/s</td><td><input type="text" id="writembps" size="6" disabled/></td><td>FlowsPerSecond*600Bytes</td></tr>
+
                            <tr><td>Write IOP/s</td><td><input type="text" id="writeiops" size="6" disabled/></td><td>20+(FlowsPerSecond/500)+(Devices/5)</td></tr>
+
                        </table></td></tr>
+
            </table>
+
        </div>
+
        <div align="center">
+
            <table width="80%" border="4">
+
                <tr><td colspan="2" align="center">Min Storage Required GB</td></tr>
+
                <tr><td><table><thead><tr><th>Type</th><th>Hour</th><th>Day</th><th>Week</th><th>Month</th><th>3 Months</th><th>Year</th></tr></thead>
+
                            <tr><td>Forensics Total</td><td><input type="text" id="forensicsh" size="6" disabled/></td><td><input type="text" id="forensicsd" size="6" disabled/></td><td><input type="text" id="forensicsw" size="6" disabled/></td><td><input type="text" id="forensicsm" size="6" disabled/></td><td><input type="text" id="forensicsq" size="6" disabled/></td><td><input type="text" id="forensicsy" size="6" disabled/></td></tr>
+
                            <tr><td>Forensics Per Device</td><td><input type="text" id="forensicshpd" size="6" disabled/></td><td><input type="text" id="forensicsdpd" size="6" disabled/></td><td><input type="text" id="forensicswpd" size="6" disabled/></td><td><input type="text" id="forensicsmpd" size="6" disabled/></td><td><input type="text" id="forensicsqpd" size="6" disabled/></td><td><input type="text" id="forensicsypd" size="6" disabled/></td></tr>
+
                        </table></td></tr>
+
            </table>
+
        </div>
+
        <div align="center">
+
            <table width="80%" border="4">
+
                <tr><td colspan="2" align="center">Min Memory Required GB</td><td><input type="text" id="memoryrequired"  size="6" disabled/></td></tr>
+
                <tr><td colspan="2" align="center">Min Cores Required</td><td><input type="text" id="coresrequired"  size="2" disabled/></td></tr>
+
  
            </table>
+
function attackStrategyFilter() {
        </div>
+
  var minTH      = document.getElementById("min-town-hall").value;
        <script>
+
  var maxTH      = document.getElementById("max-town-hall").value;
            printSliderValue('devices', 'devicesvalue');
+
  var minTrophies = document.getElementById("min-trophies").value;
            printSliderValue('flows', 'flowsvalue');
+
  var maxTrophies = document.getElementById("max-trophies").value;
        </script>
+
  var troopFilter = $('#troop-filter-text').html();
');
+
  var filterType  = $('#troop-filter-type-text').html();
 +
  var troops;
  
 +
  if (minTH === '')
 +
      minTH = 0;
 +
  else
 +
      minTH = Number(minTH);
  
 +
  if (maxTH === '')
 +
      maxTH = 99;
 +
  else
 +
      maxTH = Number(maxTH);
  
            function checkSizes() {
+
  if (minTrophies === '')
                var devices = document.getElementById("devices");
+
      minTrophies = 0;
                var maxallowedflows = 50000 - (25 * (parseInt(devices.value) - 20))
+
  else
                var flows = document.getElementById("flows");
+
      minTrophies = Number(minTrophies);
                if (parseInt(flows.value) > maxallowedflows) {
+
 
                    flows.value = maxallowedflows;
+
  if (maxTrophies === '')
                    document.getElementById("flowsvalue").value = maxallowedflows;
+
      maxTrophies = 999999;
                }
+
  else
                if (parseInt(flows.value) > 20000 || parseInt(devices.value) > 50) {
+
      maxTrophies = Number(maxTrophies);
                    document.getElementById("coresrequired").value = 16;
+
 
                } else {
+
  if (minTH < 0)
                    document.getElementById("coresrequired").value = 8;
+
      minTH = 0;
                }
+
 
 +
  if (maxTH < minTH)
 +
      maxTH = minTH;
 +
 
 +
  if (minTrophies < 0)
 +
      minTrophies = 0;
 +
 
 +
  if (maxTrophies < minTrophies)
 +
      maxTrophies = minTrophies;
 +
 
 +
  if (troopFilter.toLowerCase() === 'all')
 +
      troops = true;
 +
  else if (troopFilter.toLowerCase() === 'none')
 +
      troops = false;
 +
  else {
 +
      troops = troopFilter.split(', ');
 +
  }
 +
 
 +
  var tbl      = document.getElementById('attack-strategies-results');
 +
  var tr        = tbl.getElementsByTagName('tr');
 +
  var troopList = troopInfo('list', 'trainable');
 +
 
 +
  for (var i = 1; i < tr.length; i ++) {
 +
      var td              = tr[i].getElementsByClassName('attack-strategy-hidden-field');
 +
      var currMinTH      = Number(td[0].innerHTML);
 +
      var currMaxTH      = Number(td[1].innerHTML);
 +
      var currMinTrophies = Number(td[2].innerHTML);
 +
      var currMaxTrophies = Number(td[3].innerHTML);
 +
 
 +
      if (currMinTH > maxTH ||
 +
          currMaxTH < minTH ||
 +
          currMinTrophies > maxTrophies ||
 +
          currMaxTrophies < minTrophies)
 +
        $(tr[i]).css({'display': 'none'});
 +
      else if (troops === true && filterType === 'Includes')
 +
        $(tr[i]).css({'display': ''});
 +
      else if (troops === false && filterType === 'Excludes')
 +
        $(tr[i]).css({'display': ''});
 +
      else if (troops === true && filterType === 'Only')
 +
        $(tr[i]).css({'display': ''});
 +
      else if (troops === false && filterType === 'Includes')
 +
        $(tr[i]).css({'display': 'none'});
 +
      else if (troops === true && filterType === 'Excludes')
 +
        $(tr[i]).css({'display': 'none'});
 +
      else if (troops === false && filterType === 'Only')
 +
        $(tr[i]).css({'display': 'none'});
 +
      else if (filterType === 'Includes') {
 +
        var include = false;
 +
 
 +
        for (var j = 0; j < troops.length; j ++) {
 +
            var idx = tableIndex(troops[j]);
 +
 
 +
            if (idx >= 0 && td[idx].innerHTML === 'Yes') {
 +
              include = true;
 +
              break;
 
             }
 
             }
            function printSliderValue() {
+
        }
                checkSizes();
+
 
                document.getElementById("flowsvalue").value = document.getElementById("flows").value;
+
        $(tr[i]).css({'display': (include ? '' : 'none')});
                document.getElementById("devicesvalue").value = document.getElementById("devices").value;
+
      }
                var dayrate = (parseInt(document.getElementById("flowsvalue").value)) / (1000 * 1000) * 60 * 60 * 24 * .25;
+
      else if (filterType === 'Excludes') {
        document.getElementById("writembps").value = ((parseInt(flows.value)*.6)/1000).toFixed(2);       
+
        var include = true;
        document.getElementById("writeiops").value = (20+((parseInt(flows.value)/500))+(devices.value/5)).toFixed(2);       
+
 
       
+
        for (var j = 0; j < troops.length; j ++) {
       
+
            var idx = tableIndex(troops[j]);
        document.getElementById("forensicsh").value = (Math.ceil(dayrate) / 24).toFixed(2);
+
 
                document.getElementById("forensicsd").value = (Math.ceil(dayrate)).toFixed(2);
+
            if (idx >= 0 && td[idx].innerHTML === 'Yes') {
                document.getElementById("forensicsw").value = (Math.ceil(dayrate * 7)).toFixed(2);
+
              include = false;
                document.getElementById("forensicsm").value = (Math.ceil(dayrate * 31)).toFixed(2);
+
              break;
                document.getElementById("forensicsq").value = (Math.ceil(dayrate * 92)).toFixed(2);
+
                document.getElementById("forensicsy").value = (Math.ceil(dayrate * 366)).toFixed(2);
+
                document.getElementById("forensicshpd").value = (Math.ceil(dayrate) / 24 / devices.value).toFixed(2);
+
                document.getElementById("forensicsdpd").value = (Math.ceil(dayrate) / devices.value).toFixed(2);
+
                document.getElementById("forensicswpd").value = (Math.ceil(dayrate * 7) / devices.value).toFixed(2);
+
                document.getElementById("forensicsmpd").value = (Math.ceil(dayrate * 31) / devices.value).toFixed(2);
+
                document.getElementById("forensicsqpd").value = (Math.ceil(dayrate * 92) / devices.value).toFixed(2);
+
                document.getElementById("forensicsypd").value = (Math.ceil(dayrate * 366) / devices.value).toFixed(2);
+
                document.getElementById("memoryrequired").value = Math.ceil(4 + (0.05 * parseInt(document.getElementById("devices").value)));
+
 
             }
 
             }
 +
        }
 +
 +
        $(tr[i]).css({'display': (include ? '' : 'none')});
 +
      }
 +
      else if (filterType === 'Only') {
 +
        var include = false;
 +
 +
        for (var j = 0; j < troops.length; j ++) {
 +
            var idx = tableIndex(troops[j]);
 +
 +
            if (idx >= 0 && td[idx].innerHTML === 'Yes') {
 +
              include = true;
 +
              break;
 +
            }
 +
        }
 +
 +
        if (include) {
 +
            for (var j = 0; j < troopList.length; j ++) {
 +
              var idx = tableIndex(troopList[j]);
 +
 +
              if (!hasTroop(troopList[j]) && idx >= 0 && td[idx].innerHTML === 'Yes') {
 +
                  include = false;
 +
                  break;
 +
              }
 +
            }
 +
        }
 +
 +
        $(tr[i]).css({'display': (include ? '' : 'none')});
 +
      }
 +
      else {
 +
        $(tr[i]).css({'display': ''});
 +
      }
 +
  }
 +
 +
  function hasTroop(trooptype) {
 +
      if (troops === true || troops === false)
 +
        return troops;
 +
 +
      return troops.indexOf(trooptype) >= 0;
 +
  }
 +
 +
  function tableIndex(trooptype) {
 +
      var idx = $('#troop-filter-selector option[value="' + trooptype + '"]').index();
 +
      return (idx >= 0 ? idx + 4 : idx);
 +
  }
 +
}
 +
 +
function attackStrategyReset() {
 +
  document.getElementById("min-town-hall").value = 1;
 +
  document.getElementById("max-town-hall").value = '';
 +
  document.getElementById("min-trophies").value = 0;
 +
  document.getElementById("max-trophies").value = '';
 +
  document.getElementById("troop-filter-text").innerHTML = 'All';
 +
  document.getElementById("troop-filter-type-text").innerHTML = 'Includes';
 +
  document.getElementById("troop-filter-type-text").title =
 +
      'Will show all attack strategies that include at least one of the selected troop types.';
 +
  attackStrategyFilter();
 +
}
 +
 +
function troopFilterInitiate() {
 +
  doTroopSelect($('#troop-filter-text').html());
 +
  $('#troop-filter-type').val($('#troop-filter-type-text').html());
 +
  $('#troop-background').addClass('window-visible');
 +
}
 +
 +
function troopFilterCancel() {
 +
  $('#troop-background').removeClass('window-visible');
 +
}
 +
 +
function troopFilterExecute() {
 +
  var select    = $('#troop-filter-selector');
 +
  var all      = true;
 +
  var none      = true;
 +
  var selection = [];
 +
 +
  $('option', select).each(function(idx) {
 +
      if ($(this).prop('selected')) {
 +
        selection.push($(this).val());
 +
        none = false;
 +
      }
 +
      else
 +
        all = false;
 +
  });
 +
 +
  if (none)
 +
      $('#troop-filter-text').html('None');
 +
  else if (all)
 +
      $('#troop-filter-text').html('All');
 +
  else
 +
      $('#troop-filter-text').html(selection.join(', '));
 +
 +
  $('#troop-filter-type-text').html($('#troop-filter-type').val());
 +
 +
  switch ($('#troop-filter-type').val()) {
 +
      case 'Includes':
 +
        $('#troop-filter-type-text').prop('title',
 +
            'Will show all attack strategies that include at least one of the selected troop types.');
 +
        break;
 +
      case 'Excludes':
 +
        $('#troop-filter-type-text').prop('title',
 +
            'Will show all attack strategies that do not include any of the selected troop types.');
 +
        break;
 +
      case 'Only':
 +
        $('#troop-filter-type-text').prop('title',
 +
            'Will show all attack strategies that include only the selected troop types.');
 +
        break;
 +
  }
 +
 +
  troopFilterCancel();
 +
}
 +
 +
function troopSelectNone() {
 +
  doTroopSelect('none');
 +
}
 +
 +
function troopSelectAll() {
 +
  doTroopSelect('all');
 +
}
 +
 +
function doTroopSelect(selection) {
 +
  var select = $('#troop-filter-selector');
 +
 +
  if (selection.toLowerCase() === 'all')
 +
      $('option', select).prop('selected', true);
 +
  else if (selection.toLowerCase() === 'none')
 +
      $('option', select).prop('selected', false);
 +
  else {
 +
      var selects = selection.split(', ');
 +
 +
      $('option', select).each(function(idx) {
 +
        $(this).prop('selected', selects.indexOf($(this).val()) >= 0);
 +
      });
 +
  }
 +
}
 +
 +
Return to MediaWiki:Common.js/AttackStrategies.js.

Revision as of 11:01, 15 November 2018

GAMES
MOVIES
TV
VIDEO
WIKIS
Search

START A WIKI
 Clash of Clans Wiki Editing MediaWiki:Common.js/AttackStrategies.js Need help editing?Notifications
You do not have permission to edit this page, for the following reasons:

You are not allowed to execute the action you have requested.
This page provides interface text for the software, and is protected to prevent abuse.
Please log in to edit this wiki.
Joining Clash of Clans Wiki is free, and it only takes a minute.
We hope that you sign in, and become a member of the community!

Click here to log in or create an account
You can view and copy the source of this page:


function timeStamp_AttackStrategies_js() {
   return "2014.07.20 00:47 (UTC-7)";
}

window.onload = function() {
   attackStrategyReset();
};

function attackStrategyFilter() {
   var minTH       = document.getElementById("min-town-hall").value;
   var maxTH       = document.getElementById("max-town-hall").value;
   var minTrophies = document.getElementById("min-trophies").value;
   var maxTrophies = document.getElementById("max-trophies").value;
   var troopFilter = $('#troop-filter-text').html();
   var filterType  = $('#troop-filter-type-text').html();
   var troops;

   if (minTH === '')
      minTH = 0;
   else
      minTH = Number(minTH);

   if (maxTH === '')
      maxTH = 99;
   else
      maxTH = Number(maxTH);

   if (minTrophies === '')
      minTrophies = 0;
   else
      minTrophies = Number(minTrophies);

   if (maxTrophies === '')
      maxTrophies = 999999;
   else
      maxTrophies = Number(maxTrophies);

   if (minTH < 0)
      minTH = 0;

   if (maxTH < minTH)
      maxTH = minTH;

   if (minTrophies < 0)
      minTrophies = 0;

   if (maxTrophies < minTrophies)
      maxTrophies = minTrophies;

   if (troopFilter.toLowerCase() === 'all')
      troops = true;
   else if (troopFilter.toLowerCase() === 'none')
      troops = false;
   else {
      troops = troopFilter.split(', ');
   }

   var tbl       = document.getElementById('attack-strategies-results');
   var tr        = tbl.getElementsByTagName('tr');
   var troopList = troopInfo('list', 'trainable');

   for (var i = 1; i < tr.length; i ++) {
      var td              = tr[i].getElementsByClassName('attack-strategy-hidden-field');
      var currMinTH       = Number(td[0].innerHTML);
      var currMaxTH       = Number(td[1].innerHTML);
      var currMinTrophies = Number(td[2].innerHTML);
      var currMaxTrophies = Number(td[3].innerHTML);

      if (currMinTH > maxTH ||
          currMaxTH < minTH ||
          currMinTrophies > maxTrophies ||
          currMaxTrophies < minTrophies)
         $(tr[i]).css({'display': 'none'});
      else if (troops === true && filterType === 'Includes')
         $(tr[i]).css({'display': ''});
      else if (troops === false && filterType === 'Excludes')
         $(tr[i]).css({'display': ''});
      else if (troops === true && filterType === 'Only')
         $(tr[i]).css({'display': ''});
      else if (troops === false && filterType === 'Includes')
         $(tr[i]).css({'display': 'none'});
      else if (troops === true && filterType === 'Excludes')
         $(tr[i]).css({'display': 'none'});
      else if (troops === false && filterType === 'Only')
         $(tr[i]).css({'display': 'none'});
      else if (filterType === 'Includes') {
         var include = false;

         for (var j = 0; j < troops.length; j ++) {
            var idx = tableIndex(troops[j]);

            if (idx >= 0 && td[idx].innerHTML === 'Yes') {
               include = true;
               break;
            }
         }

         $(tr[i]).css({'display': (include ? '' : 'none')});
      }
      else if (filterType === 'Excludes') {
         var include = true;

         for (var j = 0; j < troops.length; j ++) {
            var idx = tableIndex(troops[j]);

            if (idx >= 0 && td[idx].innerHTML === 'Yes') {
               include = false;
               break;
            }
         }

         $(tr[i]).css({'display': (include ? '' : 'none')});
      }
      else if (filterType === 'Only') {
         var include = false;

         for (var j = 0; j < troops.length; j ++) {
            var idx = tableIndex(troops[j]);

            if (idx >= 0 && td[idx].innerHTML === 'Yes') {
               include = true;
               break;
            }
         }

         if (include) {
            for (var j = 0; j < troopList.length; j ++) {
               var idx = tableIndex(troopList[j]);

               if (!hasTroop(troopList[j]) && idx >= 0 && td[idx].innerHTML === 'Yes') {
                  include = false;
                  break;
               }
            }
         }

         $(tr[i]).css({'display': (include ? '' : 'none')});
      }
      else {
         $(tr[i]).css({'display': ''});
      }
   }

   function hasTroop(trooptype) {
      if (troops === true || troops === false)
         return troops;

      return troops.indexOf(trooptype) >= 0;
   }

   function tableIndex(trooptype) {
      var idx = $('#troop-filter-selector option[value="' + trooptype + '"]').index();
      return (idx >= 0 ? idx + 4 : idx);
   }
}

function attackStrategyReset() {
   document.getElementById("min-town-hall").value = 1;
   document.getElementById("max-town-hall").value = '';
   document.getElementById("min-trophies").value = 0;
   document.getElementById("max-trophies").value = '';
   document.getElementById("troop-filter-text").innerHTML = 'All';
   document.getElementById("troop-filter-type-text").innerHTML = 'Includes';
   document.getElementById("troop-filter-type-text").title =
      'Will show all attack strategies that include at least one of the selected troop types.';
   attackStrategyFilter();
}

function troopFilterInitiate() {
   doTroopSelect($('#troop-filter-text').html());
   $('#troop-filter-type').val($('#troop-filter-type-text').html());
   $('#troop-background').addClass('window-visible');
}

function troopFilterCancel() {
   $('#troop-background').removeClass('window-visible');
}

function troopFilterExecute() {
   var select    = $('#troop-filter-selector');
   var all       = true;
   var none      = true;
   var selection = [];

   $('option', select).each(function(idx) {
      if ($(this).prop('selected')) {
         selection.push($(this).val());
         none = false;
      }
      else
         all = false;
   });

   if (none)
      $('#troop-filter-text').html('None');
   else if (all)
      $('#troop-filter-text').html('All');
   else
      $('#troop-filter-text').html(selection.join(', '));

   $('#troop-filter-type-text').html($('#troop-filter-type').val());

   switch ($('#troop-filter-type').val()) {
      case 'Includes':
         $('#troop-filter-type-text').prop('title',
            'Will show all attack strategies that include at least one of the selected troop types.');
         break;
      case 'Excludes':
         $('#troop-filter-type-text').prop('title',
            'Will show all attack strategies that do not include any of the selected troop types.');
         break;
      case 'Only':
         $('#troop-filter-type-text').prop('title',
            'Will show all attack strategies that include only the selected troop types.');
         break;
   }

   troopFilterCancel();
}

function troopSelectNone() {
   doTroopSelect('none');
}

function troopSelectAll() {
   doTroopSelect('all');
}

function doTroopSelect(selection) {
   var select = $('#troop-filter-selector');

   if (selection.toLowerCase() === 'all')
      $('option', select).prop('selected', true);
   else if (selection.toLowerCase() === 'none')
      $('option', select).prop('selected', false);
   else {
      var selects = selection.split(', ');

      $('option', select).each(function(idx) {
         $(this).prop('selected', selects.indexOf($(this).val()) >= 0);
      });
   }
}

Return to MediaWiki:Common.js/AttackStrategies.js.