8805ed485805ce949759610a0f21267249041ce6
1 /***************************************************************************
2 * Copyright (C) 2003-2011 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 goodiesPopup()
134 var __goodies_active
= true;
136 var __goodies_ical
= {
137 default_title
: 'Calendrier iCal',
140 'img': 'images/icons/calendar_view_day.gif',
141 'title': 'Calendrier iCal'},
142 {'url_prefix': 'http://www.google.com/calendar/render?cid=',
143 'img': 'images/goodies/add-google-calendar.gif',
144 'title': 'Ajouter à Google Calendar'},
145 {'url_prefix': 'https://www.google.com/calendar/hosted/polytechnique.org/render?cid=',
146 'img': 'images/goodies/add-google-calendar.gif',
147 'title': 'Ajouter à Google Apps / Calendar'}
151 var __goodies_rss
= {
152 default_title
: 'Fils RSS',
155 'img': 'images/icons/feed.gif',
157 {'url_prefix': 'http://fusion.google.com/add?feedurl=',
158 'img': 'images/goodies/add-google.gif',
159 'alt': 'Add to Google',
160 'title': 'Ajouter à iGoogle/Google Reader'},
161 {'url_prefix': 'http://www.netvibes.com/subscribe.php?url=',
162 'img': 'images/goodies/add-netvibes.gif',
163 'title': 'Ajouter à Netvibes'},
164 {'url_prefix': 'http://add.my.yahoo.com/content?.intl=fr&url=',
165 'img': 'images/goodies/add-yahoo.gif',
166 'alt': 'Add to My Yahoo!',
167 'title': 'Ajouter à My Yahoo!'}
171 function disableGoodiesPopups() {
172 __goodies_active
= false;
175 function goodiesPopup(node
, goodies
) {
176 var text
= '<div style="text-align: center; line-height: 2.2">';
177 for (var site
in goodies
.sites
) {
178 var entry
= goodies
.sites
[site
];
179 var s_alt
= entry
["alt"] ? entry
["alt"] : "";
180 var s_img
= entry
["img"];
181 var s_title
= entry
["title"] ? entry
["title"] : "";
182 var s_url
= entry
["url_prefix"].length
> 0 ? entry
["url_prefix"] + escape(this.href
) : this.href
;
184 text
+= '<a href="' + s_url
+ '"><img src="' + s_img
+ '" title="' + s_title
+ '" alt="' + s_alt
+ '"></a><br />';
186 text
+= '<a href="https://www.polytechnique.org/Xorg/Goodies">Plus de bonus</a> ...</div>';
188 var title
= node
.title
? node
.title
: goodies
.default_title
;
193 if (__goodies_active
) {
194 return overlib(text
, CAPTION
, title
, CLOSETEXT
, 'Fermer', DELAY
, 800, STICKY
, WIDTH
, 150);
202 // {{{ function auto_links()
204 function auto_links() {
205 var url
= document
.URL
;
206 var fqdn
= url
.replace(/^https?:\/\/([^\/]*)\/.*$/,'$1');
207 var light
= (url
.indexOf('display=light') > url
.indexOf('?'));
208 var resource_page
= (url
.indexOf('rss') > -1 || url
.indexOf('ical') > -1);
210 $("a,link").each(function(i
) {
212 var href
= this.href
;
213 if(!href
|| node
.hasClass('xdx')
214 || href
.indexOf('mailto:') > -1 || href
.indexOf('javascript:') > -1) {
217 if ((href
.indexOf(fqdn
) < 0 && this.className
.indexOf('popup') < 0) || node
.hasClass('popup')) {
218 node
.click(function () {
223 if (href
.indexOf(fqdn
) > -1 && light
) {
224 href
= href
.replace(/([^\#\?]*)\??([^\#]*)(\#.*)?/, "$1?display=light&$2$3");
227 var rss
= href
.indexOf('rss') > -1;
228 var ical
= href
.indexOf('ical') > -1;
230 if (href
.indexOf('http') < 0) {
231 href
= 'http://' + fqdn + '/' + href
;
234 if (this.nodeName
.toLowerCase() == 'a' && !resource_page
) {
235 if (rss
&& href
.indexOf('prefs/rss') < 0 && (href
.indexOf('xml') > -1 || href
.indexOf('hash'))) {
236 goodiesPopup(this, __goodies_rss
);
238 goodiesPopup(this, __goodies_ical
);
241 if(matches
= (/^popup_([0-9]*)x([0-9]*)$/).exec(this.className
)) {
242 var w
= matches
[1], h
= matches
[2];
246 $('.popup2').popWin(840, 600);
247 $('.popup3').popWin(640, 800);
253 /***************************************************************************
257 // {{{ function checkPassword
259 function getType(c
) {
260 if (c
>= 'a' && c
<= 'z') {
262 } else if (c
>= 'A' && c
<= 'Z') {
264 } else if (c
>= '0' && c
<= '9') {
271 function differentTypes(password
) {
274 for (i
= 0 ; i
< password
.length
; ++i
) {
275 var type
= getType(password
.charAt(i
));
276 if (prev
!= 0 && prev
!= type
) {
284 function passwordStrength(password
) {
287 var firstType
= true;
288 var types
= Array(0, 0, 0, 0, 0);
290 for (i
= 0 ; i
< password
.length
; ++i
) {
291 var type
= getType(password
.charAt(i
));
292 if (prev
!= 0 && prev
!= type
) {
297 if (types
[type
] == 0 && !firstType
) {
303 if (password
.length
< 6) {
311 } else if (prop
< 0) {
318 function checkPassword(box
, okLabel
) {
319 var password
= box
.value
;
320 var prop
= passwordStrength(password
);
326 } else if (prop
>= 35) {
335 $("#passwords_measure")
337 .animate({ width
: prop
+ "%",
338 backgroundColor
: color
341 .animate({ backgroundColor
: bgcolor
}, 750);
342 var submitButton
= $(":submit[name='" + passwordprompt_submit
+ "']");
343 if (ok
&& password
.length
>= 6 && differentTypes(password
)) {
344 submitButton
.attr("value", okLabel
);
345 submitButton
.removeAttr("disabled");
347 submitButton
.attr("value", "Mot de passe trop faible");
348 submitButton
.attr("disabled", "disabled");
353 // {{{ jQuery object extension
356 /* Add new functions to jQuery namesapce */
358 /* The goal of the following functions is to provide an AJAX API that
359 * take a different callback in case of HTTP success code (2XX) and in
363 xajax
: function(source
, method
, data
, onSuccess
, onError
, type
) {
365 if ($.isFunction(data
)) {
366 type
= type
|| onError
;
371 if (onError
!= null && !$.isFunction(onError
)) {
372 type
= type
|| onError
;
376 function ajaxHandler(data
, textStatus
, xhr
) {
377 if (textStatus
== 'success') {
379 onSuccess(data
, textStatus
, xhr
);
381 } else if (textStatus
== 'error') {
383 onError(data
, textStatus
, xhr
);
385 alert("Une error s'est produite lors du traitement de la requête.\n"
386 + "Ta session a peut-être expiré");
393 success
: ajaxHandler
,
399 xget
: function(source
, data
, onSuccess
, onError
, type
) {
400 return $.xajax(source
, 'GET', data
, onSuccess
, onError
, type
);
403 xgetJSON
: function(source
, data
, onSuccess
, onError
) {
404 return $.xget(source
, data
, onSuccess
, onError
, 'json');
407 xgetScript
: function(source
, onSuccess
, onError
) {
408 return $.xget(source
, null, onSuccess
, onError
, 'script');
411 xgetText
: function(source
, data
, onSuccess
, onError
) {
412 return $.xget(source
, data
, onSuccess
, onError
, 'text');
415 xpost
: function(source
, data
, onSuccess
, onError
, type
) {
416 return $.xajax(source
, 'POST', data
, onSuccess
, onError
, type
);
420 /* Add new functions to jQuery objects */
422 tmpMessage
: function(message
, success
) {
424 this.html("<img src='images/icons/wand.gif' alt='' /> " + message
)
425 .css('color', 'green');
427 this.html("<img src='images/icons/error.gif' alt='' /> " + message
)
428 .css('color', 'red');
430 return this.css('fontWeight', 'bold')
436 updateHtml
: function(source
, callback
) {
438 function handler(data
) {
444 $.xget(source
, handler
, 'text');
448 successMessage
: function(source
, message
) {
450 $.xget(source
, function() {
451 elements
.tmpMessage(message
, true);
456 wiki
: function(text
, withTitle
) {
458 return this.html('');
460 var url
= 'wiki_preview';
465 $.post(url
, { text
: text
},
472 popWin
: function(w
, h
) {
473 return this.click(function() {
474 window
.open(this.href
, '_blank',
475 'toolbar=0,location=0,directories=0,status=0,'
476 +'menubar=0,scrollbars=1,resizable=1,'
477 +'width='+w
+',height='+h
);
487 function previewWiki(idFrom
, idTo
, withTitle
, idShow
)
489 $('#' + idTo
).wiki($('#' + idFrom
).val(), withTitle
);
490 if (idShow
!= null) {
491 $('#' + idShow
).show();
496 // {{{ send test email
498 function sendTestEmail(token
, hruid
)
500 var url
= 'emails/test';
501 var msg
= "Un email a été envoyé avec succès";
504 msg
+= " sur l'adresse de " + hruid
+ ".";
506 msg
+= " sur ton addresse.";
508 $('#mail_sent').successMessage($url
+ '?token=' + token
, msg
);
515 /***************************************************************************
519 $(document
).ready(function() {
522 setInterval(getNow
, 1000);
525 if ($(this).val() === 'Recherche dans l\'annuaire') {
528 $("#quick_button").show();
531 $("#quick_button").hide();
533 $("#quick_button").click(function() {
534 if ($("#quick").val() === 'Recherche dans l\'annuaire'
535 || $("#quick").val() === '') {
542 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: