Difference between revisions of "MediaWiki:Edittools.js"

From Learning Languages Through Video Games
Jump to navigationJump to search
Line 7: Line 7:
 
     var sel_start = textarea.selectionStart;
 
     var sel_start = textarea.selectionStart;
 
     var sel_end = textarea.selectionEnd;
 
     var sel_end = textarea.selectionEnd;
 +
    var len = textarea.value.length;
 
     var selected_text = textarea.value.substring(sel_start, sel_end);
 
     var selected_text = textarea.value.substring(sel_start, sel_end);
 
     if(!selected_text) {
 
     if(!selected_text) {
Line 12: Line 13:
 
         return;
 
         return;
 
     }
 
     }
     alert(selected_text);
+
     textarea.value = textarea.value(0, sel_start) + fixer(selected_text) + textarea.value(sel_end, len);
 
}
 
}
  
 
function fixJp(text) {
 
function fixJp(text) {
     alert(text);
+
     return "TESTING!!";
 
}
 
}
  

Revision as of 02:22, 20 October 2010

function runFixer(fixer) {
    var textarea = document.getElementById('wpTextbox1');
    if(textarea.selectionStart === undefined) {
        alert("Looks like the fixers won't work in this browser. If you're running Internet Explorer, well, that's why.");
        return;
    }
    var sel_start = textarea.selectionStart;
    var sel_end = textarea.selectionEnd;
    var len = textarea.value.length;
    var selected_text = textarea.value.substring(sel_start, sel_end);
    if(!selected_text) {
        alert("No text was selected!");
        return;
    }
    textarea.value = textarea.value(0, sel_start) + fixer(selected_text) + textarea.value(sel_end, len);
}

function fixJp(text) {
    return "TESTING!!";
}

addOnloadHook(function() {
    $j('#fixer-jp').append("<input type='button' onclick='runFixer(fixJp)' value='Tempt Fate' />");
});