Simple action

Show simple action at work

by bladnman

HTML

<script src="https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js"></script>
<script src="http://qubedpeas.com/files/currentVersion/QPTools.js"></script>
<input type=button id="theButton" value="run test" class="runButton">

<div id="log" class="log"></div>

CSS

.runButton {
    width:   125px;
    margin:  20px;
}
.log {
   padding:10px; 
    margin: 20px; 
    border: 1px dotted #ccc; 
    color:#888; 
    font-face: arial; 
    font-size:12px; 
    background: #fbfbfb; 
}

JavaScript

/* ************************************ */
function runTest() {
    for(var i=1; i<=10; i++) {
        var name = "Worker: " + i;
        var url = "http://yahoo.com/" + i;
        var worker = new Worker(name);
        worker.req.getData(url);
    }
}



var Worker = function (inName) {
    var my = this;
    my.name = inName || "unnamed";
    
    my.req = {
        getData : function (url) {
            QPU.breath(
                QPU.random(500),
                function() {
                   my.callbackHandlers.gotData(url); 
                }
            );
        }
    };
    my.callbackHandlers = {
        gotData : function (fromUrl, response) {
            log("GOT: " + my.name +  " ["+fromUrl+"]");
        }
    };
}








/* ************************************ 
 _____ ___ __  __ ___ _      _ _____ ___ 
|_   _| __|  \/  | _ \ |    /_\_   _| __|
  | | | _|| |\/| |  _/ |__ / _ \| | | _| 
  |_| |___|_|  |_|_| |____/_/ \_\_| |___|
                                         
************************************  */
function log(message, value) {
    var outMessage = message;

    if (typeof value !== "undefined" && value !== null) {
        outMessage += "&nbsp;&nbsp;&nbsp;&nbsp;[" + value + "]";
    }
    if ($("#log").html() != "") {
        $("#log").append("<br>");
    }
    $("#log").append(outMessage);

    if (window.console && console.log) {
        console.log(outMessage);
    }
}
$("#theButton").live('click', function() {
    runTest();
});