AngularJS Post Message API Wrapper. Developed for communication between two Angular apps, but can be used with non-angular apps as well.
http://petarslovic.github.io/ng-post-message/
- required: lodash
See bower.json
and index.html
in the gh-pages
branch for a full list / more details
Bower
add `"ng-post-message": "latest"` to your `bower.json` file then run `bower install` OR run `bower install ng-post-message`
post-message.min.js
i.e. in app.js
- petarslovic.ng-post-message
See the gh-pages
branch, files bower.json
and index.html
for a full example.
To configure ng-post-message, inject it in the config phase like so:
angular
.module('your-module')
.config(function(PostMessageProvider) {
PostMessageProvider.setAllowedDomains(['http://petarslovic.github.io']);
});
-
PostMessageProvider.setAllowedDomains(array) Set the list of domains that your app can communicate with. This list will be checked when your app receives a message.
-
PostMessageProvider.debug(boolean) Turn debug messages on or off.
- PostMessage.on(messageName, callback)
Registers message listeners.
Message name is like an event name, and callback will be executed when the message arrives.
When your callback is invoked, it will be provided the original event and message data as parameters in that order.
Message data is an object containing
messageName
anddata
.
var offSomeEvent = PostMessage.on('some-event', function(event, data) {
console.log(event, data);
vm.message = data;
});
The PostMessage.on
method returns a deregister function that you can call to deregister that listener.
For example, you would deregister a listener when a scope is destroyed (i.e. state changed).
$scope.$on('$destroy', offSomeEvent);
- PostMessage.send(messageName, data, iframeName, domain)
Sends a message with name
messageName
and datadata
to iframe with[name="iframeName"]
that is located on the domaindomain
. If you provide null as aniframeName
the message will be sent towindow.parent
(for sending messages from an iframe to parent window). If you don't providedomain
as a parameter,'*'
will be used.
PostMessage.send('some-event', {
some: 'data'
}, 'myIframeName', 'http://petarslovic.github.io');
git checkout gh-pages
- run
npm install && bower install
- write your code then run
grunt
- git commit your changes
- run
- copy over core files (.js and .css/.less for directives) to master branch
git checkout master
git checkout gh-pages post-message.js post-message.min.js
- update README, CHANGELOG, bower.json, and do any other final polishing to prepare for publishing
- git commit changes
- git tag with the version number, i.e.
git tag v1.0.0
- create github repo and push
- [if remote does not already exist or is incorrect]
git remote add origin [github url]
git push origin master --tags
(want to push master branch first so it is the default on github)git checkout gh-pages
git push origin gh-pages
- [if remote does not already exist or is incorrect]
- (optional) register bower component
bower register ng-post-message [git repo url]