* Hide the module. * @param {Module} module The module to hide. * @param {number} speed The speed of the hide animation. * @param {() => void} callback Called when the animation is done. * @param {object} [options] Optional settings for the hide method.
(module, speed, callback, options = {})
| 242 | * @param {object} [options] Optional settings for the hide method. |
| 243 | */ |
| 244 | function _hideModule (module, speed, callback, options = {}) { |
| 245 | // set lockString if set in options. |
| 246 | if (options.lockString) { |
| 247 | if (module.lockStrings.indexOf(options.lockString) === -1) { |
| 248 | module.lockStrings.push(options.lockString); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | const moduleWrapper = document.getElementById(module.identifier); |
| 253 | if (moduleWrapper !== null) { |
| 254 | clearTimeout(module.showHideTimer); |
| 255 | // reset all animations if needed |
| 256 | if (module.hasAnimateOut) { |
| 257 | removeAnimateCSS(module.identifier, module.hasAnimateOut); |
| 258 | Log.debug(`${module.identifier} Force remove animateOut (in hide): ${module.hasAnimateOut}`); |
| 259 | module.hasAnimateOut = false; |
| 260 | } |
| 261 | if (module.hasAnimateIn) { |
| 262 | removeAnimateCSS(module.identifier, module.hasAnimateIn); |
| 263 | Log.debug(`${module.identifier} Force remove animateIn (in hide): ${module.hasAnimateIn}`); |
| 264 | module.hasAnimateIn = false; |
| 265 | } |
| 266 | // haveAnimateName for verify if we are using AnimateCSS library |
| 267 | // we check AnimateCSSOut Array for validate it |
| 268 | // and finally return the animate name or `null` (for default MM² animation) |
| 269 | let haveAnimateName = null; |
| 270 | // check if have valid animateOut in module definition (module.data.animateOut) |
| 271 | if (module.data.animateOut && AnimateCSSOut.indexOf(module.data.animateOut) !== -1) haveAnimateName = module.data.animateOut; |
| 272 | // can't be override with options.animate |
| 273 | else if (options.animate && AnimateCSSOut.indexOf(options.animate) !== -1) haveAnimateName = options.animate; |
| 274 | |
| 275 | if (haveAnimateName) { |
| 276 | // with AnimateCSS |
| 277 | Log.debug(`${module.identifier} Has animateOut: ${haveAnimateName}`); |
| 278 | module.hasAnimateOut = haveAnimateName; |
| 279 | addAnimateCSS(module.identifier, haveAnimateName, speed / 1000); |
| 280 | module.showHideTimer = setTimeout(function () { |
| 281 | removeAnimateCSS(module.identifier, haveAnimateName); |
| 282 | Log.debug(`${module.identifier} Remove animateOut: ${module.hasAnimateOut}`); |
| 283 | // AnimateCSS is now done |
| 284 | moduleWrapper.style.opacity = 0; |
| 285 | moduleWrapper.classList.add("hidden"); |
| 286 | moduleWrapper.style.position = "fixed"; |
| 287 | module.hasAnimateOut = false; |
| 288 | |
| 289 | updateWrapperStates(); |
| 290 | if (typeof callback === "function") { |
| 291 | callback(); |
| 292 | } |
| 293 | }, speed); |
| 294 | } else { |
| 295 | // default MM² Animate |
| 296 | moduleWrapper.style.transition = `opacity ${speed / 1000}s`; |
| 297 | moduleWrapper.style.opacity = 0; |
| 298 | moduleWrapper.classList.add("hidden"); |
| 299 | module.showHideTimer = setTimeout(function () { |
| 300 | // To not take up any space, we just make the position absolute. |
| 301 | // since it's fade out anyway, we can see it lay above or |
no test coverage detected