123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['./BasePropertyAction'], function (BaseClass) {
- var BaseStylePropertyAction = null;
- BaseStylePropertyAction = BaseClass.extend({
- _getWidgetSize: function _getWidgetSize(style, propertyNodes) {
- var container = propertyNodes[0]._layout.widget ? propertyNodes[0]._layout.widget : propertyNodes[0]._layout;
- var widgetSize = this._getSize(style, container.$el);
- return widgetSize;
- },
- _getWidgetOffset: function _getWidgetOffset(style, propertyNodes) {
- // We need to look at the parent offset and remove it from the widget offset val
- var container = propertyNodes[0]._layout.widget ? propertyNodes[0]._layout.widget : propertyNodes[0]._layout;
- var widgetOffset = this._getOffset(style, container.$el);
- var parentOffset = this._getOffset(style, propertyNodes[0]._layout.parentLayout.$el);
- return widgetOffset - parentOffset;
- },
- _getParentDim: function _getParentDim(style, propertyNodes) {
- var parentSize = this._getSize(style, propertyNodes[0]._layout.parentLayout.$el);
- return parentSize;
- },
- _getSize: function _getSize(style, $el) {
- return style === 'width' ? $el.width() : $el.height();
- },
- _getOffset: function _getOffset(style, $el) {
- var offset = $el.offset();
- return style === 'width' ? offset.left : offset.top;
- },
- _sanitizePercentSizeOnPage: function _sanitizePercentSizeOnPage(value, complimentaryProperty) {
- var sanitizedValue = value;
- sanitizedValue = Math.max(Math.min(100, sanitizedValue), 0); //% sizes need to be between 0 and 100
- var maxValue = 0;
- this.propertyNodes.forEach(function (node) {
- maxValue = Math.max(maxValue, parseFloat(node._layout.model.style[complimentaryProperty]));
- });
- if (maxValue + sanitizedValue > 100) {
- sanitizedValue = 100 - maxValue;
- }
- return sanitizedValue;
- },
- _updateInputProperty: function _updateInputProperty(property, value) {
- this.ignoreOnChange = true; //setValue will trigger onChange again.
- property.setValue(value);
- property.onChangeValueHold = value;
- this.ignoreOnChange = false;
- },
- getUnitsFromValue: function getUnitsFromValue(value) {
- return value.replace(/[\d.-]/g, '');
- },
- getValueString: function getValueString(numericValue, units) {
- return String(Number(numericValue.toFixed(units === 'px' ? 0 : 2))) + ' ' + units;
- },
- changeProperty: function changeProperty(action, id /*, value*/) {
- if (action.ignoreOnChange) {
- action.ignoreOnChange = false;
- return;
- }
- var numericValue = parseFloat(this.getValue());
- if (!isNaN(numericValue)) {
- numericValue = action._processChange.apply(action, [id, numericValue, this.units]);
- var stringValue = action.getValueString(numericValue, this.units);
- action._updateInputProperty(this, stringValue);
- } else {
- action._updateInputProperty(this, this.onChangeValueHold);
- }
- },
- wrapChangeProperty: function wrapChangeProperty() {
- var action = this;
- return function () {
- var args = [action].concat(Array.prototype.slice.call(arguments));
- action.changeProperty.apply(this, args);
- };
- },
- /**
- * Get an arbitrary number of properties from the selected nodes for use in the properties pane. Values are only present if all nodes have the same value and
- * the returned values are formatted properly for use in the properties pane.
- *
- * @param {Object[]} properties - Define the properties to fetch from the selected nodes.
- * @param {Function} properties[].getProp - Function to retrieve the property from a node. Takes the node as a parameter and returns the property value.
- * @param {String} properties[].units - Unit string to be appended to the final property.
- * @param {Boolean} properties[].break - Added during this function. Set to true once this property no longer needs to be checked.
- * @param {*} properties[].value - The final value used to return this property. Blank if not all properties matched.
- */
- _getValuesForProperties: function _getValuesForProperties(properties) {
- var _this = this;
- properties.forEach(function (property) {
- property.value = property.getProp(_this.propertyNodes[0]);
- });
- if (this.propertyNodes.length > 1) {
- var _loop = function _loop(i) {
- var canBreak = true;
- properties.forEach(function (property) {
- if (!property.break) {
- var currentValue = property.getProp(_this.propertyNodes[i]);
- if (currentValue !== property.value) {
- property.value = '';
- property.break = true;
- }
- }
- });
- if (canBreak) {
- return 'break';
- }
- };
- for (var i = 1; i < this.propertyNodes.length; i++) {
- var _ret = _loop(i);
- if (_ret === 'break') break;
- }
- }
- properties.forEach(function (property) {
- if (property.value !== '') {
- property.value = _this.getValueString(parseFloat(property.value), property.units);
- }
- });
- },
- showStyleProperties: function showStyleProperties(node) {
- var parentLayout = node._layout.parentLayout;
- if (parentLayout && parentLayout.model && parentLayout.model.type === 'group') {
- return false;
- }
- return true;
- },
- getProperties: function getProperties() {
- this.propertyNodes = this.selectedNodes;
- }
- });
- return BaseStylePropertyAction;
- });
- //# sourceMappingURL=BaseStylePropertyAction.js.map
|