'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: Storytelling (C) Copyright IBM Corp. 2018 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['./PlaceholderView', 'text!./ShortcutPlaceholder.html', '../../../lib/@waca/core-client/js/core-client/utils/Utils', '../../../app/nls/StringResources', 'jquery'], function (BaseClass, Template, Utils, stringResources, $) { var ShortcutPlaceholderView = null; ShortcutPlaceholderView = BaseClass.extend({ templateString: Template, init: function init() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; ShortcutPlaceholderView.inherited('init', this, arguments); this.onVisualizationSelected = options.onVisualizationSelected; this.onTextSelected = options.onTextSelected; this.onImageSelected = options.onImageSelected; this.activeButtons = []; }, render: function render() { this.$el.append(this.dotTemplate({ visLabel: stringResources.get('live_label'), textLabel: stringResources.get('textWidgetLabel'), imageLabel: stringResources.get('imageWidgetLabel') })); var $visualizationBtn = this.$el.find('.visualization'); var $textBtn = this.$el.find('.text'); var $imageBtn = this.$el.find('.image'); Utils.setIcon($visualizationBtn, 'common-visualization'); Utils.setIcon($textBtn, 'dashboard-type-text'); Utils.setIcon($imageBtn, 'dashboard-type-image'); this._eventHandlers([[$visualizationBtn, this.onVisualizationSelected], [$textBtn, this.onTextSelected], [$imageBtn, this.onImageSelected]]); }, _isCompact: function _isCompact() { var maxWidth = 110; return this.$el.width() < maxWidth; }, resize: function resize() { this.$el.find('.shortcut').toggleClass('compact', this._isCompact()); }, _onKeyDown: function _onKeyDown(handler, e) { if (e.which === 32 || e.which === 13) { // enter, space e.preventDefault(); handler(); } }, destroy: function destroy() { this.activeButtons.forEach(function (button) { return button.off(); }); if (this.eventNamespace) { $(document).off(this.eventNamespace); } ShortcutPlaceholderView.inherited('destroy', this, arguments); }, _eventHandlers: function _eventHandlers(buttons) { var _this = this; this.eventNamespace = 'mouseup.' + this.viewId; buttons.forEach(function (pair) { var button = pair[0]; var handler = pair[1].bind(_this); button.on('keydown', _this._onKeyDown.bind(_this, handler)); button.on('primaryaction', handler); button.on('mouseup', function () { return _this.activeHandler = null; }); button.on('mousedown', function (e) { _this.time = e.timeStamp; _this.activeHandler = handler; }); _this.activeButtons.push(button); }); $(document).on(this.eventNamespace, function (e) { if (_this.activeHandler && e.timeStamp - _this.time <= 300) { _this.activeHandler(); } }); } }); return ShortcutPlaceholderView; }); //# sourceMappingURL=ShortcutPlaceholderView.js.map