Commit | Line | Data |
---|---|---|
0337d704 | 1 | /*************************************************************************** |
179afa7f | 2 | * Copyright (C) 2003-2008 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 | 21 | var is_netscape = (navigator.appName.substring(0,8) == "Netscape"); |
22 | var is_IE = (navigator.appName.substring(0,9) == "Microsoft"); | |
0337d704 | 23 | |
24 | // {{{ function getNow() | |
25 | ||
0337d704 | 26 | function 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(); | |
7143ad2b | 35 | |
9f449375 | 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 | ||
47 | function 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 | 56 | function 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) { | |
7143ad2b | 69 | alert("Impossible d'installer la barre de recherche"); |
b09e5dea | 70 | } |
71 | } | |
39fd8f50 | 72 | } |
73 | ||
39fd8f50 | 74 | // }}} |
9f449375 | 75 | // {{{ Events |
76 | ||
77 | function eventClosure(obj, methodName) { | |
78 | return (function(e) { | |
79 | e = e || window.event; | |
80 | return obj[methodName](e); | |
81 | }); | |
82 | } | |
83 | ||
84 | function 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); | |
7143ad2b | 92 | } |
4d8e2051 | 93 | return false; |
0337d704 | 94 | } |
95 | ||
96 | // }}} | |
7e6495d4 | 97 | // {{{ dynpost() |
98 | ||
99 | function 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 | 120 | function dynpostkv(action, k, v) |
121 | { | |
bee33d93 | 122 | var dict = {}; |
123 | dict[k] = v; | |
124 | dynpost(action, dict); | |
d6610b77 | 125 | } |
126 | ||
7e6495d4 | 127 | // }}} |
af2ff9ef | 128 | // {{{ function RegExp.escape() |
129 | ||
130 | RegExp.escape = function(text) { | |
131 | if (!arguments.callee.sRE) { | |
132 | var specials = [ | |
133 | '/', '.', '*', '+', '?', '|', | |
134 | '(', ')', '[', ']', '{', '}', | |
135 | '\\', '^' , '$' | |
136 | ]; | |
137 | arguments.callee.sRE = new RegExp( | |
138 | '(\\' + specials.join('|\\') + ')', 'g' | |
139 | ); | |
140 | } | |
141 | return text.replace(arguments.callee.sRE, '\\$1'); | |
142 | } | |
143 | ||
144 | // }}} | |
0337d704 | 145 | |
146 | /*************************************************************************** | |
147 | * POPUP THINGS | |
148 | */ | |
149 | ||
150 | // {{{ function popWin() | |
151 | ||
0337d704 | 152 | function popWin(theNode,w,h) { |
153 | window.open(theNode.href, '_blank', | |
3def38d5 | 154 | 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+w+',height='+h); |
0337d704 | 155 | } |
156 | ||
157 | // }}} | |
769dc7d5 VZ |
158 | // {{{ function goodiesPopup() |
159 | ||
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'); | |
165 | } | |
166 | } | |
167 | ||
f14eed3f VZ |
168 | function disableGoodiesPopups() { |
169 | __goodies_active = false; | |
170 | } | |
171 | ||
172 | var __goodies_active = true; | |
769dc7d5 VZ |
173 | var __goodies_ical_sites = [ |
174 | {'url_prefix': '', | |
175 | 'img': 'images/icons/calendar_view_day.gif', | |
176 | 'title': 'Calendrier iCal'}, | |
177 | {'url_prefix': 'http://www.google.com/calendar/render?cid=', | |
178 | 'img': 'images/goodies/add-google-calendar.gif', | |
db270710 VZ |
179 | 'title': 'Ajouter à Google Calendar'}, |
180 | {'url_prefix': 'https://www.google.com/calendar/hosted/polytechnique.org/render?cid=', | |
181 | 'img': 'images/goodies/add-google-calendar.gif', | |
182 | 'title': 'Ajouter à Google Apps / Calendar'} | |
769dc7d5 VZ |
183 | ]; |
184 | var __goodies_rss_sites = [ | |
185 | {'url_prefix': '', | |
186 | 'img': 'images/icons/feed.gif', | |
187 | 'title': 'Fil rss'}, | |
188 | {'url_prefix': 'http://fusion.google.com/add?feedurl=', | |
189 | 'img': 'images/goodies/add-google.gif', | |
190 | 'alt': 'Add to Google', | |
191 | 'title': 'Ajouter à iGoogle/Google Reader'}, | |
192 | {'url_prefix': 'http://www.netvibes.com/subscribe.php?url=', | |
193 | 'img': 'images/goodies/add-netvibes.gif', | |
194 | 'title': 'Ajouter à Netvibes'}, | |
195 | {'url_prefix': 'http://add.my.yahoo.com/content?.intl=fr&url=', | |
196 | 'img': 'images/goodies/add-yahoo.gif', | |
197 | 'alt': 'Add to My Yahoo!', | |
ad5091f2 FB |
198 | 'title': 'Ajouter à My Yahoo!'}, |
199 | {'url_prefix': 'http://www.newsgator.com/ngs/subscriber/subext.aspx?url=', | |
200 | 'img': 'images/goodies/add-newsgator.gif', | |
201 | 'alt': 'Subscribe in NewsGator Online', | |
202 | 'title': 'Ajouter à Newsgator'} | |
769dc7d5 VZ |
203 | ]; |
204 | ||
205 | function __goodies_popupText(url, sites) { | |
206 | var text = '<div style="text-align: center; line-height: 2.2">'; | |
207 | for (var site in sites) { | |
208 | var s_alt = (sites[site]["alt"] ? sites[site]["alt"] : ""); | |
209 | var s_img = sites[site]["img"]; | |
210 | var s_title = (sites[site]["title"] ? sites[site]["title"] : ""); | |
211 | var s_url = (sites[site]["url_prefix"].length > 0 ? sites[site]["url_prefix"] + escape(url) : url); | |
212 | ||
213 | text += '<a href="' + s_url + '"><img src="' + s_img + '" title="' + s_title + '" alt="' + s_alt + '"></a><br />'; | |
214 | } | |
215 | text += '<a href="https://www.polytechnique.org/Xorg/Goodies">Plus de bonus</a> ...</div>' | |
216 | return text; | |
217 | } | |
218 | ||
219 | function __goodies_popup(node, sites, default_title) { | |
220 | var mouseover_cb = function() { | |
f14eed3f VZ |
221 | if (__goodies_active) { |
222 | var rss_text = __goodies_popupText(node.href, sites); | |
223 | var rss_title = (node.title ? node.title : default_title); | |
224 | return overlib(rss_text, CAPTION, rss_title, CLOSETEXT, 'Fermer', DELAY, 800, STICKY, WIDTH, 150); | |
225 | } | |
769dc7d5 VZ |
226 | } |
227 | var mouseout_cb = function() { | |
228 | nd(); | |
229 | } | |
230 | ||
231 | node.onmouseover = mouseover_cb; | |
232 | node.onmouseout = mouseout_cb; | |
233 | } | |
234 | ||
235 | // }}} | |
0337d704 | 236 | // {{{ function auto_links() |
237 | ||
0337d704 | 238 | function auto_links() { |
3def38d5 | 239 | auto_links_nodes(document.getElementsByTagName('a')); |
240 | auto_links_nodes(document.getElementsByTagName('link')); | |
241 | } | |
242 | ||
243 | function auto_links_nodes(nodes) { | |
b277fbe5 | 244 | url = document.URL; |
245 | fqdn = url.replace(/^https?:\/\/([^\/]*)\/.*$/,'$1'); | |
246 | light = (url.indexOf('display=light') > url.indexOf('?')); | |
3def38d5 | 247 | for(var i=0; i < nodes.length; i++) { |
248 | node = nodes[i]; | |
249 | if(!node.href || node.className == 'xdx' | |
250 | || node.href.indexOf('mailto:') > -1 || node.href.indexOf('javascript:') > -1) | |
251 | continue; | |
252 | if (node.href.indexOf(fqdn) < 0 || node.className == 'popup') { | |
253 | node.onclick = function () { window.open(this.href); return false; }; | |
254 | } | |
b277fbe5 | 255 | if (node.href.indexOf(fqdn) > -1 && light) { |
e173ee9b | 256 | node.href = node.href.replace(/([^\#\?]*)\??([^\#]*)(\#.*)?/, |
257 | "$1?display=light&$2$3"); | |
b277fbe5 | 258 | } |
3def38d5 | 259 | if (node.href.indexOf('rss') > -1 || node.href.indexOf('ical') > -1) { |
260 | node.href = node.href.replace(/https/, 'http'); | |
261 | if (node.href.indexOf('http') < 0) { | |
262 | node.href = 'http://' + fqdn + '/' + node.href; | |
263 | } | |
769dc7d5 VZ |
264 | if (node.nodeName.toLowerCase() == 'a') { |
265 | goodiesPopup(node); | |
266 | } | |
3def38d5 | 267 | } |
268 | if(node.className == 'popup2') { | |
007c44cb | 269 | node.onclick = function () { popWin(this,840,600); return false; }; |
3def38d5 | 270 | } |
007c44cb | 271 | if(node.className == 'popup3') { |
272 | node.onclick = function () { popWin(this, 640, 800); return false; }; | |
273 | } | |
3def38d5 | 274 | if(matches = (/^popup_([0-9]*)x([0-9]*)$/).exec(node.className)) { |
275 | var w = matches[1], h = matches[2]; | |
276 | node.onclick = function () { popWin(this,w,h); return false; }; | |
277 | } | |
0337d704 | 278 | } |
279 | } | |
280 | ||
281 | // }}} | |
282 | ||
7143ad2b FB |
283 | |
284 | /*************************************************************************** | |
285 | * Password check | |
286 | */ | |
287 | ||
288 | // {{{ function checkPassword | |
289 | ||
290 | function getType(char) { | |
291 | if (char >= 'a' && char <= 'z') { | |
292 | return 1; | |
293 | } else if (char >= 'A' && char <= 'Z') { | |
294 | return 2; | |
295 | } else if (char >= '0' && char <= '9') { | |
296 | return 3; | |
297 | } else { | |
298 | return 4; | |
299 | } | |
300 | } | |
301 | ||
302 | function checkPassword(box) { | |
303 | var prev = 0; | |
304 | var prop = 0; | |
305 | var pass = box.value; | |
306 | var types = Array(0, 0, 0, 0, 0); | |
eaa3f284 | 307 | var firstType = true; |
7143ad2b FB |
308 | for (i = 0 ; i < pass.length ; ++i) { |
309 | type = getType(pass.charAt(i)); | |
310 | if (prev != 0 && prev != type) { | |
311 | prop += 5; | |
312 | } | |
eaa3f284 FB |
313 | prop += i; |
314 | if (types[type] == 0 && !firstType) { | |
315 | prop += 15; | |
316 | } else { | |
317 | firstType = false; | |
7143ad2b FB |
318 | } |
319 | types[type]++; | |
320 | prev = type; | |
321 | } | |
eaa3f284 | 322 | if (pass.length < 6) { |
aca1582e | 323 | prop *= 0.75; |
eaa3f284 | 324 | } |
7143ad2b FB |
325 | if (prop > 100) { |
326 | prop = 100; | |
327 | } else if (prop < 0) { | |
328 | prop = 0; | |
329 | } | |
de99248c | 330 | if (prop >= 60) { |
00681970 FB |
331 | color = "#4f4"; |
332 | bgcolor = "#050"; | |
de99248c FB |
333 | ok = true; |
334 | } else if (prop >= 40) { | |
335 | color = "#ff4"; | |
00681970 | 336 | bgcolor = "#750"; |
b19839fd | 337 | ok = true; |
de99248c FB |
338 | } else { |
339 | color = "#f20"; | |
00681970 | 340 | bgcolor = "#700"; |
de99248c FB |
341 | ok = false; |
342 | } | |
343 | $("#passwords_measure") | |
00681970 FB |
344 | .stop() |
345 | .animate({ width: prop + "%", | |
346 | backgroundColor: color | |
347 | }, 750) | |
348 | .parent().stop() | |
349 | .animate({ backgroundColor: bgcolor }, 750); | |
de99248c | 350 | var submitButton = $(":submit[@name='" + passwordprompt_submit + "']"); |
b19839fd | 351 | if (ok && pass.length >= 6) { |
de99248c | 352 | submitButton.removeAttr("disabled"); |
7143ad2b | 353 | } else { |
de99248c | 354 | submitButton.attr("disabled", "disabled"); |
7143ad2b FB |
355 | } |
356 | } | |
357 | ||
358 | // }}} | |
359 | ||
360 | ||
0337d704 | 361 | /*************************************************************************** |
362 | * The real OnLoad | |
363 | */ | |
364 | ||
365 | // {{{ function pa_onload | |
366 | ||
4d8e2051 | 367 | if (!attachEvent(window, 'load', auto_links)) { |
368 | window.onload = auto_links; | |
369 | } | |
0337d704 | 370 | |
371 | // }}} | |
372 | ||
a14159bf | 373 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |