');
}
item.inlineElement = el;
return el;
}
nd.updateStatus('ready');
nd._parseMarkup(template, {}, item);
return template;
}
}
});
/*>>inline*/
/*>>ajax*/
var AJAX_NS = 'ajax',
_ajaxCur,
_removeAjaxCursor = function() {
if(_ajaxCur) {
_body.removeClass(_ajaxCur);
}
},
_destroyAjaxRequest = function() {
_removeAjaxCursor();
if(nd.req) {
nd.req.abort();
}
};
$.magnificPopup.registerModule(AJAX_NS, {
options: {
settings: null,
cursor: 'nd-ajax-cur',
tError: '
The content could not be loaded.'
},
proto: {
initAjax: function() {
nd.types.push(AJAX_NS);
_ajaxCur = nd.st.ajax.cursor;
_ndOn(CLOSE_EVENT+'.'+AJAX_NS, _destroyAjaxRequest);
_ndOn('BeforeChange.' + AJAX_NS, _destroyAjaxRequest);
},
getAjax: function(item) {
if(_ajaxCur)
_body.addClass(_ajaxCur);
nd.updateStatus('loading');
var opts = $.extend({
url: item.src,
success: function(data, textStatus, jqXHR) {
var temp = {
data:data,
xhr:jqXHR
};
_ndTrigger('ParseAjax', temp);
nd.appendContent( $(temp.data), AJAX_NS );
item.finished = true;
_removeAjaxCursor();
nd._setFocus();
setTimeout(function() {
nd.wrap.addClass(READY_CLASS);
}, 16);
nd.updateStatus('ready');
_ndTrigger('AjaxContentAdded');
},
error: function() {
_removeAjaxCursor();
item.finished = item.loadError = true;
nd.updateStatus('error', nd.st.ajax.tError.replace('%url%', item.src));
}
}, nd.st.ajax.settings);
nd.req = $.ajax(opts);
return '';
}
}
});
/*>>ajax*/
/*>>image*/
var _imgInterval,
_getTitle = function(item) {
if(item.data && item.data.title !== undefined)
return item.data.title;
var src = nd.st.image.titleSrc;
if(src) {
if($.isFunction(src)) {
return src.call(nd, item);
} else if(item.el) {
return item.el.attr(src) || '';
}
}
return '';
};
$.magnificPopup.registerModule('image', {
options: {
markup: '
',
cursor: 'nd-zoom-out-cur',
titleSrc: 'title',
verticalFit: true,
tError: '
The image could not be loaded.'
},
proto: {
initImage: function() {
var imgSt = nd.st.image,
ns = '.image';
nd.types.push('image');
_ndOn(OPEN_EVENT+ns, function() {
if(nd.currItem.type === 'image' && imgSt.cursor) {
_body.addClass(imgSt.cursor);
}
});
_ndOn(CLOSE_EVENT+ns, function() {
if(imgSt.cursor) {
_body.removeClass(imgSt.cursor);
}
_window.off('resize' + EVENT_NS);
});
_ndOn('Resize'+ns, nd.resizeImage);
if(nd.isLowIE) {
_ndOn('AfterChange', nd.resizeImage);
}
},
resizeImage: function() {
var item = nd.currItem;
if(!item || !item.img) return;
if(nd.st.image.verticalFit) {
var decr = 0;
// fix box-sizing in ie7/8
if(nd.isLowIE) {
decr = parseInt(item.img.css('padding-top'), 10) + parseInt(item.img.css('padding-bottom'),10);
}
item.img.css('max-height', nd.wH-decr);
}
},
_onImageHasSize: function(item) {
if(item.img) {
item.hasSize = true;
if(_imgInterval) {
clearInterval(_imgInterval);
}
item.isCheckingImgSize = false;
_ndTrigger('ImageHasSize', item);
if(item.imgHidden) {
if(nd.content)
nd.content.removeClass('nd-loading');
item.imgHidden = false;
}
}
},
/**
* Function that loops until the image has size to display elements that rely on it asap
*/
findImageSize: function(item) {
var counter = 0,
img = item.img[0],
ndSetInterval = function(delay) {
if(_imgInterval) {
clearInterval(_imgInterval);
}
// decelerating interval that checks for size of an image
_imgInterval = setInterval(function() {
if(img.naturalWidth > 0) {
nd._onImageHasSize(item);
return;
}
if(counter > 200) {
clearInterval(_imgInterval);
}
counter++;
if(counter === 3) {
ndSetInterval(10);
} else if(counter === 40) {
ndSetInterval(50);
} else if(counter === 100) {
ndSetInterval(500);
}
}, delay);
};
ndSetInterval(1);
},
getImage: function(item, template) {
var guard = 0,
// image load complete handler
onLoadComplete = function() {
if(item) {
if (item.img[0].complete) {
item.img.off('.ndloader');
if(item === nd.currItem){
nd._onImageHasSize(item);
nd.updateStatus('ready');
}
item.hasSize = true;
item.loaded = true;
_ndTrigger('ImageLoadComplete');
}
else {
// if image complete check fails 200 times (20 sec), we assume that there was an error.
guard++;
if(guard < 200) {
setTimeout(onLoadComplete,100);
} else {
onLoadError();
}
}
}
},
// image error handler
onLoadError = function() {
if(item) {
item.img.off('.ndloader');
if(item === nd.currItem){
nd._onImageHasSize(item);
nd.updateStatus('error', imgSt.tError.replace('%url%', item.src) );
}
item.hasSize = true;
item.loaded = true;
item.loadError = true;
}
},
imgSt = nd.st.image;
var el = template.find('.nd-img');
if(el.length) {
var img = document.createElement('img');
img.className = 'nd-img';
item.img = $(img).on('load.ndloader', onLoadComplete).on('error.ndloader', onLoadError);
img.src = item.src;
// without clone() "error" event is not firing when IMG is replaced by new IMG
// TODO: find a way to avoid such cloning
if(el.is('img')) {
item.img = item.img.clone();
}
if(item.img[0].naturalWidth > 0) {
item.hasSize = true;
}
}
nd._parseMarkup(template, {
title: _getTitle(item),
img_replaceWith: item.img
}, item);
nd.resizeImage();
if(item.hasSize) {
if(_imgInterval) clearInterval(_imgInterval);
if(item.loadError) {
template.addClass('nd-loading');
nd.updateStatus('error', imgSt.tError.replace('%url%', item.src) );
} else {
template.removeClass('nd-loading');
nd.updateStatus('ready');
}
return template;
}
nd.updateStatus('loading');
item.loading = true;
if(!item.hasSize) {
item.imgHidden = true;
template.addClass('nd-loading');
nd.findImageSize(item);
}
return template;
}
}
});
/*>>image*/
/*>>zoom*/
var hasMozTransform,
getHasMozTransform = function() {
if(hasMozTransform === undefined) {
hasMozTransform = document.createElement('p').style.MozTransform !== undefined;
}
return hasMozTransform;
};
$.magnificPopup.registerModule('zoom', {
options: {
enabled: false,
easing: 'ease-in-out',
duration: 300,
opener: function(element) {
return element.is('img') ? element : element.find('img');
}
},
proto: {
initZoom: function() {
var zoomSt = nd.st.zoom,
ns = '.zoom',
image;
if(!zoomSt.enabled || !nd.supportsTransition) {
return;
}
var duration = zoomSt.duration,
getElToAnimate = function(image) {
var newImg = image.clone().removeAttr('style').removeAttr('class').addClass('nd-animated-image'),
transition = 'all '+(zoomSt.duration/1000)+'s ' + zoomSt.easing,
cssObj = {
position: 'fixed',
zIndex: 9999,
left: 0,
top: 0,
'-webkit-backface-visibility': 'hidden'
},
t = 'transition';
cssObj['-webkit-'+t] = cssObj['-moz-'+t] = cssObj['-o-'+t] = cssObj[t] = transition;
newImg.css(cssObj);
return newImg;
},
showMainContent = function() {
nd.content.css('visibility', 'visible');
},
openTimeout,
animatedImg;
_ndOn('BuildControls'+ns, function() {
if(nd._allowZoom()) {
clearTimeout(openTimeout);
nd.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 = nd._getItemToZoom();
if(!image) {
showMainContent();
return;
}
animatedImg = getElToAnimate(image);
animatedImg.css( nd._getOffset() );
nd.wrap.append(animatedImg);
openTimeout = setTimeout(function() {
animatedImg.css( nd._getOffset( true ) );
openTimeout = setTimeout(function() {
showMainContent();
setTimeout(function() {
animatedImg.remove();
image = animatedImg = null;
_ndTrigger('ZoomAnimationEnded');
}, 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
// Lots of timeouts...
}
});
_ndOn(BEFORE_CLOSE_EVENT+ns, function() {
if(nd._allowZoom()) {
clearTimeout(openTimeout);
nd.st.removalDelay = duration;
if(!image) {
image = nd._getItemToZoom();
if(!image) {
return;
}
animatedImg = getElToAnimate(image);
}
animatedImg.css( nd._getOffset(true) );
nd.wrap.append(animatedImg);
nd.content.css('visibility', 'hidden');
setTimeout(function() {
animatedImg.css( nd._getOffset() );
}, 16);
}
});
_ndOn(CLOSE_EVENT+ns, function() {
if(nd._allowZoom()) {
showMainContent();
if(animatedImg) {
animatedImg.remove();
}
image = null;
}
});
},
_allowZoom: function() {
return nd.currItem.type === 'image';
},
_getItemToZoom: function() {
if(nd.currItem.hasSize) {
return nd.currItem.img;
} else {
return false;
}
},
// Get element postion relative to viewport
_getOffset: function(isLarge) {
var el;
if(isLarge) {
el = nd.currItem.img;
} else {
el = nd.st.zoom.opener(nd.currItem.el || nd.currItem);
}
var offset = el.offset();
var paddingTop = parseInt(el.css('padding-top'),10);
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(),
// fix Zepto height+padding issue
height: (_isJQ ? el.innerHeight() : el[0].offsetHeight) - paddingBottom - paddingTop
};
// I hate to do this, but there is no another option
if( getHasMozTransform() ) {
obj['-moz-transform'] = obj['transform'] = 'translate(' + offset.left + 'px,' + offset.top + 'px)';
} else {
obj.left = offset.left;
obj.top = offset.top;
}
return obj;
}
}
});
/*>>zoom*/
/*>>iframe*/
var IFRAME_NS = 'iframe',
_emptyPage = '//about:blank',
_fixIframeBugs = function(isShowing) {
if(nd.currTemplate[IFRAME_NS]) {
var el = nd.currTemplate[IFRAME_NS].find('iframe');
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;
}
// IE8 black screen bug fix
if(nd.isIE8) {
el.css('display', isShowing ? 'block' : 'none');
}
}
}
};
$.magnificPopup.registerModule(IFRAME_NS, {
options: {
markup: '
',
srcAction: 'iframe_src',
// we don't care and support only one default type of URL by default
patterns: {
youtube: {
index: 'youtube.com',
id: 'v=',
src: '//www.youtube.com/embed/%id%?autoplay=1'
},
vimeo: {
index: 'vimeo.com/',
id: '/',
src: '//player.vimeo.com/video/%id%?autoplay=1'
},
gmaps: {
index: '//maps.google.',
src: '%id%&output=embed'
}
}
},
proto: {
initIframe: function() {
nd.types.push(IFRAME_NS);
_ndOn('BeforeChange', function(e, prevType, newType) {
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
//}
});
_ndOn(CLOSE_EVENT + '.' + IFRAME_NS, function() {
_fixIframeBugs();
});
},
getIframe: function(item, template) {
var embedSrc = item.src;
var iframeSt = nd.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);
} else {
embedSrc = this.id.call( this, embedSrc );
}
}
embedSrc = this.src.replace('%id%', embedSrc );
return false; // break;
}
});
var dataObj = {};
if(iframeSt.srcAction) {
dataObj[iframeSt.srcAction] = embedSrc;
}
nd._parseMarkup(template, dataObj, item);
nd.updateStatus('ready');
return template;
}
}
});
/*>>iframe*/
/*>>gallery*/
/**
* Get looped index depending on number of slides
*/
var _getLoopedId = function(index) {
var numSlides = nd.items.length;
if(index > numSlides - 1) {
return index - numSlides;
} else if(index < 0) {
return numSlides + index;
}
return index;
},
_replaceCurrTotal = function(text, curr, total) {
return text.replace(/%curr%/gi, curr + 1).replace(/%total%/gi, total);
};
$.magnificPopup.registerModule('gallery', {
options: {
enabled: false,
arrowMarkup: '
',
preload: [0,2],
navigateByImgClick: true,
arrows: true,
tPrev: 'Previous (Left arrow key)',
tNext: 'Next (Right arrow key)',
tCounter: '%curr% of %total%'
},
proto: {
initGallery: function() {
var gSt = nd.st.gallery,
ns = '.nd-gallery',
supportsFastClick = Boolean($.fn.ndFastClick);
nd.direction = true; // true - next, false - prev
if(!gSt || !gSt.enabled ) return false;
_wrapClasses += ' nd-gallery';
_ndOn(OPEN_EVENT+ns, function() {
if(gSt.navigateByImgClick) {
nd.wrap.on('click'+ns, '.nd-img', function() {
if(nd.items.length > 1) {
nd.next();
return false;
}
});
}
_document.on('keydown'+ns, function(e) {
if (e.keyCode === 37) {
nd.prev();
} else if (e.keyCode === 39) {
nd.next();
}
});
});
_ndOn('UpdateStatus'+ns, function(e, data) {
if(data.text) {
data.text = _replaceCurrTotal(data.text, nd.currItem.index, nd.items.length);
}
});
_ndOn(MARKUP_PARSE_EVENT+ns, function(e, element, values, item) {
var l = nd.items.length;
values.counter = l > 1 ? _replaceCurrTotal(gSt.tCounter, item.index, l) : '';
});
_ndOn('BuildControls' + ns, function() {
if(nd.items.length > 1 && gSt.arrows && !nd.arrowLeft) {
var markup = gSt.arrowMarkup,
arrowLeft = nd.arrowLeft = $( markup.replace(/%title%/gi, gSt.tPrev).replace(/%dir%/gi, 'left') ).addClass(PREVENT_CLOSE_CLASS),
arrowRight = nd.arrowRight = $( markup.replace(/%title%/gi, gSt.tNext).replace(/%dir%/gi, 'right') ).addClass(PREVENT_CLOSE_CLASS);
var eName = supportsFastClick ? 'ndFastClick' : 'click';
arrowLeft[eName](function() {
nd.prev();
});
arrowRight[eName](function() {
nd.next();
});
// Polyfill for :before and :after (adds elements with classes nd-a and nd-b)
if(nd.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);
}
nd.container.append(arrowLeft.add(arrowRight));
}
});
_ndOn(CHANGE_EVENT+ns, function() {
if(nd._preloadTimeout) clearTimeout(nd._preloadTimeout);
nd._preloadTimeout = setTimeout(function() {
nd.preloadNearbyImages();
nd._preloadTimeout = null;
}, 16);
});
_ndOn(CLOSE_EVENT+ns, function() {
_document.off(ns);
nd.wrap.off('click'+ns);
if(nd.arrowLeft && supportsFastClick) {
nd.arrowLeft.add(nd.arrowRight).destroyndFastClick();
}
nd.arrowRight = nd.arrowLeft = null;
});
},
next: function() {
nd.direction = true;
nd.index = _getLoopedId(nd.index + 1);
nd.updateItemHTML();
},
prev: function() {
nd.direction = false;
nd.index = _getLoopedId(nd.index - 1);
nd.updateItemHTML();
},
goTo: function(newIndex) {
nd.direction = (newIndex >= nd.index);
nd.index = newIndex;
nd.updateItemHTML();
},
preloadNearbyImages: function() {
var p = nd.st.gallery.preload,
preloadBefore = Math.min(p[0], nd.items.length),
preloadAfter = Math.min(p[1], nd.items.length),
i;
for(i = 1; i <= (nd.direction ? preloadAfter : preloadBefore); i++) {
nd._preloadItem(nd.index+i);
}
for(i = 1; i <= (nd.direction ? preloadBefore : preloadAfter); i++) {
nd._preloadItem(nd.index-i);
}
},
_preloadItem: function(index) {
index = _getLoopedId(index);
if(nd.items[index].preloaded) {
return;
}
var item = nd.items[index];
if(!item.parsed) {
item = nd.parseEl( index );
}
_ndTrigger('LazyLoad', item);
if(item.type === 'image') {
item.img = $('
![]()
').on('load.ndloader', function() {
item.hasSize = true;
}).on('error.ndloader', function() {
item.hasSize = true;
item.loadError = true;
_ndTrigger('LazyLoadError', item);
}).attr('src', item.src);
}
item.preloaded = true;
}
}
});
/*
Touch Support that might be implemented some day
addSwipeGesture: function() {
var startX,
moved,
multipleTouches;
return;
var namespace = '.nd',
addEventNames = function(pref, down, move, up, cancel) {
nd._tStart = pref + down + namespace;
nd._tMove = pref + move + namespace;
nd._tEnd = pref + up + namespace;
nd._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(nd._tStart, function(e) {
var oE = e.originalEvent;
multipleTouches = moved = false;
startX = oE.pageX || oE.changedTouches[0].pageX;
}).on(nd._tMove, function(e) {
if(e.originalEvent.touches.length > 1) {
multipleTouches = e.originalEvent.touches.length;
} else {
//e.preventDefault();
moved = true;
}
}).on(nd._tEnd + ' ' + nd._tCancel, function(e) {
if(moved && !multipleTouches) {
var oE = e.originalEvent,
diff = startX - (oE.pageX || oE.changedTouches[0].pageX);
if(diff > 20) {
nd.next();
} else if(diff < -20) {
nd.prev();
}
}
});
},
*/
/*>>gallery*/
/*>>retina*/
var RETINA_NS = 'retina';
$.magnificPopup.registerModule(RETINA_NS, {
options: {
replaceSrc: function(item) {
return item.src.replace(/\.\w+$/, function(m) { return '@2x' + m; });
},
ratio: 1 // Function or number. Set to 1 to disable.
},
proto: {
initRetina: function() {
if(window.devicePixelRatio > 1) {
var st = nd.st.retina,
ratio = st.ratio;
ratio = !isNaN(ratio) ? ratio : ratio();
if(ratio > 1) {
_ndOn('ImageHasSize' + '.' + RETINA_NS, function(e, item) {
item.img.css({
'max-width': item.img[0].naturalWidth / ratio,
'width': '100%'
});
});
_ndOn('ElementParse' + '.' + RETINA_NS, function(e, item) {
item.src = st.replaceSrc(item, ratio);
});
}
}
}
}
});
/*>>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').ndFastClick(function() {
* console.log('Clicked!');
* });
*
* To unbind:
* $('.your-el').destroyndFastClick();
*
*
* 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 = 'ndFastClick',
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.ndFastClick = 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.destroyndFastClick = function() {
$(this).off('touchstart' + ns + ' click' + ns);
if(supportsTouch) _window.off('touchmove'+ns+' touchend'+ns);
};
})();
/*>>fastclick*/
_checkInstance(); })(window.jQuery || window.Zepto);