Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kristen Hazard
committed
Jan 22, 2012
1 parent
7e7060a
commit 8798140
Showing
5 changed files
with
174 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,126 @@ | ||
$(function () { | ||
$book_rows = $('div.book'); | ||
$book_rows.each(function(index) { | ||
console.log($(this).find('img')); | ||
$(this).find('img')[0].src = books_o["books"][index]["cover_url"] | ||
|
||
// onload sort by author and display books | ||
sortAuthor(); | ||
displayBooks(); | ||
|
||
function displayBooks() { | ||
$book_rows = $('div.book'); | ||
$book_rows.each(function(index) { | ||
//console.log($(this).find('img')); | ||
$current_img = $(this).find('img')[0]; | ||
$current_img.src = books_o["books"][index]["cover_url"]; | ||
$current_img.setAttribute('data-index', index); | ||
}); | ||
} | ||
|
||
function sortAuthor() { | ||
books_o.books.sort(function (a, b) { | ||
a = a.author, | ||
b = b.author; | ||
return a.localeCompare(b); | ||
}); | ||
}; | ||
|
||
function sortTitle (a, b) { | ||
books_o.books.sort(function (a, b) { | ||
a = a.title, | ||
b = b.title; | ||
return a.localeCompare(b); | ||
}); | ||
}; | ||
|
||
function sortGenre (a, b) { | ||
books_o.books.sort(function (a, b) { | ||
a = a.genre, | ||
b = b.genre; | ||
return a.localeCompare(b); | ||
}); | ||
}; | ||
|
||
function sortPubDate (a, b) { | ||
books_o.books.sort(function (a, b) { | ||
a = a.published_date, | ||
b = b.published_date; | ||
return a.localeCompare(b); | ||
}); | ||
}; | ||
|
||
function showBook() { | ||
var book = books_o["books"][0]; | ||
$('#book-detail-author').text(book.author); | ||
$('#book-detail-genre').text(book.genre); | ||
$('#book-detail-pubdate').text(book.published_date); | ||
$('#book-detail-title').text(book.title); | ||
$('#book-detail-cover').find('img')[0].src = book.cover_url; | ||
$('#book-detail').fadeIn(); | ||
} | ||
|
||
$('#sort-icon-author').click(function() { | ||
sortAuthor(); | ||
displayBooks(); | ||
}); | ||
|
||
$('#sort-icon-genre').click(function() { | ||
sortGenre(); | ||
displayBooks(); | ||
}); | ||
|
||
$('#sort-icon-title').click(function() { | ||
sortTitle(); | ||
displayBooks(); | ||
}); | ||
|
||
$('#sort-icon-pubdate').click(function() { | ||
sortPubDate(); | ||
displayBooks(); | ||
}); | ||
|
||
$('#show-book').click(function() { | ||
showBook(); | ||
}); | ||
|
||
|
||
|
||
// LISTEN FOR MESSAGES | ||
PUBNUB.subscribe({ | ||
channel : "cosmic_book_shelf", // CONNECT TO THIS CHANNEL. | ||
error : function() { // LOST CONNECTION (auto reconnects) | ||
alert("Connection Lost. Will auto-reconnect when Online.") | ||
}, | ||
callback : function(message) { // RECEIVED A MESSAGE. | ||
console.log(message); | ||
if(message != "Hi from PubNub.") { | ||
//var gestures = message.gestures; | ||
var gesture = message.Gestures[0].Gesture; | ||
switch(gesture) | ||
{ | ||
case "SwipeToRight": | ||
sortTitle(); | ||
displayBooks(); | ||
break; | ||
case "SwipeToLeft": | ||
sortGenre(); | ||
displayBooks(); | ||
break; | ||
case "Circle": | ||
sortPubDate(); | ||
displayBooks(); | ||
break; | ||
} | ||
} | ||
|
||
|
||
}, | ||
connect : function() { // CONNECTION ESTABLISHED. | ||
|
||
// SEND MESSAGE | ||
PUBNUB.publish({ | ||
channel : "cosmic_book_shelf", | ||
message : "Hi from PubNub." | ||
}) | ||
|
||
} | ||
}) | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters