Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Cumulus MX V4 beta test release 4.0.0 (build 4019) - 03 April 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

Day / Night 'switcher'

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Post Reply
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Day / Night 'switcher'

Post by beteljuice »

In response to the DEMANDS of one :?

Cut 'n' Paste the following:

Code: Select all

<script type="text/javascript">
<!--
/* 
day / night decider / graphic 'switcher' by beteljuice Feb 09
put this code at the bottom of your Cumulus *****T.htm page just before the closing </body> tag

Where you want the graphic(s) on your page use:

<span id="day_night"></span> or you could use <div ..

*/

// user set variables
var day_graphic = "weather_graphics/big_sun.png";   // location of your day graphic
var day_text = "It's Day Time";   // mouseover text for day graphic
var night_graphic = "weather_graphics/night.png";   // location of your night graphic
var night_text = "It's Night Time";   // mouseover text for night graphic
// END user variables


var hour = "<#hour>";
var minutes = "<#minute>";

var day_start = "<#sunrise>";
var day_end = "<#sunset>";
var day_length = "<#daylength>";


	day_start = day_start.replace(':', '') *1;	// turn into a 'real' number
	day_end = day_end.replace(':', '') *1;	// turn into a 'real' number
	obs_time = (hour + minutes) *1;	// turn into a 'real' number
	sun_check = day_length.substr(0, 2) *1; // get the hours part of day length a make numeric

	if(!isNaN(day_start) && !isNaN(day_end) && !isNaN(obs_time)) { // make sure inputs are valid (numeric)

		if(obs_time < day_start || obs_time > day_end) {		// must be night
			night = true;
		} else {
			night = false;
		}
	} else { // hmm ... might be ALL DAY or ALL NIGHT !
		if(!isNan(sun_check)) { // if it really is a number
			(sun_check < 1 ? night = true : night = false);
		}
	} // end numeric check

	if(self.night != null) { // we've made some sort of decision

// day / night time graphic 'switch'
			element = document.getElementById("day_night");
			if(element) {
				(!night ? element.innerHTML = "<img src=\"" + day_graphic + "\" alt=\"" + day_text + "\" title = \"" + day_text + "\"  />" : element.innerHTML = "<img src=\"" + night_graphic + "\" alt=\"" + night_text + "\" title = \"" + night_text + "\"  />");
			}
// END graphic switch

	} // end decision made

// END day / night
-->
</script>
No guarantees on suitability for purpose etc. etc. etc.
This is a modified 'snippet' from:

https://cumulus.hosiene.co.uk/viewtopic.php?f=14&t=735
Image
......................Imagine, what you will KNOW tomorrow !
Post Reply