From 440844381475d73e910578bbaae0ee6acfc84f8d Mon Sep 17 00:00:00 2001 From: azaozz Date: Wed, 30 Nov 2011 02:15:24 +0000 Subject: [PATCH] Add tabbing JS to the admin menu, same functionality as the top menu, see #19394 git-svn-id: http://svn.automattic.com/wordpress/trunk@19485 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/common.dev.js | 34 ++++++++++++++++++++++++++++++---- wp-admin/js/common.js | 2 +- wp-includes/script-loader.php | 2 +- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/wp-admin/js/common.dev.js b/wp-admin/js/common.dev.js index 43ecab8712..20033b95cc 100644 --- a/wp-admin/js/common.dev.js +++ b/wp-admin/js/common.dev.js @@ -160,9 +160,15 @@ $('.contextual-help-tabs').delegate('a', 'click focus', function(e) { $(document).ready( function() { var lastClicked = false, checks, first, last, checked, menu = $('#adminmenu'), - pageInput = $('input.current-page'), currentPage = pageInput.val(), folded; + pageInput = $('input.current-page'), currentPage = pageInput.val(), folded, refresh; // admin menu + refresh = function(i, el){ // force the browser to refresh the tabbing index + var node = $(el), tab = node.attr('tabindex'); + if ( tab ) + node.attr('tabindex', '0').attr('tabindex', tab); + }; + $('#collapse-menu', menu).click(function(){ var body = $(document.body); @@ -206,9 +212,29 @@ $(document).ready( function() { interval: 90 }); - // If the mouse is used on the menu, shift focus to the mouse. - menu.mouseover( function(e) { - $('li.focused', this).removeClass('focused'); + // Tab to select, Enter to open sub, Esc to close sub and focus the top menu + $('li.wp-has-submenu > a.wp-not-current-submenu', menu).bind('keydown.adminmenu', function(e){ + if ( e.which != 13 ) + return; + + var target = $(e.target); + + e.stopPropagation(); + e.preventDefault(); + + target.siblings('.wp-submenu').toggleClass('sub-open').find('a[role="menuitem"]').each(refresh); + }).each(refresh); + + $('a[role="menuitem"]', menu).bind('keydown.adminmenu', function(e){ + if ( e.which != 27 ) + return; + + var target = $(e.target); + + e.stopPropagation(); + e.preventDefault(); + + target.add( target.siblings() ).closest('.sub-open').removeClass('sub-open').siblings('a.wp-not-current-submenu').focus(); }); // Move .updated and .error alert boxes. Don't move boxes designed to be inline. diff --git a/wp-admin/js/common.js b/wp-admin/js/common.js index 65601799a1..3dca91f17c 100644 --- a/wp-admin/js/common.js +++ b/wp-admin/js/common.js @@ -1 +1 @@ -var showNotice,adminMenu,columns,validateForm,screenMeta,autofold_menu;(function(a){adminMenu={init:function(){},fold:function(){},restoreMenuState:function(){},toggle:function(){},favorites:function(){}};columns={init:function(){var b=this;a(".hide-column-tog","#adv-settings").click(function(){var d=a(this),c=d.val();if(d.prop("checked")){b.checked(c)}else{b.unchecked(c)}columns.saveManageColumnsState()})},saveManageColumnsState:function(){var b=this.hidden();a.post(ajaxurl,{action:"hidden-columns",hidden:b,screenoptionnonce:a("#screenoptionnonce").val(),page:pagenow})},checked:function(b){a(".column-"+b).show();this.colSpanChange(+1)},unchecked:function(b){a(".column-"+b).hide();this.colSpanChange(-1)},hidden:function(){return a(".manage-column").filter(":hidden").map(function(){return this.id}).get().join(",")},useCheckboxesForHidden:function(){this.hidden=function(){return a(".hide-column-tog").not(":checked").map(function(){var b=this.id;return b.substring(b,b.length-5)}).get().join(",")}},colSpanChange:function(b){var d=a("table").find(".colspanchange"),c;if(!d.length){return}c=parseInt(d.attr("colspan"),10)+b;d.attr("colspan",c.toString())}};a(document).ready(function(){columns.init()});validateForm=function(b){return !a(b).find(".form-required").filter(function(){return a("input:visible",this).val()==""}).addClass("form-invalid").find("input:visible").change(function(){a(this).closest(".form-invalid").removeClass("form-invalid")}).size()};showNotice={warn:function(){var b=commonL10n.warnDelete||"";if(confirm(b)){return true}return false},note:function(b){alert(b)}};screenMeta={element:null,toggles:null,page:null,init:function(){this.element=a("#screen-meta");this.toggles=a(".screen-meta-toggle a");this.page=a("#wpcontent");this.toggles.click(this.toggleEvent)},toggleEvent:function(c){var b=a(this.href.replace(/.+#/,"#"));c.preventDefault();if(!b.length){return}if(b.is(":visible")){screenMeta.close(b,a(this))}else{screenMeta.open(b,a(this))}},open:function(b,c){a(".screen-meta-toggle").not(c.parent()).css("visibility","hidden");b.parent().show();b.slideDown("fast",function(){c.addClass("screen-meta-active")})},close:function(b,c){b.slideUp("fast",function(){c.removeClass("screen-meta-active");a(".screen-meta-toggle").css("visibility","");b.parent().hide()})}};a(".contextual-help-tabs").delegate("a","click focus",function(d){var c=a(this),b;d.preventDefault();if(c.is(".active a")){return false}a(".contextual-help-tabs .active").removeClass("active");c.parent("li").addClass("active");b=a(c.attr("href"));a(".help-tab-content").not(b).removeClass("active").hide();b.addClass("active").show()});a(document).ready(function(){var i=false,c,e,j,h,b=a("#adminmenu"),d=a("input.current-page"),f=d.val(),g;a("#collapse-menu",b).click(function(){var k=a(document.body);if(k.hasClass("folded")){k.removeClass("folded");setUserSetting("mfold","o")}else{k.addClass("folded");setUserSetting("mfold","f")}return false});a("li.wp-has-submenu",b).hoverIntent({over:function(q){var l,n,r,p,k=a(this).find(".wp-submenu");if(!a(document.body).hasClass("folded")&&a(this).hasClass("wp-menu-open")){return}l=a(this).offset().top+k.height()+1;n=a("#wpwrap").height();r=60+l-n;p=a(window).height()+a(window).scrollTop()-15;if(p<(l-r)){r=l-p}if(r>1){k.css({marginTop:"-"+r+"px"})}else{if(k.css("marginTop")){k.css({marginTop:""})}}k.addClass("sub-open")},out:function(){a(this).find(".wp-submenu").removeClass("sub-open")},timeout:200,sensitivity:7,interval:90});b.mouseover(function(k){a("li.focused",this).removeClass("focused")});a("div.wrap h2:first").nextAll("div.updated, div.error").addClass("below-h2");a("div.updated, div.error").not(".below-h2, .inline").insertAfter(a("div.wrap h2:first"));screenMeta.init();a("tbody").children().children(".check-column").find(":checkbox").click(function(k){if("undefined"==k.shiftKey){return true}if(k.shiftKey){if(!i){return true}c=a(i).closest("form").find(":checkbox");e=c.index(i);j=c.index(this);h=a(this).prop("checked");if(0=0){k=this.scrollTop;m.value=q.substring(0,r).concat("\t",q.substring(l));m.selectionStart=m.selectionEnd=r+1;this.scrollTop=k}}if(p.stopPropagation){p.stopPropagation()}if(p.preventDefault){p.preventDefault()}});a("#newcontent").bind("blur.wpevent_InsertTab",function(k){if(this.lastKey&&9==this.lastKey){this.focus()}});if(d.length){d.closest("form").submit(function(k){if(a('select[name="action"]').val()==-1&&a('select[name="action2"]').val()==-1&&d.val()==f){d.val("1")}})}a(window).bind("resize.autofold",function(){if(getUserSetting("mfold")=="f"){return}var k=a(window).width();if(k<=800){if(!g){a(document.body).addClass("folded");g=true}}else{if(g){a(document.body).removeClass("folded");g=false}}}).triggerHandler("resize")});a(document).bind("wp_CloseOnEscape",function(c,b){if(typeof(b.cb)!="function"){return}if(typeof(b.condition)!="function"||b.condition()){b.cb()}return true})})(jQuery); \ No newline at end of file +var showNotice,adminMenu,columns,validateForm,screenMeta,autofold_menu;(function(a){adminMenu={init:function(){},fold:function(){},restoreMenuState:function(){},toggle:function(){},favorites:function(){}};columns={init:function(){var b=this;a(".hide-column-tog","#adv-settings").click(function(){var d=a(this),c=d.val();if(d.prop("checked")){b.checked(c)}else{b.unchecked(c)}columns.saveManageColumnsState()})},saveManageColumnsState:function(){var b=this.hidden();a.post(ajaxurl,{action:"hidden-columns",hidden:b,screenoptionnonce:a("#screenoptionnonce").val(),page:pagenow})},checked:function(b){a(".column-"+b).show();this.colSpanChange(+1)},unchecked:function(b){a(".column-"+b).hide();this.colSpanChange(-1)},hidden:function(){return a(".manage-column").filter(":hidden").map(function(){return this.id}).get().join(",")},useCheckboxesForHidden:function(){this.hidden=function(){return a(".hide-column-tog").not(":checked").map(function(){var b=this.id;return b.substring(b,b.length-5)}).get().join(",")}},colSpanChange:function(b){var d=a("table").find(".colspanchange"),c;if(!d.length){return}c=parseInt(d.attr("colspan"),10)+b;d.attr("colspan",c.toString())}};a(document).ready(function(){columns.init()});validateForm=function(b){return !a(b).find(".form-required").filter(function(){return a("input:visible",this).val()==""}).addClass("form-invalid").find("input:visible").change(function(){a(this).closest(".form-invalid").removeClass("form-invalid")}).size()};showNotice={warn:function(){var b=commonL10n.warnDelete||"";if(confirm(b)){return true}return false},note:function(b){alert(b)}};screenMeta={element:null,toggles:null,page:null,init:function(){this.element=a("#screen-meta");this.toggles=a(".screen-meta-toggle a");this.page=a("#wpcontent");this.toggles.click(this.toggleEvent)},toggleEvent:function(c){var b=a(this.href.replace(/.+#/,"#"));c.preventDefault();if(!b.length){return}if(b.is(":visible")){screenMeta.close(b,a(this))}else{screenMeta.open(b,a(this))}},open:function(b,c){a(".screen-meta-toggle").not(c.parent()).css("visibility","hidden");b.parent().show();b.slideDown("fast",function(){c.addClass("screen-meta-active")})},close:function(b,c){b.slideUp("fast",function(){c.removeClass("screen-meta-active");a(".screen-meta-toggle").css("visibility","");b.parent().hide()})}};a(".contextual-help-tabs").delegate("a","click focus",function(d){var c=a(this),b;d.preventDefault();if(c.is(".active a")){return false}a(".contextual-help-tabs .active").removeClass("active");c.parent("li").addClass("active");b=a(c.attr("href"));a(".help-tab-content").not(b).removeClass("active").hide();b.addClass("active").show()});a(document).ready(function(){var j=false,c,e,k,i,b=a("#adminmenu"),d=a("input.current-page"),f=d.val(),h,g;g=function(l,n){var o=a(n),m=o.attr("tabindex");if(m){o.attr("tabindex","0").attr("tabindex",m)}};a("#collapse-menu",b).click(function(){var l=a(document.body);if(l.hasClass("folded")){l.removeClass("folded");setUserSetting("mfold","o")}else{l.addClass("folded");setUserSetting("mfold","f")}return false});a("li.wp-has-submenu",b).hoverIntent({over:function(r){var n,p,s,q,l=a(this).find(".wp-submenu");if(!a(document.body).hasClass("folded")&&a(this).hasClass("wp-menu-open")){return}n=a(this).offset().top+l.height()+1;p=a("#wpwrap").height();s=60+n-p;q=a(window).height()+a(window).scrollTop()-15;if(q<(n-s)){s=n-q}if(s>1){l.css({marginTop:"-"+s+"px"})}else{if(l.css("marginTop")){l.css({marginTop:""})}}l.addClass("sub-open")},out:function(){a(this).find(".wp-submenu").removeClass("sub-open")},timeout:200,sensitivity:7,interval:90});a("li.wp-has-submenu > a.wp-not-current-submenu",b).bind("keydown.adminmenu",function(m){if(m.which!=13){return}var l=a(m.target);m.stopPropagation();m.preventDefault();l.siblings(".wp-submenu").toggleClass("sub-open").find('a[role="menuitem"]').each(g)}).each(g);a('a[role="menuitem"]',b).bind("keydown.adminmenu",function(m){if(m.which!=27){return}var l=a(m.target);m.stopPropagation();m.preventDefault();l.add(l.siblings()).closest(".sub-open").removeClass("sub-open").siblings("a.wp-not-current-submenu").focus()});a("div.wrap h2:first").nextAll("div.updated, div.error").addClass("below-h2");a("div.updated, div.error").not(".below-h2, .inline").insertAfter(a("div.wrap h2:first"));screenMeta.init();a("tbody").children().children(".check-column").find(":checkbox").click(function(l){if("undefined"==l.shiftKey){return true}if(l.shiftKey){if(!j){return true}c=a(j).closest("form").find(":checkbox");e=c.index(j);k=c.index(this);i=a(this).prop("checked");if(0=0){l=this.scrollTop;n.value=r.substring(0,s).concat("\t",r.substring(m));n.selectionStart=n.selectionEnd=s+1;this.scrollTop=l}}if(q.stopPropagation){q.stopPropagation()}if(q.preventDefault){q.preventDefault()}});a("#newcontent").bind("blur.wpevent_InsertTab",function(l){if(this.lastKey&&9==this.lastKey){this.focus()}});if(d.length){d.closest("form").submit(function(l){if(a('select[name="action"]').val()==-1&&a('select[name="action2"]').val()==-1&&d.val()==f){d.val("1")}})}a(window).bind("resize.autofold",function(){if(getUserSetting("mfold")=="f"){return}var l=a(window).width();if(l<=800){if(!h){a(document.body).addClass("folded");h=true}}else{if(h){a(document.body).removeClass("folded");h=false}}}).triggerHandler("resize")});a(document).bind("wp_CloseOnEscape",function(c,b){if(typeof(b.cb)!="function"){return}if(typeof(b.condition)!="function"||b.condition()){b.cb()}return true})})(jQuery); \ No newline at end of file diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index e7f1431613..120a7a6c0a 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -61,7 +61,7 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'utils', "/wp-admin/js/utils$suffix.js", false, '20101110' ); - $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), '20111123', 1 ); + $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), '20111129', 1 ); $scripts->localize( 'common', 'commonL10n', array( 'warnDelete' => __("You are about to permanently delete the selected items.\n 'Cancel' to stop, 'OK' to delete.") ) );