| 1 |
import {Lightbox} from "./Lightbox"; |
| 2 |
import * as Util from "../Util"; |
| 3 |
|
| 4 |
export class PhotonicFancybox3 extends Lightbox { |
| 5 |
constructor($) { |
| 6 |
super(); |
| 7 |
|
| 8 |
this.$ = $; |
| 9 |
this.buttons = []; |
| 10 |
if (Photonic_JS.fb3_zoom) { |
| 11 |
this.buttons.push('zoom'); |
| 12 |
} |
| 13 |
if (Photonic_JS.fb3_slideshow) { |
| 14 |
this.buttons.push('slideShow'); |
| 15 |
} |
| 16 |
if (Photonic_JS.fb3_fullscreen_button) { |
| 17 |
this.buttons.push('fullScreen'); |
| 18 |
} |
| 19 |
if (Photonic_JS.fb3_download) { |
| 20 |
this.buttons.push('download'); |
| 21 |
} |
| 22 |
if (Photonic_JS.fb3_thumbs_button) { |
| 23 |
this.buttons.push('thumbs'); |
| 24 |
} |
| 25 |
this.buttons.push('close'); |
| 26 |
} |
| 27 |
|
| 28 |
soloImages() { |
| 29 |
const $ = this.$; |
| 30 |
$('a[href]').filter(function() { |
| 31 |
return /(\.jpg|\.jpeg|\.bmp|\.gif|\.png)/i.test( $(this).attr('href')); |
| 32 |
}).addClass("photonic-fancybox").addClass(Photonic_JS.lightbox_library); |
| 33 |
}; |
| 34 |
|
| 35 |
hostedVideo(a) { |
| 36 |
const html5 = a.getAttribute('href').match(new RegExp(/(\.mp4|\.webm|\.ogg)/i)), |
| 37 |
css = a.classList.contains('photonic-lb'); |
| 38 |
|
| 39 |
if (html5 !== null && !css) { |
| 40 |
a.classList.add(Photonic_JS.lightbox_library + "-html5-video"); |
| 41 |
this.videoIndex++; |
| 42 |
} |
| 43 |
}; |
| 44 |
|
| 45 |
changeVideoURL(element, regular, embed) { |
| 46 |
element.setAttribute('href', embed); // Don't need this for Fancybox3, but short URLs don't support "start" or "t" parameters; embed and regular URLs do. |
| 47 |
}; |
| 48 |
|
| 49 |
initialize(selector, group) { |
| 50 |
this.handleSolos(); |
| 51 |
const self = this; |
| 52 |
const $ = self.$; |
| 53 |
|
| 54 |
let lightbox_selector; |
| 55 |
if (group !== null && group !== undefined) { |
| 56 |
lightbox_selector = 'a[data-fancybox="' + group + '"]'; |
| 57 |
} |
| 58 |
else if (selector !== null && selector !== undefined) { |
| 59 |
lightbox_selector = selector + ' a.photonic-fancybox'; |
| 60 |
} |
| 61 |
else { |
| 62 |
lightbox_selector = 'a.photonic-fancybox'; |
| 63 |
} |
| 64 |
|
| 65 |
$(lightbox_selector).fancybox({ |
| 66 |
defaultType: 'image', |
| 67 |
hash: false, |
| 68 |
caption: function(instance, item) { |
| 69 |
return Util.HTMLSanitizer.SanitizeHTML($(this).data('title')); |
| 70 |
}, |
| 71 |
loop: Photonic_JS.lightbox_loop === '1', |
| 72 |
buttons: self.buttons, |
| 73 |
slideShow: { |
| 74 |
autoStart: Photonic_JS.slideshow_mode, |
| 75 |
speed: parseInt(Photonic_JS.slideshow_interval, 10) |
| 76 |
}, |
| 77 |
thumbs: { |
| 78 |
autoStart: Photonic_JS.fb3_thumbs === '1', |
| 79 |
hideOnClose: true |
| 80 |
}, |
| 81 |
fullScreen: { |
| 82 |
autoStart: Photonic_JS.fb3_fullscreen === '1' |
| 83 |
}, |
| 84 |
protect: Photonic_JS.fb3_disable_right_click === '1', |
| 85 |
transitionEffect: Photonic_JS.fb3_transition_effect, |
| 86 |
transitionDuration: Photonic_JS.fb3_transition_speed, |
| 87 |
afterShow: function(instance, slide) { |
| 88 |
const shareable = { |
| 89 |
'url': location.href, |
| 90 |
'title': $(slide).length > 0 && $(slide)[0].opts !== undefined && $(slide)[0].opts.$orig !== undefined ? Util.getText($(slide)[0].opts.$orig.attr('title')) : '', |
| 91 |
'image': $(slide).length > 0 && $(slide)[0].opts !== undefined && $(slide)[0].opts.$orig !== undefined ? $(slide)[0].opts.$orig.attr('href') : '' |
| 92 |
}; |
| 93 |
self.addSocial('.fancybox-toolbar', shareable, 'afterbegin'); |
| 94 |
}, |
| 95 |
beforeShow: function() { |
| 96 |
const videoID = this.src, |
| 97 |
videoURL = this.opts.html5Href; |
| 98 |
if (videoURL !== undefined) { |
| 99 |
self.getVideoSize(videoURL, {height: window.innerHeight * 0.85, width: window.innerWidth * 0.85}).then(function(dimensions) { |
| 100 |
$(videoID).find('video').attr('width', dimensions.newWidth).attr('height', dimensions.newHeight); |
| 101 |
$(videoID).css({width: dimensions.newWidth, height: dimensions.newHeight}); |
| 102 |
}); |
| 103 |
} |
| 104 |
self.setHash(this.opts.photonicDeep); |
| 105 |
}, |
| 106 |
afterClose: function() { |
| 107 |
self.unsetHash(); |
| 108 |
} |
| 109 |
}); |
| 110 |
|
| 111 |
$('a.fancybox3-video,a.fancybox3-html5-video').fancybox({ |
| 112 |
youtube: { } |
| 113 |
}); |
| 114 |
}; |
| 115 |
|
| 116 |
initializeForNewContainer(containerId) { |
| 117 |
this.initialize(containerId); |
| 118 |
}; |
| 119 |
|
| 120 |
} |
| 121 |
|