reload openweathermap widget by removing and re-adding script and widget
authorgregor herrmann <gregor@toastfreeware.priv.at>
Tue, 20 Nov 2018 21:20:12 +0000 (22:20 +0100)
committergregor herrmann <gregor@toastfreeware.priv.at>
Tue, 20 Nov 2018 21:20:12 +0000 (22:20 +0100)
not very elegant. but finally it at least works.

web/static/seepark_web.css
web/static/seepark_web.js
web/templates/seepark_web.html

index 174c4eb..ce8f885 100644 (file)
@@ -26,6 +26,7 @@ body {
 
 #openweathermap-widget-15 {
     width: 300px;
+    height: 231px;
 }
 
 #windyiframe {
index 7e727a1..5aaf55a 100644 (file)
@@ -217,7 +217,7 @@ dayschart('chart_air_7',     'Die Luft (Woche)',   7, '%a %d');
 dayschart('chart_air_31',    'Die Luft (Monat)',  31, '%Y-%m-%d');
 dayschart('chart_air_365',   'Die Luft (Jahr)',  365, '%b %Y');
 
-// reload current values
+// reload current values + owm script
 setInterval(
        function() {
                var airvalue   = document.getElementById('currentairvalue');
@@ -242,6 +242,14 @@ setInterval(
                        .catch(function(error) {
                                console.log(error);
                        });
+
+               var owmwidget = document.getElementById('openweathermap-widget-15');
+               owmwidget.removeChild(owmwidget.childNodes[0]);
+               var owmscript = document.head.lastElementChild;
+               document.head.removeChild(owmscript);
+               var newowmscript = document.createElement('script');
+               newowmscript.src = '//openweathermap.org/themes/openweathermap/assets/vendor/owm/js/weather-widget-generator.js';
+               document.head.appendChild(newowmscript);
        },
        refresh_interval
 );
index 59d32e2..5273320 100644 (file)
@@ -1,6 +1,8 @@
 <!DOCTYPE html>
 <html lang="de">
        <head>
+               <title>Seepark Obsteig</title>
+
                <!-- mobile first, yeah -->
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
 
@@ -22,8 +24,6 @@
 
                <!-- Load owm script -->
                <script async="true" charset="utf-8" src="//openweathermap.org/themes/openweathermap/assets/vendor/owm/js/weather-widget-generator.js"></script>
-
-               <title>Seepark Obsteig</title>
        </head>
        <body>
                <h1>Daten zum Seepark Obsteig</h1>