Skip to content

Instantly share code, notes, and snippets.

@blivesta
Created July 7, 2017 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blivesta/1a34874946e09a4b4bcd5d096fd42e84 to your computer and use it in GitHub Desktop.
Save blivesta/1a34874946e09a4b4bcd5d096fd42e84 to your computer and use it in GitHub Desktop.
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