Skip to content
This repository has been archived by the owner on Aug 24, 2018. It is now read-only.

Commit

Permalink
Merge pull request #180 from xwp/fix/deleting-text-widget
Browse files Browse the repository at this point in the history
Abort rebuilding editor when text widget is deleted
  • Loading branch information
westonruter committed May 11, 2017
2 parents 5fade21 + 0fedcb6 commit 811779f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions wp-admin/js/widgets/text-widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ wp.textWidgets = ( function( $ ) {
function buildEditor() {
var editor, triggerChangeIfDirty, onInit;

// Abort building if the textarea is gone, likely due to the widget having been deleted entirely.
if ( ! document.getElementById( id ) ) {
return;
}

// Destroy any existing editor so that it can be re-initialized after a widget-updated event.
if ( tinymce.get( id ) ) {
restoreTextMode = tinymce.get( id ).isHidden();
Expand All @@ -137,6 +142,8 @@ wp.textWidgets = ( function( $ ) {
throw new Error( 'Failed to initialize editor' );
}
onInit = function() {

// When a widget is moved in the DOM the dynamically-created TinyMCE iframe will be destroyed and has to be re-built.
$( editor.getWin() ).on( 'unload', function() {
_.defer( buildEditor );
});
Expand Down

0 comments on commit 811779f

Please sign in to comment.