Last active
December 12, 2015 22:29
-
-
Save tylersmalley/4833177 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /*! | |
| * Wizard: Easy paging through DOM objects | |
| * | |
| * @constructor | |
| * @param {String} jQuery selector for page | |
| */ | |
| var Wizard = (function(selector){ | |
| /** | |
| * Public Methods | |
| */ | |
| this.goto = goto; | |
| this.previous = previous; | |
| this.next = next; | |
| this.current = function(){ return currentPage; }; | |
| this.count = function(){ return pages.length; }; | |
| /** | |
| * Private Variables/Methods | |
| */ | |
| var pages = [] | |
| , currentPage = 0; | |
| /** | |
| * Initializer | |
| * | |
| * @see {Page()} | |
| */ | |
| function initialize(){ | |
| pages = $(selector); | |
| next(); | |
| $('.js-next-page').on('click', next); | |
| $('.js-previous-page').on('click', previous); | |
| } | |
| /** | |
| * Navigates to the previous page if possible | |
| * | |
| * @returns {Boolean} | |
| */ | |
| function previous(){ | |
| return goto(currentPage - 1); | |
| } | |
| /** | |
| * Navigates to the next page if possible | |
| * | |
| * @returns {Boolean} | |
| */ | |
| function next(){ | |
| return goto(currentPage + 1); | |
| } | |
| /** | |
| * Navigates to a specified page | |
| * | |
| * @returns {Boolean} | |
| */ | |
| function goto(page){ | |
| var selector = pages[page - 1]; | |
| if (selector) { | |
| pages.hide(); | |
| $(selector).show(); | |
| currentPage = page; | |
| return true; | |
| } | |
| return false; | |
| } | |
| initialize.apply(this, arguments); | |
| }); | |
| $(function(){ | |
| new Wizard('.page'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment