From 9910c64764fa042d7c2a2b5ce99a7adfc8d2109b Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Fri, 29 Mar 2013 08:28:58 +0000 Subject: [PATCH] Use jQuery.on() properly in accordion code. Some other cleanup. see #23890. git-svn-id: https://develop.svn.wordpress.org/trunk@23856 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/js/accordion.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/wp-admin/js/accordion.js b/wp-admin/js/accordion.js index a5c63f28f9..20277162c6 100644 --- a/wp-admin/js/accordion.js +++ b/wp-admin/js/accordion.js @@ -1,17 +1,16 @@ jQuery(document).ready( function($) { // Expand/Collapse - $('.accordion-section-title').on('click keydown', function( event ) { - - if ( event.type === 'keydown' && 13 !== event.which ) // enter + $('.accordion-container').on( 'click keydown', '.accordion-section-title', function(e) { + if ( e.type === 'keydown' && 13 !== e.which ) // "return" key return; + e.preventDefault(); // Keep this AFTER the key filter above - var clicked = $( this ).closest( '.accordion-section' ); + var section = $( this ).closest( '.accordion-section' ); - if ( clicked.hasClass('cannot-expand') ) + if ( section.hasClass('cannot-expand') ) return; - clicked.closest( '.accordion-container' ).find( '.accordion-section' ).not( clicked ).removeClass( 'open' ); - clicked.toggleClass( 'open' ); - event.preventDefault(); + section.closest( '.accordion-container' ).find( '.accordion-section' ).not( section ).removeClass( 'open' ); + section.toggleClass( 'open' ); }); });