lightgallery.bundle.js
143 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
/*!
* justifiedGallery - v3.7.0
* http://miromannino.github.io/Justified-Gallery/
* Copyright (c) 2018 Miro Mannino
* Licensed under the MIT license.
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
module.exports = function( root, jQuery ) {
if ( jQuery === undefined ) {
// require('jQuery') returns a factory that requires window to
// build a jQuery instance, we normalize how we use modules
// that require this pattern but the window provided is a noop
// if it's defined (how jquery works)
if ( typeof window !== 'undefined' ) {
jQuery = require('jquery');
}
else {
jQuery = require('jquery')(root);
}
}
factory(jQuery);
return jQuery;
};
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
/**
* Justified Gallery controller constructor
*
* @param $gallery the gallery to build
* @param settings the settings (the defaults are in JustifiedGallery.defaults)
* @constructor
*/
var JustifiedGallery = function ($gallery, settings) {
this.settings = settings;
this.checkSettings();
this.imgAnalyzerTimeout = null;
this.entries = null;
this.buildingRow = {
entriesBuff : [],
width : 0,
height : 0,
aspectRatio : 0
};
this.lastFetchedEntry = null;
this.lastAnalyzedIndex = -1;
this.yield = {
every : 2, // do a flush every n flushes (must be greater than 1)
flushed : 0 // flushed rows without a yield
};
this.border = settings.border >= 0 ? settings.border : settings.margins;
this.maxRowHeight = this.retrieveMaxRowHeight();
this.suffixRanges = this.retrieveSuffixRanges();
this.offY = this.border;
this.rows = 0;
this.spinner = {
phase : 0,
timeSlot : 150,
$el : $('<div class="spinner"><span></span><span></span><span></span></div>'),
intervalId : null
};
this.scrollBarOn = false;
this.checkWidthIntervalId = null;
this.galleryWidth = $gallery.width();
this.$gallery = $gallery;
};
/** @returns {String} the best suffix given the width and the height */
JustifiedGallery.prototype.getSuffix = function (width, height) {
var longestSide, i;
longestSide = (width > height) ? width : height;
for (i = 0; i < this.suffixRanges.length; i++) {
if (longestSide <= this.suffixRanges[i]) {
return this.settings.sizeRangeSuffixes[this.suffixRanges[i]];
}
}
return this.settings.sizeRangeSuffixes[this.suffixRanges[i - 1]];
};
/**
* Remove the suffix from the string
*
* @returns {string} a new string without the suffix
*/
JustifiedGallery.prototype.removeSuffix = function (str, suffix) {
return str.substring(0, str.length - suffix.length);
};
/**
* @returns {boolean} a boolean to say if the suffix is contained in the str or not
*/
JustifiedGallery.prototype.endsWith = function (str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
};
/**
* Get the used suffix of a particular url
*
* @param str
* @returns {String} return the used suffix
*/
JustifiedGallery.prototype.getUsedSuffix = function (str) {
for (var si in this.settings.sizeRangeSuffixes) {
if (this.settings.sizeRangeSuffixes.hasOwnProperty(si)) {
if (this.settings.sizeRangeSuffixes[si].length === 0) continue;
if (this.endsWith(str, this.settings.sizeRangeSuffixes[si])) return this.settings.sizeRangeSuffixes[si];
}
}
return '';
};
/**
* Given an image src, with the width and the height, returns the new image src with the
* best suffix to show the best quality thumbnail.
*
* @returns {String} the suffix to use
*/
JustifiedGallery.prototype.newSrc = function (imageSrc, imgWidth, imgHeight, image) {
var newImageSrc;
if (this.settings.thumbnailPath) {
newImageSrc = this.settings.thumbnailPath(imageSrc, imgWidth, imgHeight, image);
} else {
var matchRes = imageSrc.match(this.settings.extension);
var ext = (matchRes !== null) ? matchRes[0] : '';
newImageSrc = imageSrc.replace(this.settings.extension, '');
newImageSrc = this.removeSuffix(newImageSrc, this.getUsedSuffix(newImageSrc));
newImageSrc += this.getSuffix(imgWidth, imgHeight) + ext;
}
return newImageSrc;
};
/**
* Shows the images that is in the given entry
*
* @param $entry the entry
* @param callback the callback that is called when the show animation is finished
*/
JustifiedGallery.prototype.showImg = function ($entry, callback) {
if (this.settings.cssAnimation) {
$entry.addClass('entry-visible');
if (callback) callback();
} else {
$entry.stop().fadeTo(this.settings.imagesAnimationDuration, 1.0, callback);
$entry.find(this.settings.imgSelector).stop().fadeTo(this.settings.imagesAnimationDuration, 1.0, callback);
}
};
/**
* Extract the image src form the image, looking from the 'safe-src', and if it can't be found, from the
* 'src' attribute. It saves in the image data the 'jg.originalSrc' field, with the extracted src.
*
* @param $image the image to analyze
* @returns {String} the extracted src
*/
JustifiedGallery.prototype.extractImgSrcFromImage = function ($image) {
var imageSrc = (typeof $image.data('safe-src') !== 'undefined') ? $image.data('safe-src') : $image.attr('src');
$image.data('jg.originalSrc', imageSrc);
return imageSrc;
};
/** @returns {jQuery} the image in the given entry */
JustifiedGallery.prototype.imgFromEntry = function ($entry) {
var $img = $entry.find(this.settings.imgSelector);
return $img.length === 0 ? null : $img;
};
/** @returns {jQuery} the caption in the given entry */
JustifiedGallery.prototype.captionFromEntry = function ($entry) {
var $caption = $entry.find('> .caption');
return $caption.length === 0 ? null : $caption;
};
/**
* Display the entry
*
* @param {jQuery} $entry the entry to display
* @param {int} x the x position where the entry must be positioned
* @param y the y position where the entry must be positioned
* @param imgWidth the image width
* @param imgHeight the image height
* @param rowHeight the row height of the row that owns the entry
*/
JustifiedGallery.prototype.displayEntry = function ($entry, x, y, imgWidth, imgHeight, rowHeight) {
$entry.width(imgWidth);
$entry.height(rowHeight);
$entry.css('top', y);
$entry.css('left', x);
var $image = this.imgFromEntry($entry);
if ($image !== null) {
$image.css('width', imgWidth);
$image.css('height', imgHeight);
$image.css('margin-left', - imgWidth / 2);
$image.css('margin-top', - imgHeight / 2);
// Image reloading for an high quality of thumbnails
var imageSrc = $image.attr('src');
var newImageSrc = this.newSrc(imageSrc, imgWidth, imgHeight, $image[0]);
$image.one('error', function () {
$image.attr('src', $image.data('jg.originalSrc')); //revert to the original thumbnail, we got it.
});
var loadNewImage = function () {
if (imageSrc !== newImageSrc) { //load the new image after the fadeIn
$image.attr('src', newImageSrc);
}
};
if ($entry.data('jg.loaded') === 'skipped') {
this.onImageEvent(imageSrc, $.proxy(function() {
this.showImg($entry, loadNewImage);
$entry.data('jg.loaded', true);
}, this));
} else {
this.showImg($entry, loadNewImage);
}
} else {
this.showImg($entry);
}
this.displayEntryCaption($entry);
};
/**
* Display the entry caption. If the caption element doesn't exists, it creates the caption using the 'alt'
* or the 'title' attributes.
*
* @param {jQuery} $entry the entry to process
*/
JustifiedGallery.prototype.displayEntryCaption = function ($entry) {
var $image = this.imgFromEntry($entry);
if ($image !== null && this.settings.captions) {
var $imgCaption = this.captionFromEntry($entry);
// Create it if it doesn't exists
if ($imgCaption === null) {
var caption = $image.attr('alt');
if (!this.isValidCaption(caption)) caption = $entry.attr('title');
if (this.isValidCaption(caption)) { // Create only we found something
$imgCaption = $('<div class="caption">' + caption + '</div>');
$entry.append($imgCaption);
$entry.data('jg.createdCaption', true);
}
}
// Create events (we check again the $imgCaption because it can be still inexistent)
if ($imgCaption !== null) {
if (!this.settings.cssAnimation) $imgCaption.stop().fadeTo(0, this.settings.captionSettings.nonVisibleOpacity);
this.addCaptionEventsHandlers($entry);
}
} else {
this.removeCaptionEventsHandlers($entry);
}
};
/**
* Validates the caption
*
* @param caption The caption that should be validated
* @return {boolean} Validation result
*/
JustifiedGallery.prototype.isValidCaption = function (caption) {
return (typeof caption !== 'undefined' && caption.length > 0);
};
/**
* The callback for the event 'mouseenter'. It assumes that the event currentTarget is an entry.
* It shows the caption using jQuery (or using CSS if it is configured so)
*
* @param {Event} eventObject the event object
*/
JustifiedGallery.prototype.onEntryMouseEnterForCaption = function (eventObject) {
var $caption = this.captionFromEntry($(eventObject.currentTarget));
if (this.settings.cssAnimation) {
$caption.addClass('caption-visible').removeClass('caption-hidden');
} else {
$caption.stop().fadeTo(this.settings.captionSettings.animationDuration,
this.settings.captionSettings.visibleOpacity);
}
};
/**
* The callback for the event 'mouseleave'. It assumes that the event currentTarget is an entry.
* It hides the caption using jQuery (or using CSS if it is configured so)
*
* @param {Event} eventObject the event object
*/
JustifiedGallery.prototype.onEntryMouseLeaveForCaption = function (eventObject) {
var $caption = this.captionFromEntry($(eventObject.currentTarget));
if (this.settings.cssAnimation) {
$caption.removeClass('caption-visible').removeClass('caption-hidden');
} else {
$caption.stop().fadeTo(this.settings.captionSettings.animationDuration,
this.settings.captionSettings.nonVisibleOpacity);
}
};
/**
* Add the handlers of the entry for the caption
*
* @param $entry the entry to modify
*/
JustifiedGallery.prototype.addCaptionEventsHandlers = function ($entry) {
var captionMouseEvents = $entry.data('jg.captionMouseEvents');
if (typeof captionMouseEvents === 'undefined') {
captionMouseEvents = {
mouseenter: $.proxy(this.onEntryMouseEnterForCaption, this),
mouseleave: $.proxy(this.onEntryMouseLeaveForCaption, this)
};
$entry.on('mouseenter', undefined, undefined, captionMouseEvents.mouseenter);
$entry.on('mouseleave', undefined, undefined, captionMouseEvents.mouseleave);
$entry.data('jg.captionMouseEvents', captionMouseEvents);
}
};
/**
* Remove the handlers of the entry for the caption
*
* @param $entry the entry to modify
*/
JustifiedGallery.prototype.removeCaptionEventsHandlers = function ($entry) {
var captionMouseEvents = $entry.data('jg.captionMouseEvents');
if (typeof captionMouseEvents !== 'undefined') {
$entry.off('mouseenter', undefined, captionMouseEvents.mouseenter);
$entry.off('mouseleave', undefined, captionMouseEvents.mouseleave);
$entry.removeData('jg.captionMouseEvents');
}
};
/**
* Clear the building row data to be used for a new row
*/
JustifiedGallery.prototype.clearBuildingRow = function () {
this.buildingRow.entriesBuff = [];
this.buildingRow.aspectRatio = 0;
this.buildingRow.width = 0;
};
/**
* Justify the building row, preparing it to
*
* @param isLastRow
* @returns a boolean to know if the row has been justified or not
*/
JustifiedGallery.prototype.prepareBuildingRow = function (isLastRow) {
var i, $entry, imgAspectRatio, newImgW, newImgH, justify = true;
var minHeight = 0;
var availableWidth = this.galleryWidth - 2 * this.border - (
(this.buildingRow.entriesBuff.length - 1) * this.settings.margins);
var rowHeight = availableWidth / this.buildingRow.aspectRatio;
var defaultRowHeight = this.settings.rowHeight;
var justifiable = this.buildingRow.width / availableWidth > this.settings.justifyThreshold;
//Skip the last row if we can't justify it and the lastRow == 'hide'
if (isLastRow && this.settings.lastRow === 'hide' && !justifiable) {
for (i = 0; i < this.buildingRow.entriesBuff.length; i++) {
$entry = this.buildingRow.entriesBuff[i];
if (this.settings.cssAnimation)
$entry.removeClass('entry-visible');
else {
$entry.stop().fadeTo(0, 0.1);
$entry.find('> img, > a > img').fadeTo(0, 0);
}
}
return -1;
}
// With lastRow = nojustify, justify if is justificable (the images will not become too big)
if (isLastRow && !justifiable && this.settings.lastRow !== 'justify' && this.settings.lastRow !== 'hide') {
justify = false;
if (this.rows > 0) {
defaultRowHeight = (this.offY - this.border - this.settings.margins * this.rows) / this.rows;
justify = defaultRowHeight * this.buildingRow.aspectRatio / availableWidth > this.settings.justifyThreshold;
}
}
for (i = 0; i < this.buildingRow.entriesBuff.length; i++) {
$entry = this.buildingRow.entriesBuff[i];
imgAspectRatio = $entry.data('jg.width') / $entry.data('jg.height');
if (justify) {
newImgW = (i === this.buildingRow.entriesBuff.length - 1) ? availableWidth : rowHeight * imgAspectRatio;
newImgH = rowHeight;
} else {
newImgW = defaultRowHeight * imgAspectRatio;
newImgH = defaultRowHeight;
}
availableWidth -= Math.round(newImgW);
$entry.data('jg.jwidth', Math.round(newImgW));
$entry.data('jg.jheight', Math.ceil(newImgH));
if (i === 0 || minHeight > newImgH) minHeight = newImgH;
}
this.buildingRow.height = minHeight;
return justify;
};
/**
* Flush a row: justify it, modify the gallery height accordingly to the row height
*
* @param isLastRow
*/
JustifiedGallery.prototype.flushRow = function (isLastRow) {
var settings = this.settings;
var $entry, buildingRowRes, offX = this.border, i;
buildingRowRes = this.prepareBuildingRow(isLastRow);
if (isLastRow && settings.lastRow === 'hide' && buildingRowRes === -1) {
this.clearBuildingRow();
return;
}
if(this.maxRowHeight) {
if(this.maxRowHeight < this.buildingRow.height) this.buildingRow.height = this.maxRowHeight;
}
//Align last (unjustified) row
if (isLastRow && (settings.lastRow === 'center' || settings.lastRow === 'right')) {
var availableWidth = this.galleryWidth - 2 * this.border - (this.buildingRow.entriesBuff.length - 1) * settings.margins;
for (i = 0; i < this.buildingRow.entriesBuff.length; i++) {
$entry = this.buildingRow.entriesBuff[i];
availableWidth -= $entry.data('jg.jwidth');
}
if (settings.lastRow === 'center')
offX += availableWidth / 2;
else if (settings.lastRow === 'right')
offX += availableWidth;
}
var lastEntryIdx = this.buildingRow.entriesBuff.length - 1;
for (i = 0; i <= lastEntryIdx; i++) {
$entry = this.buildingRow.entriesBuff[ this.settings.rtl ? lastEntryIdx - i : i ];
this.displayEntry($entry, offX, this.offY, $entry.data('jg.jwidth'), $entry.data('jg.jheight'), this.buildingRow.height);
offX += $entry.data('jg.jwidth') + settings.margins;
}
//Gallery Height
this.galleryHeightToSet = this.offY + this.buildingRow.height + this.border;
this.setGalleryTempHeight(this.galleryHeightToSet + this.getSpinnerHeight());
if (!isLastRow || (this.buildingRow.height <= settings.rowHeight && buildingRowRes)) {
//Ready for a new row
this.offY += this.buildingRow.height + settings.margins;
this.rows += 1;
this.clearBuildingRow();
this.settings.triggerEvent.call(this, 'jg.rowflush');
}
};
// Scroll position not restoring: https://github.com/miromannino/Justified-Gallery/issues/221
var galleryPrevStaticHeight = 0;
JustifiedGallery.prototype.rememberGalleryHeight = function () {
galleryPrevStaticHeight = this.$gallery.height();
this.$gallery.height(galleryPrevStaticHeight);
};
// grow only
JustifiedGallery.prototype.setGalleryTempHeight = function (height) {
galleryPrevStaticHeight = Math.max(height, galleryPrevStaticHeight);
this.$gallery.height(galleryPrevStaticHeight);
};
JustifiedGallery.prototype.setGalleryFinalHeight = function (height) {
galleryPrevStaticHeight = height;
this.$gallery.height(height);
};
/**
* @returns {boolean} a boolean saying if the scrollbar is active or not
*/
function hasScrollBar() {
return $("body").height() > $(window).height();
}
/**
* Checks the width of the gallery container, to know if a new justification is needed
*/
JustifiedGallery.prototype.checkWidth = function () {
this.checkWidthIntervalId = setInterval($.proxy(function () {
// if the gallery is not currently visible, abort.
if (!this.$gallery.is(":visible")) return;
var galleryWidth = parseFloat(this.$gallery.width());
if (hasScrollBar() === this.scrollBarOn) {
if (Math.abs(galleryWidth - this.galleryWidth) > this.settings.refreshSensitivity) {
this.galleryWidth = galleryWidth;
this.rewind();
this.rememberGalleryHeight();
// Restart to analyze
this.startImgAnalyzer(true);
}
} else {
this.scrollBarOn = hasScrollBar();
this.galleryWidth = galleryWidth;
}
}, this), this.settings.refreshTime);
};
/**
* @returns {boolean} a boolean saying if the spinner is active or not
*/
JustifiedGallery.prototype.isSpinnerActive = function () {
return this.spinner.intervalId !== null;
};
/**
* @returns {int} the spinner height
*/
JustifiedGallery.prototype.getSpinnerHeight = function () {
return this.spinner.$el.innerHeight();
};
/**
* Stops the spinner animation and modify the gallery height to exclude the spinner
*/
JustifiedGallery.prototype.stopLoadingSpinnerAnimation = function () {
clearInterval(this.spinner.intervalId);
this.spinner.intervalId = null;
this.setGalleryTempHeight(this.$gallery.height() - this.getSpinnerHeight());
this.spinner.$el.detach();
};
/**
* Starts the spinner animation
*/
JustifiedGallery.prototype.startLoadingSpinnerAnimation = function () {
var spinnerContext = this.spinner;
var $spinnerPoints = spinnerContext.$el.find('span');
clearInterval(spinnerContext.intervalId);
this.$gallery.append(spinnerContext.$el);
this.setGalleryTempHeight(this.offY + this.buildingRow.height + this.getSpinnerHeight());
spinnerContext.intervalId = setInterval(function () {
if (spinnerContext.phase < $spinnerPoints.length) {
$spinnerPoints.eq(spinnerContext.phase).fadeTo(spinnerContext.timeSlot, 1);
} else {
$spinnerPoints.eq(spinnerContext.phase - $spinnerPoints.length).fadeTo(spinnerContext.timeSlot, 0);
}
spinnerContext.phase = (spinnerContext.phase + 1) % ($spinnerPoints.length * 2);
}, spinnerContext.timeSlot);
};
/**
* Rewind the image analysis to start from the first entry.
*/
JustifiedGallery.prototype.rewind = function () {
this.lastFetchedEntry = null;
this.lastAnalyzedIndex = -1;
this.offY = this.border;
this.rows = 0;
this.clearBuildingRow();
};
/**
* Update the entries searching it from the justified gallery HTML element
*
* @param norewind if norewind only the new entries will be changed (i.e. randomized, sorted or filtered)
* @returns {boolean} true if some entries has been founded
*/
JustifiedGallery.prototype.updateEntries = function (norewind) {
var newEntries;
if (norewind && this.lastFetchedEntry != null) {
newEntries = $(this.lastFetchedEntry).nextAll(this.settings.selector).toArray();
} else {
this.entries = [];
newEntries = this.$gallery.children(this.settings.selector).toArray();
}
if (newEntries.length > 0) {
// Sort or randomize
if ($.isFunction(this.settings.sort)) {
newEntries = this.sortArray(newEntries);
} else if (this.settings.randomize) {
newEntries = this.shuffleArray(newEntries);
}
this.lastFetchedEntry = newEntries[newEntries.length - 1];
// Filter
if (this.settings.filter) {
newEntries = this.filterArray(newEntries);
} else {
this.resetFilters(newEntries);
}
}
this.entries = this.entries.concat(newEntries);
return true;
};
/**
* Apply the entries order to the DOM, iterating the entries and appending the images
*
* @param entries the entries that has been modified and that must be re-ordered in the DOM
*/
JustifiedGallery.prototype.insertToGallery = function (entries) {
var that = this;
$.each(entries, function () {
$(this).appendTo(that.$gallery);
});
};
/**
* Shuffle the array using the Fisher-Yates shuffle algorithm
*
* @param a the array to shuffle
* @return the shuffled array
*/
JustifiedGallery.prototype.shuffleArray = function (a) {
var i, j, temp;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
this.insertToGallery(a);
return a;
};
/**
* Sort the array using settings.comparator as comparator
*
* @param a the array to sort (it is sorted)
* @return the sorted array
*/
JustifiedGallery.prototype.sortArray = function (a) {
a.sort(this.settings.sort);
this.insertToGallery(a);
return a;
};
/**
* Reset the filters removing the 'jg-filtered' class from all the entries
*
* @param a the array to reset
*/
JustifiedGallery.prototype.resetFilters = function (a) {
for (var i = 0; i < a.length; i++) $(a[i]).removeClass('jg-filtered');
};
/**
* Filter the entries considering theirs classes (if a string has been passed) or using a function for filtering.
*
* @param a the array to filter
* @return the filtered array
*/
JustifiedGallery.prototype.filterArray = function (a) {
var settings = this.settings;
if ($.type(settings.filter) === 'string') {
// Filter only keeping the entries passed in the string
return a.filter(function (el) {
var $el = $(el);
if ($el.is(settings.filter)) {
$el.removeClass('jg-filtered');
return true;
} else {
$el.addClass('jg-filtered').removeClass('jg-visible');
return false;
}
});
} else if ($.isFunction(settings.filter)) {
// Filter using the passed function
var filteredArr = a.filter(settings.filter);
for (var i = 0; i < a.length; i++) {
if (filteredArr.indexOf(a[i]) === -1) {
$(a[i]).addClass('jg-filtered').removeClass('jg-visible');
} else {
$(a[i]).removeClass('jg-filtered');
}
}
return filteredArr;
}
};
/**
* Destroy the Justified Gallery instance.
*
* It clears all the css properties added in the style attributes. We doesn't backup the original
* values for those css attributes, because it costs (performance) and because in general one
* shouldn't use the style attribute for an uniform set of images (where we suppose the use of
* classes). Creating a backup is also difficult because JG could be called multiple times and
* with different style attributes.
*/
JustifiedGallery.prototype.destroy = function () {
clearInterval(this.checkWidthIntervalId);
$.each(this.entries, $.proxy(function(_, entry) {
var $entry = $(entry);
// Reset entry style
$entry.css('width', '');
$entry.css('height', '');
$entry.css('top', '');
$entry.css('left', '');
$entry.data('jg.loaded', undefined);
$entry.removeClass('jg-entry');
// Reset image style
var $img = this.imgFromEntry($entry);
$img.css('width', '');
$img.css('height', '');
$img.css('margin-left', '');
$img.css('margin-top', '');
$img.attr('src', $img.data('jg.originalSrc'));
$img.data('jg.originalSrc', undefined);
// Remove caption
this.removeCaptionEventsHandlers($entry);
var $caption = this.captionFromEntry($entry);
if ($entry.data('jg.createdCaption')) {
// remove also the caption element (if created by jg)
$entry.data('jg.createdCaption', undefined);
if ($caption !== null) $caption.remove();
} else {
if ($caption !== null) $caption.fadeTo(0, 1);
}
}, this));
this.$gallery.css('height', '');
this.$gallery.removeClass('justified-gallery');
this.$gallery.data('jg.controller', undefined);
};
/**
* Analyze the images and builds the rows. It returns if it found an image that is not loaded.
*
* @param isForResize if the image analyzer is called for resizing or not, to call a different callback at the end
*/
JustifiedGallery.prototype.analyzeImages = function (isForResize) {
for (var i = this.lastAnalyzedIndex + 1; i < this.entries.length; i++) {
var $entry = $(this.entries[i]);
if ($entry.data('jg.loaded') === true || $entry.data('jg.loaded') === 'skipped') {
var availableWidth = this.galleryWidth - 2 * this.border - (
(this.buildingRow.entriesBuff.length - 1) * this.settings.margins);
var imgAspectRatio = $entry.data('jg.width') / $entry.data('jg.height');
if (availableWidth / (this.buildingRow.aspectRatio + imgAspectRatio) < this.settings.rowHeight) {
this.flushRow(false);
if(++this.yield.flushed >= this.yield.every) {
this.startImgAnalyzer(isForResize);
return;
}
}
this.buildingRow.entriesBuff.push($entry);
this.buildingRow.aspectRatio += imgAspectRatio;
this.buildingRow.width += imgAspectRatio * this.settings.rowHeight;
this.lastAnalyzedIndex = i;
} else if ($entry.data('jg.loaded') !== 'error') {
return;
}
}
// Last row flush (the row is not full)
if (this.buildingRow.entriesBuff.length > 0) this.flushRow(true);
if (this.isSpinnerActive()) {
this.stopLoadingSpinnerAnimation();
}
/* Stop, if there is, the timeout to start the analyzeImages.
This is because an image can be set loaded, and the timeout can be set,
but this image can be analyzed yet.
*/
this.stopImgAnalyzerStarter();
//On complete callback
this.settings.triggerEvent.call(this, isForResize ? 'jg.resize' : 'jg.complete');
this.setGalleryFinalHeight(this.galleryHeightToSet);
};
/**
* Stops any ImgAnalyzer starter (that has an assigned timeout)
*/
JustifiedGallery.prototype.stopImgAnalyzerStarter = function () {
this.yield.flushed = 0;
if (this.imgAnalyzerTimeout !== null) {
clearTimeout(this.imgAnalyzerTimeout);
this.imgAnalyzerTimeout = null;
}
};
/**
* Starts the image analyzer. It is not immediately called to let the browser to update the view
*
* @param isForResize specifies if the image analyzer must be called for resizing or not
*/
JustifiedGallery.prototype.startImgAnalyzer = function (isForResize) {
var that = this;
this.stopImgAnalyzerStarter();
this.imgAnalyzerTimeout = setTimeout(function () {
that.analyzeImages(isForResize);
}, 0.001); // we can't start it immediately due to a IE different behaviour
};
/**
* Checks if the image is loaded or not using another image object. We cannot use the 'complete' image property,
* because some browsers, with a 404 set complete = true.
*
* @param imageSrc the image src to load
* @param onLoad callback that is called when the image has been loaded
* @param onError callback that is called in case of an error
*/
JustifiedGallery.prototype.onImageEvent = function (imageSrc, onLoad, onError) {
if (!onLoad && !onError) return;
var memImage = new Image();
var $memImage = $(memImage);
if (onLoad) {
$memImage.one('load', function () {
$memImage.off('load error');
onLoad(memImage);
});
}
if (onError) {
$memImage.one('error', function() {
$memImage.off('load error');
onError(memImage);
});
}
memImage.src = imageSrc;
};
/**
* Init of Justified Gallery controlled
* It analyzes all the entries starting theirs loading and calling the image analyzer (that works with loaded images)
*/
JustifiedGallery.prototype.init = function () {
var imagesToLoad = false, skippedImages = false, that = this;
$.each(this.entries, function (index, entry) {
var $entry = $(entry);
var $image = that.imgFromEntry($entry);
$entry.addClass('jg-entry');
if ($entry.data('jg.loaded') !== true && $entry.data('jg.loaded') !== 'skipped') {
// Link Rel global overwrite
if (that.settings.rel !== null) $entry.attr('rel', that.settings.rel);
// Link Target global overwrite
if (that.settings.target !== null) $entry.attr('target', that.settings.target);
if ($image !== null) {
// Image src
var imageSrc = that.extractImgSrcFromImage($image);
$image.attr('src', imageSrc);
/* If we have the height and the width, we don't wait that the image is loaded, but we start directly
* with the justification */
if (that.settings.waitThumbnailsLoad === false) {
var width = parseFloat($image.prop('width'));
var height = parseFloat($image.prop('height'));
if (!isNaN(width) && !isNaN(height)) {
$entry.data('jg.width', width);
$entry.data('jg.height', height);
$entry.data('jg.loaded', 'skipped');
skippedImages = true;
that.startImgAnalyzer(false);
return true; // continue
}
}
$entry.data('jg.loaded', false);
imagesToLoad = true;
// Spinner start
if (!that.isSpinnerActive()) that.startLoadingSpinnerAnimation();
that.onImageEvent(imageSrc, function (loadImg) { // image loaded
$entry.data('jg.width', loadImg.width);
$entry.data('jg.height', loadImg.height);
$entry.data('jg.loaded', true);
that.startImgAnalyzer(false);
}, function () { // image load error
$entry.data('jg.loaded', 'error');
that.startImgAnalyzer(false);
});
} else {
$entry.data('jg.loaded', true);
$entry.data('jg.width', $entry.width() | parseFloat($entry.css('width')) | 1);
$entry.data('jg.height', $entry.height() | parseFloat($entry.css('height')) | 1);
}
}
});
if (!imagesToLoad && !skippedImages) this.startImgAnalyzer(false);
this.checkWidth();
};
/**
* Checks that it is a valid number. If a string is passed it is converted to a number
*
* @param settingContainer the object that contains the setting (to allow the conversion)
* @param settingName the setting name
*/
JustifiedGallery.prototype.checkOrConvertNumber = function (settingContainer, settingName) {
if ($.type(settingContainer[settingName]) === 'string') {
settingContainer[settingName] = parseFloat(settingContainer[settingName]);
}
if ($.type(settingContainer[settingName]) === 'number') {
if (isNaN(settingContainer[settingName])) throw 'invalid number for ' + settingName;
} else {
throw settingName + ' must be a number';
}
};
/**
* Checks the sizeRangeSuffixes and, if necessary, converts
* its keys from string (e.g. old settings with 'lt100') to int.
*/
JustifiedGallery.prototype.checkSizeRangesSuffixes = function () {
if ($.type(this.settings.sizeRangeSuffixes) !== 'object') {
throw 'sizeRangeSuffixes must be defined and must be an object';
}
var suffixRanges = [];
for (var rangeIdx in this.settings.sizeRangeSuffixes) {
if (this.settings.sizeRangeSuffixes.hasOwnProperty(rangeIdx)) suffixRanges.push(rangeIdx);
}
var newSizeRngSuffixes = {0: ''};
for (var i = 0; i < suffixRanges.length; i++) {
if ($.type(suffixRanges[i]) === 'string') {
try {
var numIdx = parseInt(suffixRanges[i].replace(/^[a-z]+/, ''), 10);
newSizeRngSuffixes[numIdx] = this.settings.sizeRangeSuffixes[suffixRanges[i]];
} catch (e) {
throw 'sizeRangeSuffixes keys must contains correct numbers (' + e + ')';
}
} else {
newSizeRngSuffixes[suffixRanges[i]] = this.settings.sizeRangeSuffixes[suffixRanges[i]];
}
}
this.settings.sizeRangeSuffixes = newSizeRngSuffixes;
};
/**
* check and convert the maxRowHeight setting
* requires rowHeight to be already set
* TODO: should be always called when only rowHeight is changed
* @return number or null
*/
JustifiedGallery.prototype.retrieveMaxRowHeight = function () {
var newMaxRowHeight = null;
var rowHeight = this.settings.rowHeight;
if ($.type(this.settings.maxRowHeight) === 'string') {
if (this.settings.maxRowHeight.match(/^[0-9]+%$/)) {
newMaxRowHeight = rowHeight * parseFloat(this.settings.maxRowHeight.match(/^([0-9]+)%$/)[1]) / 100;
} else {
newMaxRowHeight = parseFloat(this.settings.maxRowHeight);
}
} else if ($.type(this.settings.maxRowHeight) === 'number') {
newMaxRowHeight = this.settings.maxRowHeight;
} else if (this.settings.maxRowHeight === false || this.settings.maxRowHeight == null) {
return null;
} else {
throw 'maxRowHeight must be a number or a percentage';
}
// check if the converted value is not a number
if (isNaN(newMaxRowHeight)) throw 'invalid number for maxRowHeight';
// check values, maxRowHeight must be >= rowHeight
if (newMaxRowHeight < rowHeight) newMaxRowHeight = rowHeight;
return newMaxRowHeight;
};
/**
* Checks the settings
*/
JustifiedGallery.prototype.checkSettings = function () {
this.checkSizeRangesSuffixes();
this.checkOrConvertNumber(this.settings, 'rowHeight');
this.checkOrConvertNumber(this.settings, 'margins');
this.checkOrConvertNumber(this.settings, 'border');
var lastRowModes = [
'justify',
'nojustify',
'left',
'center',
'right',
'hide'
];
if (lastRowModes.indexOf(this.settings.lastRow) === -1) {
throw 'lastRow must be one of: ' + lastRowModes.join(', ');
}
this.checkOrConvertNumber(this.settings, 'justifyThreshold');
if (this.settings.justifyThreshold < 0 || this.settings.justifyThreshold > 1) {
throw 'justifyThreshold must be in the interval [0,1]';
}
if ($.type(this.settings.cssAnimation) !== 'boolean') {
throw 'cssAnimation must be a boolean';
}
if ($.type(this.settings.captions) !== 'boolean') throw 'captions must be a boolean';
this.checkOrConvertNumber(this.settings.captionSettings, 'animationDuration');
this.checkOrConvertNumber(this.settings.captionSettings, 'visibleOpacity');
if (this.settings.captionSettings.visibleOpacity < 0 ||
this.settings.captionSettings.visibleOpacity > 1) {
throw 'captionSettings.visibleOpacity must be in the interval [0, 1]';
}
this.checkOrConvertNumber(this.settings.captionSettings, 'nonVisibleOpacity');
if (this.settings.captionSettings.nonVisibleOpacity < 0 ||
this.settings.captionSettings.nonVisibleOpacity > 1) {
throw 'captionSettings.nonVisibleOpacity must be in the interval [0, 1]';
}
this.checkOrConvertNumber(this.settings, 'imagesAnimationDuration');
this.checkOrConvertNumber(this.settings, 'refreshTime');
this.checkOrConvertNumber(this.settings, 'refreshSensitivity');
if ($.type(this.settings.randomize) !== 'boolean') throw 'randomize must be a boolean';
if ($.type(this.settings.selector) !== 'string') throw 'selector must be a string';
if (this.settings.sort !== false && !$.isFunction(this.settings.sort)) {
throw 'sort must be false or a comparison function';
}
if (this.settings.filter !== false && !$.isFunction(this.settings.filter) &&
$.type(this.settings.filter) !== 'string') {
throw 'filter must be false, a string or a filter function';
}
};
/**
* It brings all the indexes from the sizeRangeSuffixes and it orders them. They are then sorted and returned.
* @returns {Array} sorted suffix ranges
*/
JustifiedGallery.prototype.retrieveSuffixRanges = function () {
var suffixRanges = [];
for (var rangeIdx in this.settings.sizeRangeSuffixes) {
if (this.settings.sizeRangeSuffixes.hasOwnProperty(rangeIdx)) suffixRanges.push(parseInt(rangeIdx, 10));
}
suffixRanges.sort(function (a, b) { return a > b ? 1 : a < b ? -1 : 0; });
return suffixRanges;
};
/**
* Update the existing settings only changing some of them
*
* @param newSettings the new settings (or a subgroup of them)
*/
JustifiedGallery.prototype.updateSettings = function (newSettings) {
// In this case Justified Gallery has been called again changing only some options
this.settings = $.extend({}, this.settings, newSettings);
this.checkSettings();
// As reported in the settings: negative value = same as margins, 0 = disabled
this.border = this.settings.border >= 0 ? this.settings.border : this.settings.margins;
this.maxRowHeight = this.retrieveMaxRowHeight();
this.suffixRanges = this.retrieveSuffixRanges();
};
JustifiedGallery.prototype.defaults = {
sizeRangeSuffixes: { }, /* e.g. Flickr configuration
{
100: '_t', // used when longest is less than 100px
240: '_m', // used when longest is between 101px and 240px
320: '_n', // ...
500: '',
640: '_z',
1024: '_b' // used as else case because it is the last
}
*/
thumbnailPath: undefined, /* If defined, sizeRangeSuffixes is not used, and this function is used to determine the
path relative to a specific thumbnail size. The function should accept respectively three arguments:
current path, width and height */
rowHeight: 120, // required? required to be > 0?
maxRowHeight: false, // false or negative value to deactivate. Positive number to express the value in pixels,
// A string '[0-9]+%' to express in percentage (e.g. 300% means that the row height
// can't exceed 3 * rowHeight)
margins: 1,
border: -1, // negative value = same as margins, 0 = disabled, any other value to set the border
lastRow: 'nojustify', // โฆ which is the same as 'left', or can be 'justify', 'center', 'right' or 'hide'
justifyThreshold: 0.90, /* if row width / available space > 0.90 it will be always justified
* (i.e. lastRow setting is not considered) */
waitThumbnailsLoad: true,
captions: true,
cssAnimation: true,
imagesAnimationDuration: 500, // ignored with css animations
captionSettings: { // ignored with css animations
animationDuration: 500,
visibleOpacity: 0.7,
nonVisibleOpacity: 0.0
},
rel: null, // rewrite the rel of each analyzed links
target: null, // rewrite the target of all links
extension: /\.[^.\\/]+$/, // regexp to capture the extension of an image
refreshTime: 200, // time interval (in ms) to check if the page changes its width
refreshSensitivity: 0, // change in width allowed (in px) without re-building the gallery
randomize: false,
rtl: false, // right-to-left mode
sort: false, /*
- false: to do not sort
- function: to sort them using the function as comparator (see Array.prototype.sort())
*/
filter: false, /*
- false, null or undefined: for a disabled filter
- a string: an entry is kept if entry.is(filter string) returns true
see jQuery's .is() function for further information
- a function: invoked with arguments (entry, index, array). Return true to keep the entry, false otherwise.
It follows the specifications of the Array.prototype.filter() function of JavaScript.
*/
selector: 'a, div:not(.spinner)', // The selector that is used to know what are the entries of the gallery
imgSelector: '> img, > a > img', // The selector that is used to know what are the images of each entry
triggerEvent: function (event) { // This is called to trigger events, the default behavior is to call $.trigger
this.$gallery.trigger(event); // Consider that 'this' is this set to the JustifiedGallery object, so it can
} // access to fields such as $gallery, useful to trigger events with jQuery.
};
/**
* Justified Gallery plugin for jQuery
*
* Events
* - jg.complete : called when all the gallery has been created
* - jg.resize : called when the gallery has been resized
* - jg.rowflush : when a new row appears
*
* @param arg the action (or the settings) passed when the plugin is called
* @returns {*} the object itself
*/
$.fn.justifiedGallery = function (arg) {
return this.each(function (index, gallery) {
var $gallery = $(gallery);
$gallery.addClass('justified-gallery');
var controller = $gallery.data('jg.controller');
if (typeof controller === 'undefined') {
// Create controller and assign it to the object data
if (typeof arg !== 'undefined' && arg !== null && $.type(arg) !== 'object') {
if (arg === 'destroy') return; // Just a call to an unexisting object
throw 'The argument must be an object';
}
controller = new JustifiedGallery($gallery, $.extend({}, JustifiedGallery.prototype.defaults, arg));
$gallery.data('jg.controller', controller);
} else if (arg === 'norewind') {
// In this case we don't rewind: we analyze only the latest images (e.g. to complete the last unfinished row
// ... left to be more readable
} else if (arg === 'destroy') {
controller.destroy();
return;
} else {
// In this case Justified Gallery has been called again changing only some options
controller.updateSettings(arg);
controller.rewind();
}
// Update the entries list
if (!controller.updateEntries(arg === 'norewind')) return;
// Init justified gallery
controller.init();
});
};
}));
/*!
* jQuery Mousewheel 3.1.13
*
* Copyright jQuery Foundation and other contributors
* Released under the MIT license
* http://jquery.org/license
*/
(function (factory) {
if ( typeof define === 'function' && define.amd ) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS style for Browserify
module.exports = factory;
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'],
toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?
['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
slice = Array.prototype.slice,
nullLowestDeltaTimeout, lowestDelta;
if ( $.event.fixHooks ) {
for ( var i = toFix.length; i; ) {
$.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;
}
}
var special = $.event.special.mousewheel = {
version: '3.1.12',
setup: function() {
if ( this.addEventListener ) {
for ( var i = toBind.length; i; ) {
this.addEventListener( toBind[--i], handler, false );
}
} else {
this.onmousewheel = handler;
}
// Store the line height and page height for this particular element
$.data(this, 'mousewheel-line-height', special.getLineHeight(this));
$.data(this, 'mousewheel-page-height', special.getPageHeight(this));
},
teardown: function() {
if ( this.removeEventListener ) {
for ( var i = toBind.length; i; ) {
this.removeEventListener( toBind[--i], handler, false );
}
} else {
this.onmousewheel = null;
}
// Clean up the data we added to the element
$.removeData(this, 'mousewheel-line-height');
$.removeData(this, 'mousewheel-page-height');
},
getLineHeight: function(elem) {
var $elem = $(elem),
$parent = $elem['offsetParent' in $.fn ? 'offsetParent' : 'parent']();
if (!$parent.length) {
$parent = $('body');
}
return parseInt($parent.css('fontSize'), 10) || parseInt($elem.css('fontSize'), 10) || 16;
},
getPageHeight: function(elem) {
return $(elem).height();
},
settings: {
adjustOldDeltas: true, // see shouldAdjustOldDeltas() below
normalizeOffset: true // calls getBoundingClientRect for each event
}
};
$.fn.extend({
mousewheel: function(fn) {
return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel');
},
unmousewheel: function(fn) {
return this.unbind('mousewheel', fn);
}
});
function handler(event) {
var orgEvent = event || window.event,
args = slice.call(arguments, 1),
delta = 0,
deltaX = 0,
deltaY = 0,
absDelta = 0,
offsetX = 0,
offsetY = 0;
event = $.event.fix(orgEvent);
event.type = 'mousewheel';
// Old school scrollwheel delta
if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; }
if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; }
if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }
if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }
// Firefox < 17 horizontal scrolling related to DOMMouseScroll event
if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
deltaX = deltaY * -1;
deltaY = 0;
}
// Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy
delta = deltaY === 0 ? deltaX : deltaY;
// New school wheel delta (wheel event)
if ( 'deltaY' in orgEvent ) {
deltaY = orgEvent.deltaY * -1;
delta = deltaY;
}
if ( 'deltaX' in orgEvent ) {
deltaX = orgEvent.deltaX;
if ( deltaY === 0 ) { delta = deltaX * -1; }
}
// No change actually happened, no reason to go any further
if ( deltaY === 0 && deltaX === 0 ) { return; }
// Need to convert lines and pages to pixels if we aren't already in pixels
// There are three delta modes:
// * deltaMode 0 is by pixels, nothing to do
// * deltaMode 1 is by lines
// * deltaMode 2 is by pages
if ( orgEvent.deltaMode === 1 ) {
var lineHeight = $.data(this, 'mousewheel-line-height');
delta *= lineHeight;
deltaY *= lineHeight;
deltaX *= lineHeight;
} else if ( orgEvent.deltaMode === 2 ) {
var pageHeight = $.data(this, 'mousewheel-page-height');
delta *= pageHeight;
deltaY *= pageHeight;
deltaX *= pageHeight;
}
// Store lowest absolute delta to normalize the delta values
absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
if ( !lowestDelta || absDelta < lowestDelta ) {
lowestDelta = absDelta;
// Adjust older deltas if necessary
if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
lowestDelta /= 40;
}
}
// Adjust older deltas if necessary
if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
// Divide all the things by 40!
delta /= 40;
deltaX /= 40;
deltaY /= 40;
}
// Get a whole, normalized value for the deltas
delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
// Normalise offsetX and offsetY properties
if ( special.settings.normalizeOffset && this.getBoundingClientRect ) {
var boundingRect = this.getBoundingClientRect();
offsetX = event.clientX - boundingRect.left;
offsetY = event.clientY - boundingRect.top;
}
// Add information to the event object
event.deltaX = deltaX;
event.deltaY = deltaY;
event.deltaFactor = lowestDelta;
event.offsetX = offsetX;
event.offsetY = offsetY;
// Go ahead and set deltaMode to 0 since we converted to pixels
// Although this is a little odd since we overwrite the deltaX/Y
// properties with normalized deltas.
event.deltaMode = 0;
// Add event and delta to the front of the arguments
args.unshift(event, delta, deltaX, deltaY);
// Clearout lowestDelta after sometime to better
// handle multiple device types that give different
// a different lowestDelta
// Ex: trackpad = 3 and mouse wheel = 120
if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
return ($.event.dispatch || $.event.handle).apply(this, args);
}
function nullLowestDelta() {
lowestDelta = null;
}
function shouldAdjustOldDeltas(orgEvent, absDelta) {
// If this is an older event and the delta is divisable by 120,
// then we are assuming that the browser is treating this as an
// older mouse wheel event and that we should divide the deltas
// by 40 to try and get a more usable deltaFactor.
// Side note, this actually impacts the reported scroll distance
// in older browsers and can cause scrolling to be slower than native.
// Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.
return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0;
}
}));
(function() {
'use strict';
var defaults = {
mode: 'lg-slide',
// Ex : 'ease'
cssEasing: 'ease',
//'for jquery animation'
easing: 'linear',
speed: 600,
height: '100%',
width: '100%',
addClass: '',
startClass: 'lg-start-zoom',
backdropDuration: 150,
hideBarsDelay: 6000,
useLeft: false,
closable: true,
loop: true,
escKey: true,
keyPress: true,
controls: true,
slideEndAnimatoin: true,
hideControlOnEnd: false,
mousewheel: true,
getCaptionFromTitleOrAlt: true,
// .lg-item || '.lg-sub-html'
appendSubHtmlTo: '.lg-sub-html',
subHtmlSelectorRelative: false,
/**
* @desc number of preload slides
* will exicute only after the current slide is fully loaded.
*
* @ex you clicked on 4th image and if preload = 1 then 3rd slide and 5th
* slide will be loaded in the background after the 4th slide is fully loaded..
* if preload is 2 then 2nd 3rd 5th 6th slides will be preloaded.. ... ...
*
*/
preload: 1,
showAfterLoad: true,
selector: '',
selectWithin: '',
nextHtml: '',
prevHtml: '',
// 0, 1
index: false,
iframeMaxWidth: '100%',
download: true,
counter: true,
appendCounterTo: '.lg-toolbar',
swipeThreshold: 50,
enableSwipe: true,
enableDrag: true,
dynamic: false,
dynamicEl: [],
galleryId: 1
};
function Plugin(element, options) {
// Current lightGallery element
this.el = element;
// Current jquery element
this.$el = $(element);
// lightGallery settings
this.s = $.extend({}, defaults, options);
// When using dynamic mode, ensure dynamicEl is an array
if (this.s.dynamic && this.s.dynamicEl !== 'undefined' && this.s.dynamicEl.constructor === Array && !this.s.dynamicEl.length) {
throw ('When using dynamic mode, you must also define dynamicEl as an Array.');
}
// lightGallery modules
this.modules = {};
// false when lightgallery complete first slide;
this.lGalleryOn = false;
this.lgBusy = false;
// Timeout function for hiding controls;
this.hideBartimeout = false;
// To determine browser supports for touch events;
this.isTouch = ('ontouchstart' in document.documentElement);
// Disable hideControlOnEnd if sildeEndAnimation is true
if (this.s.slideEndAnimatoin) {
this.s.hideControlOnEnd = false;
}
// Gallery items
if (this.s.dynamic) {
this.$items = this.s.dynamicEl;
} else {
if (this.s.selector === 'this') {
this.$items = this.$el;
} else if (this.s.selector !== '') {
if (this.s.selectWithin) {
this.$items = $(this.s.selectWithin).find(this.s.selector);
} else {
this.$items = this.$el.find($(this.s.selector));
}
} else {
this.$items = this.$el.children();
}
}
// .lg-item
this.$slide = '';
// .lg-outer
this.$outer = '';
this.init();
return this;
}
Plugin.prototype.init = function() {
var _this = this;
// s.preload should not be more than $item.length
if (_this.s.preload > _this.$items.length) {
_this.s.preload = _this.$items.length;
}
// if dynamic option is enabled execute immediately
var _hash = window.location.hash;
if (_hash.indexOf('lg=' + this.s.galleryId) > 0) {
_this.index = parseInt(_hash.split('&slide=')[1], 10);
$('body').addClass('lg-from-hash');
if (!$('body').hasClass('lg-on')) {
setTimeout(function() {
_this.build(_this.index);
});
$('body').addClass('lg-on');
}
}
if (_this.s.dynamic) {
_this.$el.trigger('onBeforeOpen.lg');
_this.index = _this.s.index || 0;
// prevent accidental double execution
if (!$('body').hasClass('lg-on')) {
setTimeout(function() {
_this.build(_this.index);
$('body').addClass('lg-on');
});
}
} else {
// Using different namespace for click because click event should not unbind if selector is same object('this')
_this.$items.on('click.lgcustom', function(event) {
// For IE8
try {
event.preventDefault();
event.preventDefault();
} catch (er) {
event.returnValue = false;
}
_this.$el.trigger('onBeforeOpen.lg');
_this.index = _this.s.index || _this.$items.index(this);
// prevent accidental double execution
if (!$('body').hasClass('lg-on')) {
_this.build(_this.index);
$('body').addClass('lg-on');
}
});
}
};
Plugin.prototype.build = function(index) {
var _this = this;
_this.structure();
// module constructor
$.each($.fn.lightGallery.modules, function(key) {
_this.modules[key] = new $.fn.lightGallery.modules[key](_this.el);
});
// initiate slide function
_this.slide(index, false, false, false);
if (_this.s.keyPress) {
_this.keyPress();
}
if (_this.$items.length > 1) {
_this.arrow();
setTimeout(function() {
_this.enableDrag();
_this.enableSwipe();
}, 50);
if (_this.s.mousewheel) {
_this.mousewheel();
}
} else {
_this.$slide.on('click.lg', function() {
_this.$el.trigger('onSlideClick.lg');
});
}
_this.counter();
_this.closeGallery();
_this.$el.trigger('onAfterOpen.lg');
// Hide controllers if mouse doesn't move for some period
_this.$outer.on('mousemove.lg click.lg touchstart.lg', function() {
_this.$outer.removeClass('lg-hide-items');
clearTimeout(_this.hideBartimeout);
// Timeout will be cleared on each slide movement also
_this.hideBartimeout = setTimeout(function() {
_this.$outer.addClass('lg-hide-items');
}, _this.s.hideBarsDelay);
});
_this.$outer.trigger('mousemove.lg');
};
Plugin.prototype.structure = function() {
var list = '';
var controls = '';
var i = 0;
var subHtmlCont = '';
var template;
var _this = this;
$('body').append('<div class="lg-backdrop"></div>');
$('.lg-backdrop').css('transition-duration', this.s.backdropDuration + 'ms');
// Create gallery items
for (i = 0; i < this.$items.length; i++) {
list += '<div class="lg-item"></div>';
}
// Create controlls
if (this.s.controls && this.$items.length > 1) {
controls = '<div class="lg-actions">' +
'<button class="lg-prev lg-icon">' + this.s.prevHtml + '</button>' +
'<button class="lg-next lg-icon">' + this.s.nextHtml + '</button>' +
'</div>';
}
if (this.s.appendSubHtmlTo === '.lg-sub-html') {
subHtmlCont = '<div class="lg-sub-html"></div>';
}
template = '<div class="lg-outer ' + this.s.addClass + ' ' + this.s.startClass + '">' +
'<div class="lg" style="width:' + this.s.width + '; height:' + this.s.height + '">' +
'<div class="lg-inner">' + list + '</div>' +
'<div class="lg-toolbar lg-group">' +
'<span class="lg-close lg-icon"></span>' +
'</div>' +
controls +
subHtmlCont +
'</div>' +
'</div>';
$('body').append(template);
this.$outer = $('.lg-outer');
this.$slide = this.$outer.find('.lg-item');
if (this.s.useLeft) {
this.$outer.addClass('lg-use-left');
// Set mode lg-slide if use left is true;
this.s.mode = 'lg-slide';
} else {
this.$outer.addClass('lg-use-css3');
}
// For fixed height gallery
_this.setTop();
$(window).on('resize.lg orientationchange.lg', function() {
setTimeout(function() {
_this.setTop();
}, 100);
});
// add class lg-current to remove initial transition
this.$slide.eq(this.index).addClass('lg-current');
// add Class for css support and transition mode
if (this.doCss()) {
this.$outer.addClass('lg-css3');
} else {
this.$outer.addClass('lg-css');
// Set speed 0 because no animation will happen if browser doesn't support css3
this.s.speed = 0;
}
this.$outer.addClass(this.s.mode);
if (this.s.enableDrag && this.$items.length > 1) {
this.$outer.addClass('lg-grab');
}
if (this.s.showAfterLoad) {
this.$outer.addClass('lg-show-after-load');
}
if (this.doCss()) {
var $inner = this.$outer.find('.lg-inner');
$inner.css('transition-timing-function', this.s.cssEasing);
$inner.css('transition-duration', this.s.speed + 'ms');
}
setTimeout(function() {
$('.lg-backdrop').addClass('in');
});
setTimeout(function() {
_this.$outer.addClass('lg-visible');
}, this.s.backdropDuration);
if (this.s.download) {
this.$outer.find('.lg-toolbar').append('<a id="lg-download" target="_blank" download class="lg-download lg-icon"></a>');
}
// Store the current scroll top value to scroll back after closing the gallery..
this.prevScrollTop = $(window).scrollTop();
};
// For fixed height gallery
Plugin.prototype.setTop = function() {
if (this.s.height !== '100%') {
var wH = $(window).height();
var top = (wH - parseInt(this.s.height, 10)) / 2;
var $lGallery = this.$outer.find('.lg');
if (wH >= parseInt(this.s.height, 10)) {
$lGallery.css('top', top + 'px');
} else {
$lGallery.css('top', '0px');
}
}
};
// Find css3 support
Plugin.prototype.doCss = function() {
// check for css animation support
var support = function() {
var transition = ['transition', 'MozTransition', 'WebkitTransition', 'OTransition', 'msTransition', 'KhtmlTransition'];
var root = document.documentElement;
var i = 0;
for (i = 0; i < transition.length; i++) {
if (transition[i] in root.style) {
return true;
}
}
};
if (support()) {
return true;
}
return false;
};
/**
* @desc Check the given src is video
* @param {String} src
* @return {Object} video type
* Ex:{ youtube : ["//www.youtube.com/watch?v=c0asJgSyxcY", "c0asJgSyxcY"] }
*/
Plugin.prototype.isVideo = function(src, index) {
var html;
if (this.s.dynamic) {
html = this.s.dynamicEl[index].html;
} else {
html = this.$items.eq(index).attr('data-html');
}
if (!src) {
if(html) {
return {
html5: true
};
} else {
console.error('lightGallery :- data-src is not pvovided on slide item ' + (index + 1) + '. Please make sure the selector property is properly configured. More info - http://sachinchoolur.github.io/lightGallery/demos/html-markup.html');
return false;
}
}
var youtube = src.match(/\/\/(?:www\.)?youtu(?:\.be|be\.com|be-nocookie\.com)\/(?:watch\?v=|embed\/)?([a-z0-9\-\_\%]+)/i);
var vimeo = src.match(/\/\/(?:www\.)?vimeo.com\/([0-9a-z\-_]+)/i);
var dailymotion = src.match(/\/\/(?:www\.)?dai.ly\/([0-9a-z\-_]+)/i);
var vk = src.match(/\/\/(?:www\.)?(?:vk\.com|vkontakte\.ru)\/(?:video_ext\.php\?)(.*)/i);
if (youtube) {
return {
youtube: youtube
};
} else if (vimeo) {
return {
vimeo: vimeo
};
} else if (dailymotion) {
return {
dailymotion: dailymotion
};
} else if (vk) {
return {
vk: vk
};
}
};
/**
* @desc Create image counter
* Ex: 1/10
*/
Plugin.prototype.counter = function() {
if (this.s.counter) {
$(this.s.appendCounterTo).append('<div id="lg-counter"><span id="lg-counter-current">' + (parseInt(this.index, 10) + 1) + '</span> / <span id="lg-counter-all">' + this.$items.length + '</span></div>');
}
};
/**
* @desc add sub-html into the slide
* @param {Number} index - index of the slide
*/
Plugin.prototype.addHtml = function(index) {
var subHtml = null;
var subHtmlUrl;
var $currentEle;
if (this.s.dynamic) {
if (this.s.dynamicEl[index].subHtmlUrl) {
subHtmlUrl = this.s.dynamicEl[index].subHtmlUrl;
} else {
subHtml = this.s.dynamicEl[index].subHtml;
}
} else {
$currentEle = this.$items.eq(index);
if ($currentEle.attr('data-sub-html-url')) {
subHtmlUrl = $currentEle.attr('data-sub-html-url');
} else {
subHtml = $currentEle.attr('data-sub-html');
if (this.s.getCaptionFromTitleOrAlt && !subHtml) {
subHtml = $currentEle.attr('title') || $currentEle.find('img').first().attr('alt');
}
}
}
if (!subHtmlUrl) {
if (typeof subHtml !== 'undefined' && subHtml !== null) {
// get first letter of subhtml
// if first letter starts with . or # get the html form the jQuery object
var fL = subHtml.substring(0, 1);
if (fL === '.' || fL === '#') {
if (this.s.subHtmlSelectorRelative && !this.s.dynamic) {
subHtml = $currentEle.find(subHtml).html();
} else {
subHtml = $(subHtml).html();
}
}
} else {
subHtml = '';
}
}
if (this.s.appendSubHtmlTo === '.lg-sub-html') {
if (subHtmlUrl) {
this.$outer.find(this.s.appendSubHtmlTo).load(subHtmlUrl);
} else {
this.$outer.find(this.s.appendSubHtmlTo).html(subHtml);
}
} else {
if (subHtmlUrl) {
this.$slide.eq(index).load(subHtmlUrl);
} else {
this.$slide.eq(index).append(subHtml);
}
}
// Add lg-empty-html class if title doesn't exist
if (typeof subHtml !== 'undefined' && subHtml !== null) {
if (subHtml === '') {
this.$outer.find(this.s.appendSubHtmlTo).addClass('lg-empty-html');
} else {
this.$outer.find(this.s.appendSubHtmlTo).removeClass('lg-empty-html');
}
}
this.$el.trigger('onAfterAppendSubHtml.lg', [index]);
};
/**
* @desc Preload slides
* @param {Number} index - index of the slide
*/
Plugin.prototype.preload = function(index) {
var i = 1;
var j = 1;
for (i = 1; i <= this.s.preload; i++) {
if (i >= this.$items.length - index) {
break;
}
this.loadContent(index + i, false, 0);
}
for (j = 1; j <= this.s.preload; j++) {
if (index - j < 0) {
break;
}
this.loadContent(index - j, false, 0);
}
};
/**
* @desc Load slide content into slide.
* @param {Number} index - index of the slide.
* @param {Boolean} rec - if true call loadcontent() function again.
* @param {Boolean} delay - delay for adding complete class. it is 0 except first time.
*/
Plugin.prototype.loadContent = function(index, rec, delay) {
var _this = this;
var _hasPoster = false;
var _$img;
var _src;
var _poster;
var _srcset;
var _sizes;
var _html;
var getResponsiveSrc = function(srcItms) {
var rsWidth = [];
var rsSrc = [];
for (var i = 0; i < srcItms.length; i++) {
var __src = srcItms[i].split(' ');
// Manage empty space
if (__src[0] === '') {
__src.splice(0, 1);
}
rsSrc.push(__src[0]);
rsWidth.push(__src[1]);
}
var wWidth = $(window).width();
for (var j = 0; j < rsWidth.length; j++) {
if (parseInt(rsWidth[j], 10) > wWidth) {
_src = rsSrc[j];
break;
}
}
};
if (_this.s.dynamic) {
if (_this.s.dynamicEl[index].poster) {
_hasPoster = true;
_poster = _this.s.dynamicEl[index].poster;
}
_html = _this.s.dynamicEl[index].html;
_src = _this.s.dynamicEl[index].src;
if (_this.s.dynamicEl[index].responsive) {
var srcDyItms = _this.s.dynamicEl[index].responsive.split(',');
getResponsiveSrc(srcDyItms);
}
_srcset = _this.s.dynamicEl[index].srcset;
_sizes = _this.s.dynamicEl[index].sizes;
} else {
if (_this.$items.eq(index).attr('data-poster')) {
_hasPoster = true;
_poster = _this.$items.eq(index).attr('data-poster');
}
_html = _this.$items.eq(index).attr('data-html');
_src = _this.$items.eq(index).attr('href') || _this.$items.eq(index).attr('data-src');
if (_this.$items.eq(index).attr('data-responsive')) {
var srcItms = _this.$items.eq(index).attr('data-responsive').split(',');
getResponsiveSrc(srcItms);
}
_srcset = _this.$items.eq(index).attr('data-srcset');
_sizes = _this.$items.eq(index).attr('data-sizes');
}
//if (_src || _srcset || _sizes || _poster) {
var iframe = false;
if (_this.s.dynamic) {
if (_this.s.dynamicEl[index].iframe) {
iframe = true;
}
} else {
if (_this.$items.eq(index).attr('data-iframe') === 'true') {
iframe = true;
}
}
var _isVideo = _this.isVideo(_src, index);
if (!_this.$slide.eq(index).hasClass('lg-loaded')) {
if (iframe) {
_this.$slide.eq(index).prepend('<div class="lg-video-cont lg-has-iframe" style="max-width:' + _this.s.iframeMaxWidth + '"><div class="lg-video"><iframe class="lg-object" frameborder="0" src="' + _src + '" allowfullscreen="true"></iframe></div></div>');
} else if (_hasPoster) {
var videoClass = '';
if (_isVideo && _isVideo.youtube) {
videoClass = 'lg-has-youtube';
} else if (_isVideo && _isVideo.vimeo) {
videoClass = 'lg-has-vimeo';
} else {
videoClass = 'lg-has-html5';
}
_this.$slide.eq(index).prepend('<div class="lg-video-cont ' + videoClass + ' "><div class="lg-video"><span class="lg-video-play"></span><img class="lg-object lg-has-poster" src="' + _poster + '" /></div></div>');
} else if (_isVideo) {
_this.$slide.eq(index).prepend('<div class="lg-video-cont "><div class="lg-video"></div></div>');
_this.$el.trigger('hasVideo.lg', [index, _src, _html]);
} else {
_this.$slide.eq(index).prepend('<div class="lg-img-wrap"><img class="lg-object lg-image" src="' + _src + '" /></div>');
}
_this.$el.trigger('onAferAppendSlide.lg', [index]);
_$img = _this.$slide.eq(index).find('.lg-object');
if (_sizes) {
_$img.attr('sizes', _sizes);
}
if (_srcset) {
_$img.attr('srcset', _srcset);
try {
picturefill({
elements: [_$img[0]]
});
} catch (e) {
console.warn('lightGallery :- If you want srcset to be supported for older browser please include picturefil version 2 javascript library in your document.');
}
}
if (this.s.appendSubHtmlTo !== '.lg-sub-html') {
_this.addHtml(index);
}
_this.$slide.eq(index).addClass('lg-loaded');
}
_this.$slide.eq(index).find('.lg-object').on('load.lg error.lg', function() {
// For first time add some delay for displaying the start animation.
var _speed = 0;
// Do not change the delay value because it is required for zoom plugin.
// If gallery opened from direct url (hash) speed value should be 0
if (delay && !$('body').hasClass('lg-from-hash')) {
_speed = delay;
}
setTimeout(function() {
_this.$slide.eq(index).addClass('lg-complete');
_this.$el.trigger('onSlideItemLoad.lg', [index, delay || 0]);
}, _speed);
});
// @todo check load state for html5 videos
if (_isVideo && _isVideo.html5 && !_hasPoster) {
_this.$slide.eq(index).addClass('lg-complete');
}
if (rec === true) {
if (!_this.$slide.eq(index).hasClass('lg-complete')) {
_this.$slide.eq(index).find('.lg-object').on('load.lg error.lg', function() {
_this.preload(index);
});
} else {
_this.preload(index);
}
}
//}
};
/**
* @desc slide function for lightgallery
** Slide() gets call on start
** ** Set lg.on true once slide() function gets called.
** Call loadContent() on slide() function inside setTimeout
** ** On first slide we do not want any animation like slide of fade
** ** So on first slide( if lg.on if false that is first slide) loadContent() should start loading immediately
** ** Else loadContent() should wait for the transition to complete.
** ** So set timeout s.speed + 50
<=> ** loadContent() will load slide content in to the particular slide
** ** It has recursion (rec) parameter. if rec === true loadContent() will call preload() function.
** ** preload will execute only when the previous slide is fully loaded (images iframe)
** ** avoid simultaneous image load
<=> ** Preload() will check for s.preload value and call loadContent() again accoring to preload value
** loadContent() <====> Preload();
* @param {Number} index - index of the slide
* @param {Boolean} fromTouch - true if slide function called via touch event or mouse drag
* @param {Boolean} fromThumb - true if slide function called via thumbnail click
* @param {String} direction - Direction of the slide(next/prev)
*/
Plugin.prototype.slide = function(index, fromTouch, fromThumb, direction) {
var _prevIndex = this.$outer.find('.lg-current').index();
var _this = this;
// Prevent if multiple call
// Required for hsh plugin
if (_this.lGalleryOn && (_prevIndex === index)) {
return;
}
var _length = this.$slide.length;
var _time = _this.lGalleryOn ? this.s.speed : 0;
if (!_this.lgBusy) {
if (this.s.download) {
var _src;
if (_this.s.dynamic) {
_src = _this.s.dynamicEl[index].downloadUrl !== false && (_this.s.dynamicEl[index].downloadUrl || _this.s.dynamicEl[index].src);
} else {
_src = _this.$items.eq(index).attr('data-download-url') !== 'false' && (_this.$items.eq(index).attr('data-download-url') || _this.$items.eq(index).attr('href') || _this.$items.eq(index).attr('data-src'));
}
if (_src) {
$('#lg-download').attr('href', _src);
_this.$outer.removeClass('lg-hide-download');
} else {
_this.$outer.addClass('lg-hide-download');
}
}
this.$el.trigger('onBeforeSlide.lg', [_prevIndex, index, fromTouch, fromThumb]);
_this.lgBusy = true;
clearTimeout(_this.hideBartimeout);
// Add title if this.s.appendSubHtmlTo === lg-sub-html
if (this.s.appendSubHtmlTo === '.lg-sub-html') {
// wait for slide animation to complete
setTimeout(function() {
_this.addHtml(index);
}, _time);
}
this.arrowDisable(index);
if (!direction) {
if (index < _prevIndex) {
direction = 'prev';
} else if (index > _prevIndex) {
direction = 'next';
}
}
if (!fromTouch) {
// remove all transitions
_this.$outer.addClass('lg-no-trans');
this.$slide.removeClass('lg-prev-slide lg-next-slide');
if (direction === 'prev') {
//prevslide
this.$slide.eq(index).addClass('lg-prev-slide');
this.$slide.eq(_prevIndex).addClass('lg-next-slide');
} else {
// next slide
this.$slide.eq(index).addClass('lg-next-slide');
this.$slide.eq(_prevIndex).addClass('lg-prev-slide');
}
// give 50 ms for browser to add/remove class
setTimeout(function() {
_this.$slide.removeClass('lg-current');
//_this.$slide.eq(_prevIndex).removeClass('lg-current');
_this.$slide.eq(index).addClass('lg-current');
// reset all transitions
_this.$outer.removeClass('lg-no-trans');
}, 50);
} else {
this.$slide.removeClass('lg-prev-slide lg-current lg-next-slide');
var touchPrev;
var touchNext;
if (_length > 2) {
touchPrev = index - 1;
touchNext = index + 1;
if ((index === 0) && (_prevIndex === _length - 1)) {
// next slide
touchNext = 0;
touchPrev = _length - 1;
} else if ((index === _length - 1) && (_prevIndex === 0)) {
// prev slide
touchNext = 0;
touchPrev = _length - 1;
}
} else {
touchPrev = 0;
touchNext = 1;
}
if (direction === 'prev') {
_this.$slide.eq(touchNext).addClass('lg-next-slide');
} else {
_this.$slide.eq(touchPrev).addClass('lg-prev-slide');
}
_this.$slide.eq(index).addClass('lg-current');
}
if (_this.lGalleryOn) {
setTimeout(function() {
_this.loadContent(index, true, 0);
}, this.s.speed + 50);
setTimeout(function() {
_this.lgBusy = false;
_this.$el.trigger('onAfterSlide.lg', [_prevIndex, index, fromTouch, fromThumb]);
}, this.s.speed);
} else {
_this.loadContent(index, true, _this.s.backdropDuration);
_this.lgBusy = false;
_this.$el.trigger('onAfterSlide.lg', [_prevIndex, index, fromTouch, fromThumb]);
}
_this.lGalleryOn = true;
if (this.s.counter) {
$('#lg-counter-current').text(index + 1);
}
}
_this.index = index;
};
/**
* @desc Go to next slide
* @param {Boolean} fromTouch - true if slide function called via touch event
*/
Plugin.prototype.goToNextSlide = function(fromTouch) {
var _this = this;
var _loop = _this.s.loop;
if (fromTouch && _this.$slide.length < 3) {
_loop = false;
}
if (!_this.lgBusy) {
if ((_this.index + 1) < _this.$slide.length) {
_this.index++;
_this.$el.trigger('onBeforeNextSlide.lg', [_this.index]);
_this.slide(_this.index, fromTouch, false, 'next');
} else {
if (_loop) {
_this.index = 0;
_this.$el.trigger('onBeforeNextSlide.lg', [_this.index]);
_this.slide(_this.index, fromTouch, false, 'next');
} else if (_this.s.slideEndAnimatoin && !fromTouch) {
_this.$outer.addClass('lg-right-end');
setTimeout(function() {
_this.$outer.removeClass('lg-right-end');
}, 400);
}
}
}
};
/**
* @desc Go to previous slide
* @param {Boolean} fromTouch - true if slide function called via touch event
*/
Plugin.prototype.goToPrevSlide = function(fromTouch) {
var _this = this;
var _loop = _this.s.loop;
if (fromTouch && _this.$slide.length < 3) {
_loop = false;
}
if (!_this.lgBusy) {
if (_this.index > 0) {
_this.index--;
_this.$el.trigger('onBeforePrevSlide.lg', [_this.index, fromTouch]);
_this.slide(_this.index, fromTouch, false, 'prev');
} else {
if (_loop) {
_this.index = _this.$items.length - 1;
_this.$el.trigger('onBeforePrevSlide.lg', [_this.index, fromTouch]);
_this.slide(_this.index, fromTouch, false, 'prev');
} else if (_this.s.slideEndAnimatoin && !fromTouch) {
_this.$outer.addClass('lg-left-end');
setTimeout(function() {
_this.$outer.removeClass('lg-left-end');
}, 400);
}
}
}
};
Plugin.prototype.keyPress = function() {
var _this = this;
if (this.$items.length > 1) {
$(window).on('keyup.lg', function(e) {
if (_this.$items.length > 1) {
if (e.keyCode === 37) {
e.preventDefault();
_this.goToPrevSlide();
}
if (e.keyCode === 39) {
e.preventDefault();
_this.goToNextSlide();
}
}
});
}
$(window).on('keydown.lg', function(e) {
if (_this.s.escKey === true && e.keyCode === 27) {
e.preventDefault();
if (!_this.$outer.hasClass('lg-thumb-open')) {
_this.destroy();
} else {
_this.$outer.removeClass('lg-thumb-open');
}
}
});
};
Plugin.prototype.arrow = function() {
var _this = this;
this.$outer.find('.lg-prev').on('click.lg', function() {
_this.goToPrevSlide();
});
this.$outer.find('.lg-next').on('click.lg', function() {
_this.goToNextSlide();
});
};
Plugin.prototype.arrowDisable = function(index) {
// Disable arrows if s.hideControlOnEnd is true
if (!this.s.loop && this.s.hideControlOnEnd) {
if ((index + 1) < this.$slide.length) {
this.$outer.find('.lg-next').removeAttr('disabled').removeClass('disabled');
} else {
this.$outer.find('.lg-next').attr('disabled', 'disabled').addClass('disabled');
}
if (index > 0) {
this.$outer.find('.lg-prev').removeAttr('disabled').removeClass('disabled');
} else {
this.$outer.find('.lg-prev').attr('disabled', 'disabled').addClass('disabled');
}
}
};
Plugin.prototype.setTranslate = function($el, xValue, yValue) {
// jQuery supports Automatic CSS prefixing since jQuery 1.8.0
if (this.s.useLeft) {
$el.css('left', xValue);
} else {
$el.css({
transform: 'translate3d(' + (xValue) + 'px, ' + yValue + 'px, 0px)'
});
}
};
Plugin.prototype.touchMove = function(startCoords, endCoords) {
var distance = endCoords - startCoords;
if (Math.abs(distance) > 15) {
// reset opacity and transition duration
this.$outer.addClass('lg-dragging');
// move current slide
this.setTranslate(this.$slide.eq(this.index), distance, 0);
// move next and prev slide with current slide
this.setTranslate($('.lg-prev-slide'), -this.$slide.eq(this.index).width() + distance, 0);
this.setTranslate($('.lg-next-slide'), this.$slide.eq(this.index).width() + distance, 0);
}
};
Plugin.prototype.touchEnd = function(distance) {
var _this = this;
// keep slide animation for any mode while dragg/swipe
if (_this.s.mode !== 'lg-slide') {
_this.$outer.addClass('lg-slide');
}
this.$slide.not('.lg-current, .lg-prev-slide, .lg-next-slide').css('opacity', '0');
// set transition duration
setTimeout(function() {
_this.$outer.removeClass('lg-dragging');
if ((distance < 0) && (Math.abs(distance) > _this.s.swipeThreshold)) {
_this.goToNextSlide(true);
} else if ((distance > 0) && (Math.abs(distance) > _this.s.swipeThreshold)) {
_this.goToPrevSlide(true);
} else if (Math.abs(distance) < 5) {
// Trigger click if distance is less than 5 pix
_this.$el.trigger('onSlideClick.lg');
}
_this.$slide.removeAttr('style');
});
// remove slide class once drag/swipe is completed if mode is not slide
setTimeout(function() {
if (!_this.$outer.hasClass('lg-dragging') && _this.s.mode !== 'lg-slide') {
_this.$outer.removeClass('lg-slide');
}
}, _this.s.speed + 100);
};
Plugin.prototype.enableSwipe = function() {
var _this = this;
var startCoords = 0;
var endCoords = 0;
var isMoved = false;
if (_this.s.enableSwipe && _this.doCss()) {
_this.$slide.on('touchstart.lg', function(e) {
if (!_this.$outer.hasClass('lg-zoomed') && !_this.lgBusy) {
e.preventDefault();
_this.manageSwipeClass();
startCoords = e.originalEvent.targetTouches[0].pageX;
}
});
_this.$slide.on('touchmove.lg', function(e) {
if (!_this.$outer.hasClass('lg-zoomed')) {
e.preventDefault();
endCoords = e.originalEvent.targetTouches[0].pageX;
_this.touchMove(startCoords, endCoords);
isMoved = true;
}
});
_this.$slide.on('touchend.lg', function() {
if (!_this.$outer.hasClass('lg-zoomed')) {
if (isMoved) {
isMoved = false;
_this.touchEnd(endCoords - startCoords);
} else {
_this.$el.trigger('onSlideClick.lg');
}
}
});
}
};
Plugin.prototype.enableDrag = function() {
var _this = this;
var startCoords = 0;
var endCoords = 0;
var isDraging = false;
var isMoved = false;
if (_this.s.enableDrag && _this.doCss()) {
_this.$slide.on('mousedown.lg', function(e) {
if (!_this.$outer.hasClass('lg-zoomed') && !_this.lgBusy && !$(e.target).text().trim()) {
e.preventDefault();
_this.manageSwipeClass();
startCoords = e.pageX;
isDraging = true;
// ** Fix for webkit cursor issue https://code.google.com/p/chromium/issues/detail?id=26723
_this.$outer.scrollLeft += 1;
_this.$outer.scrollLeft -= 1;
// *
_this.$outer.removeClass('lg-grab').addClass('lg-grabbing');
_this.$el.trigger('onDragstart.lg');
}
});
$(window).on('mousemove.lg', function(e) {
if (isDraging) {
isMoved = true;
endCoords = e.pageX;
_this.touchMove(startCoords, endCoords);
_this.$el.trigger('onDragmove.lg');
}
});
$(window).on('mouseup.lg', function(e) {
if (isMoved) {
isMoved = false;
_this.touchEnd(endCoords - startCoords);
_this.$el.trigger('onDragend.lg');
} else if ($(e.target).hasClass('lg-object') || $(e.target).hasClass('lg-video-play')) {
_this.$el.trigger('onSlideClick.lg');
}
// Prevent execution on click
if (isDraging) {
isDraging = false;
_this.$outer.removeClass('lg-grabbing').addClass('lg-grab');
}
});
}
};
Plugin.prototype.manageSwipeClass = function() {
var _touchNext = this.index + 1;
var _touchPrev = this.index - 1;
if (this.s.loop && this.$slide.length > 2) {
if (this.index === 0) {
_touchPrev = this.$slide.length - 1;
} else if (this.index === this.$slide.length - 1) {
_touchNext = 0;
}
}
this.$slide.removeClass('lg-next-slide lg-prev-slide');
if (_touchPrev > -1) {
this.$slide.eq(_touchPrev).addClass('lg-prev-slide');
}
this.$slide.eq(_touchNext).addClass('lg-next-slide');
};
Plugin.prototype.mousewheel = function() {
var _this = this;
_this.$outer.on('mousewheel.lg', function(e) {
if (!e.deltaY) {
return;
}
if (e.deltaY > 0) {
_this.goToPrevSlide();
} else {
_this.goToNextSlide();
}
e.preventDefault();
});
};
Plugin.prototype.closeGallery = function() {
var _this = this;
var mousedown = false;
this.$outer.find('.lg-close').on('click.lg', function() {
_this.destroy();
});
if (_this.s.closable) {
// If you drag the slide and release outside gallery gets close on chrome
// for preventing this check mousedown and mouseup happened on .lg-item or lg-outer
_this.$outer.on('mousedown.lg', function(e) {
if ($(e.target).is('.lg-outer') || $(e.target).is('.lg-item ') || $(e.target).is('.lg-img-wrap')) {
mousedown = true;
} else {
mousedown = false;
}
});
_this.$outer.on('mousemove.lg', function() {
mousedown = false;
});
_this.$outer.on('mouseup.lg', function(e) {
if ($(e.target).is('.lg-outer') || $(e.target).is('.lg-item ') || $(e.target).is('.lg-img-wrap') && mousedown) {
if (!_this.$outer.hasClass('lg-dragging')) {
_this.destroy();
}
}
});
}
};
Plugin.prototype.destroy = function(d) {
var _this = this;
if (!d) {
_this.$el.trigger('onBeforeClose.lg');
$(window).scrollTop(_this.prevScrollTop);
}
/**
* if d is false or undefined destroy will only close the gallery
* plugins instance remains with the element
*
* if d is true destroy will completely remove the plugin
*/
if (d) {
if (!_this.s.dynamic) {
// only when not using dynamic mode is $items a jquery collection
this.$items.off('click.lg click.lgcustom');
}
$.removeData(_this.el, 'lightGallery');
}
// Unbind all events added by lightGallery
this.$el.off('.lg.tm');
// Distroy all lightGallery modules
$.each($.fn.lightGallery.modules, function(key) {
if (_this.modules[key]) {
_this.modules[key].destroy();
}
});
this.lGalleryOn = false;
clearTimeout(_this.hideBartimeout);
this.hideBartimeout = false;
$(window).off('.lg');
$('body').removeClass('lg-on lg-from-hash');
if (_this.$outer) {
_this.$outer.removeClass('lg-visible');
}
$('.lg-backdrop').removeClass('in');
setTimeout(function() {
if (_this.$outer) {
_this.$outer.remove();
}
$('.lg-backdrop').remove();
if (!d) {
_this.$el.trigger('onCloseAfter.lg');
}
}, _this.s.backdropDuration + 50);
};
$.fn.lightGallery = function(options) {
return this.each(function() {
if (!$.data(this, 'lightGallery')) {
$.data(this, 'lightGallery', new Plugin(this, options));
} else {
try {
$(this).data('lightGallery').init();
} catch (err) {
console.error('lightGallery has not initiated properly');
}
}
});
};
$.fn.lightGallery.modules = {};
})();
/*! lg-autoplay - v1.0.4 - 2017-03-28
* http://sachinchoolur.github.io/lightGallery
* Copyright (c) 2017 Sachin N; Licensed GPLv3 */
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define(['jquery'], function (a0) {
return (factory(a0));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require('jquery'));
} else {
factory(jQuery);
}
}(this, function ($) {
(function() {
'use strict';
var defaults = {
autoplay: false,
pause: 5000,
progressBar: true,
fourceAutoplay: false,
autoplayControls: true,
appendAutoplayControlsTo: '.lg-toolbar'
};
/**
* Creates the autoplay plugin.
* @param {object} element - lightGallery element
*/
var Autoplay = function(element) {
this.core = $(element).data('lightGallery');
this.$el = $(element);
// Execute only if items are above 1
if (this.core.$items.length < 2) {
return false;
}
this.core.s = $.extend({}, defaults, this.core.s);
this.interval = false;
// Identify if slide happened from autoplay
this.fromAuto = true;
// Identify if autoplay canceled from touch/drag
this.canceledOnTouch = false;
// save fourceautoplay value
this.fourceAutoplayTemp = this.core.s.fourceAutoplay;
// do not allow progress bar if browser does not support css3 transitions
if (!this.core.doCss()) {
this.core.s.progressBar = false;
}
this.init();
return this;
};
Autoplay.prototype.init = function() {
var _this = this;
// append autoplay controls
if (_this.core.s.autoplayControls) {
_this.controls();
}
// Create progress bar
if (_this.core.s.progressBar) {
_this.core.$outer.find('.lg').append('<div class="lg-progress-bar"><div class="lg-progress"></div></div>');
}
// set progress
_this.progress();
// Start autoplay
if (_this.core.s.autoplay) {
_this.$el.one('onSlideItemLoad.lg.tm', function() {
_this.startlAuto();
});
}
// cancel interval on touchstart and dragstart
_this.$el.on('onDragstart.lg.tm touchstart.lg.tm', function() {
if (_this.interval) {
_this.cancelAuto();
_this.canceledOnTouch = true;
}
});
// restore autoplay if autoplay canceled from touchstart / dragstart
_this.$el.on('onDragend.lg.tm touchend.lg.tm onSlideClick.lg.tm', function() {
if (!_this.interval && _this.canceledOnTouch) {
_this.startlAuto();
_this.canceledOnTouch = false;
}
});
};
Autoplay.prototype.progress = function() {
var _this = this;
var _$progressBar;
var _$progress;
_this.$el.on('onBeforeSlide.lg.tm', function() {
// start progress bar animation
if (_this.core.s.progressBar && _this.fromAuto) {
_$progressBar = _this.core.$outer.find('.lg-progress-bar');
_$progress = _this.core.$outer.find('.lg-progress');
if (_this.interval) {
_$progress.removeAttr('style');
_$progressBar.removeClass('lg-start');
setTimeout(function() {
_$progress.css('transition', 'width ' + (_this.core.s.speed + _this.core.s.pause) + 'ms ease 0s');
_$progressBar.addClass('lg-start');
}, 20);
}
}
// Remove setinterval if slide is triggered manually and fourceautoplay is false
if (!_this.fromAuto && !_this.core.s.fourceAutoplay) {
_this.cancelAuto();
}
_this.fromAuto = false;
});
};
// Manage autoplay via play/stop buttons
Autoplay.prototype.controls = function() {
var _this = this;
var _html = '<span class="lg-autoplay-button lg-icon"></span>';
// Append autoplay controls
$(this.core.s.appendAutoplayControlsTo).append(_html);
_this.core.$outer.find('.lg-autoplay-button').on('click.lg', function() {
if ($(_this.core.$outer).hasClass('lg-show-autoplay')) {
_this.cancelAuto();
_this.core.s.fourceAutoplay = false;
} else {
if (!_this.interval) {
_this.startlAuto();
_this.core.s.fourceAutoplay = _this.fourceAutoplayTemp;
}
}
});
};
// Autostart gallery
Autoplay.prototype.startlAuto = function() {
var _this = this;
_this.core.$outer.find('.lg-progress').css('transition', 'width ' + (_this.core.s.speed + _this.core.s.pause) + 'ms ease 0s');
_this.core.$outer.addClass('lg-show-autoplay');
_this.core.$outer.find('.lg-progress-bar').addClass('lg-start');
_this.interval = setInterval(function() {
if (_this.core.index + 1 < _this.core.$items.length) {
_this.core.index++;
} else {
_this.core.index = 0;
}
_this.fromAuto = true;
_this.core.slide(_this.core.index, false, false, 'next');
}, _this.core.s.speed + _this.core.s.pause);
};
// cancel Autostart
Autoplay.prototype.cancelAuto = function() {
clearInterval(this.interval);
this.interval = false;
this.core.$outer.find('.lg-progress').removeAttr('style');
this.core.$outer.removeClass('lg-show-autoplay');
this.core.$outer.find('.lg-progress-bar').removeClass('lg-start');
};
Autoplay.prototype.destroy = function() {
this.cancelAuto();
this.core.$outer.find('.lg-progress-bar').remove();
};
$.fn.lightGallery.modules.autoplay = Autoplay;
})();
}));
/*! lg-fullscreen - v1.1.0 - 2019-02-19
* http://sachinchoolur.github.io/lightGallery
* Copyright (c) 2019 Sachin N; Licensed GPLv3 */
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define(['jquery'], function (a0) {
return (factory(a0));
});
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require('jquery'));
} else {
factory(root["jQuery"]);
}
}(this, function ($) {
(function() {
'use strict';
var defaults = {
fullScreen: true
};
function isFullScreen() {
return (
document.fullscreenElement ||
document.mozFullScreenElement ||
document.webkitFullscreenElement ||
document.msFullscreenElement
);
}
var Fullscreen = function(element) {
// get lightGallery core plugin data
this.core = $(element).data('lightGallery');
this.$el = $(element);
// extend module defalut settings with lightGallery core settings
this.core.s = $.extend({}, defaults, this.core.s);
this.init();
return this;
};
Fullscreen.prototype.init = function() {
var fullScreen = '';
if (this.core.s.fullScreen) {
// check for fullscreen browser support
if (!document.fullscreenEnabled && !document.webkitFullscreenEnabled &&
!document.mozFullScreenEnabled && !document.msFullscreenEnabled) {
return;
} else {
fullScreen = '<span class="lg-fullscreen lg-icon"></span>';
this.core.$outer.find('.lg-toolbar').append(fullScreen);
this.fullScreen();
}
}
};
Fullscreen.prototype.requestFullscreen = function() {
var el = document.documentElement;
if (el.requestFullscreen) {
el.requestFullscreen();
} else if (el.msRequestFullscreen) {
el.msRequestFullscreen();
} else if (el.mozRequestFullScreen) {
el.mozRequestFullScreen();
} else if (el.webkitRequestFullscreen) {
el.webkitRequestFullscreen();
}
};
Fullscreen.prototype.exitFullscreen = function() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
};
// https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode
Fullscreen.prototype.fullScreen = function() {
var _this = this;
$(document).on('fullscreenchange.lg webkitfullscreenchange.lg mozfullscreenchange.lg MSFullscreenChange.lg', function() {
_this.core.$outer.toggleClass('lg-fullscreen-on');
});
this.core.$outer.find('.lg-fullscreen').on('click.lg', function() {
if (isFullScreen()) {
_this.exitFullscreen();
} else {
_this.requestFullscreen();
}
});
};
Fullscreen.prototype.destroy = function() {
// exit from fullscreen if activated
if(isFullScreen()) {
this.exitFullscreen();
}
$(document).off('fullscreenchange.lg webkitfullscreenchange.lg mozfullscreenchange.lg MSFullscreenChange.lg');
};
$.fn.lightGallery.modules.fullscreen = Fullscreen;
})();
}));
/*! lg-hash - v1.0.4 - 2017-12-20
* http://sachinchoolur.github.io/lightGallery
* Copyright (c) 2017 Sachin N; Licensed GPLv3 */
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define(['jquery'], function (a0) {
return (factory(a0));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require('jquery'));
} else {
factory(jQuery);
}
}(this, function ($) {
(function() {
'use strict';
var defaults = {
hash: true
};
var Hash = function(element) {
this.core = $(element).data('lightGallery');
this.core.s = $.extend({}, defaults, this.core.s);
if (this.core.s.hash) {
this.oldHash = window.location.hash;
this.init();
}
return this;
};
Hash.prototype.init = function() {
var _this = this;
var _hash;
// Change hash value on after each slide transition
_this.core.$el.on('onAfterSlide.lg.tm', function(event, prevIndex, index) {
if (history.replaceState) {
history.replaceState(null, null, window.location.pathname + window.location.search + '#lg=' + _this.core.s.galleryId + '&slide=' + index);
} else {
window.location.hash = 'lg=' + _this.core.s.galleryId + '&slide=' + index;
}
});
// Listen hash change and change the slide according to slide value
$(window).on('hashchange.lg.hash', function() {
_hash = window.location.hash;
var _idx = parseInt(_hash.split('&slide=')[1], 10);
// it galleryId doesn't exist in the url close the gallery
if ((_hash.indexOf('lg=' + _this.core.s.galleryId) > -1)) {
_this.core.slide(_idx, false, false);
} else if (_this.core.lGalleryOn) {
_this.core.destroy();
}
});
};
Hash.prototype.destroy = function() {
if (!this.core.s.hash) {
return;
}
// Reset to old hash value
if (this.oldHash && this.oldHash.indexOf('lg=' + this.core.s.galleryId) < 0) {
if (history.replaceState) {
history.replaceState(null, null, this.oldHash);
} else {
window.location.hash = this.oldHash;
}
} else {
if (history.replaceState) {
history.replaceState(null, document.title, window.location.pathname + window.location.search);
} else {
window.location.hash = '';
}
}
this.core.$el.off('.lg.hash');
};
$.fn.lightGallery.modules.hash = Hash;
})();
}));
/*! lg-pager - v1.0.2 - 2017-01-22
* http://sachinchoolur.github.io/lightGallery
* Copyright (c) 2017 Sachin N; Licensed GPLv3 */
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define(['jquery'], function (a0) {
return (factory(a0));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require('jquery'));
} else {
factory(jQuery);
}
}(this, function ($) {
(function() {
'use strict';
var defaults = {
pager: false
};
var Pager = function(element) {
this.core = $(element).data('lightGallery');
this.$el = $(element);
this.core.s = $.extend({}, defaults, this.core.s);
if (this.core.s.pager && this.core.$items.length > 1) {
this.init();
}
return this;
};
Pager.prototype.init = function() {
var _this = this;
var pagerList = '';
var $pagerCont;
var $pagerOuter;
var timeout;
_this.core.$outer.find('.lg').append('<div class="lg-pager-outer"></div>');
if (_this.core.s.dynamic) {
for (var i = 0; i < _this.core.s.dynamicEl.length; i++) {
pagerList += '<span class="lg-pager-cont"> <span class="lg-pager"></span><div class="lg-pager-thumb-cont"><span class="lg-caret"></span> <img src="' + _this.core.s.dynamicEl[i].thumb + '" /></div></span>';
}
} else {
_this.core.$items.each(function() {
if (!_this.core.s.exThumbImage) {
pagerList += '<span class="lg-pager-cont"> <span class="lg-pager"></span><div class="lg-pager-thumb-cont"><span class="lg-caret"></span> <img src="' + $(this).find('img').attr('src') + '" /></div></span>';
} else {
pagerList += '<span class="lg-pager-cont"> <span class="lg-pager"></span><div class="lg-pager-thumb-cont"><span class="lg-caret"></span> <img src="' + $(this).attr(_this.core.s.exThumbImage) + '" /></div></span>';
}
});
}
$pagerOuter = _this.core.$outer.find('.lg-pager-outer');
$pagerOuter.html(pagerList);
$pagerCont = _this.core.$outer.find('.lg-pager-cont');
$pagerCont.on('click.lg touchend.lg', function() {
var _$this = $(this);
_this.core.index = _$this.index();
_this.core.slide(_this.core.index, false, true, false);
});
$pagerOuter.on('mouseover.lg', function() {
clearTimeout(timeout);
$pagerOuter.addClass('lg-pager-hover');
});
$pagerOuter.on('mouseout.lg', function() {
timeout = setTimeout(function() {
$pagerOuter.removeClass('lg-pager-hover');
});
});
_this.core.$el.on('onBeforeSlide.lg.tm', function(e, prevIndex, index) {
$pagerCont.removeClass('lg-pager-active');
$pagerCont.eq(index).addClass('lg-pager-active');
});
};
Pager.prototype.destroy = function() {
};
$.fn.lightGallery.modules.pager = Pager;
})();
}));
/*! lg-thumbnail - v1.1.0 - 2017-08-08
* http://sachinchoolur.github.io/lightGallery
* Copyright (c) 2017 Sachin N; Licensed GPLv3 */
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define(['jquery'], function (a0) {
return (factory(a0));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require('jquery'));
} else {
factory(jQuery);
}
}(this, function ($) {
(function() {
'use strict';
var defaults = {
thumbnail: true,
animateThumb: true,
currentPagerPosition: 'middle',
thumbWidth: 100,
thumbHeight: '80px',
thumbContHeight: 100,
thumbMargin: 5,
exThumbImage: false,
showThumbByDefault: true,
toogleThumb: true,
pullCaptionUp: true,
enableThumbDrag: true,
enableThumbSwipe: true,
swipeThreshold: 50,
loadYoutubeThumbnail: true,
youtubeThumbSize: 1,
loadVimeoThumbnail: true,
vimeoThumbSize: 'thumbnail_small',
loadDailymotionThumbnail: true
};
var Thumbnail = function(element) {
// get lightGallery core plugin data
this.core = $(element).data('lightGallery');
// extend module default settings with lightGallery core settings
this.core.s = $.extend({}, defaults, this.core.s);
this.$el = $(element);
this.$thumbOuter = null;
this.thumbOuterWidth = 0;
this.thumbTotalWidth = (this.core.$items.length * (this.core.s.thumbWidth + this.core.s.thumbMargin));
this.thumbIndex = this.core.index;
if (this.core.s.animateThumb) {
this.core.s.thumbHeight = '100%';
}
// Thumbnail animation value
this.left = 0;
this.init();
return this;
};
Thumbnail.prototype.init = function() {
var _this = this;
if (this.core.s.thumbnail && this.core.$items.length > 1) {
if (this.core.s.showThumbByDefault) {
setTimeout(function(){
_this.core.$outer.addClass('lg-thumb-open');
}, 700);
}
if (this.core.s.pullCaptionUp) {
this.core.$outer.addClass('lg-pull-caption-up');
}
this.build();
if (this.core.s.animateThumb && this.core.doCss()) {
if (this.core.s.enableThumbDrag) {
this.enableThumbDrag();
}
if (this.core.s.enableThumbSwipe) {
this.enableThumbSwipe();
}
this.thumbClickable = false;
} else {
this.thumbClickable = true;
}
this.toogle();
this.thumbkeyPress();
}
};
Thumbnail.prototype.build = function() {
var _this = this;
var thumbList = '';
var vimeoErrorThumbSize = '';
var $thumb;
var html = '<div class="lg-thumb-outer">' +
'<div class="lg-thumb lg-group">' +
'</div>' +
'</div>';
switch (this.core.s.vimeoThumbSize) {
case 'thumbnail_large':
vimeoErrorThumbSize = '640';
break;
case 'thumbnail_medium':
vimeoErrorThumbSize = '200x150';
break;
case 'thumbnail_small':
vimeoErrorThumbSize = '100x75';
}
_this.core.$outer.addClass('lg-has-thumb');
_this.core.$outer.find('.lg').append(html);
_this.$thumbOuter = _this.core.$outer.find('.lg-thumb-outer');
_this.thumbOuterWidth = _this.$thumbOuter.width();
if (_this.core.s.animateThumb) {
_this.core.$outer.find('.lg-thumb').css({
width: _this.thumbTotalWidth + 'px',
position: 'relative'
});
}
if (this.core.s.animateThumb) {
_this.$thumbOuter.css('height', _this.core.s.thumbContHeight + 'px');
}
function getThumb(src, thumb, index) {
var isVideo = _this.core.isVideo(src, index) || {};
var thumbImg;
var vimeoId = '';
if (isVideo.youtube || isVideo.vimeo || isVideo.dailymotion) {
if (isVideo.youtube) {
if (_this.core.s.loadYoutubeThumbnail) {
thumbImg = '//img.youtube.com/vi/' + isVideo.youtube[1] + '/' + _this.core.s.youtubeThumbSize + '.jpg';
} else {
thumbImg = thumb;
}
} else if (isVideo.vimeo) {
if (_this.core.s.loadVimeoThumbnail) {
thumbImg = '//i.vimeocdn.com/video/error_' + vimeoErrorThumbSize + '.jpg';
vimeoId = isVideo.vimeo[1];
} else {
thumbImg = thumb;
}
} else if (isVideo.dailymotion) {
if (_this.core.s.loadDailymotionThumbnail) {
thumbImg = '//www.dailymotion.com/thumbnail/video/' + isVideo.dailymotion[1];
} else {
thumbImg = thumb;
}
}
} else {
thumbImg = thumb;
}
thumbList += '<div data-vimeo-id="' + vimeoId + '" class="lg-thumb-item" style="width:' + _this.core.s.thumbWidth + 'px; height: ' + _this.core.s.thumbHeight + '; margin-right: ' + _this.core.s.thumbMargin + 'px"><img src="' + thumbImg + '" /></div>';
vimeoId = '';
}
if (_this.core.s.dynamic) {
for (var i = 0; i < _this.core.s.dynamicEl.length; i++) {
getThumb(_this.core.s.dynamicEl[i].src, _this.core.s.dynamicEl[i].thumb, i);
}
} else {
_this.core.$items.each(function(i) {
if (!_this.core.s.exThumbImage) {
getThumb($(this).attr('href') || $(this).attr('data-src'), $(this).find('img').attr('src'), i);
} else {
getThumb($(this).attr('href') || $(this).attr('data-src'), $(this).attr(_this.core.s.exThumbImage), i);
}
});
}
_this.core.$outer.find('.lg-thumb').html(thumbList);
$thumb = _this.core.$outer.find('.lg-thumb-item');
// Load vimeo thumbnails
$thumb.each(function() {
var $this = $(this);
var vimeoVideoId = $this.attr('data-vimeo-id');
if (vimeoVideoId) {
$.getJSON('//www.vimeo.com/api/v2/video/' + vimeoVideoId + '.json?callback=?', {
format: 'json'
}, function(data) {
$this.find('img').attr('src', data[0][_this.core.s.vimeoThumbSize]);
});
}
});
// manage active class for thumbnail
$thumb.eq(_this.core.index).addClass('active');
_this.core.$el.on('onBeforeSlide.lg.tm', function() {
$thumb.removeClass('active');
$thumb.eq(_this.core.index).addClass('active');
});
$thumb.on('click.lg touchend.lg', function() {
var _$this = $(this);
setTimeout(function() {
// In IE9 and bellow touch does not support
// Go to slide if browser does not support css transitions
if ((_this.thumbClickable && !_this.core.lgBusy) || !_this.core.doCss()) {
_this.core.index = _$this.index();
_this.core.slide(_this.core.index, false, true, false);
}
}, 50);
});
_this.core.$el.on('onBeforeSlide.lg.tm', function() {
_this.animateThumb(_this.core.index);
});
$(window).on('resize.lg.thumb orientationchange.lg.thumb', function() {
setTimeout(function() {
_this.animateThumb(_this.core.index);
_this.thumbOuterWidth = _this.$thumbOuter.width();
}, 200);
});
};
Thumbnail.prototype.setTranslate = function(value) {
// jQuery supports Automatic CSS prefixing since jQuery 1.8.0
this.core.$outer.find('.lg-thumb').css({
transform: 'translate3d(-' + (value) + 'px, 0px, 0px)'
});
};
Thumbnail.prototype.animateThumb = function(index) {
var $thumb = this.core.$outer.find('.lg-thumb');
if (this.core.s.animateThumb) {
var position;
switch (this.core.s.currentPagerPosition) {
case 'left':
position = 0;
break;
case 'middle':
position = (this.thumbOuterWidth / 2) - (this.core.s.thumbWidth / 2);
break;
case 'right':
position = this.thumbOuterWidth - this.core.s.thumbWidth;
}
this.left = ((this.core.s.thumbWidth + this.core.s.thumbMargin) * index - 1) - position;
if (this.left > (this.thumbTotalWidth - this.thumbOuterWidth)) {
this.left = this.thumbTotalWidth - this.thumbOuterWidth;
}
if (this.left < 0) {
this.left = 0;
}
if (this.core.lGalleryOn) {
if (!$thumb.hasClass('on')) {
this.core.$outer.find('.lg-thumb').css('transition-duration', this.core.s.speed + 'ms');
}
if (!this.core.doCss()) {
$thumb.animate({
left: -this.left + 'px'
}, this.core.s.speed);
}
} else {
if (!this.core.doCss()) {
$thumb.css('left', -this.left + 'px');
}
}
this.setTranslate(this.left);
}
};
// Enable thumbnail dragging and swiping
Thumbnail.prototype.enableThumbDrag = function() {
var _this = this;
var startCoords = 0;
var endCoords = 0;
var isDraging = false;
var isMoved = false;
var tempLeft = 0;
_this.$thumbOuter.addClass('lg-grab');
_this.core.$outer.find('.lg-thumb').on('mousedown.lg.thumb', function(e) {
if (_this.thumbTotalWidth > _this.thumbOuterWidth) {
// execute only on .lg-object
e.preventDefault();
startCoords = e.pageX;
isDraging = true;
// ** Fix for webkit cursor issue https://code.google.com/p/chromium/issues/detail?id=26723
_this.core.$outer.scrollLeft += 1;
_this.core.$outer.scrollLeft -= 1;
// *
_this.thumbClickable = false;
_this.$thumbOuter.removeClass('lg-grab').addClass('lg-grabbing');
}
});
$(window).on('mousemove.lg.thumb', function(e) {
if (isDraging) {
tempLeft = _this.left;
isMoved = true;
endCoords = e.pageX;
_this.$thumbOuter.addClass('lg-dragging');
tempLeft = tempLeft - (endCoords - startCoords);
if (tempLeft > (_this.thumbTotalWidth - _this.thumbOuterWidth)) {
tempLeft = _this.thumbTotalWidth - _this.thumbOuterWidth;
}
if (tempLeft < 0) {
tempLeft = 0;
}
// move current slide
_this.setTranslate(tempLeft);
}
});
$(window).on('mouseup.lg.thumb', function() {
if (isMoved) {
isMoved = false;
_this.$thumbOuter.removeClass('lg-dragging');
_this.left = tempLeft;
if (Math.abs(endCoords - startCoords) < _this.core.s.swipeThreshold) {
_this.thumbClickable = true;
}
} else {
_this.thumbClickable = true;
}
if (isDraging) {
isDraging = false;
_this.$thumbOuter.removeClass('lg-grabbing').addClass('lg-grab');
}
});
};
Thumbnail.prototype.enableThumbSwipe = function() {
var _this = this;
var startCoords = 0;
var endCoords = 0;
var isMoved = false;
var tempLeft = 0;
_this.core.$outer.find('.lg-thumb').on('touchstart.lg', function(e) {
if (_this.thumbTotalWidth > _this.thumbOuterWidth) {
e.preventDefault();
startCoords = e.originalEvent.targetTouches[0].pageX;
_this.thumbClickable = false;
}
});
_this.core.$outer.find('.lg-thumb').on('touchmove.lg', function(e) {
if (_this.thumbTotalWidth > _this.thumbOuterWidth) {
e.preventDefault();
endCoords = e.originalEvent.targetTouches[0].pageX;
isMoved = true;
_this.$thumbOuter.addClass('lg-dragging');
tempLeft = _this.left;
tempLeft = tempLeft - (endCoords - startCoords);
if (tempLeft > (_this.thumbTotalWidth - _this.thumbOuterWidth)) {
tempLeft = _this.thumbTotalWidth - _this.thumbOuterWidth;
}
if (tempLeft < 0) {
tempLeft = 0;
}
// move current slide
_this.setTranslate(tempLeft);
}
});
_this.core.$outer.find('.lg-thumb').on('touchend.lg', function() {
if (_this.thumbTotalWidth > _this.thumbOuterWidth) {
if (isMoved) {
isMoved = false;
_this.$thumbOuter.removeClass('lg-dragging');
if (Math.abs(endCoords - startCoords) < _this.core.s.swipeThreshold) {
_this.thumbClickable = true;
}
_this.left = tempLeft;
} else {
_this.thumbClickable = true;
}
} else {
_this.thumbClickable = true;
}
});
};
Thumbnail.prototype.toogle = function() {
var _this = this;
if (_this.core.s.toogleThumb) {
_this.core.$outer.addClass('lg-can-toggle');
_this.$thumbOuter.append('<span class="lg-toogle-thumb lg-icon"></span>');
_this.core.$outer.find('.lg-toogle-thumb').on('click.lg', function() {
_this.core.$outer.toggleClass('lg-thumb-open');
});
}
};
Thumbnail.prototype.thumbkeyPress = function() {
var _this = this;
$(window).on('keydown.lg.thumb', function(e) {
if (e.keyCode === 38) {
e.preventDefault();
_this.core.$outer.addClass('lg-thumb-open');
} else if (e.keyCode === 40) {
e.preventDefault();
_this.core.$outer.removeClass('lg-thumb-open');
}
});
};
Thumbnail.prototype.destroy = function() {
if (this.core.s.thumbnail && this.core.$items.length > 1) {
$(window).off('resize.lg.thumb orientationchange.lg.thumb keydown.lg.thumb');
this.$thumbOuter.remove();
this.core.$outer.removeClass('lg-has-thumb');
}
};
$.fn.lightGallery.modules.Thumbnail = Thumbnail;
})();
}));
/*! lg-zoom - v1.1.0 - 2017-08-08
* http://sachinchoolur.github.io/lightGallery
* Copyright (c) 2017 Sachin N; Licensed GPLv3 */
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define(['jquery'], function (a0) {
return (factory(a0));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require('jquery'));
} else {
factory(jQuery);
}
}(this, function ($) {
(function() {
'use strict';
var getUseLeft = function() {
var useLeft = false;
var isChrome = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
if (isChrome && parseInt(isChrome[2], 10) < 54) {
useLeft = true;
}
return useLeft;
};
var defaults = {
scale: 1,
zoom: true,
actualSize: true,
enableZoomAfter: 300,
useLeftForZoom: getUseLeft()
};
var Zoom = function(element) {
this.core = $(element).data('lightGallery');
this.core.s = $.extend({}, defaults, this.core.s);
if (this.core.s.zoom && this.core.doCss()) {
this.init();
// Store the zoomable timeout value just to clear it while closing
this.zoomabletimeout = false;
// Set the initial value center
this.pageX = $(window).width() / 2;
this.pageY = ($(window).height() / 2) + $(window).scrollTop();
}
return this;
};
Zoom.prototype.init = function() {
var _this = this;
var zoomIcons = '<span id="lg-zoom-in" class="lg-icon"></span><span id="lg-zoom-out" class="lg-icon"></span>';
if (_this.core.s.actualSize) {
zoomIcons += '<span id="lg-actual-size" class="lg-icon"></span>';
}
if (_this.core.s.useLeftForZoom) {
_this.core.$outer.addClass('lg-use-left-for-zoom');
} else {
_this.core.$outer.addClass('lg-use-transition-for-zoom');
}
this.core.$outer.find('.lg-toolbar').append(zoomIcons);
// Add zoomable class
_this.core.$el.on('onSlideItemLoad.lg.tm.zoom', function(event, index, delay) {
// delay will be 0 except first time
var _speed = _this.core.s.enableZoomAfter + delay;
// set _speed value 0 if gallery opened from direct url and if it is first slide
if ($('body').hasClass('lg-from-hash') && delay) {
// will execute only once
_speed = 0;
} else {
// Remove lg-from-hash to enable starting animation.
$('body').removeClass('lg-from-hash');
}
_this.zoomabletimeout = setTimeout(function() {
_this.core.$slide.eq(index).addClass('lg-zoomable');
}, _speed + 30);
});
var scale = 1;
/**
* @desc Image zoom
* Translate the wrap and scale the image to get better user experience
*
* @param {String} scaleVal - Zoom decrement/increment value
*/
var zoom = function(scaleVal) {
var $image = _this.core.$outer.find('.lg-current .lg-image');
var _x;
var _y;
// Find offset manually to avoid issue after zoom
var offsetX = ($(window).width() - $image.prop('offsetWidth')) / 2;
var offsetY = (($(window).height() - $image.prop('offsetHeight')) / 2) + $(window).scrollTop();
_x = _this.pageX - offsetX;
_y = _this.pageY - offsetY;
var x = (scaleVal - 1) * (_x);
var y = (scaleVal - 1) * (_y);
$image.css('transform', 'scale3d(' + scaleVal + ', ' + scaleVal + ', 1)').attr('data-scale', scaleVal);
if (_this.core.s.useLeftForZoom) {
$image.parent().css({
left: -x + 'px',
top: -y + 'px'
}).attr('data-x', x).attr('data-y', y);
} else {
$image.parent().css('transform', 'translate3d(-' + x + 'px, -' + y + 'px, 0)').attr('data-x', x).attr('data-y', y);
}
};
var callScale = function() {
if (scale > 1) {
_this.core.$outer.addClass('lg-zoomed');
} else {
_this.resetZoom();
}
if (scale < 1) {
scale = 1;
}
zoom(scale);
};
var actualSize = function(event, $image, index, fromIcon) {
var w = $image.prop('offsetWidth');
var nw;
if (_this.core.s.dynamic) {
nw = _this.core.s.dynamicEl[index].width || $image[0].naturalWidth || w;
} else {
nw = _this.core.$items.eq(index).attr('data-width') || $image[0].naturalWidth || w;
}
var _scale;
if (_this.core.$outer.hasClass('lg-zoomed')) {
scale = 1;
} else {
if (nw > w) {
_scale = nw / w;
scale = _scale || 2;
}
}
if (fromIcon) {
_this.pageX = $(window).width() / 2;
_this.pageY = ($(window).height() / 2) + $(window).scrollTop();
} else {
_this.pageX = event.pageX || event.originalEvent.targetTouches[0].pageX;
_this.pageY = event.pageY || event.originalEvent.targetTouches[0].pageY;
}
callScale();
setTimeout(function() {
_this.core.$outer.removeClass('lg-grabbing').addClass('lg-grab');
}, 10);
};
var tapped = false;
// event triggered after appending slide content
_this.core.$el.on('onAferAppendSlide.lg.tm.zoom', function(event, index) {
// Get the current element
var $image = _this.core.$slide.eq(index).find('.lg-image');
$image.on('dblclick', function(event) {
actualSize(event, $image, index);
});
$image.on('touchstart', function(event) {
if (!tapped) {
tapped = setTimeout(function() {
tapped = null;
}, 300);
} else {
clearTimeout(tapped);
tapped = null;
actualSize(event, $image, index);
}
event.preventDefault();
});
});
// Update zoom on resize and orientationchange
$(window).on('resize.lg.zoom scroll.lg.zoom orientationchange.lg.zoom', function() {
_this.pageX = $(window).width() / 2;
_this.pageY = ($(window).height() / 2) + $(window).scrollTop();
zoom(scale);
});
$('#lg-zoom-out').on('click.lg', function() {
if (_this.core.$outer.find('.lg-current .lg-image').length) {
scale -= _this.core.s.scale;
callScale();
}
});
$('#lg-zoom-in').on('click.lg', function() {
if (_this.core.$outer.find('.lg-current .lg-image').length) {
scale += _this.core.s.scale;
callScale();
}
});
$('#lg-actual-size').on('click.lg', function(event) {
actualSize(event, _this.core.$slide.eq(_this.core.index).find('.lg-image'), _this.core.index, true);
});
// Reset zoom on slide change
_this.core.$el.on('onBeforeSlide.lg.tm', function() {
scale = 1;
_this.resetZoom();
});
// Drag option after zoom
_this.zoomDrag();
_this.zoomSwipe();
};
// Reset zoom effect
Zoom.prototype.resetZoom = function() {
this.core.$outer.removeClass('lg-zoomed');
this.core.$slide.find('.lg-img-wrap').removeAttr('style data-x data-y');
this.core.$slide.find('.lg-image').removeAttr('style data-scale');
// Reset pagx pagy values to center
this.pageX = $(window).width() / 2;
this.pageY = ($(window).height() / 2) + $(window).scrollTop();
};
Zoom.prototype.zoomSwipe = function() {
var _this = this;
var startCoords = {};
var endCoords = {};
var isMoved = false;
// Allow x direction drag
var allowX = false;
// Allow Y direction drag
var allowY = false;
_this.core.$slide.on('touchstart.lg', function(e) {
if (_this.core.$outer.hasClass('lg-zoomed')) {
var $image = _this.core.$slide.eq(_this.core.index).find('.lg-object');
allowY = $image.prop('offsetHeight') * $image.attr('data-scale') > _this.core.$outer.find('.lg').height();
allowX = $image.prop('offsetWidth') * $image.attr('data-scale') > _this.core.$outer.find('.lg').width();
if ((allowX || allowY)) {
e.preventDefault();
startCoords = {
x: e.originalEvent.targetTouches[0].pageX,
y: e.originalEvent.targetTouches[0].pageY
};
}
}
});
_this.core.$slide.on('touchmove.lg', function(e) {
if (_this.core.$outer.hasClass('lg-zoomed')) {
var _$el = _this.core.$slide.eq(_this.core.index).find('.lg-img-wrap');
var distanceX;
var distanceY;
e.preventDefault();
isMoved = true;
endCoords = {
x: e.originalEvent.targetTouches[0].pageX,
y: e.originalEvent.targetTouches[0].pageY
};
// reset opacity and transition duration
_this.core.$outer.addClass('lg-zoom-dragging');
if (allowY) {
distanceY = (-Math.abs(_$el.attr('data-y'))) + (endCoords.y - startCoords.y);
} else {
distanceY = -Math.abs(_$el.attr('data-y'));
}
if (allowX) {
distanceX = (-Math.abs(_$el.attr('data-x'))) + (endCoords.x - startCoords.x);
} else {
distanceX = -Math.abs(_$el.attr('data-x'));
}
if ((Math.abs(endCoords.x - startCoords.x) > 15) || (Math.abs(endCoords.y - startCoords.y) > 15)) {
if (_this.core.s.useLeftForZoom) {
_$el.css({
left: distanceX + 'px',
top: distanceY + 'px'
});
} else {
_$el.css('transform', 'translate3d(' + distanceX + 'px, ' + distanceY + 'px, 0)');
}
}
}
});
_this.core.$slide.on('touchend.lg', function() {
if (_this.core.$outer.hasClass('lg-zoomed')) {
if (isMoved) {
isMoved = false;
_this.core.$outer.removeClass('lg-zoom-dragging');
_this.touchendZoom(startCoords, endCoords, allowX, allowY);
}
}
});
};
Zoom.prototype.zoomDrag = function() {
var _this = this;
var startCoords = {};
var endCoords = {};
var isDraging = false;
var isMoved = false;
// Allow x direction drag
var allowX = false;
// Allow Y direction drag
var allowY = false;
_this.core.$slide.on('mousedown.lg.zoom', function(e) {
// execute only on .lg-object
var $image = _this.core.$slide.eq(_this.core.index).find('.lg-object');
allowY = $image.prop('offsetHeight') * $image.attr('data-scale') > _this.core.$outer.find('.lg').height();
allowX = $image.prop('offsetWidth') * $image.attr('data-scale') > _this.core.$outer.find('.lg').width();
if (_this.core.$outer.hasClass('lg-zoomed')) {
if ($(e.target).hasClass('lg-object') && (allowX || allowY)) {
e.preventDefault();
startCoords = {
x: e.pageX,
y: e.pageY
};
isDraging = true;
// ** Fix for webkit cursor issue https://code.google.com/p/chromium/issues/detail?id=26723
_this.core.$outer.scrollLeft += 1;
_this.core.$outer.scrollLeft -= 1;
_this.core.$outer.removeClass('lg-grab').addClass('lg-grabbing');
}
}
});
$(window).on('mousemove.lg.zoom', function(e) {
if (isDraging) {
var _$el = _this.core.$slide.eq(_this.core.index).find('.lg-img-wrap');
var distanceX;
var distanceY;
isMoved = true;
endCoords = {
x: e.pageX,
y: e.pageY
};
// reset opacity and transition duration
_this.core.$outer.addClass('lg-zoom-dragging');
if (allowY) {
distanceY = (-Math.abs(_$el.attr('data-y'))) + (endCoords.y - startCoords.y);
} else {
distanceY = -Math.abs(_$el.attr('data-y'));
}
if (allowX) {
distanceX = (-Math.abs(_$el.attr('data-x'))) + (endCoords.x - startCoords.x);
} else {
distanceX = -Math.abs(_$el.attr('data-x'));
}
if (_this.core.s.useLeftForZoom) {
_$el.css({
left: distanceX + 'px',
top: distanceY + 'px'
});
} else {
_$el.css('transform', 'translate3d(' + distanceX + 'px, ' + distanceY + 'px, 0)');
}
}
});
$(window).on('mouseup.lg.zoom', function(e) {
if (isDraging) {
isDraging = false;
_this.core.$outer.removeClass('lg-zoom-dragging');
// Fix for chrome mouse move on click
if (isMoved && ((startCoords.x !== endCoords.x) || (startCoords.y !== endCoords.y))) {
endCoords = {
x: e.pageX,
y: e.pageY
};
_this.touchendZoom(startCoords, endCoords, allowX, allowY);
}
isMoved = false;
}
_this.core.$outer.removeClass('lg-grabbing').addClass('lg-grab');
});
};
Zoom.prototype.touchendZoom = function(startCoords, endCoords, allowX, allowY) {
var _this = this;
var _$el = _this.core.$slide.eq(_this.core.index).find('.lg-img-wrap');
var $image = _this.core.$slide.eq(_this.core.index).find('.lg-object');
var distanceX = (-Math.abs(_$el.attr('data-x'))) + (endCoords.x - startCoords.x);
var distanceY = (-Math.abs(_$el.attr('data-y'))) + (endCoords.y - startCoords.y);
var minY = (_this.core.$outer.find('.lg').height() - $image.prop('offsetHeight')) / 2;
var maxY = Math.abs(($image.prop('offsetHeight') * Math.abs($image.attr('data-scale'))) - _this.core.$outer.find('.lg').height() + minY);
var minX = (_this.core.$outer.find('.lg').width() - $image.prop('offsetWidth')) / 2;
var maxX = Math.abs(($image.prop('offsetWidth') * Math.abs($image.attr('data-scale'))) - _this.core.$outer.find('.lg').width() + minX);
if ((Math.abs(endCoords.x - startCoords.x) > 15) || (Math.abs(endCoords.y - startCoords.y) > 15)) {
if (allowY) {
if (distanceY <= -maxY) {
distanceY = -maxY;
} else if (distanceY >= -minY) {
distanceY = -minY;
}
}
if (allowX) {
if (distanceX <= -maxX) {
distanceX = -maxX;
} else if (distanceX >= -minX) {
distanceX = -minX;
}
}
if (allowY) {
_$el.attr('data-y', Math.abs(distanceY));
} else {
distanceY = -Math.abs(_$el.attr('data-y'));
}
if (allowX) {
_$el.attr('data-x', Math.abs(distanceX));
} else {
distanceX = -Math.abs(_$el.attr('data-x'));
}
if (_this.core.s.useLeftForZoom) {
_$el.css({
left: distanceX + 'px',
top: distanceY + 'px'
});
} else {
_$el.css('transform', 'translate3d(' + distanceX + 'px, ' + distanceY + 'px, 0)');
}
}
};
Zoom.prototype.destroy = function() {
var _this = this;
// Unbind all events added by lightGallery zoom plugin
_this.core.$el.off('.lg.zoom');
$(window).off('.lg.zoom');
_this.core.$slide.off('.lg.zoom');
_this.core.$el.off('.lg.tm.zoom');
_this.resetZoom();
clearTimeout(_this.zoomabletimeout);
_this.zoomabletimeout = false;
};
$.fn.lightGallery.modules.zoom = Zoom;
})();
}));