1c18fbe51cb78e3efde0ddbbb96b18bad7b0f770
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">';
136 for (site
in goodies
[type
].sites
) {
137 entry
= goodies
[type
].sites
[site
];
138 s_alt
= entry
.alt
|| "";
140 s_title
= entry
.title
|| "";
141 s_url
= entry
.url_prefix
.length
> 0 ? entry
.url_prefix
+ escape(this.href
) : this.href
;
143 text
+= '<a href="' + s_url
+ '"><img src="' + s_img
+ '" title="' + s_title
+ '" alt="' + s_alt
+ '"></a><br />';
145 text
+= '<a href="https://www.polytechnique.org/Xorg/Goodies">Plus de bonus</a> ...</div>';
147 return this.overlib({
149 caption
: this.attr('title') || goodies
.default_title
,
150 close_text
: 'Fermer',
160 // {{{ function auto_links()
162 function auto_links() {
163 var url
= document
.URL
;
164 var fqdn
= url
.replace(/^https?:\/\/([^\/]*)\/.*$/,'$1');
165 var light
= url
.indexOf('display=light') > url
.indexOf('?');
166 var resource_page
= url
.contains('rss') || url
.contains('ical');
168 $("a,link").each(function(i
) {
170 var href
= this.href
;
175 if(!href
|| node
.hasClass('xdx')
176 || href
.startsWith('mailto:') || href
.startsWith('javascript:')) {
179 if ((!href
.contains(fqdn
) && !this.className
.contains('popup')) || node
.hasClass('popup')) {
180 node
.click(function () {
185 if (href
.contains(fqdn
) && light
) {
186 href
= href
.replace(/([^\#\?]*)\??([^\#]*)(\#.*)?/, "$1?display=light&$2$3");
189 rss
= href
.contains('rss');
190 ical
= href
.contains('ical');
192 if (!href
.startsWith('http')) {
193 href
= 'http://' + fqdn + '/' + href
;
196 if (this.nodeName
.toLowerCase() === 'a' && !resource_page
) {
197 if (rss
&& !href
.contains('prefs/rss') && (href
.contains('xml') || href
.contains('hash'))) {
198 node
.goodiesPopup('rss');
200 node
.goodiesPopup('ical');
203 matches
= /^popup_([0-9]*)x([0-9]*)$/.exec(this.className
);
205 node
.popWin(matches
[1], matches
[2]);
208 $('.popup2').popWin(840, 600);
209 $('.popup3').popWin(640, 800);
215 /***************************************************************************
219 // {{{ function checkPassword
221 /* {{{ SHA1 Implementation */
224 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
226 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
227 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
228 * Distributed under the BSD License
229 * See http://pajhome.org.uk/crypt/md5 for details.
233 * Configurable variables. You may need to tweak these to be compatible with
234 * the server-side, but the defaults work in most cases.
236 var hexcase
= 0; /* hex output format. 0 - lowercase; 1 - uppercase */
237 var b64pad
= ""; /* base-64 pad character. "=" for strict RFC compliance */
238 var chrsz
= 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
241 * These are the functions you'll usually want to call
242 * They take string arguments and return either hex or base-64 encoded strings
244 function hex_sha1(s
){return binb2hex(core_sha1(str2binb(s
),s
.length
* chrsz
));}
245 function b64_sha1(s
){return binb2b64(core_sha1(str2binb(s
),s
.length
* chrsz
));}
246 function str_sha1(s
){return binb2str(core_sha1(str2binb(s
),s
.length
* chrsz
));}
247 function hex_hmac_sha1(key
, data
){ return binb2hex(core_hmac_sha1(key
, data
));}
248 function b64_hmac_sha1(key
, data
){ return binb2b64(core_hmac_sha1(key
, data
));}
249 function str_hmac_sha1(key
, data
){ return binb2str(core_hmac_sha1(key
, data
));}
252 * Perform a simple self-test to see if the VM is working
254 function sha1_vm_test()
256 return hex_sha1("abc") === "a9993e364706816aba3e25717850c26c9cd0d89d";
260 * Calculate the SHA-1 of an array of big-endian words, and a bit length
262 function core_sha1(x
, len
)
264 var w
, a
, b
, c
, d
, e
;
265 var olda
, oldb
, oldc
, oldd
, olde
;
269 x
[len
>> 5] |= 0x80 << (24 - len
% 32);
270 x
[((len
+ 64 >> 9) << 4) + 15] = len
;
279 for(i
= 0; i
< x
.length
; i
+= 16)
287 for(j
= 0; j
< 80; j
++)
289 if(j
< 16) w
[j
] = x
[i
+ j
];
290 else w
[j
] = rol(w
[j
-3] ^ w
[j
-8] ^ w
[j
-14] ^ w
[j
-16], 1);
291 t
= safe_add(safe_add(rol(a
, 5), sha1_ft(j
, b
, c
, d
)),
292 safe_add(safe_add(e
, w
[j
]), sha1_kt(j
)));
300 a
= safe_add(a
, olda
);
301 b
= safe_add(b
, oldb
);
302 c
= safe_add(c
, oldc
);
303 d
= safe_add(d
, oldd
);
304 e
= safe_add(e
, olde
);
306 return Array(a
, b
, c
, d
, e
);
311 * Perform the appropriate triplet combination function for the current
314 function sha1_ft(t
, b
, c
, d
)
316 if(t
< 20) return (b
& c
) | ((~b
) & d
);
317 if(t
< 40) return b
^ c
^ d
;
318 if(t
< 60) return (b
& c
) | (b
& d
) | (c
& d
);
323 * Determine the appropriate additive constant for the current iteration
327 return (t
< 20) ? 1518500249 : (t
< 40) ? 1859775393 :
328 (t
< 60) ? -1894007588 : -899497514;
332 * Calculate the HMAC-SHA1 of a key and some data
334 function core_hmac_sha1(key
, data
)
336 var bkey
= str2binb(key
);
340 if(bkey
.length
> 16) bkey
= core_sha1(bkey
, key
.length
* chrsz
);
344 for(i
= 0; i
< 16; i
++)
346 ipad
[i
] = bkey
[i
] ^ 0x36363636;
347 opad
[i
] = bkey
[i
] ^ 0x5C5C5C5C;
350 hash
= core_sha1(ipad
.concat(str2binb(data
)), 512 + data
.length
* chrsz
);
351 return core_sha1(opad
.concat(hash
), 512 + 160);
355 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
356 * to work around bugs in some JS interpreters.
358 function safe_add(x
, y
)
360 var lsw
= (x
& 0xFFFF) + (y
& 0xFFFF);
361 var msw
= (x
>> 16) + (y
>> 16) + (lsw
>> 16);
362 return (msw
<< 16) | (lsw
& 0xFFFF);
366 * Bitwise rotate a 32-bit number to the left.
368 function rol(num
, cnt
)
370 return (num
<< cnt
) | (num
>>> (32 - cnt
));
374 * Convert an 8-bit or 16-bit string to an array of big-endian words
375 * In 8-bit function, characters >255 have their hi-byte silently ignored.
377 function str2binb(str
)
380 var mask
= (1 << chrsz
) - 1;
382 for(i
= 0; i
< str
.length
* chrsz
; i
+= chrsz
)
383 bin
[i
>>5] |= (str
.charCodeAt(i
/ chrsz
) & mask
) << (32 - chrsz
- i
%32);
388 * Convert an array of big-endian words to a string
390 function binb2str(bin
)
393 var mask
= (1 << chrsz
) - 1;
395 for(i
= 0; i
< bin
.length
* 32; i
+= chrsz
)
396 str
+= String
.fromCharCode((bin
[i
>>5] >>> (32 - chrsz
- i
%32)) & mask
);
401 * Convert an array of big-endian words to a hex string.
403 function binb2hex(binarray
)
405 var hex_tab
= hexcase
? "0123456789ABCDEF" : "0123456789abcdef";
408 for(i
= 0; i
< binarray
.length
* 4; i
++)
410 str
+= hex_tab
.charAt((binarray
[i
>>2] >> ((3 - i
%4)*8+4)) & 0xF) +
411 hex_tab
.charAt((binarray
[i
>>2] >> ((3 - i
%4)*8 )) & 0xF);
417 * Convert an array of big-endian words to a base-64 string
419 function binb2b64(binarray
)
421 var tab
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
424 for(i
= 0; i
< binarray
.length
* 4; i
+= 3)
426 triplet
= (((binarray
[i
>> 2] >> 8 * (3 - i
%4)) & 0xFF) << 16)
427 | (((binarray
[i
+1 >> 2] >> 8 * (3 - (i
+1)%4)) & 0xFF) << 8 )
428 | ((binarray
[i
+2 >> 2] >> 8 * (3 - (i
+2)%4)) & 0xFF);
429 for(j
= 0; j
< 4; j
++)
431 if(i
* 8 + j
* 6 > binarray
.length
* 32) str
+= b64pad
;
432 else str
+= tab
.charAt((triplet
>> 6*(3-j
)) & 0x3F);
440 function hash_encrypt(a
) {
444 var hexa_h
= "0123456789abcdef";
447 return hexa_h
.charAt(a
);
451 return hexa_h
.indexOf(a
);
454 function hash_xor(a
, b
) {
463 for (k
= 0; k
< j
; k
++) {
464 c
+= dechex(hexdec(a
.charAt(k
)) ^ hexdec(b
.charAt(k
)));
472 function getType(c
) {
473 if (c
>= 'a' && c
<= 'z') {
475 } else if (c
>= 'A' && c
<= 'Z') {
477 } else if (c
>= '0' && c
<= '9') {
484 function differentTypes(password
) {
488 for (i
= 0 ; i
< password
.length
; ++i
) {
489 type
= getType(password
.charAt(i
));
490 if (prev
!== 0 && prev
!== type
) {
498 function passwordStrength(password
) {
501 var firstType
= true;
502 var types
= Array(0, 0, 0, 0, 0);
505 for (i
= 0 ; i
< password
.length
; ++i
) {
506 type
= getType(password
.charAt(i
));
507 if (prev
!== 0 && prev
!== type
) {
512 if (types
[type
] === 0 && !firstType
) {
518 if (password
.length
< 6) {
526 } else if (prop
< 0) {
533 function checkPassword(box
, okLabel
) {
534 var password
= box
.value
;
535 var prop
= passwordStrength(password
);
542 } else if (prop
>= 35) {
551 $("#passwords_measure")
553 .animate({ width
: prop
+ "%",
554 backgroundColor
: color
557 .animate({ backgroundColor
: bgcolor
}, 750);
558 submitButton
= $(":submit[name='" + passwordprompt_submit
+ "']");
559 if (ok
&& password
.length
>= 6 && differentTypes(password
)) {
560 submitButton
.attr("value", okLabel
);
561 submitButton
.removeAttr("disabled");
563 submitButton
.attr("value", "Mot de passe trop faible");
564 submitButton
.attr("disabled", "disabled");
568 function hashResponse(password1
, password2
, hasConfirmation
) {
569 var pw1
= $('[name=' + password1
+ ']').val();
572 if (hasConfirmation
) {
573 pw2
= $('[name=' + password2
+ ']').val();
575 alert("\nErreur : les deux champs ne sont pas identiques !");
578 $('[name=' + password2
+ ']').val('');
579 } else if (pw1
=== '********') {
583 if (pw1
.length
< 6) {
584 alert("\nErreur : le nouveau mot de passe doit faire au moins 6 caractères !");
587 if (!differentTypes(pw1
)) {
588 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.");
592 alert("Le mot de passe que tu as rentré va être chiffré avant de nous parvenir par Internet ! Ainsi il ne circulera pas en clair.");
593 $('[name=' + password1
+ ']').val('');
594 $('[name=pwhash]').val(hash_encrypt(pw1
));
598 function correctUserName() {
599 var u
= document
.forms
.login
.username
;
602 // login with no space
603 if (!u
.value
.contains(' ')) {
606 mots
= u
.value
.split(' ');
607 // jean paul.du pont -> jean-paul.du-pont
608 if (u
.value
.contains('.')) {
609 u
.value
= mots
.join('-');
612 // jean dupont -> jean.dupont
613 if (mots
.length
=== 2) {
614 u
.value
= mots
[0] + "." + mots
[1];
617 // jean dupont 2001 -> jean.dupont.2001
618 if (mots
.length
=== 3 && mots
[2] > 1920 && mots
[2] < 3000) {
619 u
.value
= mots
.join('.');
622 // jean de la vallee -> jean.de-la-vallee
623 if (mots
[1].toUpperCase() === 'DE') {
624 u
.value
= mots
[0] + "." + mots
.join('-').substr(mots
[0].length
+1);
627 // jean paul dupont -> jean-paul.dupont
628 if (mots
.length
=== 3 && mots
[0].toUpperCase() === 'JEAN') {
629 u
.value
= mots
[0] + "-" + mots
[1] + "." + mots
[2];
633 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 -');
638 function doChallengeResponse() {
639 var new_pass
, old_pass
, str
;
641 if (!correctUserName()) {
645 new_pass
= hash_encrypt(document
.forms
.login
.password
.value
);
646 old_pass
= hash_encrypt(document
.forms
.login
.password
.value
.substr(0, 10));
648 str
= document
.forms
.login
.username
.value
+ ":" +
650 document
.forms
.loginsub
.challenge
.value
;
652 document
.forms
.loginsub
.response
.value
= hash_encrypt(str
);
653 if (new_pass
!== old_pass
) {
654 document
.forms
.loginsub
.xorpass
.value
= hash_xor(new_pass
, old_pass
);
656 document
.forms
.loginsub
.username
.value
= document
.forms
.login
.username
.value
;
657 document
.forms
.loginsub
.remember
.value
= document
.forms
.login
.remember
.checked
;
658 document
.forms
.loginsub
.domain
.value
= document
.forms
.login
.domain
.value
;
659 document
.forms
.login
.password
.value
= "";
660 document
.forms
.loginsub
.submit();
663 function doChallengeResponseLogged() {
664 var str
= document
.forms
.loginsub
.username
.value
+ ":" +
665 hash_encrypt(document
.forms
.login
.password
.value
) + ":" +
666 document
.forms
.loginsub
.challenge
.value
;
668 document
.forms
.loginsub
.response
.value
= hash_encrypt(str
);
669 document
.forms
.loginsub
.remember
.value
= document
.forms
.login
.remember
.checked
;
670 document
.forms
.login
.password
.value
= "";
671 document
.forms
.loginsub
.submit();
675 // {{{ send test email
677 function sendTestEmail(token
, hruid
)
679 var url
= 'emails/test';
680 var msg
= "Un email a été envoyé avec succès";
683 msg
+= " sur l'adresse de " + hruid
+ ".";
685 msg
+= " sur ton addresse.";
687 $('#mail_sent').successMessage($url
+ '?token=' + token
, msg
);
692 // {{{ jQuery object extension
695 /* Add new functions to jQuery namesapce */
697 /* The goal of the following functions is to provide an AJAX API that
698 * take a different callback in case of HTTP success code (2XX) and in
702 xajax
: function(source
, method
, data
, onSuccess
, onError
, type
) {
704 if ($.isFunction(data
)) {
705 type
= type
|| onError
;
710 if (onError
!= null && !$.isFunction(onError
)) {
711 type
= type
|| onError
;
715 function ajaxHandler(data
, textStatus
, xhr
) {
716 if (textStatus
== 'success') {
718 onSuccess(data
, textStatus
, xhr
);
720 } else if (textStatus
== 'error') {
722 onError(data
, textStatus
, xhr
);
724 alert("Une error s'est produite lors du traitement de la requête.\n"
725 + "Ta session a peut-être expiré");
732 success
: ajaxHandler
,
738 xget
: function(source
, data
, onSuccess
, onError
, type
) {
739 return $.xajax(source
, 'GET', data
, onSuccess
, onError
, type
);
742 xgetJSON
: function(source
, data
, onSuccess
, onError
) {
743 return $.xget(source
, data
, onSuccess
, onError
, 'json');
746 xgetScript
: function(source
, onSuccess
, onError
) {
747 return $.xget(source
, null, onSuccess
, onError
, 'script');
750 xgetText
: function(source
, data
, onSuccess
, onError
) {
751 return $.xget(source
, data
, onSuccess
, onError
, 'text');
754 xpost
: function(source
, data
, onSuccess
, onError
, type
) {
755 return $.xajax(source
, 'POST', data
, onSuccess
, onError
, type
);
759 /* Add new functions to jQuery objects */
761 tmpMessage
: function(message
, success
) {
763 this.html("<img src='images/icons/wand.gif' alt='' /> " + message
)
764 .css('color', 'green');
766 this.html("<img src='images/icons/error.gif' alt='' /> " + message
)
767 .css('color', 'red');
769 return this.css('fontWeight', 'bold')
775 updateHtml
: function(source
, callback
) {
777 function handler(data
) {
783 $.xget(source
, handler
, 'text');
787 successMessage
: function(source
, message
) {
789 $.xget(source
, function() {
790 elements
.tmpMessage(message
, true);
795 wiki
: function(text
, withTitle
) {
797 return this.html('');
799 var url
= 'wiki_preview';
804 $.post(url
, { text
: text
},
811 popWin
: function(w
, h
) {
812 return this.click(function() {
813 window
.open(this.href
, '_blank',
814 'toolbar=0,location=0,directories=0,status=0,'
815 +'menubar=0,scrollbars=1,resizable=1,'
816 +'width='+w
+',height='+h
);
826 function previewWiki(idFrom
, idTo
, withTitle
, idShow
)
828 $('#' + idTo
).wiki($('#' + idFrom
).val(), withTitle
);
829 if (idShow
!= null) {
830 $('#' + idShow
).show();
835 // {{{ send test email
837 function sendTestEmail(token
, hruid
)
839 var url
= 'emails/test';
840 var msg
= "Un email a été envoyé avec succès";
843 msg
+= " sur l'adresse de " + hruid
+ ".";
845 msg
+= " sur ton addresse.";
847 $('#mail_sent').successMessage($url
+ '?token=' + token
, msg
);
853 /***************************************************************************
857 /* quick search {{{ */
859 function findPos(obj
) {
860 var curleft
= obj
.offsetLeft
|| 0;
861 var curtop
= obj
.offsetTop
|| 0;
862 while (obj
= obj
.offsetParent
) {
863 curleft
+= obj
.offsetLeft
864 curtop
+= obj
.offsetTop
866 return {x
:curleft
,y
:curtop
};
869 $.template('quickMinifiche',
870 '<div class="contact grayed" style="clear: both">' +
871 '<div class="identity">' +
872 '<div class="photo"><img src="photo/${hrpid}" alt="${directory_name}" /></div>' +
873 '<div class="nom">' +
874 '{{if is_female}}•{{/if}}<a href="profile/${hrpid}">${directory_name}</a>' +
876 '<div class="edu">${promo}</div>' +
878 '<div class="noprint bits"></div>' +
879 '<div class="long"></div>' +
883 function buildPopup(input
, destination
, linkBindFunction
)
885 var pos
= findPos(input
.get(0));
886 var $popup
= destination
;
889 function updateSelection()
891 var sel
= $popup
.children('.contact').addClass('grayed');
892 if (selected
!== null) {
893 while (selected
< 0) {
894 selected
+= sel
.length
;
896 if (selected
>= sel
.length
) {
897 selected
-= sel
.length
;
899 sel
.eq(selected
).removeClass('grayed');
903 function formatProfile(i
, profile
) {
904 var data
= $.tmpl('quickMinifiche', profile
)
909 if (selected
=== i
) {
913 }).mouseup(function() {
914 if (!($(this).find('a').is(':hover'))) {
915 $(this).find('a').click();
922 $popup
= $('<div>').hide()
923 .addClass('contact-list')
925 position
: 'absolute',
927 top
: input
.css('bottom'),
928 left
: pos
.x
- 300 + input
.width(),
936 hide
: function(ignoreIfHover
) {
937 if (ignoreIfHover
&& $popup
.is(':hover')) {
951 selected
: function() {
952 return selected
!== null;
955 unselect
: function() {
960 selectNext
: function() {
961 if (selected
=== null) {
970 selectPrev
: function() {
971 if (selected
=== null) {
980 activeCurrent
: function() {
981 var sel
= $popup
.children('.contact');
982 if (selected
!== null) {
983 sel
.eq(selected
).find('a').click();
989 updateContent
: function(profiles
) {
992 for (var i
= 0, len
= profiles
.length
; i
< len
; i
++) {
993 profile
= formatProfile(i
, profiles
[i
]);
994 profile
.find('a').each(linkBindFunction
);
995 profile
.appendTo($popup
);
1014 quickSearch
: function(options
) {
1016 var $input
= $this.get(0);
1018 var previous
= null;
1019 var pending
= false;
1020 var disabled
= false;
1024 options
= options
|| { };
1025 options
= $.extend({
1035 loadingClassLeft
: 'ac_loading',
1036 loadingClassRight
: 'ac_loading_left',
1037 selectAction
: function() {
1038 $(this).popWin(840, 600);
1041 console
.log(options
);
1042 options
.loadingClass
= $this.css('text-align') === 'right' ? options
.loadingClassRight
1043 : options
.loadingClassLeft
;
1045 $popup
= buildPopup(this, options
.destination
, function() {
1046 options
.selectAction
.apply(this, arguments
);
1047 $(this).click(function() {
1052 function markPending() {
1056 function performUpdate(quick
)
1058 if (updatePopup
=== markPending
) {
1061 updatePopup
= markPending
;
1062 $this.addClass(options
.loadingClass
);
1063 $.xapi('search', $.extend({ 'quick': quick
}, options
.queryParams
), function(data
) {
1064 if (data
.profile_count
> options
.queryParams
.count
|| data
.profile_count
< 0) {
1065 return $popup
.hide();
1067 $popup
.updateContent(data
.profiles
);
1069 }, function(data
, text
) {
1070 if (text
!== 'abort') {
1073 }).complete(function() {
1074 $this.removeClass(options
.loadingClass
);
1075 updatePopup
= doUpdatePopup
;
1083 function doUpdatePopup(dontDelay
)
1085 var quick
= $this.val();
1086 if ($.isFunction(quick
.trim
)) {
1087 quick
= quick
.trim();
1090 if (disabled
|| quick
.length
< options
.minChars
) {
1092 return $popup
.hide();
1093 } else if (!dontDelay
) {
1094 var timeout
= quick
.length
< options
.shortChars
? options
.shortTimeout
: options
.longTimeout
;
1095 setTimeout(function() {
1099 } else if (previous
=== quick
) {
1100 return $popup
.show();
1102 return performUpdate(quick
);
1105 updatePopup
= doUpdatePopup
;
1107 return this.keyup(function(e
) {
1108 if (e
.keyCode
!== 27 /* escape */ && e
.keyCode
!== 13 /* enter */
1109 && e
.keyCode
!== 9 /* tab */ && e
.keyCode
!== 38 /* up */
1110 && e
.keyCode
!== 40 /* down */) {
1111 return updatePopup();
1115 .keydown(function(e
) {
1116 switch (e
.keyCode
) {
1119 $popup
.selectNext();
1123 $popup
.selectPrev();
1126 case 13: /* Return */
1127 return $popup
.activeCurrent();
1129 case 27: /* Escape */
1130 if ($popup
.selected()) {
1140 return $popup
.hide(true);
1142 .focus(updatePopup
);
1147 /***************************************************************************
1148 * Overlib made simple
1153 overlib
: function(text
, width
, height
) {
1157 if (typeof text
=== 'string') {
1169 args
.unshift(text
[key
]);
1172 args
.push(CAPTION
, text
[key
]);
1175 args
.push(CLOSETEXT
, text
[key
]);
1178 args
.push(DELAY
, text
[key
]);
1186 args
.push(WIDTH
, text
[key
]);
1189 args
.push(HEIGHT
, text
[key
]);
1195 .mouseover(function () {
1196 return overlib
.apply(null, args
);
1204 /***************************************************************************
1211 setInterval(getNow
, 1000);
1214 if ($(this).val() === 'Recherche dans l\'annuaire') {
1217 $("#quick_button").show();
1220 $("#quick_button").hide();
1223 $("#quick_button").click(function() {
1224 if ($("#quick").val() === 'Recherche dans l\'annuaire'
1225 || $("#quick").val() === '') {
1232 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: