Commit f55aeaf7 authored by Sven Franck's avatar Sven Franck

fwd postMessage to preview gadget, digest and display

parent ad7d15e1
...@@ -3,6 +3,23 @@ ...@@ -3,6 +3,23 @@
"use strict"; "use strict";
(function (document, $) { (function (document, $) {
var myIndexOf = function (path, contains) {
var len = path.length;
var wordLen = contains.length;
for(var i = 0; i < len; i++) {
var j = 0;
for(j = 0; j < wordLen; j++) {
if(path[i+j] != contains[j]) {
break;
}
}
if(j == wordLen) {
return i;
}
}
return -1;
};
var getParameter = function(searchString, paramName) { var getParameter = function(searchString, paramName) {
var i, val, params = searchString.split("&"); var i, val, params = searchString.split("&");
...@@ -15,10 +32,19 @@ ...@@ -15,10 +32,19 @@
return null; return null;
}; };
// this is our "interactor", it only knows one other iFrame
// so we post to this one!
var handler = function (event) { var handler = function (event) {
console.log(event.data); var frames = document.getElementsByTagName("iframe"), frame, i;
console.log("hello inside handler"); for (i = 0; i < frames.length; i += 1) {
console.log(event); frame = frames[i];
if (myIndexOf(
event.source.location.pathname,
frame.getAttribute("src").split("?")[0]
) < 0) {
frame.contentWindow.postMessage(event.data, window.location.href);
}
}
}; };
var mapUrl = function (url) { var mapUrl = function (url) {
......
...@@ -8,7 +8,32 @@ ...@@ -8,7 +8,32 @@
/*global document, jQuery */ /*global document, jQuery */
"use strict"; "use strict";
(function (document, $) { (function (document, $) {
$(document).ready(function () {
var ajaxGet = function (src, cb) {
$.ajax({
method: 'GET',
url: src,
context: $('body'),
error: function (jqXHR, textStatus, errorThrown) {
$(this).text(errorThrown);
},
success: function (value, textStatus, jqXHR) {
cb(value, textStatus, jqXHR);
}
});
};
var handler = function (event) {
ajaxGet(event.data, function(value, status, jqXHR) {
ajaxGet(value._links.enclosure.href, function(value, status, jqXHR) {
if (value === "") {
window.document.body.innerHTML = "file not found";
} else {
window.document.body.innerHTML = value;
}
});
});
}
var mapUrl = function (url) { var mapUrl = function (url) {
var searchString = url.href.split("?")[1], var searchString = url.href.split("?")[1],
...@@ -50,7 +75,14 @@ ...@@ -50,7 +75,14 @@
return null; return null;
}; };
mapUrl(window.location); $(document).ready(function () {
// mapUrl(window.location);
if (window.addEventListener){
window.addEventListener("message", handler, false)
} else {
window.attachEvent("onmessage", handler)
}
}); });
}(document, jQuery)); }(document, jQuery));
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment