PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 4.2.11
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v4.2.11
4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.12.0 3.12.1 All 134 releases
optimole-wp / assets / js / modal-attachment.js

modal-attachment.js in Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization 4.2.11, at assets/js/modal-attachment.js

69 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function($) {
2 if (!$('body').hasClass('upload-php')) {
3 return;
4 }
5
6 /**
7 * Helper function to add Replace or Rename button to attachment actions
8 * @param {Object} view - The attachment view instance
9 */
10 function addReplaceRenameButton(view) {
11 var $el = view.$el;
12 var $actions = $el.find('.actions');
13
14 if (!$actions.length || $actions.find('.optml-replace-rename-link').length) {
15 return;
16 }
17
18 var attachmentId = view.model.get('id');
19
20 if (!attachmentId) {
21 return;
22 }
23
24 var editUrl = OptimoleModalAttachment.editPostURL + '?post=' + attachmentId +
25 '&action=edit&TB_iframe=true&width=90%&height=90%';
26
27 var $editLink = $actions.find('a[href*="post.php"]');
28
29 if ($editLink.length) {
30 $editLink.after(
31 ' <span class="links-separator">|</span>' +
32 '<a href="' + editUrl + '" class="optml-replace-rename-link thickbox" title="' +
33 OptimoleModalAttachment.i18n.replaceOrRename + '"> ' +
34 OptimoleModalAttachment.i18n.replaceOrRename + '</a>'
35 );
36 }
37 }
38
39 /**
40 * Extend a WordPress media view with Replace/Rename functionality
41 * @param {Object} OriginalView - The original view to extend
42 * @returns {Object} Extended view
43 */
44 function extendMediaView(OriginalView) {
45 return OriginalView.extend({
46 initialize: function() {
47 OriginalView.prototype.initialize.apply(this, arguments);
48 },
49
50 render: function() {
51 OriginalView.prototype.render.apply(this, arguments);
52 addReplaceRenameButton(this);
53 return this;
54 }
55 });
56 }
57
58 var originalAttachmentDetails = wp.media.view.Attachment.Details;
59 wp.media.view.Attachment.Details = extendMediaView(originalAttachmentDetails);
60
61 if (wp.media.view.Attachment.Details.TwoColumn) {
62 var originalTwoColumn = wp.media.view.Attachment.Details.TwoColumn;
63 wp.media.view.Attachment.Details.TwoColumn = extendMediaView(originalTwoColumn);
64 }
65
66 $(document).on('click', '.optml-replace-rename-link.thickbox', function() {
67 tb_init('a.thickbox');
68 });
69 });