PluginProbe
WP Ultimate Post Grid / 4.0.1
WP Ultimate Post Grid v4.0.1
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / assets / js / admin-modal / general / Media.js

Media.js in WP Ultimate Post Grid 4.0.1, at assets/js/admin-modal/general/Media.js

52 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __wpupg } from 'Shared/Translations';
2
3 const Media = {
4 selectImage( callback ) {
5 this.select( 'image', callback );
6 },
7 selectVideo( callback ) {
8 this.select( 'video', callback );
9 },
10 select( type, callback ) {
11 let media_arguments = {
12 title: __wpupg( 'Select Media' ),
13 button: {
14 text: __wpupg( 'Select' ),
15 },
16 multiple: false,
17 };
18
19 // Check what media type we're getting.
20 if ( 'video' === type ) {
21 media_arguments.frame = 'video';
22 media_arguments.state = 'video-details';
23 } else {
24 // Default to image.
25 media_arguments.library = {
26 type: 'image',
27 };
28 }
29
30 // Create a new media frame (don't reuse because we have multiple different inputs)
31 let frame = wp.media(media_arguments);
32
33 // Handle image selection
34 frame.on('select', function() {
35 var attachment = frame.state().get('selection').first().toJSON();
36 callback( attachment );
37 });
38
39 // Handle video selection
40 frame.on('update', function() {
41 let attachment = frame.state().media.attachment;
42
43 if ( attachment ) {
44 callback( attachment );
45 }
46 });
47
48 // Finally, open the modal on click
49 frame.open();
50 }
51 }
52 export default Media;