DialogBlocker.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI
  5. * (C) Copyright IBM Corp. 2019
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. /**
  9. * This helper is needed to work past inconsistencies in dialog blocker class names between our legacy code
  10. * and the ba-ui-toolkit dialog blocker which is triggered from some dialogs and interactions
  11. */
  12. define(['jquery'], function ($) {
  13. return {
  14. dialogBlockerClasses: ['dialogBlocker', 'ba-common-dialog__blockerCell'],
  15. /**
  16. * Check if any dialog blockers are open
  17. * @returns {Boolean} checks if the document has any active elements with any dialog blocker class
  18. */
  19. isShowingDialogBlocker: function isShowingDialogBlocker() {
  20. return this.dialogBlockerClasses.some(function (className) {
  21. return document.getElementsByClassName(className).length > 0;
  22. });
  23. },
  24. /**
  25. * @returns {DOMElement} blocker
  26. */
  27. createBlocker: function createBlocker() {
  28. var $blocker = document.createElement('div');
  29. $blocker.classList.add('dialogBlocker');
  30. $blocker.setAttribute('tabindex', '-1');
  31. return $blocker;
  32. },
  33. /**
  34. * Same as createBlocker but wraps the returned ele in a jq wrapper for api consistency in core
  35. * @returns {jqElement}
  36. */
  37. getJqBlocker: function getJqBlocker() {
  38. return this._wrapEleInJq(this.createBlocker());
  39. },
  40. /**
  41. * This is a non declarative convenience function to keep the API in core and its use of jq consistent
  42. * @param {*} parent jqEle or dom ele
  43. * @param {*} $blocker (optional) jqEle or dom ele
  44. * @returns {jqElement} a wrapped blocker element ref
  45. */
  46. show: function show(parent, $blocker) {
  47. if (!$blocker) {
  48. $blocker = this.createBlocker();
  49. } else if ($blocker.length > 0) {
  50. $blocker = $blocker[0];
  51. }
  52. parent = parent.length ? parent[0] : parent; // convert jq eles to normal dom eles
  53. parent.appendChild($blocker);
  54. return this._wrapEleInJq($blocker);
  55. },
  56. _wrapEleInJq: function _wrapEleInJq(domEle) {
  57. return $(domEle);
  58. }
  59. };
  60. });
  61. //# sourceMappingURL=DialogBlocker.js.map