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.js

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

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