Update Magnific Popup to v1.1.0

This commit is contained in:
Michael Rose 2017-09-12 12:54:17 -04:00
parent 7845654225
commit 1570e85fb1
2 changed files with 1764 additions and 1953 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,20 +1,31 @@
/*! Magnific Popup - v0.9.9 - 2013-12-27 /*! Magnific Popup - v1.1.0 - 2016-02-20
* http://dimsemenov.com/plugins/magnific-popup/ * http://dimsemenov.com/plugins/magnific-popup/
* Copyright (c) 2013 Dmitry Semenov; */ * Copyright (c) 2016 Dmitry Semenov; */
;(function($) { ;(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS
factory(require('jquery'));
} else {
// Browser globals
factory(window.jQuery || window.Zepto);
}
}(function($) {
/*>>core*/ /*>>core*/
/** /**
* *
* Magnific Popup Core JS file * Magnific Popup Core JS file
* *
*/ */
/** /**
* Private static constants * Private static constants
*/ */
var CLOSE_EVENT = 'Close', var CLOSE_EVENT = 'Close',
BEFORE_CLOSE_EVENT = 'BeforeClose', BEFORE_CLOSE_EVENT = 'BeforeClose',
AFTER_CLOSE_EVENT = 'AfterClose', AFTER_CLOSE_EVENT = 'AfterClose',
BEFORE_APPEND_EVENT = 'BeforeAppend', BEFORE_APPEND_EVENT = 'BeforeAppend',
@ -28,25 +39,25 @@ var CLOSE_EVENT = 'Close',
PREVENT_CLOSE_CLASS = 'mfp-prevent-close'; PREVENT_CLOSE_CLASS = 'mfp-prevent-close';
/** /**
* Private vars * Private vars
*/ */
var mfp, // As we have only one instance of MagnificPopup object, we define it locally to not to use 'this' /*jshint -W079 */
var mfp, // As we have only one instance of MagnificPopup object, we define it locally to not to use 'this'
MagnificPopup = function(){}, MagnificPopup = function(){},
_isJQ = !!(window.jQuery), _isJQ = !!(window.jQuery),
_prevStatus, _prevStatus,
_window = $(window), _window = $(window),
_body,
_document, _document,
_prevContentType, _prevContentType,
_wrapClasses, _wrapClasses,
_currPopupType; _currPopupType;
/** /**
* Private functions * Private functions
*/ */
var _mfpOn = function(name, f) { var _mfpOn = function(name, f) {
mfp.ev.on(NS + name + EVENT_NS, f); mfp.ev.on(NS + name + EVENT_NS, f);
}, },
_getEl = function(className, appendTo, html, raw) { _getEl = function(className, appendTo, html, raw) {
@ -86,6 +97,7 @@ var _mfpOn = function(name, f) {
// Initialize Magnific Popup only when called at least once // Initialize Magnific Popup only when called at least once
_checkInstance = function() { _checkInstance = function() {
if(!$.magnificPopup.instance) { if(!$.magnificPopup.instance) {
/*jshint -W020 */
mfp = new MagnificPopup(); mfp = new MagnificPopup();
mfp.init(); mfp.init();
$.magnificPopup.instance = mfp; $.magnificPopup.instance = mfp;
@ -111,10 +123,10 @@ var _mfpOn = function(name, f) {
/** /**
* Public functions * Public functions
*/ */
MagnificPopup.prototype = { MagnificPopup.prototype = {
constructor: MagnificPopup, constructor: MagnificPopup,
@ -124,9 +136,7 @@ MagnificPopup.prototype = {
*/ */
init: function() { init: function() {
var appVersion = navigator.appVersion; var appVersion = navigator.appVersion;
mfp.isIE7 = appVersion.indexOf("MSIE 7.") !== -1; mfp.isLowIE = mfp.isIE8 = document.all && !document.addEventListener;
mfp.isIE8 = appVersion.indexOf("MSIE 8.") !== -1;
mfp.isLowIE = mfp.isIE7 || mfp.isIE8;
mfp.isAndroid = (/android/gi).test(appVersion); mfp.isAndroid = (/android/gi).test(appVersion);
mfp.isIOS = (/iphone|ipad|ipod/gi).test(appVersion); mfp.isIOS = (/iphone|ipad|ipod/gi).test(appVersion);
mfp.supportsTransition = supportsTransitions(); mfp.supportsTransition = supportsTransitions();
@ -145,10 +155,6 @@ MagnificPopup.prototype = {
*/ */
open: function(data) { open: function(data) {
if(!_body) {
_body = $(document.body);
}
var i; var i;
if(data.isObj === false) { if(data.isObj === false) {
@ -347,7 +353,7 @@ MagnificPopup.prototype = {
$('html').css(windowStyles); $('html').css(windowStyles);
// add everything to DOM // add everything to DOM
mfp.bgOverlay.add(mfp.wrap).prependTo( mfp.st.prependTo || _body ); mfp.bgOverlay.add(mfp.wrap).prependTo( mfp.st.prependTo || $(document.body) );
// Save last focused element // Save last focused element
mfp._lastFocusedEl = document.activeElement; mfp._lastFocusedEl = document.activeElement;
@ -438,7 +444,7 @@ MagnificPopup.prototype = {
} }
if(mfp._lastFocusedEl) { if(mfp.st.autoFocusLast && mfp._lastFocusedEl) {
$(mfp._lastFocusedEl).focus(); // put tab focus back $(mfp._lastFocusedEl).focus(); // put tab focus back
} }
mfp.currItem = null; mfp.currItem = null;
@ -493,10 +499,6 @@ MagnificPopup.prototype = {
mfp.currItem = item; mfp.currItem = item;
if(!mfp.currTemplate[type]) { if(!mfp.currTemplate[type]) {
var markup = mfp.st[type] ? mfp.st[type].markup : false; var markup = mfp.st[type] ? mfp.st[type].markup : false;
@ -557,8 +559,6 @@ MagnificPopup.prototype = {
}, },
/** /**
* Creates Magnific Popup data object based on given data * Creates Magnific Popup data object based on given data
* @param {int} index Index of item to parse * @param {int} index Index of item to parse
@ -634,7 +634,7 @@ MagnificPopup.prototype = {
var midClick = options.midClick !== undefined ? options.midClick : $.magnificPopup.defaults.midClick; var midClick = options.midClick !== undefined ? options.midClick : $.magnificPopup.defaults.midClick;
if(!midClick && ( e.which === 2 || e.ctrlKey || e.metaKey ) ) { if(!midClick && ( e.which === 2 || e.ctrlKey || e.metaKey || e.altKey || e.shiftKey ) ) {
return; return;
} }
@ -661,7 +661,6 @@ MagnificPopup.prototype = {
} }
} }
options.el = $(e.mfpEl); options.el = $(e.mfpEl);
if(options.delegate) { if(options.delegate) {
options.items = el.find(options.delegate); options.items = el.find(options.delegate);
@ -789,7 +788,7 @@ MagnificPopup.prototype = {
if(el.is('img')) { if(el.is('img')) {
el.attr('src', value); el.attr('src', value);
} else { } else {
el.replaceWith( '<img src="'+value+'" class="' + el.attr('class') + '" />' ); el.replaceWith( $('<img>').attr('src', value).attr('class', el.attr('class')) );
} }
} else { } else {
el.attr(arr[1], value); el.attr(arr[1], value);
@ -806,7 +805,6 @@ MagnificPopup.prototype = {
// thx David // thx David
if(mfp.scrollbarSize === undefined) { if(mfp.scrollbarSize === undefined) {
var scrollDiv = document.createElement("div"); var scrollDiv = document.createElement("div");
scrollDiv.id = "mfp-sbm";
scrollDiv.style.cssText = 'width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;'; scrollDiv.style.cssText = 'width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;';
document.body.appendChild(scrollDiv); document.body.appendChild(scrollDiv);
mfp.scrollbarSize = scrollDiv.offsetWidth - scrollDiv.clientWidth; mfp.scrollbarSize = scrollDiv.offsetWidth - scrollDiv.clientWidth;
@ -815,15 +813,15 @@ MagnificPopup.prototype = {
return mfp.scrollbarSize; return mfp.scrollbarSize;
} }
}; /* MagnificPopup core prototype end */ }; /* MagnificPopup core prototype end */
/** /**
* Public static functions * Public static functions
*/ */
$.magnificPopup = { $.magnificPopup = {
instance: null, instance: null,
proto: MagnificPopup.prototype, proto: MagnificPopup.prototype,
modules: [], modules: [],
@ -837,7 +835,6 @@ $.magnificPopup = {
options = $.extend(true, {}, options); options = $.extend(true, {}, options);
} }
options.isObj = true; options.isObj = true;
options.index = index || 0; options.index = index || 0;
return this.instance.open(options); return this.instance.open(options);
@ -896,18 +893,20 @@ $.magnificPopup = {
overflowY: 'auto', overflowY: 'auto',
closeMarkup: '<button title="%title%" type="button" class="mfp-close">&times;</button>', closeMarkup: '<button title="%title%" type="button" class="mfp-close">&#215;</button>',
tClose: 'Close (Esc)', tClose: 'Close (Esc)',
tLoading: 'Loading...' tLoading: 'Loading...',
autoFocusLast: true
} }
}; };
$.fn.magnificPopup = function(options) { $.fn.magnificPopup = function(options) {
_checkInstance(); _checkInstance();
var jqEl = $(this); var jqEl = $(this);
@ -954,33 +953,13 @@ $.fn.magnificPopup = function(options) {
} }
return jqEl; return jqEl;
}; };
/*>>core*/
//Quick benchmark /*>>inline*/
/*
var start = performance.now(),
i,
rounds = 1000;
for(i = 0; i < rounds; i++) { var INLINE_NS = 'inline',
}
console.log('Test #1:', performance.now() - start);
start = performance.now();
for(i = 0; i < rounds; i++) {
}
console.log('Test #2:', performance.now() - start);
*/
/*>>core*/
/*>>inline*/
var INLINE_NS = 'inline',
_hiddenClass, _hiddenClass,
_inlinePlaceholder, _inlinePlaceholder,
_lastInlineElement, _lastInlineElement,
@ -991,7 +970,7 @@ var INLINE_NS = 'inline',
} }
}; };
$.magnificPopup.registerModule(INLINE_NS, { $.magnificPopup.registerModule(INLINE_NS, {
options: { options: {
hiddenClass: 'hide', // will be appended with `mfp-` prefix hiddenClass: 'hide', // will be appended with `mfp-` prefix
markup: '', markup: '',
@ -1044,16 +1023,16 @@ $.magnificPopup.registerModule(INLINE_NS, {
return template; return template;
} }
} }
}); });
/*>>inline*/ /*>>inline*/
/*>>ajax*/ /*>>ajax*/
var AJAX_NS = 'ajax', var AJAX_NS = 'ajax',
_ajaxCur, _ajaxCur,
_removeAjaxCursor = function() { _removeAjaxCursor = function() {
if(_ajaxCur) { if(_ajaxCur) {
_body.removeClass(_ajaxCur); $(document.body).removeClass(_ajaxCur);
} }
}, },
_destroyAjaxRequest = function() { _destroyAjaxRequest = function() {
@ -1063,7 +1042,7 @@ var AJAX_NS = 'ajax',
} }
}; };
$.magnificPopup.registerModule(AJAX_NS, { $.magnificPopup.registerModule(AJAX_NS, {
options: { options: {
settings: null, settings: null,
@ -1081,8 +1060,9 @@ $.magnificPopup.registerModule(AJAX_NS, {
}, },
getAjax: function(item) { getAjax: function(item) {
if(_ajaxCur) if(_ajaxCur) {
_body.addClass(_ajaxCur); $(document.body).addClass(_ajaxCur);
}
mfp.updateStatus('loading'); mfp.updateStatus('loading');
@ -1124,18 +1104,12 @@ $.magnificPopup.registerModule(AJAX_NS, {
return ''; return '';
} }
} }
}); });
/*>>ajax*/
/*>>image*/
var _imgInterval,
/*>>ajax*/
/*>>image*/
var _imgInterval,
_getTitle = function(item) { _getTitle = function(item) {
if(item.data && item.data.title !== undefined) if(item.data && item.data.title !== undefined)
return item.data.title; return item.data.title;
@ -1152,7 +1126,7 @@ var _imgInterval,
return ''; return '';
}; };
$.magnificPopup.registerModule('image', { $.magnificPopup.registerModule('image', {
options: { options: {
markup: '<div class="mfp-figure">'+ markup: '<div class="mfp-figure">'+
@ -1182,13 +1156,13 @@ $.magnificPopup.registerModule('image', {
_mfpOn(OPEN_EVENT+ns, function() { _mfpOn(OPEN_EVENT+ns, function() {
if(mfp.currItem.type === 'image' && imgSt.cursor) { if(mfp.currItem.type === 'image' && imgSt.cursor) {
_body.addClass(imgSt.cursor); $(document.body).addClass(imgSt.cursor);
} }
}); });
_mfpOn(CLOSE_EVENT+ns, function() { _mfpOn(CLOSE_EVENT+ns, function() {
if(imgSt.cursor) { if(imgSt.cursor) {
_body.removeClass(imgSt.cursor); $(document.body).removeClass(imgSt.cursor);
} }
_window.off('resize' + EVENT_NS); _window.off('resize' + EVENT_NS);
}); });
@ -1326,6 +1300,9 @@ $.magnificPopup.registerModule('image', {
if(el.length) { if(el.length) {
var img = document.createElement('img'); var img = document.createElement('img');
img.className = 'mfp-img'; img.className = 'mfp-img';
if(item.el && item.el.find('img').length) {
img.alt = item.el.find('img').attr('alt');
}
item.img = $(img).on('load.mfploader', onLoadComplete).on('error.mfploader', onLoadError); item.img = $(img).on('load.mfploader', onLoadComplete).on('error.mfploader', onLoadError);
img.src = item.src; img.src = item.src;
@ -1375,14 +1352,12 @@ $.magnificPopup.registerModule('image', {
return template; return template;
} }
} }
}); });
/*>>image*/
/*>>zoom*/
/*>>image*/ var hasMozTransform,
/*>>zoom*/
var hasMozTransform,
getHasMozTransform = function() { getHasMozTransform = function() {
if(hasMozTransform === undefined) { if(hasMozTransform === undefined) {
hasMozTransform = document.createElement('p').style.MozTransform !== undefined; hasMozTransform = document.createElement('p').style.MozTransform !== undefined;
@ -1390,7 +1365,7 @@ var hasMozTransform,
return hasMozTransform; return hasMozTransform;
}; };
$.magnificPopup.registerModule('zoom', { $.magnificPopup.registerModule('zoom', {
options: { options: {
enabled: false, enabled: false,
@ -1492,7 +1467,6 @@ $.magnificPopup.registerModule('zoom', {
animatedImg = getElToAnimate(image); animatedImg = getElToAnimate(image);
} }
animatedImg.css( mfp._getOffset(true) ); animatedImg.css( mfp._getOffset(true) );
mfp.wrap.append(animatedImg); mfp.wrap.append(animatedImg);
mfp.content.css('visibility', 'hidden'); mfp.content.css('visibility', 'hidden');
@ -1564,15 +1538,15 @@ $.magnificPopup.registerModule('zoom', {
} }
} }
}); });
/*>>zoom*/ /*>>zoom*/
/*>>iframe*/ /*>>iframe*/
var IFRAME_NS = 'iframe', var IFRAME_NS = 'iframe',
_emptyPage = '//about:blank', _emptyPage = '//about:blank',
_fixIframeBugs = function(isShowing) { _fixIframeBugs = function(isShowing) {
@ -1592,7 +1566,7 @@ var IFRAME_NS = 'iframe',
} }
}; };
$.magnificPopup.registerModule(IFRAME_NS, { $.magnificPopup.registerModule(IFRAME_NS, {
options: { options: {
markup: '<div class="mfp-iframe-scaler">'+ markup: '<div class="mfp-iframe-scaler">'+
@ -1671,17 +1645,17 @@ $.magnificPopup.registerModule(IFRAME_NS, {
return template; return template;
} }
} }
}); });
/*>>iframe*/ /*>>iframe*/
/*>>gallery*/ /*>>gallery*/
/** /**
* Get looped index depending on number of slides * Get looped index depending on number of slides
*/ */
var _getLoopedId = function(index) { var _getLoopedId = function(index) {
var numSlides = mfp.items.length; var numSlides = mfp.items.length;
if(index > numSlides - 1) { if(index > numSlides - 1) {
return index - numSlides; return index - numSlides;
@ -1694,7 +1668,7 @@ var _getLoopedId = function(index) {
return text.replace(/%curr%/gi, curr + 1).replace(/%total%/gi, total); return text.replace(/%curr%/gi, curr + 1).replace(/%total%/gi, total);
}; };
$.magnificPopup.registerModule('gallery', { $.magnificPopup.registerModule('gallery', {
options: { options: {
enabled: false, enabled: false,
@ -1712,8 +1686,7 @@ $.magnificPopup.registerModule('gallery', {
initGallery: function() { initGallery: function() {
var gSt = mfp.st.gallery, var gSt = mfp.st.gallery,
ns = '.mfp-gallery', ns = '.mfp-gallery';
supportsFastClick = Boolean($.fn.mfpFastClick);
mfp.direction = true; // true - next, false - prev mfp.direction = true; // true - next, false - prev
@ -1758,22 +1731,13 @@ $.magnificPopup.registerModule('gallery', {
arrowLeft = mfp.arrowLeft = $( markup.replace(/%title%/gi, gSt.tPrev).replace(/%dir%/gi, 'left') ).addClass(PREVENT_CLOSE_CLASS), arrowLeft = mfp.arrowLeft = $( markup.replace(/%title%/gi, gSt.tPrev).replace(/%dir%/gi, 'left') ).addClass(PREVENT_CLOSE_CLASS),
arrowRight = mfp.arrowRight = $( markup.replace(/%title%/gi, gSt.tNext).replace(/%dir%/gi, 'right') ).addClass(PREVENT_CLOSE_CLASS); arrowRight = mfp.arrowRight = $( markup.replace(/%title%/gi, gSt.tNext).replace(/%dir%/gi, 'right') ).addClass(PREVENT_CLOSE_CLASS);
var eName = supportsFastClick ? 'mfpFastClick' : 'click'; arrowLeft.click(function() {
arrowLeft[eName](function() {
mfp.prev(); mfp.prev();
}); });
arrowRight[eName](function() { arrowRight.click(function() {
mfp.next(); mfp.next();
}); });
// Polyfill for :before and :after (adds elements with classes mfp-a and mfp-b)
if(mfp.isIE7) {
_getEl('b', arrowLeft[0], false, true);
_getEl('a', arrowLeft[0], false, true);
_getEl('b', arrowRight[0], false, true);
_getEl('a', arrowRight[0], false, true);
}
mfp.container.append(arrowLeft.add(arrowRight)); mfp.container.append(arrowLeft.add(arrowRight));
} }
}); });
@ -1791,10 +1755,6 @@ $.magnificPopup.registerModule('gallery', {
_mfpOn(CLOSE_EVENT+ns, function() { _mfpOn(CLOSE_EVENT+ns, function() {
_document.off(ns); _document.off(ns);
mfp.wrap.off('click'+ns); mfp.wrap.off('click'+ns);
if(mfp.arrowLeft && supportsFastClick) {
mfp.arrowLeft.add(mfp.arrowRight).destroyMfpFastClick();
}
mfp.arrowRight = mfp.arrowLeft = null; mfp.arrowRight = mfp.arrowLeft = null;
}); });
@ -1855,67 +1815,15 @@ $.magnificPopup.registerModule('gallery', {
item.preloaded = true; item.preloaded = true;
} }
} }
});
/*
Touch Support that might be implemented some day
addSwipeGesture: function() {
var startX,
moved,
multipleTouches;
return;
var namespace = '.mfp',
addEventNames = function(pref, down, move, up, cancel) {
mfp._tStart = pref + down + namespace;
mfp._tMove = pref + move + namespace;
mfp._tEnd = pref + up + namespace;
mfp._tCancel = pref + cancel + namespace;
};
if(window.navigator.msPointerEnabled) {
addEventNames('MSPointer', 'Down', 'Move', 'Up', 'Cancel');
} else if('ontouchstart' in window) {
addEventNames('touch', 'start', 'move', 'end', 'cancel');
} else {
return;
}
_window.on(mfp._tStart, function(e) {
var oE = e.originalEvent;
multipleTouches = moved = false;
startX = oE.pageX || oE.changedTouches[0].pageX;
}).on(mfp._tMove, function(e) {
if(e.originalEvent.touches.length > 1) {
multipleTouches = e.originalEvent.touches.length;
} else {
//e.preventDefault();
moved = true;
}
}).on(mfp._tEnd + ' ' + mfp._tCancel, function(e) {
if(moved && !multipleTouches) {
var oE = e.originalEvent,
diff = startX - (oE.pageX || oE.changedTouches[0].pageX);
if(diff > 20) {
mfp.next();
} else if(diff < -20) {
mfp.prev();
}
}
}); });
},
*/
/*>>gallery*/
/*>>gallery*/ /*>>retina*/
/*>>retina*/ var RETINA_NS = 'retina';
var RETINA_NS = 'retina'; $.magnificPopup.registerModule(RETINA_NS, {
$.magnificPopup.registerModule(RETINA_NS, {
options: { options: {
replaceSrc: function(item) { replaceSrc: function(item) {
return item.src.replace(/\.\w+$/, function(m) { return '@2x' + m; }); return item.src.replace(/\.\w+$/, function(m) { return '@2x' + m; });
@ -1946,104 +1854,7 @@ $.magnificPopup.registerModule(RETINA_NS, {
} }
} }
});
/*>>retina*/
/*>>fastclick*/
/**
* FastClick event implementation. (removes 300ms delay on touch devices)
* Based on https://developers.google.com/mobile/articles/fast_buttons
*
* You may use it outside the Magnific Popup by calling just:
*
* $('.your-el').mfpFastClick(function() {
* console.log('Clicked!');
* });
*
* To unbind:
* $('.your-el').destroyMfpFastClick();
*
*
* Note that it's a very basic and simple implementation, it blocks ghost click on the same element where it was bound.
* If you need something more advanced, use plugin by FT Labs https://github.com/ftlabs/fastclick
*
*/
(function() {
var ghostClickDelay = 1000,
supportsTouch = 'ontouchstart' in window,
unbindTouchMove = function() {
_window.off('touchmove'+ns+' touchend'+ns);
},
eName = 'mfpFastClick',
ns = '.'+eName;
// As Zepto.js doesn't have an easy way to add custom events (like jQuery), so we implement it in this way
$.fn.mfpFastClick = function(callback) {
return $(this).each(function() {
var elem = $(this),
lock;
if( supportsTouch ) {
var timeout,
startX,
startY,
pointerMoved,
point,
numPointers;
elem.on('touchstart' + ns, function(e) {
pointerMoved = false;
numPointers = 1;
point = e.originalEvent ? e.originalEvent.touches[0] : e.touches[0];
startX = point.clientX;
startY = point.clientY;
_window.on('touchmove'+ns, function(e) {
point = e.originalEvent ? e.originalEvent.touches : e.touches;
numPointers = point.length;
point = point[0];
if (Math.abs(point.clientX - startX) > 10 ||
Math.abs(point.clientY - startY) > 10) {
pointerMoved = true;
unbindTouchMove();
}
}).on('touchend'+ns, function(e) {
unbindTouchMove();
if(pointerMoved || numPointers > 1) {
return;
}
lock = true;
e.preventDefault();
clearTimeout(timeout);
timeout = setTimeout(function() {
lock = false;
}, ghostClickDelay);
callback();
});
}); });
} /*>>retina*/
_checkInstance(); }));
elem.on('click' + ns, function() {
if(!lock) {
callback();
}
});
});
};
$.fn.destroyMfpFastClick = function() {
$(this).off('touchstart' + ns + ' click' + ns);
if(supportsTouch) _window.off('touchmove'+ns+' touchend'+ns);
};
})();
/*>>fastclick*/
_checkInstance(); })(window.jQuery || window.Zepto);