Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Delay Demo</title>
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css">


    <link href="client/css/App.css" rel="stylesheet" >

<script
  src="https://code.jquery.com/jquery-1.9.1.min.js"
  integrity="sha256-wS9gmOZBqsqWxgIVgA8Y9WcQOa7PgSIX+rPA0VL2rbQ="
  crossorigin="anonymous"></script>
  


    <script>

        var app;

        $(document).ready(function() {
            app = DelayDemo();
            app.start();
        });

    </script>
</head>
<body>

<div class="container top-container">
    <div class="page-header">
        <h1>Delay Demo</h1>
    </div>

    <div class="panel panel-default">
        <div id="content" class="panel-body">


            <table>
                <div id="message"></div>
                <div id="counter"></div>
                <button id="doAgainBtn">Do Again</button>
            </table>
        </div>
    </div>
</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="client/lib/jquery-1.9.1.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="client/js/bootstrap.min.js"></script>
</body>
</html>


              
            
!

CSS

              
                
a {
    cursor: pointer;
}

#caret {

    display:inline;
    float: left;

}

#btn {
    vertical-align: top;
}

.left-arrow {
    width:20px;
    height:20px;
    background:url('../images/left-arrow.png') center no-repeat;
    display:block;
    float:left;
    cursor:pointer;
    background-size: 100% auto;
}

.top-container {
    width: 150px;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}

.panel-default {
    width: 150px;
    margin-left: auto;
    margin-right: auto;
}

.page-header {
    text-align: center;
    width: 150px;
}
              
            
!

JS

              
                //-------------------------------------------------//
//                                                 //
//             Frame Machine Notation              //
//                                                 //
//-------------------------------------------------//

// FMN Gist by Mark Truluck

/*
#DelayDemo

	-interface-

	 start @(|>>|)
	 timeout
	 doAgain
	
	-machine-
    
        $Begin => $Default
		|>>| 
			log("$Begin |>>|")
                        disableDoAgainBtn()
                        -> $Delaying  ^  
                        
        $Delaying
                |>|
			log("$Delaying |>|")
			showDelayMessage()
			initCounter()
			startTimer() ^
                |timeout|
			log("$Delaying |timeout|")
			decrementCounter()
			isCounterAt0() ? -> $Ready :: ^
                |<|
			stopTimer() 
			log("$Delaying |<|") ^                  
   
        $Ready
                |>|
			log("$Ready |>|")
			addListeners()
			enableDoAgainBtn()
			showReadyMessage() ^
			
                |doAgain|
			log("$Ready |doAgain|")
			-> $Delaying ^
                |<|
			disableDoAgainBtn()
			removeListeners() 
			log("$Ready |<|") ^                  
			
*/

 //-------------------------------------------------//
 //                                                 //
 //                 Implementation                  //
 //                                                 //
 //-------------------------------------------------//
  
 var FrameEvent = function(message, data) {

    var that = {};

    that.message = message;
    that.data = data;
    that.return = null;

    return that;
};


// #DelayDemo

var DelayDemo = function()
{

    var that = {};

	/********************

	-interface-

	 start @(|>>|)
	 timeout
	 doAgain

	********************/

	that.start = function () {
		var e = FrameEvent(">>");
		_state_(e);
	};

	that.timeout = function () {
		var e = FrameEvent("timeout");
		_state_(e);
	};

	that.doAgain = function () {
		var e = FrameEvent("doAgain");
		_state_(e);
	};

    	// -machine-

	/********************

	$Begin => $Default
		|>>| 
			log("$Begin |>>|")
			disableDoAgainBtn()
			-> $Delaying  ^  

	********************/

	var _sBegin = function (e) {
		if (e.message == ">>") {
			log("$Begin |>>|");
			disableDoAgainBtn();
			_transition(_sDelaying);
			return;
		}
	};

	var _state_ = _sBegin;

	/********************

        $Delaying
                |>|
			log("$Delaying |>|")
                        showDelayMessage()
                        initCounter()
                        startTimer() ^
                |timeout|
			log("$Delaying |timeout|")
                        decrementCounter()
                        isCounterAt0() ? -> $Ready :: ^
                |<|
                        stopTimer() 
			log("$Delaying |<|") ^ 

     	********************/


	var _sDelaying = function (e) {
		if (e.message == ">") {
			log("$Delaying |>|");
			showDelayMessage();
			initCounter();
			startTimer();
			return;
		}
		if (e.message == "timeout") {
			log("$Delaying |timeout|");
			decrementCounter();
			if (isCounterAt0()) {
				_transition(_sReady);
				return;
			}
			return;
		}
		if (e.message == "<") {
			stopTimer();
			log("$Delaying |<|");
			return;
		}
	};

    	/********************

        $Ready
                |>|
			log("$Ready |>|")
                        addListeners()
                        enableDoAgainBtn()
                        showReadyMessage() ^
                |doAgain|
 			log("$Ready |doAgain|")
                       -> $Delaying ^
                |<|
                        disableDoAgainBtn()
			removeListeners() 
			log("$Ready |<|") ^   

     	********************/


	var _sReady = function (e) {
		if (e.message == ">") {
			log("$Ready |>|");
			addListeners();
			enableDoAgainBtn();
			showReadyMessage();
			return;
		}
		if (e.message == "doAgain") {
 			log("$Ready |doAgain|")
			_transition(_sDelaying);
			return;
		}
		if (e.message == "<") {
			disableDoAgainBtn();
			removeListeners();
			log("$Ready |<|");
			return;
		}
	};

    // -actions-

    var addListeners = function(msg) {
        $("#doAgainBtn").on("click", that.doAgain);
    };

    var removeListeners = function(msg) {
        $("#doAgainBtn").off("click", that.doAgain);
    };

    var showDelayMessage = function() {
        $("#message").text("Delaying");
    };

    var initCounter = function() {
        counter = 5;
        $("#counter").text(counter);
    };

    var startTimer = function() {
        timer = setInterval(that.timeout,1000);
    };

    var decrementCounter = function() {
        counter--;
        $("#counter").text(counter);
    };

    var isCounterAt0 = function() {
        return counter == 0;
    };

    var stopTimer = function() {
        clearInterval(timer);
        timer = null;
    };

    var showReadyMessage = function() {
        $("#message").html("Ready!");
    };

    var enableDoAgainBtn = function() {
        $("#doAgainBtn").removeAttr("disabled");
    };
	
    var disableDoAgainBtn = function() {
        $("#doAgainBtn").attr("disabled", "disabled");
    };
	
    var log = function(msg) {
      console.log(msg);
    };
	
    // -domain-

    var counter;
    var timer;

    // Machinery and mechanisms

    var _transition = function(newState) {
        _state_(FrameEvent("<"));
        _state_ = newState;
        _state_(FrameEvent(">"));
    };

//-------------------------------------------------//

    return that;
};
              
            
!
999px

Console