float.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. /**
  6. * @api
  7. * @deprecated since version 2.2.0
  8. */
  9. define([
  10. 'jquery',
  11. 'jquery/ui'
  12. ], function ($) {
  13. 'use strict';
  14. $.widget('mage.float', {
  15. options: {
  16. productOptionsSelector: '#product-options-wrapper'
  17. },
  18. /**
  19. * Bind handlers to scroll event
  20. * @private
  21. */
  22. _create: function () {
  23. $(window).on('scroll', $.proxy(this._setTop, this));
  24. },
  25. /**
  26. * float bundleSummary on windowScroll
  27. * @private
  28. */
  29. _setTop: function () {
  30. var starTop, offset, maxTop, allowedTop;
  31. if (this.element.is(':visible')) {
  32. starTop = $(this.options.productOptionsSelector).offset().top;
  33. offset = $(document).scrollTop();
  34. maxTop = this.element.parent().offset().top;
  35. if (!this.options.top) {
  36. this.options.top = this.element.position().top;
  37. this.element.css('top', this.options.top);
  38. }
  39. if (starTop > offset) {
  40. return false;
  41. }
  42. if (offset < this.options.top) {
  43. offset = this.options.top;
  44. }
  45. allowedTop = this.options.top + offset - starTop;
  46. if (allowedTop < maxTop) {
  47. this.element.css('top', allowedTop);
  48. }
  49. }
  50. }
  51. });
  52. });