| 1 |
import {Lightbox} from "./Lightbox"; |
| 2 |
import * as Util from "../Util"; |
| 3 |
|
| 4 |
export class PhotonicFancybox extends Lightbox { |
| 5 |
constructor($) { |
| 6 |
super(); |
| 7 |
this.$ = $; |
| 8 |
} |
| 9 |
|
| 10 |
swipe(e) { |
| 11 |
const $ = this.$; |
| 12 |
$("#fancybox-wrap, .fancybox-wrap") |
| 13 |
.on('swipeleft', function() { $.fancybox.next(); }) |
| 14 |
.on('swiperight', function() { $.fancybox.prev(); }); |
| 15 |
}; |
| 16 |
|
| 17 |
formatTitle(title, currentArray, currentIndex, currentOpts) { |
| 18 |
if (currentArray[currentIndex].getAttribute('data-title') !== undefined && currentArray[currentIndex].getAttribute('data-title') !== '') { |
| 19 |
return Util.HTMLSanitizer.SanitizeHTML(currentArray[currentIndex].getAttribute('data-title')); |
| 20 |
} |
| 21 |
return title; |
| 22 |
}; |
| 23 |
|
| 24 |
changeVideoURL(element, regular, embed) { |
| 25 |
const $ = this.$; |
| 26 |
$(element).attr('href', embed); |
| 27 |
}; |
| 28 |
|
| 29 |
hostedVideo(a) { |
| 30 |
const $ = this.$; |
| 31 |
const html5 = $(a).attr('href').match(new RegExp(/(\.mp4|\.webm|\.ogg)/i)); |
| 32 |
let css = $(a).attr('class'); |
| 33 |
css = css !== undefined && css.includes('photonic-lb'); |
| 34 |
|
| 35 |
if (html5 !== null && !css) { |
| 36 |
$(a).addClass(Photonic_JS.lightbox_library + "-html5-video"); |
| 37 |
let $videos = $('#photonic-html5-videos'); |
| 38 |
$videos = $videos.length ? $videos : $('<div style="display:none;" id="photonic-html5-videos"></div>').appendTo(document.body); |
| 39 |
$videos.append('<div id="photonic-html5-video-' + this.videoIndex + '"><video controls preload="none"><source src="' + $(a).attr('href') + '" type="video/mp4">Your browser does not support HTML5 video.</video></div>'); |
| 40 |
$(a).attr('data-html5-href', $(a).attr('href')); |
| 41 |
$(a).attr('href', '#photonic-html5-video-' + this.videoIndex); |
| 42 |
this.videoIndex++; |
| 43 |
} |
| 44 |
}; |
| 45 |
|
| 46 |
initialize(selector, group) { |
| 47 |
const $ = this.$; |
| 48 |
const self = this; |
| 49 |
this.handleSolos(); |
| 50 |
|
| 51 |
if (Photonic_JS.slideshow_mode) { |
| 52 |
setInterval($.fancybox.next, parseInt(Photonic_JS.slideshow_interval, 10)); |
| 53 |
} |
| 54 |
|
| 55 |
$(document).on('click', 'a.photonic-fancybox', function(e) { |
| 56 |
e.preventDefault(); |
| 57 |
let videoID = $(this).attr('href'); |
| 58 |
let videoURL = $(this).attr('data-html5-href'); |
| 59 |
let $vclone; |
| 60 |
|
| 61 |
$('a.photonic-fancybox').fancybox({ |
| 62 |
overlayShow : true, |
| 63 |
overlayColor : '#000', |
| 64 |
overlayOpacity : 0.8, |
| 65 |
cyclic : true, |
| 66 |
titleShow : Photonic_JS.fbox_show_title === '1', |
| 67 |
titleFormat : self.formatTitle, |
| 68 |
titlePosition : Photonic_JS.fbox_title_position, |
| 69 |
type : $(this).attr('data-photonic-media-type') === 'image' ? 'image' : false, |
| 70 |
autoScale: true, |
| 71 |
scrolling: 'no', |
| 72 |
onStart: function(selectedArray, selectedIndex, selectedOpts) { |
| 73 |
const currentItem = selectedArray[selectedIndex]; |
| 74 |
videoID = $(currentItem).attr('href'); |
| 75 |
videoURL = $(currentItem).attr('data-html5-href'); |
| 76 |
}, |
| 77 |
onClosed : function() { |
| 78 |
$('#photonic-html5-external-videos').append($vclone); |
| 79 |
$('.fancybox-inline-tmp').remove(); |
| 80 |
}, |
| 81 |
onComplete : function() { |
| 82 |
if (videoURL !== undefined) { |
| 83 |
$vclone = $(videoID).clone(true); |
| 84 |
self.getVideoSize(videoURL, {height: window.innerHeight * 0.85, width: window.innerWidth * 0.85}).then(function(dimensions) { |
| 85 |
$(videoID).find('video').attr('width', dimensions.newWidth).attr('height', dimensions.newHeight); |
| 86 |
$(videoID).css({width: dimensions.newWidth, height: dimensions.newHeight}); |
| 87 |
$('#fancybox-content').css({width: dimensions.newWidth, height: dimensions.newHeight}); |
| 88 |
$('#fancybox-wrap').css({width: 'auto', height: 'auto' }); |
| 89 |
$.fancybox.resize(); |
| 90 |
}); |
| 91 |
} |
| 92 |
self.swipe(e); |
| 93 |
} |
| 94 |
}); |
| 95 |
this.click(); |
| 96 |
}); |
| 97 |
|
| 98 |
$('a.fancybox-video').fancybox({ type: 'iframe' }); |
| 99 |
$('a.fancybox-html5-video').each(function() { |
| 100 |
const videoID = $(this).attr('href'); |
| 101 |
const videoURL = $(this).attr('data-html5-href'); |
| 102 |
let $vclone; |
| 103 |
$(this).fancybox({ |
| 104 |
overlayShow : true, |
| 105 |
overlayColor : '#000', |
| 106 |
overlayOpacity : 0.8, |
| 107 |
type: 'inline', |
| 108 |
titleShow : Photonic_JS.fbox_show_title === '1', |
| 109 |
titleFormat : self.formatTitle, |
| 110 |
titlePosition : Photonic_JS.fbox_title_position, |
| 111 |
autoScale: true, |
| 112 |
scrolling: 'no', |
| 113 |
onStart: function() { |
| 114 |
$vclone = $(videoID).clone(true); |
| 115 |
self.getVideoSize(videoURL, {height: window.innerHeight * 0.85, width: window.innerWidth * 0.85}).then(function(dimensions) { |
| 116 |
$(videoID).find('video').attr('width', dimensions.newWidth).attr('height', dimensions.newHeight); |
| 117 |
$(videoID).css({width: dimensions.newWidth, height: dimensions.newHeight}); |
| 118 |
$('#fancybox-content').css({width: dimensions.newWidth + 'px', height: dimensions.newHeight + 'px'}); |
| 119 |
$('#fancybox-wrap').css({width: (dimensions.newWidth + 20) + 'px', height: (dimensions.newHeight + 20) + 'px'}); |
| 120 |
}); |
| 121 |
}, |
| 122 |
onClosed : function() { |
| 123 |
$('#photonic-html5-videos').append($vclone); |
| 124 |
$('.fancybox-inline-tmp').remove(); |
| 125 |
}, |
| 126 |
onComplete: function() { |
| 127 |
$.fancybox.resize(); |
| 128 |
} |
| 129 |
}); |
| 130 |
}); |
| 131 |
}; |
| 132 |
} |
| 133 |
|