page-scroll.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 = (0, utils_1.getCurrentPage)().vanPageScroller, vanPageScroller = _a === void 0 ? [] : _a;
  7. vanPageScroller.forEach(function (scroller) {
  8. if (typeof scroller === 'function') {
  9. // @ts-ignore
  10. scroller(event);
  11. }
  12. });
  13. }
  14. var pageScrollMixin = function (scroller) {
  15. return Behavior({
  16. attached: function () {
  17. var page = (0, utils_1.getCurrentPage)();
  18. if (!(0, utils_1.isDef)(page)) {
  19. return;
  20. }
  21. if (Array.isArray(page.vanPageScroller)) {
  22. page.vanPageScroller.push(scroller.bind(this));
  23. }
  24. else {
  25. page.vanPageScroller =
  26. typeof page.onPageScroll === 'function'
  27. ? [page.onPageScroll.bind(page), scroller.bind(this)]
  28. : [scroller.bind(this)];
  29. }
  30. page.onPageScroll = onPageScroll;
  31. },
  32. detached: function () {
  33. var _a;
  34. var page = (0, utils_1.getCurrentPage)();
  35. if ((0, utils_1.isDef)(page)) {
  36. page.vanPageScroller =
  37. ((_a = page.vanPageScroller) === null || _a === void 0 ? void 0 : _a.filter(function (item) { return item !== scroller; })) || [];
  38. }
  39. },
  40. });
  41. };
  42. exports.pageScrollMixin = pageScrollMixin;