MediaWiki:Index.js

//Compile into array, execute command on array - php. ajax success to move to next on array. // {Table, Function} < -- Add, Remove, Filter (Only w/ cat) //Arrays for testing purposes var array0 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11.5] var array1 = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20] var array2 = [0, 2, 4, 6, 8, 10] var array3 = [1, 3, 5, 7, 9] var array4 = [0, 3, 6, 9] var array5 = [11, 12] var array6 = [13, 14] var array7 = [16, 17] var array8 = [18, 19] var array9 = [20, 15] var arraylist = [array0, array1, array2, array3, array4, array5, array6, array7, array8, array9] var mainarray = array0 //Array selection $(document).ready(function { var element = $('#Submit')  element.click(function(element) { var commands = $('#index-units').children; var output = $('#index-units').children("#index-output"); Index(commands, output); }); }); // The guts function Index(commands, output) { //Master function to hold the local integer //incase we want to run multiple instances of this script var i = -1 //Primary integer loadNext(commands, output, []); //Main looping function. Forces the async/ajax calls to run in-order. function loadNext(commands, output, mainarray) { if (i < commands.length) { // Sets the length of the loop var array = arraylist[$(commands[i]).data("array")]; var mode = $(commands[i]).data("command") $.ajax({       url: '/echo/js/?js=hello%20world!',        complete: function(response) {          var temp = [];          if (mode != 'add') {            for (var ii = 0; ii < mainarray.length; ii++) {              var a = mainarray[ii]              var match = false              for (var iii = 0; iii < array.length; iii++) {                var b = array[iii]                if (a == b) {                  match = true                }              }              if (mode == "remove" && match == false) {                temp.push(a);              } else if (mode == "filter" && match == true) {                temp.push(a);              }            }          } else {            temp = array          }          alert(i + '    ' + $(commands[i]).attr('id') + '   ' + $(commands[i]).data('command'));          output.text(temp);          loadNext(commands, output, temp);        },        error: function { alert('error') },     });      i++;    }  } }