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

Fetch parameter from url

parent b82bce7b
/*global document, jQuery */ /*global document, jQuery */
// filebrowser.html?file=browser%3A%2F%2Fbrowse%2Fls%2F
"use strict"; "use strict";
(function (document, $) { (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({ $.ajax({
method: 'GET', method: 'GET',
// XXX Hardcoded // XXX Hardcoded
url: "browser://browse/ls/", url: fileToDisplay,
context: $('body'), context: $('body'),
error: function (jqXHR, textStatus, errorThrown) { error: function (jqXHR, textStatus, errorThrown) {
$(this).text(errorThrown); $(this).text(errorThrown);
...@@ -18,7 +38,12 @@ ...@@ -18,7 +38,12 @@
// XXX Will fail if response does not send expected links... // XXX Will fail if response does not send expected links...
$(this).html("<ul>"); $(this).html("<ul>");
for (var i in value._links.contents){ 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>"); $(this).append("</ul>");
} else { } else {
...@@ -26,6 +51,14 @@ ...@@ -26,6 +51,14 @@
}; };
}, },
}); });
} else {
$(this).text("No parameter found in url");
}
}
};
$(document).ready(function () {
mapUrl(window.location);
}); });
}(document, jQuery)); }(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