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

Commit 60c3724

Browse files
committed
Support Google Maps search links
1 parent b4d7543 commit 60c3724

File tree

4 files changed

+55
-28
lines changed

4 files changed

+55
-28
lines changed

dist/jquery.fancybox.js

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ==================================================
2-
// fancyBox v3.1.23
2+
// fancyBox v3.1.24
33
//
44
// Licensed GPLv3 for open source use
55
// or fancyBox Commercial License for commercial use
@@ -2629,7 +2629,7 @@
26292629

26302630
$.fancybox = {
26312631

2632-
version : "3.1.23",
2632+
version : "3.1.24",
26332633
defaults : defaults,
26342634

26352635

@@ -3074,14 +3074,26 @@
30743074

30753075
// Examples:
30763076
// http://maps.google.com/?ll=48.857995,2.294297&spn=0.007666,0.021136&t=m&z=16
3077-
// http://maps.google.com/?ll=48.857995,2.294297&spn=0.007666,0.021136&t=m&z=16
3078-
// https://www.google.lv/maps/place/Googleplex/@37.4220041,-122.0833494,17z/data=!4m5!3m4!1s0x0:0x6c296c66619367e0!8m2!3d37.4219998!4d-122.0840572
3079-
google_maps : {
3077+
// https://www.google.com/maps/@37.7852006,-122.4146355,14.65z
3078+
// https://www.google.com/maps/place/Googleplex/@37.4220041,-122.0833494,17z/data=!4m5!3m4!1s0x0:0x6c296c66619367e0!8m2!3d37.4219998!4d-122.0840572
3079+
gmap_place : {
30803080
matcher : /(maps\.)?google\.([a-z]{2,3}(\.[a-z]{2})?)\/(((maps\/(place\/(.*)\/)?\@(.*),(\d+.?\d+?)z))|(\?ll=))(.*)?/i,
30813081
type : 'iframe',
30823082
url : function (rez) {
30833083
return '//maps.google.' + rez[2] + '/?ll=' + ( rez[9] ? rez[9] + '&z=' + Math.floor( rez[10] ) + ( rez[12] ? rez[12].replace(/^\//, "&") : '' ) : rez[12] ) + '&output=' + ( rez[12] && rez[12].indexOf('layer=c') > 0 ? 'svembed' : 'embed' );
30843084
}
3085+
},
3086+
3087+
// Examples:
3088+
// https://www.google.com/maps/search/Empire+State+Building/
3089+
// https://www.google.com/maps/search/?api=1&query=centurylink+field
3090+
// https://www.google.com/maps/search/?api=1&query=47.5951518,-122.3316393
3091+
gmap_search : {
3092+
matcher : /(maps\.)?google\.([a-z]{2,3}(\.[a-z]{2})?)\/(maps\/search\/)(.*)/i,
3093+
type : 'iframe',
3094+
url : function (rez) {
3095+
return '//maps.google.' + rez[2] + '/maps?q=' + rez[5].replace('query=', 'q=').replace('api=1', '') + '&output=embed';
3096+
}
30853097
}
30863098
};
30873099

@@ -3170,7 +3182,7 @@
31703182

31713183
item.contentProvider = provider;
31723184

3173-
item.opts.slideClass += ' fancybox-slide--' + ( provider == 'google_maps' ? 'map' : 'video' );
3185+
item.opts.slideClass += ' fancybox-slide--' + ( provider == 'gmap_place' || provider == 'gmap_search' ? 'map' : 'video' );
31743186
}
31753187

31763188
} else {
@@ -4728,11 +4740,14 @@
47284740
};
47294741
}
47304742

4743+
// Create new history entry only once
4744+
var shouldCreateHistory = true;
4745+
47314746
// Variable containing last hash value set by fancyBox
47324747
// It will be used to determine if fancyBox needs to close after hash change is detected
47334748
var currentHash = null;
47344749

4735-
// Throtlling the history change
4750+
// Throttling the history change
47364751
var timerID = null;
47374752

47384753
// Get info about gallery name and current index from url
@@ -4763,14 +4778,15 @@
47634778
// If we can find element matching 'data-fancybox' atribute, then trigger click event for that ..
47644779
$el = $( "[data-fancybox='" + $.escapeSelector( url.gallery ) + "']" ).eq( url.index - 1 );
47654780

4766-
if ( $el.length ) {
4767-
$el.trigger( 'click' );
4768-
4769-
} else {
4770-
4781+
if ( !$el.length ) {
47714782
// .. if not, try finding element by ID
4772-
$( "#" + $.escapeSelector( url.gallery ) + "" ).trigger( 'click' );
4783+
$el = $( "#" + $.escapeSelector( url.gallery ) + "" );
4784+
}
47734785

4786+
if ( $el.length ) {
4787+
shouldCreateHistory = false;
4788+
4789+
$el.trigger( 'click' );
47744790
}
47754791

47764792
}
@@ -4819,7 +4835,7 @@
48194835

48204836
},
48214837

4822-
'beforeShow.fb' : function( e, instance, current, firstRun ) {
4838+
'beforeShow.fb' : function( e, instance, current ) {
48234839
var gallery;
48244840

48254841
if ( current.opts.hash === false ) {
@@ -4843,10 +4859,12 @@
48434859
}
48444860

48454861
timerID = setTimeout(function() {
4846-
window.history[ firstRun ? 'pushState' : 'replaceState' ]( {} , document.title, window.location.pathname + window.location.search + '#' + currentHash );
4862+
window.history[ shouldCreateHistory ? 'pushState' : 'replaceState' ]( {} , document.title, window.location.pathname + window.location.search + '#' + currentHash );
48474863

48484864
timerID = null;
48494865

4866+
shouldCreateHistory = false;
4867+
48504868
}, 300);
48514869

48524870
} else {
@@ -4898,18 +4916,15 @@
48984916
currentHash = null;
48994917

49004918
$.fancybox.close();
4919+
4920+
shouldCreateHistory = true;
49014921
}
49024922

49034923
} else if ( url.gallery !== '' ) {
49044924
triggerFromUrl( url );
49054925
}
49064926
});
49074927

4908-
// If navigating away from current page
4909-
$(window).one('unload.fb popstate.fb', function() {
4910-
$.fancybox.getInstance( 'close', true, 0 );
4911-
});
4912-
49134928
// Check current hash and trigger click event on matching element to start fancyBox, if needed
49144929
triggerFromUrl( parseUrl() );
49154930

dist/jquery.fancybox.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

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

src/js/media.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,26 @@
9999

100100
// Examples:
101101
// http://maps.google.com/?ll=48.857995,2.294297&spn=0.007666,0.021136&t=m&z=16
102-
// http://maps.google.com/?ll=48.857995,2.294297&spn=0.007666,0.021136&t=m&z=16
103-
// https://www.google.lv/maps/place/Googleplex/@37.4220041,-122.0833494,17z/data=!4m5!3m4!1s0x0:0x6c296c66619367e0!8m2!3d37.4219998!4d-122.0840572
104-
google_maps : {
102+
// https://www.google.com/maps/@37.7852006,-122.4146355,14.65z
103+
// https://www.google.com/maps/place/Googleplex/@37.4220041,-122.0833494,17z/data=!4m5!3m4!1s0x0:0x6c296c66619367e0!8m2!3d37.4219998!4d-122.0840572
104+
gmap_place : {
105105
matcher : /(maps\.)?google\.([a-z]{2,3}(\.[a-z]{2})?)\/(((maps\/(place\/(.*)\/)?\@(.*),(\d+.?\d+?)z))|(\?ll=))(.*)?/i,
106106
type : 'iframe',
107107
url : function (rez) {
108108
return '//maps.google.' + rez[2] + '/?ll=' + ( rez[9] ? rez[9] + '&z=' + Math.floor( rez[10] ) + ( rez[12] ? rez[12].replace(/^\//, "&") : '' ) : rez[12] ) + '&output=' + ( rez[12] && rez[12].indexOf('layer=c') > 0 ? 'svembed' : 'embed' );
109109
}
110+
},
111+
112+
// Examples:
113+
// https://www.google.com/maps/search/Empire+State+Building/
114+
// https://www.google.com/maps/search/?api=1&query=centurylink+field
115+
// https://www.google.com/maps/search/?api=1&query=47.5951518,-122.3316393
116+
gmap_search : {
117+
matcher : /(maps\.)?google\.([a-z]{2,3}(\.[a-z]{2})?)\/(maps\/search\/)(.*)/i,
118+
type : 'iframe',
119+
url : function (rez) {
120+
return '//maps.google.' + rez[2] + '/maps?q=' + rez[5].replace('query=', 'q=').replace('api=1', '') + '&output=embed';
121+
}
110122
}
111123
};
112124

@@ -195,7 +207,7 @@
195207

196208
item.contentProvider = provider;
197209

198-
item.opts.slideClass += ' fancybox-slide--' + ( provider == 'google_maps' ? 'map' : 'video' );
210+
item.opts.slideClass += ' fancybox-slide--' + ( provider == 'gmap_place' || provider == 'gmap_search' ? 'map' : 'video' );
199211
}
200212

201213
} else {

0 commit comments

Comments
 (0)