| 1 |
import {Core} from "../Core"; |
| 2 |
import {Lightbox} from "./Lightbox"; |
| 3 |
import * as Util from "../Util"; |
| 4 |
|
| 5 |
export class PhotonicImageLightbox extends Lightbox { |
| 6 |
constructor($) { |
| 7 |
super(); |
| 8 |
this.$ = $; |
| 9 |
} |
| 10 |
|
| 11 |
soloImages() { |
| 12 |
const $ = this.$; |
| 13 |
$('a[href]').filter(function() { |
| 14 |
return /(\.jpg|\.jpeg|\.bmp|\.gif|\.png)/i.test( $(this).attr('href')); |
| 15 |
}).filter(function() { |
| 16 |
const res = new RegExp('photonic-lb').test($(this).attr('class')); |
| 17 |
return !res; |
| 18 |
}).attr("rel", 'photonic-' + Photonic_JS.lightbox_library); |
| 19 |
}; |
| 20 |
|
| 21 |
initialize(selector, group) { |
| 22 |
const $ = this.$; |
| 23 |
this.handleSolos(); |
| 24 |
const self = this; |
| 25 |
|
| 26 |
$(selector).each(function(i, current) { |
| 27 |
let lightbox_selector; |
| 28 |
let rel = $(current).find('a.photonic-imagelightbox'); |
| 29 |
if (rel.length > 0) { |
| 30 |
rel = $(rel[0]).attr('rel'); |
| 31 |
} |
| 32 |
|
| 33 |
lightbox_selector = selector.indexOf('rel') > -1 ? selector : 'a[rel="' + rel + '"]'; |
| 34 |
|
| 35 |
const photonicImageLightbox = $(lightbox_selector).imageLightbox(lightbox_selector, { |
| 36 |
onLoadStart: function () { |
| 37 |
imageLightboxCaptionOff(); |
| 38 |
imageLightboxLoadingOn(); |
| 39 |
}, |
| 40 |
onLoadEnd: function () { |
| 41 |
imageLightboxCaptionOn(); |
| 42 |
$('#imagelightbox-loading').remove(); |
| 43 |
$('.imagelightbox-arrow').css('display', 'block'); |
| 44 |
const lightbox = $('#imagelightbox'); |
| 45 |
const base = $(current).find('a[href="' + lightbox.attr('src') + '"]'); |
| 46 |
if (base.length > 0) { |
| 47 |
self.setHash(base[0]); |
| 48 |
} |
| 49 |
const shareable = { |
| 50 |
'url': location.href, |
| 51 |
'title': Util.getText($(base).data('title')), |
| 52 |
'image': lightbox.attr('src') |
| 53 |
}; |
| 54 |
self.addSocial('#imagelightbox-overlay', shareable); |
| 55 |
}, |
| 56 |
onStart: function () { |
| 57 |
$('<div id="imagelightbox-overlay"></div>').appendTo('body'); |
| 58 |
imageLightboxArrowsOn(photonicImageLightbox, lightbox_selector); |
| 59 |
imageLightboxCloseButtonOn(photonicImageLightbox); |
| 60 |
}, |
| 61 |
onEnd: function () { |
| 62 |
imageLightboxCaptionOff(); |
| 63 |
$('#imagelightbox-overlay').remove(); |
| 64 |
$('#imagelightbox-loading').remove(); |
| 65 |
imageLightboxArrowsOff(); |
| 66 |
imageLightboxCloseButtonOff(); |
| 67 |
self.unsetHash(); |
| 68 |
} |
| 69 |
}); |
| 70 |
Core.addToLightboxList(lightbox_selector, photonicImageLightbox); |
| 71 |
}); |
| 72 |
}; |
| 73 |
|
| 74 |
initializeForNewContainer(containerId) { |
| 75 |
this.initialize(containerId); |
| 76 |
}; |
| 77 |
|
| 78 |
} |
| 79 |
|