From 0f4155c33283522fe278b3f47e3405446f2165ff Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sat, 3 Mar 2012 22:56:36 +0100 Subject: Format artist and title in directory item template. --- static/init.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'static') diff --git a/static/init.js b/static/init.js index 26ef404..0dd0af6 100644 --- a/static/init.js +++ b/static/init.js @@ -13,8 +13,27 @@ function pause() { sound.togglePause(); } +Handlebars.registerHelper('trackname', function() { + var item = this; + if(!item.metadata) + return item.name; + + var s = ''; + if(item.metadata.title) + s = item.metadata.title; + if(item.metadata.artist) { + if(s.length) { + s = ' - ' + s; + s = item.metadata.artist + s; + } + } + if(!s.length) + s = item.name; + return s; +}); + var templates = new (function Templates() { - this.directory_item = Handlebars.compile('
  • {{name}}'); + this.directory_item = Handlebars.compile('
  • {{trackname}}'); })(); function load_directory(dir_id, dir_item) { -- cgit v1.2.3