| 1 |
import {Lightbox} from "./Lightbox"; |
| 2 |
import * as Util from "../Util"; |
| 3 |
|
| 4 |
export class PhotonicLightcase extends Lightbox { |
| 5 |
constructor($) { |
| 6 |
super(); |
| 7 |
this.$ = $; |
| 8 |
} |
| 9 |
|
| 10 |
soloImages() { |
| 11 |
const $ = this.$; |
| 12 |
$('a[href]').filter(function() { |
| 13 |
return /(\.jpg|\.jpeg|\.bmp|\.gif|\.png)/i.test( $(this).attr('href')); |
| 14 |
}).filter(function() { |
| 15 |
const res = new RegExp('photonic-lb').test($(this).attr('class')); |
| 16 |
return !res; |
| 17 |
}).attr("data-rel", 'photonic-lightcase'); |
| 18 |
}; |
| 19 |
|
| 20 |
changeVideoURL(element, regular, embed) { |
| 21 |
const $ = this.$; |
| 22 |
$(element).attr('href', embed); |
| 23 |
$(element).attr("data-rel", 'photonic-lightcase-video'); |
| 24 |
}; |
| 25 |
|
| 26 |
hostedVideo(a) { |
| 27 |
const $ = this.$; |
| 28 |
const html5 = $(a).attr('href').match(new RegExp(/(\.mp4|\.webm|\.ogg)/i)); |
| 29 |
let css = $(a).attr('class'); |
| 30 |
css = css !== undefined && css.includes('photonic-lb'); |
| 31 |
|
| 32 |
if (html5 !== null && !css) { |
| 33 |
$(a).addClass(Photonic_JS.lightbox_library + "-html5-video"); |
| 34 |
$(a).attr("data-rel", 'photonic-html5-video'); |
| 35 |
|
| 36 |
this.videoIndex++; |
| 37 |
} |
| 38 |
}; |
| 39 |
|
| 40 |
initialize(selector, group) { |
| 41 |
const $ = this.$; |
| 42 |
this.handleSolos(); |
| 43 |
const self = this; |
| 44 |
|
| 45 |
$(selector).each(function(i, current) { |
| 46 |
let lightbox_selector, |
| 47 |
rel = $(current).find('a.photonic-lightcase'); |
| 48 |
if (rel.length > 0) { |
| 49 |
rel = $(rel[0]).data('rel'); |
| 50 |
} |
| 51 |
|
| 52 |
lightbox_selector = selector.indexOf('data-rel') > -1 ? selector : 'a[data-rel="' + rel + '"]'; |
| 53 |
$(lightbox_selector).lightcase({ |
| 54 |
showSequenceInfo: false, |
| 55 |
transition: Photonic_JS.lc_transition_effect, |
| 56 |
slideshow: Photonic_JS.slideshow_mode, |
| 57 |
timeout: Photonic_JS.slideshow_interval, |
| 58 |
navigateEndless: Photonic_JS.lightbox_loop === '1', |
| 59 |
disableShrink: Photonic_JS.lc_disable_shrink === '1', |
| 60 |
attrPrefix: '', |
| 61 |
caption: ' ', |
| 62 |
swipe: true, |
| 63 |
onStart: { |
| 64 |
getVideoSize: function() { |
| 65 |
const elem = this, |
| 66 |
videoURL = $(elem).attr('data-html5-href');// || $(elem).attr('href'); |
| 67 |
if (lightbox_selector.indexOf('photonic-html5-video') > -1 || videoURL !== undefined) { |
| 68 |
self.getVideoSize(videoURL === undefined ? $(elem).attr('href') : videoURL, {height: window.innerHeight * 0.8, width: 800 }).then(function(dimensions) { |
| 69 |
$(elem).attr('data-lc-options', '{"width": ' + Math.round(dimensions.newWidth) + ', "height": ' + Math.round(dimensions.newHeight) + '}'); |
| 70 |
$('#lightcase-content').find('video').attr({ width: Math.round(dimensions.newWidth), height: Math.round(dimensions.newHeight)}).css({ width: Math.round(dimensions.newWidth), height: Math.round(dimensions.newHeight)}); |
| 71 |
lightcase.resize({ width: Math.round(dimensions.newWidth), height: Math.round(dimensions.newHeight) }); |
| 72 |
}); |
| 73 |
} |
| 74 |
} |
| 75 |
}, |
| 76 |
onFinish: { |
| 77 |
setHash: function() { |
| 78 |
if (this.length > 0) { |
| 79 |
self.setHash(this[0]); |
| 80 |
} |
| 81 |
const shareable = { |
| 82 |
'url': location.href, |
| 83 |
'title': Util.getText($(this).data('title')), |
| 84 |
'image': $(this).attr('href') |
| 85 |
}; |
| 86 |
self.addSocial('#lightcase-info', shareable); |
| 87 |
} |
| 88 |
}, |
| 89 |
onClose: { |
| 90 |
unsetHash: self.unsetHash |
| 91 |
} |
| 92 |
}); |
| 93 |
}); |
| 94 |
}; |
| 95 |
|
| 96 |
initializeForNewContainer(containerId) { |
| 97 |
this.initialize(containerId); |
| 98 |
}; |
| 99 |
} |
| 100 |
|