popup-window.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'jquery',
  7. 'jquery/ui'
  8. ], function ($) {
  9. 'use strict';
  10. $.widget('mage.popupWindow', {
  11. options: {
  12. centerBrowser: 0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left
  13. centerScreen: 0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
  14. height: 500, // sets the height in pixels of the window.
  15. left: 0, // left position when the window appears.
  16. location: 0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
  17. menubar: 0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
  18. resizable: 0, // whether the window can be resized {1 (YES) or 0 (NO)}.
  19. scrollbars: 0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
  20. status: 0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
  21. width: 500, // sets the width in pixels of the window.
  22. windowName: null, // name of window set from the name attribute of the element that invokes the click
  23. windowURL: null, // url used for the popup
  24. top: 0, // top position when the window appears.
  25. toolbar: 0 // determines whether a toolbar is displayed {1 (YES) or 0 (NO)}.
  26. },
  27. /**
  28. * @private
  29. */
  30. _create: function () {
  31. this.element.on('click', $.proxy(this._openPopupWindow, this));
  32. },
  33. /**
  34. * @param {jQuery.Event} event
  35. * @private
  36. */
  37. _openPopupWindow: function (event) {
  38. var element = $(event.target),
  39. settings = this.options,
  40. windowFeatures =
  41. 'height=' + settings.height +
  42. ',width=' + settings.width +
  43. ',toolbar=' + settings.toolbar +
  44. ',scrollbars=' + settings.scrollbars +
  45. ',status=' + settings.status +
  46. ',resizable=' + settings.resizable +
  47. ',location=' + settings.location +
  48. ',menuBar=' + settings.menubar,
  49. centeredX,
  50. centeredY;
  51. settings.windowName = settings.windowName || element.attr('name');
  52. settings.windowURL = settings.windowURL || element.attr('href');
  53. if (settings.centerBrowser) {
  54. centeredY = window.screenY + ((window.outerHeight / 2 - settings.height / 2));
  55. centeredX = window.screenX + ((window.outerWidth / 2 - settings.width / 2));
  56. windowFeatures += ',left=' + centeredX + ',top=' + centeredY;
  57. } else if (settings.centerScreen) {
  58. centeredY = (screen.height - settings.height) / 2;
  59. centeredX = (screen.width - settings.width) / 2;
  60. windowFeatures += ',left=' + centeredX + ',top=' + centeredY;
  61. } else {
  62. windowFeatures += ',left=' + settings.left + ',top=' + settings.top;
  63. }
  64. window.open(settings.windowURL, settings.windowName, windowFeatures).focus();
  65. event.preventDefault();
  66. }
  67. });
  68. return $.mage.popupWindow;
  69. });