| 1 |
import {Lightbox} from "./Lightbox"; |
| 2 |
import * as Util from "../Util"; |
| 3 |
|
| 4 |
export class PhotonicMagnific extends Lightbox { |
| 5 |
constructor($) { |
| 6 |
super(); |
| 7 |
this.$ = $; |
| 8 |
|
| 9 |
this.$.expr[':'].parents = function(a,i,m){ |
| 10 |
return jQuery(a).parents(m[3]).length < 1; |
| 11 |
}; |
| 12 |
} |
| 13 |
|
| 14 |
initialize(selector, group) { |
| 15 |
this.handleSolos(); |
| 16 |
const self = this; |
| 17 |
const $ = self.$; |
| 18 |
|
| 19 |
$('a.photonic-magnific').each(function (i, a) { |
| 20 |
const $a = $(a); |
| 21 |
if ($a.attr('data-photonic-media-type') === 'video') { |
| 22 |
$a.removeClass('mfp-image'); |
| 23 |
$a.addClass('mfp-inline'); |
| 24 |
} |
| 25 |
else if ($a.attr('data-photonic-media-type') === 'image') { |
| 26 |
$a.addClass('mfp-image'); |
| 27 |
$a.removeClass('mfp-inline'); |
| 28 |
} |
| 29 |
|
| 30 |
}); |
| 31 |
|
| 32 |
$(selector).each(function(idx, obj) { |
| 33 |
$(obj).magnificPopup({ |
| 34 |
delegate: 'a.photonic-magnific', |
| 35 |
type: 'image', |
| 36 |
gallery: { |
| 37 |
enabled: true |
| 38 |
}, |
| 39 |
image: { |
| 40 |
titleSrc: 'data-title' |
| 41 |
}, |
| 42 |
callbacks: { |
| 43 |
change: function () { |
| 44 |
const $content = $(this.content), |
| 45 |
videoId = $content.attr('id'); |
| 46 |
if (videoId !== undefined && videoId.indexOf('photonic-video') > -1) { |
| 47 |
const videoURL = $content.find('video').find('source').attr('src'); |
| 48 |
if (videoURL !== undefined) { |
| 49 |
self.getVideoSize(videoURL, {height: window.innerHeight * 0.8, width: window.innerWidth * 0.8 }).then(function(dimensions) { |
| 50 |
$content.find('video').attr({ |
| 51 |
height: dimensions.newHeight, |
| 52 |
width: dimensions.newWidth |
| 53 |
}); |
| 54 |
}); |
| 55 |
} |
| 56 |
} |
| 57 |
if (this.currItem.el.length > 0) { |
| 58 |
self.setHash(this.currItem.el[0]); |
| 59 |
} |
| 60 |
if (this.currItem.type === 'inline') { |
| 61 |
$(this.content).append($('<div></div>').html(Util.HTMLSanitizer.SanitizeHTML($(this.currItem.el).data('title')))); |
| 62 |
} |
| 63 |
}, |
| 64 |
imageLoadComplete: function() { |
| 65 |
const shareable = { |
| 66 |
'url': location.href, |
| 67 |
'title': Util.getText($(this.currItem.el).data('title')), |
| 68 |
'image': $(this.currItem.el).attr('href') |
| 69 |
}; |
| 70 |
self.addSocial('.mfp-figure', shareable); |
| 71 |
}, |
| 72 |
close: function() { |
| 73 |
self.unsetHash(); |
| 74 |
} |
| 75 |
} |
| 76 |
}); |
| 77 |
}); |
| 78 |
}; |
| 79 |
|
| 80 |
initializeForNewContainer(selector) { |
| 81 |
this.initialize(selector); |
| 82 |
}; |
| 83 |
|
| 84 |
changeVideoURL(element, regular, embed) { |
| 85 |
this.$(element).attr('href', regular); |
| 86 |
}; |
| 87 |
|
| 88 |
hostedVideo(a) { |
| 89 |
const $ = this.$; |
| 90 |
const html5 = $(a).attr('href').match(new RegExp(/(\.mp4|\.webm|\.ogg)/i)); |
| 91 |
let css = $(a).attr('class'); |
| 92 |
css = css !== undefined && css.includes('photonic-lb'); |
| 93 |
|
| 94 |
if (html5 !== null && !css) { |
| 95 |
$(a).addClass(Photonic_JS.lightbox_library + "-html5-video"); |
| 96 |
let $videos = $('#photonic-html5-videos'); |
| 97 |
$videos = $videos.length ? $videos : $('<div style="display:none;" id="photonic-html5-videos"></div>').appendTo(document.body); |
| 98 |
$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>'); |
| 99 |
$(a).attr('data-html5-href', $(a).attr('href')); |
| 100 |
$(a).attr('href', '#photonic-html5-video-' + this.videoIndex); |
| 101 |
this.videoIndex++; |
| 102 |
} |
| 103 |
}; |
| 104 |
|
| 105 |
initializeSolos() { |
| 106 |
const self = this; |
| 107 |
const $ = self.$; |
| 108 |
|
| 109 |
if (Photonic_JS.lightbox_for_all) { |
| 110 |
$('a.photonic-magnific').filter(':parents(.photonic-level-1)').each(function(idx, obj) { // Solo images |
| 111 |
$(obj).magnificPopup({ |
| 112 |
type: 'image' |
| 113 |
}); |
| 114 |
}); |
| 115 |
} |
| 116 |
|
| 117 |
if (Photonic_JS.lightbox_for_videos) { |
| 118 |
$('.magnific-video').each(function(idx, obj) { |
| 119 |
$(obj).magnificPopup({ |
| 120 |
type: 'iframe' |
| 121 |
}); |
| 122 |
}); |
| 123 |
|
| 124 |
$('.magnific-html5-video').each(function(idx, obj) { |
| 125 |
$(obj).magnificPopup({ |
| 126 |
type: 'inline', |
| 127 |
callbacks: { |
| 128 |
change: function () { |
| 129 |
const $content = $(this.content), |
| 130 |
videoId = $content.attr('id'); |
| 131 |
if (videoId !== undefined && videoId.indexOf('photonic-html5-video') > -1) { |
| 132 |
const videoURL = $content.find('video').find('source').attr('src'); |
| 133 |
if (videoURL !== undefined) { |
| 134 |
self.getVideoSize(videoURL, {height: window.innerHeight * 0.8, width: window.innerWidth * 0.8 }).then(function(dimensions) { |
| 135 |
$content.find('video').attr({ |
| 136 |
height: dimensions.newHeight, |
| 137 |
width: dimensions.newWidth |
| 138 |
}); |
| 139 |
}); |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
}); |
| 145 |
}); |
| 146 |
} |
| 147 |
}; |
| 148 |
} |
| 149 |
|