Use OpenSearch toolbar ==> IE7 & FF compatible
[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// }}}
39fd8f50 45// {{{ Firefox
46
b09e5dea 47function addSearchEngine()
48{
49 var searchURI = "http://www.polytechnique.org/xorg.opensearch.xml";
39fd8f50 50 if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")) {
51 window.sidebar.addSearchEngine(
b09e5dea 52 searchURI,
39fd8f50 53 "http://www.polytechnique.org/images/xorg.png",
b09e5dea 54 "Annuaire Polytechnique.org",
39fd8f50 55 "Academic");
b09e5dea 56 } else {
57 try {
58 window.external.AddSearchProvider(searchURI);
59 } catch(e) {
60 alert("Impossible d'installer la barre de recherche");
61 }
62 }
39fd8f50 63}
64
39fd8f50 65// }}}
9f449375 66// {{{ Events
67
68function eventClosure(obj, methodName) {
69 return (function(e) {
70 e = e || window.event;
71 return obj[methodName](e);
72 });
73}
74
75function attachEvent(obj, evt, f, useCapture) {
76 if (!useCapture) useCapture = false;
77
78 if (obj.addEventListener) {
79 obj.addEventListener(evt, f, useCapture);
80 return true;
81 } else if (obj.attachEvent) {
82 return obj.attachEvent("on"+evt, f);
4d8e2051 83 }
84 return false;
0337d704 85}
86
87// }}}
7e6495d4 88// {{{ dynpost()
89
90function dynpost(action, values)
91{
92 var body = document.getElementsByTagName('body')[0];
93
94 var form = document.createElement('form');
95 form.action = action;
96 form.method = 'post';
97
98 body.appendChild(form);
99
100 for (var k in values) {
101 var input = document.createElement('input');
102 input.type = 'hidden';
103 input.name = k;
104 input.value = values[k];
105 form.appendChild(input);
106 }
107
108 form.submit();
109}
110
d6610b77 111function dynpostkv(action, k, v)
112{
bee33d93 113 var dict = {};
114 dict[k] = v;
115 dynpost(action, dict);
d6610b77 116}
117
7e6495d4 118// }}}
0337d704 119
120/***************************************************************************
121 * POPUP THINGS
122 */
123
124// {{{ function popWin()
125
0337d704 126function popWin(theNode,w,h) {
127 window.open(theNode.href, '_blank',
128 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+w+',height='+h);
129}
130
131// }}}
132// {{{ function auto_links()
133
0337d704 134function auto_links() {
135 nodes = document.getElementsByTagName('a');
136 fqdn = document.URL;
137 fqdn = fqdn.replace(/^https?:\/\/([^\/]*)\/.*$/,'$1');
138 for(var i=0; i<nodes.length; i++) {
139 node = nodes[i];
140 if(!node.href || node.className == 'xdx' || node.href.indexOf('mailto:') > -1 || node.href.indexOf('javascript:')>-1) continue;
141 if(node.href.indexOf(fqdn)<0 || node.className == 'popup') {
142 node.onclick = function () { window.open(this.href); return false; };
143 }
144 if(node.className == 'popup2') {
4d8e2051 145 node.onclick = function () { popWin(this,840,600); return false; };
0337d704 146 }
147 if(matches = (/^popup_([0-9]*)x([0-9]*)$/).exec(node.className)) {
148 var w = matches[1], h = matches[2];
149 node.onclick = function () { popWin(this,w,h); return false; };
150 }
151 }
152}
153
154// }}}
155
156/***************************************************************************
157 * The real OnLoad
158 */
159
160// {{{ function pa_onload
161
4d8e2051 162if (!attachEvent(window, 'load', auto_links)) {
163 window.onload = auto_links;
164}
0337d704 165
166// }}}
167
a14159bf 168// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: