Skip to content

Commit

Permalink
Support for relative urls with custom ports
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Jan 23, 2017
1 parent 0d8f52d commit a9dfd30
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,4 +630,20 @@ function setupMobileTicker() {
startEmpty:true
});

}

// Parses passed url and looks for the form 'https://:34343/something'. If after double slash after protocol there is no host present, a local host is assumed and is placed before port part.
// The url from the example will be transformed into 'https://somehost:34343/something', where somehost is the host at which the muximux was accessed.
function parseRelativeUrlWithPortIfPresent(url) {
var parts = /^(http|https|ftp):\/\/:(\d+)(.*)$/.exec(url),
fullUrl;
if(parts) {
var protocol = parts[1],
port = parts[2],
relativePath = parts[3];
fullUrl = protocol + '://' + window.location.hostname + ':' + port + relativePath;
} else {
fullUrl = url;
}
return fullUrl;
}
2 changes: 1 addition & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jQuery(document).ready(function($) {
selectedContent.children('iframe').attr('src', selectedContent.children('iframe').attr('src'));
});
var sifsrc = selectedContent.children('iframe').attr('src');
var srcUrl = selectedContent.children('iframe').data('src');
var srcUrl = parseRelativeUrlWithPortIfPresent(selectedContent.children('iframe').data('src'));
if (sifsrc === undefined || sifsrc === "") {
selectedContent.children('iframe').attr('src', srcUrl);
}
Expand Down

0 comments on commit a9dfd30

Please sign in to comment.