67d106addc3039814fe8cfb2418f5dc460f639f2
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 // {{{ function getNow()
22 var days
= ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
23 var months
= ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet',
24 'août', 'septembre', 'octobre', 'novembre', 'décembre'];
29 var mh
= dt
.getMonth();
30 var wd
= dt
.getDate();
31 var yr
= dt
.getYear();
32 var hr
= dt
.getHours();
33 var mi
= dt
.getMinutes();
34 var se
= dt
.getSeconds();
46 $(".date-heure").html(days
[dy
] + ' ' + wd
+ ' ' + months
[mh
] + ' ' + yr
+ '<br />'
47 + hr
+ ':' + mi
+ ':' + se
);
53 function canAddSearchEngine()
55 if (((typeof window
.sidebar
=== "object") && $.isFunction(window
.sidebar
.addSearchEngine
))
56 || ((typeof window
.external
=== "object") && $.isFunction(window
.external
.AddSearchProvider
))) {
62 function addSearchEngine()
64 var searchURI
= "http://www.polytechnique.org/xorg.opensearch.xml";
65 if ((typeof window
.sidebar
=== "object") && $.isFunction(window
.sidebar
.addSearchEngine
)) {
66 window
.sidebar
.addSearchEngine(
68 "http://www.polytechnique.org/images/xorg.png",
69 "Annuaire Polytechnique.org",
73 window
.external
.AddSearchProvider(searchURI
);
75 alert("Impossible d'installer la barre de recherche");
82 /***************************************************************************
86 // {{{ function goodiesPopup()
91 default_title
: 'Calendrier iCal',
94 img
: 'images/icons/calendar_view_day.gif',
95 title
: 'Calendrier iCal'},
96 {url_prefix
: 'http://www.google.com/calendar/render?cid=',
97 img
: 'images/goodies/add-google-calendar.gif',
98 title
: 'Ajouter à Google Calendar'},
99 {url_prefix
: 'https://www.google.com/calendar/hosted/polytechnique.org/render?cid=',
100 img
: 'images/goodies/add-google-calendar.gif',
101 title
: 'Ajouter à Google Apps / Calendar'}
106 default_title
: 'Fils RSS',
109 img
: 'images/icons/feed.gif',
111 {url_prefix
: 'http://fusion.google.com/add?feedurl=',
112 img
: 'images/goodies/add-google.gif',
113 alt
: 'Add to Google',
114 title
: 'Ajouter à iGoogle/Google Reader'},
115 {url_prefix
: 'http://www.netvibes.com/subscribe.php?url=',
116 img
: 'images/goodies/add-netvibes.gif',
117 title
: 'Ajouter à Netvibes'},
118 {url_prefix
: 'http://add.my.yahoo.com/content?.intl=fr&url=',
119 img
: 'images/goodies/add-yahoo.gif',
120 alt
: 'Add to My Yahoo!',
121 title
: 'Ajouter à My Yahoo!'}
127 goodiesPopup
: function goodiesPopup(type
) {
128 var text
= '<div style="text-align: center; line-height: 2.2">';
135 var href
= this.attr('href');
137 for (site
in goodies
[type
].sites
) {
138 entry
= goodies
[type
].sites
[site
];
139 s_alt
= entry
.alt
|| "";
141 s_title
= entry
.title
|| "";
142 s_url
= entry
.url_prefix
.length
> 0 ? entry
.url_prefix
+ escape(href
) : href
;
144 text
+= '<a href="' + s_url
+ '"><img src="' + s_img
+ '" title="' + s_title
+ '" alt="' + s_alt
+ '"></a><br />';
146 text
+= '<a href="https://www.polytechnique.org/Xorg/Goodies">Plus de bonus</a> ...</div>';
148 return this.overlib({
150 caption
: this.attr('title') || goodies
.default_title
,
151 close_text
: 'Fermer',
161 // {{{ function auto_links()
163 function auto_links() {
164 var url
= document
.URL
;
165 var fqdn
= url
.replace(/^https?:\/\/([^\/]*)\/.*$/,'$1');
166 var light
= url
.indexOf('display=light') > url
.indexOf('?');
167 var resource_page
= url
.contains('rss') || url
.contains('ical');
169 $("a,link").each(function(i
) {
171 var href
= this.href
;
176 if(!href
|| node
.hasClass('xdx')
177 || href
.startsWith('mailto:') || href
.startsWith('javascript:')) {
180 if ((!href
.contains(fqdn
) && !this.className
.contains('popup')) || node
.hasClass('popup')) {
181 node
.click(function () {
182 window
.open($.plURL(this.href
));
186 if (href
.contains(fqdn
) && light
) {
187 href
= href
.replace(/([^\#\?]*)\??([^\#]*)(\#.*)?/, "$1?display=light&$2$3");
190 rss
= href
.contains('rss');
191 ical
= href
.contains('ical');
193 if (!href
.startsWith('http')) {
194 href
= 'http://' + fqdn + '/' + href
;
197 if (this.nodeName
.toLowerCase() === 'a' && !resource_page
) {
198 if (rss
&& !href
.contains('prefs/rss') && (href
.contains('xml') || href
.contains('hash'))) {
199 node
.goodiesPopup('rss');
201 node
.goodiesPopup('ical');
204 matches
= /^popup_([0-9]*)x([0-9]*)$/.exec(this.className
);
206 node
.popWin(matches
[1], matches
[2]);
209 $('.popup2').popWin(840, 600);
210 $('.popup3').popWin(640, 800);
216 /***************************************************************************
220 // {{{ function checkPassword
222 /* {{{ SHA1 Implementation */
225 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
227 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
228 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
229 * Distributed under the BSD License
230 * See http://pajhome.org.uk/crypt/md5 for details.
234 * Configurable variables. You may need to tweak these to be compatible with
235 * the server-side, but the defaults work in most cases.
237 var hexcase
= 0; /* hex output format. 0 - lowercase; 1 - uppercase */
238 var b64pad
= ""; /* base-64 pad character. "=" for strict RFC compliance */
239 var chrsz
= 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
242 * These are the functions you'll usually want to call
243 * They take string arguments and return either hex or base-64 encoded strings
245 function hex_sha1(s
){return binb2hex(core_sha1(str2binb(s
),s
.length
* chrsz
));}
246 function b64_sha1(s
){return binb2b64(core_sha1(str2binb(s
),s
.length
* chrsz
));}
247 function str_sha1(s
){return binb2str(core_sha1(str2binb(s
),s
.length
* chrsz
));}
248 function hex_hmac_sha1(key
, data
){ return binb2hex(core_hmac_sha1(key
, data
));}
249 function b64_hmac_sha1(key
, data
){ return binb2b64(core_hmac_sha1(key
, data
));}
250 function str_hmac_sha1(key
, data
){ return binb2str(core_hmac_sha1(key
, data
));}
253 * Perform a simple self-test to see if the VM is working
255 function sha1_vm_test()
257 return hex_sha1("abc") === "a9993e364706816aba3e25717850c26c9cd0d89d";
261 * Calculate the SHA-1 of an array of big-endian words, and a bit length
263 function core_sha1(x
, len
)
265 var w
, a
, b
, c
, d
, e
;
266 var olda
, oldb
, oldc
, oldd
, olde
;
270 x
[len
>> 5] |= 0x80 << (24 - len
% 32);
271 x
[((len
+ 64 >> 9) << 4) + 15] = len
;
280 for(i
= 0; i
< x
.length
; i
+= 16)
288 for(j
= 0; j
< 80; j
++)
290 if(j
< 16) w
[j
] = x
[i
+ j
];
291 else w
[j
] = rol(w
[j
-3] ^ w
[j
-8] ^ w
[j
-14] ^ w
[j
-16], 1);
292 t
= safe_add(safe_add(rol(a
, 5), sha1_ft(j
, b
, c
, d
)),
293 safe_add(safe_add(e
, w
[j
]), sha1_kt(j
)));
301 a
= safe_add(a
, olda
);
302 b
= safe_add(b
, oldb
);
303 c
= safe_add(c
, oldc
);
304 d
= safe_add(d
, oldd
);
305 e
= safe_add(e
, olde
);
307 return Array(a
, b
, c
, d
, e
);
312 * Perform the appropriate triplet combination function for the current
315 function sha1_ft(t
, b
, c
, d
)
317 if(t
< 20) return (b
& c
) | ((~b
) & d
);
318 if(t
< 40) return b
^ c
^ d
;
319 if(t
< 60) return (b
& c
) | (b
& d
) | (c
& d
);
324 * Determine the appropriate additive constant for the current iteration
328 return (t
< 20) ? 1518500249 : (t
< 40) ? 1859775393 :
329 (t
< 60) ? -1894007588 : -899497514;
333 * Calculate the HMAC-SHA1 of a key and some data
335 function core_hmac_sha1(key
, data
)
337 var bkey
= str2binb(key
);
341 if(bkey
.length
> 16) bkey
= core_sha1(bkey
, key
.length
* chrsz
);
345 for(i
= 0; i
< 16; i
++)
347 ipad
[i
] = bkey
[i
] ^ 0x36363636;
348 opad
[i
] = bkey
[i
] ^ 0x5C5C5C5C;
351 hash
= core_sha1(ipad
.concat(str2binb(data
)), 512 + data
.length
* chrsz
);
352 return core_sha1(opad
.concat(hash
), 512 + 160);
356 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
357 * to work around bugs in some JS interpreters.
359 function safe_add(x
, y
)
361 var lsw
= (x
& 0xFFFF) + (y
& 0xFFFF);
362 var msw
= (x
>> 16) + (y
>> 16) + (lsw
>> 16);
363 return (msw
<< 16) | (lsw
& 0xFFFF);
367 * Bitwise rotate a 32-bit number to the left.
369 function rol(num
, cnt
)
371 return (num
<< cnt
) | (num
>>> (32 - cnt
));
375 * Convert an 8-bit or 16-bit string to an array of big-endian words
376 * In 8-bit function, characters >255 have their hi-byte silently ignored.
378 function str2binb(str
)
381 var mask
= (1 << chrsz
) - 1;
383 for(i
= 0; i
< str
.length
* chrsz
; i
+= chrsz
)
384 bin
[i
>>5] |= (str
.charCodeAt(i
/ chrsz
) & mask
) << (32 - chrsz
- i
%32);
389 * Convert an array of big-endian words to a string
391 function binb2str(bin
)
394 var mask
= (1 << chrsz
) - 1;
396 for(i
= 0; i
< bin
.length
* 32; i
+= chrsz
)
397 str
+= String
.fromCharCode((bin
[i
>>5] >>> (32 - chrsz
- i
%32)) & mask
);
402 * Convert an array of big-endian words to a hex string.
404 function binb2hex(binarray
)
406 var hex_tab
= hexcase
? "0123456789ABCDEF" : "0123456789abcdef";
409 for(i
= 0; i
< binarray
.length
* 4; i
++)
411 str
+= hex_tab
.charAt((binarray
[i
>>2] >> ((3 - i
%4)*8+4)) & 0xF) +
412 hex_tab
.charAt((binarray
[i
>>2] >> ((3 - i
%4)*8 )) & 0xF);
418 * Convert an array of big-endian words to a base-64 string
420 function binb2b64(binarray
)
422 var tab
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
425 for(i
= 0; i
< binarray
.length
* 4; i
+= 3)
427 triplet
= (((binarray
[i
>> 2] >> 8 * (3 - i
%4)) & 0xFF) << 16)
428 | (((binarray
[i
+1 >> 2] >> 8 * (3 - (i
+1)%4)) & 0xFF) << 8 )
429 | ((binarray
[i
+2 >> 2] >> 8 * (3 - (i
+2)%4)) & 0xFF);
430 for(j
= 0; j
< 4; j
++)
432 if(i
* 8 + j
* 6 > binarray
.length
* 32) str
+= b64pad
;
433 else str
+= tab
.charAt((triplet
>> 6*(3-j
)) & 0x3F);
441 function hash_encrypt(a
) {
445 var hexa_h
= "0123456789abcdef";
448 return hexa_h
.charAt(a
);
452 return hexa_h
.indexOf(a
);
455 function hash_xor(a
, b
) {
464 for (k
= 0; k
< j
; k
++) {
465 c
+= dechex(hexdec(a
.charAt(k
)) ^ hexdec(b
.charAt(k
)));
473 function getType(c
) {
474 if (c
>= 'a' && c
<= 'z') {
476 } else if (c
>= 'A' && c
<= 'Z') {
478 } else if (c
>= '0' && c
<= '9') {
485 function differentTypes(password
) {
489 for (i
= 0 ; i
< password
.length
; ++i
) {
490 type
= getType(password
.charAt(i
));
491 if (prev
!== 0 && prev
!== type
) {
499 function passwordStrength(password
) {
502 var firstType
= true;
503 var types
= Array(0, 0, 0, 0, 0);
506 for (i
= 0 ; i
< password
.length
; ++i
) {
507 type
= getType(password
.charAt(i
));
508 if (prev
!== 0 && prev
!== type
) {
513 if (types
[type
] === 0 && !firstType
) {
519 if (password
.length
< 6) {
527 } else if (prop
< 0) {
534 function checkPassword(box
, okLabel
) {
535 var password
= box
.value
;
536 var prop
= passwordStrength(password
);
543 } else if (prop
>= 35) {
552 $("#passwords_measure")
554 .animate({ width
: prop
+ "%",
555 backgroundColor
: color
558 .animate({ backgroundColor
: bgcolor
}, 750);
559 submitButton
= $(":submit[name='" + passwordprompt_submit
+ "']");
560 if (ok
&& password
.length
>= 6 && differentTypes(password
)) {
561 submitButton
.attr("value", okLabel
);
562 submitButton
.removeAttr("disabled");
564 submitButton
.attr("value", "Mot de passe trop faible");
565 submitButton
.attr("disabled", "disabled");
569 function hashResponse(password1
, password2
, hasConfirmation
, doAuth
) {
570 var pw1
= $('[name=' + password1
+ ']').val();
573 if (hasConfirmation
) {
574 pw2
= $('[name=' + password2
+ ']').val();
576 alert("\nErreur : les deux champs ne sont pas identiques !");
579 $('[name=' + password2
+ ']').val('');
580 } else if (pw1
=== '********') {
584 if (pw1
.length
< 6) {
585 alert("\nErreur : le nouveau mot de passe doit faire au moins 6 caractères !");
588 if (!differentTypes(pw1
)) {
589 alert ("\nErreur : le nouveau mot de passe doit comporter au moins deux types de caractères parmi les suivants : lettres minuscules, lettres majuscules, chiffres, caractères spéciaux.");
593 alert("Le mot de passe va être chiffré avant de nous parvenir par Internet ! Ainsi il ne circulera pas en clair.");
594 $('[name=' + password1
+ ']').val('');
595 $('[name=pwhash]').val(hash_encrypt(pw1
));
598 $('[name=password]').val(pw1
);
599 doChallengeResponse();
605 function correctUserName() {
606 var u
= document
.forms
.login
.username
;
609 // login with no space
610 if (!u
.value
.contains(' ')) {
613 mots
= u
.value
.split(' ');
614 // jean paul.du pont -> jean-paul.du-pont
615 if (u
.value
.contains('.')) {
616 u
.value
= mots
.join('-');
619 // jean dupont -> jean.dupont
620 if (mots
.length
=== 2) {
621 u
.value
= mots
[0] + "." + mots
[1];
624 // jean dupont 2001 -> jean.dupont.2001
625 if (mots
.length
=== 3 && mots
[2] > 1920 && mots
[2] < 3000) {
626 u
.value
= mots
.join('.');
629 // jean de la vallee -> jean.de-la-vallee
630 if (mots
[1].toUpperCase() === 'DE') {
631 u
.value
= mots
[0] + "." + mots
.join('-').substr(mots
[0].length
+1);
634 // jean paul dupont -> jean-paul.dupont
635 if (mots
.length
=== 3 && mots
[0].toUpperCase() === 'JEAN') {
636 u
.value
= mots
[0] + "-" + mots
[1] + "." + mots
[2];
640 alert('Ton email ne doit pas contenir de blanc.\nLe format standard est\n\nprenom.nom.promotion\n\nSi ton nom ou ton prenom est composé,\nsépare les mots par des -');
645 function doChallengeResponse() {
646 var new_pass
, old_pass
, str
;
648 if (!correctUserName()) {
652 new_pass
= hash_encrypt(document
.forms
.login
.password
.value
);
653 old_pass
= hash_encrypt(document
.forms
.login
.password
.value
.substr(0, 10));
655 str
= document
.forms
.login
.username
.value
+ ":" +
657 document
.forms
.loginsub
.challenge
.value
;
659 document
.forms
.loginsub
.response
.value
= hash_encrypt(str
);
660 if (new_pass
!== old_pass
) {
661 document
.forms
.loginsub
.xorpass
.value
= hash_xor(new_pass
, old_pass
);
663 document
.forms
.loginsub
.username
.value
= document
.forms
.login
.username
.value
;
664 document
.forms
.loginsub
.remember
.value
= document
.forms
.login
.remember
.checked
;
665 document
.forms
.login
.password
.value
= "";
666 document
.forms
.loginsub
.submit();
669 function doChallengeResponseLogged() {
670 var str
= document
.forms
.loginsub
.username
.value
+ ":" +
671 hash_encrypt(document
.forms
.login
.password
.value
) + ":" +
672 document
.forms
.loginsub
.challenge
.value
;
674 document
.forms
.loginsub
.response
.value
= hash_encrypt(str
);
675 document
.forms
.loginsub
.remember
.value
= document
.forms
.login
.remember
.checked
;
676 document
.forms
.login
.password
.value
= "";
677 document
.forms
.loginsub
.submit();
681 // {{{ send test email
683 function sendTestEmail(token
, hruid
)
685 var url
= 'emails/test';
686 var msg
= "Un email a été envoyé avec succès";
689 msg
+= " sur l'adresse de " + hruid
+ ".";
691 msg
+= " sur ton addresse.";
693 $('#mail_sent').successMessage(url
+ '?token=' + token
, msg
);
698 // {{{ jQuery object extension
701 /* Add new functions to jQuery namesapce */
703 /* The goal of the following functions is to provide an AJAX API that
704 * take a different callback in case of HTTP success code (2XX) and in
708 xajax
: function(source
, method
, data
, onSuccess
, onError
, type
) {
710 if ($.isFunction(data
)) {
711 type
= type
|| onError
;
716 if (onError
!= null && !$.isFunction(onError
)) {
717 type
= type
|| onError
;
721 function ajaxHandler(data
, textStatus
, xhr
) {
722 if (textStatus
== 'success') {
724 onSuccess(data
, textStatus
, xhr
);
726 } else if (textStatus
== 'error') {
728 onError(data
, textStatus
, xhr
);
730 alert("Une error s'est produite lors du traitement de la requête.\n"
731 + "Ta session a peut-être expiré");
738 success
: ajaxHandler
,
744 xget
: function(source
, data
, onSuccess
, onError
, type
) {
745 return $.xajax(source
, 'GET', data
, onSuccess
, onError
, type
);
748 xgetJSON
: function(source
, data
, onSuccess
, onError
) {
749 return $.xget(source
, data
, onSuccess
, onError
, 'json');
752 xgetScript
: function(source
, onSuccess
, onError
) {
753 return $.xget(source
, null, onSuccess
, onError
, 'script');
756 xgetText
: function(source
, data
, onSuccess
, onError
) {
757 return $.xget(source
, data
, onSuccess
, onError
, 'text');
760 xpost
: function(source
, data
, onSuccess
, onError
, type
) {
761 return $.xajax(source
, 'POST', data
, onSuccess
, onError
, type
);
765 /* Add new functions to jQuery objects */
767 tmpMessage
: function(message
, success
) {
769 this.html("<img src='images/icons/wand.gif' alt='' /> " + message
)
770 .css('color', 'green');
772 this.html("<img src='images/icons/error.gif' alt='' /> " + message
)
773 .css('color', 'red');
775 return this.css('fontWeight', 'bold')
781 updateHtml
: function(source
, callback
) {
783 function handler(data
) {
789 $.xget(source
, handler
, 'text');
793 successMessage
: function(source
, message
) {
795 $.xget(source
, function() {
796 elements
.tmpMessage(message
, true);
801 wiki
: function(text
, withTitle
) {
803 return this.html('');
805 var url
= 'wiki_preview';
810 $.post(url
, { text
: text
},
817 popWin
: function(w
, h
) {
818 return this.click(function() {
819 window
.open($.plURL(this.href
), '_blank',
820 'toolbar=0,location=0,directories=0,status=0,'
821 +'menubar=0,scrollbars=1,resizable=1,'
822 +'width='+w
+',height='+h
);
832 function previewWiki(idFrom
, idTo
, withTitle
, idShow
)
834 $('#' + idTo
).wiki($('#' + idFrom
).val(), withTitle
);
835 if (idShow
!= null) {
836 $('#' + idShow
).show();
841 // {{{ updatepromofields
843 function updatepromofields(egal1
, egal2
, promo2
) {
844 var comparator
= egal1
.val();
846 if (comparator
== '=') {
847 egal2
.attr('disabled', 'disabled');
848 promo2
.attr('disabled', 'disabled');
849 } else if (comparator
== '<=' || comparator
== '>=') {
850 egal2
.removeAttr('disabled');
851 promo2
.removeAttr('disabled');
852 if (comparator
== '<=') {
862 /***************************************************************************
866 /* quick search {{{ */
868 function findPos(obj
) {
869 var curleft
= obj
.offsetLeft
|| 0;
870 var curtop
= obj
.offsetTop
|| 0;
871 while (obj
= obj
.offsetParent
) {
872 curleft
+= obj
.offsetLeft
873 curtop
+= obj
.offsetTop
875 return {x
:curleft
,y
:curtop
};
878 $.template('quickMinifiche',
879 '<div class="contact grayed" style="clear: both">' +
880 '<div class="identity">' +
881 '<div class="photo"><img src="photo/${hrpid}" alt="${directory_name}" /></div>' +
882 '<div class="nom">' +
883 '{{if is_female}}•{{/if}}<a>${directory_name}</a>' +
885 '<div class="edu">${promo}</div>' +
887 '<div class="noprint bits"></div>' +
888 '<div class="long"></div>' +
892 function buildPopup(input
, destination
, linkBindFunction
)
894 var $popup
= destination
;
898 function updateSelection()
900 var sel
= $popup
.children('.contact').addClass('grayed');
901 if (selected
!== null) {
902 while (selected
< 0) {
903 selected
+= sel
.length
;
905 if (selected
>= sel
.length
) {
906 selected
-= sel
.length
;
908 sel
.eq(selected
).removeClass('grayed');
912 function formatProfile(i
, profile
) {
913 var data
= $.tmpl('quickMinifiche', profile
)
914 .css('cursor', 'pointer')
920 if (selected
=== i
) {
925 }).mouseup(function() {
926 var sel
= $(this).find('a');
927 if (!sel
.attr('hovered')) {
931 data
.find('a').hover(function() { $(this).attr('hovered', true) },
932 function() { $(this).attr('hovered', false) });
937 $popup
= $('<div>').hide()
938 .addClass('contact-list')
940 position
: 'absolute',
942 top
: input
.css('bottom'),
950 hide
: function(ignoreIfHover
) {
951 if (ignoreIfHover
&& hovered
!== 0) {
961 var pos
= findPos(input
.get(0));
962 $popup
.css('left', pos
.x
- 300 + input
.width()).show();
966 selected
: function() {
967 return selected
!== null;
970 unselect
: function() {
975 selectNext
: function() {
976 if (selected
=== null) {
985 selectPrev
: function() {
986 if (selected
=== null) {
995 activeCurrent
: function() {
996 var sel
= $popup
.children('.contact');
997 if (selected
!== null) {
998 sel
.eq(selected
).find('a').click();
1004 updateContent
: function(profiles
, extra
) {
1008 for (var i
= 0, len
= profiles
.length
; i
< len
; i
++) {
1010 var profile
= formatProfile(i
, elt
);
1011 profile
.find('a').each(function() {
1012 linkBindFunction
.call(this, elt
, $this, extra
);
1014 profile
.appendTo($popup
);
1034 quickSearch
: function(options
) {
1035 return this.each(function() {
1036 var $this = $(this);
1039 var previous
= null;
1040 var pending
= false;
1041 var disabled
= false;
1044 options
= options
|| { };
1045 options
= $.extend({
1056 loadingClassLeft
: 'ac_loading',
1057 loadingClassRight
: 'ac_loading_left',
1058 selectAction
: function(profile
, popup
, extra
) {
1059 var type
= extra
.link_type
|| 'profile';
1062 $(this).attr('href', 'profile/' + profile
.hrpid
)
1064 .click(function() { $popup
.hide(); return false; });
1067 $(this).attr('href', 'admin/user/' + profile
.hrpid
)
1068 .click(function() { window
.open($.plURL(this.href
)); return false });
1073 options
.loadingClass
= $this.css('text-align') === 'right' ? options
.loadingClassRight
1074 : options
.loadingClassLeft
;
1075 $this.attr('autocomplete', 'off');
1076 $popup
= buildPopup($this, options
.destination
, options
.selectAction
);
1078 function markPending() {
1082 function performUpdate(quick
)
1084 if (updatePopup
=== markPending
) {
1087 updatePopup
= markPending
;
1088 $this.addClass(options
.loadingClass
);
1089 $.xapi('search', $.extend({ 'quick': quick
}, options
.queryParams
), function(data
) {
1090 if (data
.profile_count
> options
.queryParams
.count
|| data
.profile_count
< 0) {
1091 return $popup
.hide();
1093 $popup
.updateContent(data
.profiles
, data
);
1095 }, function(data
, text
) {
1096 if (text
!== 'abort') {
1099 }).complete(function() {
1100 $this.removeClass(options
.loadingClass
);
1101 updatePopup
= doUpdatePopup
;
1109 function doUpdatePopup(dontDelay
)
1111 var quick
= $this.val();
1112 if ($.isFunction(quick
.trim
)) {
1113 quick
= quick
.trim();
1116 if (disabled
|| quick
.length
< options
.minChars
) {
1118 return $popup
.hide();
1119 } else if (!dontDelay
) {
1120 var timeout
= quick
.length
< options
.shortChars
? options
.shortTimeout
: options
.longTimeout
;
1121 setTimeout(function() {
1125 } else if (previous
=== quick
) {
1126 return $popup
.show();
1128 return performUpdate(quick
);
1131 updatePopup
= doUpdatePopup
;
1133 return $this.keyup(function(e
) {
1134 if (e
.keyCode
!== 27 /* escape */ && e
.keyCode
!== 13 /* enter */
1135 && e
.keyCode
!== 9 /* tab */ && e
.keyCode
!== 38 /* up */
1136 && e
.keyCode
!== 40 /* down */) {
1137 return updatePopup();
1141 .keydown(function(e
) {
1142 switch (e
.keyCode
) {
1145 $popup
.selectNext();
1149 $popup
.selectPrev();
1152 case 13: /* Return */
1153 return $popup
.activeCurrent();
1155 case 27: /* Escape */
1156 if ($popup
.selected()) {
1166 return $popup
.hide(true);
1168 .focus(updatePopup
);});
1173 /***************************************************************************
1174 * Overlib made simple
1179 overlib
: function(text
, width
, height
) {
1183 if (typeof text
=== 'string') {
1186 args
.push(WIDTH
, width
);
1189 args
.push(HEIGHT
, height
);
1195 args
.unshift(text
[key
]);
1198 args
.push(CAPTION
, text
[key
]);
1201 args
.push(CLOSETEXT
, text
[key
]);
1204 args
.push(DELAY
, text
[key
]);
1212 args
.push(WIDTH
, text
[key
]);
1215 args
.push(HEIGHT
, text
[key
]);
1221 .mouseover(function () {
1222 return overlib
.apply(null, args
);
1230 /***************************************************************************
1237 setInterval(getNow
, 1000);
1240 if ($(this).val() === 'Recherche dans l\'annuaire') {
1243 $("#quick_button").show();
1246 $("#quick_button").hide();
1249 $("#quick_button").click(function() {
1250 if ($("#quick").val() === 'Recherche dans l\'annuaire'
1251 || $("#quick").val() === '') {
1258 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: