Page 1 of 1

smb_ajax 1.3

Posted: Sat 17 Aug 2019 3:45 pm
by Mapantz
Hi there!

I downloaded the file from this site a long time go - brilliant script for showing live updated values on your website.

As the weather has been appalling these past few days, i've decided to do a bit of tinkering on my site.

I've set the Javascript file to show a red colour each time an updated value occurs, but I was wondering if anyone clever enough would be able to add the option of choosing a font weight to it? I wanted to give it a bold look.

Regards.
smb_ajax.1.3.js

Re: smb_ajax 1.3

Posted: Sat 17 Aug 2019 9:28 pm
by ExperiMentor
I don't know any javascript, but you got me interested!

A bit of Googling suggests that you need to go the part in your file that says

Code: Select all

if(flashtime!=0) ajx.style.color=flashcolour;
and add

Code: Select all

ajx.style.fontWeight = "bold"; //makes the text bold
Now I don't know if you can put it in the same line, or if you need to repeat the whole line or what, but that should be the code you need!

My source was: https://en.wikibooks.org/wiki/JavaScrip ... ent_styles

Added:
After a bit more research, I think you need to change this section to:

Code: Select all

if(flashtime!=0) {
  ajx.style.color=flashcolour;
  ajx.style.fontWeight = "bold";
} 
Also, you'll probably need to turn the BOLD off again in the "reset_ajax_color" function. So after:

Code: Select all

element.style.color='';
add an extra line to make:

Code: Select all

element.style.color='';
element.style.fontWeight = "normal";
Hope this helps!

Re: smb_ajax 1.3

Posted: Sat 17 Aug 2019 9:53 pm
by beteljuice
Not quite that straight-forward I'm afraid ...

Yes your code will make the text bold when the element is 'flashed', but ... how do you turn it off ?

You need to go down to ..

Code: Select all

function reset_ajax_color( ) {
// reset all the <span class="ajax"...> styles to have no colour override
    elements = getElementsByClass("span","ajax");
    numelements = elements.length;

    for (var index=0;index!=numelements;index++) {
        element = elements[index];
        element.style.color='';
// NEW ** turn off bold at end of flash period
         element.style.fontWeight='normal';
    }
}

Re: smb_ajax 1.3

Posted: Sat 17 Aug 2019 10:05 pm
by ExperiMentor
Not quite that straight-forward I'm afraid ...
I realised that too and made the same edit in parallel!!

GMTA!!

Re: smb_ajax 1.3

Posted: Sat 17 Aug 2019 10:51 pm
by Mapantz
Sweet - Nailed it!

Thanks guys!! :clap:

Bold was a little too much in the end, so as fontweight can use a numerical value, I went down the middle and set it at 600.

Thank you so much.

Re: smb_ajax 1.3

Posted: Sun 10 Nov 2019 9:05 pm
by Mapantz
Back again!

Can the .js file (in my first post) be adapted to read from two different xml files with the same schema?

Re: smb_ajax 1.3

Posted: Sat 23 Nov 2019 5:33 pm
by HansR
Is there a working example to get on track quick and easy and see how far I can get to use it?

Re: smb_ajax 1.3

Posted: Sat 23 Nov 2019 8:32 pm
by Mapantz
I can't quite remember where I got the info from, originally. I think it may have been from this forum?!

Here's the files I use, along with a quick explanation:

I get Cumulus MX to process the cumulusxml.xml file and then upload it as realtime.xml

I put this is the <head> section

Code: Select all

<script src="https://code.jquery.com/jquery-3.4.1.min.js"  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="smb_ajax.js"></script>
I put this in my header file (it can go in any file that you want to grab data with)

Code: Select all

<script>
//<![CDATA[
initialize('./realtime.xml', 4);
// ]]>
</script>
Here's my example of grabbing some of the data:

Code: Select all

<td style="text-align: left;">Inside Temperature:</td>
<td><span class="ajax" id="intemp"></span>&nbsp;&#176;C</span></td>
<td style="text-align: left;">Inside Humidity:</td>
<td><span class="ajax" id="inhum"></span>&nbsp;%</span></td>
As soon as new data in the realtime.xml appears, the data will change and flash red for a small duration.

I personally process and upload the file every 4 seconds.

The reason I ask if smb_ajax.js could be used to read two xml files at the same time is, I am now using a second instance of Cumulus MX to upload my Ecowitt GW-1000 data. I wanted to get that to upload it's own xml file with it's data so it could update like my Davis data does, albeit at 30 seconds rather than 4 seconds.

I was using a small workaround; I got Cumulus MX for the GW-1000 to upload the xml file with it's own data with the same name realtime.xml, each instance of Cumulus MX would overwrite the remote files. However, it caused a few issues.

Re: smb_ajax 1.3

Posted: Sat 23 Nov 2019 8:57 pm
by HansR
Thanks, something to digest ;)

Re: smb_ajax 1.3

Posted: Sat 23 Nov 2019 10:18 pm
by beteljuice
I'm unsure what you are asking ?

The script can parse any correct format xml file you declare:

initialize('./realtime.xml', 4);

However; In any one 'page' the output can only be used once (last one in), so you couldn't have eg. two tables with different data sources.

If you are talking about different pages for the different data, but still using the script, then the second xml file will need to have a different filename and / or path_to/filename

Re: smb_ajax 1.3

Posted: Sat 23 Nov 2019 10:39 pm
by Mapantz
beteljuice wrote: Sat 23 Nov 2019 10:18 pm I'm unsure what you are asking ?

The script can parse any correct format xml file you declare:

initialize('./realtime.xml', 4);

However; In any one 'page' the output can only be used once (last one in), so you couldn't have eg. two tables with different data sources.
That's exactly it.

I have two xml files I want to read and show the data on the same page. That's why I asked if it was possible to have the smb_ajax read from two xml's. The structure is the same, it just contains different data values.

realtime.xml and gw1000.xml

Re: smb_ajax 1.3

Posted: Sun 24 Nov 2019 1:24 am
by beteljuice
... but the output variables are the same names !

= can't be done