Skip to content

Commit

Permalink
Merge pull request #589 from fcrepo4/non-rdf-js
Browse files Browse the repository at this point in the history
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
Andrew Woods committed Oct 26, 2014
2 parents 33275b9 + c9847fd commit 5e6bb87
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions fcrepo-http-api/src/main/resources/views/common.js
Expand Up @@ -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);

Expand Down

0 comments on commit 5e6bb87

Please sign in to comment.