Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Le script insère, à l’intérieur de l’attribut `class` de la balise `body`
* Défaut : `.a42-ac-default-img`
* Adaptée : `.a42-ac-text-img`
* Note : le remplacement s’effectue par un traitement JavaScript.
* **Animation**
* Défaut : `.a42-ac-default-animation`
* Adapté : `.a42-ac-cancel-animation`

Installation
------------
Expand Down Expand Up @@ -87,4 +90,5 @@ Vous pouvez également configurer les paramètres suivants :
* `ModalTitle` : la valeur de la classe du titre de la fenêtre modale ;
* `FormFieldset` : la valeur de la classe des éléments `fieldset` à l’intérieur de la fenêtre modale ;
* `FormFieldsetLegend` : la valeur de la classe des éléments `legend` à l’intérieur de la fenêtre modale ;
* `FormRadio` : la valeur de la classe des `input[type="radio"]` à l’intérieur de la fenêtre modale.
* `FormRadio` : la valeur de la classe des `input[type="radio"]` à l’intérieur de la fenêtre modale;
* `onAnimationChange`: nom d'une fonction de callback appelée au changement d'état du bouton radio d'animation, celle-ci reçoit un paramètre qui peut avoir pour valeur "enabled" ou "disabled".
41 changes: 41 additions & 0 deletions demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<link rel="stylesheet" href="css/accessconfig.css" type="text/css" media="screen" />
<script src="https://cdn.jsdelivr.net/npm/libgif@0.0.3/libgif.min.js"></script>
<script src="js/src/accessconfig.js" type="text/javascript"></script>
<meta charset="UTF-8">

</head>
<body>
<div id="accessconfig" data-accessconfig-buttonname="Accessibility parameters" data-accessconfig-params='{ "Prefix" : "a42-ac", "ContainerClass" : "","ModalCloseButton" : "","ModalTitle" : "","FormFieldset" : "","FormFieldsetLegend" : "","FormRadio" : "", "Animation": true, "onAnimationChange": "onAnimationChange"}' ></div>


<img src="https://media.giphy.com/media/Byana3FscAMGQ/giphy.gif" id="anim" alt="cat drinking from the faucet" />
<script>
// get the default status from the cookie
var canAnimate = (document.cookie.match("a42-ac-animation=a42-ac-cancel-animation") === null);
var supergif = new SuperGif({
gif: document.getElementById("anim"),
auto_play: canAnimate,
});
supergif.load(function(){
console.log('gif loaded');
var el = document.querySelector('.jsgif canvas');
el.setAttribute('aria-label', 'cat drinking from the faucet');
el.setAttribute('role', 'img');
});

// callback function to manage the changes of the status
window.onAnimationChange = function(e) {
console.log("animation "+e);
if (e == "enabled") {
supergif.play();
} else {
supergif.pause();
}
}
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion js/accessconfig.min.js

Large diffs are not rendered by default.

100 changes: 95 additions & 5 deletions js/src/accessconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,54 @@ var AccessConfig = (function() {
en: 'Replace with text',
fr: 'Remplacer par du texte'
}
},
},
/**
Animation
**/

AnimationFieldset: {
//caution : don't change
id: 'animation'
},
AnimationLegend: {
//label
lang: {
en: 'Animations',
fr: 'Animations'
}
},
DefaultAnimationCheckbox:{
id: 'default-animation',
value: 'default-animation',
//caution : don't change
groupName: 'animation',
//label
lang: {
en: 'Default',
fr: 'Défaut'
}
},
NoAnimationCheckbox:{
id: 'cancel-animation',
value: 'cancel-animation',
//caution : don't change
groupName: 'animation',
//label
lang: {
en: 'Remove',
fr: 'Supprimer'
}
}

}
//global
var global = {
mode: null,
cookieName: null,
openObj: null,
imgTab : null,
imgSpan: null
imgSpan: null,
onAnimationChange: null
}

/** Onload */
Expand Down Expand Up @@ -386,6 +425,20 @@ var AccessConfig = (function() {
setImgtab();
setEvent();
}
// Animation feature
if(global.userParams.Animation != false){
global.mode = userPrefix+'-'+config.AnimationFieldset.id;
global.cookieName = 'animation';
if (global.userParams.onAnimationChange != false) {
var fcn = window[global.userParams.onAnimationChange];
if (typeof fcn === "function") {
global.onAnimationChange = fcn;
} else {
console.log('AccessConfig warning : onAnimationChange callback function not found');
}
}
setEvent();
}

}
}
Expand Down Expand Up @@ -597,6 +650,35 @@ var AccessConfig = (function() {
fieldsetContent.appendChild( fieldset );
}

/**
Animation feature
**/

if(global.userParams.Animation != false){
var fieldset = $create({tagName:'fieldset', id:userPrefix+'-'+config.AnimationFieldset.id});
var legend = document.createElement( 'legend' );
var legendText = document.createTextNode( config.AnimationLegend.lang[ langRef ] );
legend.appendChild( legendText );
fieldset.appendChild( legend );

/**Default option**/
var CInput = $create({tagName:'input', type:'radio',checked:'checked', id:userPrefix+'-'+config.DefaultAnimationCheckbox.id, value:userPrefix+'-'+config.DefaultAnimationCheckbox.value, name:userPrefix+'-'+config.DefaultAnimationCheckbox.groupName});
var CLabel = $create({tagName:'label', for:userPrefix+'-'+config.DefaultAnimationCheckbox.id});
var defaultCText = document.createTextNode ( config.DefaultAnimationCheckbox.lang[ langRef ] );
CLabel.appendChild( defaultCText );
fieldset.appendChild( CInput );
fieldset.appendChild( CLabel );

/**Alternative option : kill animation**/
var CInput = $create({tagName:'input', type:'radio',id:userPrefix+'-'+config.NoAnimationCheckbox.id, value:userPrefix+'-'+config.NoAnimationCheckbox.value, name:userPrefix+'-'+config.NoAnimationCheckbox.groupName});
var CLabel = $create({tagName:'label', for:userPrefix+'-'+config.NoAnimationCheckbox.id});
var defaultCText = document.createTextNode ( config.NoAnimationCheckbox.lang[ langRef ] );
CLabel.appendChild( defaultCText );
fieldset.appendChild( CInput );
fieldset.appendChild( CLabel );
fieldsetContent.appendChild( fieldset );
}

/**Set generic class attributes on fieldset, legend and radio**/

allFieldset = div.querySelectorAll( 'fieldset' );
Expand Down Expand Up @@ -684,9 +766,17 @@ var AccessConfig = (function() {
var newClass = obj.getAttribute( 'value' );
obj.setAttribute( 'checked', 'checked' );
var value = obj.getAttribute( 'value' );
if( value === userPrefix+'-'+config.ImageReplacementCheckbox.value){
replaceImg();
}
if( value === userPrefix+'-'+config.ImageReplacementCheckbox.value){
replaceImg();
} else if (value === userPrefix+'-'+config.DefaultAnimationCheckbox.value){
if (global.onAnimationChange !== null) {
global.onAnimationChange("enabled");
}
} else if (value === userPrefix+'-'+config.NoAnimationCheckbox.value){
if (global.onAnimationChange !== null) {
global.onAnimationChange("disabled");
}
}
body.classList.add( newClass );
createCookie(global.cookieName, newClass,'180');
}
Expand Down