Skip to content

Instantly share code, notes, and snippets.

@gus3000
Created February 5, 2018 15:50
Show Gist options
  • Save gus3000/9779130d3c0ef5f1748b263bfb64721f to your computer and use it in GitHub Desktop.
Save gus3000/9779130d3c0ef5f1748b263bfb64721f to your computer and use it in GitHub Desktop.
// ici on pointe vers le serveur d'integration, qui a des fonctionnalites plus a jour.
// a terme, on pourra eventuellement pointer vers le serveur de production, a savoir 'h.projet-episteme.org'
let HYPOTHESIS_SERVER = 'h.int.projet-episteme.org';
// a changer pour l'id du bouton de changement
let BUTTON_ID = 'hypothesis-reload-button';
//cette fonction ne te sera probablement pas utile, j'imagine que tu as deja un bouton cree quelque part
function createButton() {
var container = document.getElementsByClassName ('site-branding-text')[0];
var button = document.createElement('button');
button.setAttribute('type','button');
button.setAttribute('id', 'hypothesis-reload-button');
button.innerHTML = 'Load Hyperthesis';
container.appendChild(button);
}
createButton(); // s'il y a déjà un bouton, commenter cette ligne
// debut des fonctions interessantes
function toggleAnnotator()
{
let currentValue = localStorage.getItem('annotator');
if(currentValue == 'off' || currentValue == null)
{
loadHypothesis();
localStorage.setItem('annotator','on');
}
else
{
unloadHypothesis();
localStorage.setItem('annotator','off');
}
}
function unloadHypothesis() {
var appLinkEl =
document.querySelector('link[type=\'application/annotator+html\']');
appLinkEl.dispatchEvent(new Event('destroy'));
};
function loadHypothesis() {
var embedScript = document.createElement('script');
embedScript.setAttribute('src','https://'+ HYPOTHESIS_SERVER + '/app/embed.js');
document.body.appendChild(embedScript);
};
function buttonAction() {
toggleAnnotator();
// si tu veux rajouter des changements visuels lors du clic sur le bouton (autre que l'apparition de l'onglet Hypothesis), je pense qu'ici c'est pas mal.
}
if(localStorage.getItem('annotator') == 'on')
{
loadHypothesis();
}
document.getElementById(BUTTON_ID).onclick = buttonAction;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment