FANDOM


Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Chrome - Windows: Hold the Ctrl key and press the F5 key. OS X: Hold both the ⌘ Cmd and ⇧ Shift keys and press the R key.
  • Safari - Hold down the ⇧ Shift key and click the Reload toolbar button.
  • Firefox - Windows: Hold the Ctrl key, and press F5. OS X: Hold the ⌘ Cmd and ⇧ Shift keys, and then press R.
  • Internet Explorer - Hold the Ctrl key, and press F5 (or click the Refresh button).
// ==== List Columnizer ====
// Mostly written by Splarka - // Version 0.0.1 beta
// Breaks large lists of text in the wiki textarea into multicolumn tables using templates that you define (below).
// Features
//  * Suggests evenly divisible columns
//  * Removes blank lines at the end
//  * Has an undo button
// Current limitations
//  * Number of columns      : 2-10 (easily changed)
//  * Min number of elements : 11
//  * String space           : browser
//  * Number of template tags: 3 (start/middle/end)
//  * Parameterized first tag: not yet
//  * Requires the full edit window, will listify *everything*
 
addOnloadHook(columnbutton);
var colStart = '{{MultiCol}}';
var colMid = '{{ColBreak}}';
var colEnd = '{{EndMultiCol}}';
 
function columnbutton() {
    if(!document.getElementById('wpTextbox1')) return;
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    if(document.getElementById('wpTextbox1').value.indexOf(colStart) == -1) {
        addlilink(tabs, 'javascript:columns()', 'columns', 'ca-columns');
    } else {
        addlilink(tabs, 'javascript:columnsoff()', 'undo columns', 'ca-columns');
    }
}
 
function columns() {
    var lines = document.getElementById('wpTextbox1').value.split('\n');
    if(lines.length < 11) {
        alert('Oh come on, there are only ' + lines.length + ' lines.\nYou can do that many yourself!');
        return;
    }
 
    for(var i = lines.length; i > 1; i--) {
        if(lines[lines.length -1] == '') { 
            lines.length = lines.length - 1;
        } else {
            break; // remove this to strip all blank lines, default is just at the end
        }
    }
 
    var evendiv = '';
    for(var i = 2; i < 11; i++) {
        if(lines.length % i == 0) evendiv = evendiv + ' /' + i
    }
    if(evendiv.length != 0) evendiv = 'This divides evenly by: ' + evendiv + '\n'
 
    var numcol = prompt('There are currently ' + lines.length + ' lines.\n' + evendiv + 'Enter a number of columns from 2 to 10:','3')
    if((isNaN(numcol))||(numcol > 10)||(numcol < 2)) { 
        alert('Invalid number or cancellation.');
        return;
    }
 
    if(lines.length % numcol == 0) {
        collen = lines.length / numcol;
    } else {
        collen = Math.ceil(lines.length / numcol);
    }
 
    var tag=colStart;
    for(var i = 0; i < numcol; i++) {
        lines.splice(collen * i + i,0,tag);
        tag=colMid;
    }
    lines[lines.length] = colEnd;
    document.getElementById('wpTextbox1').value = lines.join('\n');
    document.getElementById('ca-columns').innerHTML = 'undo columns';
    document.getElementById('ca-columns').href = 'javascript:columnsoff()';
}
 
function columnsoff() {
    document.getElementById('ca-columns').innerHTML = 'columns';
    document.getElementById('ca-columns').href = 'javascript:columns()';
 
    var lines = document.getElementById('wpTextbox1').value.split('\n');
    var totag = 0
    for(var i = 0; i < lines.length; i++) {
        if((lines[i] == colStart)||(lines[i] == colMid)||(lines[i] == colEnd)) {
            lines.splice(i,1);
            i--;
            totag++;
        }
    }
    alert(totag + ' column tags removed.');
    document.getElementById('wpTextbox1').value = lines.join('\n')
}
 
function addlilink(tabs, url, name, id) {
    var na = document.createElement('a');
    na.href = url;
    na.id = id;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.appendChild(na);
    tabs.appendChild(li);
    return li;
}
 
// ==== End List Columnizer ====
Community content is available under CC-BY-SA unless otherwise noted.