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 | // }}} |
7e6495d4 | 75 | // {{{ dynpost() |
76 | ||
77 | function dynpost(action, values) | |
78 | { | |
79 | var body = document.getElementsByTagName('body')[0]; | |
80 | ||
81 | var form = document.createElement('form'); | |
82 | form.action = action; | |
83 | form.method = 'post'; | |
84 | ||
85 | body.appendChild(form); | |
86 | ||
87 | for (var k in values) { | |
88 | var input = document.createElement('input'); | |
89 | input.type = 'hidden'; | |
90 | input.name = k; | |
91 | input.value = values[k]; | |
92 | form.appendChild(input); | |
93 | } | |
94 | ||
95 | form.submit(); | |
96 | } | |
97 | ||
e83d83e8 | 98 | |
d6610b77 | 99 | function dynpostkv(action, k, v) |
100 | { | |
bee33d93 | 101 | var dict = {}; |
102 | dict[k] = v; | |
103 | dynpost(action, dict); | |
d6610b77 | 104 | } |
105 | ||
7e6495d4 | 106 | // }}} |
af2ff9ef | 107 | // {{{ function RegExp.escape() |
108 | ||
109 | RegExp.escape = function(text) { | |
110 | if (!arguments.callee.sRE) { | |
111 | var specials = [ | |
112 | '/', '.', '*', '+', '?', '|', | |
113 | '(', ')', '[', ']', '{', '}', | |
114 | '\\', '^' , '$' | |
115 | ]; | |
116 | arguments.callee.sRE = new RegExp( | |
117 | '(\\' + specials.join('|\\') + ')', 'g' | |
118 | ); | |
119 | } | |
120 | return text.replace(arguments.callee.sRE, '\\$1'); | |
121 | } | |
122 | ||
123 | // }}} | |
0337d704 | 124 | |
125 | /*************************************************************************** | |
126 | * POPUP THINGS | |
127 | */ | |
128 | ||
129 | // {{{ function popWin() | |
130 | ||
e83d83e8 | 131 | function popWin(theNode, w, h) { |
0337d704 | 132 | window.open(theNode.href, '_blank', |
e83d83e8 FB |
133 | 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+w+',height='+h); |
134 | return false; | |
0337d704 | 135 | } |
136 | ||
137 | // }}} | |
769dc7d5 VZ |
138 | // {{{ function goodiesPopup() |
139 | ||
140 | function goodiesPopup(node) { | |
141 | if (node.href.indexOf('ical') > -1) { | |
142 | __goodies_popup(node, __goodies_ical_sites, 'Calendrier iCal'); | |
269154e2 | 143 | } else if (node.href.indexOf('rss') > -1 && node.href.indexOf('prefs/rss') < 0 && (node.href.indexOf('xml') > -1 || node.href.indexOf('hash'))) { |
769dc7d5 VZ |
144 | __goodies_popup(node, __goodies_rss_sites, 'Fil rss'); |
145 | } | |
146 | } | |
147 | ||
f14eed3f VZ |
148 | function disableGoodiesPopups() { |
149 | __goodies_active = false; | |
150 | } | |
151 | ||
152 | var __goodies_active = true; | |
769dc7d5 VZ |
153 | var __goodies_ical_sites = [ |
154 | {'url_prefix': '', | |
155 | 'img': 'images/icons/calendar_view_day.gif', | |
156 | 'title': 'Calendrier iCal'}, | |
157 | {'url_prefix': 'http://www.google.com/calendar/render?cid=', | |
158 | 'img': 'images/goodies/add-google-calendar.gif', | |
db270710 VZ |
159 | 'title': 'Ajouter à Google Calendar'}, |
160 | {'url_prefix': 'https://www.google.com/calendar/hosted/polytechnique.org/render?cid=', | |
161 | 'img': 'images/goodies/add-google-calendar.gif', | |
162 | 'title': 'Ajouter à Google Apps / Calendar'} | |
769dc7d5 VZ |
163 | ]; |
164 | var __goodies_rss_sites = [ | |
165 | {'url_prefix': '', | |
166 | 'img': 'images/icons/feed.gif', | |
167 | 'title': 'Fil rss'}, | |
168 | {'url_prefix': 'http://fusion.google.com/add?feedurl=', | |
169 | 'img': 'images/goodies/add-google.gif', | |
170 | 'alt': 'Add to Google', | |
171 | 'title': 'Ajouter à iGoogle/Google Reader'}, | |
172 | {'url_prefix': 'http://www.netvibes.com/subscribe.php?url=', | |
173 | 'img': 'images/goodies/add-netvibes.gif', | |
174 | 'title': 'Ajouter à Netvibes'}, | |
175 | {'url_prefix': 'http://add.my.yahoo.com/content?.intl=fr&url=', | |
176 | 'img': 'images/goodies/add-yahoo.gif', | |
177 | 'alt': 'Add to My Yahoo!', | |
ad5091f2 FB |
178 | 'title': 'Ajouter à My Yahoo!'}, |
179 | {'url_prefix': 'http://www.newsgator.com/ngs/subscriber/subext.aspx?url=', | |
180 | 'img': 'images/goodies/add-newsgator.gif', | |
181 | 'alt': 'Subscribe in NewsGator Online', | |
182 | 'title': 'Ajouter à Newsgator'} | |
769dc7d5 VZ |
183 | ]; |
184 | ||
185 | function __goodies_popupText(url, sites) { | |
186 | var text = '<div style="text-align: center; line-height: 2.2">'; | |
187 | for (var site in sites) { | |
188 | var s_alt = (sites[site]["alt"] ? sites[site]["alt"] : ""); | |
189 | var s_img = sites[site]["img"]; | |
190 | var s_title = (sites[site]["title"] ? sites[site]["title"] : ""); | |
191 | var s_url = (sites[site]["url_prefix"].length > 0 ? sites[site]["url_prefix"] + escape(url) : url); | |
192 | ||
193 | text += '<a href="' + s_url + '"><img src="' + s_img + '" title="' + s_title + '" alt="' + s_alt + '"></a><br />'; | |
194 | } | |
195 | text += '<a href="https://www.polytechnique.org/Xorg/Goodies">Plus de bonus</a> ...</div>' | |
196 | return text; | |
197 | } | |
198 | ||
199 | function __goodies_popup(node, sites, default_title) { | |
200 | var mouseover_cb = function() { | |
f14eed3f VZ |
201 | if (__goodies_active) { |
202 | var rss_text = __goodies_popupText(node.href, sites); | |
203 | var rss_title = (node.title ? node.title : default_title); | |
204 | return overlib(rss_text, CAPTION, rss_title, CLOSETEXT, 'Fermer', DELAY, 800, STICKY, WIDTH, 150); | |
205 | } | |
769dc7d5 VZ |
206 | } |
207 | var mouseout_cb = function() { | |
208 | nd(); | |
209 | } | |
210 | ||
211 | node.onmouseover = mouseover_cb; | |
212 | node.onmouseout = mouseout_cb; | |
213 | } | |
214 | ||
215 | // }}} | |
0337d704 | 216 | // {{{ function auto_links() |
217 | ||
0337d704 | 218 | function auto_links() { |
b277fbe5 | 219 | url = document.URL; |
220 | fqdn = url.replace(/^https?:\/\/([^\/]*)\/.*$/,'$1'); | |
221 | light = (url.indexOf('display=light') > url.indexOf('?')); | |
e83d83e8 FB |
222 | |
223 | $("a,link").each( | |
224 | function(i) { | |
225 | node = $(this); | |
226 | enode = node.get(0); | |
227 | href = enode.href; | |
228 | if(!href || node.hasClass('xdx') | |
229 | || href.indexOf('mailto:') > -1 || href.indexOf('javascript:') > -1) { | |
230 | return; | |
3def38d5 | 231 | } |
e83d83e8 FB |
232 | if (href.indexOf(fqdn) < 0 || node.hasClass('popup')) { |
233 | node.click(function () { window.open(this.href); return false; }); | |
234 | } | |
235 | if (href.indexOf(fqdn) > -1 && light) { | |
236 | href = href.replace(/([^\#\?]*)\??([^\#]*)(\#.*)?/, "$1?display=light&$2$3"); | |
237 | enode.href = href; | |
238 | } | |
239 | if (href.indexOf('rss') > -1 || href.indexOf('ical') > -1) { | |
240 | if (href.indexOf('http') < 0) { | |
241 | href = 'http://' + fqdn + '/' + href; | |
242 | } | |
243 | enode.href = href; | |
244 | if (enode.nodeName.toLowerCase() == 'a') { | |
245 | goodiesPopup(enode); | |
246 | } | |
247 | } | |
248 | if(matches = (/^popup_([0-9]*)x([0-9]*)$/).exec(enode.className)) { | |
249 | var w = matches[1], h = matches[2]; | |
250 | node.click(function() { return popWin(this, w, h); }); | |
769dc7d5 | 251 | } |
3def38d5 | 252 | } |
e83d83e8 FB |
253 | ); |
254 | $('.popup2').click(function() { return popWin(this, 840, 600); }); | |
255 | $('.popup3').click(function() { return popWin(this, 640, 800); }); | |
0337d704 | 256 | } |
257 | ||
e83d83e8 | 258 | |
0337d704 | 259 | // }}} |
260 | ||
7143ad2b FB |
261 | |
262 | /*************************************************************************** | |
263 | * Password check | |
264 | */ | |
265 | ||
266 | // {{{ function checkPassword | |
267 | ||
268 | function getType(char) { | |
269 | if (char >= 'a' && char <= 'z') { | |
270 | return 1; | |
271 | } else if (char >= 'A' && char <= 'Z') { | |
272 | return 2; | |
273 | } else if (char >= '0' && char <= '9') { | |
274 | return 3; | |
275 | } else { | |
276 | return 4; | |
277 | } | |
278 | } | |
279 | ||
7b7d0970 | 280 | function checkPassword(box, okLabel) { |
7143ad2b FB |
281 | var prev = 0; |
282 | var prop = 0; | |
283 | var pass = box.value; | |
284 | var types = Array(0, 0, 0, 0, 0); | |
eaa3f284 | 285 | var firstType = true; |
7143ad2b FB |
286 | for (i = 0 ; i < pass.length ; ++i) { |
287 | type = getType(pass.charAt(i)); | |
288 | if (prev != 0 && prev != type) { | |
289 | prop += 5; | |
290 | } | |
eaa3f284 FB |
291 | prop += i; |
292 | if (types[type] == 0 && !firstType) { | |
293 | prop += 15; | |
294 | } else { | |
295 | firstType = false; | |
7143ad2b FB |
296 | } |
297 | types[type]++; | |
298 | prev = type; | |
299 | } | |
eaa3f284 | 300 | if (pass.length < 6) { |
aca1582e | 301 | prop *= 0.75; |
eaa3f284 | 302 | } |
7143ad2b FB |
303 | if (prop > 100) { |
304 | prop = 100; | |
305 | } else if (prop < 0) { | |
306 | prop = 0; | |
307 | } | |
de99248c | 308 | if (prop >= 60) { |
00681970 FB |
309 | color = "#4f4"; |
310 | bgcolor = "#050"; | |
de99248c FB |
311 | ok = true; |
312 | } else if (prop >= 40) { | |
313 | color = "#ff4"; | |
00681970 | 314 | bgcolor = "#750"; |
b19839fd | 315 | ok = true; |
de99248c FB |
316 | } else { |
317 | color = "#f20"; | |
00681970 | 318 | bgcolor = "#700"; |
de99248c FB |
319 | ok = false; |
320 | } | |
321 | $("#passwords_measure") | |
00681970 FB |
322 | .stop() |
323 | .animate({ width: prop + "%", | |
324 | backgroundColor: color | |
325 | }, 750) | |
326 | .parent().stop() | |
327 | .animate({ backgroundColor: bgcolor }, 750); | |
de99248c | 328 | var submitButton = $(":submit[@name='" + passwordprompt_submit + "']"); |
b19839fd | 329 | if (ok && pass.length >= 6) { |
7b7d0970 | 330 | submitButton.attr("value", okLabel); |
de99248c | 331 | submitButton.removeAttr("disabled"); |
7143ad2b | 332 | } else { |
7b7d0970 | 333 | submitButton.attr("value", "Mot de passe trop faible"); |
de99248c | 334 | submitButton.attr("disabled", "disabled"); |
7143ad2b FB |
335 | } |
336 | } | |
337 | ||
338 | // }}} | |
339 | ||
340 | ||
0337d704 | 341 | /*************************************************************************** |
342 | * The real OnLoad | |
343 | */ | |
344 | ||
e83d83e8 | 345 | $(window).load(auto_links); |
0337d704 | 346 | |
a14159bf | 347 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |