index.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 8);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 8:
  90. /***/ (function(module, exports, __webpack_require__) {
  91. "use strict";
  92. var selectQuery = __webpack_require__(9);
  93. var target = '.weui-sticky';
  94. Component({
  95. options: {
  96. addGlobalClass: true,
  97. pureDataPattern: /^_/,
  98. multipleSlots: true
  99. },
  100. behaviors: [selectQuery],
  101. properties: {
  102. offsetTop: {
  103. type: Number,
  104. value: 0
  105. },
  106. zIndex: {
  107. type: Number,
  108. value: 99
  109. },
  110. disabled: {
  111. type: Boolean,
  112. value: false
  113. },
  114. container: {
  115. type: null
  116. }
  117. },
  118. data: {
  119. fixed: false,
  120. height: 0,
  121. _attached: false,
  122. _containerHeight: 0
  123. },
  124. observers: {
  125. disabled: function disabled(newVal) {
  126. if (!this._attached) return;
  127. newVal ? this.disconnectObserver() : this.initObserver();
  128. },
  129. container: function container(newVal) {
  130. if (typeof newVal !== 'function' || !this.data.height) return;
  131. this.observerContainer();
  132. }
  133. },
  134. lifetimes: {
  135. attached: function attached() {
  136. this.data._attached = true;
  137. if (!this.data.disabled) this.initObserver();
  138. },
  139. detached: function detached() {
  140. this.data._attached = false;
  141. this.disconnectObserver();
  142. }
  143. },
  144. methods: {
  145. getContainerRect: function getContainerRect() {
  146. var nodesRef = this.data.container();
  147. return new Promise(function (resolve) {
  148. return nodesRef.boundingClientRect(resolve).exec();
  149. });
  150. },
  151. initObserver: function initObserver() {
  152. var _this = this;
  153. this.disconnectObserver();
  154. this.getRect(target).then(function (rect) {
  155. _this.setData({
  156. height: rect.height
  157. });
  158. _this.observerContent();
  159. _this.observerContainer();
  160. });
  161. },
  162. disconnectObserver: function disconnectObserver(observerName) {
  163. if (observerName) {
  164. var observer = this[observerName];
  165. observer && observer.disconnect();
  166. } else {
  167. this.contentObserver && this.contentObserver.disconnect();
  168. this.containerObserver && this.containerObserver.disconnect();
  169. }
  170. },
  171. observerContent: function observerContent() {
  172. var _this2 = this;
  173. var offsetTop = this.data.offsetTop;
  174. this.disconnectObserver('contentObserver');
  175. var contentObserver = this.createIntersectionObserver({
  176. thresholds: [1],
  177. initialRatio: 1
  178. });
  179. contentObserver.relativeToViewport({
  180. top: -offsetTop
  181. });
  182. contentObserver.observe(target, function (res) {
  183. if (_this2.data.disabled) return;
  184. _this2.setFixed(res.boundingClientRect.top);
  185. });
  186. this.contentObserver = contentObserver;
  187. },
  188. observerContainer: function observerContainer() {
  189. var _this3 = this;
  190. var _data = this.data,
  191. container = _data.container,
  192. height = _data.height,
  193. offsetTop = _data.offsetTop;
  194. if (typeof container !== 'function') return;
  195. this.disconnectObserver('containerObserver');
  196. this.getContainerRect().then(function (rect) {
  197. _this3.getRect(target).then(function (contentRect) {
  198. var _contentTop = contentRect.top;
  199. var _containerTop = rect.top;
  200. var _containerHeight = rect.height;
  201. var _relativeTop = _contentTop - _containerTop;
  202. var containerObserver = _this3.createIntersectionObserver({
  203. thresholds: [1],
  204. initialRatio: 1
  205. });
  206. containerObserver.relativeToViewport({
  207. top: _containerHeight - height - offsetTop - _relativeTop
  208. });
  209. containerObserver.observe(target, function (res) {
  210. if (_this3.data.disabled) return;
  211. _this3.setFixed(res.boundingClientRect.top);
  212. });
  213. _this3.data._relativeTop = _relativeTop;
  214. _this3.data._containerHeight = _containerHeight;
  215. _this3.containerObserver = containerObserver;
  216. });
  217. });
  218. },
  219. setFixed: function setFixed(top) {
  220. var _data2 = this.data,
  221. height = _data2.height,
  222. _containerHeight = _data2._containerHeight,
  223. _relativeTop = _data2._relativeTop,
  224. offsetTop = _data2.offsetTop;
  225. var fixed = _containerHeight && height ? top >= height + offsetTop + _relativeTop - _containerHeight && top < offsetTop : top < offsetTop;
  226. this.triggerEvent('scroll', {
  227. scrollTop: top,
  228. isFixed: fixed
  229. });
  230. this.setData({ fixed: fixed });
  231. }
  232. }
  233. });
  234. /***/ }),
  235. /***/ 9:
  236. /***/ (function(module, exports, __webpack_require__) {
  237. "use strict";
  238. module.exports = Behavior({
  239. methods: {
  240. getRect: function getRect(selector) {
  241. var _this = this;
  242. return new Promise(function (resolve, reject) {
  243. _this.createSelectorQuery().select(selector).boundingClientRect(function (rect) {
  244. if (rect) {
  245. resolve(rect);
  246. } else {
  247. reject(new Error("can not find selector: " + selector));
  248. }
  249. }).exec();
  250. });
  251. },
  252. getAllRects: function getAllRects(selector) {
  253. var _this2 = this;
  254. return new Promise(function (resolve, reject) {
  255. _this2.createSelectorQuery().selectAll(selector).boundingClientRect(function (rects) {
  256. if (rects && rects.lenght > 0) {
  257. resolve(rects);
  258. } else {
  259. reject(new Error("can not find selector: " + selector));
  260. }
  261. }).exec();
  262. });
  263. }
  264. }
  265. });
  266. /***/ })
  267. /******/ });