2 function RefreshNowPlaying() {
4 var req = new XMLHttpRequest();
6 req.onreadystatechange = function () {
7 if (this.readyState != 4 || this.status != 200) return;
8 document.getElementById('nowplaying_content').innerHTML=this.responseText;
11 req.open("GET", "ajax/trackinfo.php", true);
16 function RefreshTitle() {
18 var req = new XMLHttpRequest();
20 req.onreadystatechange = function () {
21 if (this.readyState != 4 || this.status != 200) return;
22 document.title='MPD Player: '+this.responseText;
25 req.open("GET", "ajax/trackname.php", true);
29 function RefreshPlayerState() {
31 var req = new XMLHttpRequest();
33 req.onreadystatechange = function () {
34 if (this.readyState != 4 || this.status != 200) return;
35 if (this.responseText=="play") {
36 document.getElementById('playpausebutton').innerHTML="<span onclick=\"Command('pause')\"><img class=\"button\" src=\"images/pause.png\"></span>";
38 document.getElementById('playpausebutton').innerHTML="<span onclick=\"Command('play')\"><img class=\"button\" src=\"images/play.png\"></span>";
42 req.open("GET", "ajax/playerstate.php", true);
47 function RefreshRepeatState() {
49 var req = new XMLHttpRequest();
51 req.onreadystatechange = function () {
52 if (this.readyState != 4 || this.status != 200) return;
53 if (this.responseText=="1") {
54 document.getElementById('repeatstate').innerHTML="<img src=\"images/repeaton.png\"></a>";
56 document.getElementById('repeatstate').innerHTML="<img src=\"images/repeatoff.png\"></a>";
60 req.open("GET", "ajax/repeatstate.php", true);
65 function RefreshVolume() {
67 var req = new XMLHttpRequest();
69 req.onreadystatechange = function () {
70 if (this.readyState != 4 || this.status != 200) return;
71 document.getElementById('volume_total').innerHTML="<div id=\"volume_actual\" style=\"width:"+this.responseText+"%\">";
74 req.open("GET", "ajax/volume.php", true);
79 function RefreshPageStatus() {
89 function RefreshPlaylist() {
91 var req = new XMLHttpRequest();
93 req.onreadystatechange = function () {
94 if (this.readyState != 4 || this.status != 200) return;
95 document.getElementById('playlist').innerHTML=this.responseText;
98 req.open("GET", "ajax/playlist.php", true);
103 function EditPlayList(dir) {
105 var req = new XMLHttpRequest();
107 req.onreadystatechange = function () {
108 if (this.readyState != 4 || this.status != 200) return;
109 document.getElementById('playlist').innerHTML=this.responseText;
112 if (!dir) { dir = ''; };
114 req.open("GET", "ajax/editplaylist.php?dir="+dir, true);
119 function LoadPlayList() {
121 var req = new XMLHttpRequest();
123 req.onreadystatechange = function () {
124 if (this.readyState != 4 || this.status != 200) return;
125 document.getElementById('playlist').innerHTML=this.responseText;
128 req.open("GET", "ajax/playlists.php", true);
133 function RefreshPageContent() {
140 function Command(cmd) {
142 var req = new XMLHttpRequest();
144 req.onreadystatechange = function () {
145 if (this.readyState != 4 || this.status != 200) return;
149 req.open("GET", "ajax/command.php?task="+cmd, true);
154 function PlaylistCommand(cmd,item) {
156 var req = new XMLHttpRequest();
158 req.onreadystatechange = function () {
159 if (this.readyState != 4 || this.status != 200) return;
160 RefreshPageContent();
163 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
168 function PlaylistCommandRefStatus(cmd,item) {
170 var req = new XMLHttpRequest();
172 req.onreadystatechange = function () {
173 if (this.readyState != 4 || this.status != 200) return;
177 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
182 function PlaylistEditCommand(cmd,item) {
184 var req = new XMLHttpRequest();
186 req.onreadystatechange = function () {
187 if (this.readyState != 4 || this.status != 200) return;
191 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
196 function PlaylistEditCommandRefFull(cmd,item) {
198 var req = new XMLHttpRequest();
200 req.onreadystatechange = function () {
201 if (this.readyState != 4 || this.status != 200) return;
202 RefreshPageContent();
205 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
211 function PlaylistItemsCommand(cmd) {
213 var req = new XMLHttpRequest();
215 var selected = [].filter.call(document.getElementsByName('itemlist[]'), function(c) {
221 req.onreadystatechange = function () {
222 if (this.readyState != 4 || this.status != 200) return;
223 RefreshPageContent();
226 params=selected.map(function(el) {
227 //Map each field into a name=value string, make sure to properly escape!
228 return 'itemlist[]=' + encodeURIComponent(el);
231 req.open("POST", "ajax/playlist-command.php?task="+cmd, true);
232 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
237 function PlaylistEditItemsCommand(cmd,dir) {
239 var req = new XMLHttpRequest();
241 var selected = [].filter.call(document.getElementsByName('itemlist[]'), function(c) {
247 params=selected.map(function(el) {
248 //Map each field into a name=value string, make sure to properly escape!
249 return 'itemlist[]=' + encodeURIComponent(el);
252 req.onreadystatechange = function () {
253 if (this.readyState != 4 || this.status != 200) return;
257 req.open("POST", "ajax/playlist-command.php?dir="+dir+"&task="+cmd, true);
258 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
263 setInterval(RefreshPageStatus, 10000);