-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexif-lightbox.js
89 lines (69 loc) · 2.79 KB
/
exif-lightbox.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
jQuery(document).ready(function () {
// find any image placed inside .bbp-topic-content or bbp-reply-content
format_exp_time = function(time){
if (time<1){
tmp = (1/time);
tmp = Math.round(tmp * 1000) / 1000; //make sure time=0.0666667 is turning into 1/15 and not 1/14.999999
return '1/' + tmp;
}
return '"' + time;
}
getItems = function () {
var items = [];
itemCounter = 0;
jQuery('.bbp-reply-content .lightbox, .bbp-topic-content .lightbox').each(function (index) {
//get all images that wants to be displayed in a lightbox
var imageAnchor = jQuery(this);
var exifData = imageAnchor.attr('data-exif');
fullSizeImage = imageAnchor.attr('href'),
dimensions = imageAnchor.attr('data-dimensions').split('x'),
width = dimensions[0],
height = dimensions[1];
var modifiedExifData = JSON.parse(exifData);
var exifHtml = '';
jQuery.each(modifiedExifData.image_meta, function(key, value){
if(key == 'aperture' && value != '0'){
exifHtml += '<strong>Aperture:</strong> f/' + value;
}
if(key == 'camera' && value != ''){
exifHtml += ' | <strong>Camera:</strong> ' + value;
}
if (key == 'shutter_speed' && value != '0') {
exifHtml += ' | <strong>Exposure time:</strong> ' + format_exp_time(value);
}
if (key == 'focal_length' && value != '0') {
exifHtml += ' | <strong>Focal length:</strong> ' + value + ' mm';
}
if (key == 'iso' && value != '0') {
exifHtml += ' | <strong>ISO:</strong> ' + value;
}
});
var item = {
src: fullSizeImage,
w: width,
h: height,
index: itemCounter,
title: exifHtml
}
jQuery(this).attr('data-index', itemCounter);
items.push(item);
itemCounter++;
});
return items;
}
var items = getItems();
var pswp = jQuery('.pswp')[0];
jQuery('.bbp-reply-content .lightbox, .bbp-topic-content .lightbox').click(function (event) {
event.preventDefault();
var itemCount = parseInt(jQuery(this).attr("data-index"), 10);
var options = {
index: itemCount,
bgOpacity: 0.7,
showHideOpacity: true
}
// Initialize PhotoSwipe
var lightBox = new PhotoSwipe(pswp, PhotoSwipeUI_Default, items, options);
lightBox.init();
return false;
});
});