Add unique ids as well as of classes in the admin bar to make it easier for plugins to extend.

Ensure we escape the classname.
Fixes #16211 props koopersmith.

git-svn-id: http://svn.automattic.com/wordpress/trunk@17279 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
westi 2011-01-13 01:34:15 +00:00
parent d1c2b06a7e
commit 2a75d9c511
5 changed files with 21 additions and 18 deletions

View File

@ -113,13 +113,15 @@ class WP_Admin_Bar {
/* Helpers */
function recursive_render( $id, &$menu_item ) { ?>
<?php $menuclass = ( ! empty( $menu_item['children'] ) ) ? 'menupop ' : ''; ?>
<?php
$is_parent = ! empty( $menu_item['children'] );
$menuclass = $is_parent ? 'menupop' : '';
if ( ! empty( $menu_item['meta']['class'] ) )
$menuclass .= ' ' . $menu_item['meta']['class'];
?>
<li class="<?php echo $menuclass . "ab-$id" ?><?php
if ( ! empty( $menu_item['meta']['class'] ) ) :
echo ' ' . esc_attr( $menu_item['meta']['class'] );
endif;
?>">
<li id="<?php echo esc_attr( "wp-admin-bar-$id" ); ?>" class="<?php echo esc_attr( $menuclass ); ?>">
<a href="<?php echo esc_url( $menu_item['href'] ) ?>"<?php
if ( ! empty( $menu_item['meta']['onclick'] ) ) :
?> onclick="<?php echo esc_js( $menu_item['meta']['onclick'] ); ?>"<?php
@ -133,19 +135,19 @@ class WP_Admin_Bar {
?>><?php
if ( ! empty( $menuclass ) ) :
if ( $is_parent ) :
?><span><?php
endif;
echo $menu_item['title'];
if ( ! empty( $menuclass ) ) :
if ( $is_parent ) :
?></span><?php
endif;
?></a>
<?php if ( ! empty( $menu_item['children'] ) ) : ?>
<?php if ( $is_parent ) : ?>
<ul>
<?php foreach ( $menu_item['children'] as $child_id => $child_menu_item ) : ?>
<?php $this->recursive_render( $child_id, $child_menu_item ); ?>

File diff suppressed because one or more lines are too long

View File

@ -182,16 +182,16 @@
background: #fff;
color: #000;
}
#wpadminbar .quicklinks li.ab-my-account > a {
#wpadminbar .quicklinks li#wp-admin-bar-my-account > a {
border-left: none;
}
#wpadminbar .quicklinks li.ab-my-account-with-avatar > a {
#wpadminbar .quicklinks li#wp-admin-bar-my-account-with-avatar > a {
border-left: none;
background: url(../images/admin-bar-sprite.png?d=11122010) top left no-repeat;
}
#wpadminbar .quicklinks li.ab-my-account-with-avatar > a img {
#wpadminbar .quicklinks li#wp-admin-bar-my-account-with-avatar > a img {
display: inline;
border: 1px solid #999;
vertical-align: middle;
@ -201,7 +201,7 @@
float: none;
}
#wpadminbar .quicklinks li.ab-my-account-with-avatar ul {
#wpadminbar .quicklinks li#wp-admin-bar-my-account-with-avatar ul {
left: 30px;
}

View File

@ -90,15 +90,16 @@
if ( ! t || t == d || t == aB )
return;
// Check if we've found the shortlink node.
if ( t.className && -1 != t.className.indexOf('ab-get-shortlink') )
if ( t.id && t.id == 'wp-admin-bar-get-shortlink' )
break;
t = t.parentNode;
}
// IE doesn't support preventDefault, and does support returnValue
if ( e.preventDefault )
e.preventDefault();
e.returnValue = false;
if ( -1 == t.className.indexOf('selected') )
t.className += ' selected';

View File

@ -1 +1 @@
(function(i,k){var c=function(n,m,d){if(n.addEventListener){n.addEventListener(m,d,false)}else{if(n.attachEvent){n.attachEvent("on"+m,function(){return d.call(n,window.event)})}}},e,f=new RegExp("\\bhover\\b","g"),a=[],j=new RegExp("\\bselected\\b","g"),g=function(m){var d=a.length;while(d--){if(a[d]&&m==a[d][1]){return a[d][0]}}return false},h=function(s){var n,d,q,m,p,r,u=[],o=0;while(s&&s!=e&&s!=i){if("LI"==s.nodeName.toUpperCase()){u[u.length]=s;d=g(s);if(d){clearTimeout(d)}s.className=s.className?(s.className.replace(f,"")+" hover"):"hover";m=s}s=s.parentNode}if(m&&m.parentNode){p=m.parentNode;if(p&&"UL"==p.nodeName.toUpperCase()){n=p.childNodes.length;while(n--){r=p.childNodes[n];if(r!=m){r.className=r.className?r.className.replace(j,""):""}}}}n=a.length;while(n--){q=false;o=u.length;while(o--){if(u[o]==a[n][1]){q=true}}if(!q){a[n][1].className=a[n][1].className?a[n][1].className.replace(f,""):""}}},l=function(d){while(d&&d!=e&&d!=i){if("LI"==d.nodeName.toUpperCase()){(function(m){var n=setTimeout(function(){m.className=m.className?m.className.replace(f,""):""},500);a[a.length]=[n,m]})(d)}d=d.parentNode}},b=function(p){var n,d,o,m=p.target||p.srcElement;while(true){if(!m||m==i||m==e){return}if(m.className&&-1!=m.className.indexOf("ab-get-shortlink")){break}m=m.parentNode}if(p.preventDefault){p.preventDefault()}p.returnValue=false;if(-1==m.className.indexOf("selected")){m.className+=" selected"}for(n=0,d=m.childNodes.length;n<d;n++){o=m.childNodes[n];if(o.className&&-1!=o.className.indexOf("shortlink-input")){o.focus();o.select();o.onblur=function(){m.className=m.className?m.className.replace(j,""):""};break}}return false};c(k,"load",function(){e=i.getElementById("wpadminbar");if(i.body&&e){i.body.appendChild(e);c(e,"mouseover",function(d){h(d.target||d.srcElement)});c(e,"mouseout",function(d){l(d.target||d.srcElement)});c(e,"click",b)}if(k.location.hash){k.scrollBy(0,-32)}})})(document,window);
(function(i,k){var c=function(n,m,d){if(n.addEventListener){n.addEventListener(m,d,false)}else{if(n.attachEvent){n.attachEvent("on"+m,function(){return d.call(n,window.event)})}}},e,f=new RegExp("\\bhover\\b","g"),a=[],j=new RegExp("\\bselected\\b","g"),g=function(m){var d=a.length;while(d--){if(a[d]&&m==a[d][1]){return a[d][0]}}return false},h=function(s){var n,d,q,m,p,r,u=[],o=0;while(s&&s!=e&&s!=i){if("LI"==s.nodeName.toUpperCase()){u[u.length]=s;d=g(s);if(d){clearTimeout(d)}s.className=s.className?(s.className.replace(f,"")+" hover"):"hover";m=s}s=s.parentNode}if(m&&m.parentNode){p=m.parentNode;if(p&&"UL"==p.nodeName.toUpperCase()){n=p.childNodes.length;while(n--){r=p.childNodes[n];if(r!=m){r.className=r.className?r.className.replace(j,""):""}}}}n=a.length;while(n--){q=false;o=u.length;while(o--){if(u[o]==a[n][1]){q=true}}if(!q){a[n][1].className=a[n][1].className?a[n][1].className.replace(f,""):""}}},l=function(d){while(d&&d!=e&&d!=i){if("LI"==d.nodeName.toUpperCase()){(function(m){var n=setTimeout(function(){m.className=m.className?m.className.replace(f,""):""},500);a[a.length]=[n,m]})(d)}d=d.parentNode}},b=function(p){var n,d,o,m=p.target||p.srcElement;while(true){if(!m||m==i||m==e){return}if(m.id&&m.id=="wp-admin-bar-get-shortlink"){break}m=m.parentNode}if(p.preventDefault){p.preventDefault()}p.returnValue=false;if(-1==m.className.indexOf("selected")){m.className+=" selected"}for(n=0,d=m.childNodes.length;n<d;n++){o=m.childNodes[n];if(o.className&&-1!=o.className.indexOf("shortlink-input")){o.focus();o.select();o.onblur=function(){m.className=m.className?m.className.replace(j,""):""};break}}return false};c(k,"load",function(){e=i.getElementById("wpadminbar");if(i.body&&e){i.body.appendChild(e);c(e,"mouseover",function(d){h(d.target||d.srcElement)});c(e,"mouseout",function(d){l(d.target||d.srcElement)});c(e,"click",b)}if(k.location.hash){k.scrollBy(0,-32)}})})(document,window);