[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

"weekly" javascript?

super70s

12/27/2015 4:25:00 PM

One of the features on my site is putting up the No. 1 single and LP a
certain amount of years ago (currently alternating between 40 or 45
years ago every week, as the years progress it will eventually be
45/50). I do this according to what week of the year it is currently,
and have been doing this manually every week for a long time.

I was just wondering if there's a good JS I could use for this, say put
all 52 weekly items in a separate file and then have the appropriate
item come up according to what week it is?

I have a "birthday" JS on the same page that's worked pretty well for me
over the years, I just have to change it each month....

<script language="JavaScript">
<!-- Begin
var msg = new Array();
Stamp = new Date();
today = Stamp.getDate();
msg[1] = "Dan Peek (11/1/50)<a href=america.html><img src=arrow1.gif
width=12 height=11 border=0 align=bottom></a>";
msg[2] = "Keith Emerson (11/2/44)<a href=spemersonlp3.html><img
src=arrow1.gif width=12 height=11 border=0 align=bottom></a>";
(ect.)
(ect.)
(ect.)...
msg[30] = "Dick Clark (11/30/29)<a href=extra_12_5.html><img
src=arrow1.gif width=12 height=11 border=0 align=bottom></a>";

function writeTip() {
document.write(msg[today]);
}
// End -->
</script>


However the items for that are a lot simpler than what I need for the
weekly No. 1's, an example of which is...

<p>&nbsp;&nbsp;&nbsp;<font size="2" face="arial"><I>Week Ending January
3, 1976</I></font><a href="sdmc_73_Jan_76.html"><img src="arrow3.gif"
width="12" height="11" border="0" align="bottom"></a><br>
<font color="#e06213">&#149;</font> <font size="2"
face="arial">#1 45: "Saturday Night"<br>&nbsp;&nbsp;&nbsp;- Bay City
Rollers</font><a href="sw_saturdaynight.html"><img src="arrow3.gif"
width="12" height="11" border="0" align="bottom"></a><br>
<font color="#e06213">&#149;</font> <font size="2"
face="arial">#1 LP: <cite>Chicago IX - Chicago's</cite><br>
&nbsp;&nbsp;&nbsp;<cite>Greatest Hits</cite> - Chicago</font><a
href="spchicago9.html"><img src="arrow3.gif" width="12" height="11"
border="0" align="bottom"></a></p>


I just don't know if this could work with the HTML markup that's
required for the above, when I tried to insert HTML (say, bold text) for
the birthday one, it wouldn't work at all.

Is what I want to do possible with javascript, or am I stuck with
manually updating this thing each week? Just curious.
9 Answers

ram

12/27/2015 5:12:00 PM

0

super70s <super70s@super70s.invalid> writes:
>I was just wondering if there's a good JS I could use for this, say put
>all 52 weekly items in a separate file and then have the appropriate
>item come up according to what week it is?
>I just don't know if this could work with the HTML markup that's
>required for the above, when I tried to insert HTML (say, bold text) for
>the birthday one, it wouldn't work at all.

The following example shows how to insert a strong element
read from a file »example«.

<!DOCTYPE HTML><html><head><meta charset="UTF-8">
<title>Main</title>
</head><body>
<p id="id201512271754350100"></p>
<pre><code>
<script type="application/javascript;version=1.8">
( { "main": function()
{ "use strict";
let mainThis = this;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{ if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
{ console.log( this.insert );
mainThis.insert( JSON.parse( xmlhttp.responseText )); }};
xmlhttp.open
( "GET", "http://userpage.fu-berlin.de/~ram/pub/JSON/exa...,
true );
xmlhttp.send(); },
"insert" : function( object )
{ "use strict";
let e = document.createElement( 'strong' );
let t = document.createTextNode( object[ 0 ] );
e.appendChild( t );
document.getElementById( 'id201512271754350100' ).
appendChild( e ); }}.main() );
</script></code></pre></body></html>


ram

12/27/2015 5:47:00 PM

0

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>super70s <super70s@super70s.invalid> writes:
>>I was just wondering if there's a good JS I could use for this, say put
>>all 52 weekly items in a separate file and then have the appropriate
>>item come up according to what week it is?
>>I just don't know if this could work with the HTML markup that's
>>required for the above, when I tried to insert HTML (say, bold text) for
>>the birthday one, it wouldn't work at all.
>The following example shows how to insert a strong element
>read from a file »example«.

I tried to reduce the size of the code a little bit.
I used an arrow function to get rid of the »that«
(variable to access the outer »this«), but then I got
rid of the need to access an outer »this« too.

<!DOCTYPE HTML><html><head><meta charset="UTF-8">
<title>Main</title>
</head><body>
<p id="id201512271754350100"></p>
<pre><code>
<script type="application/javascript;version=1.8">
( function()
{ "use strict"; let request = new XMLHttpRequest();
request.onreadystatechange = () =>
{ if( request.readyState == 4 && request.status == 200 )
{ let e = document.createElement( 'strong' );
e.appendChild( document.createTextNode
( JSON.parse( request.responseText )[ 0 ] ));
document.getElementById( 'id201512271754350100' ).
appendChild( e ); }};
request.open
( "GET", "http://userpage.fu-berlin.de/~ram/pub/JSON/exa...,
true );
request.send(); }() );
</script></code></pre></body></html>

super70s

12/27/2015 6:03:00 PM

0

In article
<XmlHttpRequest-JSON-DHTML-20151227174128@ram.dialup.fu-berlin.de>,
ram@zedat.fu-berlin.de (Stefan Ram) wrote:

> super70s <super70s@super70s.invalid> writes:
> >I was just wondering if there's a good JS I could use for this, say put
> >all 52 weekly items in a separate file and then have the appropriate
> >item come up according to what week it is?
> >I just don't know if this could work with the HTML markup that's
> >required for the above, when I tried to insert HTML (say, bold text) for
> >the birthday one, it wouldn't work at all.
>
> The following example shows how to insert a strong element
> read from a file »example«.
>
> <!DOCTYPE HTML><html><head><meta charset="UTF-8">
> <title>Main</title>
> </head><body>
> <p id="id201512271754350100"></p>
> <pre><code>
> <script type="application/javascript;version=1.8">
> ( { "main": function()
> { "use strict";
> let mainThis = this;
> var xmlhttp = new XMLHttpRequest();
> xmlhttp.onreadystatechange = function()
> { if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
> { console.log( this.insert );
> mainThis.insert( JSON.parse( xmlhttp.responseText )); }};
> xmlhttp.open
> ( "GET", "http://userpage.fu-berlin.de/~ram/pub/JSON/exa...,
> true );
> xmlhttp.send(); },
> "insert" : function( object )
> { "use strict";
> let e = document.createElement( 'strong' );
> let t = document.createTextNode( object[ 0 ] );
> e.appendChild( t );
> document.getElementById( 'id201512271754350100' ).
> appendChild( e ); }}.main() );
> </script></code></pre></body></html>

OK, but how do I indicate the appropriate element to come up according
to the week of year?

I think it would be way too complicated to pull off the more I think
about it, in some years it would be "week ending Jan. 1, Jan. 8, Jan.
15...," then in another one it would be something like "week ending Jan.
3, Jan. 11, Jan. 17...."

For each of the 5 groups (1970/75, 1971/76, 1972/1977, 1973/1978 and
1974/1979), I would need to indicate a firm date (plus 7 days since it's
"week ending...") to pull up the appropriate element, I guess.

ram

12/27/2015 6:28:00 PM

0

super70s <super70s@super70s.invalid> writes:
>OK, but how do I indicate the appropriate element to come up according
>to the week of year?

The rules for the determination of the week of the year
depend on the culture (locale). Germany (»Kalenderwoche«)
might have other rules than the United States of America.
So, you first need to decide which culture to use. The
following code contains an example of how one might proceed
for an undetermined example culture. (I have not extensively
reviewed or tested this code, so you need to be careful.)

let date = new Date( '1975-12-27T00:00:00' );
date.setDate( date.getDate() + 4 -( date.getDay() || 7 ));
let week = Math.ceil
(((( date - new Date( date.getFullYear(), 0, 1 ))/ 8.64e7 )+ 1 )/ 7 );
let textOfWeek ={ 52: "example" };
console.log( textOfWeek[ week ]);

Thomas 'PointedEars' Lahn

12/28/2015 11:26:00 AM

0

Stefan Ram wrote:

> super70s <super70s@super70s.invalid> writes:
>>OK, but how do I indicate the appropriate element to come up according
>>to the week of year?
>
> The rules for the determination of the week of the year
> depend on the culture (locale). Germany (»Kalenderwoche«)
> might have other rules than the United States of America.

The reason for that, however, is only secondary the locale. Germany, like
all EU countries, â??most of other European countries, most of Asia and
Oceania�, uses the ISO week numbering, while the U.S. locale uses another
numbering that is also used in â??Canada, [â?¦], China, Japan, Israel, South
Africa, [and] most of Latin America.�

<https://en.wikipedia.org/wiki/Week#Week_num...

JSX:date.js provides jsx.date.isoWeekNumber(),
Date.prototype.getISOWeekNumber(), and jsx.date.strftime() and
Date.prototype.strftime() with the "%V" format string, and jsx.date.format()
and Date.prototype.format() with the "ww" format string, respectively.

<http://PointedEars.de/wsvn/JSX/trunk/d...
<http://PointedEars.de/scripts/tes...

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.

Dr J R Stockton

12/28/2015 4:16:00 PM

0

In comp.lang.javascript message <XmlHttpRequest-JSON-DHTML-
20151227174128@ram.dialup.fu-berlin.de>, Sun, 27 Dec 2015 17:12:08,
Stefan Ram <ram@zedat.fu-berlin.de> posted:

>super70s <super70s@super70s.invalid> writes:
>>I was just wondering if there's a good JS I could use for this, say put
>>all 52 weekly items in a separate file and then have the appropriate
>>item come up according to what week it is?
>>I just don't know if this could work with the HTML markup that's
>>required for the above, when I tried to insert HTML (say, bold text) for
>>the birthday one, it wouldn't work at all.
>
> The following example shows how to insert a strong element
> read from a file â?ºexampleâ?¹.

String is most useful when it is strong, or sometimes when it is strung.

There is an easier way to read data from a file, if that file can be
suitably prepared :

In the main page, something like

<script type="text/javascript" src="chron16.js"></script>

and in adjacent file chron16.js, for example,

var clndr = [,
msg01,
msg02,
...
msg53 ]
where each msg is a string literal (or, more elegantly, an Object of
strings) -

together with any other variables wanted.

The OP might consult
<http://web.archive.org/web/20150907215801/http://www.merlyn.d...
/weekcalc.htm>.

--
(c) John Stockton, nr London, UK. E-mail, see Home Page. Turnpike v6.05.
Website < > - w. FAQish topics, links, acronyms
PAS EXE etc. : < programs/> - see in 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

Ben Bacarisse

12/29/2015 11:18:00 AM

0

super70s <super70s@super70s.invalid> writes:

> One of the features on my site is putting up the No. 1 single and LP a
> certain amount of years ago (currently alternating between 40 or 45
> years ago every week, as the years progress it will eventually be
> 45/50). I do this according to what week of the year it is currently,
> and have been doing this manually every week for a long time.
>
> I was just wondering if there's a good JS I could use for this, say put
> all 52 weekly items in a separate file and then have the appropriate
> item come up according to what week it is?
>
> I have a "birthday" JS on the same page that's worked pretty well for me
> over the years, I just have to change it each month....
>
> <script language="JavaScript">
<snip>

This group tends to discuss client-side scripting (as in your example)
but both the "historic single" and "birthday" examples are classic cases
that are usually best handled by server-side code. (Obviously
JavaScript can be used server side (see node.js) but that's not really
the point.)

You should consider doing some or all of this server-side.

--
Ben.

RobG

2/6/2016 7:07:00 AM

0

On 28/12/2015 04:27, Stefan Ram wrote:
> super70s <super70s@super70s.invalid> writes:
>> OK, but how do I indicate the appropriate element to come up according
>> to the week of year?
>
> The rules for the determination of the week of the year
> depend on the culture (locale). Germany (»Kalenderwoche«)
> might have other rules than the United States of America.

Culture and locale are distinctly different concepts. Germany and USA
are countries defined by administrative boundaries, each encompassing a
great many locales and cultures.


> So, you first need to decide which culture to use.

Culture? My grandmother thought I had none, so better to not start there.

A better place might be the administrative areas in which most of your
users reside (perhaps countries or continental regions) and then look to
the systems the administrators of those areas have chosen.

If you have a truly global audience, then chose the one most
administrations have chosen, which is likely ISO 8601.



--
Rob

Evertjan.

2/6/2016 9:59:00 AM

0

RobG <rgqld@iinet.net.au> wrote on 06 Feb 2016 in comp.lang.javascript:

> On 28/12/2015 04:27, Stefan Ram wrote:
>> super70s <super70s@super70s.invalid> writes:
>>> OK, but how do I indicate the appropriate element to come up according
>>> to the week of year?
>>
>> The rules for the determination of the week of the year
>> depend on the culture (locale). Germany (»Kalenderwoche«)
>> might have other rules than the United States of America.
>
> Culture and locale are distinctly different concepts. Germany and USA
> are countries defined by administrative boundaries, each encompassing a
> great many locales and cultures.
>
>
>> So, you first need to decide which culture to use.
>
> Culture? My grandmother thought I had none, so better to not start there.
>
> A better place might be the administrative areas in which most of your
> users reside (perhaps countries or continental regions) and then look to
> the systems the administrators of those areas have chosen.
>
> If you have a truly global audience, then chose the one most
> administrations have chosen, which is likely ISO 8601.

This ISO being a child of DIN [Deutche Industri Norm] ???

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)