Commit 6c6b8534 authored by JC Brand's avatar JC Brand

Move functions out to make containing function smaller

parent b31cdd77
...@@ -88,6 +88,25 @@ ...@@ -88,6 +88,25 @@
} }
} }
function calculateElementHeight (el) {
/* Return the height of the passed in DOM element,
* based on the heights of its children.
*/
return _.reduce(
el.children,
(result, child) => result + child.offsetHeight, 0
);
}
function slideOutWrapup (el) {
/* Wrapup function for slideOut. */
el.removeAttribute('data-slider-marker');
el.classList.remove('collapsed');
el.style.overflow = "";
el.style.height = "";
}
var u = {}; var u = {};
// Translation machinery // Translation machinery
...@@ -186,22 +205,12 @@ ...@@ -186,22 +205,12 @@
}; };
u.slideOut = function (el, duration=900) { u.slideOut = function (el, duration=900) {
/* Shows/expands an element by sliding it out of itself. */ /* Shows/expands an element by sliding it out of itself
*
function calculateEndHeight (el) { * Parameters:
return _.reduce( * (HTMLElement) el - The HTML string
el.children, * (Number) duration - The duration amount in milliseconds
(result, child) => result + child.offsetHeight, 0 */
);
}
function wrapup (el) {
el.removeAttribute('data-slider-marker');
el.classList.remove('collapsed');
el.style.overflow = "";
el.style.height = "";
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (_.isNil(el)) { if (_.isNil(el)) {
const err = "Undefined or null element passed into slideOut" const err = "Undefined or null element passed into slideOut"
...@@ -214,10 +223,10 @@ ...@@ -214,10 +223,10 @@
el.removeAttribute('data-slider-marker'); el.removeAttribute('data-slider-marker');
window.clearInterval(interval_marker); window.clearInterval(interval_marker);
} }
const end_height = calculateEndHeight(el); const end_height = calculateElementHeight(el);
if (window.converse_disable_effects) { // Effects are disabled (for tests) if (window.converse_disable_effects) { // Effects are disabled (for tests)
el.style.height = end_height + 'px'; el.style.height = end_height + 'px';
wrapup(el); slideOutWrapup(el);
resolve(); resolve();
return; return;
} }
...@@ -234,9 +243,9 @@ ...@@ -234,9 +243,9 @@
// We recalculate the height to work around an apparent // We recalculate the height to work around an apparent
// browser bug where browsers don't know the correct // browser bug where browsers don't know the correct
// offsetHeight beforehand. // offsetHeight beforehand.
el.style.height = calculateEndHeight(el) + 'px'; el.style.height = calculateElementHeight(el) + 'px';
window.clearInterval(interval_marker); window.clearInterval(interval_marker);
wrapup(el); slideOutWrapup(el);
resolve(); resolve();
} }
}, interval); }, interval);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment