Skip to content

Commit

Permalink
Cleanup JS a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Joakim Bodin committed Jan 15, 2012
1 parent d2d58aa commit 95f6c37
Showing 1 changed file with 70 additions and 70 deletions.
140 changes: 70 additions & 70 deletions spapp/resources/js/kontroll.js
Expand Up @@ -2,6 +2,7 @@ var kontroll = {
apiEndpoint: "http://spkontroll.appspot.com",
sp: null,
models: null,
views: null,

init: function() {
jQuery.support.cors = true;
Expand All @@ -20,7 +21,7 @@ var kontroll = {

// Handle items dropped'on your icon
kontroll.models.application.observe(kontroll.models.EVENT.LINKSCHANGED, kontroll.links.changed);

// Handle items dropped in the app
var drop = document.querySelector('#playlist-dnd');
drop.addEventListener('dragenter', kontroll.playlistDnd.dragEnter, false);
Expand Down Expand Up @@ -77,18 +78,20 @@ var kontroll = {
},

beacon: {
listen: function(channels) {
listen: function(channels)
{
Beacon.connect('018efdb4', channels, {"log":true, "forceClient": "XhrLongPoll"});
Beacon.listen(kontroll.beacon.message);
},
message: function(eventInfo) {

message: function(eventInfo)
{
if (eventInfo.recipient != "spapp")
{
return;
}

console.debug("Beacon message, event: " + eventInfo.event);

switch(eventInfo.event)
{
case "synced":
Expand Down Expand Up @@ -135,15 +138,12 @@ var kontroll = {
show: function(selectedPlaylist)
{
kontroll.storage.selectedPlaylist(selectedPlaylist.uri);

var list = new kontroll.views.List(selectedPlaylist);

jQuery("#playlist-name").replaceWith(selectedPlaylist.name);
jQuery("#playlist-content").append(list.node);

// jQuery("#playlist-content").children('a[href="+ "]')
// sp-track-selected sp-track-playing

jQuery("#playlist").show();
},

Expand All @@ -161,17 +161,53 @@ var kontroll = {
jQuery("#sync-code").replaceWith(syncCode);
jQuery("#sync").show();
},

hide: function()
{
jQuery("#sync").hide();
kontroll.playlistDnd.show();
}
},

deviceId: function()
playlistDnd:
{
return kontroll.models.session.anonymousUserID;
show: function()
{
jQuery("#playlist-dnd").show();
},

hide: function(selectedPlaylist)
{
jQuery("#playlist-dnd").hide();
kontroll.selectedPlaylist.show(selectedPlaylist);
},

dragEnter: function(e)
{
this.style.background = '#444444';
},

dragOver: function(e)
{
e.preventDefault();
e.dataTransfer.dropEffect = 'copy'; // See the section on the DataTransfer object.
return false;
},

dragLeave: function(e)
{
this.style.background = '#333333';
},

drop: function(e)
{
this.style.background = '#333333';
var uri = e.dataTransfer.getData('Text');
kontroll.models.Playlist.fromURI(uri, function(playlist)
{
kontroll.playlistDnd.hide(playlist);
});
}
},

storage:
Expand All @@ -198,7 +234,7 @@ var kontroll = {
});
}
},

isSynced: function(isSynced)
{
if (isSynced != undefined)
Expand All @@ -210,7 +246,7 @@ var kontroll = {
return (localStorage.getItem("synced") === "true");
}
},

selectedPlaylist: function(playlistUri)
{
if (playlistUri != undefined)
Expand All @@ -234,6 +270,22 @@ var kontroll = {
}
}
},

links:
{
changed: function()
{
var links = kontroll.models.application.links;
if(links.length)
{
var playlistUri = links[0];
kontroll.models.Playlist.fromURI(playlistUri, function(playlist)
{
kontroll.playlistDnd.hide(playlist);
});
}
}
},

remote:
{
Expand All @@ -249,7 +301,7 @@ var kontroll = {
},
"json");
},

devicePlaystate: function(playstate, callback)
{
var url = kontroll.apiEndpoint + "/device/playstate";
Expand All @@ -262,64 +314,12 @@ var kontroll = {
"json");
}
},

links:
{
changed: function()
{
var links = kontroll.models.application.links;
if(links.length)
{
var playlistUri = links[0];
kontroll.models.Playlist.fromURI(playlistUri, function(playlist)
{
kontroll.playlistDnd.hide(playlist);
});
}
}
},

playlistDnd:
deviceId: function()
{
show: function()
{
jQuery("#playlist-dnd").show();
},

hide: function(selectedPlaylist)
{

jQuery("#playlist-dnd").hide();
kontroll.selectedPlaylist.show(selectedPlaylist);
},

dragEnter: function(e)
{
this.style.background = '#444444';
},

dragOver: function(e)
{
e.preventDefault();
e.dataTransfer.dropEffect = 'copy'; // See the section on the DataTransfer object.
return false;
},

dragLeave: function(e)
{
this.style.background = '#333333';
},

drop: function(e)
{
this.style.background = '#333333';
var uri = e.dataTransfer.getData('Text');
kontroll.models.Playlist.fromURI(uri, function(playlist)
{
kontroll.playlistDnd.hide(playlist);
});
}
return kontroll.models.session.anonymousUserID;
}

};

$(document).ready(function() {
Expand Down

0 comments on commit 95f6c37

Please sign in to comment.