PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.41
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.41
3.36 3.35 3.34 3.33 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 2.31 2.32 2.33 2.34 2.40 2.41 2.42 2.43 2.44 All 141 releases
photonic / include / scripts / front-end / src / lightboxes / Lightbox_Magnific.js

Lightbox_Magnific.js in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 2.41, at include/scripts/front-end/src/lightboxes/Lightbox_Magnific.js

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