Linux Survival
'); } function commandCorrect(command, commandNum) { var entered = command.trim(); var numPoss = numPossibles[commandNum]; for (var i = 0; i < numPoss; i++) { // check all possibles var expected = commands[commandNum][i]; if (commandsMatch(entered, expected)) return true; } return false; } function commandAlmostCorrect(entered, commandNum) { var numAlmsts = numAlmosts[commandNum]; for (var i = 0; i < numAlmsts; i++) { // check all possibles var almost = almosts[commandNum][i]; if (commandsMatch(entered, almost)) return i; } return -1; } function commandsMatch(entered, expected) { if (expected == "#SPACE#") if (entered == " ") return true; else return false; else { var enteredTokens = entered.split(" "); var expectedTokens = expected.split(" "); var enteredCount = enteredTokens.length; var expectedCount = expectedTokens.length; var match = true; if (enteredCount == expectedCount) { for (var i = 0; i <= expectedCount; i++) if (!(enteredTokens[i] == expectedTokens[i])) { match = false; // Command word doesn't match break; } } else match = false; // Wrong number of words in command return(match); } } function strEndsWith(str, suffix) { return str.match(suffix+"$")==suffix; } // Create the terminal $('#term').terminal(function(command, term) { // Allow closing dialog box with Enter key without terminal thinking it's a command term.pause(); dialogNum = 1; if (commandCorrect(command, commandNum)) { var congratulations = congrats[commandNum]; if (!(congratulations == "#NO_CONGRATS#")) jqdialogs[0] = $.jqdialog(congratulations, true, term); } else { var expected = commands[commandNum][0]; var almostIndex = commandAlmostCorrect(command, commandNum); if (almostIndex > -1) // Show failure message for almost correct command jqdialogs[0] = $.jqdialog(almostFailures[commandNum][almostIndex], true, term); else { // Show failure text var failure = failures[commandNum]; if (failure == "#STANDARD_FAILURE#") jqdialogs[0] = $.jqdialog('You would type "' + expected + '".', true, term); else jqdialogs[0] = $.jqdialog(failure, true, term); } term.echo('[[;#ffff00;#000]' + prompt + expected + ']'); } // Display image var gif = gifs[commandNum]; if (!(gif == "#NO_GIF#" || gif == "#SAME_GIF#")) showGraphic(gif); // Set prompt text var lastprompt = prompt; prompt = prompts[commandNum]; if (prompt == "#SAME_PROMPT#") prompt = lastprompt; else prompt = prompt + " "; term.set_prompt(prompt); // Show command output var output = outputs[commandNum]; if (output != "#NO_OUTPUT#") term.echo(output); // command output // If no subsequent dialog boxes, then resume terminal after initial dialog closes if (numDialogs[commandNum] == 0) jqdialogs[0].on("dialogclose", function(event, ui) { if (commandNum < numCommands) { term.resume(); } }); // Show subsequent dialog boxes for (var i = 0; i < numDialogs[commandNum]; i++) { jqdialogs[i+1] = $.jqdialog(dialogs[commandNum][i], false, term); jqdialogs[i].on("dialogclose", function(event, ui) { jqdialogs[dialogNum].dialog("open"); dialogNum++; }); if ((i + 1) == numDialogs[commandNum]) { jqdialogs[i+1].on("dialogclose", function(event, ui) { if (commandNum < numCommands) { term.resume(); } }); } } commandNum++; // ready for next command // If no more commands, force user to go to next page if (commandNum >= numCommands) { $("#arrow_label").show(); term.pause(); } }, { prompt: "zoo> ", exit: false, clear: false, onBlur: function(term) { return false; }, onInit: function(term) { term.clear(); greetings(term); }, }); if (image != "null") { showGraphic(image); } $("#leftArrow").click(function() { window.location = '/index.php' }); $("#rightArrow").click(function() { window.location = 'linux-directory-structure' }); $("#term").trigger("click"); });

Page 1

Click the right arrow.




Where learning Linux is easy