2 Pitchfork Music Player Daemon Client
3 Copyright (C) 2007 Roger Bystrøm
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; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 var quickadd_last_term = "";
21 function quickadd_focus(e) {
22 var qa = document.getElementById('quickadd');
23 var qa_disp = document.getElementById('qa_suggestions');
24 if(e&&e.type&&e.type!="focus");
26 if(qa.value==qa.defaultValue) {
29 qa_disp.style.display = "block";
31 function quickadd_blur(e) {
32 var qa = document.getElementById('quickadd');
33 var qa_disp = document.getElementById('qa_suggestions');
35 if(qa.value.trim().length==0) {
36 qa.value=qa.defaultValue;
40 function quickadd_keydown_handler(e) {
42 var qa = document.getElementById('quickadd');
45 /* return key, send request to add if something to add */
46 if(key==RETURN_KEY_CODE) {
51 var txt_node = document.getElementById('qa_suggestions_txt');
52 var elems = txt_node.getElementsByTagName("span");
53 var i = qa_get_selected_id(elems);
58 send_command("add=" + encodeURIComponent(add), function(response)
59 { if(response=="failed") show_status_bar(LANG.E_FAILED_ADD); },
66 else if(key==27) { // esc :(
72 else if(key>=37&&key<=40) { /* left up right down */
74 quickadd_move_selection(1);
77 else if(key==38) { // up
78 quickadd_move_selection(-1);
81 else if(key==39) { // right
82 var txt_node = document.getElementById('qa_suggestions_txt');
83 var elems = txt_node.getElementsByTagName("span");
84 var sel = qa_get_selected_id(elems);
87 qa.value = elems[sel].name + "/";
88 quickadd_keyup_handler();
93 else if(key==37) { // left
98 function quickadd_clean() {
99 var qa = document.getElementById('quickadd');
105 function qa_get_selected_id(elems) {
106 for(var i=0; i<elems.length; i++) {
107 if(elems[i].hasAttribute("qa_selected")) {
114 function quickadd_move_selection(num) {
115 var txt_node = document.getElementById('qa_suggestions_txt');
116 var elems = txt_node.getElementsByTagName("span");
117 var sel_node = qa_get_selected_id(elems);
120 elems[sel_node].removeAttribute("qa_selected");
125 if(num>=elems.length ||num==-1) {
128 else if(num<0) // flip it around
130 elems[num].setAttribute("qa_selected", "omg");
131 /* safari workaround */
132 elems[num].className = elems[num].className;
135 function quickadd_hide() {
136 var txt_node = document.getElementById('qa_suggestions_txt');
137 var qa_disp = document.getElementById('qa_suggestions');
138 qa_disp.style.display = "none";
139 remove_children(txt_node);
142 function quickadd_keyup_handler(e) {
143 var qa = document.getElementById('quickadd');
144 var search_str = qa.value;
145 search_str = search_str.trim();
150 if(e.altKey||e.metaKey||e.ctrlKey) {
155 if(search_str.length>0) {
156 if(search_str!=quickadd_last_term) {
157 quickadd_last_term = search_str;
158 send_command("quick_search=" + encodeURIComponent(search_str), quickadd_result_handler);
162 var txt_node = document.getElementById('qa_suggestions_txt');
163 remove_children(txt_node);
164 quickadd_last_term = "";
168 function quickadd_result_handler(res) {
169 var txt_node = document.getElementById('qa_suggestions_txt');
170 if(!res||res=="failed") {
171 remove_children(txt_node);
172 txt_node.appendChild(create_txt(LANG.E_NOTHING_FOUND));
175 remove_children(txt_node);
178 var node = create_node("span");
179 node.className = "qa_element";
181 var idx = name.lastIndexOf(DIR_SEPARATOR);
182 node.appendChild(create_txt((idx>0?"..":"") + name.substring(idx)));
183 txt_node.appendChild(node);