Skip to content

Instantly share code, notes, and snippets.

@creativepsyco
Created October 10, 2012 20:44
Show Gist options
  • Save creativepsyco/3868297 to your computer and use it in GitHub Desktop.
Save creativepsyco/3868297 to your computer and use it in GitHub Desktop.
Replace tabzine_page by the class of the page element
/**
* [PageControl: does page related magic for tabzine_page class divs]
* @type {Object}
*/
var PageControl = {
currentPage : 1,
totalPages: 1,
/**
* [nextPage Goes to the next Page]
* @param {[type]} page [description]
* @return {[type]} [description]
*/
nextPage: function() {
//XXX: Do page+1
// Load the DOM with new page
var page_id = '#page_' + PageControl.currentPage;
// Calculate the next page
var next = PageControl.currentPage + 1;
if(next > PageControl.totalPages) {
// Do nothing
} else {
$(page_id).hide();
var next_id = '#page_' + next;
$(next_id).show();
PageControl.currentPage++;
}
},
/**
* [prevPage Goes to the prevPage]
* @param {[type]} page [description]
* @return {[type]} [description]
*/
prevPage: function () {
var page_id = '#page_' + PageControl.currentPage;
var prev = PageControl.currentPage - 1;
if(prev < 1) {
// Do nothing
} else {
$(page_id).hide();
var prev_id = '#page_' + prev;
$(prev_id).show();
PageControl.currentPage--;
}
}
};
/**
* Display only the first page when the app is first loaded
* @param {[type]} $ [depends on jquery]
* @return {[type]} [none]
*/
$(document).ready(function($) {
PageControl.currentPage = 1;
// Stuff to do as soon as the DOM is ready. Use $() w/o colliding with other libs;
PageControl.totalPages = $('.tabzine_page').length;
$('.tabzine_page').hide();
var cur_page = '#page_' + PageControl.currentPage;
// Now we just display it
$(cur_page).show();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment