WikEd

edit
This user edits with the gadget wikEd.




Custom Table Add

edit

The following code adds a button which shows a div where you can select how many colums x rows a new table must be.
 

Custom button:

wikEdButton[101] = ['tableImg', 'wikEdButton', 'Add custom table', 'http://upload.wikimedia.org/wikipedia/commons/b/bd/WikEd_table.png', '16', '16', 'Add custom table', 'javascript:WikEdEditButton(this, this.id, null, showTableAdd);' ];

Custom function:

/*** framework ***/
// used other functions from US_functions, which you can find here: http://userscripts.org/scripts/show/16142
function $isInt(n,way){if(way==true){var reg=/^[0-9]+$/;}else if(way==false){var reg=/^-[0-9]+$/;}else{var reg=/^-?[0-9]+$/;}return reg.test(n.toString());}
String.prototype.firstLetterCapital=function(){return this.toString().substr(0,1).toUpperCase()+this.toString().toLowerCase().substr(1,this.toString().length);};

/*** script ***/
var tableClicked=false;
var defXas=5, defYas=4;
var curXas=5, curYas=4;

function showTableAdd(obj){
/*     WikEdGetText(obj, 'selection, cursor');
    if (obj.selection.plain != '') {
        obj.changed = obj.selection;
    }
    else {
        obj.changed = obj.cursor;
    } */
    WikEdGetText(obj, 'cursor');
        obj.changed = obj.cursor;
    obj.changed.plain=" ";
    obj.changed.keepSel = true;
    $addCSS("div#tableAdd{position:absolute;border:1px solid gray;background-color:white;}div#tableNote{position:relative;width:auto;background-color:white;text-align:center;}table#tableAddTable{width: auto;height:auto;border-spacing:1px;}#tableAddTable tr{background-color:white;border:1px solid gray;}#tableAddTable td{font-size:1px;border:1px solid gray;background-color:white;width:13px;/* FF&O -> 16px */height:17px;/* FF&O -> 16px */}#tableAddTable td:hover{background-color: #316ac5;}");
    drawTable(defXas,defYas);
    return;
};
function drawTable(cols,rows){
    if(!$gi('tableAdd')){
        var addDivMain=$ce("div");
        addDivMain.id="tableAdd";
        var addDivDraw=$ce("div");
        addDivDraw.id="tableDraw";
        var addDivNote=$ce("div");
        addDivNote.id="tableNote";
        addDivNote.innerHTML=wikEdControlChars[24].firstLetterCapital();
        
        var addTbl=$ce("table");
        addTbl.id="tableAddTable";
        for(i=0;i<rows;i++){5
            var addTR=addTbl.insertRow(i);
            for(j=0;j<cols;j++){
                var addTD=addTR.insertCell(j); 
                $ac(addTD,document.createTextNode(' '));  // can't use .innerHTML because of IE bug;
                $addEvent(addTD,"mouseover",function(){highlightCellsOver(this.parentNode.rowIndex,this.cellIndex);});
                $addEvent(addTD,"mouseout",function(){highlightCellsOut(this.parentNode.rowIndex,this.cellIndex);});
                $addEvent(addTD,"mouseup",function(){WikEdEditButton(this, this.id, null, addTable);});
                $addEvent(addTD,"mousedown",function(){highlightDrag(this.parentNode.rowIndex,this.cellIndex);});
            }
        }
        
        $ac($gi('wikEdButtonsWrapper'),addDivMain);
        $ac(addDivMain,addDivDraw);
        $ac(addDivMain,addDivNote);
        $ac(addDivDraw,addTbl);
        
        var tableImgHeight=$isInt($getStyle($gi("tableImg"),"height").replace("px",""))?$getStyle($gi("tableImg"),"height").replace("px",""):16;
        $gi("tableAdd").style.top=($gi("tableImg").offsetTop + Number(tableImgHeight)) + "px";
        $gi("tableAdd").style.left=$gi("tableImg").offsetLeft + "px";
        $gi("tableAdd").style.position="absolute";
        
        theTable=$gi("tableAddTable");
        tableBody=theTable.tBodies[0]?theTable.tBodies[0]:theTable;
    }
    else {
        $hs($gi('tableAdd'),3)
    }
};
function insertColumn(){
    for(var k=0;k<tableBody.rows.length;k++) {
        oneRow=tableBody.rows[k];
        newCell=oneRow.insertCell(0);
        $ac(newCell,document.createTextNode(' '));
        $addEvent(newCell,"mouseover",function(){highlightCellsOver(this.parentNode.rowIndex,this.cellIndex);});
        $addEvent(newCell,"mouseout",function(){highlightCellsOut(this.parentNode.rowIndex,this.cellIndex);});
        $addEvent(newCell,"mouseup",function(){WikEdEditButton(this, this.id, null, addTable);});
        $addEvent(newCell,"mousedown",function(){highlightDrag(this.parentNode.rowIndex,this.cellIndex);});
    }
};
function insertRow(){
    var oneRowX=tableBody.insertRow(tableBody.rows.length);
    for(var l=0;l<tableBody.rows[0].cells.length;l++){
        newCellX=oneRowX.insertCell(0);
        $ac(newCellX,document.createTextNode(' '));
        $addEvent(newCellX,"mouseover",function(){highlightCellsOver(this.parentNode.rowIndex,this.cellIndex);});
        $addEvent(newCellX,"mouseout",function(){highlightCellsOut(this.parentNode.rowIndex,this.cellIndex);});
        $addEvent(newCellX,"mouseup",function(){WikEdEditButton(this, this.id, null, addTable);});
        $addEvent(newCellX,"mousedown",function(){highlightDrag(this.parentNode.rowIndex,this.cellIndex);});
    }
};
function highlightCellsOut(xas,yas){
    for(var mx=0;mx<xas+1;mx++){
        for(var ny=0;ny<yas+1;ny++){
            tableBody.rows[mx].cells[ny].style.backgroundColor="white";
        }
    }
    tableBody.rows[xas].cells[yas].style.backgroundColor="white";
    $gi("tableNote").innerHTML=wikEdControlChars[24].firstLetterCapital();;
};
function highlightCellsOver(xas,yas){
    curXas=xas;
    curYas=yas;
    for(var ox=0;ox<xas+1;ox++){
        for(var py=0;py<yas+1;py++){
            tableBody.rows[ox].cells[py].style.backgroundColor="green";
        }
    }
    tableBody.rows[xas].cells[yas].style.backgroundColor="green";
    $gi("tableNote").innerHTML=(xas+1) + " x " + (yas+1) + " " + wikEdText['wikEdTable title'].toLowerCase();
    if(tableClicked)highlightDrag(xas,yas);
};
function highlightDrag(xas,yas){
    tableClicked=true;
    if(xas==(tableBody.rows.length-1)){
        insertRow();
    }
    if(yas==(tableBody.rows[0].cells.length-1)){
        insertColumn();
    }
};
function addTable(obj,xas,yas){
    if(!xas)xas=curXas;
    if(!yas)yas=curYas;
    xas=xas+1;
    yas=yas+1;
    
    tableInput="{| class='wikitable'\n";
    tableInput+='|+ <span class="wikEdInsertHere">' + wikEdText['table caption'] + '</span>\n';
    tableInput+='! <span class="wikEdinserthere">' + wikEdText['table heading'] + '</span>';
    for(var qy=1;qy<yas;qy++){
        tableInput+=' !! <span class="wikEdInsertHere">' + wikEdText['table heading'] + '</span>';
    }
    tableInput+="\n";
    for(var rx=0;rx<xas;rx++){
        tableInput+="|-\n";
        tableInput+='| <span class="wikEdInsertHere">' + wikEdText['table cell'] + '</span>';
        for(var sy=1;sy<yas;sy++){
            tableInput+=' || <span class="wikEdInsertHere">' + wikEdText['table cell'] + '</span>';
        }
        tableInput+="\n";
    }
    tableInput+="|}";
    
    WikEdGetText(obj, 'selection, cursor');
    if (obj.selection.plain != '') {
        obj.changed = obj.selection;
    }
    else {
        obj.changed = obj.cursor;
    }
    obj.changed.plain = "\n" + tableInput + "\n";
    obj.changed.keepSel = false;
    $gi("tableAdd").parentNode.removeChild($gi("tableAdd"));
    tableClicked=false;
    return;
};


Custom Block Quote

edit

The following code adds blockquote.

Custom button:

wikEdButton[102] = ['blockquote', 'wikEdButton', 'Adds blockqoute', 'http://img509.imageshack.us/img509/6253/blockquotelw7.png', '16', '16', 'Adds blockqoute', 'javascript:WikEdEditButton(this, this.id, null, addBlockqoute);' ];

Custom function:

function addBlockqoute(obj) {
    WikEdGetText(obj, 'selection, cursor');
    if (obj.selection.plain != '') {
        obj.changed = obj.selection;
    }
    else {
        obj.changed = obj.cursor;
    }
    obj.changed.plain = '<blockqoute>' + obj.changed.plain + '</blockqoute>';
    obj.changed.keepSel = true;
    return;
}


Custom Signature

edit

The following code adds your signature.

Custom button:

wikEdButton[103] = ['signature', 'wikEdButton', 'Add your signature', 'http://img512.imageshack.us/img512/8158/signaturegp1.png', '16', '16', 'Add your signature', 'javascript:WikEdEditButton(this, this.id, null, signature);' ];

Custom function:

function signature(obj) {
    WikEdGetText(obj, 'cursor');
    obj.changed = obj.cursor;
    obj.changed.plain = ' --~~~~';
    return;
}


Custom Print Page

edit

The following code directs you to the print page.

Custom button:

wikEdButton[104] = ['printPage', 'wikEdButton', 'Print orginal page', 'http://img178.imageshack.us/img178/9848/printzw2.png', '16', '16', 'Print orginal page', 'javascript:WikEdEditButton(this, this.id, null, printPage);' ];

Custom function:

function printPage(){
    window.location.href = "http://live.msgdiscovery.com/wiki/index.php?title=" + wikEdWikiGlobals['wgTitle'] + "&printable=yes";
}


Custom Code Tags

edit

The following code adds code tags.

Custom button:

wikEdButton[105] = ['codeTags', 'wikEdButton', 'Add code tags', 'http://img98.imageshack.us/img98/3057/codegp5.png', '16', '16', 'Add code tags', 'javascript:WikEdEditButton(this, this.id, null, codeTags);' ];

Custom function:

function codeTags(obj){
    WikEdGetText(obj, 'selection, cursor');
    if (obj.selection.plain != '') {
        obj.changed = obj.selection;
    }
    else {
        obj.changed = obj.cursor;
    }
    obj.changed.plain = '<code>' + obj.changed.plain + '</code>';
    obj.changed.keepSel = true;
    return;
}


Custom Pre Tags

edit

The following code adds pre tags.

Custom button:

wikEdButton[106] = ['preTags', 'wikEdButton', 'Add pre tags', 'http://img84.imageshack.us/img84/8696/preti8.png', '16', '16', 'Add pre tags', 'javascript:WikEdEditButton(this, this.id, null, preTags);' ];

Custom function:

function preTags(obj){
    WikEdGetText(obj, 'selection, cursor');
    if (obj.selection.plain != '') {
        obj.changed = obj.selection;
    }
    else {
        obj.changed = obj.cursor;
    }
    obj.changed.plain = '<pre>' + obj.changed.plain + '</pre>';
    obj.changed.keepSel = true;
    return;
}


Custom Horizontal Line

edit

The following code adds a horizontal line.

Custom button:

wikEdButton[107] = ['horLine', 'wikEdButton', 'Add horizontal line', 'http://img146.imageshack.us/img146/2171/horizontallineyy6.png', '16', '16', 'Add horizontal line', 'javascript:WikEdEditButton(this, this.id, null, horLine);' ];

Custom function:

function horLine(obj){
    WikEdGetText(obj, 'focusLine, cursor');
    obj.changed = obj.cursor;
    if(obj.focusLine.plain==''){
        obj.changed.plain = '----';
    }
    else{
        obj.changed.plain = '\n----';
    }
    obj.changed.keepSel = false;
    return;
}


Custom Noinclude

edit

The following code adds noinclude tags.

Custom button:

wikEdButton[108] = ['noInclude', 'wikEdButton', 'Add noinclude tags', 'http://img239.imageshack.us/img239/9867/noincludeqb0.png', '16', '16', 'Add noinclude tags', 'javascript:WikEdEditButton(this, this.id, null, noInclude);' ];

Custom function:

function noInclude(obj){
    WikEdGetText(obj, 'selection, cursor');
    if (obj.selection.plain != '') {
        obj.changed = obj.selection;
    }
    else {
        obj.changed = obj.cursor;
    }
    obj.changed.plain = '<noinclude>' + obj.changed.plain + '</noinclude>';
    obj.changed.keepSel = true;
    return;
}


Custom Includeonly

edit

The following code adds includeonly tags.

Custom button:

wikEdButton[109] = ['includeOnly', 'wikEdButton', 'Add includeonly tags', 'http://img412.imageshack.us/img412/948/includeonlych9.png', '16', '16', 'Add includeonly tags', 'javascript:WikEdEditButton(this, this.id, null, includeOnly);' ];

Custom function:

function includeOnly(obj){
    WikEdGetText(obj, 'selection, cursor');
    if (obj.selection.plain != '') {
        obj.changed = obj.selection;
    }
    else {
        obj.changed = obj.cursor;
    }
    obj.changed.plain = '<includeonly>' + obj.changed.plain + '</includeonly>';
    obj.changed.keepSel = true;
    return;
}


Custom Hidden Comment

edit

The following code adds a hidden comment.

Custom button:

wikEdButton[110] = ['hiddenComment', 'wikEdButton', 'Add a hidden comment', 'http://img138.imageshack.us/img138/3255/hiddencommentsl2.png', '16', '16', 'Add a hidden comment', 'javascript:WikEdEditButton(this, this.id, null, hiddenComment);' ];

Custom function:

function hiddenComment(obj){
    WikEdGetText(obj, 'selection, cursor');
    if (obj.selection.plain != '') {
        obj.changed = obj.selection;
    }
    else {
        obj.changed = obj.cursor;
    }
    obj.changed.plain = '<!--' + obj.changed.plain + '-->';
    obj.changed.keepSel = true;
    return;
}


edit

The following code adds a plain link.

Custom button:

wikEdButton[111] = ['plainLinks', 'wikEdButton', 'Add a plain link', 'http://img523.imageshack.us/img523/7645/linkcj3.png', '16', '16', 'Add a plain link', 'javascript:WikEdEditButton(this, this.id, null, plainLinks);' ];

Custom function:

function plainLinks(obj){
    WikEdGetText(obj, 'selection, cursor');
    if (obj.selection.plain != '') {
        obj.changed = obj.selection;
    }
    else {
        obj.changed = obj.cursor;
    }
    obj.changed.plain = '<span class="plainlinks" >' + obj.changed.plain + '</span>';
    obj.changed.keepSel = true;
    return;
}


Custom File

edit

The following code adds a file.

Custom button:

wikEdButton[112] = ['addFile', 'wikEdButton', 'Add a file', 'http://img413.imageshack.us/img413/8151/filepl4.png', '16', '16', 'Add a file', 'javascript:WikEdEditButton(this, this.id, null, addFile);' ];

Custom function:

function addFile(obj){
    WikEdGetText(obj, 'selection, cursor');
    if (obj.selection.plain != '') {
        obj.changed = obj.selection;
    }
    else {
        obj.changed = obj.cursor;
    }
    obj.changed.plain = '[[Media:' + obj.changed.plain + ']]';
    obj.changed.keepSel = true;
    return;
}


edit

The following code adds an image gallery.

Custom button:

wikEdButton[113] = ['imageGallery', 'wikEdButton', 'Add a image gallery', 'http://img247.imageshack.us/img247/5619/imagegalleryop8.png', '16', '16', 'Add a image gallery', 'javascript:WikEdEditButton(this, this.id, null, imageGallery);' ];

Custom function:

function imageGallery(obj){
    WikEdGetText(obj, 'selection, cursor');
    if (obj.selection.plain != '') {
        obj.changed = obj.selection;
    }
    else {
        obj.changed = obj.cursor;
    }
    obj.changed.plain = '<gallery>\nImage:<span class="wikEdInsertHere">Example1.jpg</span>|<span class="wikEdInsertHere">Caption1</span>\nImage:<span class="wikEdInsertHere">Example2.jpg</span>|<span class="wikEdInsertHere">Caption2</span>\n</gallery>';
    obj.changed.keepSel = true;
    return;
}


Custom ###

edit

The following code adds ###.

Custom button:


Custom function:


Jeronevw (talk) 15:16, 12 April 2008 (UTC)