wot-design
Version:
Mobile UI components built on vue.js
555 lines (487 loc) • 16.3 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 116);
/******/ })
/************************************************************************/
/******/ ({
/***/ 0:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; });
/* globals __VUE_SSR_CONTEXT__ */
// IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
// This module is a runtime utility for cleaner component module output and will
// be included in the final webpack user bundle.
function normalizeComponent (
scriptExports,
render,
staticRenderFns,
functionalTemplate,
injectStyles,
scopeId,
moduleIdentifier, /* server only */
shadowMode /* vue-cli only */
) {
// Vue.extend constructor export interop
var options = typeof scriptExports === 'function'
? scriptExports.options
: scriptExports
// render functions
if (render) {
options.render = render
options.staticRenderFns = staticRenderFns
options._compiled = true
}
// functional template
if (functionalTemplate) {
options.functional = true
}
// scopedId
if (scopeId) {
options._scopeId = 'data-v-' + scopeId
}
var hook
if (moduleIdentifier) { // server build
hook = function (context) {
// 2.3 injection
context =
context || // cached call
(this.$vnode && this.$vnode.ssrContext) || // stateful
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__
}
// inject component styles
if (injectStyles) {
injectStyles.call(this, context)
}
// register component module identifier for async chunk inferrence
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier)
}
}
// used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook
} else if (injectStyles) {
hook = shadowMode
? function () { injectStyles.call(this, this.$root.$options.shadowRoot) }
: injectStyles
}
if (hook) {
if (options.functional) {
// for template-only hot-reload because in that case the render fn doesn't
// go through the normalizer
options._injectStyles = hook
// register for functioal component in vue file
var originalRender = options.render
options.render = function renderWithStyleInjection (h, context) {
hook.call(context)
return originalRender(h, context)
}
} else {
// inject component registration as beforeCreate hook
var existing = options.beforeCreate
options.beforeCreate = existing
? [].concat(existing, hook)
: [hook]
}
}
return {
exports: scriptExports,
options: options
}
}
/***/ }),
/***/ 116:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
// EXTERNAL MODULE: ./src/utils/animateScrollLeft.js
var animateScrollLeft = __webpack_require__(19);
// EXTERNAL MODULE: external "wot-design/lib/sticky"
var sticky_ = __webpack_require__(22);
var sticky_default = /*#__PURE__*/__webpack_require__.n(sticky_);
// CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/anchor/src/main.vue?vue&type=script&lang=js&
var anchorTimer;
/* harmony default export */ var mainvue_type_script_lang_js_ = ({
name: 'WdAnchor',
data: function data() {
return {
ifAnimate: false,
lineStyle: {},
clientWidth: 0,
isScroll: true,
anchorChange: true
};
},
props: {
value: String,
data: {
type: Array,
default: function _default() {
return [];
}
},
slidableNum: {
type: Number,
default: 5
},
offsetTop: {
type: Number,
default: 0
},
containerOffsetTop: {
type: Number,
default: 0
}
},
components: {
Sticky: sticky_default.a
},
computed: {
activeIndex: function activeIndex() {
return this.value;
}
},
watch: {
data: function data() {
this.lineScrollIntoView();
this.setLineStyle();
},
activeIndex: function activeIndex() {
this.lineScrollIntoView();
this.setLineStyle();
}
},
methods: {
/**
* 滚动效果实现
* @param {timer} obj
* @param {direction} number 滚动方向
*/
onScroll: function onScroll(timer, direction) {
var _this = this;
clearInterval(anchorTimer);
var bodyTop = document.documentElement.scrollTop || document.body.scrollTop;
anchorTimer = setInterval(function () {
if (Math.abs(bodyTop - timer.SCOLLOR_OFFSETTOP) <= timer.step) {
window.scrollTo(0, timer.SCOLLOR_OFFSETTOP);
clearInterval(anchorTimer);
setTimeout(function () {
_this.anchorChange = true;
}, 100);
} else {
bodyTop += direction * timer.step;
window.scrollTo(0, bodyTop);
}
}, timer.times);
},
/**
* @param {String} id
*/
anchorIndex: function anchorIndex(id) {
var item = document.getElementById(id);
var scrollerOffsetTop = this.getOffsetTop(item);
var windowScrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var timer = {
step: 30,
times: 16,
SCOLLOR_OFFSETTOP: scrollerOffsetTop
};
if (windowScrollTop > scrollerOffsetTop) {
this.onScroll(timer, -1); // -1向上滚动 1向下滚动
} else if (windowScrollTop < scrollerOffsetTop) {
if (scrollerOffsetTop + document.documentElement.clientHeight > document.documentElement.offsetHeight) {
timer = {
step: 30,
times: 16,
SCOLLOR_OFFSETTOP: document.documentElement.offsetHeight - document.documentElement.clientHeight
};
}
this.onScroll(timer, 1);
}
},
/**
* 获取元素以浏览器左上角为原点的距离
* @param {Object} obj
* @returns {String} 返回需要滚动的距离
*/
getOffsetTop: function getOffsetTop(obj) {
var offsetTop = obj.offsetTop; // 获取该元素对应父容器的上边距
var node = obj.offsetParent;
while (node != null) {
// 判断是否有父容器,如果存在则累加其边距
offsetTop += node.offsetTop;
node = node.offsetParent;
}
return offsetTop - this.containerOffsetTop;
},
/**
* Tab切换
* @param {string} id 选中id
* @param {Number} index 选中index
*/
changeTab: function changeTab(id, index) {
this.isScroll = false;
this.anchorChange = false;
this.anchorIndex(id);
this.$emit('input', id);
this.$emit('change', index);
this.$emit('click', index);
},
setLineStyle: function setLineStyle() {
var _this2 = this;
var shouldAnimate = this.ifAnimate;
this.$nextTick(function () {
var left = 0;
var width = 19;
if (_this2.$refs["navs_".concat(_this2.activeIndex)]) {
var _this2$$refs$ = _this2.$refs["navs_".concat(_this2.activeIndex)],
clientWidth = _this2$$refs$.clientWidth,
offsetLeft = _this2$$refs$.offsetLeft;
left = offsetLeft + (clientWidth - width) / 2;
}
_this2.lineStyle = {
width: "".concat(width, "px"),
transform: "translateX(".concat(left, "px)"),
transition: shouldAnimate ? 'width 300ms, transform 300ms' : ''
};
});
},
getNavDom: function getNavDom() {
var _this3 = this;
var h = this.$createElement;
return this.data.map(function (item, index) {
return h("div", {
"key": item.id,
"ref": "navs_".concat(item.id),
"class": {
'wd-anchor__nav-item': true,
'is-active': _this3.activeIndex === index
},
"on": {
"click": function click() {
_this3.changeTab(item.id, index);
}
}
}, [item.title]);
});
},
lineScrollIntoView: function lineScrollIntoView(immediate) {
var activeNav = this.$refs["navs_".concat(this.activeIndex)];
if (!activeNav) return;
var visibleWidth = this.$refs.navVisible.offsetWidth;
var activeLeft = activeNav.offsetWidth / 2 + activeNav.offsetLeft;
var nextNavContainerLeft = activeLeft - visibleWidth / 2;
Object(animateScrollLeft["a" /* default */])(this.$refs.navContainer, nextNavContainerLeft, immediate ? 0 : 300);
},
onShow: function onShow() {
var _this4 = this;
this.$nextTick(function () {
_this4.setLineStyle();
_this4.lineScrollIntoView(true);
_this4.ifAnimate = true;
});
},
/**
* 判断是否在可视线区
*/
isInVisibleArea: function isInVisibleArea(ele) {
var rect = ele.getBoundingClientRect();
if (rect.top + this.containerOffsetTop <= window.innerHeight && rect.top <= this.containerOffsetTop && rect.bottom >= this.containerOffsetTop) {
return true;
}
return false;
},
/**
* 屏幕滚动事件监听
*/
handleScroll: function handleScroll() {
var _this5 = this;
if (this.anchorChange) {
// Tab切换按钮会滚动视图,标记判断滚动是否结束
this.isScroll = true;
}
if (!this.isScroll) return;
this.data.every(function (item, index) {
if (_this5.isInVisibleArea(document.getElementById(item.id))) {
_this5.$emit('input', item.id);
_this5.$emit('change', index);
return false;
}
return true;
});
}
},
mounted: function mounted() {
var _this6 = this;
this.clientWidth = document.body.clientWidth;
this.onShow();
this.$nextTick(function () {
window.addEventListener('scroll', _this6.handleScroll);
});
},
beforeDestroy: function beforeDestroy() {
clearInterval(anchorTimer);
window.removeEventListener('scroll', this.handleScroll);
},
render: function render(h) {
var Navs = this.getNavDom();
var Nav = h("div", {
"class": "wd-anchor__nav",
"ref": "navVisible"
}, [h("div", {
"class": "wd-anchor__nav-container",
"ref": "navContainer"
}, [Navs, h("i", {
"class": "wd-anchor__line",
"style": this.lineStyle
})])]);
return h("div", {
"class": {
'wd-anchor': true,
'is-slide': this.slidableNum < this.data.length
}
}, [h(sticky_default.a, {
"attrs": {
"offsetTop": this.offsetTop,
"container": this.$el
}
}, [Nav]), h("div", {
"class": "wd-anchor__container"
}, [h("div", {
"class": "wd-anchor__body"
}, [this.$slots.default])])]);
}
});
// CONCATENATED MODULE: ./packages/anchor/src/main.vue?vue&type=script&lang=js&
/* harmony default export */ var src_mainvue_type_script_lang_js_ = (mainvue_type_script_lang_js_);
// EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
var componentNormalizer = __webpack_require__(0);
// CONCATENATED MODULE: ./packages/anchor/src/main.vue
var main_render, staticRenderFns
/* normalize component */
var component = Object(componentNormalizer["a" /* default */])(
src_mainvue_type_script_lang_js_,
main_render,
staticRenderFns,
false,
null,
null,
null
)
/* hot reload */
if (false) { var api; }
component.options.__file = "packages/anchor/src/main.vue"
/* harmony default export */ var main = (component.exports);
// CONCATENATED MODULE: ./packages/anchor/index.js
main.install = function (Vue) {
Vue.component(main.name, main);
};
/* harmony default export */ var packages_anchor = __webpack_exports__["default"] = (main);
/***/ }),
/***/ 19:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony default export */ __webpack_exports__["a"] = (function ($el, to, duration) {
var count = 0;
var from = $el.scrollLeft;
var frames = duration === 0 ? 1 : Math.round(duration / 16);
function animate() {
$el.scrollLeft += (to - from) / frames;
if (++count < frames) {
requestAnimationFrame(animate);
}
}
animate();
});
/***/ }),
/***/ 22:
/***/ (function(module, exports) {
module.exports = require("wot-design/lib/sticky");
/***/ })
/******/ });