Skip to content

Instantly share code, notes, and snippets.

@jessepearson
Created October 15, 2014 15:40
Show Gist options
  • Select an option

  • Save jessepearson/1801878b5d5fd4ab23da to your computer and use it in GitHub Desktop.

Select an option

Save jessepearson/1801878b5d5fd4ab23da to your computer and use it in GitHub Desktop.
Turn WordPress editor resizing on and off based on page template
jQuery( document ).ready( function( $ ) {
// our variables
var page_template = $( '#page_template' ), // Page - page template select box
main_editor_container = $( '#postdivrich' ), // All - main editor
editor_expand_toggle = $( '#editor-expand-toggle' ); // All - the checkbox to turn autoresizing of the editor on and off.
// function that flips the switch to turn the auto resize of the MCE editor on and off
// basically, it gets it to reinitialize itself once we've shown it after hiding it, fixing layout issues
function expand_toggle(){
if( editor_expand_toggle.prop( 'checked' ) ) {
setTimeout( function () {
window.editorExpand.off();
window.editorExpand.on();
}, 401 );
}
}
// listen for a template change
page_template.change( function() {
switch( $( this ).val() ) {
case 'template-sectional.php':
main_editor_container.slideUp();
break;
case 'template-big-head.php':
main_editor_container.slideDown();
break;
default:
main_editor_container.slideDown();
}
// flip the switch
expand_toggle();
} ).change();
} );
@shivapoudel
Copy link
Copy Markdown

// Auto resize WordPress editor
if ( $( '#editor-expand-toggle' ).prop( 'checked' ) ) {
    window.editorExpand.off();
    window.editorExpand.on();
}

Uncaught TypeError: Cannot read property 'off' of undefined

On chrome I have set the mobile devices. How to get this fix ;)

@jessepearson
Copy link
Copy Markdown
Author

@shivapoudel I never got an email with your comment, if you're still having an issue let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment