PluginProbe ʕ •ᴥ•ʔ
Image Widget / 3.3
Image Widget v3.3
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 / image-widget.js
image-widget Last commit date
lang 15 years ago views 15 years ago image-widget-fix-browser-upload.js 14 years ago image-widget.js 14 years ago image-widget.php 14 years ago readme.txt 14 years ago screenshot-1.png 16 years ago screenshot-2.png 16 years ago screenshot-3.png 16 years ago
image-widget.js
117 lines
1 (function($){
2
3 window.set_active_widget = function(instance_id) {
4 self.IW_instance = instance_id;
5 }
6
7 function image_widget_send_to_editor(h) {
8 // ignore content returned from media uploader and use variables passed to window instead
9
10 // store attachment id in hidden field
11 $( '#widget-'+self.IW_instance+'-image' ).val( self.IW_img_id );
12
13 // display attachment preview
14 $( '#display-widget-'+self.IW_instance+'-image' ).html( self.IW_html );
15
16 // change width & height fields in widget to match image
17 $( '#widget-'+self.IW_instance+'-width' ).val($( '#display-widget-'+self.IW_instance+'-image img').attr('width'));
18 $( '#widget-'+self.IW_instance+'-height' ).val($( '#display-widget-'+self.IW_instance+'-image img').attr('height'));
19
20 // set alignment in widget
21 $( '#widget-'+self.IW_instance+'-align' ).val(self.IW_align);
22
23 // set title in widget
24 $( '#widget-'+self.IW_instance+'-title' ).val(self.IW_title);
25
26 // set caption in widget
27 $( '#widget-'+self.IW_instance+'-description' ).val(self.IW_caption);
28
29 // set alt text in widget
30 $( '#widget-'+self.IW_instance+'-alt' ).val(self.IW_alt);
31
32 // set link in widget
33 $( '#widget-'+self.IW_instance+'-link' ).val(self.IW_url);
34
35 // close thickbox
36 tb_remove();
37
38 // change button text
39 $('#add_image-widget-'+self.IW_instance+'-image').html($('#add_image-widget-'+self.IW_instance+'-image').html().replace(/Add Image/g, 'Change Image'));
40 }
41
42 function changeImgWidth(instance) {
43 var width = $( '#widget-'+instance+'-width' ).val();
44 var height = Math.round(width / imgRatio(instance));
45 changeImgSize(instance,width,height);
46 }
47
48 function changeImgHeight(instance) {
49 var height = $( '#widget-'+instance+'-height' ).val();
50 var width = Math.round(height * imgRatio(instance));
51 changeImgSize(instance,width,height);
52 }
53
54 function imgRatio(instance) {
55 var width_old = $( '#display-widget-'+instance+'-image img').attr('width');
56 var height_old = $( '#display-widget-'+instance+'-image img').attr('height');
57 var ratio = width_old / height_old;
58 return ratio;
59 }
60
61 function changeImgSize(instance,width,height) {
62 if (isNaN(width) || width < 1) {
63 $( '#widget-'+instance+'-width' ).val('');
64 width = 'none';
65 } else {
66 $( '#widget-'+instance+'-width' ).val(width);
67 width = width + 'px';
68 }
69 $( '#display-widget-'+instance+'-image img' ).css({
70 'width':width
71 });
72
73 if (isNaN(height) || height < 1) {
74 $( '#widget-'+instance+'-height' ).val('');
75 height = 'none';
76 } else {
77 $( '#widget-'+instance+'-height' ).val(height);
78 height = height + 'px';
79 }
80 $( '#display-widget-'+instance+'-image img' ).css({
81 'height':height
82 });
83 }
84
85 function changeImgAlign(instance) {
86 var align = $( '#widget-'+instance+'-align' ).val();
87 $( '#display-widget-'+instance+'-image img' ).attr(
88 'class', (align == 'none' ? '' : 'align'+align)
89 );
90 }
91
92 function imgHandler(event) {
93 event.preventDefault();
94 window.send_to_editor = image_widget_send_to_editor;
95 tb_show("Add an Image", event.target.href, false);
96 }
97
98 $(document).ready(function() {
99 // Use new style event handling since $.fn.live() will be deprecated
100 if ( typeof $.fn.on !== 'undefined' ) {
101 $("#wpbody").on("click", ".thickbox-image-widget", imgHandler);
102 }
103 else {
104 $("a.thickbox-image-widget").live('click', imgHandler);
105 }
106
107 // Modify thickbox link to fit window. Adapted from wp-admin\js\media-upload.dev.js.
108 $('a.thickbox-image-widget').each( function() {
109 var href = $(this).attr('href'), width = $(window).width(), H = $(window).height(), W = ( 720 < width ) ? 720 : width;
110 if ( ! href ) return;
111 href = href.replace(/&width=[0-9]+/g, '');
112 href = href.replace(/&height=[0-9]+/g, '');
113 $(this).attr( 'href', href + '&width=' + ( W - 80 ) + '&height=' + ( H - 85 ) );
114 });
115 });
116
117 })(jQuery);