-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinner.js
More file actions
49 lines (38 loc) · 1.04 KB
/
Copy pathinner.js
File metadata and controls
49 lines (38 loc) · 1.04 KB
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
(function () {
"use strict";
var worker = new SharedWorker('shared-worker.js', 'my-shared-scope')
, log = document.getElementById('log')
, sendMessage
, sendBark
;
worker.port.addEventListener('message', function (e) {
log.textContent += '\n' + e.data.msg;
});
worker.port.start();
sendBark = (function () {
var count = 0
;
return function (ev) {
console.log('going to bark');
worker.port.postMessage({ msg: '[' + count + '] Bark!' });
count += 1;
};
}());
sendMessage = (function () {
var count = 0
;
return function (ev) {
ev.preventDefault();
var msg = $(this).find('.js-message').val()
;
console.log('going to send message (from inner):', msg);
worker.port.postMessage({ msg: '[' + count + ']' + msg });
count += 1;
};
}());
function attachHandlers() {
$('body').delegate('.js-bark', 'click', sendBark);
$('body').delegate('form.js-messenger', 'submit', sendMessage);
}
$.domReady(attachHandlers);
}());