PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.7
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.7
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / assets / js / charitable-admin-media.js

charitable-admin-media.js in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.7, at assets/js/charitable-admin-media.js

88 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function( $ ) {
2
3 var file_frame;
4 window.formfield = '';
5
6 $( document.body ).on( 'click', '.charitable-upload-button', function(e) {
7
8 e.preventDefault();
9
10 var $button = $(this);
11
12 window.formfield = $button;
13
14 // If the media frame already exists, reopen it.
15 if ( file_frame ) {
16 //file_frame.uploader.uploader.param( 'post_id', set_to_post_id );
17 file_frame.open();
18 return;
19 }
20
21 // Create the media frame.
22 file_frame = wp.media.frames.file_frame = wp.media( {
23 frame: 'post',
24 state: 'insert',
25 title: $button.data( 'uploader-title' ),
26 button: {
27 text: $button.data( 'uploader-button-text' )
28 },
29 library: {
30 type: $button.data( 'uploader-library' )
31 },
32 multiple: false
33 } );
34
35 file_frame.on( 'menu:render:default', function( view ) {
36 // Store our views in an object.
37 var views = {};
38
39 // Unset default menu items
40 view.unset( 'library-separator' );
41 view.unset( 'gallery' );
42 view.unset( 'featured-image' );
43 view.unset( 'embed' );
44 view.unset( 'playlist' );
45 view.unset( 'video-playlist' );
46
47 // Initialize the views in our view object.
48 view.set( views );
49 } );
50
51 // When an image is selected, run a callback.
52 file_frame.on( 'insert', function() {
53
54 var selection = file_frame.state().get('selection');
55 selection.each( function( attachment, index ) {
56 attachment = attachment.toJSON();
57
58 var id_field_name = $button.data( 'uploader-attachment-id-field-name' ),
59 src_field_name = $button.data( 'uploader-attachment-src-field-name' ),
60 display_field_id = $button.data( 'uploader-attachment-preview-field' );
61
62 if ( 'undefined' !== typeof id_field_name ) {
63 var attachment_id_field = $( "[name='" + id_field_name + "']" );
64 attachment_id_field.val( attachment.id );
65 }
66
67 if ( 'undefined' !== typeof src_field_name ) {
68 var attachment_src_field = $( '[name="' + src_field_name + '"]' );
69 attachment_src_field.val( attachment.url );
70 }
71
72 if ( 'undefined' !== typeof display_field_id ) {
73 var display_field = $( '#' + display_field_id );
74 display_field.html( '<img src="' + attachment.url + '" alt="" style="max-width:100%;" />' );
75 }
76 } );
77 } );
78
79 // Finally, open the modal
80 file_frame.open();
81 });
82
83
84 // WP 3.5+ uploader
85 var file_frame;
86 window.formfield = '';
87 })( jQuery);
88