]>
git.r.bdr.sh - rbdr/lyricli.rb/blob - doc/js/full_list.js
5 var regexSearchString
= '';
6 var caseSensitiveMatch
= false;
7 var ignoreKeyCodeMin
= 8;
8 var ignoreKeyCodeMax
= 46;
11 RegExp
.escape = function(text
) {
12 return text
.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
15 function fullListSearch() {
18 $('#full_list li').each(function() {
19 var link
= $(this).find('.object_link a');
20 var fullName
= link
.attr('title').split(' ')[0];
21 searchCache
.push({name:link
.text(), fullName:fullName
, node:$(this), link:link
});
24 $('#search input').keyup(function(event
) {
25 if ((event
.keyCode
> ignoreKeyCodeMin
&& event
.keyCode
< ignoreKeyCodeMax
)
26 || event
.keyCode
== commandKey
)
28 searchString
= this.value
;
29 caseSensitiveMatch
= searchString
.match(/[A-Z]/) != null;
30 regexSearchString
= RegExp
.escape(searchString
);
31 if (caseSensitiveMatch
) {
32 regexSearchString
+= "|" +
33 $.map(searchString
.split(''), function(e
) { return RegExp
.escape(e
); }).
36 if (searchString
=== "") {
37 clearTimeout(inSearch
);
39 $('ul .search_uncollapsed').removeClass('search_uncollapsed');
40 $('#full_list, #content').removeClass('insearch');
41 $('#full_list li').removeClass('found').each(function() {
43 var link
= $(this).find('.object_link a');
44 link
.text(link
.text());
47 clicked
.parents('ul').each(function() {
48 $(this).removeClass('collapsed').prev().removeClass('collapsed');
54 if (inSearch
) clearTimeout(inSearch
);
57 $('#full_list, #content').addClass('insearch');
58 $('#noresults').text('');
63 $('#search input').focus();
64 $('#full_list').after("<div id='noresults'></div>");
67 var lastRowClass
= '';
68 function searchItem() {
69 for (var i
= 0; i
< searchCache
.length
/ 50; i
++) {
70 var item
= searchCache
[searchIndex
];
71 var searchName
= (searchString
.indexOf('::') != -1 ? item
.fullName : item
.name
);
72 var matchString
= regexSearchString
;
73 var matchRegexp
= new RegExp(matchString
, caseSensitiveMatch
? "" : "i");
74 if (searchName
.match(matchRegexp
) == null) {
75 item
.node
.removeClass('found');
78 item
.node
.css('padding-left', '10px').addClass('found');
79 item
.node
.parents().addClass('search_uncollapsed');
80 item
.node
.removeClass(lastRowClass
).addClass(lastRowClass
== 'r1' ? 'r2' : 'r1');
81 lastRowClass
= item
.node
.hasClass('r1') ? 'r1' : 'r2';
82 item
.link
.html(item
.name
.replace(matchRegexp
, "<strong>$&</strong>"));
85 if (searchCache
.length
=== searchIndex
+ 1) {
93 inSearch
= setTimeout('searchItem()', 0);
96 function searchDone() {
98 if ($('#full_list li:visible').size() === 0) {
99 $('#noresults').text('No results were found.').hide().fadeIn();
102 $('#noresults').text('');
104 $('#content').removeClass('insearch');
105 clearTimeout(inSearch
);
110 function linkList() {
111 $('#full_list li, #full_list li a:last').click(function(evt
) {
112 if ($(this).hasClass('toggle')) return true;
113 if (this.tagName
.toLowerCase() == "li") {
114 var toggle
= $(this).children('a.toggle');
115 if (toggle
.size() > 0 && evt
.pageX
< toggle
.offset().left
) {
120 if (clicked
) clicked
.removeClass('clicked');
121 var win
= window
.top
.frames
.main
? window
.top
.frames
.main : window
.parent
;
122 if (this.tagName
.toLowerCase() == "a") {
123 clicked
= $(this).parent('li').addClass('clicked');
124 win
.location
= this.href
;
127 clicked
= $(this).addClass('clicked');
128 win
.location
= $(this).find('a:last').attr('href');
134 function collapse() {
135 if (!$('#full_list').hasClass('class')) return;
136 $('#full_list.class a.toggle').click(function() {
137 $(this).parent().toggleClass('collapsed').next().toggleClass('collapsed');
141 $('#full_list.class ul').each(function() {
142 $(this).addClass('collapsed').prev().addClass('collapsed');
144 $('#full_list.class').children().removeClass('collapsed');
148 function highlight(no_padding
) {
150 $('#full_list li:visible').each(function() {
151 var next
= n
== 1 ? 2 : 1;
152 $(this).removeClass("r" + next
).addClass("r" + n
);
153 if (!no_padding
&& $('#full_list').hasClass('class')) {
154 $(this).css('padding-left', (10 + $(this).parents('ul').size() * 15) + 'px');
160 function escapeShortcut() {
161 $(document
).keydown(function(evt
) {
162 if (evt
.which
== 27) {
163 $('#search_frame', window
.top
.document
).slideUp(100);
164 $('#search a', window
.top
.document
).removeClass('active inactive');
165 $(window
.top
).focus();