|
|
@@ -8,36 +8,21 @@
|
|
|
* @{
|
|
|
*/
|
|
|
|
|
|
-Array.prototype.indexOfMediaObject = function (o) {
|
|
|
+Array.prototype.indexOfMediaObject = function (iMediaId) {
|
|
|
var iLength = this.length;
|
|
|
for (var i=0 ; i < iLength ; ++i) {
|
|
|
- if (o['media-id'] == this[i]['media-id'])
|
|
|
+ if (iMediaId == this[i]['media-id'])
|
|
|
return i;
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-function bx_albums_open_gallery(eve, e, sContext) {
|
|
|
- var ePswp = document.querySelectorAll('.pswp')[0];
|
|
|
- var $e = $(e);
|
|
|
- var aItems = []; // more items are added dynamically
|
|
|
- var oItem = {};
|
|
|
- var iCount = 0;
|
|
|
- var options = {
|
|
|
- bx_albums_context: sContext,
|
|
|
- shareEl: false,
|
|
|
- counterEl: false,
|
|
|
- history: false,
|
|
|
- loop: false,
|
|
|
- showHideOpacity: true,
|
|
|
- index: 0,
|
|
|
- getThumbBoundsFn: function(index) {
|
|
|
- var e = $('a[data-media-id] img');
|
|
|
- if (!e.length)
|
|
|
- return false;
|
|
|
- return {x:e.offset().left, y:e.offset().top, w:e.width()};
|
|
|
- }
|
|
|
- };
|
|
|
+function bx_albums_open_gallery(eve, e, sContext, aItems) {
|
|
|
+
|
|
|
+ eve.preventDefault ? eve.preventDefault() : eve.returnValue = false;
|
|
|
+
|
|
|
+ var options = {};
|
|
|
+
|
|
|
var fnProcessRetina = function (o) {
|
|
|
var dpr = ((window.glBxDisableRetina !== undefined && window.glBxDisableRetina) || window.devicePixelRatio === undefined ? 1 : window.devicePixelRatio);
|
|
|
if (dpr < 2)
|
|
|
@@ -47,140 +32,29 @@ function bx_albums_open_gallery(eve, e, sContext) {
|
|
|
return o;
|
|
|
}
|
|
|
|
|
|
- eve.preventDefault ? eve.preventDefault() : eve.returnValue = false;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // get data for initial item from the attributes of the item which was clicked
|
|
|
- $.each(e.attributes, function(i, attr) {
|
|
|
- var sName = attr.name;
|
|
|
- if (sName.indexOf('data-') !== 0)
|
|
|
- return;
|
|
|
- sName = sName.replace('data-', '');
|
|
|
- oItem[sName] = attr.value;
|
|
|
-
|
|
|
- ++iCount;
|
|
|
- });
|
|
|
-
|
|
|
- oItem.msrc = oItem.src;
|
|
|
- oItem = fnProcessRetina(oItem);
|
|
|
-
|
|
|
- if (!iCount) // no image - no concert!
|
|
|
+ if (!aItems.length) // no images - no concert!
|
|
|
return false;
|
|
|
|
|
|
- aItems.push(oItem);
|
|
|
-
|
|
|
- var fnConverMedia = function (oMedia) {
|
|
|
- var oMap = {
|
|
|
- 'id': 'media-id',
|
|
|
- 'url': 'url',
|
|
|
- 'url_img' : 'src',
|
|
|
- 'w': 'w',
|
|
|
- 'h': 'h',
|
|
|
- 'title': 'title'
|
|
|
- };
|
|
|
-
|
|
|
- if ('undefined' !== typeof(oMedia.html) && oMedia.html.length)
|
|
|
- return {'media-id': oMedia['id'], 'title': oMedia['title'], 'html': oMedia['html'], 'url': oMedia['url']};
|
|
|
-
|
|
|
- var o = {};
|
|
|
- for (var i in oMap)
|
|
|
- o[oMap[i]] = oMedia[i];
|
|
|
- return fnProcessRetina(o);
|
|
|
- };
|
|
|
-
|
|
|
- var fnDisableArrows = function (oItem) {
|
|
|
-
|
|
|
- // disable prev item and action if we are on the first item
|
|
|
- if (0 == aItems.indexOfMediaObject(oItem)) {
|
|
|
- $('.pswp__button--arrow--left').hide();
|
|
|
- glBxAlbumsPrevFn = glBxAlbumsGallery.prev;
|
|
|
- glBxAlbumsGallery.prev = function () { };
|
|
|
- } else {
|
|
|
- $('.pswp__button--arrow--left').show();
|
|
|
- if ('undefined' !== typeof(glBxAlbumsPrevFn))
|
|
|
- glBxAlbumsGallery.prev = glBxAlbumsPrevFn;
|
|
|
- }
|
|
|
-
|
|
|
- // disable next item and action when we are in the last item
|
|
|
- if ((aItems.length-1) == aItems.indexOfMediaObject(oItem)) {
|
|
|
- $('.pswp__button--arrow--right').hide();
|
|
|
- glBxAlbumsNextFn = glBxAlbumsGallery.next;
|
|
|
- glBxAlbumsGallery.next = function () { };
|
|
|
- } else {
|
|
|
- $('.pswp__button--arrow--right').show();
|
|
|
- if ('undefined' !== typeof(glBxAlbumsNextFn))
|
|
|
- glBxAlbumsGallery.next = glBxAlbumsNextFn;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- var fnLoadMoreItem = function (oItemCurrent, bFirstLoad) {
|
|
|
-
|
|
|
- // load addutional items only for items on the border
|
|
|
- if (0 != aItems.indexOfMediaObject(oItemCurrent) && (aItems.length-1) != aItems.indexOfMediaObject(oItemCurrent))
|
|
|
- return;
|
|
|
-
|
|
|
- var sUrl = sUrlRoot + 'modules/index.php?r=albums/get_sibling_media/' + oItemCurrent['media-id'] + '/' + sContext;
|
|
|
- $.getJSON(sUrl, function(oData) {
|
|
|
-
|
|
|
- if ('undefined' !== typeof(oData.error)) {
|
|
|
- if ('undefined' !== typeof(console))
|
|
|
- console.log(oData.error);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- var iGoTo = -1;
|
|
|
- var iLength = aItems.length;
|
|
|
-
|
|
|
- if (0 == aItems.indexOfMediaObject(oItemCurrent) && 'undefined' !== typeof(oData.prev.url)) {
|
|
|
- aItems.unshift(fnConverMedia(oData.prev));
|
|
|
- if (bFirstLoad)
|
|
|
- options.index = 1;
|
|
|
- else
|
|
|
- iGoTo = glBxAlbumsGallery.getCurrentIndex() + 1;
|
|
|
- }
|
|
|
-
|
|
|
- if ((aItems.length - 1) == aItems.indexOfMediaObject(oItemCurrent) && 'undefined' !== typeof(oData.next.url))
|
|
|
- aItems.push(fnConverMedia(oData.next));
|
|
|
-
|
|
|
- if (!bFirstLoad && iLength != aItems.length) {
|
|
|
- glBxAlbumsGallery.invalidateCurrItems();
|
|
|
- glBxAlbumsGallery.updateSize(true);
|
|
|
-
|
|
|
- if(iGoTo >= 0)
|
|
|
- glBxAlbumsGallery.goTo(iGoTo);
|
|
|
- }
|
|
|
+ options.dataSource = aItems;
|
|
|
+ options.pswpModule = PhotoSwipe;
|
|
|
+ options.preload = [1,2];
|
|
|
+ options.showHideAnimationType = 'none';
|
|
|
|
|
|
- if (bFirstLoad) {
|
|
|
- glBxAlbumsGallery = new PhotoSwipe(ePswp, PhotoSwipeUI_Default, aItems, options);
|
|
|
- glBxAlbumsGallery.init();
|
|
|
+ var lightbox = new PhotoSwipeLightbox(options);
|
|
|
+ lightbox.init();
|
|
|
|
|
|
- glBxAlbumsGallery.listen('beforeChange', function() {
|
|
|
- // load more items if we are on first or on the last item
|
|
|
- fnLoadMoreItem(glBxAlbumsGallery.currItem, false);
|
|
|
- });
|
|
|
-
|
|
|
- glBxAlbumsGallery.listen('afterChange', function() {
|
|
|
- var bChangeHistory = 'undefined' !== typeof(glBxAlbumsGallery._bx_albums_skip_history) && glBxAlbumsGallery._bx_albums_skip_history ? false : true;
|
|
|
- bx_albums_reload_page(glBxAlbumsGallery.currItem.url, glBxAlbumsGallery.currItem.title, bChangeHistory, false); // refresh url when we navigate to next/prev item
|
|
|
- glBxAlbumsGallery._bx_albums_skip_history = false;
|
|
|
-
|
|
|
- fnDisableArrows(glBxAlbumsGallery.currItem);
|
|
|
- });
|
|
|
-
|
|
|
- glBxAlbumsGallery.listen('close', function() {
|
|
|
- // upon gallery close reload page via AJAX, since url was changes when we navigate through items in the gallery
|
|
|
- bx_albums_reload_page(glBxAlbumsGallery.currItem.url, glBxAlbumsGallery.currItem.title, false, true);
|
|
|
- });
|
|
|
-
|
|
|
- fnDisableArrows(glBxAlbumsGallery.currItem);
|
|
|
- }
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
- fnLoadMoreItem(oItem, true);
|
|
|
+ lightbox.addFilter('numItems', (numItems) => {
|
|
|
+ return aItems.length;
|
|
|
+ });
|
|
|
+ lightbox.addFilter('itemData', (itemData, index) => {
|
|
|
+ return aItems[index];
|
|
|
+ });
|
|
|
+ lightbox.on('close', () => {
|
|
|
+ const { pswp } = lightbox;
|
|
|
+ bx_albums_reload_page(pswp.currSlide.data.url, pswp.currSlide.data.alt, true, true);
|
|
|
+ });
|
|
|
|
|
|
- return false;
|
|
|
+ lightbox.loadAndOpen(aItems.indexOfMediaObject($(e).attr('data-media-id')));
|
|
|
}
|
|
|
|
|
|
function bx_albums_reload_page(sUrl, sTitle, bChangeHistory, bChangeContent) {
|