TinyCore.js - Handling Errors

by JuanMa Garrido

HTML

<script src="https://raw.github.com/mawrkus/tinycore/master/src/TinyCore.js"></script>
<div id="container">
    <h3>Press buttons to see the messages in the "console"...</h3>
    
    <ol>
      <li><button id='startModule'>Start Module</button> &rarr; press button to start the module</li>
    </ol>
</div>

<div id="logs"></div>

CSS

#container { padding:10px; font-family: Arial; }
#logs { height:200px; margin:20px 10px; padding:10px; font-family: Courier; font-size:11px; border:1px solid #000; overflow-y:scroll; }
em { font-family: Courier; font-size:13px; font-weight:bold; }
h3 { font-style: italic; margin-bottom:10px; }
#clear_logs { position: absolute; right: 9px; margin-top: -5px; }

JavaScript

TinyCore.ErrorHandler.log = function ( sMsg ){
    var oParag = document.createElement('p'),
        oLogs = document.getElementById( 'logs' );
    oParag.innerHTML = sMsg;
    oLogs.appendChild(oParag);
    oLogs.scrollTop = oLogs.scrollHeight;
}

$(document).ready(function () {

    // Register the Module    
    TinyCore.Module.register( 'my-module', function( bus ) {
        return {
            onStart: function( ) {
               UnexistingMethod();
            }        
        };
    });
    
    $("#startModule").click(function () {
        // Start the Module
        TinyCore.Module.start("my-module");
        return false;
    });

});