Postit
An elegant wrapper for postMessage
Install / Use
/learn @outbrain-inc/PostitREADME
PostIt
An elegant wrapper for postMessage.
Installation
Install postit-js as a dependency.
$ npm install --save postit-js
Run PostIt in a Browser
HTML Script Element
<script src="path/to/postit.js"></script>
CommonJS Browser Shimming (Browserify and Other Flavors)
var PostIt = require('postit');
API Documentation
.add(id) => object
Creates and manages a PostIt instance (id).
| Param | Type |
|:-----:|:--------:|
| id | string |
PostIt.add('baz');
.remove(id) => object
Removes a PostIt instance (id).
| Param | Type |
|:-----:|:--------:|
| id | string |
PostIt.remove('baz');
.removeAll() => object
Removes all PostIt instances.
PostIt.removeAll();
.size() => number
Returns the length of all PostIt instances.
PostIt.size();
.get(id) => object | void
Gets a PostIt instance (id).
| Param | Type |
|:-----:|:--------:|
| id | string |
PostIt.get('baz');
.getAll() => object
Gets all PostIt instances.
PostIt.getAll();
.on(id, event, listener) => object
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) {
// ...
});
.off(id, event[, listener]) => object
- If a
listeneris not provided, then unregister all listeners from aPostItinstance (id), for a givenevent. - If a
listeneris provided, then unregister alistenerfrom aPostItinstance (id), for a givenevent.
| Param | Type |
|:----------:|:----------:|
| id | string |
| event | string |
| [listener] | function |
PostIt.off('baz', 'bar');
function bazBar() {}
PostIt.off('baz', 'bar', bazBar);
.emit(id, event, target, message, origin) => object
- If
eventis an asterisk (*), then emit aneventto all listeners registered to aPostItinstance (id), for all givenevents. - If
eventis not an asterisk (*), then emit aneventto all listeners registered to aPostItinstance (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');
.openWindow(url, name, options) => object
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
});
Example
Contributing
Changelog
License
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
