1 /***************************************************************************
2 * Copyright (C) 2003-2008 Polytechnique.org *
3 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 ***************************************************************************/
21 var is_netscape
= (navigator
.appName
.substring(0,8) == "Netscape");
22 var is_IE
= (navigator
.appName
.substring(0,9) == "Microsoft");
24 // {{{ function getNow()
32 if (yr
<1000) yr
+= 1900;
36 time
= (mi
< 10) ? hr
+':0'+mi
: hr
+':'+mi
;
37 days
= ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
38 months
= ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet',
39 'août', 'septembre', 'octobre', 'novembre', 'décembre']
41 return days
[dy
]+' '+wd
+' '+months
[mh
]+' '+yr
+'<br />'+time
;
47 function canAddSearchEngine()
49 if (((typeof window
.sidebar
== "object") && (typeof window
.sidebar
.addSearchEngine
== "function"))
50 || ((typeof window
.sidebar
== "object") && (typeof window
.sidebar
.addSearchEngine
== "function"))) {
56 function addSearchEngine()
58 var searchURI
= "http://www.polytechnique.org/xorg.opensearch.xml";
59 if ((typeof window
.sidebar
== "object") && (typeof window
.sidebar
.addSearchEngine
== "function")) {
60 window
.sidebar
.addSearchEngine(
62 "http://www.polytechnique.org/images/xorg.png",
63 "Annuaire Polytechnique.org",
67 window
.external
.AddSearchProvider(searchURI
);
69 alert("Impossible d'installer la barre de recherche");
77 function eventClosure(obj
, methodName
) {
79 e
= e
|| window
.event
;
80 return obj
[methodName
](e
);
84 function attachEvent(obj
, evt
, f
, useCapture
) {
85 if (!useCapture
) useCapture
= false;
87 if (obj
.addEventListener
) {
88 obj
.addEventListener(evt
, f
, useCapture
);
90 } else if (obj
.attachEvent
) {
91 return obj
.attachEvent("on"+evt
, f
);
99 function dynpost(action
, values
)
101 var body
= document
.getElementsByTagName('body')[0];
103 var form
= document
.createElement('form');
104 form
.action
= action
;
105 form
.method
= 'post';
107 body
.appendChild(form
);
109 for (var k
in values
) {
110 var input
= document
.createElement('input');
111 input
.type
= 'hidden';
113 input
.value
= values
[k
];
114 form
.appendChild(input
);
120 function dynpostkv(action
, k
, v
)
124 dynpost(action
, dict
);
128 // {{{ function RegExp.escape()
130 RegExp
.escape
= function(text
) {
131 if (!arguments
.callee
.sRE
) {
133 '/', '.', '*', '+', '?', '|',
134 '(', ')', '[', ']', '{', '}',
137 arguments
.callee
.sRE
= new RegExp(
138 '(\\' + specials
.join('|\\') + ')', 'g'
141 return text
.replace(arguments
.callee
.sRE
, '\\$1');
146 /***************************************************************************
150 // {{{ function popWin()
152 function popWin(theNode
,w
,h
) {
153 window
.open(theNode
.href
, '_blank',
154 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+w
+',height='+h
);
158 // {{{ function goodiesPopup()
160 function goodiesPopup(node
) {
161 if (node
.href
.indexOf('ical') > -1) {
162 __goodies_popup(node
, __goodies_ical_sites
, 'Calendrier iCal');
163 } else if (node
.href
.indexOf('rss') > -1 && (node
.href
.indexOf('xml') > -1 || node
.href
.indexOf('hash'))) {
164 __goodies_popup(node
, __goodies_rss_sites
, 'Fil rss');
168 var __goodies_ical_sites
= [
170 'img': 'images/icons/calendar_view_day.gif',
171 'title': 'Calendrier iCal'},
172 {'url_prefix': 'http://www.google.com/calendar/render?cid=',
173 'img': 'images/goodies/add-google-calendar.gif',
174 'title': 'Ajouter à Google Calendar'}
176 var __goodies_rss_sites
= [
178 'img': 'images/icons/feed.gif',
180 {'url_prefix': 'http://fusion.google.com/add?feedurl=',
181 'img': 'images/goodies/add-google.gif',
182 'alt': 'Add to Google',
183 'title': 'Ajouter à iGoogle/Google Reader'},
184 {'url_prefix': 'http://www.netvibes.com/subscribe.php?url=',
185 'img': 'images/goodies/add-netvibes.gif',
186 'title': 'Ajouter à Netvibes'},
187 {'url_prefix': 'http://add.my.yahoo.com/content?.intl=fr&url=',
188 'img': 'images/goodies/add-yahoo.gif',
189 'alt': 'Add to My Yahoo!',
190 'title': 'Ajouter à My Yahoo!'}
193 function __goodies_popupText(url
, sites
) {
194 var text
= '<div style="text-align: center; line-height: 2.2">';
195 for (var site
in sites
) {
196 var s_alt
= (sites
[site
]["alt"] ? sites
[site
]["alt"] : "");
197 var s_img
= sites
[site
]["img"];
198 var s_title
= (sites
[site
]["title"] ? sites
[site
]["title"] : "");
199 var s_url
= (sites
[site
]["url_prefix"].length
> 0 ? sites
[site
]["url_prefix"] + escape(url
) : url
);
201 text
+= '<a href="' + s_url
+ '"><img src="' + s_img
+ '" title="' + s_title
+ '" alt="' + s_alt
+ '"></a><br />';
203 text
+= '<a href="https://www.polytechnique.org/Xorg/Goodies">Plus de bonus</a> ...</div>'
207 function __goodies_popup(node
, sites
, default_title
) {
208 var mouseover_cb
= function() {
209 var rss_text
= __goodies_popupText(node
.href
, sites
);
210 var rss_title
= (node
.title
? node
.title
: default_title
);
211 return overlib(rss_text
, CAPTION
, rss_title
, CLOSETEXT
, 'Fermer', DELAY
, 800, STICKY
, WIDTH
, 150);
213 var mouseout_cb
= function() {
217 node
.onmouseover
= mouseover_cb
;
218 node
.onmouseout
= mouseout_cb
;
222 // {{{ function auto_links()
224 function auto_links() {
225 auto_links_nodes(document
.getElementsByTagName('a'));
226 auto_links_nodes(document
.getElementsByTagName('link'));
229 function auto_links_nodes(nodes
) {
231 fqdn
= url
.replace(/^https?:\/\/([^\/]*)\/.*$/,'$1');
232 light
= (url
.indexOf('display=light') > url
.indexOf('?'));
233 for(var i
=0; i
< nodes
.length
; i
++) {
235 if(!node
.href
|| node
.className
== 'xdx'
236 || node
.href
.indexOf('mailto:') > -1 || node
.href
.indexOf('javascript:') > -1)
238 if (node
.href
.indexOf(fqdn
) < 0 || node
.className
== 'popup') {
239 node
.onclick
= function () { window
.open(this.href
); return false; };
241 if (node
.href
.indexOf(fqdn
) > -1 && light
) {
242 node
.href
= node
.href
.replace(/([^\#\?]*)\??([^\#]*)(\#.*)?/,
243 "$1?display=light&$2$3");
245 if (node
.href
.indexOf('rss') > -1 || node
.href
.indexOf('ical') > -1) {
246 node
.href
= node
.href
.replace(/https/, 'http');
247 if (node
.href
.indexOf('http') < 0) {
248 node
.href
= 'http://' + fqdn + '/' + node
.href
;
250 if (node
.nodeName
.toLowerCase() == 'a') {
254 if(node
.className
== 'popup2') {
255 node
.onclick
= function () { popWin(this,840,600); return false; };
257 if(node
.className
== 'popup3') {
258 node
.onclick
= function () { popWin(this, 640, 800); return false; };
260 if(matches
= (/^popup_([0-9]*)x([0-9]*)$/).exec(node
.className
)) {
261 var w
= matches
[1], h
= matches
[2];
262 node
.onclick
= function () { popWin(this,w
,h
); return false; };
269 /***************************************************************************
273 // {{{ function pa_onload
275 if (!attachEvent(window
, 'load', auto_links
)) {
276 window
.onload
= auto_links
;
281 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: