123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2013, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['./Move', '../../../../lib/@waca/dashboard-common/dist/ui/interaction/Utils', 'jquery', '../../../../lib/@waca/core-client/js/core-client/utils/BrowserUtils'], function (BaseMoveClass, utils, $, BrowserUtils) {
- var MoveWidgets = BaseMoveClass.extend({
- init: function init() {
- MoveWidgets.inherited('init', this, arguments);
- this.isIE = BrowserUtils.isIE();
- },
- /**
- * Called by the base class to get the type of the data being drag.
- * Layout drop zone will only accept 'widget' types
- * @returns {String}
- */
- getDragDataType: function getDragDataType() {
- return 'widget';
- },
- /**
- * Called by the base class after a drop has occurred.
- * If we didn't drop in a drop zone, we restore the old position of the nodes
- * @param dropContext
- */
- handleDrop: function handleDrop(dropContext) {
- if (!dropContext.isDropped) {
- this.restoreOriginalPosition();
- }
- if (dropContext.dragObject) {
- $(dropContext.dragObject.data.nodeInfoList[0].node).parent().css('overflow', 'visible');
- }
- },
- /**
- * Restore the selected items to their original location
- *
- */
- restoreOriginalPosition: function restoreOriginalPosition() {
- var nList = this.dropInfo.nodeInfoList;
- var n;
- for (var i = 0, iLen = nList.length; i < iLen; i++) {
- var nodeInfo = nList[i];
- n = nodeInfo.node;
- if (!nodeInfo.oldValues.parent) {
- n.parentNode.removeChild(n);
- } else {
- nodeInfo.oldValues.parent.insertBefore(n, nodeInfo.oldValues.nextSibling);
- n.style.left = nodeInfo.oldValues.left;
- n.style.top = nodeInfo.oldValues.top;
- n.style.height = nodeInfo.oldValues.height;
- n.style.width = nodeInfo.oldValues.width;
- }
- }
- },
- /**
- * Called by the base class once a drag starts
- * to update the drop payload that the drop zone will receive.
- *
- * @param dropInfo
- */
- prepareDropInfo: function prepareDropInfo(dropInfo) {
- // Indicate to the drop zone that we are moving a widget
- dropInfo.operation = 'move';
- },
- /**
- * Called by the start of the dragging operation for every node that is being moved
- * @param {object} n - contains the dom node being dragged
- */
- prepareNodeForMove: function prepareNodeForMove(n) {
- var $n = $(n);
- // Set the height and width in case the CSS height/width is using percentage
- $n.height($n.height());
- $n.width($n.width());
- // Workaround for iOS 13 bug, RTC 299193
- if (!this._isIpadVersion13orGreater()) {
- $n.parent().css('overflow', 'hidden');
- this.getAvatarContainer().append(n);
- }
- return n;
- },
- postNodeForMove: function postNodeForMove(nodes) {
- if (this.isIE) {
- this.emit('moveWidgets:start', {
- 'nodes': nodes
- });
- }
- },
- /**
- * Called by the base class on every move event
- *
- */
- handleMove: function handleMove(nodeInfo, coords, dragContext) {
- // Calculate the drop position within the drop zone.
- var nDropZone = dragContext.dropTargetNode;
- if (nDropZone) {
- var $n = $(nodeInfo.node);
- var offset = void 0;
- // Workaround for iOS 13 bug, RTC 299193
- if (this._isIpadVersion13orGreater()) {
- offset = { left: 0, top: 0 };
- } else {
- offset = dragContext.dropTargetNodeOffset || $(nDropZone).offset();
- }
- var x = Math.round(coords.x - offset.left + nDropZone.scrollLeft);
- var y = Math.round(coords.y - offset.top + nDropZone.scrollTop);
- var bounds = utils.widgetSize($n);
- nodeInfo.dropPosition = {
- x: x,
- y: y,
- height: bounds.height,
- width: bounds.width,
- center_x: x + $n.outerWidth() / 2,
- center_y: y + $n.outerHeight() / 2,
- before: nDropZone === nodeInfo.oldValues.parent ? nodeInfo.oldValues.nextSibling : null
- };
- }
- },
- dragMoveEvent: function dragMoveEvent() {
- MoveWidgets.inherited('dragMoveEvent', this, arguments);
- },
- /**
- * Event handler call after the drag and drop had completed
- */
- dragStopEvent: function dragStopEvent() {
- MoveWidgets.inherited('dragStopEvent', this, arguments);
- if (this.isIE) {
- this.emit('moveWidgets:end', {
- 'nodes': this.getSelectedDomNodes()
- });
- }
- },
- /**
- * Determine if userAgent is an iPad and os version 13+
- * The format of an iOS userAgent is as follows:
- * 'Mozilla/5.0 (iPad; CPU OS 13_2_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
- */
- _isIpadVersion13orGreater: function _isIpadVersion13orGreater() {
- var regExMatch = window.navigator.userAgent.match(/ipad.*os\s((\d+_?){2,3})\s/i);
- var version = regExMatch ? regExMatch[1].split('_') : null;
- return version ? parseInt(version[0], 10) > 12 : false;
- }
- });
- return MoveWidgets;
- });
- //# sourceMappingURL=MoveWidgets.js.map
|