-
Notifications
You must be signed in to change notification settings - Fork 5
/
script.js
60 lines (50 loc) · 1.79 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
jQuery(document).ready(function() {
if (JSINFO.ACT === "admin") {return;}
jQuery('.plugin_caption_figure').each(function(i,e) {
let figureElem = jQuery(this).find("img").first();
let figureCaptionElem = jQuery(this).find("figcaption").first();
getImageSize(figureElem, function(width, height){
figureElemWidth = width;
if (figureElem.attr("width") !== 0 && figureElem.attr("width") !== undefined && figureElem.attr("width") !== false) {
figureElemWidth = figureElem.attr('width');
}
let figureClassList = figureElem.attr('class').split(/\s+/);
jQuery(figureClassList).each(function(index){
switch(figureClassList[index]) {
case 'medialeft':
figureCaptionElem.addClass("medialeft");
figureCaptionElem.css("width", figureElemWidth);
break;
case 'mediaright':
figureCaptionElem.addClass("mediaright");
figureCaptionElem.css("width", figureElemWidth);
break;
}
});
});
});
});
function getImageSize(img, callback){
img = jQuery(img);
var wait = setInterval(function(){
var w = img.width(),
h = img.height();
if(w && h){
done(w, h);
}
}, 0);
var onLoad;
img.on('load', onLoad = function(){
done(img.width(), img.height());
});
var isDone = false;
function done(){
if(isDone){
return;
}
isDone = true;
clearInterval(wait);
img.off('load', onLoad);
callback.apply(this, arguments);
}
}