Skip to content

Instantly share code, notes, and snippets.

@cvn
Last active December 18, 2015 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvn/5734676 to your computer and use it in GitHub Desktop.
Save cvn/5734676 to your computer and use it in GitHub Desktop.
Wordpress Subheading plugin tab order fix
/**
* 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