Skip to content
Snippets Groups Projects
Commit 2fe4cf5a authored by ale's avatar ale
Browse files

autogenerate minified and precompressed bundles for javascript and css

parent 2e908fee
Branches
No related tags found
No related merge requests found
CSS_SINGLE_FILE = css/bundle.css
CSS_SOURCES = \
css/style.css \
css/jquery.autocomplete.css
JS_SINGLE_FILE = js/bundle.js
JS_SOURCES = \
js/jquery-1.6.4.min.js \
js/jquery.autocomplete.min.js \
js/jquery.fullbg.min.js \
js/jquery.grab.min.js \
js/jquery.transform.min.js \
js/mod.csstransforms.min.js \
js/jquery.jplayer.min.js \
js/circle.player.min.js \
js/djr.min.js
BUNDLES = $(CSS_SINGLE_FILE) \
$(JS_SINGLE_FILE)
COMPRESSED_BUNDLES = $(BUNDLES:%=%.gz)
%.gz: %
gzip -9cv $^ > $@
all: subdirs bundles compress
subdirs:
$(MAKE) -C js/djr
$(MAKE) -C js
bundles: $(BUNDLES)
compress: $(COMPRESSED_BUNDLES)
js/bundle.js: $(JS_SOURCES)
(for file in $^ ; \
do cat $$file ; echo ; done) > $@
css/bundle.css: $(CSS_SOURCES)
(for file in $^ ; \
do cat $$file ; echo ; done) > $@
.PHONY: bundles compress subdirs
JSCOMPILER_JAR = /usr/lib/jscompiler/compiler.jar
JSCOMPILER = java -jar $(JSCOMPILER_JAR)
SOURCES = \
circle.player.js \
jquery.grab.js \
jquery.transform.js
TARGETS = $(SOURCES:%.js=%.min.js)
%.min.js: %.js
$(JSCOMPILER) $(^:%=--js=%) --js_output_file=$@
all: $(TARGETS)
djr={loading:function(a){var b=$("#loaderImg");a?b.show():b.hide()}};var CHARS="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");djr.generateRandomId=function(){var a=[],b=CHARS,c,d=b.length;for(c=0;c<40;c++)a[c]=b[0|Math.random()*d];return a.join("")};djr.Backend=function(){};var wrap_with_loader=function(a){djr.loading(!0);var b=a.success;a.success=function(a,d,e){b(a,d,e);djr.loading(!1)};a.error=function(){djr.loading(!1)};return $.ajax(a)};djr.Backend.prototype.search=function(a,b,c){wrap_with_loader({url:"/json/search",data:{q:a},dataType:"json",type:"GET",context:c||this,success:function(a){b(a.results);djr.loading(!1)}})};
djr.Backend.prototype.moreLikeThese=function(a,b,c){wrap_with_loader({url:"/json/morelikethese",data:{h:a.join(",")},dataType:"json",type:"POST",context:c||this,success:function(a){b(a.results)}})};djr.Backend.prototype.getPlList=function(a,b,c){$.ajax({url:"/json/playlist/list/"+a,dataType:"json",type:"GET",context:c||this,success:function(a){b(a.results)}})};djr.Backend.prototype.getPlaylist=function(a,b,c){$.ajax({url:"/json/playlist/get/"+a,dataType:"json",type:"GET",context:c||this,success:function(a){b(a.results)}})};
djr.Backend.prototype.savePlaylist=function(a,b,c){$.ajax({url:"/json/playlist/save",data:{uuid:a,title:b,h:c.join(",")},type:"POST"})};djr.Backend.prototype.streamPlaylist=function(a,b,c,d){$.ajax({url:"/json/playlist/stream",data:{uuid:a,stream:b?"y":"n"},dataType:"json",type:"POST",context:d||this,success:function(a){c(a)}})};djr.Backend.prototype.getHtmlForSongs=function(a,b,c){wrap_with_loader({url:"/fragment/songs",data:{h:a.join(",")},dataType:"html",type:"POST",context:c||this,success:b})};
djr.Backend.prototype.nowPlaying=function(a,b){$.ajax({url:"/json/playing",data:{cur:a,prev:b.join(",")},type:"POST"})};djr.Backend.prototype.neverPlayedPlaylist=function(a,b,c){wrap_with_loader({url:"/json/never_played",data:{n:a},dataType:"json",type:"GET",context:c||this,success:function(a){b(a.results)}})};djr.Backend.prototype.mostPlayedPlaylist=function(a,b,c){wrap_with_loader({url:"/json/most_played",data:{n:a},dataType:"json",type:"GET",context:c||this,success:function(a){b(a.results)}})};
djr.Backend.prototype.lastPlaylist=function(a,b,c){wrap_with_loader({url:"/json/last_uploaded",data:{n:a},dataType:"json",type:"GET",context:c||this,success:function(a){b(a.results)}})};djr.Backend.prototype.markovPlaylist=function(a,b,c,d){wrap_with_loader({url:"/json/markov",data:{h:b.join(","),n:a},dataType:"json",type:"POST",context:d||this,success:function(a){c(a.results)}})};
djr.Backend.prototype.randomPlaylist=function(a,b,c){wrap_with_loader({url:"/json/random",data:{n:a},dataType:"json",type:"GET",context:c||this,success:function(a){b(a.results)}})};djr.PlaylistChunk=function(a,b){this.songs=a||[];this.title=b};djr.PlaylistChunk.prototype.hasSong=function(a){return this.songs.indexOf(a)>=0};djr.PlaylistChunk.prototype.removeSong=function(a){this.songs=$.grep(this.songs,function(b){return b!=a})};djr.controlButtons=function(a){return'<div class="ctlbox" style="display:none"><a id="'+a+'_remove" class="ctl_btn ctl_remove">&nbsp;</a></div>'};
djr.PlaylistChunk.prototype.wrapHtml=function(a,b){return'<div id="chunk_'+a+'" class="chunk"><div class="chunk_ctl_wrap">'+djr.controlButtons("chunk_ctl_"+a)+'<a class="chunk_title">'+this.title+'</a></div><div class="chunk_inner">'+(b||"")+"</div></div>"};djr.Playlist=function(a){this.uuid=a||djr.generateRandomId();this.chunks=[];this.song_map={};this.chunk_map={};this.title="";this.next_chunk_id=0};
djr.Playlist.prototype.allSongs=function(){var a=[],b,c;for(b=0;b<this.chunks.length;b++)for(c=0;c<this.chunk_map[this.chunks[b]].songs.length;c++)a.push(this.chunk_map[this.chunks[b]].songs[c]);return a};djr.Playlist.prototype.createUniqueChunk=function(a,b){var c=[],d;for(d=0;d<a.length;d++)this.song_map[a[d]]==null&&c.push(a[d]);return c.length>0?new djr.PlaylistChunk(c,b):null};
djr.Playlist.prototype.addChunk=function(a){djr.debug("adding chunk to playlist "+this.uuid);var b,c=this.next_chunk_id++;for(b=0;b<a.songs.length;b++)this.song_map[a.songs[b]]=c;this.chunk_map[c]=a;this.chunks.push(c);return c};djr.Playlist.prototype.getChunkSongs=function(a){return this.chunk_map[a].songs};
djr.Playlist.prototype.removeChunk=function(a){djr.debug("removing chunk "+a);var b=this.chunk_map[a].songs,c;for(c=0;c<b.length;c++)delete this.song_map[b[c]];delete this.chunk_map[a];this.chunks=$.grep(this.chunks,function(b){return b!=a})};djr.Playlist.prototype.removeSong=function(a){djr.debug("removing song "+a);var b=this.song_map[a];this.chunk_map[b].removeSong(a);delete this.song_map[a];return this.chunk_map[b].songs.length==0?(this.removeChunk(b),b):-1};
djr.Playlist.prototype.merge=function(){var a=[],b;for(b=0;b<this.chunks.length;b++)a.push(this.chunk_map[this.chunks[b]].title);a=a.join(" + ");b=new djr.Playlist;b.uuid=this.uuid;b.addChunk(new djr.PlaylistChunk(this.allSongs(),a));return b};djr.Playlist.prototype.getNextSong=function(a){var b=this.song_map[a],c=this.chunk_map[b].songs,b=this.chunks.indexOf(b),a=c.indexOf(a)+1;a>=c.length&&(a=0,b++,b>=this.chunks.length&&(b=0));return this.chunk_map[this.chunks[b]].songs[a]};
djr.Playlist.prototype.isLastSong=function(a){var b=this.song_map[a],c=this.chunk_map[b].songs,b=this.chunks.indexOf(b),a=c.indexOf(a),c=c.length-1;return b==this.chunks.length-1&&a==c?!0:!1};djr.Player=function(a,b){this.backend=a;this.playlist=new djr.Playlist;this.old_songs=[];this.cur_song=null;this.auto_extend=!0;this.circleplayer=new CirclePlayer(b,{},{supplied:"mp3",swfPath:"/static/js",cssSelectorAncestor:"#cp_container",error:function(a){djr.state.player.reportError(a)}});this.player=this.circleplayer.player;this.player.bind($.jPlayer.event.ended+".djr",function(){djr.state.player.nextSong()})};djr.Player.prototype.hideAllChunks=function(){$(".chunk .chunk_inner").hide()};
djr.Player.prototype.removeChunk=function(a){this.playlist.removeChunk(a);this.savePlaylist();$("#chunk_"+a).remove()};djr.Player.prototype.removeSong=function(a){$("#song_"+a).remove();a=this.playlist.removeSong(a);this.savePlaylist();a>0&&$("#chunk_"+a).remove()};djr.Player.prototype.savePlaylist=function(){this.backend.savePlaylist(this.playlist.uuid,"",this.playlist.allSongs())};djr.Player.prototype.saveNewPlaylist=function(a){this.backend.savePlaylist(djr.generateRandomId(),a,this.playlist.allSongs())};
djr.Player.prototype.clearPlaylist=function(){this.playlist=new djr.Playlist;$("#playlistDiv").empty()};djr.Player.prototype.mergePlaylistChunks=function(){this.playlist=this.playlist.merge();var a=[];$(".chunk .chunk_inner").each(function(){a.push($(this).html())});$("#playlistDiv").empty();var b=this.playlist.chunks[0];this.setChunkHtml(this.playlist.chunk_map[b],b,a.join(""))};
djr.Player.prototype.search=function(a){var b=this;this.backend.search(a,function(c){var d=[];$.each(c,function(a,b){d.push(b.sha1)});d.length==0?djr.debug("No results found."):b.createChunk(d,a)})};djr.Player.prototype.lastPlaylist=function(a){var b=this,c="Last "+a+" Songs Uploaded";this.backend.lastPlaylist(a,function(a){a.length==0?djr.debug("No results found."):b.createChunk(a,c)})};
djr.Player.prototype.randomPlaylist=function(a){var b=this,c=""+a+" Random Songs ";this.backend.randomPlaylist(a,function(a){a.length==0?djr.debug("No results found."):b.createChunk(a,c)})};djr.Player.prototype.neverPlayedPlaylist=function(a){var b=this,c=""+a+" Never Played Songs";this.backend.neverPlayedPlaylist(a,function(a){a.length==0?djr.debug("No results found."):b.createChunk(a,c)})};
djr.Player.prototype.mostPlayedPlaylist=function(a){var b=this,c=""+a+" Most Played Songs";this.backend.mostPlayedPlaylist(a,function(a){var e=[];$.each(a,function(a,b){e.push(b.sha1)});e.length==0?djr.debug("No results found."):b.createChunk(e,c)})};djr.Player.prototype.extendCurrentPlaylist=function(){var a=this;this.backend.moreLikeThese(this.playlist.allSongs(),function(b){a.createChunk(b,"suggestions")})};
djr.Player.prototype.autoExtendCurrentPlaylist=function(a){var b=this;this.backend.markovPlaylist(10,this.playlist.allSongs(),function(c){b.createChunk(c,"more...");a()})};djr.Player.prototype.createChunk=function(a,b){var c=this.playlist.createUniqueChunk(a,b);if(c){this.playlist.chunks.length>1&&this.mergePlaylistChunks();var d=this.playlist.addChunk(c);this.savePlaylist();var e=this;this.backend.getHtmlForSongs(a,function(a){e.hideAllChunks();e.setChunkHtml(c,d,a)})}else djr.debug("All the results are already in the playlist")};
djr.Player.prototype.setChunkHtml=function(a,b,c){a=a.wrapHtml(b,c);$("#playlistDiv").append(a);var d=this,e=$("#chunk_"+b);e.find(".song_a").click(function(){d.play($(this).attr("id").substr(5))});e.find(".album_a").click(function(){d.search('(album:"'+$(this).text()+'")')});e.find(".chunk_title").click(function(){e.find(".chunk_inner").toggle()});e.hover(function(){$(this).find(".chunk_ctl_wrap .ctlbox").show()},function(){$(this).find(".chunk_ctl_wrap .ctlbox").hide()});e.find(".chunk_ctl_wrap .ctlbox .ctl_remove").click(function(){djr.debug("removing chunk "+
b);d.removeChunk(b)});e.find(".chunk_inner .song").hover(function(){$(this).find(".ctlbox").show()},function(){$(this).find(".ctlbox").hide()});e.find(".chunk_inner .ctlbox .ctl_remove").click(function(){var a=$(this).parent().parent().attr("id").substr(5);d.removeSong(a)})};
djr.Player.prototype.play=function(a){djr.debug("play "+a);this.cur_song&&(this.old_songs.push(this.cur_song),this.old_songs.length>5&&this.old_songs.shift());this.cur_song=a;$(".song").removeClass("playing");$("#song_"+a).addClass("playing");this.player.jPlayer("setMedia",{mp3:"/dl/"+a}).jPlayer("play");var b=$("#song_"+a+" .artist").text(),c=$("#song_"+a+" .album").text();$("#songInfoDiv").html($("#song_"+a+" .title").text()+"<br>"+b+"<br><small>"+c+"</small>");b="/album_image/"+escape(b)+"/"+escape(c);
$("#albumart_fs").attr("src",b);$("#albumart_fs").fullBg();$("#albumart_fs").show();this.backend.nowPlaying(a,this.old_songs)};djr.Player.prototype.nextSong=function(){if(this.auto_extend&&this.playlist.isLastSong(this.cur_song)){var a=this;this.autoExtendCurrentPlaylist(function(){a.nextSong()})}else this.play(this.playlist.getNextSong(this.cur_song))};djr.Player.prototype.streamCurrentPlaylist=function(){};djr.state={backend:null,player:null};
djr.init=function(){djr.state.backend=new djr.Backend;djr.state.player=new djr.Player(djr.state.backend,"#djr_player");$("#playlistClearBtn").click(function(){djr.state.player.clearPlaylist()});$("#playlistStreamBtn").click(function(){djr.state.player.streamCurrentPlaylist()});$("#playlistExtendBtn").click(function(){djr.state.player.extendCurrentPlaylist()});$("#playlistLast5").click(function(){djr.state.player.lastPlaylist(5)});$("#playlistLast25").click(function(){djr.state.player.lastPlaylist(25)});
$("#playlistRandom5").click(function(){djr.state.player.randomPlaylist(5)});$("#playlistRandom25").click(function(){djr.state.player.randomPlaylist(25)});$("#playlistMost5").click(function(){djr.state.player.mostPlayedPlaylist(5)});$("#playlistMost25").click(function(){djr.state.player.mostPlayedPlaylist(25)});$("#playlistNever5").click(function(){djr.state.player.neverPlayedPlaylist(5)});$("#playlistNever25").click(function(){djr.state.player.neverPlayedPlaylist(25)});$("#playlistSave").click(function(){$("#saveForm").is(":visible")==
!1?($("#savetext").val(djr.playlist.title),$("#saveForm").show("slow")):($("#savetext").val(""),$("#saveForm").hide("slow"))});$("#playlistSaveBtn").click(function(){$("#savetext").val()!=""&&djr.player.saveNewPlaylist($("#savetext").val())});$("#wikibtn").click(function(){var a=$("#song_"+djr.state.player.cur_song+" .artist").text();$("#wikipedia").is(":visible")==!1?a!=""&&(a=a.split(" ").join("+"),$("#wikipedia").show("slow"),$("#wikipedia").attr("src","http://en.m.wikipedia.org/w/index.php?search="+
a)):$("#wikipedia").hide("slow")});$("#lastfmbtn").click(function(){var a=$("#song_"+djr.state.player.cur_song+" .title").text(),b=$("#song_"+djr.state.player.cur_song+" .artist").text();$("#lastfm").is(":visible")==!1?a!=""&&(a=a.split(" ").join("+"),b=b.split(" ").join("+"),$("#lastfm").show("slow"),$("#lastfm").attr("src","http://m.last.fm/search?q="+a+b)):$("#lastfm").hide("slow")});$("#lyricsbtn").click(function(){var a=$("#song_"+djr.state.player.cur_song+" .title").text();$("#lyrics").is(":visible")==
!1?a!=""&&(a=a.split(" ").join("+"),$("#lyrics").show("slow"),$("#lyrics").attr("src","http://lyrics.wikia.com/index.php?search="+a+"&fulltext=0")):$("#lyrics").hide("slow")});$("#pllistbtn").click(function(){$("#pllist").is(":visible")==!1?($("#pllist").show("slow"),this.backend.getPlList(uid,function(a){if(a.length==0)djr.debug("No results found.");else{for(var b="<ul>",c;c<a.lenght;c++)b+="<il><a id='"+a[c].uuid+"' onclick='djm.player.showPlaylist(\""+a[c].uuid+"\"' >"+a[c].title+"</a></il>";b+=
"</ul>";$("#pllist").html(b)}})):$("#pllist").hide("slow")});$("#albumart_fs").load(function(){$(this).fullBg();$(this).show()})};djr.player=function(){return djr.state.player};djr.debug=function(a){$("#debug").append(a+"<br>")};djr.Player.prototype.reportError=function(a){console.log(a.jPlayer.error);console.log(a.jPlayer.error.type);switch(a.jPlayer.error.type){case $.jPlayer.error.URL:djr.debug("Error downloading song, skipping...");this.nextSong();break;case $.jPlayer.error.NO_SOLUTION:djr.debug("Error: unexpected error!")}};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment