Commit 5e269eda authored by Sven Franck's avatar Sven Franck

updated first example to only using Ajax links

parent 8a1e595d
// > grab URL with parameters of file to open
// > call addGadget with those parameters?
// > display a file from some storage (local/session)
// > storage type will also be a parameter in the url?
// return "browser://localstorage/foo"
// file=browser%3A%2F%2Flocalstorage%2Ffoo
/*global document, jQuery */ /*global document, jQuery */
"use strict"; "use strict";
(function (document, $) { (function (document, $) {
...@@ -24,44 +17,21 @@ ...@@ -24,44 +17,21 @@
}; };
var handler = function (event) { var handler = function (event) {
ajaxGet(event.data, function(value, status, jqXHR) { var type = event.data.type,
ajaxGet(value._links.enclosure.href, function(value, status, jqXHR) { method = type ? type.split("/")[0] : undefined;
if (value === "") { // prevent both renderJs and page events triggering on "run"
window.document.body.innerHTML = "file not found"; if (type === undefined || method !== "run") {
} else { ajaxGet(event.data, function(value, status, jqXHR) {
window.document.body.innerHTML = value; 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 searchString = url.href.split("?")[1],
fileToDisplay;
if (searchString) {
fileToDisplay = getParameter(searchString, "file");
if (fileToDisplay) {
$.ajax({
method: 'GET',
url: fileToDisplay,
context: $('body'),
error: function (jqXHR, textStatus, errorThrown) {
$(this).text(errorThrown);
},
success: function (value, textStatus, jqXHR) {
if (value === "") {
$(this).text("file not found");
} else {
$(this).text(value);
}
},
}); });
} });
} else {
$(this).text("no file to display");
} }
}; }
var getParameter = function(searchString, paramName) { var getParameter = function(searchString, paramName) {
var i, val, params = searchString.split("&"); var i, val, params = searchString.split("&");
...@@ -75,18 +45,64 @@ ...@@ -75,18 +45,64 @@
return null; return null;
}; };
$(document).ready(function () { var mapUrl = function (searchString) {
// mapUrl(window.location); var fileToDisplay = getParameter(searchString, "file"),
scope,
register,
service;
if (fileToDisplay) {
$.ajax({
method: 'GET',
url: fileToDisplay,
context: $('body'),
error: function (jqXHR, textStatus, errorThrown) {
$(this).text(errorThrown);
},
success: function (value, textStatus, jqXHR) {
scope = value._links.scope.href.slice(0,-1).split(/[/]+/).pop();
register = value._links.call.href
.replace("{method}", "register")
.replace("{scope}", scope )
.replace("{interaction}", "");
service = {
"type": "service/test",
"src": encodeURIComponent(window.location.href),
"rel": "preview",
"self": window.frameElement.id
};
$.ajax({
method: 'POST',
url: register,
context: $(this),
data: JSON.stringify(service),
error: function (jqXHR, textStatus, errorThrown) {
console.log("registration failed: " + errorThrown);
},
success: function (value, textStatus, jqXHR) {
// console.log("registration successful");
}
});
}
});
}
}
$(document).ready(function () {
var search = window.location.search;
if (search) {
mapUrl(search.slice(1));
} else {
$("body").text("No parameter found in url");
}
if (window.addEventListener){ if (window.addEventListener){
window.addEventListener("message", handler, false) window.addEventListener("message", handler, false)
} else { } else {
window.attachEvent("onmessage", handler) window.attachEvent("onmessage", handler)
} }
// $(window).on('hashchange', function() {
// console.log("LE HASH CHANGED");
// });
// $(window).trigger("hashchange");
}); });
}(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