-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
51 lines (41 loc) · 1.31 KB
/
index.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PostIt</title>
</head>
<body>
<button id="postIt">PostIt</button>
<iframe src="iframe.html" width="300" height="300"></iframe>
<!-- Scripts -->
<script src="../dist/postit.js"></script>
<script>
(function() {
'use strict';
/**
* @note Always specify a more explicit target `origin`, not `*`, when utilizing `postMessage` to send data.
*/
var postItElem = document.getElementById('postIt');
PostIt
// Creates and manages a `PostIt` instance.
.add('foo')
// Registers a `listener` to a `PostIt` instance, for a given `event`.
.on('foo', 'bar', function(event) {
postItElem.innerHTML = event.dataParsed.message;
// Emits an `event` to all listeners registered to a `PostIt` instance, for a given `event`.
PostIt.emit('foo', 'baz', event.source, { message: 'Message from `index.html`' }, '*');
})
// Registers a `listener` to a `PostIt` instance, for all given `event`s.
.on('foo', '*', function(event) {
console.log('[foo.*]', event.dataParsed);
});
postItElem.addEventListener('click', function() {
PostIt.openWindow('window.html', 'PostIt', {
width: 700,
height: 500
});
}, false);
})();
</script>
</body>
</html>