From 856416049df3b7958982c0db70e6cd4bff9a77cd Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 27 Jan 2017 18:29:48 +0000 Subject: [PATCH] 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 --- src/wp-admin/js/image-edit.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wp-admin/js/image-edit.js b/src/wp-admin/js/image-edit.js index 0ea8a4b11c..0d8eaf081f 100644 --- a/src/wp-admin/js/image-edit.js +++ b/src/wp-admin/js/image-edit.js @@ -573,6 +573,11 @@ imgLoaded : function(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.setCropSelection(postid, 0); this.toggleEditor(postid, 0);