PluginProbe
WP Directory Kit / 1.1.0
WP Directory Kit v1.1.0
1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 1.4.0 All 36 releases
wpdirectorykit / vendor / Winter_MVC / assets / js / jquery.wpmediaelement_file.js

jquery.wpmediaelement_file.js in WP Directory Kit 1.1.0, at vendor/Winter_MVC/assets/js/jquery.wpmediaelement_file.js

113 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2
3 jQuery.fn.wpMediaElementFile = function (options)
4 {
5 var defaults = {
6 obj: null,
7 mediaControl: null,
8 addImgLinkSelector: '.upload-custom-img',
9 delImgLinkSelector: '.delete-custom-img',
10 imgContainerSelector: '.custom-img-container',
11 imgIdInputSelector: '.logo_file_id',
12 addImgLink: null,
13 delImgLink: null,
14 imgContainer: null,
15 imgIdInput: null,
16 frame: null
17 };
18 console.log(options);
19 var options = jQuery.extend(defaults, options);
20
21 /* Public API */
22 this.getCurrent = function()
23 {
24 return options.obj;
25 }
26
27 return this.each (function ()
28 {
29 options.obj = jQuery(this);
30
31 options.addImgLink = options.obj.find(options.addImgLinkSelector);
32 options.delImgLink = options.obj.find(options.delImgLinkSelector);
33 options.imgContainer = options.obj.find(options.imgContainerSelector);
34 options.imgIdInput = options.obj.find(options.imgIdInputSelector);
35
36 init_start();
37
38 return this;
39 });
40
41 function init_start()
42 {
43 console.log('init_start'+options.obj.attr('id'));
44
45 options.frame = wp.media({
46 title: 'Select or Upload Media Of Your Chosen Persuasion',
47 library: {
48 type: 'image'
49 },
50 button: {
51 text: 'Use this media'
52 },
53 multiple: false
54 });
55
56 options.frame.on( 'open', updateFrame ).state('library').on( 'select', selectImg );
57
58 options.addImgLink.on( 'click', function( e ) {
59 e.preventDefault();
60
61 options.frame.open();
62 });
63
64 // DELETE IMAGE LINK
65 options.delImgLink.on( 'click', function( event ){
66
67 event.preventDefault();
68
69 // Clear out the preview image
70 options.imgContainer.html( '' );
71
72 // Un-hide the add image link
73 options.addImgLink.removeClass( 'hidden' );
74
75 // Hide the delete image link
76 options.delImgLink.addClass( 'hidden' );
77
78 // Delete the image id from the hidden input
79 options.imgIdInput.val( '' );
80
81 //trigger update widget
82 options.imgIdInput.change();
83 });
84
85 }
86
87 function updateFrame()
88 {
89 // Do something when the media frame is opened.
90 }
91
92 function selectImg()
93 {
94 // Get media attachment details from the frame state
95 var attachment = options.frame.state().get('selection').first().toJSON();
96 console.log(attachment);
97 // Send the attachment URL to our custom image input field.
98 options.imgContainer.append( attachment.name );
99
100 // Send the attachment id to our hidden input
101 options.imgIdInput.val( attachment.id );
102
103 // Hide the add image link
104 options.addImgLink.addClass( 'hidden' );
105
106 // Unhide the remove image link
107 options.delImgLink.removeClass( 'hidden' );
108
109 //trigger update widget
110 options.imgIdInput.change();
111 }
112
113 }