diff options
author | Hakim El Hattab <hakim.elhattab@gmail.com> | 2020-03-16 15:18:47 +0100 |
---|---|---|
committer | Hakim El Hattab <hakim.elhattab@gmail.com> | 2020-03-16 15:18:47 +0100 |
commit | 2540712714096f800bb8bcc41ef297f9e16975b4 (patch) | |
tree | 5f886f4b0a38f81ec5bbaef7d8347648315b64ac /js/utils | |
parent | 6ff4e9306c8f7947bd2eafa8f6ef31a83d3e8652 (diff) | |
download | fosdem-2021-minimalism-presentation-2540712714096f800bb8bcc41ef297f9e16975b4.tar fosdem-2021-minimalism-presentation-2540712714096f800bb8bcc41ef297f9e16975b4.tar.gz |
switch old toArray helper to Array.from
Diffstat (limited to 'js/utils')
-rw-r--r-- | js/utils/util.js | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/js/utils/util.js b/js/utils/util.js index e2118e2..f3716b7 100644 --- a/js/utils/util.js +++ b/js/utils/util.js @@ -16,14 +16,11 @@ export const extend = ( a, b ) => { } /** - * Converts the target object to an array. - * - * @param {object} o - * @return {object[]} + * querySelectorAll but returns an Array. */ -export const toArray = ( o ) => { +export const queryAll = ( el, selector ) => { - return Array.prototype.slice.call( o ); + return Array.from( el.querySelectorAll( selector ) ); } @@ -220,4 +217,41 @@ export const getQueryHash = () => { return query; +} + +/** + * Returns the remaining height within the parent of the + * target element. + * + * remaining height = [ configured parent height ] - [ current parent height ] + * + * @param {HTMLElement} element + * @param {number} [height] + */ +export const getRemainingHeight = ( element, height = 0 ) => { + + if( element ) { + let newHeight, oldHeight = element.style.height; + + // Change the .stretch element height to 0 in order find the height of all + // the other elements + element.style.height = '0px'; + + // In Overview mode, the parent (.slide) height is set of 700px. + // Restore it temporarily to its natural height. + element.parentNode.style.height = 'auto'; + + newHeight = height - element.parentNode.offsetHeight; + + // Restore the old height, just in case + element.style.height = oldHeight + 'px'; + + // Clear the parent (.slide) height. .removeProperty works in IE9+ + element.parentNode.style.removeProperty('height'); + + return newHeight; + } + + return height; + }
\ No newline at end of file |