(open in new tab class="pops") |
No edit summary |
||
(4 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
/* menu links */ | |||
/* menu links */ | |||
// In the function below, add more lines like "regexTool('link text','function_name()')" to add | // In the function below, add more lines like "regexTool('link text','function_name()')" to add | ||
// links to the sidebar menu. The function name is the function defined in rfmscripts() below. | // links to the sidebar menu. The function name is the function defined in rfmscripts() below. | ||
Line 135: | Line 125: | ||
//Open link in new tab class="pops" | //Open link in new tab class="pops" | ||
if (window.addEventListener) // W3C standard | |||
window.addEventListener('load', prepTargetBlank, false); // NB **not** 'onload' | |||
else if (window.attachEvent) // Microsoft | |||
window.attachEvent('onload', prepTargetBlank); | |||
function prepTargetBlank() { | |||
var pops = function( elems ) { | var pops = function( elems ) { | ||
for (var i=0; i<elems.length; i++) { | for (var i=0; i<elems.length; i++) { | ||
Line 142: | Line 138: | ||
} | } | ||
}; | }; | ||
var bc = document.getElementById(' | var bc = document.getElementById('content'); | ||
var tags = ['span', 'div', 'table', 'td', 'th']; | var tags = ['span', 'div', 'table', 'td', 'th']; | ||
for (var i=0; i<tags.length; i++) pops( bc.getElementsByTagName( tags[i] ) ); | for (var i=0; i<tags.length; i++) pops( bc.getElementsByTagName( tags[i] ) ); | ||
} | }; | ||
//End open in new tab | //End open in new tab |
Latest revision as of 19:51, 7 November 2020
/* menu links */ // In the function below, add more lines like "regexTool('link text','function_name()')" to add // links to the sidebar menu. The function name is the function defined in rfmscripts() below. function rmflinks() { regexTool('Custom regex','custom()'); // a default tool which performs regex input in a dynamic form } /* scripts */ // Below, define the functions linked to from rmflinks() above. These functions can use any JavaScript, // but there is a set of simplified tools documented at // http://meta.wikimedia.org/wiki/User:Pathoschild/Script:Regex_menu_framework . // End Regex menu framework stuff //Begin code template select stuff // // In each code block (identified by <div class="code">) // create a link which the reader can use to select // all the code in the code block for copy-and-paste // // code by Emanuele // //window.onload = add_code_select; if (window.addEventListener) // W3C standard window.addEventListener('load', add_code_select, false); // NB **not** 'onload' else if (window.attachEvent) // Microsoft window.attachEvent('onload', add_code_select); function add_code_select(){ var cont = document.getElementById('content'); var codes = getElementsByClass('code', cont, 'div'); if(codes != null){ for (var a in codes) { var aSpan = document.createElement('span'); var aLink = document.createElement('a'); var aText = document.createTextNode("Code: ["); aSpan.appendChild(aText); aSpan.className='code_select'; aText = document.createTextNode("Select"); aLink.appendChild(aText); aLink.onclick = new Function("return smfWikiSelectText(this,true)"); aLink.onmouseover=new Function("this.style.cursor='pointer'"); aLink.id = 'link_code_'+a; aSpan.appendChild(aLink); var aText = document.createTextNode("]"); aSpan.appendChild(aText); codes[a].insertBefore(aSpan, codes[a].firstChild); codes[a].id = 'code_'+a; } } } function getElementsByClass(searchClass,node,tag) { var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } } return classElements; } // Get the text in a code tag. function smfWikiSelectText(oElement, bActOnElement) { oCurElement = oElement.id.substr(5); // The place we're looking for is one div up, and next door - if it's auto detect. if (typeof(bActOnElement) == 'boolean' && bActOnElement) var oCodeArea = document.getElementById(oCurElement); else var oCodeArea = oCurElement.parentNode.nextSibling; var els = oCodeArea.getElementsByTagName('pre'); oCodeArea = els[0]; if (typeof(oCodeArea) != 'object' || oCodeArea == null) return false; // Start off with my favourite, internet explorer. if ('createTextRange' in document.body) { var oCurRange = document.body.createTextRange(); oCurRange.moveToElementText(oCodeArea); oCurRange.select(); } // Firefox at el. else if (window.getSelection) { var oCurSelection = window.getSelection(); // Safari is special! if (oCurSelection.setBaseAndExtent) { var oLastChild = oCodeArea.lastChild; oCurSelection.setBaseAndExtent(oCodeArea, 0, oLastChild, 'innerText' in oLastChild ? oLastChild.innerText.length : oLastChild.textContent.length); } else { var curRange = document.createRange(); curRange.selectNodeContents(oCodeArea); oCurSelection.removeAllRanges(); oCurSelection.addRange(curRange); } } return false; } // End code template select stuff //Open link in new tab class="pops" if (window.addEventListener) // W3C standard window.addEventListener('load', prepTargetBlank, false); // NB **not** 'onload' else if (window.attachEvent) // Microsoft window.attachEvent('onload', prepTargetBlank); function prepTargetBlank() { var pops = function( elems ) { for (var i=0; i<elems.length; i++) { if ( !(' '+elems[i].className+' ').match( / pops / ) ) continue; var anchs = elems[i].getElementsByTagName('a'); for (var j=0; j<anchs.length; j++) anchs[j].target = '_blank'; } }; var bc = document.getElementById('content'); var tags = ['span', 'div', 'table', 'td', 'th']; for (var i=0; i<tags.length; i++) pops( bc.getElementsByTagName( tags[i] ) ); }; //End open in new tab