Commit 316ab164 authored by rg's avatar rg

Création

parent 7105ae63
# tools
# toolkit
Quelques outils utiles
Tous les outils et petites fonctions utiles quelque soit le langage
\ No newline at end of file
## bash
### SelectMenu
Permet d'effectuer une selection visuelle parmi une liste d'éléments.
## Javascript
### RGPWhat
Permet l'affichage de Popin de consentement RGPD. (bêta)
# selectmenu
Permet de créer un menu de navigation par touche fléchées.
Options:
-ro : retourne l'offset de la selection en partant de 1, plutot que le libellé de la selection
-s<offset>: préselectionne un élément. Par défaut 1. Pour ne rien préselectionner, entrer -s0
selectmenu() {
local POS=0;
local RET=0;
for var in $@; do
if [[ "$var" =~ ^-s([0-9]+)$ ]]; then POS=$[${BASH_REMATCH[1]}-1]; shift; fi
if [[ "$var" =~ ^-ro$ ]]; then RET=1; shift; fi
done
local NB_ITEMS=$#;
while true;
do
local i=0;
for item in $@;
do
local STYLE="\x1b[0m";
if [ $((i++)) -eq $POS ]; then STYLE="\e[7m"; fi
echo -en "$STYLE${item}\x1b[0m\n";
done
read -rsn1 key;
case "$key" in
$'\x1b') # Arrow hors escape
read -rsn2 -t0.1 key;
if [ "$key" = $'[A' ] && [ $POS -ne 0 ]; then POS=$[$POS-1]; fi
if [ "$key" = $'[B' ] && [ $POS -lt $[$NB_ITEMS-1] ]; then POS=$[$POS+1]; fi
if [ "$key" = "" ]; then return 1; fi
;;
"") # Enter
if [ $POS -ge 0 ]; then ((POS++)); break; fi
;;
esac
echo -e "\033["$[$NB_ITEMS+1]"A";
done
[[ $RET -eq 0 ]] && echo ${!POS} || echo $POS;
}
/*!
* jQuery InfoCookie becomes RgpWhat Plugin v2.0 for RGPD consent
*
* Copyright 2015 - 2020 by sreg
* Released under the MIT license
* Options:
* - class: set class for the cookie notice bar (default "cookie-notice")
* - LoadCss: load default css rgpwhat/rgpwhat.css. Maybe false to load nothing.
* - delay: set delay before to appear (default 1000ms)
* - cookieDuration: define the max duration (in month) before to appear a new bar if it was first accepted (default 12 months)
* - cookieName: the cookie name to remember the acceptation (default "rgpwhat")
* - position: "top" or "bottom" -> defines the position of the bar at the top of the screen or at the bottom (default "top")
* - fixed: boolean (default true). If false, css position = "relative". If true css position = "absolute"
* - validateFollow: true/false -> is equal to a click on "ok" on first document click (default true). A false value specifies a click to button "ok" as mandatory
* - consent: array of specifics cookies (optional)
* - buttons : default="ok|notOk|choice" -> displayed buttons
* - locale: json to change default text
* ex: var locale={
* 'ok': 'Ok',
* 'notOk': 'Interdire',
* 'choice': 'Choisir mes cookies',
* 'acceptAll': 'Autoriser tous les cookies',
* 'denyAll': 'Interdire tous les cookies',
* 'accept': 'Autoriser',
* 'deny': 'Interdire',
* 'close': 'X'
* };
*
* Example: (Attention to mandatory tags)
* - $.rgpWhat('Les cookies assurent le bon fonctionnement de nos services. En utilisant ces derniers, vous acceptez l\'utilisation des cookies. <a href="" target="_blank">En savoir plus</a>.',
* {
* class: "rgpwhat"
* "consent": [
* {
* title: "hotjar", //Mandatory
* description: "Service de feedback", //Usefull
* key: "hotjar", //Mandatory
* callbackAccepted: function() { //Optionnal
* alert('callback accept hotjar');
* },
* callbackDenied: function() { //Optionnal
* alert('callback denied hotjar');
* }
* },
* {
* title: "Google Analytics",
* description: "Service google de statistiques de trafic",
* key: "ga",
* callbackAccepted: function() {
* alert('callback accept ga');
* },
* callbackDenied: function() {
* alert('callback denied ga');
* }
* }
* ],
* "position": "top",
* "fixed": false
* });
*
* Css sample :
*
* .rgpwhat {background-color: rgba(33,33,33,0.9); color: white; text-align: center; line-height: 2.5em; padding: 2px; vertical-align: middle; position: relative; top: 0;}
* .rgpwhat .consent-list {background-color: black; padding: 1em; width: 100%;}
* .rgpwhat .consent-list .all-cookies-choice {width: 50%; margin: auto;}
* .rgpwhat .consent-list .cookie-choice {width: 50%; margin: auto; display: flex; flex-direction: row; align-items: center; border-bottom: 1px solid grey;}
* .rgpwhat .consent-list .cookie-choice .explanations {text-align: left; flex: 2;}
* .rgpwhat .consent-list .cookie-choice .explanations .title {font-size: 1.5em; font-weight: bold;}
* .rgpwhat .consent-list .cookie-choice .explanations .description {line-height: 1em;}
* .rgpwhat .consent-list .cookie-choice .buttons {flex: 1; text-align: right;}
* .rgpwhat .consent-list .cookie-choice .buttons .accept, .rgpwhat .consent-list .cookie-choice .buttons .deny {color: white;}
* .rgpwhat .consent-list button {background-color: #f00; line-height: 2.2em; margin-top: 2px; opacity: .9;}
* .rgpwhat .consent-list button:hover {opacity: 1;}
* .rgpwhat .consent-list button.selected {background-color: #1BD2A4;}
* .rgpwhat button, .rgpwhat input[type=button] {color: white; background-color: #1BD2A4; border-radius: 5px; border: 0; padding: 0 20px; margin-left: 10px;}
*
* Change since v1
* - authorize cookieDuration to 0
* Since v2
* - Add multi-cookie choice
* - Add callbacks
* - Add locales
*/
(function($) {
$.infoCookie=$.rgpWhat=function(text,options) {
var className="rgpwhat"