page-scroll.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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, 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 = utils_1.getCurrentPage();
  18. if (Array.isArray(page.vanPageScroller)) {
  19. page.vanPageScroller.push(scroller.bind(this));
  20. }
  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 ? void 0 : _a.filter(function (item) { return item !== scroller; })) || [];
  35. }
  36. },
  37. });
  38. };
  39. exports.pageScrollMixin = pageScrollMixin;