Skip to content

Instantly share code, notes, and snippets.

@LaurensRietveld
Last active August 29, 2015 14:09
Show Gist options
  • Save LaurensRietveld/a65749b9fbe9e6b1dcd5 to your computer and use it in GitHub Desktop.
Save LaurensRietveld/a65749b9fbe9e6b1dcd5 to your computer and use it in GitHub Desktop.
Hide YASQE via URL parameter
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hide YASQE via URL arg</title>
<link href='http://cdn.jsdelivr.net/g/[email protected](yasqe.min.css),[email protected](yasr.min.css)' rel='stylesheet' type='text/css'/>
</head>
<body>
<div id="yasqe"></div>
<div id="yasr"></div>
<script src='http://cdn.jsdelivr.net/yasr/2.0/yasr.bundled.min.js'></script>
<script src='http://cdn.jsdelivr.net/yasqe/2.0/yasqe.bundled.min.js'></script>
<script src="init.js"></script>
</body>
var consumeUrl = function(yasqe, args) {
//change query and endpoint value if there are any
if (args.query) yasqe.setValue(args.query);
if (args.endpoint) yasqe.options.sparql.endpoint = args.endpoint;
if (args.hide) {
document.getElementById("yasqe").style.display = "none";
YASR.defaults.drawOutputSelector = false;
}
//want to consume other arguments such as the request type (POST/GET), or arguments to send to endpoint
//feel free to add them in this function as well.
//as you see, all options you can specify in the default settings, are configurable via yasqe.options as well
//Or, if you want to configure yasqe via a remote url (e.g. a query in some file elsewhere),
//feel free to do so!
//This example uses a cors proxy to access a github file containing a query
if (args.queryRef) $.get(args.queryRef, function(result){yasqe.setValue(result);});
};
var yasqe = YASQE(document.getElementById("yasqe"), {
sparql: {
showQueryButton: true
},
consumeShareLink: consumeUrl
});
var yasr = YASR(document.getElementById("yasr"));
/**
* Set some of the hooks to link YASR and YASQE
*/
yasqe.options.sparql.callbacks.success = function(data, textStatus, xhr) {
yasr.setResponse({response: data, contentType: xhr.getResponseHeader("Content-Type")});
};
yasqe.options.sparql.callbacks.error = function(xhr, textStatus, errorThrown) {
var exceptionMsg = textStatus + " (#" + xhr.status + ")";
if (errorThrown && errorThrown.length) exceptionMsg += ": " + errorThrown;
yasr.setResponse({exception: exceptionMsg});
};
@jneubert
Copy link

Hi Laurens, Thank you very much, that's really elegant! Cheers, Joachim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment