LiveWidgetDOM.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /*
  4. * Licensed Materials - Property of IBM
  5. * IBM Business Analytics (C) Copyright IBM Corp. 2019, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. /**
  9. * @class LiveWidgetDOM
  10. * @hideconstructor
  11. * @classdesc Implements LiveWidgetDOMAPI
  12. */
  13. define(['./api/LiveWidgetDOMAPI', 'jquery', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory'], function (LiveWidgetDOMAPI, $, APIFactory) {
  14. var LiveWidgetDOM = function () {
  15. function LiveWidgetDOM(options) {
  16. _classCallCheck(this, LiveWidgetDOM);
  17. this._domNode = options.features.ContentViewDOM.getNode();
  18. this.providers = [];
  19. }
  20. LiveWidgetDOM.prototype.getAPI = function getAPI() {
  21. if (!this._api) {
  22. this._api = APIFactory.createAPI(this, [LiveWidgetDOMAPI]);
  23. }
  24. return this._api;
  25. };
  26. /**
  27. * @implements LiveWidgetDOMAPI.getUIJSON
  28. */
  29. LiveWidgetDOM.prototype.getUIJSON = function getUIJSON() {
  30. var UIJSON = {
  31. widgetIcons: this._retrieveWidgetIcons(),
  32. title: this._retrieveTitle()
  33. };
  34. this.providers.forEach(function (provider) {
  35. Object.assign(UIJSON, provider.getUIJSON());
  36. });
  37. return UIJSON;
  38. };
  39. LiveWidgetDOM.prototype.registerProvider = function registerProvider(providerAPI) {
  40. this.providers.push(providerAPI);
  41. };
  42. LiveWidgetDOM.prototype._retrieveWidgetIcons = function _retrieveWidgetIcons() {
  43. var $widgetIcons = $(this._domNode).find('.widgetHeader div.widgetIcons .dataWidgetIcon');
  44. var icons = [];
  45. if ($widgetIcons.length) {
  46. $widgetIcons.each(function (index, icon) {
  47. var $icon = $(icon);
  48. var title = $icon.attr('title');
  49. var ariaLabel = $icon.attr('aria-label');
  50. if ($icon.is(':visible')) {
  51. if (title && ariaLabel && title === ariaLabel) {
  52. icons.push({
  53. label: title
  54. });
  55. } else icons.push({ label: null });
  56. }
  57. });
  58. }
  59. return icons.length ? icons : undefined;
  60. };
  61. LiveWidgetDOM.prototype._retrieveTitle = function _retrieveTitle() {
  62. var $title = $(this._domNode).find('.widgetHeader .widgetTitle .textArea');
  63. var title = void 0;
  64. if ($title && $title.length && $title.is(':visible')) {
  65. var $textNode = $title.find('span.textFitted p span');
  66. title = {
  67. value: $textNode.text(),
  68. fontSize: $textNode.css('font-size'),
  69. fontFamily: $textNode.css('font-family'),
  70. alignment: $textNode.css('text-align')
  71. };
  72. }
  73. return title;
  74. };
  75. return LiveWidgetDOM;
  76. }();
  77. return LiveWidgetDOM;
  78. });
  79. //# sourceMappingURL=LiveWidgetDOM.js.map