1
- /*! Magnific Popup - v1.1 .0 - 2016-02-20
1
+ /*! Magnific Popup - v1.2 .0 - 2024-06-08
2
2
* http://dimsemenov.com/plugins/magnific-popup/
3
- * Copyright (c) 2016 Dmitry Semenov; */
3
+ * Copyright (c) 2024 Dmytro Semenov; */
4
4
; ( function ( factory ) {
5
5
if ( typeof define === 'function' && define . amd ) {
6
6
// AMD. Register as an anonymous module.
@@ -83,7 +83,7 @@ var _mfpOn = function(name, f) {
83
83
// converts "mfpEventName" to "eventName" callback and triggers it if it's present
84
84
e = e . charAt ( 0 ) . toLowerCase ( ) + e . slice ( 1 ) ;
85
85
if ( mfp . st . callbacks [ e ] ) {
86
- mfp . st . callbacks [ e ] . apply ( mfp , $ . isArray ( data ) ? data : [ data ] ) ;
86
+ mfp . st . callbacks [ e ] . apply ( mfp , Array . isArray ( data ) ? data : [ data ] ) ;
87
87
}
88
88
}
89
89
} ,
@@ -175,7 +175,7 @@ MagnificPopup.prototype = {
175
175
}
176
176
}
177
177
} else {
178
- mfp . items = $ . isArray ( data . items ) ? data . items : [ data . items ] ;
178
+ mfp . items = Array . isArray ( data . items ) ? data . items : [ data . items ] ;
179
179
mfp . index = data . index || 0 ;
180
180
}
181
181
@@ -641,7 +641,7 @@ MagnificPopup.prototype = {
641
641
var disableOn = options . disableOn !== undefined ? options . disableOn : $ . magnificPopup . defaults . disableOn ;
642
642
643
643
if ( disableOn ) {
644
- if ( $ . isFunction ( disableOn ) ) {
644
+ if ( typeof disableOn === "function" ) {
645
645
if ( ! disableOn . call ( mfp ) ) {
646
646
return true ;
647
647
}
@@ -693,7 +693,11 @@ MagnificPopup.prototype = {
693
693
status = data . status ;
694
694
text = data . text ;
695
695
696
- mfp . preloader . html ( text ) ;
696
+ if ( mfp . st . allowHTMLInStatusIndicator ) {
697
+ mfp . preloader . html ( text ) ;
698
+ } else {
699
+ mfp . preloader . text ( text ) ;
700
+ }
697
701
698
702
mfp . preloader . find ( 'a' ) . on ( 'click' , function ( e ) {
699
703
e . stopImmediatePropagation ( ) ;
@@ -712,7 +716,7 @@ MagnificPopup.prototype = {
712
716
// "target" is an element that was clicked
713
717
_checkIfClose : function ( target ) {
714
718
715
- if ( $ ( target ) . hasClass ( PREVENT_CLOSE_CLASS ) ) {
719
+ if ( $ ( target ) . closest ( '.' + PREVENT_CLOSE_CLASS ) . length ) {
716
720
return ;
717
721
}
718
722
@@ -724,7 +728,7 @@ MagnificPopup.prototype = {
724
728
} else {
725
729
726
730
// We close the popup if click is on close button or on preloader. Or if there is no content.
727
- if ( ! mfp . content || $ ( target ) . hasClass ( ' mfp-close') || ( mfp . preloader && target === mfp . preloader [ 0 ] ) ) {
731
+ if ( ! mfp . content || $ ( target ) . closest ( '. mfp-close') . length || ( mfp . preloader && target === mfp . preloader [ 0 ] ) ) {
728
732
return true ;
729
733
}
730
734
@@ -796,7 +800,11 @@ MagnificPopup.prototype = {
796
800
}
797
801
798
802
} else {
799
- template . find ( EVENT_NS + '-' + key ) . html ( value ) ;
803
+ if ( mfp . st . allowHTMLInTemplate ) {
804
+ template . find ( EVENT_NS + '-' + key ) . html ( value ) ;
805
+ } else {
806
+ template . find ( EVENT_NS + '-' + key ) . text ( value ) ;
807
+ }
800
808
}
801
809
} ) ;
802
810
} ,
@@ -899,7 +907,11 @@ $.magnificPopup = {
899
907
900
908
tLoading : 'Loading...' ,
901
909
902
- autoFocusLast : true
910
+ autoFocusLast : true ,
911
+
912
+ allowHTMLInStatusIndicator : false ,
913
+
914
+ allowHTMLInTemplate : false
903
915
904
916
}
905
917
} ;
@@ -1047,7 +1059,7 @@ $.magnificPopup.registerModule(AJAX_NS, {
1047
1059
options : {
1048
1060
settings : null ,
1049
1061
cursor : 'mfp-ajax-cur' ,
1050
- tError : '<a href="%url%"> The content</a> could not be loaded.'
1062
+ tError : 'The content could not be loaded.'
1051
1063
} ,
1052
1064
1053
1065
proto : {
@@ -1117,7 +1129,7 @@ var _imgInterval,
1117
1129
var src = mfp . st . image . titleSrc ;
1118
1130
1119
1131
if ( src ) {
1120
- if ( $ . isFunction ( src ) ) {
1132
+ if ( typeof src === "function" ) {
1121
1133
return src . call ( mfp , item ) ;
1122
1134
} else if ( item . el ) {
1123
1135
return item . el . attr ( src ) || '' ;
@@ -1144,7 +1156,7 @@ $.magnificPopup.registerModule('image', {
1144
1156
cursor : 'mfp-zoom-out-cur' ,
1145
1157
titleSrc : 'title' ,
1146
1158
verticalFit : true ,
1147
- tError : '<a href="%url%"> The image</a> could not be loaded.'
1159
+ tError : 'The image could not be loaded.'
1148
1160
} ,
1149
1161
1150
1162
proto : {
@@ -1249,6 +1261,23 @@ $.magnificPopup.registerModule('image', {
1249
1261
1250
1262
var guard = 0 ,
1251
1263
1264
+ imgSt = mfp . st . image ,
1265
+
1266
+ // image error handler
1267
+ onLoadError = function ( ) {
1268
+ if ( item ) {
1269
+ item . img . off ( '.mfploader' ) ;
1270
+ if ( item === mfp . currItem ) {
1271
+ mfp . _onImageHasSize ( item ) ;
1272
+ mfp . updateStatus ( 'error' , imgSt . tError . replace ( '%url%' , item . src ) ) ;
1273
+ }
1274
+
1275
+ item . hasSize = true ;
1276
+ item . loaded = true ;
1277
+ item . loadError = true ;
1278
+ }
1279
+ } ,
1280
+
1252
1281
// image load complete handler
1253
1282
onLoadComplete = function ( ) {
1254
1283
if ( item ) {
@@ -1277,23 +1306,8 @@ $.magnificPopup.registerModule('image', {
1277
1306
}
1278
1307
}
1279
1308
}
1280
- } ,
1281
-
1282
- // image error handler
1283
- onLoadError = function ( ) {
1284
- if ( item ) {
1285
- item . img . off ( '.mfploader' ) ;
1286
- if ( item === mfp . currItem ) {
1287
- mfp . _onImageHasSize ( item ) ;
1288
- mfp . updateStatus ( 'error' , imgSt . tError . replace ( '%url%' , item . src ) ) ;
1289
- }
1290
-
1291
- item . hasSize = true ;
1292
- item . loaded = true ;
1293
- item . loadError = true ;
1294
- }
1295
- } ,
1296
- imgSt = mfp . st . image ;
1309
+ } ;
1310
+
1297
1311
1298
1312
1299
1313
var el = template . find ( '.mfp-img' ) ;
@@ -1638,6 +1652,7 @@ $.magnificPopup.registerModule(IFRAME_NS, {
1638
1652
if ( iframeSt . srcAction ) {
1639
1653
dataObj [ iframeSt . srcAction ] = embedSrc ;
1640
1654
}
1655
+
1641
1656
mfp . _parseMarkup ( template , dataObj , item ) ;
1642
1657
1643
1658
mfp . updateStatus ( 'ready' ) ;
@@ -1679,7 +1694,10 @@ $.magnificPopup.registerModule('gallery', {
1679
1694
1680
1695
tPrev : 'Previous (Left arrow key)' ,
1681
1696
tNext : 'Next (Right arrow key)' ,
1682
- tCounter : '%curr% of %total%'
1697
+ tCounter : '%curr% of %total%' ,
1698
+
1699
+ langDir : null ,
1700
+ loop : true ,
1683
1701
} ,
1684
1702
1685
1703
proto : {
@@ -1691,6 +1709,10 @@ $.magnificPopup.registerModule('gallery', {
1691
1709
mfp . direction = true ; // true - next, false - prev
1692
1710
1693
1711
if ( ! gSt || ! gSt . enabled ) return false ;
1712
+
1713
+ if ( ! gSt . langDir ) {
1714
+ gSt . langDir = document . dir || 'ltr' ;
1715
+ }
1694
1716
1695
1717
_wrapClasses += ' mfp-gallery' ;
1696
1718
@@ -1707,11 +1729,20 @@ $.magnificPopup.registerModule('gallery', {
1707
1729
1708
1730
_document . on ( 'keydown' + ns , function ( e ) {
1709
1731
if ( e . keyCode === 37 ) {
1710
- mfp . prev ( ) ;
1732
+ if ( gSt . langDir === 'rtl' ) mfp . next ( ) ;
1733
+ else mfp . prev ( ) ;
1711
1734
} else if ( e . keyCode === 39 ) {
1712
- mfp . next ( ) ;
1735
+ if ( gSt . langDir === 'rtl' ) mfp . prev ( ) ;
1736
+ else mfp . next ( ) ;
1713
1737
}
1714
1738
} ) ;
1739
+
1740
+ mfp . updateGalleryButtons ( ) ;
1741
+
1742
+ } ) ;
1743
+
1744
+ _mfpOn ( 'UpdateStatus' + ns , function ( /*e, data*/ ) {
1745
+ mfp . updateGalleryButtons ( ) ;
1715
1746
} ) ;
1716
1747
1717
1748
_mfpOn ( 'UpdateStatus' + ns , function ( e , data ) {
@@ -1727,18 +1758,44 @@ $.magnificPopup.registerModule('gallery', {
1727
1758
1728
1759
_mfpOn ( 'BuildControls' + ns , function ( ) {
1729
1760
if ( mfp . items . length > 1 && gSt . arrows && ! mfp . arrowLeft ) {
1730
- var markup = gSt . arrowMarkup ,
1731
- arrowLeft = mfp . arrowLeft = $ ( markup . replace ( / % t i t l e % / gi, gSt . tPrev ) . replace ( / % d i r % / gi, 'left' ) ) . addClass ( PREVENT_CLOSE_CLASS ) ,
1732
- arrowRight = mfp . arrowRight = $ ( markup . replace ( / % t i t l e % / gi, gSt . tNext ) . replace ( / % d i r % / gi, 'right' ) ) . addClass ( PREVENT_CLOSE_CLASS ) ;
1733
1761
1734
- arrowLeft . click ( function ( ) {
1735
- mfp . prev ( ) ;
1762
+ var arrowLeftDesc , arrowRightDesc , arrowLeftAction , arrowRightAction ;
1763
+
1764
+ if ( gSt . langDir === 'rtl' ) {
1765
+ arrowLeftDesc = gSt . tNext ;
1766
+ arrowRightDesc = gSt . tPrev ;
1767
+ arrowLeftAction = 'next' ;
1768
+ arrowRightAction = 'prev' ;
1769
+ } else {
1770
+ arrowLeftDesc = gSt . tPrev ;
1771
+ arrowRightDesc = gSt . tNext ;
1772
+ arrowLeftAction = 'prev' ;
1773
+ arrowRightAction = 'next' ;
1774
+ }
1775
+
1776
+ var markup = gSt . arrowMarkup ,
1777
+ arrowLeft = mfp . arrowLeft = $ ( markup . replace ( / % t i t l e % / gi, arrowLeftDesc ) . replace ( / % a c t i o n % / gi, arrowLeftAction ) . replace ( / % d i r % / gi, 'left' ) ) . addClass ( PREVENT_CLOSE_CLASS ) ,
1778
+ arrowRight = mfp . arrowRight = $ ( markup . replace ( / % t i t l e % / gi, arrowRightDesc ) . replace ( / % a c t i o n % / gi, arrowRightAction ) . replace ( / % d i r % / gi, 'right' ) ) . addClass ( PREVENT_CLOSE_CLASS ) ;
1779
+
1780
+ if ( gSt . langDir === 'rtl' ) {
1781
+ mfp . arrowNext = arrowLeft ;
1782
+ mfp . arrowPrev = arrowRight ;
1783
+ } else {
1784
+ mfp . arrowNext = arrowRight ;
1785
+ mfp . arrowPrev = arrowLeft ;
1786
+ }
1787
+
1788
+ arrowLeft . on ( 'click' , function ( ) {
1789
+ if ( gSt . langDir === 'rtl' ) mfp . next ( ) ;
1790
+ else mfp . prev ( ) ;
1736
1791
} ) ;
1737
- arrowRight . click ( function ( ) {
1738
- mfp . next ( ) ;
1792
+ arrowRight . on ( 'click' , function ( ) {
1793
+ if ( gSt . langDir === 'rtl' ) mfp . prev ( ) ;
1794
+ else mfp . next ( ) ;
1739
1795
} ) ;
1740
1796
1741
1797
mfp . container . append ( arrowLeft . add ( arrowRight ) ) ;
1798
+
1742
1799
}
1743
1800
} ) ;
1744
1801
@@ -1760,13 +1817,17 @@ $.magnificPopup.registerModule('gallery', {
1760
1817
1761
1818
} ,
1762
1819
next : function ( ) {
1820
+ var newIndex = _getLoopedId ( mfp . index + 1 ) ;
1821
+ if ( ! mfp . st . gallery . loop && newIndex === 0 ) return false ;
1763
1822
mfp . direction = true ;
1764
- mfp . index = _getLoopedId ( mfp . index + 1 ) ;
1823
+ mfp . index = newIndex ;
1765
1824
mfp . updateItemHTML ( ) ;
1766
1825
} ,
1767
1826
prev : function ( ) {
1827
+ var newIndex = mfp . index - 1 ;
1828
+ if ( ! mfp . st . gallery . loop && newIndex < 0 ) return false ;
1768
1829
mfp . direction = false ;
1769
- mfp . index = _getLoopedId ( mfp . index - 1 ) ;
1830
+ mfp . index = _getLoopedId ( newIndex ) ;
1770
1831
mfp . updateItemHTML ( ) ;
1771
1832
} ,
1772
1833
goTo : function ( newIndex ) {
@@ -1813,10 +1874,31 @@ $.magnificPopup.registerModule('gallery', {
1813
1874
1814
1875
1815
1876
item . preloaded = true ;
1816
- }
1877
+ } ,
1878
+
1879
+ /**
1880
+ * Show/hide the gallery prev/next buttons if we're at the start/end, if looping is turned off
1881
+ * Added by Joloco for Veg
1882
+ */
1883
+ updateGalleryButtons : function ( ) {
1884
+
1885
+ if ( ! mfp . st . gallery . loop && typeof mfp . arrowPrev === 'object' && mfp . arrowPrev !== null ) {
1886
+
1887
+ if ( mfp . index === 0 ) mfp . arrowPrev . hide ( ) ;
1888
+ else mfp . arrowPrev . show ( ) ;
1889
+
1890
+ if ( mfp . index === ( mfp . items . length - 1 ) ) mfp . arrowNext . hide ( ) ;
1891
+ else mfp . arrowNext . show ( ) ;
1892
+
1893
+ }
1894
+
1895
+ } ,
1896
+
1817
1897
}
1898
+
1818
1899
} ) ;
1819
1900
1901
+
1820
1902
/*>>gallery*/
1821
1903
1822
1904
/*>>retina*/
0 commit comments