-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
wp-content/mu-plugins/viget-wp/src/assets/js/skip-cropping.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* This allows the user to skip the cropping step when uploading a site icon. | ||
* | ||
* @package VigetWP | ||
*/ | ||
|
||
(function($, wp) { | ||
$(document).ready(function() { | ||
if (!wp.media) { | ||
return; | ||
} | ||
|
||
const originalController = wp.media.controller.SiteIconCropper; | ||
|
||
wp.media.controller.SiteIconCropper = originalController.extend({ | ||
activate: function() { | ||
originalController.prototype.activate.apply(this, arguments); | ||
this.set('canSkipCrop', true); | ||
} | ||
}); | ||
|
||
const originalButton = wp.media.view.Button; | ||
|
||
wp.media.view.Button = originalButton.extend({ | ||
click: function( e ) { | ||
if (!this.options.classes.includes('media-button-skip')) { | ||
originalButton.prototype.click.apply(this, arguments); | ||
return; | ||
} | ||
|
||
e.preventDefault(); | ||
|
||
const controller = this.controller; | ||
const attachment = controller.state().get('selection').first().toJSON(); | ||
controller.trigger('cropped', attachment); | ||
controller.close(); | ||
} | ||
}); | ||
}); | ||
})(jQuery, wp); |
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