Skip to content

Commit 31eb9a7

Browse files
committedJun 8, 2024
1.2.0 build
1 parent f77d6d5 commit 31eb9a7

4 files changed

+328
-182
lines changed
 

‎dist/jquery.magnific-popup.js

+125-43
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/*! Magnific Popup - v1.1.0 - 2016-02-20
1+
/*! Magnific Popup - v1.2.0 - 2024-06-08
22
* http://dimsemenov.com/plugins/magnific-popup/
3-
* Copyright (c) 2016 Dmitry Semenov; */
3+
* Copyright (c) 2024 Dmytro Semenov; */
44
;(function (factory) {
55
if (typeof define === 'function' && define.amd) {
66
// AMD. Register as an anonymous module.
@@ -83,7 +83,7 @@ var _mfpOn = function(name, f) {
8383
// converts "mfpEventName" to "eventName" callback and triggers it if it's present
8484
e = e.charAt(0).toLowerCase() + e.slice(1);
8585
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]);
8787
}
8888
}
8989
},
@@ -175,7 +175,7 @@ MagnificPopup.prototype = {
175175
}
176176
}
177177
} else {
178-
mfp.items = $.isArray(data.items) ? data.items : [data.items];
178+
mfp.items = Array.isArray(data.items) ? data.items : [data.items];
179179
mfp.index = data.index || 0;
180180
}
181181

@@ -641,7 +641,7 @@ MagnificPopup.prototype = {
641641
var disableOn = options.disableOn !== undefined ? options.disableOn : $.magnificPopup.defaults.disableOn;
642642

643643
if(disableOn) {
644-
if($.isFunction(disableOn)) {
644+
if(typeof disableOn === "function") {
645645
if( !disableOn.call(mfp) ) {
646646
return true;
647647
}
@@ -693,7 +693,11 @@ MagnificPopup.prototype = {
693693
status = data.status;
694694
text = data.text;
695695

696-
mfp.preloader.html(text);
696+
if (mfp.st.allowHTMLInStatusIndicator) {
697+
mfp.preloader.html(text);
698+
} else {
699+
mfp.preloader.text(text);
700+
}
697701

698702
mfp.preloader.find('a').on('click', function(e) {
699703
e.stopImmediatePropagation();
@@ -712,7 +716,7 @@ MagnificPopup.prototype = {
712716
// "target" is an element that was clicked
713717
_checkIfClose: function(target) {
714718

715-
if($(target).hasClass(PREVENT_CLOSE_CLASS)) {
719+
if($(target).closest('.' + PREVENT_CLOSE_CLASS).length) {
716720
return;
717721
}
718722

@@ -724,7 +728,7 @@ MagnificPopup.prototype = {
724728
} else {
725729

726730
// 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]) ) {
728732
return true;
729733
}
730734

@@ -796,7 +800,11 @@ MagnificPopup.prototype = {
796800
}
797801

798802
} 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+
}
800808
}
801809
});
802810
},
@@ -899,7 +907,11 @@ $.magnificPopup = {
899907

900908
tLoading: 'Loading...',
901909

902-
autoFocusLast: true
910+
autoFocusLast: true,
911+
912+
allowHTMLInStatusIndicator: false,
913+
914+
allowHTMLInTemplate: false
903915

904916
}
905917
};
@@ -1047,7 +1059,7 @@ $.magnificPopup.registerModule(AJAX_NS, {
10471059
options: {
10481060
settings: null,
10491061
cursor: 'mfp-ajax-cur',
1050-
tError: '<a href="%url%">The content</a> could not be loaded.'
1062+
tError: 'The content could not be loaded.'
10511063
},
10521064

10531065
proto: {
@@ -1117,7 +1129,7 @@ var _imgInterval,
11171129
var src = mfp.st.image.titleSrc;
11181130

11191131
if(src) {
1120-
if($.isFunction(src)) {
1132+
if(typeof src === "function") {
11211133
return src.call(mfp, item);
11221134
} else if(item.el) {
11231135
return item.el.attr(src) || '';
@@ -1144,7 +1156,7 @@ $.magnificPopup.registerModule('image', {
11441156
cursor: 'mfp-zoom-out-cur',
11451157
titleSrc: 'title',
11461158
verticalFit: true,
1147-
tError: '<a href="%url%">The image</a> could not be loaded.'
1159+
tError: 'The image could not be loaded.'
11481160
},
11491161

11501162
proto: {
@@ -1249,6 +1261,23 @@ $.magnificPopup.registerModule('image', {
12491261

12501262
var guard = 0,
12511263

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+
12521281
// image load complete handler
12531282
onLoadComplete = function() {
12541283
if(item) {
@@ -1277,23 +1306,8 @@ $.magnificPopup.registerModule('image', {
12771306
}
12781307
}
12791308
}
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+
12971311

12981312

12991313
var el = template.find('.mfp-img');
@@ -1638,6 +1652,7 @@ $.magnificPopup.registerModule(IFRAME_NS, {
16381652
if(iframeSt.srcAction) {
16391653
dataObj[iframeSt.srcAction] = embedSrc;
16401654
}
1655+
16411656
mfp._parseMarkup(template, dataObj, item);
16421657

16431658
mfp.updateStatus('ready');
@@ -1679,7 +1694,10 @@ $.magnificPopup.registerModule('gallery', {
16791694

16801695
tPrev: 'Previous (Left arrow key)',
16811696
tNext: 'Next (Right arrow key)',
1682-
tCounter: '%curr% of %total%'
1697+
tCounter: '%curr% of %total%',
1698+
1699+
langDir: null,
1700+
loop: true,
16831701
},
16841702

16851703
proto: {
@@ -1691,6 +1709,10 @@ $.magnificPopup.registerModule('gallery', {
16911709
mfp.direction = true; // true - next, false - prev
16921710

16931711
if(!gSt || !gSt.enabled ) return false;
1712+
1713+
if (!gSt.langDir) {
1714+
gSt.langDir = document.dir || 'ltr';
1715+
}
16941716

16951717
_wrapClasses += ' mfp-gallery';
16961718

@@ -1707,11 +1729,20 @@ $.magnificPopup.registerModule('gallery', {
17071729

17081730
_document.on('keydown'+ns, function(e) {
17091731
if (e.keyCode === 37) {
1710-
mfp.prev();
1732+
if (gSt.langDir === 'rtl') mfp.next();
1733+
else mfp.prev();
17111734
} else if (e.keyCode === 39) {
1712-
mfp.next();
1735+
if (gSt.langDir === 'rtl') mfp.prev();
1736+
else mfp.next();
17131737
}
17141738
});
1739+
1740+
mfp.updateGalleryButtons();
1741+
1742+
});
1743+
1744+
_mfpOn('UpdateStatus'+ns, function(/*e, data*/) {
1745+
mfp.updateGalleryButtons();
17151746
});
17161747

17171748
_mfpOn('UpdateStatus'+ns, function(e, data) {
@@ -1727,18 +1758,44 @@ $.magnificPopup.registerModule('gallery', {
17271758

17281759
_mfpOn('BuildControls' + ns, function() {
17291760
if(mfp.items.length > 1 && gSt.arrows && !mfp.arrowLeft) {
1730-
var markup = gSt.arrowMarkup,
1731-
arrowLeft = mfp.arrowLeft = $( markup.replace(/%title%/gi, gSt.tPrev).replace(/%dir%/gi, 'left') ).addClass(PREVENT_CLOSE_CLASS),
1732-
arrowRight = mfp.arrowRight = $( markup.replace(/%title%/gi, gSt.tNext).replace(/%dir%/gi, 'right') ).addClass(PREVENT_CLOSE_CLASS);
17331761

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(/%title%/gi, arrowLeftDesc).replace(/%action%/gi, arrowLeftAction).replace(/%dir%/gi, 'left') ).addClass(PREVENT_CLOSE_CLASS),
1778+
arrowRight = mfp.arrowRight = $( markup.replace(/%title%/gi, arrowRightDesc).replace(/%action%/gi, arrowRightAction).replace(/%dir%/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();
17361791
});
1737-
arrowRight.click(function() {
1738-
mfp.next();
1792+
arrowRight.on('click', function() {
1793+
if (gSt.langDir === 'rtl') mfp.prev();
1794+
else mfp.next();
17391795
});
17401796

17411797
mfp.container.append(arrowLeft.add(arrowRight));
1798+
17421799
}
17431800
});
17441801

@@ -1760,13 +1817,17 @@ $.magnificPopup.registerModule('gallery', {
17601817

17611818
},
17621819
next: function() {
1820+
var newIndex = _getLoopedId(mfp.index + 1);
1821+
if (!mfp.st.gallery.loop && newIndex === 0 ) return false;
17631822
mfp.direction = true;
1764-
mfp.index = _getLoopedId(mfp.index + 1);
1823+
mfp.index = newIndex;
17651824
mfp.updateItemHTML();
17661825
},
17671826
prev: function() {
1827+
var newIndex = mfp.index - 1;
1828+
if (!mfp.st.gallery.loop && newIndex < 0) return false;
17681829
mfp.direction = false;
1769-
mfp.index = _getLoopedId(mfp.index - 1);
1830+
mfp.index = _getLoopedId(newIndex);
17701831
mfp.updateItemHTML();
17711832
},
17721833
goTo: function(newIndex) {
@@ -1813,10 +1874,31 @@ $.magnificPopup.registerModule('gallery', {
18131874

18141875

18151876
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+
18171897
}
1898+
18181899
});
18191900

1901+
18201902
/*>>gallery*/
18211903

18221904
/*>>retina*/

‎dist/jquery.magnific-popup.min.js

+1-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/magnific-popup.css

+200-134
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"node": ">= 0.8.0"
3535
},
3636
"scripts": {
37-
"test": "grunt jshint"
37+
"test": "grunt jshint",
38+
"prod": "grunt production"
3839
},
3940
"devDependencies": {
4041
"dart-sass": "^1.25.0",

0 commit comments

Comments
 (0)
Please sign in to comment.