Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update Froogaloop library to work with HSTS

commit f433dfe16446b10925c0d907c987257c12ef86f7 1 parent 8c28433
@bdougherty bdougherty authored
Showing with 17 additions and 48 deletions.
  1. +13 −43 javascript/froogaloop.js
  2. +4 −5 javascript/froogaloop.min.js
View
56 javascript/froogaloop.js
@@ -1,5 +1,3 @@
-alert('Remove this line before using in production!');
-
// Init style shamelessly stolen from jQuery http://jquery.com
var Froogaloop = (function(){
// Define a local copy of Froogaloop
@@ -12,7 +10,7 @@ var Froogaloop = (function(){
hasWindowEvent = false,
isReady = false,
slice = Array.prototype.slice,
- playerDomain = '';
+ playerOrigin = '*';
Froogaloop.fn = Froogaloop.prototype = {
element: null,
@@ -24,9 +22,6 @@ var Froogaloop = (function(){
this.element = iframe;
- // Register message event listeners
- playerDomain = getDomainFromUrl(this.element.getAttribute('src'));
-
return this;
},
@@ -123,17 +118,12 @@ var Froogaloop = (function(){
return false;
}
- var url = target.getAttribute('src').split('?')[0],
- data = JSON.stringify({
- method: method,
- value: params
- });
-
- if (url.substr(0, 2) === '//') {
- url = window.location.protocol + url;
- }
+ var data = JSON.stringify({
+ method: method,
+ value: params
+ });
- target.contentWindow.postMessage(data, url);
+ target.contentWindow.postMessage(data, playerOrigin);
}
/**
@@ -155,11 +145,15 @@ var Froogaloop = (function(){
isReady = true;
}
- // Handles messages from moogaloop only
- if (event.origin != playerDomain) {
+ // Handles messages from the vimeo player only
+ if (!(/^https?:\/\/player.vimeo.com/).test(event.origin)) {
return false;
}
+ if (playerOrigin === '*') {
+ playerOrigin = event.origin;
+ }
+
var value = data.value,
eventData = data.data,
target_id = target_id === '' ? null : data.player_id,
@@ -239,30 +233,6 @@ var Froogaloop = (function(){
return true;
}
- /**
- * Returns a domain's root domain.
- * Eg. returns http://vimeo.com when http://vimeo.com/channels is sbumitted
- *
- * @param url (String): Url to test against.
- * @return url (String): Root domain of submitted url
- */
- function getDomainFromUrl(url) {
- if (url.substr(0, 2) === '//') {
- url = window.location.protocol + url;
- }
-
- var url_pieces = url.split('/'),
- domain_str = '';
-
- for(var i = 0, length = url_pieces.length; i < length; i++) {
- if(i<3) {domain_str += url_pieces[i];}
- else {break;}
- if(i<2) {domain_str += '/';}
- }
-
- return domain_str;
- }
-
function isFunction(obj) {
return !!(obj && obj.constructor && obj.call && obj.apply);
}
@@ -287,4 +257,4 @@ var Froogaloop = (function(){
// Expose froogaloop to the global object
return (window.Froogaloop = window.$f = Froogaloop);
-})();
+})();
View
9 javascript/froogaloop.min.js
@@ -1,5 +1,4 @@
-alert("Remove this line before using in production!");
-var Froogaloop=function(){function e(a){return new e.fn.init(a)}function h(a,c,b){if(!b.contentWindow.postMessage)return!1;var f=b.getAttribute("src").split("?")[0],a=JSON.stringify({method:a,value:c});"//"===f.substr(0,2)&&(f=window.location.protocol+f);b.contentWindow.postMessage(a,f)}function j(a){var c,b;try{c=JSON.parse(a.data),b=c.event||c.method}catch(f){}"ready"==b&&!i&&(i=!0);if(a.origin!=k)return!1;var a=c.value,e=c.data,g=""===g?null:c.player_id;c=g?d[g][b]:d[b];b=[];if(!c)return!1;void 0!==
-a&&b.push(a);e&&b.push(e);g&&b.push(g);return 0<b.length?c.apply(null,b):c.call()}function l(a,c,b){b?(d[b]||(d[b]={}),d[b][a]=c):d[a]=c}var d={},i=!1,k="";e.fn=e.prototype={element:null,init:function(a){"string"===typeof a&&(a=document.getElementById(a));this.element=a;a=this.element.getAttribute("src");"//"===a.substr(0,2)&&(a=window.location.protocol+a);for(var a=a.split("/"),c="",b=0,f=a.length;b<f;b++){if(3>b)c+=a[b];else break;2>b&&(c+="/")}k=c;return this},api:function(a,c){if(!this.element||
-!a)return!1;var b=this.element,f=""!==b.id?b.id:null,d=!c||!c.constructor||!c.call||!c.apply?c:null,e=c&&c.constructor&&c.call&&c.apply?c:null;e&&l(a,e,f);h(a,d,b);return this},addEvent:function(a,c){if(!this.element)return!1;var b=this.element,d=""!==b.id?b.id:null;l(a,c,d);"ready"!=a?h("addEventListener",a,b):"ready"==a&&i&&c.call(null,d);return this},removeEvent:function(a){if(!this.element)return!1;var c=this.element,b;a:{if((b=""!==c.id?c.id:null)&&d[b]){if(!d[b][a]){b=!1;break a}d[b][a]=null}else{if(!d[a]){b=
-!1;break a}d[a]=null}b=!0}"ready"!=a&&b&&h("removeEventListener",a,c)}};e.fn.init.prototype=e.fn;window.addEventListener?window.addEventListener("message",j,!1):window.attachEvent("onmessage",j);return window.Froogaloop=window.$f=e}();
+var Froogaloop=function(){function e(a){return new e.fn.init(a)}function g(a,c,b){if(!b.contentWindow.postMessage)return!1;a=JSON.stringify({method:a,value:c});b.contentWindow.postMessage(a,h)}function l(a){var c,b;try{c=JSON.parse(a.data),b=c.event||c.method}catch(e){}"ready"!=b||k||(k=!0);if(!/^https?:\/\/player.vimeo.com/.test(a.origin))return!1;"*"===h&&(h=a.origin);a=c.value;var m=c.data,f=""===f?null:c.player_id;c=f?d[f][b]:d[b];b=[];if(!c)return!1;void 0!==a&&b.push(a);m&&b.push(m);f&&b.push(f);
+return 0<b.length?c.apply(null,b):c.call()}function n(a,c,b){b?(d[b]||(d[b]={}),d[b][a]=c):d[a]=c}var d={},k=!1,h="*";e.fn=e.prototype={element:null,init:function(a){"string"===typeof a&&(a=document.getElementById(a));this.element=a;return this},api:function(a,c){if(!this.element||!a)return!1;var b=this.element,d=""!==b.id?b.id:null,e=c&&c.constructor&&c.call&&c.apply?null:c,f=c&&c.constructor&&c.call&&c.apply?c:null;f&&n(a,f,d);g(a,e,b);return this},addEvent:function(a,c){if(!this.element)return!1;
+var b=this.element,d=""!==b.id?b.id:null;n(a,c,d);"ready"!=a?g("addEventListener",a,b):"ready"==a&&k&&c.call(null,d);return this},removeEvent:function(a){if(!this.element)return!1;var c=this.element,b=""!==c.id?c.id:null;a:{if(b&&d[b]){if(!d[b][a]){b=!1;break a}d[b][a]=null}else{if(!d[a]){b=!1;break a}d[a]=null}b=!0}"ready"!=a&&b&&g("removeEventListener",a,c)}};e.fn.init.prototype=e.fn;window.addEventListener?window.addEventListener("message",l,!1):window.attachEvent("onmessage",l);return window.Froogaloop=
+window.$f=e}();
Please sign in to comment.
Something went wrong with that request. Please try again.