// PostComm.js // https://github.com/dwighthouse/PostComm.js // // Under MIT License // Copyright (c) 2013 Dwight House // // Colossians 3:23-24 // Compressed with Uglify2 // http://lisperator.net/uglifyjs/ !function(n){"use strict" function e(n){var e,t=0,i=n.length for(e=0;i>e;e+=1)t=31*t+n.charCodeAt(e),t=Math.floor(t) return t}function t(n,e){var t,i,o=n.length for(t=0;o>t;t+=1)if(i=n[t],e(i,t))return i}function i(){return+new Date}function o(n,e,t){n[e]=n.hasOwnProperty(e)?n[e]:t}function r(n){return/^https?:\/\//.test(n)}function c(n){return!!n&&!!n.window&&n===n.window}function u(){}function s(n){var e=n.indexOf("//")+2,t=n.indexOf("/",e) return-1!==t?n.substr(0,t):n}function a(n,e){var i=A[n]||[] return t(i,function(n){return n.details.contentWindow===e})}function f(n,e){var t=a(n,e) return(t||{}).comm}function d(n,e,t){e&&e.postMessage(t,n)}function g(n){var e="string"==typeof n return e&&_.test(n)}function m(n){return g(n)&&n.replace(P,"")===x}function p(n){var e=n.pingSuccess n.isConnected=!0,n.pingSuccess=u,n.pingFailure=u,e(f(n.origin,n.contentWindow))}function v(n){var e=n.pingFailure n.isConnected=!1,n.pingSuccess=u,n.pingFailure=u,e(f(n.origin,n.contentWindow))}function l(e){function t(){return i()-o>=r?(v(e),void 0):(e.isConnected||(d("*",e.contentWindow,u),c=Math.min(2*c,500),n.setTimeout(t,c)),void 0)}var o=i(),r=5e3,c=1,u=P+x t()}function C(n){var e=n.data,t=g(e),i=m(e),o=a(n.origin,n.source) t&&!i&&d(n.origin,n.source,e),o&&p(o.details),o&&!t&&o.details.messageHandler(e,o.comm)}function w(){L(n,"message",C)}function h(){V(n,"message",C)}function W(n,e){var t=e.origin o(A,t,[]),A[t].push({comm:n,details:e})}function E(n){var e=n.origin,i=n.contentWindow,o=A[e]||[] t(o,function(n,e){return n.details.contentWindow===i?(o.splice(e,1),!0):void 0}),0===o.length&&delete A[e]}function M(n){n.getOrigin=u,n.getContentWindow=u,n.getMessageHandler=function(){return u},n.isValid=function(){return!1},n.isConnected=function(){return!1},n.ping=u,n.sendMessage=u,n.destroy=u}function y(n,e){n.getOrigin=function(){return e.origin},n.getContentWindow=function(){return e.contentWindow},n.getMessageHandler=function(){return e.messageHandler},n.isValid=function(){return e.isValid},n.isConnected=function(){return e.isConnected},n.ping=function(n,t){e.isConnected=!1,e.pingSuccess=n,e.pingFailure=t||u,l(e)},n.sendMessage=function(n){d(e.origin,e.contentWindow,n)},n.destroy=function(){E(e),M(n)}}function F(n,e,t){var i,o,a=s(n),d=f(a,e),g={} return d?d:(i=r(a)&&c(e))?(o={origin:a,contentWindow:e,messageHandler:t,isValid:i,isConnected:!1,pingSuccess:u,pingFailure:u},y(g,o),W(g,o),g):(M(g),g)}function H(n,e){return F(n.src,n.contentWindow,e)}function O(e){var t=(n.document||{}).referrer,i=n.opener||n.parent return F(t,i,e)}function S(){return n.postComm=b,D}var L,V,x,P="postComm_ping_",_=RegExp("^"+P+"-?\\d+$",""),b=n.postComm,A={},D={} L=function(){return n.addEventListener?function(n,e,t){n.addEventListener(e,t,!1)}:n.attachEvent?function(n,e,t){n.attachEvent("on"+e,t)}:function(n,e,t){n["on"+e]=t}}(),V=function(){return n.removeEventListener?function(n,e,t){n.removeEventListener(e,t,!1)}:n.detachEvent?function(n,e,t){n.detachEvent("on"+e,t)}:function(n,e){n["on"+e]=[].u}}(),function(){var t=i()+"",o=Math.random()+"",r=(n.document||{}).referrer+"" x=""+e(t+"-"+o+"-"+r)%1e21}(),D.findComm=f,D.engage=w,D.disengage=h,D.createComm=F,D.createIframeComm=H,D.createParentComm=O,D.noConflict=S,n.postMessage&&(n.postComm=D,w(),"function"==typeof n.define&&n.define.amd&&n.define("postComm",[],function(){return D}))}(this)