Close #595.
[platal.git] / htdocs / javascript / xorg.js
CommitLineData
0337d704 1/***************************************************************************
5ddeb07c 2 * Copyright (C) 2003-2007 Polytechnique.org *
0337d704 3 * http://opensource.polytechnique.org/ *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., *
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 ***************************************************************************/
20
9f449375 21var is_netscape = (navigator.appName.substring(0,8) == "Netscape");
22var is_IE = (navigator.appName.substring(0,9) == "Microsoft");
0337d704 23
24// {{{ function getNow()
25
0337d704 26function getNow() {
9f449375 27 dt = new Date();
28 dy = dt.getDay();
29 mh = dt.getMonth();
30 wd = dt.getDate();
31 yr = dt.getYear();
0337d704 32 if (yr<1000) yr += 1900;
9f449375 33 hr = dt.getHours();
34 mi = dt.getMinutes();
35
36 time = (mi < 10) ? hr +':0'+mi : hr+':'+mi;
37 days = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
a14159bf 38 months = ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet',
39 'août', 'septembre', 'octobre', 'novembre', 'décembre']
9f449375 40
41 return days[dy]+' '+wd+' '+months[mh]+' '+yr+'<br />'+time;
42}
43
44// }}}
a27c6df8 45// {{{ Search Engine
46
47function canAddSearchEngine()
48{
49 if (((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function"))
50 || ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function"))) {
51 return true;
52 }
53 return false;
54}
39fd8f50 55
b09e5dea 56function addSearchEngine()
57{
58 var searchURI = "http://www.polytechnique.org/xorg.opensearch.xml";
39fd8f50 59 if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")) {
60 window.sidebar.addSearchEngine(
b09e5dea 61 searchURI,
39fd8f50 62 "http://www.polytechnique.org/images/xorg.png",
b09e5dea 63 "Annuaire Polytechnique.org",
39fd8f50 64 "Academic");
b09e5dea 65 } else {
66 try {
67 window.external.AddSearchProvider(searchURI);
68 } catch(e) {
69 alert("Impossible d'installer la barre de recherche");
70 }
71 }
39fd8f50 72}
73
39fd8f50 74// }}}
9f449375 75// {{{ Events
76
77function eventClosure(obj, methodName) {
78 return (function(e) {
79 e = e || window.event;
80 return obj[methodName](e);
81 });
82}
83
84function attachEvent(obj, evt, f, useCapture) {
85 if (!useCapture) useCapture = false;
86
87 if (obj.addEventListener) {
88 obj.addEventListener(evt, f, useCapture);
89 return true;
90 } else if (obj.attachEvent) {
91 return obj.attachEvent("on"+evt, f);
4d8e2051 92 }
93 return false;
0337d704 94}
95
96// }}}
7e6495d4 97// {{{ dynpost()
98
99function dynpost(action, values)
100{
101 var body = document.getElementsByTagName('body')[0];
102
103 var form = document.createElement('form');
104 form.action = action;
105 form.method = 'post';
106
107 body.appendChild(form);
108
109 for (var k in values) {
110 var input = document.createElement('input');
111 input.type = 'hidden';
112 input.name = k;
113 input.value = values[k];
114 form.appendChild(input);
115 }
116
117 form.submit();
118}
119
d6610b77 120function dynpostkv(action, k, v)
121{
bee33d93 122 var dict = {};
123 dict[k] = v;
124 dynpost(action, dict);
d6610b77 125}
126
7e6495d4 127// }}}
0337d704 128
129/***************************************************************************
130 * POPUP THINGS
131 */
132
133// {{{ function popWin()
134
0337d704 135function popWin(theNode,w,h) {
136 window.open(theNode.href, '_blank',
137 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+w+',height='+h);
138}
139
140// }}}
141// {{{ function auto_links()
142
0337d704 143function auto_links() {
144 nodes = document.getElementsByTagName('a');
145 fqdn = document.URL;
146 fqdn = fqdn.replace(/^https?:\/\/([^\/]*)\/.*$/,'$1');
147 for(var i=0; i<nodes.length; i++) {
148 node = nodes[i];
149 if(!node.href || node.className == 'xdx' || node.href.indexOf('mailto:') > -1 || node.href.indexOf('javascript:')>-1) continue;
150 if(node.href.indexOf(fqdn)<0 || node.className == 'popup') {
151 node.onclick = function () { window.open(this.href); return false; };
152 }
153 if(node.className == 'popup2') {
4d8e2051 154 node.onclick = function () { popWin(this,840,600); return false; };
0337d704 155 }
156 if(matches = (/^popup_([0-9]*)x([0-9]*)$/).exec(node.className)) {
157 var w = matches[1], h = matches[2];
158 node.onclick = function () { popWin(this,w,h); return false; };
159 }
160 }
161}
162
163// }}}
164
165/***************************************************************************
166 * The real OnLoad
167 */
168
169// {{{ function pa_onload
170
4d8e2051 171if (!attachEvent(window, 'load', auto_links)) {
172 window.onload = auto_links;
173}
0337d704 174
175// }}}
176
a14159bf 177// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: