|
1 /** |
|
2 * Volume widget presentation code |
|
3 * |
|
4 * Web control interface script for Amarok |
|
5 * Written by Dan Fuhry - 2008 |
|
6 * |
|
7 * This script is in the public domain. Use it for good, not evil. |
|
8 */ |
|
9 |
|
10 var current_volume = 0; |
|
11 |
|
12 function set_volume_fill(amount) |
|
13 { |
|
14 amount = 10 * ( Math.round(amount / 10) ); |
|
15 if ( amount == 0 ) |
|
16 amount = -10; |
|
17 for ( var i = 0; i <= amount; i += 10 ) |
|
18 { |
|
19 if ( !$('volbtn_' + i).hasClass('volume_button_active') ) |
|
20 { |
|
21 $('volbtn_' + i).addClass('volume_button_active'); |
|
22 } |
|
23 } |
|
24 for ( ; i <= 100; i += 10 ) |
|
25 { |
|
26 if ( $('volbtn_' + i).hasClass('volume_button_active') ) |
|
27 { |
|
28 $('volbtn_' + i).rmClass('volume_button_active'); |
|
29 } |
|
30 } |
|
31 } |
|
32 |
|
33 function volume_over(amount) |
|
34 { |
|
35 set_volume_fill(amount); |
|
36 } |
|
37 |
|
38 function volume_out() |
|
39 { |
|
40 set_volume_fill(current_volume); |
|
41 } |
|
42 |
|
43 function set_volume(level) |
|
44 { |
|
45 setAjaxLoading(); |
|
46 if ( level == current_volume ) |
|
47 return false; |
|
48 ajaxGet('/action.json/volume/' + level, function() |
|
49 { |
|
50 if ( ajax.readyState == 4 && ajax.status == 200 ) |
|
51 { |
|
52 unsetAjaxLoading(); |
|
53 var response = (' ' + ajax.responseText).substr(1); |
|
54 // quickie JSON parser :) |
|
55 response = eval('(' + response + ')'); |
|
56 // update volume |
|
57 if ( response.volume != current_volume ) |
|
58 { |
|
59 set_volume_fill(response.volume); |
|
60 current_volume = response.volume; |
|
61 } |
|
62 } |
|
63 }); |
|
64 } |
|
65 |