Navigation Menu

Skip to content

Commit

Permalink
Use javascript to detect requests to non-rdf source properties and re…
Browse files Browse the repository at this point in the history
…direct them to the metadata page instead
  • Loading branch information
cbeer committed Oct 24, 2014
1 parent 33275b9 commit c9847fd
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 c9847fd

Please sign in to comment.