Skip to content

Instantly share code, notes, and snippets.

View firestar300's full-sized avatar

Milan Ricoul firestar300

View GitHub Profile
@firestar300
firestar300 / fixtures.json
Last active February 28, 2024 17:11
Schema for fixtures in Cypress Omnes Education project
{
"properties": {
"name": {
"description": "The slug name of your site.",
"type": "string",
"minLength": 1
},
"production": {
"description": "The production URL of your site.",
"type": "object",
@firestar300
firestar300 / index.js
Last active May 24, 2022 08:17
Check if WordPress Gutenberg Block Editor is ready
const { select, subscribe } = wp.data;
const closeListener = subscribe( () => {
const isReady = select( 'core/editor' ).__unstableIsEditorReady();
if ( ! isReady ) {
// Editor not ready.
return;
}
// Close the listener as soon as we know we are ready to avoid an infinite loop.
closeListener();
@firestar300
firestar300 / AbstractDomElement.js
Created March 4, 2021 16:56
Transform native YouTube video player into a custom HTML markup
const $ = jQuery
class AbstractDomElement {
constructor(element, options) {
let oldInstance
// provide an explicit spaceName to prevent conflict after minification
// MaClass.nameSpace = 'MaClass'
this.constructor.nameSpace = this.constructor.nameSpace || this.constructor.name
const nameSpace = this.constructor.nameSpace
@firestar300
firestar300 / AbstractDomElement.js
Last active March 4, 2021 10:49
Accessible Tabs
const $ = jQuery
class AbstractDomElement {
constructor(element, options) {
let oldInstance
// provide an explicit spaceName to prevent conflict after minification
// MaClass.nameSpace = 'MaClass'
this.constructor.nameSpace = this.constructor.nameSpace || this.constructor.name
const nameSpace = this.constructor.nameSpace
@firestar300
firestar300 / highlight.js
Created December 18, 2019 10:47
Highlight text
/**
* Escape Regex if string has any symbols
* @param {String} input input string to escape
*/
const escapeRegExp = input => {
if (/\W|[_]/g.test(input)) {
return input.replace(/\W|_/g, '[$&]')
}
return input
/**
* Scroll to animation
* @param {(HTMLElement|Number)} destination Scroll to an specific element or a numerical value
* @param {Number} duration Duration of the animation
* @param {String} easing Easing of the animation
* @param {Number} offset Offset of the scroll
* @param {Function} callback Callback function
*/
const smoothScroll = (destination, duration = 300, easing = 'linear', offset = 0, callback) => {
const easings = {
@firestar300
firestar300 / getSiblings.js
Created February 21, 2019 14:34
get siblings method
export const getSiblings = element => {
// Setup siblings array and get the first sibling
const siblings = []
let sibling = element.parentNode.firstChild
// Loop through each sibling and push to the array
while (sibling) {
if (sibling.nodeType === 1 && sibling !== element) {
siblings.push(sibling)
}
@firestar300
firestar300 / setCookie.js
Created February 4, 2019 10:58
set cookie method
/**
* Set a new cookie
* @param {String} cname Name of the cookie
* @param {String} cvalue Value of the cookie
* @param {Number} exdays Number of days until cookie should expire
*/
export const setCookie = (cname, cvalue, exdays) => {
const d = new Date()
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000))
const expires = `expires=${d.toUTCString()}`
@firestar300
firestar300 / getCookie.js
Created February 4, 2019 10:58
get cookie method
/**
* Get a cookie by cookie name
* @param {String} cname Name of the cookie
*/
export const getCookie = (cname) => {
const name = `${cname}=`
const decodedCookie = decodeURIComponent(document.cookie)
const ca = decodedCookie.split(';')
for(var i = 0; i < ca.length; i++) {
@firestar300
firestar300 / prevAll.js
Last active December 16, 2020 02:05
prevAll method with Vanilla JS
export const prevAll = element => {
const prevElements = []
let prevElement = element.parentNode.firstElementChild
while(prevElement !== element) {
prevElements.push(prevElement)
prevElement = prevElement.nextElementSibling
}
return prevElements