My favorites | Sign in
Project Logo
             
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

function Pipe(wp, sends, handler) {

var forEach = Array.forEach || function(a, func, cx) {
for(var i = 0; i < a.length; i++) {
func.call(cx || {}, a[i], i, a);
}
}

forEach(sends, function(send) {
this[send] = function() {
sendMessage(send, arguments);
}
}, this);

var pipe = this;

wp.onmessage = function(a, b, msg) {
var l = msg.text.split(':');
if (l.length) {
var h = function() {
this.sender = msg.sender;
this.origin = msg.origin;
};
h.prototype = pipe;
return (handler[l.shift()]||nil).apply(new h(), unmarshall(l));
}
}

function sendMessage(cmd, args) {
var a = [ escape(cmd) ];
var sender;
forEach(args, function(arg, i) {
(i > 0 && a.push(atos(arg))) || (sender = arg);
});
wp.sendMessage(a.join(':'), sender);
}

function unmarshall(args) {
var r = [];
forEach(args, function(arg) {
r.push(stoa(arg));
})
return r;
}

function isArray(a) {
return a && (a.constructor === Array || a.callee);
}

function nil() {}

function atos(a) {
if (a) {
if (isArray(a)) {
var r = [ null ];
forEach(a, function(item) {
r.push(escape(item));
});
return r.join('|');
}
return escape(a);
}
return a;
}

function stoa(s) {
if (s) {
if (s.charAt(0) == '|') {
var a = s.substring(1).split('|');
var r = [];
forEach(a, function(item) {
r.push(unescape(item));
})
return r;
}
return unescape(s);
}
return s;
}

}
Show details Hide details

Change log

r6 by dimitri.glazkov on Feb 02, 2008   Diff
 * added corner, which will be where the
code comes to rest and recharge
 * added html5-sql-player, which is
http://attic.glazkov.com/player/ code
 * added glazkov-com, which is the
styles/scripts for http://glazkov.com/
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1640 bytes, 82 lines
Hosted by Google Code