PluginProbe
Image Source Control Lite – Show Image Credits and Captions / 1.10.1
Image Source Control Lite – Show Image Credits and Captions v1.10.1
3.12.0 3.11.0 trunk 1.1 1.1.1 1.1.2 1.1.2.1 1.1.3 1.10 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.2 1.2.0.1 1.2.0.2 1.2.0.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.4.1 1.3.5 All 110 releases
image-source-control-isc / public / assets / js / front-js.js

front-js.js in Image Source Control Lite – Show Image Credits and Captions 1.10.1, at public/assets/js/front-js.js

113 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var isc_nb = 0;
2
3 jQuery(document).ready(function(){
4 /**
5 * Move caption into image with a short delay to way for the images to load
6 */
7 setTimeout( function(){
8 jQuery('.isc-source').each(function(){
9 jQuery(this).find('.isc-source-text').css({
10 position: 'absolute',
11 fontSize: '0.9em',
12 backgroundColor: "#333",
13 color: "#fff",
14 opacity: "0.70",
15 padding: '0 0.15em',
16 textShadow: 'none',
17 display: 'block',
18 });
19 // Some themes handle the bottom padding of the attachment's div with the caption text (which is in between
20 // the image and the bottom border) not with the div itself. The following line set the padding on the bottom equal to the top.
21 jQuery(this).css('padding-bottom', jQuery(this).css('padding-top'));
22 isc_update_caption_position(jQuery(this));
23 });
24 }, 100 );
25
26 jQuery(window).resize(function(){
27 isc_update_captions_positions();
28 });
29 /** doesn’t seem needed anymore
30 jQuery('.isc-source img').on('load', function(){
31 isc_update_captions_positions();
32 });
33 */
34 });
35
36 function isc_update_captions_positions() {
37 jQuery('.isc-source').each(function(){
38 isc_update_caption_position(jQuery(this));
39 });
40 }
41
42 function isc_update_caption_position(jQ_Obj) {
43 var main_id = jQ_Obj.attr('id');
44 var att_number = main_id.split('_')[2];
45 // try to look for single image only in case this is a gallery
46 // var att = jQ_Obj.find('.wp-image-' + att_number);
47 var att = jQ_Obj.find( 'img' );
48 // console.log( att );
49 var attw = att.width();
50 var atth = att.height();
51
52 //relative position
53 var l = att.position().left;
54 //relative position
55 var t = att.position().top;
56
57 var caption = jQ_Obj.find('.isc-source-text');
58
59 //caption width + padding & margin (after moving onto image)
60 var tw = caption.outerWidth(true);
61 //caption height + padding (idem)
62 var th = caption.outerHeight(true);
63
64 var attpl = parseInt(att.css('padding-left').substring(0, att.css('padding-left').indexOf('px')));
65 var attml = parseInt(att.css('margin-left').substring(0, att.css('margin-left').indexOf('px')));
66 var attpt = parseInt(att.css('padding-top').substring(0, att.css('padding-top').indexOf('px')));
67 var attmt = parseInt(att.css('margin-top').substring(0, att.css('margin-top').indexOf('px')));
68
69 //caption horizontal margin
70 var tml = 5;
71 //caption vertical margin
72 var tmt = 5;
73
74 var pos = isc_front_data.caption_position;
75 var posl = 0;
76 var post = 0;
77 switch (pos) {
78 case 'top-left':
79 posl = l + attpl + attml + tml;
80 post = t + attpt + attmt + tmt;
81 break;
82 case 'top-center':
83 posl = l + (Math.round(attw/2) - (Math.round(tw/2))) + attpl + attml;
84 post = t + attpt + attmt + tmt;
85 break;
86 case 'top-right':
87 posl = l - attpl + attml - tml + attw - tw;
88 post = t + attpt + attmt + tmt;
89 break;
90 case 'center':
91 posl = l + (Math.round(attw/2) - (Math.round(tw/2))) + attpl + attml;
92 post = t + (Math.round(atth/2) - (Math.round(th/2))) + attpt + attmt;
93 break;
94 case 'bottom-left':
95 posl = l + attpl + attml + tml;
96 post = t - attpt + attmt - tmt - th + atth;
97 break;
98 case 'bottom-center':
99 posl = l + (Math.round(attw/2) - (Math.round(tw/2))) + attpl + attml;
100 post = t + attpt + attmt - tmt - th + atth;
101 break;
102 case 'bottom-right':
103 posl = l - attpl + attml - tml + attw - tw;
104 post = t + attpt + attmt - tmt - th + atth;
105 break;
106 }
107 caption.css({
108 left: posl + 'px',
109 top: post + 'px',
110 zIndex: 9999,
111 });
112 }
113