angular-post-message
Version:
Allow angularJS to listen and publish cross-document messages though window.postMessage API.
6 lines • 889 B
JavaScript
/*!
* angular-post-message v1.4.0
* Copyright 2016 Kyle Welsby <kyle@mekyle.com>
* Licensed under The MIT License
*/
(function(){"use strict";var a;a=angular.module("ngPostMessage",["ng"]),a.run(["$window","$postMessage","$rootScope",function(a,b,c){c.$on("$messageOutgoing",function(b,d,e){var f;return null==e&&(e="*"),f=c.sender||a.parent,f.postMessage(d,e)}),angular.element(a).bind("message",function(a){var d;if(a=a.originalEvent||a,a&&a.data){d=null,c.sender=a.source;try{d=angular.fromJson(a.data)}catch(e){d={},d.text=a.data}return d.origin=a.origin,c.$root.$broadcast("$messageIncoming",d),b.messages(d)}})}]),a.factory("$postMessage",["$rootScope",function(a){var b,c;return b=[],c={messages:function(c){return c&&(b.push(c),a.$digest()),b},lastMessage:function(){return b[b.length-1]},post:function(b,c){return c||(c="*"),a.$broadcast("$messageOutgoing",b,c)}}}])}).call(this);