page-scroll.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. exports.pageScrollMixin = void 0;
  4. var utils_1 = require('../common/utils');
  5. function onPageScroll(event) {
  6. var _a = utils_1.getCurrentPage().vanPageScroller,
  7. vanPageScroller = _a === void 0 ? [] : _a;
  8. vanPageScroller.forEach(function (scroller) {
  9. if (typeof scroller === 'function') {
  10. // @ts-ignore
  11. scroller(event);
  12. }
  13. });
  14. }
  15. var pageScrollMixin = function (scroller) {
  16. return Behavior({
  17. attached: function () {
  18. var page = utils_1.getCurrentPage();
  19. if (Array.isArray(page.vanPageScroller)) {
  20. page.vanPageScroller.push(scroller.bind(this));
  21. } else {
  22. page.vanPageScroller =
  23. typeof page.onPageScroll === 'function'
  24. ? [page.onPageScroll.bind(page), scroller.bind(this)]
  25. : [scroller.bind(this)];
  26. }
  27. page.onPageScroll = onPageScroll;
  28. },
  29. detached: function () {
  30. var _a;
  31. var page = utils_1.getCurrentPage();
  32. if (!utils_1.isDef(page)) {
  33. page.vanPageScroller =
  34. ((_a = page.vanPageScroller) === null || _a === void 0
  35. ? void 0
  36. : _a.filter(function (item) {
  37. return item !== scroller;
  38. })) || [];
  39. }
  40. },
  41. });
  42. };
  43. exports.pageScrollMixin = pageScrollMixin;