Skip to content

Instantly share code, notes, and snippets.

View EmmanuelBeziat's full-sized avatar
🎮
Leave me alone!

Emmanuel Béziat EmmanuelBeziat

🎮
Leave me alone!
View GitHub Profile
@EmmanuelBeziat
EmmanuelBeziat / countries.json
Created September 12, 2022 01:50
Countries indicators and iso
[
{
"iso": "af",
"tel": "93",
"name": "Afghanistan"
},
{
"iso": "za",
"tel": "27",
"name": "Afrique du sud"
@EmmanuelBeziat
EmmanuelBeziat / switch.js
Last active May 6, 2022 03:40
Add "switch" method to element.classList property
Object.defineProperty(DOMTokenList.prototype, 'switch', {
writable: false,
enumerable: false,
configurable: false,
value (...list) {
const el = this
const matchedClass = list.filter(cls => el.contains(cls))
if (!matchedClass.length) {
@EmmanuelBeziat
EmmanuelBeziat / arrays.js
Created July 4, 2021 16:45
JS Arrays Cheatsheet
/** Static properties **/
// Creates an array from a String
// Output ['🍎', '🍌', '🍇']
// https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/from
Array.from('🍎🍌🍇')
// Check for an array
// Output true
// https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
@EmmanuelBeziat
EmmanuelBeziat / checkboxes.js
Last active November 27, 2020 18:31
Limit checkboxes
const setCheckboxLimit = (list, limit, warning = false) => {
if (!list) return
const checkboxes = list.querySelectorAll('input[type="checkbox"]')
if (!checkboxes.length) return
checkboxes.forEach(checkbox => checkbox.addEventListener('click', event => {
const checkedChecks = list.querySelectorAll('input[type="checkbox"]:checked')
if (checkedChecks.length >= limit + 1) {
@EmmanuelBeziat
EmmanuelBeziat / oneliners.js
Last active April 1, 2019 19:33 — forked from mikowl/oneliners.js
👑 Awesome one-liners you might find useful while coding.
const headings = [ ... document.querySelectorAll('h1') ]
[{id: 1}, {id: 2}].map(x => x.id)
// [1,2]
// By @coderitual
// https://twitter.com/coderitual/status/1112297299307384833
// Remove any duplicates from an array of primitives.
@EmmanuelBeziat
EmmanuelBeziat / compare.js
Created March 24, 2019 02:01
Return differences between javascript objects's parameters' values
function compare (object1, object2) {
let result = []
Object.keys(object1).forEach(key => {
if (object1[key] !== object2[key]) {
result.push(object2[key])
}
})
return result
@EmmanuelBeziat
EmmanuelBeziat / gesture.js
Created October 2, 2018 12:15
Swipe left / right for mobile and desktop
el.addEventListener('touchstart', event => { start(event.touches[0].clientX, event.touches[0].clientY) }, false)
el.addEventListener('touchmove', event => { swipe(event.touches[0].clientX, event.touches[0].clientY) }, false)
el.addEventListener('mousedown', event => { start(event.clientX, event.clientY) }, false)
el.addEventListener('mousemove', event => { swipe(event.clientX, event.clientY) }, false)
let xDown = null
let yDown = null
function start (x, y) {
xDown = x
@EmmanuelBeziat
EmmanuelBeziat / functions.php
Created July 23, 2018 14:42
WordPress Walker — move custom menu class from list item to link
<?php
class Social_Walker extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth, $args) {
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$link_class = $classes[0];
$link_target = $item->target == '' ? '' : 'target="'.$item->target.'"';
unset($classes[0]);
$output .= '<li class="'. join($classes, ' ') .'">'
@EmmanuelBeziat
EmmanuelBeziat / gist:eb659b6f316001b99b92782e36ffe58a
Created January 27, 2017 04:01
Get siblings of an element in plain JS
function getSiblings(element) {
Array.prototype.filter.call(element.parentNode.children, function (child) {
return child !== element;
});
}
/*!
*
* Version :
* Emmanuel B. (www.emmanuelbeziat.com)
* https://github.com/EmmanuelBeziat/
**/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.