Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="enter a command.">
    <title>unilogue</title>
  <link rel="icon" href="favi.png">
  <link rel="stylesheet" href="https://unilogue.github.io/css/style.css">
  <script type="text/javascript" src="https://unilogue.github.io/js/jquery-1.11.3.min.js"></script>
 
  </head>
<body>
<header>
    
    <div id="prompt">enter the letter 'g' to load the div, notice how it keeps reloading if you enter the letter 'g' again? i don't want that to happen.</div>
    <br>
</header>
<div class="container"><p>&#62;&nbsp;</p><input class="inputs" type="text" placeholder="ENTER COMMAND" /></div>
</body>
</html>
 
$(document).ready(function() {
 $.ajaxSetup ({
     cache: false
 });
      // Check on keydown
     $('.inputs').keyup(function (e) {
            if (e.keyCode == 13) {
           var value = $(this).val();
           var ajax_load = "<p>LOADING<span class=\"blink\">_</span></p>";
          var loadGlossary = "https://unilogue.github.io/commands/glossary.asp";
           var errorLine = $("<p><span class=\"cmd\">&#62;&nbsp;UNKNOWN COMMAND</span></p><br>");
           var newLine = $('.inputs').clone(true).val('');
           var glossary = $("<div id=\"div3\"></div>");
          $.fn.gCmd = function() {
             $('.container').append(glossary);
             $("#div3").html(ajax_load).load(loadGlossary);
           };
           $.fn.newLine = function() {
            $('.container').append("<p>&#62;&nbsp;</p>").append(newLine);
            $(this).prop('disabled', true);
            $(this).removeClass('inputs');
            $('.inputs').replaceWith(newLine);
            $('.inputs:first').focus();
           };
          // Tiny jQuery Plugin
          // by Chris Goodchild
          $.fn.exists = function(callback) {
            var args = [].slice.call(arguments, 1);
            if (this.length) {
              callback.call(this, args);
            }
            return this;
          };
          /* Usage
          $(glossary).exists(function() {
            this.append('<p><span class=\"cmd\">&#62;&nbsp;[g]lossary is already open!</span></p><br>');
          });*/
            if (value == 'g' && !($('#div3').length)) { // If input value is div3
                $(this).gCmd();
            } else if  (value == 'g' && $(glossary).length === 0) { 
                $(this).append('<p>Look! A Thing!</p>');
            } else if (value !== '' && $(glossary).length === 0) { // If input value is wrong
                $(this).append(errorLine);
            } /*appends to all lines */ $(this).newLine();
          }
        });
    });
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
uniloguepro
0viewers