OverlayView.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2014, 2017
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['../../lib/@waca/core-client/js/core-client/ui/core/View', 'jquery', 'underscore', '../../lib/@waca/dashboard-common/dist/utils/DialogBlocker'], function (View, $, _, DialogBlocker) {
  8. var OverlayView = null;
  9. OverlayView = View.extend({
  10. _dHeight: null,
  11. _dWidth: null,
  12. init: function init(options) {
  13. _.extend(this, options);
  14. OverlayView.inherited('init', this, arguments);
  15. if (options.height) {
  16. this._dHeight = options.height;
  17. }
  18. if (options.width) {
  19. this._dWidth = options.width;
  20. }
  21. },
  22. render: function render() {
  23. var _self = this;
  24. var container = DialogBlocker.show(document.body);
  25. this._container = container;
  26. var card = $('<div class="overlay"></div>');
  27. container.append(card);
  28. // adjust size to available window
  29. $(card).width(this._dWidth === null ? $(container).width() * 0.5 : this._dWidth);
  30. $(card).height(this._dHeight === null ? $(container).height() * 0.5 : this._dHeight);
  31. $(container).css('overflow', 'hidden');
  32. // setup animation
  33. var endpos = {
  34. height: $(card).css('height'),
  35. width: $(card).css('width')
  36. };
  37. $(card).css(endpos);
  38. container.fadeIn('fast', function () {}.bind(this));
  39. container.hammer();
  40. DialogBlocker.dialogBlockerClasses.forEach(function (classname) {
  41. // tap outside card area - same as cancel on mobile devices
  42. $('body').on('tap', 'div.' + classname, function () {
  43. _self.cancel();
  44. });
  45. });
  46. // tap inside card should not end things
  47. container.on('tap', 'div.overlay', function (event) {
  48. event.preventDefault();
  49. event.stopImmediatePropagation();
  50. return;
  51. });
  52. var content = this._renderContent();
  53. if (content !== null) {
  54. content.appendTo(card);
  55. }
  56. return this;
  57. },
  58. _renderContent: function _renderContent() {
  59. return null;
  60. },
  61. cancel: function cancel() {
  62. this._container.fadeOut('fast', function () {
  63. this.remove();
  64. }.bind(this));
  65. },
  66. _getPosition: function _getPosition(element) {
  67. var xPosition = 0;
  68. var yPosition = 0;
  69. while (element) {
  70. xPosition += element.offsetLeft - element.scrollLeft + element.clientLeft;
  71. yPosition += element.offsetTop - element.scrollTop + element.clientTop;
  72. element = element.offsetParent;
  73. }
  74. return { x: xPosition, y: yPosition };
  75. },
  76. remove: function remove() {
  77. if (this._container) {
  78. this._container.remove();
  79. this._container = null;
  80. }
  81. return OverlayView.inherited('remove', this, arguments);
  82. }
  83. });
  84. return OverlayView;
  85. });
  86. //# sourceMappingURL=OverlayView.js.map