📄 wikibits.js
字号:
range.select(); //restore window scroll position if (document.documentElement && document.documentElement.scrollTop) document.documentElement.scrollTop = winScroll else if (document.body) document.body.scrollTop = winScroll; } else if (txtarea.selectionStart || txtarea.selectionStart == '0') { // Mozilla //save textarea scroll position var textScroll = txtarea.scrollTop; //get current selection txtarea.focus(); var startPos = txtarea.selectionStart; var endPos = txtarea.selectionEnd; selText = txtarea.value.substring(startPos, endPos); //insert tags checkSelectedText(); txtarea.value = txtarea.value.substring(0, startPos) + tagOpen + selText + tagClose + txtarea.value.substring(endPos, txtarea.value.length); //set new selection if (isSample) { txtarea.selectionStart = startPos + tagOpen.length; txtarea.selectionEnd = startPos + tagOpen.length + selText.length; } else { txtarea.selectionStart = startPos + tagOpen.length + selText.length + tagClose.length; txtarea.selectionEnd = txtarea.selectionStart; } //restore textarea scroll position txtarea.scrollTop = textScroll; } function checkSelectedText(){ if (!selText) { selText = sampleText; isSample = true; } else if (selText.charAt(selText.length - 1) == ' ') { //exclude ending space char selText = selText.substring(0, selText.length - 1); tagClose += ' ' } }}/** * Set the accesskey prefix based on browser detection. */var tooltipAccessKeyPrefix = 'alt-';if (is_opera) { tooltipAccessKeyPrefix = 'shift-esc-';} else if (is_safari || navigator.userAgent.toLowerCase().indexOf('mac') != -1 || navigator.userAgent.toLowerCase().indexOf('konqueror') != -1 ) { tooltipAccessKeyPrefix = 'ctrl-';} else if (is_ff2_x11 || is_ff2_win) { tooltipAccessKeyPrefix = 'alt-shift-';}var tooltipAccessKeyRegexp = /\[(ctrl-)?(alt-)?(shift-)?(esc-)?.\]$/;/** * Add the appropriate prefix to the accesskey shown in the tooltip. * If the nodeList parameter is given, only those nodes are updated; * otherwise, all the nodes that will probably have accesskeys by * default are updated. * * @param Array nodeList -- list of elements to update */function updateTooltipAccessKeys( nodeList ) { if ( !nodeList ) { // skins without a "column-one" element don't seem to have links with accesskeys either var columnOne = document.getElementById("column-one"); if ( columnOne ) updateTooltipAccessKeys( columnOne.getElementsByTagName("a") ); // these are rare enough that no such optimization is needed updateTooltipAccessKeys( document.getElementsByTagName("input") ); updateTooltipAccessKeys( document.getElementsByTagName("label") ); return; } for ( var i = 0; i < nodeList.length; i++ ) { var element = nodeList[i]; var tip = element.getAttribute("title"); var key = element.getAttribute("accesskey"); if ( key && tooltipAccessKeyRegexp.exec(tip) ) { tip = tip.replace(tooltipAccessKeyRegexp, "["+tooltipAccessKeyPrefix+key+"]"); element.setAttribute("title", tip ); } }}/** * Add a link to one of the portlet menus on the page, including: * * p-cactions: Content actions (shown as tabs above the main content in Monobook) * p-personal: Personal tools (shown at the top right of the page in Monobook) * p-navigation: Navigation * p-tb: Toolbox * * This function exists for the convenience of custom JS authors. All * but the first three parameters are optional, though providing at * least an id and a tooltip is recommended. * * By default the new link will be added to the end of the list. To * add the link before a given existing item, pass the DOM node of * that item (easily obtained with document.getElementById()) as the * nextnode parameter; to add the link _after_ an existing item, pass * the node's nextSibling instead. * * @param String portlet -- id of the target portlet ("p-cactions", "p-personal", "p-navigation" or "p-tb") * @param String href -- link URL * @param String text -- link text (will be automatically lowercased by CSS for p-cactions in Monobook) * @param String id -- id of the new item, should be unique and preferably have the appropriate prefix ("ca-", "pt-", "n-" or "t-") * @param String tooltip -- text to show when hovering over the link, without accesskey suffix * @param String accesskey -- accesskey to activate this link (one character, try to avoid conflicts) * @param Node nextnode -- the DOM node before which the new item should be added, should be another item in the same list * * @return Node -- the DOM node of the new item (an LI element) or null */function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode) { var node = document.getElementById(portlet); if ( !node ) return null; node = node.getElementsByTagName( "ul" )[0]; if ( !node ) return null; var link = document.createElement( "a" ); link.appendChild( document.createTextNode( text ) ); link.href = href; var item = document.createElement( "li" ); item.appendChild( link ); if ( id ) item.id = id; if ( accesskey ) { link.setAttribute( "accesskey", accesskey ); tooltip += " ["+accesskey+"]"; } if ( tooltip ) { link.setAttribute( "title", tooltip ); } if ( accesskey && tooltip ) { updateTooltipAccessKeys( new Array( link ) ); } if ( nextnode && nextnode.parentNode == node ) node.insertBefore( item, nextnode ); else node.appendChild( item ); // IE compatibility (?) return item;}/** * Set up accesskeys/tooltips from the deprecated ta array. If doId * is specified, only set up for that id. Note that this function is * deprecated and will not be supported indefinitely -- use * updateTooltipAccessKey() instead. * * @param mixed doId string or null */function akeytt( doId ) { // A lot of user scripts (and some of the code below) break if // ta isn't defined, so we make sure it is. Explictly using // window.ta avoids a "ta is not defined" error. if (!window.ta) window.ta = new Array; // Make a local, possibly restricted, copy to avoid clobbering // the original. var ta; if ( doId ) { ta = [doId]; } else { ta = window.ta; } // Now deal with evil deprecated ta var watchCheckboxExists = document.getElementById( 'wpWatchthis' ) ? true : false; for (var id in ta) { var n = document.getElementById(id); if (n) { var a = null; var ak = ''; // Are we putting accesskey in it if (ta[id][0].length > 0) { // Is this object a object? If not assume it's the next child. if (n.nodeName.toLowerCase() == "a") { a = n; } else { a = n.childNodes[0]; } // Don't add an accesskey for the watch tab if the watch // checkbox is also available. if (a && ((id != 'ca-watch' && id != 'ca-unwatch') || !watchCheckboxExists)) { a.accessKey = ta[id][0]; ak = ' ['+tooltipAccessKeyPrefix+ta[id][0]+']'; } } else { // We don't care what type the object is when assigning tooltip a = n; ak = ''; } if (a) { a.title = ta[id][1]+ak; } } }}function setupRightClickEdit() { if (document.getElementsByTagName) { var spans = document.getElementsByTagName('span'); for (var i = 0; i < spans.length; i++) { var el = spans[i]; if(el.className == 'editsection') { addRightClickEditHandler(el); } } }}function addRightClickEditHandler(el) { for (var i = 0; i < el.childNodes.length; i++) { var link = el.childNodes[i]; if (link.nodeType == 1 && link.nodeName.toLowerCase() == 'a') { var editHref = link.getAttribute('href'); // find the enclosing (parent) header var prev = el.parentNode; if (prev && prev.nodeType == 1 && prev.nodeName.match(/^[Hh][1-6]$/)) { prev.oncontextmenu = function(e) { if (!e) { e = window.event; } // e is now the event in all browsers var targ; if (e.target) { targ = e.target; } else if (e.srcElement) { targ = e.srcElement; } if (targ.nodeType == 3) { // defeat Safari bug targ = targ.parentNode; } // targ is now the target element // We don't want to deprive the noble reader of a context menu // for the section edit link, do we? (Might want to extend this // to all <a>'s?) if (targ.nodeName.toLowerCase() != 'a' || targ.parentNode.className != 'editsection') { document.location = editHref; return false; } return true; }; } } }}var checkboxes;var lastCheckbox;function setupCheckboxShiftClick() { checkboxes = []; lastCheckbox = null; var inputs = document.getElementsByTagName('input'); addCheckboxClickHandlers(inputs);}function addCheckboxClickHandlers(inputs, start) { if ( !start) start = 0; var finish = start + 250; if ( finish > inputs.length ) finish = inputs.length; for ( var i = start; i < finish; i++ ) { var cb = inputs[i]; if ( !cb.type || cb.type.toLowerCase() != 'checkbox' ) continue; var end = checkboxes.length; checkboxes[end] = cb; cb.index = end; cb.onclick = checkboxClickHandler; } if ( finish < inputs.length ) { setTimeout( function () { addCheckboxClickHandlers(inputs, finish); }, 200 ); }}function checkboxClickHandler(e) { if (typeof e == 'undefined') { e = window.event; } if ( !e.shiftKey || lastCheckbox === null ) { lastCheckbox = this.index; return true; } var endState = this.checked; var start, finish; if ( this.index < lastCheckbox ) { start = this.index + 1; finish = lastCheckbox; } else { start = lastCheckbox; finish = this.index - 1; } for (var i = start; i <= finish; ++i ) { checkboxes[i].checked = endState; } lastCheckbox = this.index; return true;}function toggle_element_activation(ida,idb) { if (!document.getElementById) { return; } document.getElementById(ida).disabled=true; document.getElementById(idb).disabled=false;}function toggle_element_check(ida,idb) { if (!document.getElementById) { return; } document.getElementById(ida).checked=true; document.getElementById(idb).checked=false;}/** * Restore the edit box scroll state following a preview operation, * and set up a form submission handler to remember this state */function scrollEditBox() { var editBox = document.getElementById( 'wpTextbox1' ); var scrollTop = document.getElementById( 'wpScrolltop' ); var editForm = document.getElementById( 'editform' ); if( editBox && scrollTop ) { if( scrollTop.value ) editBox.scrollTop = scrollTop.value; addHandler( editForm, 'submit', function() { document.getElementById( 'wpScrolltop' ).value = document.getElementById( 'wpTextbox1' ).scrollTop; } ); }}hookEvent( 'load', scrollEditBox );var allmessages_nodelist = false;var allmessages_modified = false;var allmessages_timeout = false;var allmessages_running = false;function allmessagesmodified() { allmessages_modified = !allmessages_modified; allmessagesfilter();}function allmessagesfilter() { if ( allmessages_timeout ) window.clearTimeout( allmessages_timeout ); if ( !allmessages_running ) allmessages_timeout = window.setTimeout( 'allmessagesfilter_do();', 500 );}function allmessagesfilter_do() { if ( !allmessages_nodelist ) return; var text = document.getElementById('allmessagesinput').value; var nodef = allmessages_modified; allmessages_running = true; for ( var name in allmessages_nodelist ) { var nodes = allmessages_nodelist[name]; var display = ( name.indexOf( text ) == -1 ? 'none' : '' ); for ( var i = 0; i < nodes.length; i++) nodes[i].style.display = ( nodes[i].className == "def" && nodef ? 'none' : display ); } if ( text != document.getElementById('allmessagesinput').value || nodef != allmessages_modified ) allmessagesfilter_do(); // repeat allmessages_running = false;}function allmessagesfilter_init() { if ( allmessages_nodelist ) return; var nodelist = new Array(); var templist = new Array(); var table = document.getElementById('allmessagestable'); if ( !table ) return; var rows = document.getElementsByTagName('tr'); for ( var i = 0; i < rows.length; i++ ) { var id = rows[i].getAttribute('id') if ( id && id.substring(0,16) != 'sp-allmessages-r' ) continue; templist[ id ] = rows[i]; } var spans = table.getElementsByTagName('span'); for ( var i = 0; i < spans.length; i++ ) { var id = spans[i].getAttribute('id') if ( id && id.substring(0,17) != 'sp-allmessages-i-' ) continue; if ( !spans[i].firstChild || spans[i].firstChild.nodeType != 3 ) continue; var nodes = new Array(); var row1 = templist[ id.replace('i', 'r1') ]; var row2 = templist[ id.replace('i', 'r2') ]; if ( row1 ) nodes[nodes.length] = row1; if ( row2 ) nodes[nodes.length] = row2; nodelist[ spans[i].firstChild.nodeValue ] = nodes; } var k = document.getElementById('allmessagesfilter'); if (k) { k.style.display = ''; } allmessages_nodelist = nodelist;}hookEvent( "load", allmessagesfilter_init );/* Written by Jonathan Snook, http://www.snook.ca/jonathan Add-ons by Robert Nyman, http://www.robertnyman.com Author says "The credit comment is all it takes, no license. Go crazy with it!:-)" From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/*/function getElementsByClassName(oElm, strTagName, oClassNames){ var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName); var arrReturnElements = new Array(); var arrRegExpClassNames = new Array();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -