/usr/share/beets/beetsplug/web/static/beets.js is in beets 1.3.8+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | // Format times as minutes and seconds.
var timeFormat = function(secs) {
if (secs == undefined || isNaN(secs)) {
return '0:00';
}
secs = Math.round(secs);
var mins = '' + Math.round(secs / 60);
secs = '' + (secs % 60);
if (secs.length < 2) {
secs = '0' + secs;
}
return mins + ':' + secs;
}
// jQuery extension encapsulating event hookups for audio element controls.
$.fn.player = function(debug) {
// Selected element should contain an HTML5 Audio element.
var audio = $('audio', this).get(0);
// Control elements that may be present, identified by class.
var playBtn = $('.play', this);
var pauseBtn = $('.pause', this);
var disabledInd = $('.disabled', this);
var timesEl = $('.times', this);
var curTimeEl = $('.currentTime', this);
var totalTimeEl = $('.totalTime', this);
var sliderPlayedEl = $('.slider .played', this);
var sliderLoadedEl = $('.slider .loaded', this);
// Button events.
playBtn.click(function() {
audio.play();
});
pauseBtn.click(function(ev) {
audio.pause();
});
// Utilities.
var timePercent = function(cur, total) {
if (cur == undefined || isNaN(cur) ||
total == undefined || isNaN(total) || total == 0) {
return 0;
}
var ratio = cur / total;
if (ratio > 1.0) {
ratio = 1.0;
}
return (Math.round(ratio * 10000) / 100) + '%';
}
// Event helpers.
var dbg = function(msg) {
if (debug)
console.log(msg);
}
var showState = function() {
if (audio.duration == undefined || isNaN(audio.duration)) {
playBtn.hide();
pauseBtn.hide();
disabledInd.show();
timesEl.hide();
} else if (audio.paused) {
playBtn.show();
pauseBtn.hide();
disabledInd.hide();
timesEl.show();
} else {
playBtn.hide();
pauseBtn.show();
disabledInd.hide();
timesEl.show();
}
}
var showTimes = function() {
curTimeEl.text(timeFormat(audio.currentTime));
totalTimeEl.text(timeFormat(audio.duration));
sliderPlayedEl.css('width',
timePercent(audio.currentTime, audio.duration));
// last time buffered
var bufferEnd = 0;
for (var i = 0; i < audio.buffered.length; ++i) {
if (audio.buffered.end(i) > bufferEnd)
bufferEnd = audio.buffered.end(i);
}
sliderLoadedEl.css('width',
timePercent(bufferEnd, audio.duration));
}
// Initialize controls.
showState();
showTimes();
// Bind events.
$('audio', this).bind({
playing: function() {
dbg('playing');
showState();
},
pause: function() {
dbg('pause');
showState();
},
ended: function() {
dbg('ended');
showState();
},
progress: function() {
dbg('progress ' + audio.buffered);
},
timeupdate: function() {
dbg('timeupdate ' + audio.currentTime);
showTimes();
},
durationchange: function() {
dbg('durationchange ' + audio.duration);
showState();
showTimes();
},
loadeddata: function() {
dbg('loadeddata');
},
loadedmetadata: function() {
dbg('loadedmetadata');
}
});
}
// Simple selection disable for jQuery.
// Cut-and-paste from:
// http://stackoverflow.com/questions/2700000
$.fn.disableSelection = function() {
$(this).attr('unselectable', 'on')
.css('-moz-user-select', 'none')
.each(function() {
this.onselectstart = function() { return false; };
});
};
$(function() {
// Routes.
var BeetsRouter = Backbone.Router.extend({
routes: {
"item/query/:query": "itemQuery",
},
itemQuery: function(query) {
$.getJSON('/item/query/' + query, function(data) {
var models = _.map(
data['results'],
function(d) { return new Item(d); }
);
var results = new Items(models);
app.showItems(results);
});
}
});
var router = new BeetsRouter();
// Model.
var Item = Backbone.Model.extend({
urlRoot: '/item'
});
var Items = Backbone.Collection.extend({
model: Item
});
// Item views.
var ItemEntryView = Backbone.View.extend({
tagName: "li",
template: _.template($('#item-entry-template').html()),
events: {
'click': 'select',
'dblclick': 'play'
},
initialize: function() {
this.playing = false;
},
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
this.setPlaying(this.playing);
return this;
},
select: function() {
app.selectItem(this);
},
play: function() {
app.playItem(this.model);
},
setPlaying: function(val) {
this.playing = val;
if (val)
this.$('.playing').show();
else
this.$('.playing').hide();
}
});
//Holds Title, Artist, Album etc.
var ItemMainDetailView = Backbone.View.extend({
tagName: "div",
template: _.template($('#item-main-detail-template').html()),
events: {
'click .play': 'play',
},
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
return this;
},
play: function() {
app.playItem(this.model);
}
});
// Holds Track no., Format, MusicBrainz link, Lyrics, Comments etc.
var ItemExtraDetailView = Backbone.View.extend({
tagName: "div",
template: _.template($('#item-extra-detail-template').html()),
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
return this;
}
});
// Main app view.
var AppView = Backbone.View.extend({
el: $('body'),
events: {
'submit #queryForm': 'querySubmit',
},
querySubmit: function(ev) {
ev.preventDefault();
router.navigate('item/query/' + escape($('#query').val()), true);
},
initialize: function() {
this.playingItem = null;
this.shownItems = null;
// Not sure why these events won't bind automatically.
this.$('audio').bind({
'play': _.bind(this.audioPlay, this),
'pause': _.bind(this.audioPause, this),
'ended': _.bind(this.audioEnded, this)
});
},
showItems: function(items) {
this.shownItems = items;
$('#results').empty();
items.each(function(item) {
var view = new ItemEntryView({model: item});
item.entryView = view;
$('#results').append(view.render().el);
});
},
selectItem: function(view) {
// Mark row as selected.
$('#results li').removeClass("selected");
$(view.el).addClass("selected");
// Show main and extra detail.
var mainDetailView = new ItemMainDetailView({model: view.model});
$('#main-detail').empty().append(mainDetailView.render().el);
var extraDetailView = new ItemExtraDetailView({model: view.model});
$('#extra-detail').empty().append(extraDetailView.render().el);
},
playItem: function(item) {
var url = '/item/' + item.get('id') + '/file';
$('#player audio').attr('src', url);
$('#player audio').get(0).play();
if (this.playingItem != null) {
this.playingItem.entryView.setPlaying(false);
}
item.entryView.setPlaying(true);
this.playingItem = item;
},
audioPause: function() {
this.playingItem.entryView.setPlaying(false);
},
audioPlay: function() {
if (this.playingItem != null)
this.playingItem.entryView.setPlaying(true);
},
audioEnded: function() {
this.playingItem.entryView.setPlaying(false);
// Try to play the next track.
var idx = this.shownItems.indexOf(this.playingItem);
if (idx == -1) {
// Not in current list.
return;
}
var nextIdx = idx + 1;
if (nextIdx >= this.shownItems.size()) {
// End of list.
return;
}
this.playItem(this.shownItems.at(nextIdx));
}
});
var app = new AppView();
// App setup.
Backbone.history.start({pushState: false});
// Disable selection on UI elements.
$('#entities ul').disableSelection();
$('#header').disableSelection();
// Audio player setup.
$('#player').player();
});
|