From a9dfd308c77722600198a9db41e06e00a32122a8 Mon Sep 17 00:00:00 2001 From: Mateusz Galazyn Date: Mon, 23 Jan 2017 16:51:35 +0100 Subject: [PATCH] Support for relative urls with custom ports --- js/functions.js | 16 ++++++++++++++++ js/main.js | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/js/functions.js b/js/functions.js index 15a12d9..0b4a950 100644 --- a/js/functions.js +++ b/js/functions.js @@ -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; } \ No newline at end of file diff --git a/js/main.js b/js/main.js index 33cdc23..b3f930c 100644 --- a/js/main.js +++ b/js/main.js @@ -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); }