Skip to content

Instantly share code, notes, and snippets.

@makenosound
Forked from virginia/preview.js
Created February 10, 2012 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makenosound/1786285 to your computer and use it in GitHub Desktop.
Save makenosound/1786285 to your computer and use it in GitHub Desktop.
Google Preview
$(document).ready(function() {
google.load("books", "0");
var viewerHeight;
var headerHeight;
var btn = $('#viewerButton'); // Single ref.
var viewer = $('#viewerContainer');
function viewerInit() {
// var header = $(document.body).down('.header');
headerHeight = 40;
viewerHeight = 700;
var vDiv = $('#viewerCanvas');
vDiv.css({
height: viewerHeight + "px"
});
var gViewer = new google.books.DefaultViewer(
vDiv.get(0), {
'showLinkChrome': false
});
gViewer.load('ISBN:' + window.bookISBN, null, showButton);
}
function showButton() {
btn.on("click", showViewer);
btn.html("» Preview this book");
btn.show('medium');
}
function showViewer() {
// Unbind
btn.off("click", showViewer);
if (!window.noBookSlide) {
viewer.animate({
height: viewerHeight + "px"
}, 400, function() {
console.log("showing!");
});
} else {
viewer.css({
height: viewerHeight + "px"
});
}
viewer.css({
visibility: "visible"
});
btn.html('« Hide the preview');
btn.on("click", hideViewer);
}
function hideViewer() {
btn.off("click", hideViewer);
if (!window.noBookSlide) {
viewer.animate({
height: 0
}, 400);
console.log("hiding!");
} else {
viewer.css({
visibility: "hidden",
height: "0"
});
}
btn.html('» Preview this book!');
btn.on("click", showViewer);
}
google.setOnLoadCallback(viewerInit);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment