Permalink
Browse files

Merge pull request #589 from fcrepo4/non-rdf-js

Use javascript to detect requests to non-rdf source properties and redirect them to the metadata page instead.

https://www.pivotaltracker.com/story/show/80952408
  • Loading branch information...
awoods committed Oct 26, 2014
2 parents 33275b9 + c9847fd commit 5e6bb871528751815219de62342123f5164e32fd
Showing with 28 additions and 0 deletions.
  1. +28 −0 fcrepo-http-api/src/main/resources/views/common.js
@@ -125,9 +125,37 @@ $(function() {
var ldpContains = $('#childList li').length;
$('#badge').text(ldpContains);
$('a[property][href*="' + location.host + '"],#childList a,.breadcrumb a').click(checkIfNonRdfResource);
});
function checkIfNonRdfResource(e) {
var url = this.href;
$.ajax({type: "HEAD", url: url}).success(function(data, status, xhr) {
var headers = xhr.getResponseHeader("Link").split(", ");
var types = $.grep(headers, function(h) {
return h.match(/rel="type"/);
});
if ($.grep(types, function(h) { return h.match(/NonRDFSource/)}).length > 0 ){
var description = $.grep(headers, function(h) { return h.match(/rel="describedby"/)});
if (description.length > 0) {
location.href = description[0].substr(1, description[0].indexOf(">") - 1);
return;
}
}
location.href = url;
});
e.preventDefault();
return false;
}
function submitAndFollowLocation() {
var $form = $(this);

0 comments on commit 5e6bb87

Please sign in to comment.