An elegant wrapper for postMessage
.
PostIt
requires git and Node.js, before proceeding.
# Install postit
$ npm install --save git+ssh://[email protected]/outbrain/postit.git
<script src="path/to/postit.js"></script>
var PostIt = require('postit');
Creates and manages a new PostIt
instance.
Param | Type |
---|---|
id | string |
PostIt.add('baz');
Removes an explicit PostIt
instance.
Param | Type |
---|---|
id | string |
PostIt.remove('baz');
Removes all PostIt
instances.
PostIt.removeAll();
Returns the length of all PostIt
instances.
PostIt.size();
Gets an explicit PostIt
instance.
Param | Type |
---|---|
id | string |
PostIt.get('baz');
Gets all PostIt
instances.
PostIt.getAll();
Registers .postMessage
event listeners.
Param | Type |
---|---|
id | string |
event | string |
listener | function |
PostIt.on('baz', 'bar', function (event) {
//
});
Unregisters (all | explicit) .postMessage
event listeners.
Param | Type |
---|---|
id | string |
event | string |
listener | function |
// Unregister all listeners of a given `event`:
PostIt.off('baz', 'bar');
function bazBar() {}
// Unregister an explicit listener of a given `event`:
PostIt.off('baz', 'bar', bazBar);
Emits explicit message
events, using the client's .postMessage
emitter.
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 |
---|---|
options.url | string |
options.title | string |
options.width | number |
options.height | number |
options.top | number |
options.left | number |
See: window.open for more options.
PostIt.openWindow({
url: 'http://www.foo.com',
title: 'foo',
width: 700,
height: 500
});
Releases will be numbered using the following format:
<major>.<minor>.<patch>
And constructed with the following guidelines:
- Breaking backward compatibility bumps the major while resetting minor and patch.
- New additions without breaking backward compatibility bumps the minor while resetting the patch.
- Bug fixes and misc. changes bumps only the patch.
For more information on SemVer, please visit http://semver.org/.