Last active
July 21, 2016 07:03
-
-
Save harisrozak/78600a7da51f6baeed6a2a489417f44b to your computer and use it in GitHub Desktop.
WordPress :: wp_editor on modal
This file contains hidden or 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
<!-- On firefox, you must remove the tinymce on before modal close --> | |
<script type="text/javascript"> | |
var harisWpEditor; | |
;(function($) { | |
harisWpEditor = { | |
config: { | |
loadingTime: 350, | |
loadingText: 'Loading...' | |
}, | |
notFirstLoad: new Array(), | |
modalOpen: function(wp_editor_id) { | |
// remove tinymce on first load | |
if(! this.notFirstLoad[wp_editor_id]) { | |
tinymce.EditorManager.execCommand('mceRemoveEditor', true, wp_editor_id); | |
this.notFirstLoad[wp_editor_id] = true; | |
} | |
// show loading | |
$('#wp-' + wp_editor_id + '-wrap').css('visibility','hidden'); | |
$('<p id="wp-' + wp_editor_id + '-wrap-early-loading">' + this.config.loadingText + '</p>') | |
.insertBefore('#wp-' + wp_editor_id + '-wrap'); | |
// reinit tinymce | |
setTimeout(function(){ | |
tinymce.EditorManager.execCommand('mceAddEditor', true, wp_editor_id); | |
$('#wp-' + wp_editor_id + '-wrap-early-loading').remove(); | |
$('#wp-' + wp_editor_id + '-wrap').css('visibility','visible'); | |
}, this.config.loadingTime); | |
}, | |
modalClose: function(wp_editor_id) { | |
if($("#" + wp_editor_id).length && this.notFirstLoad[wp_editor_id]){ | |
tinymce.EditorManager.execCommand('mceRemoveEditor', true, wp_editor_id); | |
} | |
}, | |
getContent: function(wp_editor_id) { | |
var textContent = tinyMCE.get(wp_editor_id).getContent(); | |
return textContent; | |
} | |
} | |
})(jQuery); | |
function on_modal_show() { | |
harisWpEditor.modalOpen('modaleditor'); | |
} | |
function on_before_modal_close() { | |
harisWpEditor.modalClose('modaleditor'); | |
} | |
function on_save() { | |
var textContent = harisWpEditor.getContent('modaleditor'); | |
$('textarea[name="modal_editor"]').val(textContent); | |
} | |
</script> | |
<?php | |
$content = ''; | |
$id = 'modaleditor'; | |
$settings = array( | |
'textarea_name' => 'modal_editor', | |
'media_buttons' => false, | |
'quicktags' => false, | |
'editor_height' => 200 | |
); | |
wp_editor( $content, $id, $settings ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment