HTML5 Motion Jpeg Player (Chrome, Firefox only)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
function play(renderer, url, sleep) {
    var can = document.getElementById(renderer);
    var ctx = can.getContext('2d');
    ctx.fillStyle = 'black';
    ctx.fillRect(0,0,can.width,can.height);
    window.setInterval(function() {
        var img = new Image();
        img.onload = function() {
            ctx.drawImage(img, 0, 0);
            img = null;
        };
        img.src = url;
    }, sleep);
}

Web Sockets VT100 TTY emulator

mc
browsers

JavaScript Module Design Pattern

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
 * Module Design Pattern
 * Import and Export
 */
MODULE = (function ($) {
  var my = {};
  var privateVariable = 'jQuery version ';

  function privateMethod() {
    // ...
  }

  my.moduleProperty = 1;
  my.moduleMethod = function () {
    alert(privateVariable + $().jquery)
    // ...
  }

  return my;
}(jQuery));

MODULE.moduleMethod()
console.log(MODULE.moduleProperty)

Simple AJAX module

This is the module pattern example which implement simple AJAX calls.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
$ajax = (function() {
    var my = {};
    
    my.call = function(uri, opt) {
        var xmlhttp;
        
        // options default values
        var type = 'GET';
        var mode = true;
        var data = '';
        var debug = false;
                        
        // parse options
        function parse() {
            if (opt) {
                if (opt.type) {
                    type = opt.type;
                }
                if (opt.mode) {
                    mode = opt.mode;
                }
                if (opt.data) {
                    data = opt.data;
                }
                if (opt.debug) {
                    debug = opt.debug;
                }
            }
        };
        
        // initialize
        function init() {
            if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
            }
            else { // code for IE6, IE5
                xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
            }
        }
        
        // set events
        function events() {
            xmlhttp.onerror=function() {
                // debug
                if (debug)
                    console.log(xmlhttp);
            };
            
            if (mode) {
                xmlhttp.onreadystatechange=function() {
                    // debug
                    if (debug)
                        console.log('state='+xmlhttp.readyState+', status='+xmlhttp.status);
                        
                    if (opt) {
                        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                            if (opt.success) {
                                opt.success(xmlhttp)
                            }
                        } else {
                            if (opt.error) {
                                opt.error(xmlhttp)
                            }
                        }
                    }
                }
            }
        };
        
        // send
        function send() {
            xmlhttp.open(type, uri, mode);
            if (type === 'POST') {
                xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
                xmlhttp.send(data);             }
            else
                xmlhttp.send();
        };

        // ajax call
        parse();
        init();
        events();
        send(); 
    };

    return my;
}());

$ajax.call('x.json', {
        'type' : 'POST',
        'success' : function(xmlhttp) {
            console.log(xmlhttp);
        },
        'debug' : true
    }
);

Flag Counter