1
0
mirror of https://github.com/balkian/go5ears.git synced 2024-11-22 13:22:28 +00:00

Refactored code. Cleaner

This commit is contained in:
J.Fernando Sánchez 2012-10-07 14:35:56 +02:00
parent 7c494a42f0
commit a8d1bd9a7e
3 changed files with 147 additions and 148 deletions

View File

@ -1 +1,21 @@
html,body {
height: 100%;
}
* {
margin:0;
}
.sortable { position:relative; list-style-type: none; margin: 0; padding: 0; width: 100%; }
.sortable li { margin: 0px 3px 3px 3px; padding: 0.4em; font-size: 1em; height: 18px; }
.list-name { padding-left:3em; }
.list-controls span {float:left;display:inline;}
#wrapper {
position:relative;
height: auto !important;
min-height: 90%;
margin: 0 auto 0;
}
#headerPage {
position:relative;
min-height:10%;
}

93
js/app.js Normal file
View File

@ -0,0 +1,93 @@
var audio;
var playlist;
var tracks;
var current;
function pauseSelected(id,emitter){
var newUrl = 'play?id='+id;
console.log("Already playing:"+audio.src);
audio.pause();
$(emitter).addClass('ui-icon ui-icon-play').removeClass('ui-icon-pause');
$(emitter).unbind('click');
$(emitter).click(function(){
playSelected(id,emitter);
});
}
function resumeSelected(id,emitter){
console.log("Resuming:"+audio.src);
audio.play();
$(emitter).addClass('ui-icon ui-icon-pause').removeClass('ui-icon-stop ui-icon-play');
$(emitter).unbind('click');
$(emitter).click(function(){
pauseSelected(id,emitter);
});
}
function playSelected(id,emitter){
if(audio.src.indexOf(id)!=-1){
resumeSelected(id,emitter);
}
else{
console.log("Not playing:"+audio.src);
audio.src = 'play?id='+id;
audio.load();
$(emitter).removeAttr('onClick');
$(".list-controls > span").removeClass('ui-icon-stop ui-icon-pause').addClass('ui-icon-play');
resumeSelected(id,emitter);
}
}
function search(term){
$.ajax({url:'/search?id='+term,
dataType: 'json',
success: function(data){
for(var i=0; i<data.length;i++){
var title = data[i]["title"];
var group = data[i]["group"];
var id = data[i]["id"];
var newLi = toHtml(id,group,title);
$('#searchresults').append(newLi);
}
}
});
};
function addSelected(id,group,title){
$('#playlist').append(toHtml(id,group,title));
}
function toHtml(id,group,title){
return '<li class="ui-state-default">'+
' <div class="list-controls">'+
' <span class="ui-icon ui-icon-play" onClick=\'playSelected("'+id+'",this)\'></span>'+
' <span class="ui-icon ui-icon-circle-plus" onClick=\'addSelected("'+id+'","'+group+'","'+title+'")\'></span>'+
' <a href="play?id='+id+'"><span class="ui-icon ui-icon-arrowthickstop-1-s"></span></a>'+
' </div>'+
' <div class="list-name">'+group+' - '+title+'</div>'+
'</li>';
}
$(function() {
$( ".sortable" ).sortable();
$( ".sortable" ).disableSelection();
$( "#accordion" ).accordion({fillSpace:true});
});
$('.accordion .head').click(function() {
$(this).next().toggle();
return false;
}).next().hide();
$(document).ready(function(){
audio = $('audio')[0];
playlist = $('#playlist');
tracks = [];
var champions = { id:"4b9ed95",
title:"We are the champions",
group:"Queen"};
var libertine = { id:"fe7e4f9",
title:"Libertine",
group:"Kate Ryan"};
addSelected(libertine["id"],libertine["title"],libertine["group"]);
addSelected(champions["id"],champions["title"],champions["group"]);
});

View File

@ -3,125 +3,11 @@
<head> <head>
<link rel='stylesheet' media='screen' href="css/main.css" /> <link rel='stylesheet' media='screen' href="css/main.css" />
<link type="text/css" href="css/ui-darkness/jquery-ui-1.8.24.custom.css" rel="stylesheet"> <link type="text/css" href="css/ui-darkness/jquery-ui-1.8.24.custom.css" rel="stylesheet">
<style>
html,body { height: 100%;}
* {
margin:0;
}
.sortable { position:relative; list-style-type: none; margin: 0; padding: 0; width: 100%; }
.sortable li { margin: 0px 3px 3px 3px; padding: 0.4em; font-size: 1em; height: 18px; }
.list-name { padding-left:3em; }
.list-controls span {float:left;display:inline;}
#wrapper {
position:relative;
height: auto !important;
min-height: 90%;
margin: 0 auto 0;
}
#headerPage {
position:relative;
min-height:10%;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.24.custom.min.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.24.custom.min.js"></script>
<script> <script type='text/javascript' src='js/knockout-2.1.0.js'></script>
var audio; <script type='text/javascript' src='js/app.js'></script>
var playlist;
var tracks;
var current;
function pauseSelected(id,emitter){
var newUrl = 'play?id='+id;
console.log("Already playing:"+audio.src);
audio.pause();
$(emitter).addClass('ui-icon ui-icon-play').removeClass('ui-icon-pause');
$(emitter).unbind('click');
$(emitter).click(function(){
playSelected(id,emitter);
});
}
function resumeSelected(id,emitter){
console.log("Resuming:"+audio.src);
audio.play();
$(emitter).addClass('ui-icon ui-icon-pause').removeClass('ui-icon-stop ui-icon-play');
$(emitter).unbind('click');
$(emitter).click(function(){
pauseSelected(id,emitter);
});
}
function playSelected(id,emitter){
if(audio.src.indexOf(id)!=-1){
resumeSelected(id,emitter);
}
else{
console.log("Not playing:"+audio.src);
audio.src = 'play?id='+id;
audio.load();
$(emitter).removeAttr('onClick');
$(".list-controls > span").removeClass('ui-icon-stop ui-icon-pause').addClass('ui-icon-play');
resumeSelected(id,emitter);
}
}
function search(term){
$.ajax({url:'/search?id='+term,
dataType: 'json',
success: function(data){
for(var i=0; i<data.length;i++){
var title = data[i]["title"];
var group = data[i]["group"];
var id = data[i]["id"];
var newLi = toHtml(id,group,title);
$('#searchresults').append(newLi);
}
}
});
};
function addSelected(id,group,title){
$('#playlist').append(toHtml(id,group,title));
}
function toHtml(id,group,title){
return '<li class="ui-state-default">'+
' <div class="list-controls">'+
' <span class="ui-icon ui-icon-play" onClick=\'playSelected("'+id+'",this)\'></span>'+
' <span class="ui-icon ui-icon-circle-plus" onClick=\'addSelected("'+id+'","'+group+'","'+title+'")\'></span>'+
' <a href="play?id='+id+'"><span class="ui-icon ui-icon-arrowthickstop-1-s"></span></a>'+
' </div>'+
' <div class="list-name">'+group+' - '+title+'</div>'+
'</li>';
}
$(function() {
$( ".sortable" ).sortable();
$( ".sortable" ).disableSelection();
$( "#accordion" ).accordion({fillSpace:true});
});
$('.accordion .head').click(function() {
$(this).next().toggle();
return false;
}).next().hide();
$(document).ready(function(){
audio = $('audio')[0];
playlist = $('#playlist');
tracks = [];
var champions = { id:"4b9ed95",
title:"We are the champions",
group:"Queen"};
var libertine = { id:"fe7e4f9",
title:"Libertine",
group:"Kate Ryan"};
addSelected(libertine["id"],libertine["title"],libertine["group"]);
addSelected(champions["id"],champions["title"],champions["group"]);
});
</script>
</head> </head>
<body> <body>
<div id="headerPage"> <div id="headerPage">