123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: BI Dashboard
- *| (C) Copyright IBM Corp. 2018
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['underscore', '../../../lib/@waca/upgrades/UpgradeBase', './utils/WidgetUpgradeUtils'], function (_, UpgradeBase, WidgetUpgradeUtils) {
- var TEXT_WIDGET_TYPE = 'text';
- var TextWidgetResponsiveUpgradeHelper = function (_UpgradeBase) {
- _inherits(TextWidgetResponsiveUpgradeHelper, _UpgradeBase);
- function TextWidgetResponsiveUpgradeHelper() {
- _classCallCheck(this, TextWidgetResponsiveUpgradeHelper);
- var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this));
- _this.VERSION = 1022;
- return _this;
- }
- /**
- * Perform upgrades for TextWidgets that might have been saved in a state where it was both isResponsive
- * and had font-sizes set for inner <span> elements
- *
- * @param {object} spec - spec to perform upgrade on
- *
- * @return {Promise} Promise to be resolved when upgrade performed
- */
- TextWidgetResponsiveUpgradeHelper.prototype.up = function up(spec) {
- if (!spec) {
- return Promise.resolve(spec);
- }
- if (!WidgetUpgradeUtils.specHasWidgets(spec)) {
- return Promise.resolve(spec);
- }
- return this._upgradeWidgets(spec);
- };
- TextWidgetResponsiveUpgradeHelper.prototype.down = function down(spec) {
- // no downgrade at this time; return as is:
- // we don't save backups of specs
- return Promise.resolve(spec);
- };
- TextWidgetResponsiveUpgradeHelper.prototype._upgradeWidgets = function _upgradeWidgets(spec) {
- var _this2 = this;
- try {
- _.each(spec.widgets, function (model) {
- if (model.type === TEXT_WIDGET_TYPE) {
- _this2._upgradeTextWidget(model);
- }
- });
- return Promise.resolve(spec);
- } catch (error) {
- throw error;
- }
- };
- TextWidgetResponsiveUpgradeHelper.prototype._upgradeTextWidget = function _upgradeTextWidget(model) {
- if (!model.content) {
- return;
- }
- var table = model.content.translationTable;
- if (table) {
- for (var lang in table) {
- table[lang] = this._upgradeContent(table[lang], model.isResponsive);
- }
- } else if (typeof model.content === 'string') {
- model.content = this._upgradeContent(model.content, model.isResponsive);
- }
- };
- TextWidgetResponsiveUpgradeHelper.prototype._upgradeContent = function _upgradeContent(content, isResponsive) {
- if (isResponsive) {
- content = content.replace(/\s*rt_fontSize[0-9]*/gi, '');
- content = content.replace(/\s*font-size\s*:[^;]*;*/gi, '');
- }
- if (content.indexOf('contenteditable="true"') !== -1) {
- content = content.replace(/\s*contenteditable="true"/gi, '');
- }
- if (content.indexOf('style=""') !== -1) {
- content = content.replace(/\s*style=""/gi, '');
- }
- return content;
- };
- return TextWidgetResponsiveUpgradeHelper;
- }(UpgradeBase);
- return new TextWidgetResponsiveUpgradeHelper();
- });
- //# sourceMappingURL=TextWidgetResponsiveUpgradeHelper.js.map
|