1 /***************************************************************************
2 * Copyright (C) 2003-2010 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_IE
= $.browser
.msie
;
23 // {{{ function getNow()
24 var days
= ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
25 var months
= ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet',
26 'août', 'septembre', 'octobre', 'novembre', 'décembre']
31 var mh
= dt
.getMonth();
32 var wd
= dt
.getDate();
33 var yr
= dt
.getYear();
34 if (yr
<1000) yr
+= 1900;
35 var hr
= dt
.getHours();
36 var mi
= dt
.getMinutes();
40 var se
= dt
.getSeconds();
45 $(".date-heure").html(days
[dy
] + ' ' + wd
+ ' ' + months
[mh
] + ' ' + yr
+ '<br />'
46 + hr
+ ':' + mi
+ ':' + se
);
52 function canAddSearchEngine()
54 if (((typeof window
.sidebar
== "object") && $.isFunction(window
.sidebar
.addSearchEngine
))
55 || ((typeof window
.external
== "object") && $.isFunction(window
.external
.AddSearchProvider
))) {
61 function addSearchEngine()
63 var searchURI
= "http://www.polytechnique.org/xorg.opensearch.xml";
64 if ((typeof window
.sidebar
== "object") && $.isFunction(window
.sidebar
.addSearchEngine
)) {
65 window
.sidebar
.addSearchEngine(
67 "http://www.polytechnique.org/images/xorg.png",
68 "Annuaire Polytechnique.org",
72 window
.external
.AddSearchProvider(searchURI
);
74 alert("Impossible d'installer la barre de recherche");
82 function dynpost(action
, values
)
84 var form
= document
.createElement('form');
88 $('body').get(0).appendChild(form
);
90 for (var k
in values
) {
91 var input
= document
.createElement('input');
92 input
.type
= 'hidden';
94 input
.value
= values
[k
];
95 form
.appendChild(input
);
102 function dynpostkv(action
, k
, v
)
106 dynpost(action
, dict
);
110 // {{{ function RegExp.escape()
112 RegExp
.escape
= function(text
) {
113 if (!arguments
.callee
.sRE
) {
115 '/', '.', '*', '+', '?', '|',
116 '(', ')', '[', ']', '{', '}',
119 arguments
.callee
.sRE
= new RegExp(
120 '(\\' + specials
.join('|\\') + ')', 'g'
123 return text
.replace(arguments
.callee
.sRE
, '\\$1');
128 /***************************************************************************
132 // {{{ function popWin()
134 function popWin(theNode
, w
, h
) {
135 window
.open(theNode
.href
, '_blank',
136 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+w
+',height='+h
);
141 // {{{ function goodiesPopup()
143 var __goodies_active
= true;
145 var __goodies_ical
= {
146 default_title
: 'Calendrier iCal',
149 'img': 'images/icons/calendar_view_day.gif',
150 'title': 'Calendrier iCal'},
151 {'url_prefix': 'http://www.google.com/calendar/render?cid=',
152 'img': 'images/goodies/add-google-calendar.gif',
153 'title': 'Ajouter à Google Calendar'},
154 {'url_prefix': 'https://www.google.com/calendar/hosted/polytechnique.org/render?cid=',
155 'img': 'images/goodies/add-google-calendar.gif',
156 'title': 'Ajouter à Google Apps / Calendar'}
160 var __goodies_rss
= {
161 default_title
: 'Fils RSS',
164 'img': 'images/icons/feed.gif',
166 {'url_prefix': 'http://fusion.google.com/add?feedurl=',
167 'img': 'images/goodies/add-google.gif',
168 'alt': 'Add to Google',
169 'title': 'Ajouter à iGoogle/Google Reader'},
170 {'url_prefix': 'http://www.netvibes.com/subscribe.php?url=',
171 'img': 'images/goodies/add-netvibes.gif',
172 'title': 'Ajouter à Netvibes'},
173 {'url_prefix': 'http://add.my.yahoo.com/content?.intl=fr&url=',
174 'img': 'images/goodies/add-yahoo.gif',
175 'alt': 'Add to My Yahoo!',
176 'title': 'Ajouter à My Yahoo!'}
180 function disableGoodiesPopups() {
181 __goodies_active
= false;
184 function goodiesPopup(node
, goodies
) {
185 var text
= '<div style="text-align: center; line-height: 2.2">';
186 for (var site
in goodies
.sites
) {
187 var entry
= goodies
.sites
[site
];
188 var s_alt
= entry
["alt"] ? entry
["alt"] : "";
189 var s_img
= entry
["img"];
190 var s_title
= entry
["title"] ? entry
["title"] : "";
191 var s_url
= entry
["url_prefix"].length
> 0 ? entry
["url_prefix"] + escape(this.href
) : this.href
;
193 text
+= '<a href="' + s_url
+ '"><img src="' + s_img
+ '" title="' + s_title
+ '" alt="' + s_alt
+ '"></a><br />';
195 text
+= '<a href="https://www.polytechnique.org/Xorg/Goodies">Plus de bonus</a> ...</div>';
197 var title
= node
.title
? node
.title
: goodies
.default_title
;
202 if (__goodies_active
) {
203 return overlib(text
, CAPTION
, title
, CLOSETEXT
, 'Fermer', DELAY
, 800, STICKY
, WIDTH
, 150);
211 // {{{ function auto_links()
213 function auto_links() {
214 var url
= document
.URL
;
215 var fqdn
= url
.replace(/^https?:\/\/([^\/]*)\/.*$/,'$1');
216 var light
= (url
.indexOf('display=light') > url
.indexOf('?'));
217 var resource_page
= (url
.indexOf('rss') > -1 || url
.indexOf('ical') > -1);
223 if(!href
|| node
.hasClass('xdx')
224 || href
.indexOf('mailto:') > -1 || href
.indexOf('javascript:') > -1) {
227 if ((href
.indexOf(fqdn
) < 0 && this.className
.indexOf('popup') < 0) || node
.hasClass('popup')) {
228 node
.click(function () { window
.open(this.href
); return false; });
230 if (href
.indexOf(fqdn
) > -1 && light
) {
231 href
= href
.replace(/([^\#\?]*)\??([^\#]*)(\#.*)?/, "$1?display=light&$2$3");
234 rss
= href
.indexOf('rss') > -1;
235 ical
= href
.indexOf('ical') > -1;
237 if (href
.indexOf('http') < 0) {
238 href
= 'http://' + fqdn + '/' + href
;
241 if (this.nodeName
.toLowerCase() == 'a' && !resource_page
) {
242 if (rss
&& href
.indexOf('prefs/rss') < 0 && (href
.indexOf('xml') > -1 || href
.indexOf('hash'))) {
243 goodiesPopup(this, __goodies_rss
);
245 goodiesPopup(this, __goodies_ical
);
248 if(matches
= (/^popup_([0-9]*)x([0-9]*)$/).exec(this.className
)) {
249 var w
= matches
[1], h
= matches
[2];
250 node
.click(function() { return popWin(this, w
, h
); });
254 $('.popup2').click(function() { return popWin(this, 840, 600); });
255 $('.popup3').click(function() { return popWin(this, 640, 800); });
261 /***************************************************************************
265 // {{{ function checkPassword
267 function getType(c
) {
268 if (c
>= 'a' && c
<= 'z') {
270 } else if (c
>= 'A' && c
<= 'Z') {
272 } else if (c
>= '0' && c
<= '9') {
279 function differentTypes(password
) {
282 for (i
= 0 ; i
< password
.length
; ++i
) {
283 var type
= getType(password
.charAt(i
));
284 if (prev
!= 0 && prev
!= type
) {
292 function passwordStrength(password
) {
295 var firstType
= true;
296 var types
= Array(0, 0, 0, 0, 0);
298 for (i
= 0 ; i
< password
.length
; ++i
) {
299 var type
= getType(password
.charAt(i
));
300 if (prev
!= 0 && prev
!= type
) {
305 if (types
[type
] == 0 && !firstType
) {
311 if (password
.length
< 6) {
319 } else if (prop
< 0) {
326 function checkPassword(box
, okLabel
) {
327 var password
= box
.value
;
328 var prop
= passwordStrength(password
);
334 } else if (prop
>= 35) {
343 $("#passwords_measure")
345 .animate({ width
: prop
+ "%",
346 backgroundColor
: color
349 .animate({ backgroundColor
: bgcolor
}, 750);
350 var submitButton
= $(":submit[name='" + passwordprompt_submit
+ "']");
351 if (ok
&& password
.length
>= 6 && differentTypes(password
)) {
352 submitButton
.attr("value", okLabel
);
353 submitButton
.removeAttr("disabled");
355 submitButton
.attr("value", "Mot de passe trop faible");
356 submitButton
.attr("disabled", "disabled");
361 // {{{ jQuery object extension
364 /* Add new functions to jQuery namesapce */
366 xajax
: function(source
, method
, data
, onSuccess
, onError
, type
) {
368 if ($.isFunction(data
)) {
369 type
= type
|| onError
;
374 if (onError
!= null && !$.isFunction(onError
)) {
375 type
= type
|| onError
;
379 function ajaxHandler(data
, textStatus
, xhr
) {
380 if (textStatus
== 'success') {
382 onSuccess(data
, textStatus
, xhr
);
384 } else if (textStatus
== 'error') {
386 onError(data
, textStatus
, xhr
);
388 alert("Une error s'est produite lors du traitement de la requête.\n"
389 + "Ta session a peut-être expiré");
396 success
: ajaxHandler
,
402 xget
: function(source
, data
, onSuccess
, onError
, type
) {
403 return $.xajax(source
, 'GET', data
, onSuccess
, onError
, type
);
406 xgetJSON
: function(source
, data
, onSuccess
, onError
) {
407 return $.xget(source
, data
, onSuccess
, onError
, 'json');
410 xgetScript
: function(source
, onSuccess
, onError
) {
411 return $.xget(source
, null, onSuccess
, onError
, 'script');
414 xpost
: function(source
, data
, onSuccess
, onError
, type
) {
415 return $.xajax(source
, 'POST', data
, onSuccess
, onError
, type
);
419 /* Add new functions to jQuery objects */
421 tmpMessage
: function(message
, success
) {
423 this.html("<img src='images/icons/wand.gif' alt='' /> " + message
)
424 .css('color', 'green');
426 this.html("<img src='images/icons/error.gif' alt='' /> " + message
)
427 .css('color', 'red');
429 return this.css('fontWeight', 'bold')
435 updateHtml
: function(source
, callback
) {
437 function handler(data
) {
443 $.xget(source
, handler
, 'text');
447 successMessage
: function(source
, message
) {
449 $.xget(source
, function() {
450 elements
.tmpMessage(message
, true);
455 wiki
: function(text
, withTitle
) {
457 return this.html('');
459 var url
= 'wiki_preview';
464 $.post(url
, { text
: text
},
476 function previewWiki(idFrom
, idTo
, withTitle
, idShow
)
478 $('#' + idTo
).wiki($('#' + idFrom
).val(), withTitle
);
479 if (idShow
!= null) {
480 $('#' + idShow
).show();
485 // {{{ send test email
487 function sendTestEmail(token
, hruid
)
489 var url
= 'emails/test';
490 var msg
= "Un email a été envoyé avec succès";
493 msg
+= " sur l'adresse de " + hruid
+ ".";
495 msg
+= " sur ton addresse.";
497 $('#mail_sent').successMessage($url
+ '?token=' + token
, msg
);
504 /***************************************************************************
508 $(document
).ready(function() {
511 setInterval(getNow
, 1000);
514 if ($(this).val() === 'Recherche dans l\'annuaire') {
517 $("#quick_button").show();
520 $("#quick_button").hide();
522 $("#quick_button").click(function() {
523 if ($("#quick").val() === 'Recherche dans l\'annuaire'
524 || $("#quick").val() === '') {
531 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: