Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@leegee
Last active October 3, 2017 10:41
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 leegee/be4de694f62129ab716cac0936ec8036 to your computer and use it in GitHub Desktop.
Save leegee/be4de694f62129ab716cac0936ec8036 to your computer and use it in GitHub Desktop.
Tiny Wizard
var Wizard = function (access_token) {
this.access_token = access_token;
this.page = 0;
this.el = {
main: document.getElementById('main'),
pageNumber: document.getElementById('pageNumber')
};
this.el.pageNumber.setAttribute('style', 'display:block"');
}
Wizard.prototype.gotoPageName = function (pageName) {
console.log('Wizard ', this, 'Page ', this.page, 'to', pageName);
// find element with attribute data-name === pageName
this.nextPage(
document.querySelector('script[type="text/mustache"][data-name="merge"]').id.match(/^page-(\d+)$/)[1]
);
}
Wizard.prototype.nextPage = function (pageNumber) {
console.log('Wizard ', this, 'Page ', this.page, 'to', this.page + 1);
if (pageNumber) {
this.page = pageNumber;
} else {
this.page ++;
}
try {
this.el.main.innerHTML = Mustache.render(
document.getElementById('page-' + this.page).innerHTML.toString(),
{Config: Config, wizard: wizard}
);
this.el.pageNumber.innerText = this.page;
} catch (e) {
console.error(e);
}
var fn = 'page' + this.page;
if (typeof window[fn] === 'function') {
window[fn]( arguments );
}
console.log('Page = ', this.page);
}
/*
<script type='text/mustache' id='page-1'>
<h3>....</h3>
</script>
<script>
var page1 = function () {
// ...
}
</script>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment