Commit 0ff0e9c2 authored by Romain Courteaud's avatar Romain Courteaud

Fetch parameter from url

parent b82bce7b
/*global document, jQuery */
// filebrowser.html?file=browser%3A%2F%2Fbrowse%2Fls%2F
"use strict";
(function (document, $) {
$(document).ready(function () {
var getParameter = function(searchString, paramName) {
var i, val, params = searchString.split("&");
for (i=0;i<params.length;i++) {
val = params[i].split("=");
if (val[0] == paramName) {
return decodeURIComponent(val[1]);
}
}
return null;
};
var mapUrl = function (url) {
var searchString = url.href.split("?")[1],
fileToDisplay;
if (searchString) {
fileToDisplay = getParameter(searchString, "file");
if (fileToDisplay) {
$.ajax({
method: 'GET',
// XXX Hardcoded
url: "browser://browse/ls/",
url: fileToDisplay,
context: $('body'),
error: function (jqXHR, textStatus, errorThrown) {
$(this).text(errorThrown);
......@@ -18,7 +38,12 @@
// XXX Will fail if response does not send expected links...
$(this).html("<ul>");
for (var i in value._links.contents){
$(this).append("<li>" + value._links.contents[i].href + "</li>");
$(this).append("<li><button id='" + i + "'>" +
value._links.contents[i].href + "</button></li>");
$(this).find("#" + i.toString()).on('click', function(e, target) {
// XXX What to do with the url info?
console.log($(this).text());
});
}
$(this).append("</ul>");
} else {
......@@ -26,6 +51,14 @@
};
},
});
} else {
$(this).text("No parameter found in url");
}
}
};
$(document).ready(function () {
mapUrl(window.location);
});
}(document, jQuery));
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