forked from jeffomatic/nojquery-postmessage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnojquery.ba-postmessage.min.js
12 lines (12 loc) · 1.28 KB
/
nojquery.ba-postmessage.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/*
* nojquery-postmessage by Jeff Lee
* a non-jQuery fork of:
*
* jQuery postMessage - v0.5 - 9/11/2009
* http://benalman.com/projects/jquery-postmessage-plugin/
*
* Copyright (c) 2009 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
function NoJQueryPostMessageMixin(i,g){var a,c,e,j,b,d=1;if(window.postMessage){if(window.addEventListener){a={add:"addEventListener",remove:"removeEventListener"};c="message"}else{a={add:"attachEvent",remove:"detachEvent"};c="onmessage"}function h(k){window[a.add](c,k);return k}function f(k){window[a.remove](c,k)}this[i]=function(k,m,l){if(!m){return}l.postMessage(k,m.replace(/([^:]+:\/\/[^\/]+).*/,"$1"))};this[g]=function(m,l,k){if(e){f(e);e=null}if(!m){return false}e=h(function(n){switch(Object.prototype.toString.call(l)){case"[object String]":if(l!==n.origin){return false}break;case"[object Function]":if(l(n.origin)){return false}break}m(n)})}}else{this[i]=function(k,m,l){if(!m){return}l.location=m.replace(/#.*$/,"")+"#"+(+new Date)+(d++)+"&"+k};this[g]=function(m,l,k){if(j){clearInterval(j);j=null}if(m){k=typeof l==="number"?l:typeof k==="number"?k:100;j=setInterval(function(){var o=document.location.hash,n=/^#?\d+&/;if(o!==b&&n.test(o)){b=o;m({data:o.replace(n,"")})}},k)}}}return this};