Permalink
Browse files

refactor page resolution to allow arbitrary page numbers

  • Loading branch information...
1 parent 57890f5 commit 8bf5ac3fab676b3f23a144e7e70c9190528a281e @nusco nusco committed Nov 24, 2012
Showing with 26 additions and 16 deletions.
  1. +24 −14 resources/public/javascript/tryclojure.js
  2. +2 −2 src/tryclojure/views/tutorial.clj
@@ -1,5 +1,17 @@
-var pageNum = -1;
-var page = null;
+var currentPage = -1;
+var pageNames = [
+ "page1",
+ "page2",
+ "page3",
+ "page4",
+ "page5",
+ "page6",
+ "page7",
+ "page8",
+ "page9",
+ "page10",
+ "page11"
+ ];
var pages = [
{
verify: function(data) { return false; }
@@ -37,14 +49,12 @@ var pages = [
];
function showPage(n) {
- var res = pages[n];
- if (res) {
- pageNum = n;
- page = res;
+ if (pages[n]) {
+ currentPage = n;
var block = $("#changer");
block.fadeOut(function(e) {
- block.load("/tutorial", { 'n' : n+1 }, function() {
+ block.load("/tutorial", { 'page' : pageNames[n+1] }, function() {
block.fadeIn();
changerUpdated();
});
@@ -92,23 +102,23 @@ function doCommand(input, report) {
report();
return true;
case 'back':
- if (pageNum > 0) {
- showPage(pageNum - 1);
+ if (currentPage > 0) {
+ showPage(currentPage - 1);
report();
return true;
} else {
return false;
}
case 'next':
- if (pageNum >= 0 && pageNum < pages.length - 1) {
- showPage(pageNum + 1);
+ if (currentPage >= 0 && currentPage < pages.length - 1) {
+ showPage(currentPage + 1);
report();
return true;
} else {
return false;
}
case 'restart':
- if (pageNum > 0) {
+ if (currentPage > 0) {
showPage(0);
report();
return true;
@@ -139,8 +149,8 @@ function onHandle(line, report) {
}
// handle page
- if (page && page.verify(data)) {
- showPage(pageNum + 1);
+ if (pages[n] && pages[n].verify(data)) {
+ showPage(currentPage + 1);
}
// display expr results
@@ -1,5 +1,5 @@
(ns tryclojure.views.tutorial
(:require [noir.core :refer [defpage]]))
-(defpage [:post "/tutorial"] {n :n}
- (slurp (str "resources/public/tutorial/page" n ".html")))
+(defpage [:post "/tutorial"] {page :page}
+ (slurp (str "resources/public/tutorial/" page ".html")))

0 comments on commit 8bf5ac3

Please sign in to comment.