123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- '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
|