Created
September 7, 2015 13:16
-
-
Save DavidCramer/4a30399cb012e0040c09 to your computer and use it in GitHub Desktop.
reinit WP editors dynamically
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
function re_init_wp_editors(){ | |
if( typeof tinyMCEPreInit === 'undefined'){ | |
return; | |
} | |
var ed, init, edId, qtId, firstInit, wrapper; | |
if ( typeof tinymce !== 'undefined' ) { | |
for ( edId in tinyMCEPreInit.mceInit ) { | |
if ( firstInit ) { | |
init = tinyMCEPreInit.mceInit[edId] = tinymce.extend( {}, firstInit, tinyMCEPreInit.mceInit[edId] ); | |
} else { | |
init = firstInit = tinyMCEPreInit.mceInit[edId]; | |
} | |
wrapper = tinymce.DOM.select( '#wp-' + edId + '-wrap' )[0]; | |
if ( ( tinymce.DOM.hasClass( wrapper, 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( edId ) ) && | |
! init.wp_skip_init ) { | |
try { | |
tinymce.init( init ); | |
if ( ! window.wpActiveEditor ) { | |
window.wpActiveEditor = edId; | |
} | |
} catch(e){} | |
} | |
} | |
} | |
for ( qtId in tinyMCEPreInit.qtInit ) { | |
try { | |
quicktags( tinyMCEPreInit.qtInit[qtId] ); | |
if ( ! window.wpActiveEditor ) { | |
window.wpActiveEditor = qtId; | |
} | |
} catch(e){}; | |
} | |
jQuery('.wp-editor-wrap').on( 'click.wp-editor', function() { | |
if ( this.id ) { | |
window.wpActiveEditor = this.id.slice( 3, -5 ); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Work in progress...