Mercurial > hg-website
annotate src/en/javascript/main.js @ 54:baf1530ba0b0
added random quotes via ajax
author | bbarry <bbarry@stellarfinancial.com> |
---|---|
date | Mon, 16 Feb 2009 07:14:20 -0700 |
parents | 18110c461824 |
children | 16016cc18ded |
rev | line source |
---|---|
29
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
1 // http://simonwillison.net/2004/May/26/addLoadEvent/ |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
2 function addLoadEvent(func) { |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
3 var oldonload = window.onload; |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
4 if (typeof window.onload != 'function') { |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
5 window.onload = func; |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
6 } else { |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
7 window.onload = function() { |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
8 if (oldonload) { |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
9 oldonload(); |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
10 } |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
11 func(); |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
12 } |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
13 } |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
14 } |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
15 |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
16 var xmlhttp = null; |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
17 |
54
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
18 function loadXMLDoc(url, stateChange) { |
29
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
19 if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc. |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
20 xmlhttp = new XMLHttpRequest(); |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
21 } else if (window.ActiveXObject) {// code for IE6, IE5 |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
22 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
23 } |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
24 if (xmlhttp != null) { |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
25 xmlhttp.onreadystatechange = stateChange; |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
26 xmlhttp.open("GET",url,true); |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
27 xmlhttp.send(null); |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
28 } else { |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
29 alert("Your browser does not support XMLHTTP."); |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
30 } |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
31 } |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
32 |
54
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
33 // client OS specific page section |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
34 function browserUsageRequestStateChange() { |
29
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
35 if (xmlhttp.readyState==4) {// 4 = "loaded" |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
36 document.getElementById('replace').innerHTML = xmlhttp.responseText; |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
37 } |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
38 } |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
39 |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
40 addLoadEvent(function () { |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
41 if (navigator.appVersion.indexOf("Win")!=-1) { |
54
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
42 loadXMLDoc("win.html", browserUsageRequestStateChange); |
29
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
43 } |
18110c461824
js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
44 }); |
54
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
45 |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
46 // random quotes |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
47 function quoteRequestStateChange() { |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
48 if (xmlhttp.readyState==4) {// 4 = "loaded" |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
49 document.getElementById('quote').innerHTML = xmlhttp.responseText; |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
50 } |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
51 } |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
52 |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
53 function randomNumber(low, high) { |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
54 return Math.floor(Math.random()*(high-low+1))+low; |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
55 } |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
56 |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
57 addLoadEvent(function () { |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
58 loadXMLDoc("quotes/" + randomNumber(1, 17) + ".txt", quoteRequestStateChange); |
baf1530ba0b0
added random quotes via ajax
bbarry <bbarry@stellarfinancial.com>
parents:
29
diff
changeset
|
59 }); |