This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get element offset | |
* @param {Element} obj | |
* @return {Boolean} | |
*/ | |
export function getElementViewportOffset (element) { | |
let left = element.offsetLeft, | |
top = element.offsetTop, | |
elementParent = element.parentNode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global define, Image */ | |
(function (root, factory) { | |
if (typeof define === 'function' && define.amd) { | |
define([], function () { | |
return factory() | |
}) | |
} else if (typeof exports === 'object') { | |
module.exports = factory() | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* If js doesnt load or just before it does: hide element for 2 seconds. */ | |
.no-js .u-showIfNoJs { | |
animation: showAfterLong 2000ms; | |
} | |
/* Hide when js loads and remove animation */ | |
.js .u-showIfNoJs { | |
animation: none; | |
display: none; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getMousePosition (e) { | |
let posX = 0 | |
let posY = 0 | |
if (!e) { | |
e = window.event | |
} | |
if (e.pageX || e.pageY) { | |
posX = e.pageX |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get a random int between two values | |
* @param {Int} min | |
* @param {Int} max | |
* @return {Int} | |
*/ | |
export function randomBetween(min = 0, max = 0) { | |
return Math.floor(Math.random() * (max - min + 1) + min) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get scroll position | |
* @param {Object} rootElement | |
* @return {Object} | |
*/ | |
export function getScrollPosition (rootElement) { | |
return { | |
y: rootElement ? rootElement.scrollTop : window.pageYOffset, | |
x: rootElement ? rootElement.scrollLeft : window.pageXOffset | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function creates post duplicate as a draft and redirects then to the edit post screen | |
*/ | |
function duplicate_post_as_draft() { | |
global $wpdb; | |
if (!(isset($_GET['post']) || isset($_POST['post']) || (isset($_REQUEST['action']) && 'duplicate_post_as_draft' == $_REQUEST['action']))) { | |
wp_die('No post to duplicate has been supplied!'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Demo: | |
http://codepen.io/vincentorback/pen/ZLLJbB | |
*/ | |
export function objectFit (el) { | |
let objectElReplacement = `<div | |
class="${el.classList}" | |
style=" | |
background-image:url(${el.getAttribute('src')}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const targetEl = document.querySelector('.js-target') | |
const hideMouse = false | |
const idleTime = 3000 | |
let idleMouseTimer | |
targetEl.addEventListener('mousemove', (e) => { | |
if (!hideMouse) { | |
targetEl.style.cursor = '' | |
clearTimeout(idleMouseTimer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function randomHex() { | |
return '#' + (Math.random() * 0xFFFFFF << 0).toString(16) | |
} |