Last active
March 7, 2017 13:24
-
-
Save kaisermann/524acd1aec5f3de8ea11a36ab9d95dad to your computer and use it in GitHub Desktop.
Collection of small javascript utility methods that I made and/or use
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 onceTransitionsEnd = function (node, properties, res) { | |
node.addEventListener('transitionend', (function () { | |
let propertyMatches = 0; | |
const transitionEnded = function (e) { | |
if (properties.indexOf(e.propertyName) >= 0) { | |
propertyMatches++; | |
} | |
if (propertyMatches === properties.length) { | |
this.removeEventListener('transitionend', transitionEnded); | |
res(); | |
} | |
}; | |
return transitionEnded; | |
})()); | |
}; |
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 default callback => { | |
if (document.readyState === 'complete' || | |
(document.readyState !== 'loading' && !document.documentElement.doScroll)) { | |
callback() | |
} else { | |
document.addEventListener('DOMContentLoaded', callback, false) | |
} | |
} |
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
// Returns a function that looks for every node with a 'selector' | |
// and passes it to a 'callback(node)'. | |
export default (selector, callback) => { | |
return function () { | |
const retArray = [] | |
const gridNodes = document.querySelectorAll(selector) | |
for (let i = 0; i < gridNodes.length; i++) { | |
const node = gridNodes[i] | |
if (!node.isControlled) { | |
retArray.push(callback(node) || node) | |
node.isControlled = true | |
} | |
} | |
return retArray | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment