');
1015 | }
1016 |
1017 | item.inlineElement = el;
1018 | return el;
1019 | }
1020 |
1021 | mfp.updateStatus('ready');
1022 | mfp._parseMarkup(template, {}, item);
1023 | return template;
1024 | }
1025 | }
1026 | });
1027 |
1028 | /*>>inline*/
1029 |
1030 | /*>>ajax*/
1031 | var AJAX_NS = 'ajax',
1032 | _ajaxCur,
1033 | _removeAjaxCursor = function() {
1034 | if(_ajaxCur) {
1035 | $(document.body).removeClass(_ajaxCur);
1036 | }
1037 | },
1038 | _destroyAjaxRequest = function() {
1039 | _removeAjaxCursor();
1040 | if(mfp.req) {
1041 | mfp.req.abort();
1042 | }
1043 | };
1044 |
1045 | $.magnificPopup.registerModule(AJAX_NS, {
1046 |
1047 | options: {
1048 | settings: null,
1049 | cursor: 'mfp-ajax-cur',
1050 | tError: '
The content could not be loaded.'
1051 | },
1052 |
1053 | proto: {
1054 | initAjax: function() {
1055 | mfp.types.push(AJAX_NS);
1056 | _ajaxCur = mfp.st.ajax.cursor;
1057 |
1058 | _mfpOn(CLOSE_EVENT+'.'+AJAX_NS, _destroyAjaxRequest);
1059 | _mfpOn('BeforeChange.' + AJAX_NS, _destroyAjaxRequest);
1060 | },
1061 | getAjax: function(item) {
1062 |
1063 | if(_ajaxCur) {
1064 | $(document.body).addClass(_ajaxCur);
1065 | }
1066 |
1067 | mfp.updateStatus('loading');
1068 |
1069 | var opts = $.extend({
1070 | url: item.src,
1071 | success: function(data, textStatus, jqXHR) {
1072 | var temp = {
1073 | data:data,
1074 | xhr:jqXHR
1075 | };
1076 |
1077 | _mfpTrigger('ParseAjax', temp);
1078 |
1079 | mfp.appendContent( $(temp.data), AJAX_NS );
1080 |
1081 | item.finished = true;
1082 |
1083 | _removeAjaxCursor();
1084 |
1085 | mfp._setFocus();
1086 |
1087 | setTimeout(function() {
1088 | mfp.wrap.addClass(READY_CLASS);
1089 | }, 16);
1090 |
1091 | mfp.updateStatus('ready');
1092 |
1093 | _mfpTrigger('AjaxContentAdded');
1094 | },
1095 | error: function() {
1096 | _removeAjaxCursor();
1097 | item.finished = item.loadError = true;
1098 | mfp.updateStatus('error', mfp.st.ajax.tError.replace('%url%', item.src));
1099 | }
1100 | }, mfp.st.ajax.settings);
1101 |
1102 | mfp.req = $.ajax(opts);
1103 |
1104 | return '';
1105 | }
1106 | }
1107 | });
1108 |
1109 | /*>>ajax*/
1110 |
1111 | /*>>image*/
1112 | var _imgInterval,
1113 | _getTitle = function(item) {
1114 | if(item.data && item.data.title !== undefined)
1115 | return item.data.title;
1116 |
1117 | var src = mfp.st.image.titleSrc;
1118 |
1119 | if(src) {
1120 | if($.isFunction(src)) {
1121 | return src.call(mfp, item);
1122 | } else if(item.el) {
1123 | return item.el.attr(src) || '';
1124 | }
1125 | }
1126 | return '';
1127 | };
1128 |
1129 | $.magnificPopup.registerModule('image', {
1130 |
1131 | options: {
1132 | markup: '
',
1144 | cursor: 'mfp-zoom-out-cur',
1145 | titleSrc: 'title',
1146 | verticalFit: true,
1147 | tError: '
The image could not be loaded.'
1148 | },
1149 |
1150 | proto: {
1151 | initImage: function() {
1152 | var imgSt = mfp.st.image,
1153 | ns = '.image';
1154 |
1155 | mfp.types.push('image');
1156 |
1157 | _mfpOn(OPEN_EVENT+ns, function() {
1158 | if(mfp.currItem.type === 'image' && imgSt.cursor) {
1159 | $(document.body).addClass(imgSt.cursor);
1160 | }
1161 | });
1162 |
1163 | _mfpOn(CLOSE_EVENT+ns, function() {
1164 | if(imgSt.cursor) {
1165 | $(document.body).removeClass(imgSt.cursor);
1166 | }
1167 | _window.off('resize' + EVENT_NS);
1168 | });
1169 |
1170 | _mfpOn('Resize'+ns, mfp.resizeImage);
1171 | if(mfp.isLowIE) {
1172 | _mfpOn('AfterChange', mfp.resizeImage);
1173 | }
1174 | },
1175 | resizeImage: function() {
1176 | var item = mfp.currItem;
1177 | if(!item || !item.img) return;
1178 |
1179 | if(mfp.st.image.verticalFit) {
1180 | var decr = 0;
1181 | // fix box-sizing in ie7/8
1182 | if(mfp.isLowIE) {
1183 | decr = parseInt(item.img.css('padding-top'), 10) + parseInt(item.img.css('padding-bottom'),10);
1184 | }
1185 | item.img.css('max-height', mfp.wH-decr);
1186 | }
1187 | },
1188 | _onImageHasSize: function(item) {
1189 | if(item.img) {
1190 |
1191 | item.hasSize = true;
1192 |
1193 | if(_imgInterval) {
1194 | clearInterval(_imgInterval);
1195 | }
1196 |
1197 | item.isCheckingImgSize = false;
1198 |
1199 | _mfpTrigger('ImageHasSize', item);
1200 |
1201 | if(item.imgHidden) {
1202 | if(mfp.content)
1203 | mfp.content.removeClass('mfp-loading');
1204 |
1205 | item.imgHidden = false;
1206 | }
1207 |
1208 | }
1209 | },
1210 |
1211 | /**
1212 | * Function that loops until the image has size to display elements that rely on it asap
1213 | */
1214 | findImageSize: function(item) {
1215 |
1216 | var counter = 0,
1217 | img = item.img[0],
1218 | mfpSetInterval = function(delay) {
1219 |
1220 | if(_imgInterval) {
1221 | clearInterval(_imgInterval);
1222 | }
1223 | // decelerating interval that checks for size of an image
1224 | _imgInterval = setInterval(function() {
1225 | if(img.naturalWidth > 0) {
1226 | mfp._onImageHasSize(item);
1227 | return;
1228 | }
1229 |
1230 | if(counter > 200) {
1231 | clearInterval(_imgInterval);
1232 | }
1233 |
1234 | counter++;
1235 | if(counter === 3) {
1236 | mfpSetInterval(10);
1237 | } else if(counter === 40) {
1238 | mfpSetInterval(50);
1239 | } else if(counter === 100) {
1240 | mfpSetInterval(500);
1241 | }
1242 | }, delay);
1243 | };
1244 |
1245 | mfpSetInterval(1);
1246 | },
1247 |
1248 | getImage: function(item, template) {
1249 |
1250 | var guard = 0,
1251 |
1252 | // image load complete handler
1253 | onLoadComplete = function() {
1254 | if(item) {
1255 | if (item.img[0].complete) {
1256 | item.img.off('.mfploader');
1257 |
1258 | if(item === mfp.currItem){
1259 | mfp._onImageHasSize(item);
1260 |
1261 | mfp.updateStatus('ready');
1262 | }
1263 |
1264 | item.hasSize = true;
1265 | item.loaded = true;
1266 |
1267 | _mfpTrigger('ImageLoadComplete');
1268 |
1269 | }
1270 | else {
1271 | // if image complete check fails 200 times (20 sec), we assume that there was an error.
1272 | guard++;
1273 | if(guard < 200) {
1274 | setTimeout(onLoadComplete,100);
1275 | } else {
1276 | onLoadError();
1277 | }
1278 | }
1279 | }
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;
1297 |
1298 |
1299 | var el = template.find('.mfp-img');
1300 | if(el.length) {
1301 | var img = document.createElement('img');
1302 | img.className = 'mfp-img';
1303 | if(item.el && item.el.find('img').length) {
1304 | img.alt = item.el.find('img').attr('alt');
1305 | }
1306 | item.img = $(img).on('load.mfploader', onLoadComplete).on('error.mfploader', onLoadError);
1307 | img.src = item.src;
1308 |
1309 | // without clone() "error" event is not firing when IMG is replaced by new IMG
1310 | // TODO: find a way to avoid such cloning
1311 | if(el.is('img')) {
1312 | item.img = item.img.clone();
1313 | }
1314 |
1315 | img = item.img[0];
1316 | if(img.naturalWidth > 0) {
1317 | item.hasSize = true;
1318 | } else if(!img.width) {
1319 | item.hasSize = false;
1320 | }
1321 | }
1322 |
1323 | mfp._parseMarkup(template, {
1324 | title: _getTitle(item),
1325 | img_replaceWith: item.img
1326 | }, item);
1327 |
1328 | mfp.resizeImage();
1329 |
1330 | if(item.hasSize) {
1331 | if(_imgInterval) clearInterval(_imgInterval);
1332 |
1333 | if(item.loadError) {
1334 | template.addClass('mfp-loading');
1335 | mfp.updateStatus('error', imgSt.tError.replace('%url%', item.src) );
1336 | } else {
1337 | template.removeClass('mfp-loading');
1338 | mfp.updateStatus('ready');
1339 | }
1340 | return template;
1341 | }
1342 |
1343 | mfp.updateStatus('loading');
1344 | item.loading = true;
1345 |
1346 | if(!item.hasSize) {
1347 | item.imgHidden = true;
1348 | template.addClass('mfp-loading');
1349 | mfp.findImageSize(item);
1350 | }
1351 |
1352 | return template;
1353 | }
1354 | }
1355 | });
1356 |
1357 | /*>>image*/
1358 |
1359 | /*>>zoom*/
1360 | var hasMozTransform,
1361 | getHasMozTransform = function() {
1362 | if(hasMozTransform === undefined) {
1363 | hasMozTransform = document.createElement('p').style.MozTransform !== undefined;
1364 | }
1365 | return hasMozTransform;
1366 | };
1367 |
1368 | $.magnificPopup.registerModule('zoom', {
1369 |
1370 | options: {
1371 | enabled: false,
1372 | easing: 'ease-in-out',
1373 | duration: 300,
1374 | opener: function(element) {
1375 | return element.is('img') ? element : element.find('img');
1376 | }
1377 | },
1378 |
1379 | proto: {
1380 |
1381 | initZoom: function() {
1382 | var zoomSt = mfp.st.zoom,
1383 | ns = '.zoom',
1384 | image;
1385 |
1386 | if(!zoomSt.enabled || !mfp.supportsTransition) {
1387 | return;
1388 | }
1389 |
1390 | var duration = zoomSt.duration,
1391 | getElToAnimate = function(image) {
1392 | var newImg = image.clone().removeAttr('style').removeAttr('class').addClass('mfp-animated-image'),
1393 | transition = 'all '+(zoomSt.duration/1000)+'s ' + zoomSt.easing,
1394 | cssObj = {
1395 | position: 'fixed',
1396 | zIndex: 9999,
1397 | left: 0,
1398 | top: 0,
1399 | '-webkit-backface-visibility': 'hidden'
1400 | },
1401 | t = 'transition';
1402 |
1403 | cssObj['-webkit-'+t] = cssObj['-moz-'+t] = cssObj['-o-'+t] = cssObj[t] = transition;
1404 |
1405 | newImg.css(cssObj);
1406 | return newImg;
1407 | },
1408 | showMainContent = function() {
1409 | mfp.content.css('visibility', 'visible');
1410 | },
1411 | openTimeout,
1412 | animatedImg;
1413 |
1414 | _mfpOn('BuildControls'+ns, function() {
1415 | if(mfp._allowZoom()) {
1416 |
1417 | clearTimeout(openTimeout);
1418 | mfp.content.css('visibility', 'hidden');
1419 |
1420 | // Basically, all code below does is clones existing image, puts in on top of the current one and animated it
1421 |
1422 | image = mfp._getItemToZoom();
1423 |
1424 | if(!image) {
1425 | showMainContent();
1426 | return;
1427 | }
1428 |
1429 | animatedImg = getElToAnimate(image);
1430 |
1431 | animatedImg.css( mfp._getOffset() );
1432 |
1433 | mfp.wrap.append(animatedImg);
1434 |
1435 | openTimeout = setTimeout(function() {
1436 | animatedImg.css( mfp._getOffset( true ) );
1437 | openTimeout = setTimeout(function() {
1438 |
1439 | showMainContent();
1440 |
1441 | setTimeout(function() {
1442 | animatedImg.remove();
1443 | image = animatedImg = null;
1444 | _mfpTrigger('ZoomAnimationEnded');
1445 | }, 16); // avoid blink when switching images
1446 |
1447 | }, duration); // this timeout equals animation duration
1448 |
1449 | }, 16); // by adding this timeout we avoid short glitch at the beginning of animation
1450 |
1451 |
1452 | // Lots of timeouts...
1453 | }
1454 | });
1455 | _mfpOn(BEFORE_CLOSE_EVENT+ns, function() {
1456 | if(mfp._allowZoom()) {
1457 |
1458 | clearTimeout(openTimeout);
1459 |
1460 | mfp.st.removalDelay = duration;
1461 |
1462 | if(!image) {
1463 | image = mfp._getItemToZoom();
1464 | if(!image) {
1465 | return;
1466 | }
1467 | animatedImg = getElToAnimate(image);
1468 | }
1469 |
1470 | animatedImg.css( mfp._getOffset(true) );
1471 | mfp.wrap.append(animatedImg);
1472 | mfp.content.css('visibility', 'hidden');
1473 |
1474 | setTimeout(function() {
1475 | animatedImg.css( mfp._getOffset() );
1476 | }, 16);
1477 | }
1478 |
1479 | });
1480 |
1481 | _mfpOn(CLOSE_EVENT+ns, function() {
1482 | if(mfp._allowZoom()) {
1483 | showMainContent();
1484 | if(animatedImg) {
1485 | animatedImg.remove();
1486 | }
1487 | image = null;
1488 | }
1489 | });
1490 | },
1491 |
1492 | _allowZoom: function() {
1493 | return mfp.currItem.type === 'image';
1494 | },
1495 |
1496 | _getItemToZoom: function() {
1497 | if(mfp.currItem.hasSize) {
1498 | return mfp.currItem.img;
1499 | } else {
1500 | return false;
1501 | }
1502 | },
1503 |
1504 | // Get element postion relative to viewport
1505 | _getOffset: function(isLarge) {
1506 | var el;
1507 | if(isLarge) {
1508 | el = mfp.currItem.img;
1509 | } else {
1510 | el = mfp.st.zoom.opener(mfp.currItem.el || mfp.currItem);
1511 | }
1512 |
1513 | var offset = el.offset();
1514 | var paddingTop = parseInt(el.css('padding-top'),10);
1515 | var paddingBottom = parseInt(el.css('padding-bottom'),10);
1516 | offset.top -= ( $(window).scrollTop() - paddingTop );
1517 |
1518 |
1519 | /*
1520 |
1521 | Animating left + top + width/height looks glitchy in Firefox, but perfect in Chrome. And vice-versa.
1522 |
1523 | */
1524 | var obj = {
1525 | width: el.width(),
1526 | // fix Zepto height+padding issue
1527 | height: (_isJQ ? el.innerHeight() : el[0].offsetHeight) - paddingBottom - paddingTop
1528 | };
1529 |
1530 | // I hate to do this, but there is no another option
1531 | if( getHasMozTransform() ) {
1532 | obj['-moz-transform'] = obj['transform'] = 'translate(' + offset.left + 'px,' + offset.top + 'px)';
1533 | } else {
1534 | obj.left = offset.left;
1535 | obj.top = offset.top;
1536 | }
1537 | return obj;
1538 | }
1539 |
1540 | }
1541 | });
1542 |
1543 |
1544 |
1545 | /*>>zoom*/
1546 |
1547 | /*>>iframe*/
1548 |
1549 | var IFRAME_NS = 'iframe',
1550 | _emptyPage = '//about:blank',
1551 |
1552 | _fixIframeBugs = function(isShowing) {
1553 | if(mfp.currTemplate[IFRAME_NS]) {
1554 | var el = mfp.currTemplate[IFRAME_NS].find('iframe');
1555 | if(el.length) {
1556 | // reset src after the popup is closed to avoid "video keeps playing after popup is closed" bug
1557 | if(!isShowing) {
1558 | el[0].src = _emptyPage;
1559 | }
1560 |
1561 | // IE8 black screen bug fix
1562 | if(mfp.isIE8) {
1563 | el.css('display', isShowing ? 'block' : 'none');
1564 | }
1565 | }
1566 | }
1567 | };
1568 |
1569 | $.magnificPopup.registerModule(IFRAME_NS, {
1570 |
1571 | options: {
1572 | markup: '
'+
1573 | '
'+
1574 | '
'+
1575 | '
',
1576 |
1577 | srcAction: 'iframe_src',
1578 |
1579 | // we don't care and support only one default type of URL by default
1580 | patterns: {
1581 | youtube: {
1582 | index: 'youtube.com',
1583 | id: 'v=',
1584 | src: '//www.youtube.com/embed/%id%?autoplay=1'
1585 | },
1586 | vimeo: {
1587 | index: 'vimeo.com/',
1588 | id: '/',
1589 | src: '//player.vimeo.com/video/%id%?autoplay=1'
1590 | },
1591 | gmaps: {
1592 | index: '//maps.google.',
1593 | src: '%id%&output=embed'
1594 | }
1595 | }
1596 | },
1597 |
1598 | proto: {
1599 | initIframe: function() {
1600 | mfp.types.push(IFRAME_NS);
1601 |
1602 | _mfpOn('BeforeChange', function(e, prevType, newType) {
1603 | if(prevType !== newType) {
1604 | if(prevType === IFRAME_NS) {
1605 | _fixIframeBugs(); // iframe if removed
1606 | } else if(newType === IFRAME_NS) {
1607 | _fixIframeBugs(true); // iframe is showing
1608 | }
1609 | }// else {
1610 | // iframe source is switched, don't do anything
1611 | //}
1612 | });
1613 |
1614 | _mfpOn(CLOSE_EVENT + '.' + IFRAME_NS, function() {
1615 | _fixIframeBugs();
1616 | });
1617 | },
1618 |
1619 | getIframe: function(item, template) {
1620 | var embedSrc = item.src;
1621 | var iframeSt = mfp.st.iframe;
1622 |
1623 | $.each(iframeSt.patterns, function() {
1624 | if(embedSrc.indexOf( this.index ) > -1) {
1625 | if(this.id) {
1626 | if(typeof this.id === 'string') {
1627 | embedSrc = embedSrc.substr(embedSrc.lastIndexOf(this.id)+this.id.length, embedSrc.length);
1628 | } else {
1629 | embedSrc = this.id.call( this, embedSrc );
1630 | }
1631 | }
1632 | embedSrc = this.src.replace('%id%', embedSrc );
1633 | return false; // break;
1634 | }
1635 | });
1636 |
1637 | var dataObj = {};
1638 | if(iframeSt.srcAction) {
1639 | dataObj[iframeSt.srcAction] = embedSrc;
1640 | }
1641 | mfp._parseMarkup(template, dataObj, item);
1642 |
1643 | mfp.updateStatus('ready');
1644 |
1645 | return template;
1646 | }
1647 | }
1648 | });
1649 |
1650 |
1651 |
1652 | /*>>iframe*/
1653 |
1654 | /*>>gallery*/
1655 | /**
1656 | * Get looped index depending on number of slides
1657 | */
1658 | var _getLoopedId = function(index) {
1659 | var numSlides = mfp.items.length;
1660 | if(index > numSlides - 1) {
1661 | return index - numSlides;
1662 | } else if(index < 0) {
1663 | return numSlides + index;
1664 | }
1665 | return index;
1666 | },
1667 | _replaceCurrTotal = function(text, curr, total) {
1668 | return text.replace(/%curr%/gi, curr + 1).replace(/%total%/gi, total);
1669 | };
1670 |
1671 | $.magnificPopup.registerModule('gallery', {
1672 |
1673 | options: {
1674 | enabled: false,
1675 | arrowMarkup: '
',
1676 | preload: [0,2],
1677 | navigateByImgClick: true,
1678 | arrows: true,
1679 |
1680 | tPrev: 'Previous (Left arrow key)',
1681 | tNext: 'Next (Right arrow key)',
1682 | tCounter: '%curr% of %total%'
1683 | },
1684 |
1685 | proto: {
1686 | initGallery: function() {
1687 |
1688 | var gSt = mfp.st.gallery,
1689 | ns = '.mfp-gallery';
1690 |
1691 | mfp.direction = true; // true - next, false - prev
1692 |
1693 | if(!gSt || !gSt.enabled ) return false;
1694 |
1695 | _wrapClasses += ' mfp-gallery';
1696 |
1697 | _mfpOn(OPEN_EVENT+ns, function() {
1698 |
1699 | if(gSt.navigateByImgClick) {
1700 | mfp.wrap.on('click'+ns, '.mfp-img', function() {
1701 | if(mfp.items.length > 1) {
1702 | mfp.next();
1703 | return false;
1704 | }
1705 | });
1706 | }
1707 |
1708 | _document.on('keydown'+ns, function(e) {
1709 | if (e.keyCode === 37) {
1710 | mfp.prev();
1711 | } else if (e.keyCode === 39) {
1712 | mfp.next();
1713 | }
1714 | });
1715 | });
1716 |
1717 | _mfpOn('UpdateStatus'+ns, function(e, data) {
1718 | if(data.text) {
1719 | data.text = _replaceCurrTotal(data.text, mfp.currItem.index, mfp.items.length);
1720 | }
1721 | });
1722 |
1723 | _mfpOn(MARKUP_PARSE_EVENT+ns, function(e, element, values, item) {
1724 | var l = mfp.items.length;
1725 | values.counter = l > 1 ? _replaceCurrTotal(gSt.tCounter, item.index, l) : '';
1726 | });
1727 |
1728 | _mfpOn('BuildControls' + ns, function() {
1729 | 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);
1733 |
1734 | arrowLeft.click(function() {
1735 | mfp.prev();
1736 | });
1737 | arrowRight.click(function() {
1738 | mfp.next();
1739 | });
1740 |
1741 | mfp.container.append(arrowLeft.add(arrowRight));
1742 | }
1743 | });
1744 |
1745 | _mfpOn(CHANGE_EVENT+ns, function() {
1746 | if(mfp._preloadTimeout) clearTimeout(mfp._preloadTimeout);
1747 |
1748 | mfp._preloadTimeout = setTimeout(function() {
1749 | mfp.preloadNearbyImages();
1750 | mfp._preloadTimeout = null;
1751 | }, 16);
1752 | });
1753 |
1754 |
1755 | _mfpOn(CLOSE_EVENT+ns, function() {
1756 | _document.off(ns);
1757 | mfp.wrap.off('click'+ns);
1758 | mfp.arrowRight = mfp.arrowLeft = null;
1759 | });
1760 |
1761 | },
1762 | next: function() {
1763 | mfp.direction = true;
1764 | mfp.index = _getLoopedId(mfp.index + 1);
1765 | mfp.updateItemHTML();
1766 | },
1767 | prev: function() {
1768 | mfp.direction = false;
1769 | mfp.index = _getLoopedId(mfp.index - 1);
1770 | mfp.updateItemHTML();
1771 | },
1772 | goTo: function(newIndex) {
1773 | mfp.direction = (newIndex >= mfp.index);
1774 | mfp.index = newIndex;
1775 | mfp.updateItemHTML();
1776 | },
1777 | preloadNearbyImages: function() {
1778 | var p = mfp.st.gallery.preload,
1779 | preloadBefore = Math.min(p[0], mfp.items.length),
1780 | preloadAfter = Math.min(p[1], mfp.items.length),
1781 | i;
1782 |
1783 | for(i = 1; i <= (mfp.direction ? preloadAfter : preloadBefore); i++) {
1784 | mfp._preloadItem(mfp.index+i);
1785 | }
1786 | for(i = 1; i <= (mfp.direction ? preloadBefore : preloadAfter); i++) {
1787 | mfp._preloadItem(mfp.index-i);
1788 | }
1789 | },
1790 | _preloadItem: function(index) {
1791 | index = _getLoopedId(index);
1792 |
1793 | if(mfp.items[index].preloaded) {
1794 | return;
1795 | }
1796 |
1797 | var item = mfp.items[index];
1798 | if(!item.parsed) {
1799 | item = mfp.parseEl( index );
1800 | }
1801 |
1802 | _mfpTrigger('LazyLoad', item);
1803 |
1804 | if(item.type === 'image') {
1805 | item.img = $('
![]()
').on('load.mfploader', function() {
1806 | item.hasSize = true;
1807 | }).on('error.mfploader', function() {
1808 | item.hasSize = true;
1809 | item.loadError = true;
1810 | _mfpTrigger('LazyLoadError', item);
1811 | }).attr('src', item.src);
1812 | }
1813 |
1814 |
1815 | item.preloaded = true;
1816 | }
1817 | }
1818 | });
1819 |
1820 | /*>>gallery*/
1821 |
1822 | /*>>retina*/
1823 |
1824 | var RETINA_NS = 'retina';
1825 |
1826 | $.magnificPopup.registerModule(RETINA_NS, {
1827 | options: {
1828 | replaceSrc: function(item) {
1829 | return item.src.replace(/\.\w+$/, function(m) { return '@2x' + m; });
1830 | },
1831 | ratio: 1 // Function or number. Set to 1 to disable.
1832 | },
1833 | proto: {
1834 | initRetina: function() {
1835 | if(window.devicePixelRatio > 1) {
1836 |
1837 | var st = mfp.st.retina,
1838 | ratio = st.ratio;
1839 |
1840 | ratio = !isNaN(ratio) ? ratio : ratio();
1841 |
1842 | if(ratio > 1) {
1843 | _mfpOn('ImageHasSize' + '.' + RETINA_NS, function(e, item) {
1844 | item.img.css({
1845 | 'max-width': item.img[0].naturalWidth / ratio,
1846 | 'width': '100%'
1847 | });
1848 | });
1849 | _mfpOn('ElementParse' + '.' + RETINA_NS, function(e, item) {
1850 | item.src = st.replaceSrc(item, ratio);
1851 | });
1852 | }
1853 | }
1854 |
1855 | }
1856 | }
1857 | });
1858 |
1859 | /*>>retina*/
1860 | _checkInstance(); }));
--------------------------------------------------------------------------------