Skip to content

Commit

Permalink
Correctly transfer url hashes (Closes #61)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed Sep 19, 2016
1 parent 490c9d6 commit 3c9fcc7
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 48 deletions.
2 changes: 1 addition & 1 deletion dist/lity.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Lity - v2.0.0 - 2016-09-19
/*! Lity - v2.1.0 - 2016-09-19
* http://sorgalla.com/lity/
* Copyright (c) 2015-2016 Jan Sorgalla; Licensed MIT */
.lity {
Expand Down
69 changes: 46 additions & 23 deletions dist/lity.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Lity - v2.0.0 - 2016-09-19
/*! Lity - v2.1.0 - 2016-09-19
* http://sorgalla.com/lity/
* Copyright (c) 2015-2016 Jan Sorgalla; Licensed MIT */
(function(window, factory) {
Expand Down Expand Up @@ -96,8 +96,8 @@
return this;
}

function parseQueryParams(params){
var pairs = decodeURI(params).split('&');
function parseQueryParams(params) {
var pairs = decodeURI(params.split('#')[0]).split('&');
var obj = {}, p;

for (var i = 0, n = pairs.length; i < n; i++) {
Expand All @@ -116,6 +116,20 @@
return url + (url.indexOf('?') > -1 ? '&' : '?') + $.param(params);
}

function transferHash(originalUrl, newUrl) {
var pos = originalUrl.indexOf('#');

if (-1 === pos) {
return newUrl;
}

if (pos > 0) {
originalUrl = originalUrl.substr(pos);
}

return newUrl + originalUrl;
}

function error(msg) {
return $('<span class="lity-error"/>').append(msg);
}
Expand Down Expand Up @@ -190,13 +204,16 @@
}

return iframeHandler(
appendQueryParams(
'https://www.youtube' + (matches[2] || '') + '.com/embed/' + matches[4],
$.extend(
{
autoplay: 1
},
parseQueryParams(matches[5] || '')
transferHash(
target,
appendQueryParams(
'https://www.youtube' + (matches[2] || '') + '.com/embed/' + matches[4],
$.extend(
{
autoplay: 1
},
parseQueryParams(matches[5] || '')
)
)
)
);
Expand All @@ -210,13 +227,16 @@
}

return iframeHandler(
appendQueryParams(
'https://player.vimeo.com/video/' + matches[3],
$.extend(
{
autoplay: 1
},
parseQueryParams(matches[4] || '')
transferHash(
target,
appendQueryParams(
'https://player.vimeo.com/video/' + matches[3],
$.extend(
{
autoplay: 1
},
parseQueryParams(matches[4] || '')
)
)
)
);
Expand All @@ -230,11 +250,14 @@
}

return iframeHandler(
appendQueryParams(
'https://www.google.' + matches[3] + '/maps?' + matches[6],
{
output: matches[6].indexOf('layer=c') > 0 ? 'svembed' : 'embed'
}
transferHash(
target,
appendQueryParams(
'https://www.google.' + matches[3] + '/maps?' + matches[6],
{
output: matches[6].indexOf('layer=c') > 0 ? 'svembed' : 'embed'
}
)
)
);
}
Expand Down Expand Up @@ -563,7 +586,7 @@
}
}

lity.version = '2.0.0';
lity.version = '2.1.0';
lity.options = $.proxy(settings, lity, _defaultOptions);
lity.handlers = $.proxy(settings, lity, _defaultOptions.handlers);
lity.current = currentInstance;
Expand Down
2 changes: 1 addition & 1 deletion dist/lity.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/lity.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3c9fcc7

Please sign in to comment.