MediaWiki:Common.js: Difference between revisions

From Elanthipedia
Jump to navigation Jump to search
(Blanked the page)
(Adding Select All button to scripts)
Line 1: Line 1:
jQuery.fn.selectText = function(){
var doc = document;
var element = this[0];
//console.log(this, element);
if (doc.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
};

$(function () {
$("pre:not(.no-select)").each(function() {
var pre = this;
var link = $("<a href='#'>(Select All)</a>").on("click", function(event) {
$(pre).selectText();
event.preventDefault();
});
link.insertBefore(this);}
);
});

Revision as of 21:31, 28 April 2020

jQuery.fn.selectText = function(){
    var doc = document;
    var element = this[0];
    //console.log(this, element);
    if (doc.body.createTextRange) {
        var range = document.body.createTextRange();
        range.moveToElementText(element);
        range.select();
    } else if (window.getSelection) {
        var selection = window.getSelection();        
        var range = document.createRange();
        range.selectNodeContents(element);
        selection.removeAllRanges();
        selection.addRange(range);
    }
};

$(function () {
    $("pre:not(.no-select)").each(function() { 
        var pre = this; 
        var link = $("<a href='#'>(Select All)</a>").on("click", function(event) { 
            $(pre).selectText();
            event.preventDefault(); 
        }); 
        link.insertBefore(this);}
    );
});