Skip to content

Display the console + instructions side by side. Added page counter #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions resources/public/css/tryclojure.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
.clearfix { display: inline-block; }
/* start commented backslash hack \*/
* html .clearfix { height: 1%; }
.clearfix { display: block; }
/* close commented backslash hack */

body {
background: #fff;
text-align: center;
}

#wrapper {
text-align: left;
width: 820px;
width: 1024px;
margin: 0 auto;
border-radius: 5px;
border: 5px solid #eee;
Expand Down Expand Up @@ -40,16 +54,18 @@ body {
}

#console {
width:500px;
height: 220px;
background: #eee;
margin: 10px;
border-radius: 5px;
-moz-border-radius: 5px;
border: 1px solid #aaa;
float:left;
}

#console div.jquery-console-inner {
width:780px;
width:98%;
height:200px;
margin: 10px 10px;
overflow:auto;
Expand Down Expand Up @@ -114,12 +130,15 @@ table.bottom {
}

#changer {
display:inline-block;
float:left;
margin: 10px;
padding: 0.25em 0.5em 0.25em 0.5em;
background: #EAF2F5;
border-radius: 5px;
-moz-border-radius: 5px;
border: 1px solid #BEDCE7;
width:450px;
}

#changer h3 {
Expand Down
227 changes: 116 additions & 111 deletions resources/public/javascript/tryclojure.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function goToPage(pageNumber) {
block.load("/tutorial", { 'page' : pageNumber }, function() {
block.fadeIn();
changerUpdated();
updatePageNumber();
});
});
}
Expand All @@ -34,117 +35,121 @@ function goToTag(tag) {
return goToPage(i);
}
}
return;
}

function setupLink(url) {
return function(e) { $("#changer").load(url, function(data) { $("#changer").html(data); }); }
}

function setupExamples(controller) {
$(".code").click(function(e) {
controller.promptText($(this).text());
});
}

function getStep(n, controller) {
$("#tuttext").load("tutorial", { step: n }, function() { setupExamples(controller); });
}

function eval_clojure(code) {
var data;
$.ajax({
url: "eval.json",
data: { expr : code },
async: false,
success: function(res) { data = res; }
});
return data;
}

function html_escape(val) {
var result = val;
result = result.replace(/\n/g, "<br/>");
result = result.replace(/[<]/g, "&lt;");
result = result.replace(/[>]/g, "&gt;");
return result;
}

function doCommand(input) {
if (input.match(/^gopage /)) {
goToPage(parseInt(input.substring("gopage ".length)));
return true;
}

if (input.match(/^gotag /)) {
goToTag(input.substring("gotag ".length));
return true;
}

switch (input) {
case 'next':
case 'forward':
goToPage(currentPage + 1);
return true;
case 'previous':
case 'prev':
case 'back':
goToPage(currentPage - 1);
return true;
case 'restart':
case 'reset':
case 'home':
case 'quit':
goToPage(0);
return true;
default:
return false;
}
}

function onValidate(input) {
return (input != "");
}

function onHandle(line, report) {
var input = $.trim(line);

// handle commands
if (doCommand(input)) {
report();
return;
}

// perform evaluation
var data = eval_clojure(input);

// handle error
if (data.error) {
return [{msg: data.message, className: "jquery-console-message-error"}];
}

// handle page
if (currentPage >= 0 && pageExitCondition(currentPage)(data)) {
goToPage(currentPage + 1);
}

// display expr results
return [{msg: data.result, className: "jquery-console-message-value"}];
}

/**
* This should be called anytime the changer div is updated so it can rebind event listeners.
* Currently this is just to make the code elements clickable.
*/
function changerUpdated() {
$("#changer code.expr").each(function() {
$(this).css("cursor", "pointer");
$(this).attr("title", "Click to insert '" + $(this).text() + "' into the console.");
$(this).click(function(e) {
controller.promptText($(this).text());
controller.inner.click();
});
});
return;
}

function setupLink(url) {
return function(e) { $("#changer").load(url, function(data) { $("#changer").html(data); }); }
}

function setupExamples(controller) {
$(".code").click(function(e) {
controller.promptText($(this).text());
});
}

function getStep(n, controller) {
$("#tuttext").load("tutorial", { step: n }, function() { setupExamples(controller); });
}

function eval_clojure(code) {
var data;
$.ajax({
url: "eval.json",
data: { expr : code },
async: false,
success: function(res) { data = res; }
});
return data;
}

function html_escape(val) {
var result = val;
result = result.replace(/\n/g, "<br/>");
result = result.replace(/[<]/g, "&lt;");
result = result.replace(/[>]/g, "&gt;");
return result;
}

function doCommand(input) {
if (input.match(/^gopage /)) {
goToPage(parseInt(input.substring("gopage ".length)));
return true;
}

if (input.match(/^gotag /)) {
goToTag(input.substring("gotag ".length));
return true;
}

switch (input) {
case 'next':
case 'forward':
goToPage(currentPage + 1);
return true;
case 'previous':
case 'prev':
case 'back':
goToPage(currentPage - 1);
return true;
case 'restart':
case 'reset':
case 'home':
case 'quit':
goToPage(0);
return true;
default:
return false;
}
}

function onValidate(input) {
return (input != "");
}

function onHandle(line, report) {
var input = $.trim(line);

// handle commands
if (doCommand(input)) {
report();
return;
}

// perform evaluation
var data = eval_clojure(input);

// handle error
if (data.error) {
return [{msg: data.message, className: "jquery-console-message-error"}];
}

// handle page
if (currentPage >= 0 && pageExitCondition(currentPage)(data)) {
goToPage(currentPage + 1);
}

// display expr results
return [{msg: data.result, className: "jquery-console-message-value"}];
}

/**
* This should be called anytime the changer div is updated so it can rebind event listeners.
* Currently this is just to make the code elements clickable.
*/
function changerUpdated() {
$("#changer code.expr").each(function() {
$(this).css("cursor", "pointer");
$(this).attr("title", "Click to insert '" + $(this).text() + "' into the console.");
$(this).click(function(e) {
controller.promptText($(this).text());
controller.inner.click();
});
});
}

function updatePageNumber(){
$("#changer").append("<p> <strong> Page: "+(currentPage+1)+" / 50</strong></p>")
}

var controller;
Expand Down
2 changes: 1 addition & 1 deletion src/tryclojure/views/home.clj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
[:h1
[:span.logo-try "Try"] " "
[:span.logo-clojure "Clo" [:em "j"] "ure"]]]
[:div#container
[:div#container.clearfix
[:div#console.console]
[:div#buttons
[:a#links.buttons "links"]
Expand Down