From 28204762ab26774b026f402ccee4ac2beb4ebff8 Mon Sep 17 00:00:00 2001
From: Thomas Gelf <thomas@gelf.net>
Date: Mon, 29 Feb 2016 21:40:48 +0100
Subject: [PATCH] js: fix urls for dynamic css/js reloads

---
 public/js/icinga.js    |  2 +-
 public/js/icinga/ui.js | 14 ++++++++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/public/js/icinga.js b/public/js/icinga.js
index 06c797a29..b52c19afc 100644
--- a/public/js/icinga.js
+++ b/public/js/icinga.js
@@ -217,7 +217,7 @@
                 $ = undefined;
 
                 oldjQuery.getScript(
-                    oldConfig.baseUrl + 'js/icinga.min.js'
+                    oldConfig.baseUrl.replace(/\/$/, '') + '/js/icinga.min.js'
                 ).done(function () {
                     var jQuery = window.jQuery;
                     window.icinga = new window.Icinga(oldConfig);
diff --git a/public/js/icinga/ui.js b/public/js/icinga/ui.js
index a797aab1f..09876e954 100644
--- a/public/js/icinga/ui.js
+++ b/public/js/icinga/ui.js
@@ -99,12 +99,18 @@
             $('link').each(function() {
                 var $oldLink = $(this);
                 if ($oldLink.hasAttr('type') && $oldLink.attr('type').indexOf('css') > -1) {
+                    var base = location.protocol + '//' + location.host;
+                    if (location.port) {
+                        base += location.port;
+                    }
+                    var url = icinga.utils.addUrlParams(
+                        $(this).attr('href'),
+                        { id: new Date().getTime() }
+                    );
+
                     var $newLink = $oldLink.clone().attr(
                         'href',
-                        icinga.utils.addUrlParams(
-                            $(this).attr('href'),
-                            { id: new Date().getTime() }
-                        )
+                        base + '/' + url.replace(/^\//, '')
                     ).on('load', function() {
                         icinga.ui.fixControls();
                         $oldLink.remove();