'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: Storytelling * (C) Copyright IBM Corp. 2014, 2018 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['baglass/core-client/js/core-client/ui/core/View'], function (View) { var AutoHidingControl = View.extend({ autohide: null, init: function init(options) { AutoHidingControl.inherited('init', this, arguments); options = options || {}; this.autohide = options.autohide || 6000; this.startHidden = options.startHidden || false; this.hidden = true; }, render: function render() { var _this = this; return this._renderContent().then(function () { _this.$el.on('mouseenter', _this._cancelAutoHide.bind(_this)); _this.$el.on('mouseleave', _this._setAutoHide.bind(_this)); _this.hidden = false; if (_this.startHidden) { _this.hide({ duration: 0 }); } else { _this.show({ duration: 0 }); } }); }, destroy: function destroy() { var _this2 = this; this._cancelAutoHide(); return this.hide().then(function () { _this2.remove(); }); }, toggle: function toggle() { if (this.hidden) { this.show(); } else { this.hide(); } }, _cancelAutoHide: function _cancelAutoHide() { if (this.timeout) { clearTimeout(this.timeout); } this.timeout = null; }, _setAutoHide: function _setAutoHide() { this.timeout = setTimeout(this.hide.bind(this), this.autohide); }, show: function show() { var _this3 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return Promise.delay(options.delay || 0).then(function () { return _this3._show(options).then(function () { _this3.$el.attr('aria-hidden', 'false'); _this3.hidden = false; _this3._cancelAutoHide(); _this3._setAutoHide(); }); }); }, hide: function hide() { var _this4 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; if (this.hidden) { return Promise.resolve(); } return this._hide(options).then(function () { _this4.$el.attr('aria-hidden', 'true'); _this4.hidden = true; }); }, // Override these! _renderContent: function _renderContent() { return Promise.resolve(); }, // _show is expected to return a promise that resolves when it is done showing. _show: function _show() { return Promise.resolve(); }, // _hide is expected to return a promise that resolves when it is done hiding. _hide: function _hide() { return Promise.resolve(); } }); return AutoHidingControl; }); //# sourceMappingURL=AutoHidingControl.js.map