1
0
Fork 0
mirror of https://github.com/Oreolek/undum.git synced 2024-05-02 00:59:20 +03:00

Link catcher

This commit is contained in:
Alexander Yakovlev 2015-07-23 17:18:36 +07:00
parent 1e16ea7be7
commit 38b4ae5bd1
3 changed files with 31 additions and 9 deletions

File diff suppressed because one or more lines are too long

View file

@ -290,8 +290,8 @@ var startOutputTransaction = function() {
}
// The default is "all the way down".
scrollStack.push(
$("#content").height() + $("#title").height() + 60
);
document.getElementById("content").offsetHeight + document.getElementById("title").offsetHeight + 60
);
};
var continueOutputTransaction = function() {
if (pendingFirstWrite) {
@ -342,7 +342,7 @@ var processLink = function(code) {
endOutputTransaction();
// We're able to save, if we weren't already.
$("#save").attr('disabled', false);
document.getElementById("save").setAttribute('disabled', false);
};
/* This gets called to actually do the work of processing a code.
@ -392,13 +392,21 @@ var processOneLink = function(code) {
}
};
/* This function listens on content block to filter out link clicks. */
var linkClickHandler = function(event) {
if (event.target.tagName.toLowerCase() === 'a') {
event.preventDefault();
processClick(event.target.href);
}
}
/* This gets called when the user clicks a link to carry out an
* action. */
var processClick = function(code) {
var now = (new Date()).getTime() * 0.001;
system.time = now - startTime;
progress.sequence.push({link:code, when:system.time});
processLink(code);
return processLink(code);
};
/* Transitions between situations. */

View file

@ -99,6 +99,9 @@ ready(function() {
startGame();
}
// handle the link clicks
document.getElementById("content").addEventListener("click", linkClickHandler, false);
// Display the "click to begin" message. (We do this in code
// so that, if Javascript is off, it doesn't happen.)
showBlock("click_message");