1
1
function lightbox ( ) {
2
2
let img = document . getElementsByClassName ( 'post-image' ) ;
3
- let link ;
4
3
5
4
/*
6
5
* Load all the big images in the thread
7
6
*/
8
7
for ( let i = 0 ; i < img . length ; i ++ ) {
9
- link = img [ i ] . parentElement . href ;
8
+ let link = img [ i ] . parentElement . href ;
10
9
document . getElementById ( 'thread' ) . insertAdjacentHTML ( 'afterbegin' , '<img class="lightbox-img-hide" src="' + link + '">' ) ;
11
10
}
12
11
@@ -16,13 +15,33 @@ function lightbox(){
16
15
* the image appears in the lightbox
17
16
*/
18
17
img [ i ] . addEventListener ( 'mouseover' , function ( ) {
19
- link = this . parentElement . href ;
20
- document . getElementById ( 'thread' ) . insertAdjacentHTML ( 'afterbegin' , '<div id="lightbox"><img id="lightbox-img" src="' + link + '"></div>' ) ;
18
+ let link = this . parentElement . href ;
19
+ let ext = link . slice ( - 4 , link . length ) ;
20
+ switch ( ext ) {
21
+ case '.png' :
22
+ case '.jpg' :
23
+ case 'jpeg' :
24
+ case '.gif' :
25
+ document . getElementById ( 'thread' ) . insertAdjacentHTML (
26
+ 'afterbegin' ,
27
+ '<div id="lightbox"><img id="lightbox-img" src="' + link + '"></div>'
28
+ ) ;
29
+ break ;
30
+ default :
31
+ let file = link . indexOf ( '&' ) ;
32
+ link = link . slice ( 0 , file ) ;
33
+ document . getElementById ( 'thread' ) . insertAdjacentHTML (
34
+ 'afterbegin' ,
35
+ '<div id="lightbox"><video id="lightbox-video" src="' + link + '" autoplay="true" loop="true"></video></div>'
36
+ ) ;
37
+ console . log ( link ) ;
38
+ break ;
39
+ }
21
40
} , false ) ;
22
41
23
42
/*
24
- * When pointer is out: Remove the lightbox from the DOM
25
- */
43
+ * When pointer is out: Remove the lightbox from the DOM
44
+ */
26
45
img [ i ] . addEventListener ( 'mouseout' , function ( ) {
27
46
document . getElementById ( 'lightbox' ) . parentNode . removeChild ( document . getElementById ( 'lightbox' ) ) ;
28
47
} , false ) ;
@@ -33,9 +52,9 @@ function lightbox(){
33
52
34
53
function expandIMG ( ) {
35
54
/*
36
- * It creates a button
37
- * in the bottom bar which can be used
38
- * to load all the original images in the thread
55
+ * It creates a button
56
+ * in the bottom bar which can be used
57
+ * to load all the original images in the thread
39
58
*/
40
59
41
60
let bottomBar = document . getElementsByClassName ( 'threadlinks' ) ;
0 commit comments