LJSUP-17669: Login.bml form refactoring
[livejournal.git] / cgi-bin / LJ / JSUtil.pm
blobdac50260e8c67ce7d6d209ae9b659295b37a9ca1
1 package LJ::JSUtil;
2 use strict;
4 #<LJFUNC>
5 # name: LJ::JSUtil::autocomplete
6 # class: web
7 # des: given the name of a form filed and a list of strings, return the
8 # JavaScript needed to turn on autocomplete for the given field.
9 # returns: HTML/JS to insert in an HTML page
10 # </LJFUNC>
11 sub autocomplete {
12 my %opts = @_;
14 my $fieldid = $opts{field};
15 my @list = @{$opts{list}};
17 # create formatted string to use as a javascript list
18 @list = sort { lc $a cmp lc $b } @list;
19 @list = map { $_ = "\"$_\"" } @list;
20 my $formatted_list = join(",", @list);
22 return qq{
23 <script type="text/javascript">
24 function AutoCompleteFriends(ele) \{
25 var keywords = new InputCompleteData([$formatted_list], "ignorecase");
26 new InputComplete(ele, keywords);
28 if ('$fieldid' && \$('$fieldid')) AutoCompleteFriends(\$('$fieldid'));
29 </script>