| 1 |
jQuery(document).ready( function($){ |
| 2 |
// var Library = wp.media.controller.Library; |
| 3 |
var oldMediaFrame = wp.media.view.MediaFrame.Select; |
| 4 |
// Extending the current media library frame to add a new tab |
| 5 |
wp.media.view.MediaFrame.Select = oldMediaFrame.extend({ |
| 6 |
initialize: function() { |
| 7 |
|
| 8 |
oldMediaFrame.prototype.initialize.apply( this, arguments ); |
| 9 |
this.states.add([ |
| 10 |
new wp.media.controller.State({ |
| 11 |
id: 'optimole', |
| 12 |
search: false, |
| 13 |
title: 'Optimole' |
| 14 |
}), |
| 15 |
]); |
| 16 |
this.on( 'content:create:optimole', this.renderOptimole, this ); |
| 17 |
this.on( |
| 18 |
'content:render:browse content:render:upload', function(){ |
| 19 |
$( document ).find( '.media-button-select' ).attr('disabled', 'disabled').removeAttr( 'enabled', 'enabled'); |
| 20 |
}, this |
| 21 |
); |
| 22 |
let scope = this; |
| 23 |
|
| 24 |
$( document ).on( |
| 25 |
'click', '.optml-load-more', function (e) { |
| 26 |
e.stopPropagation(); |
| 27 |
scope.page ++; |
| 28 |
scope.renderOptimole(); |
| 29 |
|
| 30 |
} |
| 31 |
); |
| 32 |
}, |
| 33 |
browseRouter: function( routerView ) { |
| 34 |
const l10n = wp.media.view.l10n; |
| 35 |
routerView.set({ |
| 36 |
upload: { |
| 37 |
text: l10n.uploadFilesTitle, |
| 38 |
priority: 20 |
| 39 |
}, |
| 40 |
browse: { |
| 41 |
text: l10n.mediaLibraryTitle, |
| 42 |
priority: 40 |
| 43 |
}, |
| 44 |
optimole: { |
| 45 |
text: 'Optimole', |
| 46 |
priority: 60 |
| 47 |
} |
| 48 |
}); |
| 49 |
}, |
| 50 |
renderOptimole: function( ) { |
| 51 |
|
| 52 |
$( document ).find( '.media-button-select' ).attr('disabled', 'disabled').removeAttr( 'enabled', 'enabled'); |
| 53 |
|
| 54 |
var state = this.state(); |
| 55 |
|
| 56 |
let options = this.options.library; |
| 57 |
options.type = ['optml_cloud']; |
| 58 |
const view = new wp.media.view.AttachmentsBrowser({ |
| 59 |
controller: this, |
| 60 |
collection: wp.media.query( options ), |
| 61 |
selection: state.get( 'selection' ), |
| 62 |
model: state, |
| 63 |
sortable: false, |
| 64 |
search: true, |
| 65 |
filters: false, |
| 66 |
date: false, |
| 67 |
display: false, |
| 68 |
dragInfo: state.get('dragInfo'), |
| 69 |
idealColumnWidth: state.get( 'idealColumnWidth' ), |
| 70 |
suggestedWidth: state.get( 'suggestedWidth' ), |
| 71 |
suggestedHeight: state.get( 'suggestedHeight' ), |
| 72 |
AttachmentView: state.get( 'AttachmentView' ) |
| 73 |
}); |
| 74 |
this.content.set( view ); |
| 75 |
} |
| 76 |
}); |
| 77 |
}); |
| 78 |
|