An elegant wrapper for postMessage
.
Install postit-js
as a dependency.
$ npm install --save postit-js
<script src="path/to/postit.js"></script>
var PostIt = require('postit');
Creates and manages a PostIt
instance (id
).
Param | Type |
---|---|
id | string |
PostIt.add('baz');
Removes a PostIt
instance (id
).
Param | Type |
---|---|
id | string |
PostIt.remove('baz');
Removes all PostIt
instances.
PostIt.removeAll();
Returns the length of all PostIt
instances.
PostIt.size();
Gets a PostIt
instance (id
).
Param | Type |
---|---|
id | string |
PostIt.get('baz');
Gets all PostIt
instances.
PostIt.getAll();
Registers a listener
to a PostIt
instance (id
), for a given event
.
Param | Type |
---|---|
id | string |
event | string |
listener | function |
PostIt.on('baz', 'bar', function(event) {
// ...
});
- If a
listener
is not provided, then unregister all listeners from aPostIt
instance (id
), for a givenevent
. - If a
listener
is provided, then unregister alistener
from aPostIt
instance (id
), for a givenevent
.
Param | Type |
---|---|
id | string |
event | string |
[listener] | function |
PostIt.off('baz', 'bar');
function bazBar() {}
PostIt.off('baz', 'bar', bazBar);
- If
event
is an asterisk (*), then emit anevent
to all listeners registered to aPostIt
instance (id
), for all givenevent
s. - If
event
is not an asterisk (*), then emit anevent
to all listeners registered to aPostIt
instance (id
), for a givenevent
.
Param | Type |
---|---|
id | string |
event | string |
target | object |
message | string array object |
origin | string |
PostIt.emit('baz', 'bar', window.parent.opener, { baz: 'bar' }, 'http://www.baz.com');
Loads a resource into a new browsing context (window
).
Param | Type |
---|---|
url | string |
name | string |
options | object |
options.width | number |
options.height | number |
See: window.open for more options.
PostIt.openWindow('http://www.foo.com', 'foo', {
width: 700,
height: 500
});