Created
July 7, 2017 08:03
-
-
Save blivesta/1a34874946e09a4b4bcd5d096fd42e84 to your computer and use it in GitHub Desktop.
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
import checkPls from 'check-pls' | |
import ImagesLoaded from 'imagesLoaded' | |
/* | |
@parentSelectors = [] | |
@selector = '' | |
@className = '' | |
*/ | |
const checkDirection = (parentSelectors, selector, className) => { | |
if (parentSelectors === undefined) return | |
if (className === undefined) className = 'is-imagePortrait' | |
if (selector === undefined) selector = 'img' | |
Array.prototype.forEach.call(parentSelectors, (node) => { | |
const el = document.querySelector(node).querySelectorAll(selector) | |
ImagesLoaded(el, () => { | |
Array.prototype.forEach.call(el, (node) => { | |
const orientation = checkPls(node) | |
if (orientation === 'portrait') { | |
node.classList.add(className) | |
} | |
}) | |
}) | |
}) | |
} | |
export default checkDirection | |
// Usage | |
// checkDirection(['.Entry-mainImage', '.Entry-content'], 'img', 'is-imagePortrait') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment