'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2015, 2019 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['../../../../lib/@waca/core-client/js/core-client/ui/core/Class', './NormalizedPosition', './NormalizedSelection', 'jquery', 'underscore'], function (Class, NormalizedPosition, NormalizedSelection, $, _) { /** * Represents a selection from the document model, but with normalized positions within its ranges */ var ContentEditableSelectionManager = Class.extend({ /** * @param {node} contentEditableNode - the node with contenteditable=true * @param {string} editableNodesSelector - a jQuery selector which will identify valid nodes under 'contentEditableNode' that the user can insert * text to, and which the first one should never be deleted */ init: function init(contentEditableNode, editableNodesSelector) { this.node = $(contentEditableNode); this.editableNodesSelector = editableNodesSelector; }, /* * Finds all nodes under this.node which can receive text */ _getEditableNodes: function _getEditableNodes() { return this.node.find(this.editableNodesSelector); }, /* * @param {node} node * @return true iff 'node' can receive text from the user */ _isInEditableNode: function _isInEditableNode(node) { return !!this._getEditableNodes().filter(function (i, n) { return n === node || $.contains(n, node); }).length; }, filterKeypress: function filterKeypress(event) { var mayNeedToBlock = false, shouldBeCursor = false, block = false; if (event.which === 8 /*backspace*/) { mayNeedToBlock = true; shouldBeCursor = true; } else if (event.ctrlKey || event.metaKey) { /* ctrl-s, ctrl-z, ctrl-y*/ block = event.which === 83 || event.which === 90 || event.which === 89; } if (mayNeedToBlock) { var selection = new NormalizedSelection(document.getSelection()); var startPosition; if ($(this.node[0]).find('.note-editable')) { startPosition = new NormalizedPosition($(this.node[0]).find('.note-editable').get(0), 0); } else { startPosition = new NormalizedPosition(this.node[0], 0); } block = _.find(selection.ranges, function (range) { return range.isCursor() === shouldBeCursor && range.start.equals(startPosition); }); } if (block) { event.preventDefault(); } } }); return ContentEditableSelectionManager; }); //# sourceMappingURL=ContentEditableSelectionManager.js.map