Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 3a5a617

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master' into 3.0
2 parents 90d8571 + 8acf7b7 commit 3a5a617

9 files changed

+325
-243
lines changed

dist/jquery.fancybox.js

+161-120
Large diffs are not rendered by default.

dist/jquery.fancybox.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "fancybox",
33
"description": "Touch enabled, responsive and fully customizable jQuery lightbox script",
4-
"version": "3.0.46",
4+
"version": "3.0.47",
55
"homepage": "http://fancyapps.com/fancybox/",
66
"main": "./dist/jquery.fancybox.min.js",
77
"author": "fancyApps",

src/js/core.js

+19-23
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@
189189

190190
rect = el.getBoundingClientRect();
191191

192-
return rect.bottom > 0 &&
193-
rect.right > 0 &&
192+
return rect.bottom > 0 && rect.right > 0 &&
194193
rect.left < (window.innerWidth || document.documentElement.clientWidth) &&
195194
rect.top < (window.innerHeight || document.documentElement.clientHeight);
196195
};
@@ -526,7 +525,10 @@
526525
$( window ).on('orientationchange.fb resize.fb', function(e) {
527526
requestAFrame(function() {
528527

529-
if ( e && e.originalEvent && e.originalEvent.type == "orientationchange" ) {
528+
if ( e && e.originalEvent && e.originalEvent.type === "resize" ) {
529+
self.update();
530+
531+
} else {
530532
self.$refs.slider_wrap.hide();
531533

532534
requestAFrame(function () {
@@ -535,8 +537,6 @@
535537
self.update();
536538
});
537539

538-
} else {
539-
self.update();
540540
}
541541

542542
});
@@ -917,35 +917,31 @@
917917

918918
self.trigger( 'beforeZoom' + type );
919919

920-
requestAFrame(function() {
920+
$what.css( 'transition', 'all ' + duration + 'ms' );
921921

922-
$what.css( 'transition', 'all ' + duration + 'ms' );
922+
$.fancybox.setTranslate( $what, end );
923923

924-
$.fancybox.setTranslate( $what, end );
924+
setTimeout(function() {
925+
var reset;
925926

926-
setTimeout(function() {
927-
requestAFrame(function() {
928-
var reset;
927+
$what.css( 'transition', 'none' );
929928

930-
$what.css( 'transition', 'none' );
929+
reset = $.fancybox.getTranslate( $what );
931930

932-
reset = $.fancybox.getTranslate( $what );
931+
reset.scaleX = 1;
932+
reset.scaleY = 1;
933933

934-
reset.scaleX = 1;
935-
reset.scaleY = 1;
934+
// Reset scalex/scaleY values; this helps for perfomance
935+
$.fancybox.setTranslate( $what, reset );
936936

937-
// Reset scalex/scaleY values; this helps for perfomance
938-
$.fancybox.setTranslate( $what, reset );
937+
self.trigger( 'afterZoom' + type );
939938

940-
self.trigger( 'afterZoom' + type );
939+
callback.apply( self );
941940

942-
callback.apply( self );
941+
self.isAnimating = false;
943942

944-
self.isAnimating = false;
945-
});
946-
}, duration);
943+
}, duration);
947944

948-
});
949945

950946
return true;
951947

src/js/fullscreen.js

+119-81
Original file line numberDiff line numberDiff line change
@@ -7,117 +7,155 @@
77
;(function (document, $) {
88
'use strict';
99

10-
var FullScreen = function( instance ) {
11-
12-
this.instance = instance;
13-
14-
this.init();
15-
16-
};
17-
18-
$.extend( FullScreen.prototype, {
19-
20-
$button : null,
21-
22-
init : function() {
23-
var self = this;
24-
25-
if ( !self.isAvailable() ) {
26-
return;
10+
// Collection of methods supported by user browser
11+
var fn = (function () {
12+
13+
var fnMap = [
14+
[
15+
'requestFullscreen',
16+
'exitFullscreen',
17+
'fullscreenElement',
18+
'fullscreenEnabled',
19+
'fullscreenchange',
20+
'fullscreenerror'
21+
],
22+
// new WebKit
23+
[
24+
'webkitRequestFullscreen',
25+
'webkitExitFullscreen',
26+
'webkitFullscreenElement',
27+
'webkitFullscreenEnabled',
28+
'webkitfullscreenchange',
29+
'webkitfullscreenerror'
30+
31+
],
32+
// old WebKit (Safari 5.1)
33+
[
34+
'webkitRequestFullScreen',
35+
'webkitCancelFullScreen',
36+
'webkitCurrentFullScreenElement',
37+
'webkitCancelFullScreen',
38+
'webkitfullscreenchange',
39+
'webkitfullscreenerror'
40+
41+
],
42+
[
43+
'mozRequestFullScreen',
44+
'mozCancelFullScreen',
45+
'mozFullScreenElement',
46+
'mozFullScreenEnabled',
47+
'mozfullscreenchange',
48+
'mozfullscreenerror'
49+
],
50+
[
51+
'msRequestFullscreen',
52+
'msExitFullscreen',
53+
'msFullscreenElement',
54+
'msFullscreenEnabled',
55+
'MSFullscreenChange',
56+
'MSFullscreenError'
57+
]
58+
];
59+
60+
var val;
61+
var ret = {};
62+
var i, j;
63+
64+
for ( i = 0; i < fnMap.length; i++ ) {
65+
val = fnMap[ i ];
66+
67+
if ( val && val[ 1 ] in document ) {
68+
for ( j = 0; j < val.length; j++ ) {
69+
ret[ fnMap[ 0 ][ j ] ] = val[ j ];
70+
}
71+
72+
return ret;
2773
}
74+
}
2875

29-
self.$button = $('<button data-fancybox-fullscreen class="fancybox-button fancybox-button--fullscreen" title="Full screen (F)"></button>')
30-
.appendTo( self.instance.$refs.buttons );
31-
32-
self.instance.$refs.container.on('click.fb-fullscreen', '[data-fancybox-fullscreen]', function(e) {
33-
34-
e.stopPropagation();
35-
e.preventDefault();
36-
37-
self.toggle();
38-
39-
});
40-
41-
$(document).on('onUpdate.fb', function(e, instance) {
42-
self.$button.toggle( !!instance.current.opts.fullScreen );
43-
44-
self.$button.toggleClass('fancybox-button-shrink', self.isActivated() );
45-
46-
});
76+
return false;
77+
})();
4778

48-
$(document).on('afterClose.fb', function() {
49-
self.exit();
50-
});
79+
if ( !fn ) {
80+
return;
81+
}
5182

52-
},
83+
var FullScreen = {
84+
request : function ( elem ) {
5385

54-
isAvailable : function() {
55-
var element = this.instance.$refs.container.get(0);
86+
elem = elem || document.documentElement;
5687

57-
return !!(element.requestFullscreen || element.msRequestFullscreen || element.mozRequestFullScreen || element.webkitRequestFullscreen);
88+
elem[ fn.requestFullscreen ]( elem.ALLOW_KEYBOARD_INPUT );
5889

5990
},
60-
61-
isActivated : function() {
62-
return !(!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement);
63-
91+
exit : function () {
92+
document[ fn.exitFullscreen ]();
6493
},
94+
toggle : function ( elem ) {
6595

66-
launch : function() {
67-
var element = this.instance.$refs.container.get(0);
68-
69-
if ( !element || this.instance.isClosing ) {
70-
return;
96+
if ( this.isFullscreen() ) {
97+
this.exit();
98+
} else {
99+
this.request( elem );
71100
}
72101

73-
if (element.requestFullscreen) {
74-
element.requestFullscreen();
102+
},
103+
isFullscreen : function() {
104+
return Boolean( document[ fn.fullscreenElement ] );
105+
},
106+
enabled : function() {
107+
return Boolean( document[ fn.fullscreenEnabled ] );
108+
}
109+
};
75110

76-
} else if (element.msRequestFullscreen) {
77-
element.msRequestFullscreen();
111+
$(document).on({
112+
'onInit.fb' : function(e, instance) {
113+
var $container;
78114

79-
} else if (element.mozRequestFullScreen) {
80-
element.mozRequestFullScreen();
115+
if ( instance && !!instance.opts.fullScreen && !instance.FullScreen) {
116+
$container = instance.$refs.container;
81117

82-
} else if (element.webkitRequestFullscreen) {
83-
element.webkitRequestFullscreen(element.ALLOW_KEYBOARD_INPUT);
84-
}
118+
instance.$refs.button_fs = $('<button data-fancybox-fullscreen class="fancybox-button fancybox-button--fullscreen" title="Full screen (F)"></button>')
119+
.appendTo( instance.$refs.buttons );
85120

86-
},
121+
$container.on('click.fb-fullscreen', '[data-fancybox-fullscreen]', function(e) {
87122

88-
exit : function() {
123+
e.stopPropagation();
124+
e.preventDefault();
89125

90-
if (document.exitFullscreen) {
91-
document.exitFullscreen();
126+
FullScreen.toggle( $container[ 0 ] );
92127

93-
} else if (document.msExitFullscreen) {
94-
document.msExitFullscreen();
128+
});
95129

96-
} else if (document.mozCancelFullScreen) {
97-
document.mozCancelFullScreen();
130+
if ( instance.opts.fullScreen.requestOnStart === true ) {
131+
FullScreen.request( $container[ 0 ] );
132+
}
98133

99-
} else if (document.webkitExitFullscreen) {
100-
document.webkitExitFullscreen();
101134
}
102135

103-
},
104-
105-
toggle : function() {
106-
107-
if ( this.isActivated() ) {
108-
this.exit();
136+
}, 'beforeMove.fb' : function(e, instance) {
109137

110-
} else if ( this.isAvailable() ) {
111-
this.launch();
138+
if ( instance && instance.$refs.button_fs ) {
139+
instance.$refs.button_fs.toggle( !!instance.current.opts.fullScreen );
112140
}
113141

142+
}, 'beforeClose.fb': function() {
143+
FullScreen.exit();
114144
}
115145
});
116146

117-
$(document).on('onInit.fb', function(e, instance) {
147+
$(document).on(fn.fullscreenchange, function() {
148+
var instance = $.fancybox.getInstance();
149+
var $what = instance ? instance.current.$placeholder : null;
150+
151+
if ( $what ) {
152+
153+
// If image is zooming, then this will force it to stop and reposition properly
154+
$what.css( 'transition', 'none' );
155+
156+
instance.isAnimating = false;
118157

119-
if ( !!instance.opts.fullScreen && !instance.FullScreen) {
120-
instance.FullScreen = new FullScreen( instance );
158+
instance.update( true, true, 0 );
121159
}
122160

123161
});

src/js/guestures.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -742,15 +742,15 @@
742742

743743
$(document).on('onActivate.fb', function (e, instance) {
744744

745-
if ( !instance.Guestures ) {
745+
if ( instance && !instance.Guestures ) {
746746
instance.Guestures = new Guestures( instance );
747747
}
748748

749749
});
750750

751751
$(document).on('beforeClose.fb', function (e, instance) {
752752

753-
if ( instance.Guestures ) {
753+
if ( instance && instance.Guestures ) {
754754
instance.Guestures.destroy();
755755
}
756756

src/js/hash.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@
7777

7878
// Get gallery name from current instance
7979
function getGallery( instance ) {
80-
var opts = instance.current ? instance.current.opts : instance.opts;
80+
var opts;
81+
82+
if ( !instance ) {
83+
return false;
84+
}
85+
86+
opts = instance.current ? instance.current.opts : instance.opts;
8187

8288
return opts.$orig ? opts.$orig.data( 'fancybox' ) : ( opts.hash || '' );
8389
}
@@ -117,15 +123,15 @@
117123
var gallery = getGallery( instance );
118124

119125
// Make sure gallery start index matches index from hash
120-
if ( url.gallery && gallery == url.gallery ) {
126+
if ( gallery && url.gallery && gallery == url.gallery ) {
121127
instance.currIndex = url.index - 1;
122128
}
123129

124130
}, 'beforeMove.fb' : function( e, instance, current ) {
125131
var gallery = getGallery( instance );
126132

127133
// Update window hash
128-
if ( gallery !== '' ) {
134+
if ( gallery && gallery !== '' ) {
129135

130136
if ( window.location.hash.indexOf( gallery ) < 0 ) {
131137
instance.opts.origHash = window.location.hash;
@@ -144,10 +150,10 @@
144150

145151
}, 'beforeClose.fb' : function( e, instance, current ) {
146152
var gallery = getGallery( instance );
147-
var origHash = instance.opts.origHash ? instance.opts.origHash : '';
153+
var origHash = instance && instance.opts.origHash ? instance.opts.origHash : '';
148154

149155
// Remove hash from location bar
150-
if ( gallery !== '' ) {
156+
if ( gallery && gallery !== '' ) {
151157
if ( "pushState" in history ) {
152158
history.pushState( '', document.title, window.location.pathname + window.location.search + origHash );
153159

0 commit comments

Comments
 (0)