From 0f60d3f9314fb536ce3f7b5d060aca5bd63fdd70 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Sun, 14 Jan 2007 23:48:42 +0000 Subject: [PATCH] * Don't iterate through all elements to update tooltips/accesskeys, iterate through as few as possible while still guaranteeing that you'll add all accesskeys * Only call updateTooltipAccessKeys from addPortletLink if necessary * Give search box a tooltip in Monobook --- includes/DefaultSettings.php | 2 +- skins/MonoBook.php | 4 +-- skins/common/wikibits.js | 51 +++++++++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 9ffc5fccd7..46f9ce6046 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1105,7 +1105,7 @@ $wgCacheEpoch = '20030516000000'; * to ensure that client-side caches don't keep obsolete copies of global * styles. */ -$wgStyleVersion = '46'; +$wgStyleVersion = '47'; # Server-side caching: diff --git a/skins/MonoBook.php b/skins/MonoBook.php index 04d135f493..b9f5f2c010 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -170,9 +170,7 @@ class MonoBookTemplate extends QuickTemplate {
- haveMsg('accesskey-search')) { - ?>accesskey="msg('accesskey-search') ?>"tooltipAndAccesskey('search'); if( isset( $this->data['search'] ) ) { ?> value="text('search') ?>" />   diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index 3a0c496b6a..4486c01c80 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -490,25 +490,43 @@ if (is_opera) { tooltipAccessKeyPrefix = 'alt-shift-'; } var tooltipAccessKeyRegexp = /\[(ctrl-)?(alt-)?(shift-)?(esc-)?.\]$/; +var parentNode = null; /** * Add the appropriate prefix to the accesskey shown in the tooltip. - * If the nodeList parameter is given, only those nodes are updated. + * 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 ) - nodeList = document.getElementsByTagName("*"); - - 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 ); + if ( !nodeList ) { + if ( !parentNode ) { + if ( !document.getElementById( "wpSave" ) && !document.getElementById( "pagehistory" ) ) { + // If this is an edit page, we need to go through the whole page. + // Otherwise we can just do non-content stuff. + // Note: hacky heuristic! Any better? + parentNode = document.getElementById( "column-one" ); + } + if (!parentNode) { + // Presumably non-Monobook, have to go through the whole page + parentNode = document; + } + } + updateTooltipAccessKeys( parentNode.getElementsByTagName("a") ); + updateTooltipAccessKeys( parentNode.getElementsByTagName("input") ); + updateTooltipAccessKeys( parentNode.getElementsByTagName("label") ); + } else { + 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 ); + } } } } @@ -562,7 +580,9 @@ function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode) { if ( tooltip ) { link.setAttribute( "title", tooltip ); } - updateTooltipAccessKeys( new Array( link ) ); + if ( accesskey && tooltip ) { + updateTooltipAccessKeys( new Array( link ) ); + } if ( nextnode && nextnode.parentNode != node ) nextnode = null; node.insertBefore( item, nextnode ); @@ -982,6 +1002,8 @@ function runOnloadHook() { return; } + var startTime = new Date().getTime(); + // set this before running any hooks, since any errors below // might cause the function to terminate prematurely doneOnloadHook = true; @@ -999,6 +1021,9 @@ function runOnloadHook() { for (var i = 0; i < onloadFuncts.length; i++) { onloadFuncts[i](); } + + var endTime = new Date().getTime(); + alert( endTime - startTime ); } //note: all skins should call runOnloadHook() at the end of html output, -- 2.20.1