Media: ensure JavaScript initialized when media edit screen is loaded directly.

Fix a JavaScript error when the media edit screen is loaded directly via a url such as `/wp-admin/post.php?post={post_id}&action=edit&image-editor`. Add a check in `imgLoaded` for `this.hold.sizer` which is set up during initialization and required for the cropping tool. Call `init` if this is undefined.

Props NoseGraze.
Fixes #38138.


git-svn-id: https://develop.svn.wordpress.org/trunk@40020 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Adam Silverstein 2017-01-27 18:29:48 +00:00
parent 1a068f2a61
commit 856416049d
1 changed files with 5 additions and 0 deletions

View File

@ -573,6 +573,11 @@
imgLoaded : function(postid) { imgLoaded : function(postid) {
var img = $('#image-preview-' + postid), parent = $('#imgedit-crop-' + postid); var img = $('#image-preview-' + postid), parent = $('#imgedit-crop-' + postid);
// Ensure init has run even when directly loaded.
if ( 'undefined' === typeof this.hold.sizer ) {
this.init( postid );
}
this.initCrop(postid, img, parent); this.initCrop(postid, img, parent);
this.setCropSelection(postid, 0); this.setCropSelection(postid, 0);
this.toggleEditor(postid, 0); this.toggleEditor(postid, 0);