Last active
December 18, 2015 05:39
-
-
Save cvn/5734676 to your computer and use it in GitHub Desktop.
Wordpress Subheading plugin tab order fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Inject javascript to fix tab order for Subheading plugin input field | |
*/ | |
function add_jquery_data() { | |
// only load on new post / edit post page | |
global $parent_file; | |
if ( is_admin() && $parent_file == 'edit.php'): ?> | |
<script type="text/javascript"> | |
jQuery(document).on('ready', function(){ | |
var titleInput = jQuery('input#title') | |
, subInput = jQuery('#wp_subheading'); | |
if (subInput.length){ | |
titleInput.off('blur keydown'); | |
titleInput.one('keydown',function(event){ | |
jQuery('#title-prompt-text').addClass('screen-reader-text'); | |
}); | |
titleInput.on('keydown',function(event){ | |
var keyCode = event.keyCode || event.which; | |
if(keyCode == 9) { | |
event.stopPropagation(); | |
event.preventDefault(); | |
if(event.shiftKey) { | |
//Focus previous input | |
} | |
else { | |
//Focus next input | |
subInput.focus(); | |
} | |
} | |
}); | |
titleInput.on('blur',function(event){ | |
if(!this.value){ | |
jQuery('#title-prompt-text').removeClass('screen-reader-text'); | |
} | |
}); | |
subInput.on('keydown',function(){ | |
var keyCode = event.keyCode || event.which; | |
if(keyCode == 9) { | |
event.stopPropagation(); | |
event.preventDefault(); | |
if(event.shiftKey) { | |
//Focus previous input | |
titleInput.focus(); | |
} | |
else { | |
//Focus next input | |
tinyMCE.get('content').focus(); | |
} | |
} | |
}); | |
} | |
}); | |
</script> | |
<?php endif; | |
} | |
add_filter('admin_footer', 'add_jquery_data'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment