PluginProbe ʕ •ᴥ•ʔ
Image Widget / 4.4.8
Image Widget v4.4.8
trunk 1.0 2.0 2.1 2.2 2.2.1 2.2.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.2 3.2.1 3.2.10 3.2.11 3.2.2 3.2.3 3.2.4 3.2.5 3.2.7 3.2.8 3.2.9 3.3 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1 4.1.1 4.1.2 4.2 4.2.1 4.2.2 4.3 4.3.1 4.4 4.4.1 4.4.11 4.4.12 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9
image-widget / resources / js / image-widget.js
image-widget / resources / js Last commit date
image-widget.deprecated.js 4 years ago image-widget.deprecated.upload-fixer.js 4 years ago image-widget.js 4 years ago index.php 4 years ago
image-widget.js
119 lines
1 /**
2 * Tribe Image Widget Javascript
3 * @author Modern Tribe, Inc.
4 * Copyright 2013.
5 */
6 jQuery(document).ready(function($){
7
8 imageWidget = {
9
10 // Call this from the upload button to initiate the upload frame.
11 uploader : function( widget_id, widget_id_string ) {
12
13 var frame = wp.media({
14 title : TribeImageWidget.frame_title,
15 multiple : false,
16 library : { type : 'image' },
17 button : { text : TribeImageWidget.button_title }
18 });
19
20 // Handle results from media manager.
21 frame.on('close',function( ) {
22 var attachments = frame.state().get('selection').toJSON();
23 imageWidget.render( widget_id, widget_id_string, attachments[0] );
24 });
25
26 frame.open();
27 return false;
28 },
29
30 // Output Image preview and populate widget form.
31 render : function( widget_id, widget_id_string, attachment ) {
32
33 var $attachment_id = $( document.getElementById( widget_id_string + 'attachment_id' ) );
34 var $image_url = $( document.getElementById( widget_id_string + 'imageurl' ) );
35
36 $("#" + widget_id_string + 'preview').html(imageWidget.imgHTML( attachment ));
37
38 $("#" + widget_id_string + 'fields').slideDown();
39
40 // update the attachment id if it has changed
41 if ( $attachment_id.val() !== attachment.id ) {
42 $attachment_id.val( attachment.id ).trigger( 'change' );
43 }
44
45 // update the url if it has changed
46 if ( $image_url.val() !== attachment.url ) {
47 $image_url.val( attachment.url ).trigger( 'change' );
48 }
49
50 $("#" + widget_id_string + 'aspect_ratio').val(attachment.width/attachment.height);
51 $("#" + widget_id_string + 'width').val(attachment.width);
52 $("#" + widget_id_string + 'height').val(attachment.height);
53
54 $("#" + widget_id_string + 'size').val('full');
55 $("#" + widget_id_string + 'custom_size_selector').slideDown();
56 imageWidget.toggleSizes( widget_id, widget_id_string );
57
58 imageWidget.updateInputIfEmpty( widget_id_string, 'title', attachment.title );
59 imageWidget.updateInputIfEmpty( widget_id_string, 'alt', attachment.alt );
60 imageWidget.updateInputIfEmpty( widget_id_string, 'description', attachment.description );
61 // attempt to populate 'description' with caption if description is blank.
62 imageWidget.updateInputIfEmpty( widget_id_string, 'description', attachment.caption );
63 },
64
65 // Update input fields if it is empty
66 updateInputIfEmpty : function( widget_id_string, name, value ) {
67 var field = $("#" + widget_id_string + name);
68 if ( field.val() == '' ) {
69 field.val(value);
70 }
71 },
72
73 // Render html for the image.
74 imgHTML : function( attachment ) {
75 var img_html = '<img src="' + attachment.url + '" ';
76 img_html += 'width="' + attachment.width + '" ';
77 img_html += 'height="' + attachment.height + '" ';
78 if ( attachment.alt != '' ) {
79 img_html += 'alt="' + attachment.alt + '" ';
80 }
81 img_html += '/>';
82 return img_html;
83 },
84
85 // Hide or display the WordPress image size fields depending on if 'Custom' is selected.
86 toggleSizes : function( widget_id, widget_id_string ) {
87 if ( $( '#' + widget_id_string + 'size' ).val() == 'tribe_image_widget_custom' ) {
88 $( '#' + widget_id_string + 'custom_size_fields').slideDown();
89 } else {
90 $( '#' + widget_id_string + 'custom_size_fields').slideUp();
91 }
92 },
93
94 // Update the image height based on the image width.
95 changeImgWidth : function( widget_id, widget_id_string ) {
96 var aspectRatio = $("#" + widget_id_string + 'aspect_ratio').val();
97 if ( aspectRatio ) {
98 var width = $( '#' + widget_id_string + 'width' ).val();
99 var height = Math.round( width / aspectRatio );
100 $( '#' + widget_id_string + 'height' ).val(height);
101 //imageWidget.changeImgSize( widget_id, widget_id_string, width, height );
102 }
103 },
104
105 // Update the image width based on the image height.
106 changeImgHeight : function( widget_id, widget_id_string ) {
107 var aspectRatio = $("#" + widget_id_string + 'aspect_ratio').val();
108 if ( aspectRatio ) {
109 var height = $( '#' + widget_id_string + 'height' ).val();
110 var width = Math.round( height * aspectRatio );
111 $( '#' + widget_id_string + 'width' ).val(width);
112 //imageWidget.changeImgSize( widget_id, widget_id_string, width, height );
113 }
114 }
115
116 };
117
118 });
119