Merge commit 'origin/master' into fusionax
[platal.git] / htdocs / javascript / xorg.js
CommitLineData
0337d704 1/***************************************************************************
8d84c630 2 * Copyright (C) 2003-2009 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
350ba5ac 21var is_IE = $.browser.msie;
0337d704 22
23// {{{ function getNow()
24
0337d704 25function getNow() {
9f449375 26 dt = new Date();
27 dy = dt.getDay();
28 mh = dt.getMonth();
29 wd = dt.getDate();
30 yr = dt.getYear();
0337d704 31 if (yr<1000) yr += 1900;
9f449375 32 hr = dt.getHours();
33 mi = dt.getMinutes();
7143ad2b 34
9f449375 35 time = (mi < 10) ? hr +':0'+mi : hr+':'+mi;
36 days = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
a14159bf 37 months = ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet',
38 'août', 'septembre', 'octobre', 'novembre', 'décembre']
9f449375 39
40 return days[dy]+' '+wd+' '+months[mh]+' '+yr+'<br />'+time;
41}
42
43// }}}
a27c6df8 44// {{{ Search Engine
45
46function canAddSearchEngine()
47{
350ba5ac
FB
48 if (((typeof window.sidebar == "object") && $.isFunction(window.sidebar.addSearchEngine))
49 || ((typeof window.external == "object") && $.isFunction(window.external.AddSearchProvider))) {
50 return true;
51 }
52 return false;
a27c6df8 53}
39fd8f50 54
b09e5dea 55function addSearchEngine()
56{
350ba5ac
FB
57 var searchURI = "http://www.polytechnique.org/xorg.opensearch.xml";
58 if ((typeof window.sidebar == "object") && $.isFunction(window.sidebar.addSearchEngine)) {
59 window.sidebar.addSearchEngine(
60 searchURI,
61 "http://www.polytechnique.org/images/xorg.png",
62 "Annuaire Polytechnique.org",
63 "Academic");
64 } else {
65 try {
66 window.external.AddSearchProvider(searchURI);
67 } catch(e) {
68 alert("Impossible d'installer la barre de recherche");
69 }
b09e5dea 70 }
39fd8f50 71}
72
39fd8f50 73// }}}
7e6495d4 74// {{{ dynpost()
75
76function dynpost(action, values)
77{
7e6495d4 78 var form = document.createElement('form');
79 form.action = action;
80 form.method = 'post';
81
7cf438aa 82 $('body').get(0).appendChild(form);
7e6495d4 83
84 for (var k in values) {
85 var input = document.createElement('input');
86 input.type = 'hidden';
87 input.name = k;
88 input.value = values[k];
89 form.appendChild(input);
90 }
91
92 form.submit();
93}
94
e83d83e8 95
d6610b77 96function dynpostkv(action, k, v)
97{
bee33d93 98 var dict = {};
99 dict[k] = v;
100 dynpost(action, dict);
d6610b77 101}
102
7e6495d4 103// }}}
af2ff9ef 104// {{{ function RegExp.escape()
105
106RegExp.escape = function(text) {
107 if (!arguments.callee.sRE) {
108 var specials = [
109 '/', '.', '*', '+', '?', '|',
110 '(', ')', '[', ']', '{', '}',
111 '\\', '^' , '$'
112 ];
113 arguments.callee.sRE = new RegExp(
114 '(\\' + specials.join('|\\') + ')', 'g'
115 );
116 }
117 return text.replace(arguments.callee.sRE, '\\$1');
118}
119
120// }}}
0337d704 121
122/***************************************************************************
123 * POPUP THINGS
124 */
125
126// {{{ function popWin()
127
e83d83e8 128function popWin(theNode, w, h) {
0337d704 129 window.open(theNode.href, '_blank',
e83d83e8
FB
130 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+w+',height='+h);
131 return false;
0337d704 132}
133
134// }}}
769dc7d5
VZ
135// {{{ function goodiesPopup()
136
350ba5ac
FB
137var __goodies_active = true;
138
139var __goodies_ical = {
140 default_title: 'Calendrier iCal',
141 sites: [
142 {'url_prefix': '',
143 'img': 'images/icons/calendar_view_day.gif',
144 'title': 'Calendrier iCal'},
145 {'url_prefix': 'http://www.google.com/calendar/render?cid=',
146 'img': 'images/goodies/add-google-calendar.gif',
147 'title': 'Ajouter à Google Calendar'},
148 {'url_prefix': 'https://www.google.com/calendar/hosted/polytechnique.org/render?cid=',
149 'img': 'images/goodies/add-google-calendar.gif',
150 'title': 'Ajouter à Google Apps / Calendar'}
151 ]
152};
153
154var __goodies_rss = {
155 default_title: 'Fils RSS',
156 sites: [
157 {'url_prefix': '',
158 'img': 'images/icons/feed.gif',
159 'title': 'Fil rss'},
160 {'url_prefix': 'http://fusion.google.com/add?feedurl=',
161 'img': 'images/goodies/add-google.gif',
162 'alt': 'Add to Google',
163 'title': 'Ajouter à iGoogle/Google Reader'},
164 {'url_prefix': 'http://www.netvibes.com/subscribe.php?url=',
165 'img': 'images/goodies/add-netvibes.gif',
166 'title': 'Ajouter à Netvibes'},
167 {'url_prefix': 'http://add.my.yahoo.com/content?.intl=fr&url=',
168 'img': 'images/goodies/add-yahoo.gif',
169 'alt': 'Add to My Yahoo!',
cb143c01 170 'title': 'Ajouter à My Yahoo!'}
350ba5ac
FB
171 ]
172};
769dc7d5 173
f14eed3f
VZ
174function disableGoodiesPopups() {
175 __goodies_active = false;
176}
177
350ba5ac 178function goodiesPopup(node, goodies) {
769dc7d5 179 var text = '<div style="text-align: center; line-height: 2.2">';
350ba5ac
FB
180 for (var site in goodies.sites) {
181 var entry = goodies.sites[site];
182 var s_alt = entry["alt"] ? entry["alt"] : "";
183 var s_img = entry["img"];
184 var s_title = entry["title"] ? entry["title"] : "";
185 var s_url = entry["url_prefix"].length > 0 ? entry["url_prefix"] + escape(this.href) : this.href;
769dc7d5
VZ
186
187 text += '<a href="' + s_url + '"><img src="' + s_img + '" title="' + s_title + '" alt="' + s_alt + '"></a><br />';
188 }
350ba5ac 189 text += '<a href="https://www.polytechnique.org/Xorg/Goodies">Plus de bonus</a> ...</div>';
769dc7d5 190
350ba5ac 191 var title = node.title ? node.title : goodies.default_title;
769dc7d5 192
350ba5ac
FB
193 $(node)
194 .mouseover(
195 function() {
196 if (__goodies_active) {
197 return overlib(text, CAPTION, title, CLOSETEXT, 'Fermer', DELAY, 800, STICKY, WIDTH, 150);
198 }
199 }
200 )
201 .mouseout(nd);
769dc7d5
VZ
202}
203
204// }}}
0337d704 205// {{{ function auto_links()
206
0337d704 207function auto_links() {
b277fbe5 208 url = document.URL;
209 fqdn = url.replace(/^https?:\/\/([^\/]*)\/.*$/,'$1');
210 light = (url.indexOf('display=light') > url.indexOf('?'));
79b8b816 211 resource_page = (url.indexOf('rss') > -1 || url.indexOf('ical') > -1);
e83d83e8
FB
212
213 $("a,link").each(
214 function(i) {
215 node = $(this);
350ba5ac 216 href = this.href;
e83d83e8
FB
217 if(!href || node.hasClass('xdx')
218 || href.indexOf('mailto:') > -1 || href.indexOf('javascript:') > -1) {
219 return;
3def38d5 220 }
ea736ad3 221 if ((href.indexOf(fqdn) < 0 && this.className.indexOf('popup') < 0) || node.hasClass('popup')) {
e83d83e8
FB
222 node.click(function () { window.open(this.href); return false; });
223 }
224 if (href.indexOf(fqdn) > -1 && light) {
225 href = href.replace(/([^\#\?]*)\??([^\#]*)(\#.*)?/, "$1?display=light&$2$3");
350ba5ac 226 this.href = href;
e83d83e8 227 }
350ba5ac
FB
228 rss = href.indexOf('rss') > -1;
229 ical = href.indexOf('ical') > -1;
230 if (rss || ical) {
e83d83e8
FB
231 if (href.indexOf('http') < 0) {
232 href = 'http://' + fqdn + '/' + href;
233 }
350ba5ac 234 }
79b8b816 235 if (this.nodeName.toLowerCase() == 'a' && !resource_page) {
350ba5ac
FB
236 if (rss && href.indexOf('prefs/rss') < 0 && (href.indexOf('xml') > -1 || href.indexOf('hash'))) {
237 goodiesPopup(this, __goodies_rss);
238 } else if (ical) {
239 goodiesPopup(this, __goodies_ical);
e83d83e8
FB
240 }
241 }
350ba5ac 242 if(matches = (/^popup_([0-9]*)x([0-9]*)$/).exec(this.className)) {
e83d83e8
FB
243 var w = matches[1], h = matches[2];
244 node.click(function() { return popWin(this, w, h); });
769dc7d5 245 }
3def38d5 246 }
e83d83e8
FB
247 );
248 $('.popup2').click(function() { return popWin(this, 840, 600); });
249 $('.popup3').click(function() { return popWin(this, 640, 800); });
0337d704 250}
251
e83d83e8 252
0337d704 253// }}}
254
7143ad2b
FB
255
256/***************************************************************************
257 * Password check
258 */
259
260// {{{ function checkPassword
261
0ba43ee4
VZ
262function getType(c) {
263 if (c >= 'a' && c <= 'z') {
7143ad2b 264 return 1;
0ba43ee4 265 } else if (c >= 'A' && c <= 'Z') {
7143ad2b 266 return 2;
0ba43ee4 267 } else if (c >= '0' && c <= '9') {
7143ad2b
FB
268 return 3;
269 } else {
270 return 4;
271 }
272}
273
7b7d0970 274function checkPassword(box, okLabel) {
7143ad2b
FB
275 var prev = 0;
276 var prop = 0;
277 var pass = box.value;
278 var types = Array(0, 0, 0, 0, 0);
eaa3f284 279 var firstType = true;
7143ad2b
FB
280 for (i = 0 ; i < pass.length ; ++i) {
281 type = getType(pass.charAt(i));
282 if (prev != 0 && prev != type) {
283 prop += 5;
284 }
eaa3f284
FB
285 prop += i;
286 if (types[type] == 0 && !firstType) {
287 prop += 15;
288 } else {
289 firstType = false;
7143ad2b
FB
290 }
291 types[type]++;
292 prev = type;
293 }
eaa3f284 294 if (pass.length < 6) {
aca1582e 295 prop *= 0.75;
eaa3f284 296 }
7143ad2b
FB
297 if (prop > 100) {
298 prop = 100;
299 } else if (prop < 0) {
300 prop = 0;
301 }
de99248c 302 if (prop >= 60) {
00681970
FB
303 color = "#4f4";
304 bgcolor = "#050";
de99248c
FB
305 ok = true;
306 } else if (prop >= 40) {
307 color = "#ff4";
00681970 308 bgcolor = "#750";
b19839fd 309 ok = true;
de99248c
FB
310 } else {
311 color = "#f20";
00681970 312 bgcolor = "#700";
de99248c
FB
313 ok = false;
314 }
315 $("#passwords_measure")
00681970
FB
316 .stop()
317 .animate({ width: prop + "%",
318 backgroundColor: color
319 }, 750)
320 .parent().stop()
321 .animate({ backgroundColor: bgcolor }, 750);
ed130f47 322 var submitButton = $(":submit[name='" + passwordprompt_submit + "']");
b19839fd 323 if (ok && pass.length >= 6) {
7b7d0970 324 submitButton.attr("value", okLabel);
de99248c 325 submitButton.removeAttr("disabled");
7143ad2b 326 } else {
7b7d0970 327 submitButton.attr("value", "Mot de passe trop faible");
de99248c 328 submitButton.attr("disabled", "disabled");
7143ad2b
FB
329 }
330}
331
332// }}}
333
334
0337d704 335/***************************************************************************
336 * The real OnLoad
337 */
338
350ba5ac 339$(document).ready(auto_links);
0337d704 340
a14159bf 341// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: