app/assets/javascripts/magnific-popup.js in magnific-popup-rails-1.0.1 vs app/assets/javascripts/magnific-popup.js in magnific-popup-rails-1.1.0

- old
+ new

@@ -1,8 +1,8 @@ -/*! Magnific Popup - v1.0.1 - 2015-12-30 +/*! Magnific Popup - v1.1.0 - 2016-02-20 * http://dimsemenov.com/plugins/magnific-popup/ -* Copyright (c) 2015 Dmitry Semenov; */ +* Copyright (c) 2016 Dmitry Semenov; */ ;(function (factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. define(['jquery'], factory); } else if (typeof exports === 'object') { @@ -134,13 +134,11 @@ * Initializes Magnific Popup plugin. * This function is triggered only once when $.fn.magnificPopup or $.magnificPopup is executed */ init: function() { var appVersion = navigator.appVersion; - mfp.isIE7 = appVersion.indexOf("MSIE 7.") !== -1; - mfp.isIE8 = appVersion.indexOf("MSIE 8.") !== -1; - mfp.isLowIE = mfp.isIE7 || mfp.isIE8; + mfp.isLowIE = mfp.isIE8 = document.all && !document.addEventListener; mfp.isAndroid = (/android/gi).test(appVersion); mfp.isIOS = (/iphone|ipad|ipod/gi).test(appVersion); mfp.supportsTransition = supportsTransitions(); // We disable fixed positioned lightbox on devices that don't handle it nicely. @@ -491,22 +489,18 @@ if(!item.parsed) { item = mfp.parseEl( mfp.index ); } - var type = item.type; + var type = item.type; _mfpTrigger('BeforeChange', [mfp.currItem ? mfp.currItem.type : '', type]); // BeforeChange event works like so: // _mfpOn('BeforeChange', function(e, prevType, newType) { }); - + mfp.currItem = item; - - - - if(!mfp.currTemplate[type]) { var markup = mfp.st[type] ? mfp.st[type].markup : false; // allows to modify markup _mfpTrigger('FirstMarkupParse', markup); @@ -520,19 +514,19 @@ } if(_prevContentType && _prevContentType !== item.type) { mfp.container.removeClass('mfp-'+_prevContentType+'-holder'); } - + var newContent = mfp['get' + type.charAt(0).toUpperCase() + type.slice(1)](item, mfp.currTemplate[type]); mfp.appendContent(newContent, type); item.preloaded = true; _mfpTrigger(CHANGE_EVENT, item); _prevContentType = item.type; - + // Append container back after its content changed mfp.container.prepend(mfp.contentContainer); _mfpTrigger('AfterChange'); }, @@ -541,11 +535,11 @@ /** * Set HTML content of popup */ appendContent: function(newContent, type) { mfp.content = newContent; - + if(newContent) { if(mfp.st.showCloseBtn && mfp.st.closeBtnInside && mfp.currTemplate[type] === true) { // if there is no markup, we just append close button element inside if(!mfp.content.find('.mfp-close').length) { @@ -563,12 +557,10 @@ mfp.contentContainer.append(mfp.content); }, - - /** * Creates Magnific Popup data object based on given data * @param {int} index Index of item to parse */ parseEl: function(index) { @@ -618,15 +610,15 @@ mfp._openClick(e, el, options); }; if(!options) { options = {}; - } + } var eName = 'click.magnificPopup'; options.mainEl = el; - + if(options.items) { options.isObj = true; el.off(eName).on(eName, eHandler); } else { options.isObj = false; @@ -657,20 +649,19 @@ if( _window.width() < disableOn ) { return true; } } } - + if(e.type) { e.preventDefault(); // This will prevent popup from closing if element is inside and popup is already opened if(mfp.isOpen) { e.stopPropagation(); } } - options.el = $(e.mfpEl); if(options.delegate) { options.items = el.find(options.delegate); } @@ -795,11 +786,11 @@ } } else if(attr === 'img') { if(el.is('img')) { el.attr('src', value); } else { - el.replaceWith( '<img src="'+value+'" class="' + el.attr('class') + '" />' ); + el.replaceWith( $('<img>').attr('src', value).attr('class', el.attr('class')) ); } } else { el.attr(arr[1], value); } } @@ -834,18 +825,17 @@ instance: null, proto: MagnificPopup.prototype, modules: [], open: function(options, index) { - _checkInstance(); + _checkInstance(); if(!options) { options = {}; } else { options = $.extend(true, {}, options); } - options.isObj = true; options.index = index || 0; return this.instance.open(options); }, @@ -856,51 +846,51 @@ registerModule: function(name, module) { if(module.options) { $.magnificPopup.defaults[name] = module.options; } - $.extend(this.proto, module.proto); + $.extend(this.proto, module.proto); this.modules.push(name); }, - defaults: { + defaults: { // Info about options is in docs: // http://dimsemenov.com/plugins/magnific-popup/documentation.html#options - - disableOn: 0, + disableOn: 0, + key: null, midClick: false, mainClass: '', preloader: true, focus: '', // CSS selector of input to focus after popup is opened - + closeOnContentClick: false, closeOnBgClick: true, - closeBtnInside: true, + closeBtnInside: true, showCloseBtn: true, enableEscapeKey: true, modal: false, alignTop: false, - + removalDelay: 0, prependTo: null, - - fixedContentPos: 'auto', - + + fixedContentPos: 'auto', + fixedBgPos: 'auto', overflowY: 'auto', closeMarkup: '<button title="%title%" type="button" class="mfp-close">&#215;</button>', @@ -945,13 +935,13 @@ } } else { // clone options obj options = $.extend(true, {}, options); - + /* - * As Zepto doesn't support .data() method for objects + * As Zepto doesn't support .data() method for objects * and it works only in normal browsers * we assign "options" object directly to the DOM element. FTW! */ if(_isJQ) { jqEl.data('magnificPopup', options); @@ -963,37 +953,17 @@ } return jqEl; }; - -//Quick benchmark -/* -var start = performance.now(), - i, - rounds = 1000; - -for(i = 0; i < rounds; i++) { - -} -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, - _inlinePlaceholder, + _inlinePlaceholder, _lastInlineElement, _putInlineElementsBack = function() { if(_lastInlineElement) { _inlinePlaceholder.after( _lastInlineElement.addClass(_hiddenClass) ).detach(); _lastInlineElement = null; @@ -1134,22 +1104,16 @@ return ''; } } }); - - - - - - /*>>ajax*/ /*>>image*/ var _imgInterval, _getTitle = function(item) { - if(item.data && item.data.title !== undefined) + if(item.data && item.data.title !== undefined) return item.data.title; var src = mfp.st.image.titleSrc; if(src) { @@ -1176,11 +1140,11 @@ '</div>'+ '</figcaption>'+ '</figure>'+ '</div>', cursor: 'mfp-zoom-out-cur', - titleSrc: 'title', + titleSrc: 'title', verticalFit: true, tError: '<a href="%url%">The image</a> could not be loaded.' }, proto: { @@ -1221,25 +1185,25 @@ item.img.css('max-height', mfp.wH-decr); } }, _onImageHasSize: function(item) { if(item.img) { - + item.hasSize = true; if(_imgInterval) { clearInterval(_imgInterval); } - + item.isCheckingImgSize = false; _mfpTrigger('ImageHasSize', item); if(item.imgHidden) { if(mfp.content) mfp.content.removeClass('mfp-loading'); - + item.imgHidden = false; } } }, @@ -1288,22 +1252,22 @@ // image load complete handler onLoadComplete = function() { if(item) { if (item.img[0].complete) { item.img.off('.mfploader'); - + if(item === mfp.currItem){ mfp._onImageHasSize(item); mfp.updateStatus('ready'); } item.hasSize = true; item.loaded = true; _mfpTrigger('ImageLoadComplete'); - + } else { // if image complete check fails 200 times (20 sec), we assume that there was an error. guard++; if(guard < 200) { @@ -1349,11 +1313,11 @@ } img = item.img[0]; if(img.naturalWidth > 0) { item.hasSize = true; - } else if(!img.width) { + } else if(!img.width) { item.hasSize = false; } } mfp._parseMarkup(template, { @@ -1381,28 +1345,26 @@ if(!item.hasSize) { item.imgHidden = true; template.addClass('mfp-loading'); mfp.findImageSize(item); - } + } return template; } } }); - - /*>>image*/ /*>>zoom*/ var hasMozTransform, getHasMozTransform = function() { if(hasMozTransform === undefined) { hasMozTransform = document.createElement('p').style.MozTransform !== undefined; } - return hasMozTransform; + return hasMozTransform; }; $.magnificPopup.registerModule('zoom', { options: { @@ -1418,11 +1380,11 @@ initZoom: function() { var zoomSt = mfp.st.zoom, ns = '.zoom', image; - + if(!zoomSt.enabled || !mfp.supportsTransition) { return; } var duration = zoomSt.duration, @@ -1454,20 +1416,20 @@ clearTimeout(openTimeout); mfp.content.css('visibility', 'hidden'); // Basically, all code below does is clones existing image, puts in on top of the current one and animated it - + image = mfp._getItemToZoom(); if(!image) { showMainContent(); return; } - animatedImg = getElToAnimate(image); - + animatedImg = getElToAnimate(image); + animatedImg.css( mfp._getOffset() ); mfp.wrap.append(animatedImg); openTimeout = setTimeout(function() { @@ -1478,11 +1440,11 @@ setTimeout(function() { animatedImg.remove(); image = animatedImg = null; _mfpTrigger('ZoomAnimationEnded'); - }, 16); // avoid blink when switching images + }, 16); // avoid blink when switching images }, duration); // this timeout equals animation duration }, 16); // by adding this timeout we avoid short glitch at the beginning of animation @@ -1502,16 +1464,15 @@ if(!image) { return; } animatedImg = getElToAnimate(image); } - - + animatedImg.css( mfp._getOffset(true) ); mfp.wrap.append(animatedImg); mfp.content.css('visibility', 'hidden'); - + setTimeout(function() { animatedImg.css( mfp._getOffset() ); }, 16); } @@ -1522,11 +1483,11 @@ showMainContent(); if(animatedImg) { animatedImg.remove(); } image = null; - } + } }); }, _allowZoom: function() { return mfp.currItem.type === 'image'; @@ -1554,11 +1515,11 @@ var paddingBottom = parseInt(el.css('padding-bottom'),10); offset.top -= ( $(window).scrollTop() - paddingTop ); /* - + Animating left + top + width/height looks glitchy in Firefox, but perfect in Chrome. And vice-versa. */ var obj = { width: el.width(), @@ -1585,15 +1546,15 @@ /*>>iframe*/ var IFRAME_NS = 'iframe', _emptyPage = '//about:blank', - + _fixIframeBugs = function(isShowing) { if(mfp.currTemplate[IFRAME_NS]) { var el = mfp.currTemplate[IFRAME_NS].find('iframe'); - if(el.length) { + if(el.length) { // reset src after the popup is closed to avoid "video keeps playing after popup is closed" bug if(!isShowing) { el[0].src = _emptyPage; } @@ -1616,12 +1577,12 @@ srcAction: 'iframe_src', // we don't care and support only one default type of URL by default patterns: { youtube: { - index: 'youtube.com', - id: 'v=', + index: 'youtube.com', + id: 'v=', src: '//www.youtube.com/embed/%id%?autoplay=1' }, vimeo: { index: 'vimeo.com/', id: '/', @@ -1642,11 +1603,11 @@ if(prevType !== newType) { if(prevType === IFRAME_NS) { _fixIframeBugs(); // iframe if removed } else if(newType === IFRAME_NS) { _fixIframeBugs(true); // iframe is showing - } + } }// else { // iframe source is switched, don't do anything //} }); @@ -1656,11 +1617,11 @@ }, getIframe: function(item, template) { var embedSrc = item.src; var iframeSt = mfp.st.iframe; - + $.each(iframeSt.patterns, function() { if(embedSrc.indexOf( this.index ) > -1) { if(this.id) { if(typeof this.id === 'string') { embedSrc = embedSrc.substr(embedSrc.lastIndexOf(this.id)+this.id.length, embedSrc.length); @@ -1670,11 +1631,11 @@ } embedSrc = this.src.replace('%id%', embedSrc ); return false; // break; } }); - + var dataObj = {}; if(iframeSt.srcAction) { dataObj[iframeSt.srcAction] = embedSrc; } mfp._parseMarkup(template, dataObj, item); @@ -1723,15 +1684,14 @@ proto: { initGallery: function() { var gSt = mfp.st.gallery, - ns = '.mfp-gallery', - supportsFastClick = Boolean($.fn.mfpFastClick); + ns = '.mfp-gallery'; mfp.direction = true; // true - next, false - prev - + if(!gSt || !gSt.enabled ) return false; _wrapClasses += ' mfp-gallery'; _mfpOn(OPEN_EVENT+ns, function() { @@ -1766,54 +1726,41 @@ }); _mfpOn('BuildControls' + ns, function() { if(mfp.items.length > 1 && gSt.arrows && !mfp.arrowLeft) { var markup = gSt.arrowMarkup, - 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); - var eName = supportsFastClick ? 'mfpFastClick' : 'click'; - arrowLeft[eName](function() { + arrowLeft.click(function() { mfp.prev(); - }); - arrowRight[eName](function() { + }); + arrowRight.click(function() { 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)); } }); _mfpOn(CHANGE_EVENT+ns, function() { if(mfp._preloadTimeout) clearTimeout(mfp._preloadTimeout); mfp._preloadTimeout = setTimeout(function() { mfp.preloadNearbyImages(); mfp._preloadTimeout = null; - }, 16); + }, 16); }); _mfpOn(CLOSE_EVENT+ns, function() { _document.off(ns); mfp.wrap.off('click'+ns); - - if(mfp.arrowLeft && supportsFastClick) { - mfp.arrowLeft.add(mfp.arrowRight).destroyMfpFastClick(); - } mfp.arrowRight = mfp.arrowLeft = null; }); - }, + }, next: function() { mfp.direction = true; mfp.index = _getLoopedId(mfp.index + 1); mfp.updateItemHTML(); }, @@ -1868,62 +1815,10 @@ 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*/ /*>>retina*/ var RETINA_NS = 'retina'; @@ -1960,103 +1855,6 @@ } } }); /*>>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(); - }); - }); - - } - - 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(); })); \ No newline at end of file