123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577 |
- /*
- * Vuescroll v4.18.1
- * (c) 2018-2023 Yi(Yves) Wang
- * Released under the MIT License
- * Github: https://github.com/YvesCoding/vuescroll
- * Website: http://vuescrolljs.yvescoding.me/
- */
-
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('vue')) :
- typeof define === 'function' && define.amd ? define(['vue'], factory) :
- (global = global || self, global.vuescroll = factory(global.Vue));
- }(this, (function (Vue) { 'use strict';
- Vue = Vue && Object.prototype.hasOwnProperty.call(Vue, 'default') ? Vue['default'] : Vue;
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
- return typeof obj;
- } : function (obj) {
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
- };
- var classCallCheck = function (instance, Constructor) {
- if (!(instance instanceof Constructor)) {
- throw new TypeError("Cannot call a class as a function");
- }
- };
- var createClass = function () {
- function defineProperties(target, props) {
- for (var i = 0; i < props.length; i++) {
- var descriptor = props[i];
- descriptor.enumerable = descriptor.enumerable || false;
- descriptor.configurable = true;
- if ("value" in descriptor) descriptor.writable = true;
- Object.defineProperty(target, descriptor.key, descriptor);
- }
- }
- return function (Constructor, protoProps, staticProps) {
- if (protoProps) defineProperties(Constructor.prototype, protoProps);
- if (staticProps) defineProperties(Constructor, staticProps);
- return Constructor;
- };
- }();
- var defineProperty = function (obj, key, value) {
- if (key in obj) {
- Object.defineProperty(obj, key, {
- value: value,
- enumerable: true,
- configurable: true,
- writable: true
- });
- } else {
- obj[key] = value;
- }
- return obj;
- };
- var _extends = Object.assign || function (target) {
- for (var i = 1; i < arguments.length; i++) {
- var source = arguments[i];
- for (var key in source) {
- if (Object.prototype.hasOwnProperty.call(source, key)) {
- target[key] = source[key];
- }
- }
- }
- return target;
- };
- var toConsumableArray = function (arr) {
- if (Array.isArray(arr)) {
- for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
- return arr2;
- } else {
- return Array.from(arr);
- }
- };
- function isIE() {
- /* istanbul ignore if */
- if (isServer()) return false;
- var agent = navigator.userAgent.toLowerCase();
- return agent.indexOf('msie') !== -1 || agent.indexOf('trident') !== -1 || agent.indexOf(' edge/') !== -1;
- }
- var isIos = function isIos() {
- /* istanbul ignore if */
- if (isServer()) return false;
- var u = navigator.userAgent;
- return !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
- };
- /* istanbul ignore next */
- var isServer = function isServer() {
- return Vue.prototype.$isServer;
- };
- var touchManager = function () {
- function touchManager() {
- classCallCheck(this, touchManager);
- }
- createClass(touchManager, [{
- key: 'getEventObject',
- value: function getEventObject(originEvent) {
- return this.touchObject ? this.isTouch ? originEvent.touches : [originEvent] : null;
- }
- }, {
- key: 'getTouchObject',
- value: function getTouchObject() /* istanbul ignore next */{
- if (isServer()) return null;
- this.isTouch = false;
- var agent = navigator.userAgent,
- platform = navigator.platform,
- touchObject = {};
- touchObject.touch = !!('ontouchstart' in window && !window.opera || 'msmaxtouchpoints' in window.navigator || 'maxtouchpoints' in window.navigator || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0);
- touchObject.nonDeskTouch = touchObject.touch && !/win32/i.test(platform) || touchObject.touch && /win32/i.test(platform) && /mobile/i.test(agent);
- touchObject.eventType = 'onmousedown' in window && !touchObject.nonDeskTouch ? 'mouse' : 'ontouchstart' in window ? 'touch' : 'msmaxtouchpoints' in window.navigator || navigator.msMaxTouchPoints > 0 ? 'mstouchpoints' : 'maxtouchpoints' in window.navigator || navigator.maxTouchPoints > 0 ? 'touchpoints' : 'mouse';
- switch (touchObject.eventType) {
- case 'mouse':
- touchObject.touchstart = 'mousedown';
- touchObject.touchend = 'mouseup';
- touchObject.touchmove = 'mousemove';
- touchObject.touchenter = 'mouseenter';
- touchObject.touchmove = 'mousemove';
- touchObject.touchleave = 'mouseleave';
- break;
- case 'touch':
- touchObject.touchstart = 'touchstart';
- touchObject.touchend = 'touchend';
- touchObject.touchmove = 'touchmove';
- touchObject.touchcancel = 'touchcancel';
- touchObject.touchenter = 'touchstart';
- touchObject.touchmove = 'touchmove';
- touchObject.touchleave = 'touchend';
- this.isTouch = true;
- break;
- case 'mstouchpoints':
- touchObject.touchstart = 'MSPointerDown';
- touchObject.touchend = 'MSPointerUp';
- touchObject.touchmove = 'MSPointerMove';
- touchObject.touchcancel = 'MSPointerCancel';
- touchObject.touchenter = 'MSPointerDown';
- touchObject.touchmove = 'MSPointerMove';
- touchObject.touchleave = 'MSPointerUp';
- break;
- case 'touchpoints':
- touchObject.touchstart = 'pointerdown';
- touchObject.touchend = 'pointerup';
- touchObject.touchmove = 'pointermove';
- touchObject.touchcancel = 'pointercancel';
- touchObject.touchenter = 'pointerdown';
- touchObject.touchmove = 'pointermove';
- touchObject.touchleave = 'pointerup';
- break;
- }
- return this.touchObject = touchObject;
- }
- }]);
- return touchManager;
- }();
- /**
- * ZoomManager
- * Get the browser zoom ratio
- */
- var ZoomManager = function () {
- function ZoomManager() {
- var _this = this;
- classCallCheck(this, ZoomManager);
- this.originPixelRatio = this.getRatio();
- this.lastPixelRatio = this.originPixelRatio;
- window.addEventListener('resize', function () {
- _this.lastPixelRatio = _this.getRatio();
- });
- }
- createClass(ZoomManager, [{
- key: 'getRatio',
- value: function getRatio() {
- var ratio = 0;
- var screen = window.screen;
- var ua = navigator.userAgent.toLowerCase();
- if (window.devicePixelRatio !== undefined) {
- ratio = window.devicePixelRatio;
- } else if (~ua.indexOf('msie')) {
- if (screen.deviceXDPI && screen.logicalXDPI) {
- ratio = screen.deviceXDPI / screen.logicalXDPI;
- }
- } else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
- ratio = window.outerWidth / window.innerWidth;
- }
- if (ratio) {
- ratio = Math.round(ratio * 100);
- }
- return ratio;
- }
- }, {
- key: 'getRatioBetweenPreAndCurrent',
- value: function getRatioBetweenPreAndCurrent() {
- return this.originPixelRatio / this.lastPixelRatio;
- }
- }]);
- return ZoomManager;
- }();
- function deepCopy(from, to, shallow) {
- if (shallow && isUndef(to)) {
- return from;
- }
- if (isArray(from)) {
- to = [];
- from.forEach(function (item, index) {
- to[index] = deepCopy(item, to[index]);
- });
- } else if (from) {
- if (!isPlainObj(from)) {
- return from;
- }
- to = {};
- for (var key in from) {
- to[key] = _typeof(from[key]) === 'object' ? deepCopy(from[key], to[key]) : from[key];
- }
- }
- return to;
- }
- function mergeObject(from, to, force, shallow) {
- if (shallow && isUndef(to)) {
- return from;
- }
- to = to || {};
- if (isArray(from)) {
- if (!isArray(to) && force) {
- to = [];
- }
- if (isArray(to)) {
- from.forEach(function (item, index) {
- to[index] = mergeObject(item, to[index], force, shallow);
- });
- }
- } else if (from) {
- if (!isPlainObj(from)) {
- if (force) {
- to = from;
- }
- } else {
- for (var key in from) {
- if (_typeof(from[key]) === 'object') {
- if (isUndef(to[key])) {
- to[key] = deepCopy(from[key], to[key], shallow);
- } else {
- mergeObject(from[key], to[key], force, shallow);
- }
- } else {
- if (isUndef(to[key]) || force) to[key] = from[key];
- }
- }
- }
- }
- return to;
- }
- function defineReactive(target, key, source, souceKey) {
- /* istanbul ignore if */
- if (!source[key] && typeof source !== 'function') {
- return;
- }
- souceKey = souceKey || key;
- Object.defineProperty(target, key, {
- get: function get() {
- return source[souceKey];
- },
- configurable: true
- });
- }
- var scrollBarWidth = void 0;
- var zoomManager = void 0;
- function getGutter() {
- /* istanbul ignore next */
- if (isServer()) return 0;
- if (!zoomManager) {
- zoomManager = new ZoomManager();
- }
- if (scrollBarWidth !== undefined) return scrollBarWidth * zoomManager.getRatioBetweenPreAndCurrent();
- var outer = document.createElement('div');
- outer.style.visibility = 'hidden';
- outer.style.width = '100px';
- outer.style.position = 'absolute';
- outer.style.top = '-9999px';
- document.body.appendChild(outer);
- var widthNoScroll = outer.offsetWidth;
- outer.style.overflow = 'scroll';
- var inner = document.createElement('div');
- inner.style.width = '100%';
- outer.appendChild(inner);
- var widthWithScroll = inner.offsetWidth;
- outer.parentNode.removeChild(outer);
- scrollBarWidth = widthNoScroll - widthWithScroll;
- // multi the browser zoom
- if (!zoomManager) {
- zoomManager = new ZoomManager();
- }
- return scrollBarWidth * zoomManager.getRatioBetweenPreAndCurrent();
- }
- function eventCenter(dom, eventName, hander) {
- var capture = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
- var type = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'on';
- type == 'on' ? dom.addEventListener(eventName, hander, capture) : dom.removeEventListener(eventName, hander, capture);
- }
- var warn = function warn(msg) {
- console.warn('[vuescroll] ' + msg);
- };
- function isChildInParent(child, parent) {
- var flag = false;
- if (!child || !parent) {
- return flag;
- }
- while (child.parentNode !== parent && child.parentNode.nodeType !== 9 && !child.parentNode._isVuescroll) {
- child = child.parentNode;
- }
- if (child.parentNode == parent) {
- flag = true;
- }
- return flag;
- }
- function getPrefix(global) {
- var docStyle = document.documentElement.style;
- var engine;
- /* istanbul ignore if */
- if (global.opera && Object.prototype.toString.call(opera) === '[object Opera]') {
- engine = 'presto';
- } /* istanbul ignore next */else if ('MozAppearance' in docStyle) {
- engine = 'gecko';
- } else if ('WebkitAppearance' in docStyle) {
- engine = 'webkit';
- } /* istanbul ignore next */else if (typeof navigator.cpuClass === 'string') {
- engine = 'trident';
- }
- var vendorPrefix = {
- trident: 'ms',
- gecko: 'moz',
- webkit: 'webkit',
- presto: 'O'
- }[engine];
- return vendorPrefix;
- }
- function getComplitableStyle(property, value) {
- /* istanbul ignore if */
- if (isServer()) return false;
- var compatibleValue = '-' + getPrefix(window) + '-' + value;
- var testElm = document.createElement('div');
- testElm.style[property] = compatibleValue;
- if (testElm.style[property] == compatibleValue) {
- return compatibleValue;
- }
- /* istanbul ignore next */
- return false;
- }
- /**
- * Insert children into user-passed slot at vnode level
- */
- function insertChildrenIntoSlot(h) {
- var parentVnode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
- var childVNode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
- var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
- var swapChildren = arguments[4];
- /* istanbul ignore if */
- if (parentVnode && parentVnode.length > 1) {
- return swapChildren ? [].concat(toConsumableArray(childVNode), toConsumableArray(parentVnode)) : [].concat(toConsumableArray(parentVnode), toConsumableArray(childVNode));
- }
- parentVnode = parentVnode[0];
- var _getVnodeInfo = getVnodeInfo(parentVnode),
- ch = _getVnodeInfo.ch,
- tag = _getVnodeInfo.tag,
- isComponent = _getVnodeInfo.isComponent;
- if (isComponent) {
- parentVnode.data = mergeObject({ attrs: parentVnode.componentOptions.propsData }, parentVnode.data, false, // force: false
- true // shallow: true
- );
- }
- ch = swapChildren ? [].concat(toConsumableArray(childVNode), toConsumableArray(ch)) : [].concat(toConsumableArray(ch), toConsumableArray(childVNode));
- delete parentVnode.data.slot;
- return h(tag, mergeObject(data, parentVnode.data, false, true), ch);
- }
- /**
- * Get the info of a vnode,
- * vnode must be parentVnode
- */
- function getVnodeInfo(vnode) {
- if (!vnode || vnode.length > 1) return {};
- vnode = vnode[0] ? vnode[0] : vnode;
- var isComponent = !!vnode.componentOptions;
- var ch = void 0;
- var tag = void 0;
- if (isComponent) {
- ch = vnode.componentOptions.children || [];
- tag = vnode.componentOptions.tag;
- } else {
- ch = vnode.children || [];
- tag = vnode.tag;
- }
- return {
- isComponent: isComponent,
- ch: ch,
- tag: tag
- };
- }
- /**
- * Get the vuescroll instance instead of
- * user pass component like slot.
- */
- function getRealParent(ctx) {
- var parent = ctx.$parent;
- if (!parent._isVuescrollRoot && parent) {
- parent = parent.$parent;
- }
- return parent;
- }
- var isArray = function isArray(_) {
- return Array.isArray(_);
- };
- var isPlainObj = function isPlainObj(_) {
- return Object.prototype.toString.call(_) == '[object Object]';
- };
- var isUndef = function isUndef(_) {
- return typeof _ === 'undefined';
- };
- function getNumericValue(distance, size) {
- var number = void 0;
- if (!(number = /(-?\d+(?:\.\d+?)?)%$/.exec(distance))) {
- number = distance - 0;
- } else {
- number = number[1] - 0;
- number = size * number / 100;
- }
- return number;
- }
- function createStyle(styleId, cssText) {
- /* istanbul ignore if */
- if (isServer() || document.getElementById(styleId)) {
- return;
- }
- var head = document.head || doc.getElementsByTagName('head')[0];
- var style = document.createElement('style');
- style.id = styleId;
- style.type = 'text/css';
- /* istanbul ignore if */
- if (style.styleSheet) {
- style.styleSheet.cssText = cssText;
- } else {
- style.appendChild(document.createTextNode(cssText));
- }
- head.appendChild(style);
- }
- // Hide the ios native scrollbar.
- function createHideBarStyle() {
- /* istanbul ignore next */
- {
- var cssText = '.__hidebar::-webkit-scrollbar {\n width: 0;\n height: 0;\n }';
- createStyle('vuescroll-hide-ios-bar', cssText);
- }
- }
- var api = {
- mounted: function mounted() {
- vsInstances[this._uid] = this;
- },
- beforeDestroy: function beforeDestroy() {
- delete vsInstances[this._uid];
- },
- methods: {
- // public api
- scrollTo: function scrollTo(_ref, speed, easing) {
- var x = _ref.x,
- y = _ref.y;
- // istanbul ignore if
- if (speed === true || typeof speed == 'undefined') {
- speed = this.mergedOptions.scrollPanel.speed;
- }
- this.internalScrollTo(x, y, speed, easing);
- },
- scrollBy: function scrollBy(_ref2, speed, easing) {
- var _ref2$dx = _ref2.dx,
- dx = _ref2$dx === undefined ? 0 : _ref2$dx,
- _ref2$dy = _ref2.dy,
- dy = _ref2$dy === undefined ? 0 : _ref2$dy;
- var _getPosition = this.getPosition(),
- _getPosition$scrollLe = _getPosition.scrollLeft,
- scrollLeft = _getPosition$scrollLe === undefined ? 0 : _getPosition$scrollLe,
- _getPosition$scrollTo = _getPosition.scrollTop,
- scrollTop = _getPosition$scrollTo === undefined ? 0 : _getPosition$scrollTo;
- if (dx) {
- scrollLeft += getNumericValue(dx, this.scrollPanelElm.scrollWidth - this.$el.clientWidth);
- }
- if (dy) {
- scrollTop += getNumericValue(dy, this.scrollPanelElm.scrollHeight - this.$el.clientHeight);
- }
- this.internalScrollTo(scrollLeft, scrollTop, speed, easing);
- },
- scrollIntoView: function scrollIntoView(elm) {
- var animate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
- var parentElm = this.$el;
- if (typeof elm === 'string') {
- elm = parentElm.querySelector(elm);
- }
- if (!isChildInParent(elm, parentElm)) {
- warn('The element or selector you passed is not the element of Vuescroll, please pass the element that is in Vuescroll to scrollIntoView API. ');
- return;
- }
- // parent elm left, top
- var _$el$getBoundingClien = this.$el.getBoundingClientRect(),
- left = _$el$getBoundingClien.left,
- top = _$el$getBoundingClien.top;
- // child elm left, top
- var _elm$getBoundingClien = elm.getBoundingClientRect(),
- childLeft = _elm$getBoundingClien.left,
- childTop = _elm$getBoundingClien.top;
- var diffX = left - childLeft;
- var diffY = top - childTop;
- this.scrollBy({
- dx: -diffX,
- dy: -diffY
- }, animate);
- },
- refresh: function refresh() {
- this.refreshInternalStatus();
- // refresh again to keep status is correct
- this.$nextTick(this.refreshInternalStatus);
- }
- }
- };
- /** Public Api */
- /**
- * Refresh all
- */
- var vsInstances = {};
- function refreshAll() {
- for (var vs in vsInstances) {
- vsInstances[vs].refresh();
- }
- }
- var baseConfig = {
- // vuescroll
- vuescroll: {
- // vuescroll's size(height/width) should be a percent(100%)
- // or be a number that is equal to its parentNode's width or
- // height ?
- sizeStrategy: 'percent',
- /** Whether to detect dom resize or not */
- detectResize: true,
- /** Enable locking to the main axis if user moves only slightly on one of them at start */
- locking: true
- },
- scrollPanel: {
- // when component mounted.. it will automatically scrolls.
- initialScrollY: false,
- initialScrollX: false,
- // feat: #11
- scrollingX: true,
- scrollingY: true,
- speed: 300,
- easing: undefined,
- // Sometimes, the nativebar maybe on the left,
- // See https://github.com/YvesCoding/vuescroll/issues/64
- verticalNativeBarPos: 'right',
- maxHeight: undefined,
- maxWidth: undefined
- },
- //
- rail: {
- background: '#01a99a',
- opacity: 0,
- border: 'none',
- /** Rail's size(Height/Width) , default -> 6px */
- size: '6px',
- /** Specify rail's border-radius, or the border-radius of rail and bar will be equal to the rail's size. default -> false **/
- specifyBorderRadius: false,
- /** Rail the distance from the two ends of the X axis and Y axis. **/
- gutterOfEnds: null,
- /** Rail the distance from the side of container. **/
- gutterOfSide: '2px',
- /** Whether to keep rail show or not, default -> false, event content height is not enough */
- keepShow: false
- },
- bar: {
- /** How long to hide bar after mouseleave, default -> 500 */
- showDelay: 500,
- /** Specify bar's border-radius, or the border-radius of rail and bar will be equal to the rail's size. default -> false **/
- specifyBorderRadius: false,
- /** Whether to show bar on scrolling, default -> true */
- onlyShowBarOnScroll: true,
- /** Whether to keep show or not, default -> false */
- keepShow: false,
- /** Bar's background , default -> #00a650 */
- background: 'rgb(3, 185, 118)',
- /** Bar's opacity, default -> 1 */
- opacity: 1,
- /** bar's size(Height/Width) , default -> 6px */
- size: '6px',
- minSize: 0,
- disable: false
- },
- scrollButton: {
- enable: false,
- background: 'rgb(3, 185, 118)',
- opacity: 1,
- step: 180,
- mousedownStep: 30
- }
- };
- /**
- * validate the options
- * @export
- * @param {any} ops
- */
- function validateOps(ops) {
- var renderError = false;
- var scrollPanel = ops.scrollPanel;
- var _ops$bar = ops.bar,
- vBar = _ops$bar.vBar,
- hBar = _ops$bar.hBar;
- var _ops$rail = ops.rail,
- vRail = _ops$rail.vRail,
- hRail = _ops$rail.hRail;
- // validate scrollPanel
- var initialScrollY = scrollPanel['initialScrollY'];
- var initialScrollX = scrollPanel['initialScrollX'];
- if (initialScrollY && !String(initialScrollY).match(/^\d+(\.\d+)?(%)?$/)) {
- warn('The prop `initialScrollY` or `initialScrollX` should be a percent number like `10%` or an exact number that greater than or equal to 0 like `100`.');
- }
- if (initialScrollX && !String(initialScrollX).match(/^\d+(\.\d+)?(%)?$/)) {
- warn('The prop `initialScrollY` or `initialScrollX` should be a percent number like `10%` or an exact number that greater than or equal to 0 like `100`.');
- }
- // validate deprecated vBar/hBar vRail/hRail
- if (vBar || hBar || vRail || hRail) {
- warn('The options: vRail, hRail, vBar, hBar have been deprecated since v4.7.0,' + 'please use corresponing rail/bar instead!');
- }
- if (_extraValidate) {
- _extraValidate = [].concat(_extraValidate);
- _extraValidate.forEach(function (hasError) {
- if (hasError(ops)) {
- renderError = true;
- }
- });
- }
- return renderError;
- }
- var _extraValidate = null;
- var extendOpts = function extendOpts(extraOpts, extraValidate) {
- extraOpts = [].concat(extraOpts);
- extraOpts.forEach(function (opts) {
- mergeObject(opts, baseConfig);
- });
- _extraValidate = extraValidate;
- };
- // all modes
- // some small changes.
- var smallChangeArray = ['mergedOptions.vuescroll.pullRefresh.tips', 'mergedOptions.vuescroll.pushLoad.tips', 'mergedOptions.vuescroll.scroller.disable', 'mergedOptions.rail', 'mergedOptions.bar'];
- var scrollMap = {
- vertical: {
- size: 'height',
- opsSize: 'width',
- posName: 'top',
- opposName: 'bottom',
- sidePosName: 'right',
- page: 'pageY',
- scroll: 'scrollTop',
- scrollSize: 'scrollHeight',
- offset: 'offsetHeight',
- client: 'clientY',
- axis: 'Y',
- scrollButton: {
- start: 'top',
- end: 'bottom'
- }
- },
- horizontal: {
- size: 'width',
- opsSize: 'height',
- posName: 'left',
- opposName: 'right',
- sidePosName: 'bottom',
- page: 'pageX',
- scroll: 'scrollLeft',
- scrollSize: 'scrollWidth',
- offset: 'offsetWidth',
- client: 'clientX',
- axis: 'X',
- scrollButton: {
- start: 'left',
- end: 'right'
- }
- }
- };
- function requestAnimationFrame(global) {
- // Check for request animation Frame support
- var requestFrame = global.requestAnimationFrame || global.webkitRequestAnimationFrame || global.mozRequestAnimationFrame || global.oRequestAnimationFrame;
- var isNative = !!requestFrame;
- if (requestFrame && !/requestAnimationFrame\(\)\s*\{\s*\[native code\]\s*\}/i.test(requestFrame.toString())) {
- isNative = false;
- }
- if (isNative) {
- return function (callback, root) {
- requestFrame(callback, root);
- };
- }
- var TARGET_FPS = 60;
- var requests = {};
- var rafHandle = 1;
- var intervalHandle = null;
- var lastActive = +new Date();
- return function (callback) {
- var callbackHandle = rafHandle++;
- // Store callback
- requests[callbackHandle] = callback;
- // Create timeout at first request
- if (intervalHandle === null) {
- intervalHandle = setInterval(function () {
- var time = +new Date();
- var currentRequests = requests;
- // Reset data structure before executing callbacks
- requests = {};
- for (var key in currentRequests) {
- if (currentRequests.hasOwnProperty(key)) {
- currentRequests[key](time);
- lastActive = time;
- }
- }
- // Disable the timeout when nothing happens for a certain
- // period of time
- if (time - lastActive > 2500) {
- clearInterval(intervalHandle);
- intervalHandle = null;
- }
- }, 1000 / TARGET_FPS);
- }
- return callbackHandle;
- };
- }
- var colorCache = {};
- var rgbReg = /rgb\(/;
- var extractRgbColor = /rgb\((.*)\)/;
- // Transform a common color int oa `rgbA` color
- function getRgbAColor(color, opacity) {
- var id = color + '&' + opacity;
- if (colorCache[id]) {
- return colorCache[id];
- }
- var div = document.createElement('div');
- div.style.background = color;
- document.body.appendChild(div);
- var computedColor = window.getComputedStyle(div).backgroundColor;
- document.body.removeChild(div);
- /* istanbul ignore if */
- if (!rgbReg.test(computedColor)) {
- return color;
- }
- return colorCache[id] = 'rgba(' + extractRgbColor.exec(computedColor)[1] + ', ' + opacity + ')';
- }
- var bar = {
- name: 'bar',
- props: {
- ops: Object,
- state: Object,
- hideBar: Boolean,
- otherBarHide: Boolean,
- type: String
- },
- computed: {
- bar: function bar() {
- return scrollMap[this.type];
- },
- barSize: function barSize() {
- return Math.max(this.state.size, this.ops.bar.minSize);
- },
- barRatio: function barRatio() {
- return (1 - this.barSize) / (1 - this.state.size);
- }
- },
- render: function render(h) {
- var _style, _style2, _barStyle;
- var vm = this;
- /** Get rgbA format background color */
- var railBackgroundColor = getRgbAColor(vm.ops.rail.background, vm.ops.rail.opacity);
- if (!this.touchManager) {
- this.touchManager = new touchManager();
- }
- /** Rail Data */
- var railSize = vm.ops.rail.size;
- var endPos = vm.otherBarHide ? 0 : railSize;
- var touchObj = vm.touchManager.getTouchObject();
- var rail = {
- class: '__rail-is-' + vm.type,
- style: (_style = {
- position: 'absolute',
- 'z-index': '1',
- borderRadius: vm.ops.rail.specifyBorderRadius || railSize,
- background: railBackgroundColor,
- border: vm.ops.rail.border
- }, defineProperty(_style, vm.bar.opsSize, railSize), defineProperty(_style, vm.bar.posName, vm.ops.rail['gutterOfEnds'] || 0), defineProperty(_style, vm.bar.opposName, vm.ops.rail['gutterOfEnds'] || endPos), defineProperty(_style, vm.bar.sidePosName, vm.ops.rail['gutterOfSide']), _style)
- };
- if (touchObj) {
- var _rail$on;
- rail.on = (_rail$on = {}, defineProperty(_rail$on, touchObj.touchenter, function () {
- vm.setRailHover();
- }), defineProperty(_rail$on, touchObj.touchleave, function () {
- vm.setRailLeave();
- }), _rail$on);
- }
- // left space for scroll button
- var buttonSize = vm.ops.scrollButton.enable ? railSize : 0;
- var barWrapper = {
- class: '__bar-wrap-is-' + vm.type,
- style: (_style2 = {
- position: 'absolute',
- borderRadius: vm.ops.rail.specifyBorderRadius || railSize
- }, defineProperty(_style2, vm.bar.posName, buttonSize), defineProperty(_style2, vm.bar.opposName, buttonSize), _style2),
- on: {}
- };
- var scrollDistance = vm.state.posValue * vm.state.size;
- var pos = scrollDistance * vm.barRatio / vm.barSize;
- var opacity = vm.state.opacity;
- var parent = getRealParent(this);
- // set class hook
- parent.setClassHook(this.type == 'vertical' ? 'vBarVisible' : 'hBarVisible', !!opacity);
- /** Scrollbar style */
- var barStyle = (_barStyle = {
- cursor: 'pointer',
- position: 'absolute',
- margin: 'auto',
- transition: 'opacity 0.5s',
- 'user-select': 'none',
- 'border-radius': 'inherit'
- }, defineProperty(_barStyle, vm.bar.size, vm.barSize * 100 + '%'), defineProperty(_barStyle, 'background', vm.ops.bar.background), defineProperty(_barStyle, vm.bar.opsSize, vm.ops.bar.size), defineProperty(_barStyle, 'opacity', opacity), defineProperty(_barStyle, 'transform', 'translate' + scrollMap[vm.type].axis + '(' + pos + '%)'), _barStyle);
- var bar = {
- style: barStyle,
- class: '__bar-is-' + vm.type,
- ref: 'thumb',
- on: {}
- };
- if (vm.type == 'vertical') {
- barWrapper.style.width = '100%';
- // Let bar to be on the center.
- bar.style.left = 0;
- bar.style.right = 0;
- } else {
- barWrapper.style.height = '100%';
- bar.style.top = 0;
- bar.style.bottom = 0;
- }
- /* istanbul ignore next */
- {
- var _touchObj = this.touchManager.getTouchObject();
- bar.on[_touchObj.touchstart] = this.createBarEvent();
- barWrapper.on[_touchObj.touchstart] = this.createTrackEvent();
- }
- return h(
- 'div',
- rail,
- [this.createScrollbarButton(h, 'start'), this.hideBar ? null : h(
- 'div',
- barWrapper,
- [h('div', bar)]
- ), this.createScrollbarButton(h, 'end')]
- );
- },
- data: function data() {
- return {
- isBarDragging: false
- };
- },
- methods: {
- setRailHover: function setRailHover() {
- var parent = getRealParent(this);
- var state = parent.vuescroll.state;
- if (!state.isRailHover) {
- state.isRailHover = true;
- parent.showBar();
- }
- },
- setRailLeave: function setRailLeave() {
- var parent = getRealParent(this);
- var state = parent.vuescroll.state;
- state.isRailHover = false;
- parent.hideBar();
- },
- setBarDrag: function setBarDrag(val) /* istanbul ignore next */{
- this.$emit('setBarDrag', this.isBarDragging = val);
- var parent = getRealParent(this);
- // set class hook
- parent.setClassHook(this.type == 'vertical' ? 'vBarDragging' : 'hBarDragging', !!val);
- },
- createBarEvent: function createBarEvent() {
- var ctx = this;
- var parent = getRealParent(ctx);
- var touchObj = ctx.touchManager.getTouchObject();
- function mousedown(e) /* istanbul ignore next */{
- var event = ctx.touchManager.getEventObject(e);
- if (!event) return;
- e.stopImmediatePropagation();
- e.preventDefault();
- event = event[0];
- document.onselectstart = function () {
- return false;
- };
- ctx.axisStartPos = event[ctx.bar.client] - ctx.$refs['thumb'].getBoundingClientRect()[ctx.bar.posName];
- // Tell parent that the mouse has been down.
- ctx.setBarDrag(true);
- eventCenter(document, touchObj.touchmove, mousemove);
- eventCenter(document, touchObj.touchend, mouseup);
- }
- function mousemove(e) /* istanbul ignore next */{
- if (!ctx.axisStartPos) {
- return;
- }
- var event = ctx.touchManager.getEventObject(e);
- if (!event) return;
- event = event[0];
- var thubmParent = ctx.$refs.thumb.parentNode;
- var delta = event[ctx.bar.client] - thubmParent.getBoundingClientRect()[ctx.bar.posName];
- delta = delta / ctx.barRatio;
- var percent = (delta - ctx.axisStartPos) / thubmParent[ctx.bar.offset];
- parent.scrollTo(defineProperty({}, ctx.bar.axis.toLowerCase(), parent.scrollPanelElm[ctx.bar.scrollSize] * percent), false);
- }
- function mouseup() /* istanbul ignore next */{
- ctx.setBarDrag(false);
- parent.hideBar();
- document.onselectstart = null;
- ctx.axisStartPos = 0;
- eventCenter(document, touchObj.touchmove, mousemove, false, 'off');
- eventCenter(document, touchObj.touchend, mouseup, false, 'off');
- }
- return mousedown;
- },
- createTrackEvent: function createTrackEvent() {
- var ctx = this;
- return function handleClickTrack(e) {
- var parent = getRealParent(ctx);
- var _ctx$bar = ctx.bar,
- client = _ctx$bar.client,
- offset = _ctx$bar.offset,
- posName = _ctx$bar.posName,
- axis = _ctx$bar.axis;
- var thumb = ctx.$refs['thumb'];
- e.preventDefault();
- e.stopImmediatePropagation();
- /* istanbul ignore if */
- if (!thumb) return;
- var barOffset = thumb[offset];
- var event = ctx.touchManager.getEventObject(e)[0];
- var percent = (event[client] - e.currentTarget.getBoundingClientRect()[posName] - barOffset / 2) / (e.currentTarget[offset] - barOffset);
- parent.scrollTo(defineProperty({}, axis.toLowerCase(), percent * 100 + '%'));
- };
- },
- // Scrollbuton relative things...
- createScrollbarButton: function createScrollbarButton(h, type /* start or end */) {
- var _style3;
- var barContext = this;
- if (!barContext.ops.scrollButton.enable) {
- return null;
- }
- var size = barContext.ops.rail.size;
- var _barContext$ops$scrol = barContext.ops.scrollButton,
- opacity = _barContext$ops$scrol.opacity,
- background = _barContext$ops$scrol.background;
- var borderColor = getRgbAColor(background, opacity);
- var wrapperProps = {
- class: ['__bar-button', '__bar-button-is-' + barContext.type + '-' + type],
- style: (_style3 = {}, defineProperty(_style3, barContext.bar.scrollButton[type], 0), defineProperty(_style3, 'width', size), defineProperty(_style3, 'height', size), defineProperty(_style3, 'position', 'absolute'), defineProperty(_style3, 'cursor', 'pointer'), defineProperty(_style3, 'display', 'table'), _style3),
- ref: type
- };
- var innerProps = {
- class: '__bar-button-inner',
- style: {
- border: 'calc(' + size + ' / 2.5) solid transparent',
- width: '0',
- height: '0',
- margin: 'auto',
- position: 'absolute',
- top: '0',
- bottom: '0',
- right: '0',
- left: '0'
- },
- on: {}
- };
- if (barContext.type == 'vertical') {
- if (type == 'start') {
- innerProps.style['border-bottom-color'] = borderColor;
- innerProps.style['transform'] = 'translateY(-25%)';
- } else {
- innerProps.style['border-top-color'] = borderColor;
- innerProps.style['transform'] = 'translateY(25%)';
- }
- } else {
- if (type == 'start') {
- innerProps.style['border-right-color'] = borderColor;
- innerProps.style['transform'] = 'translateX(-25%)';
- } else {
- innerProps.style['border-left-color'] = borderColor;
- innerProps.style['transform'] = 'translateX(25%)';
- }
- }
- /* istanbul ignore next */
- {
- var touchObj = this.touchManager.getTouchObject();
- innerProps.on[touchObj.touchstart] = this.createScrollButtonEvent(type, touchObj);
- }
- return h(
- 'div',
- wrapperProps,
- [h('div', innerProps)]
- );
- },
- createScrollButtonEvent: function createScrollButtonEvent(type, touchObj) {
- var ctx = this;
- var parent = getRealParent(ctx);
- var _ctx$ops$scrollButton = ctx.ops.scrollButton,
- step = _ctx$ops$scrollButton.step,
- mousedownStep = _ctx$ops$scrollButton.mousedownStep;
- var stepWithDirection = type == 'start' ? -step : step;
- var mousedownStepWithDirection = type == 'start' ? -mousedownStep : mousedownStep;
- var ref = requestAnimationFrame(window);
- // bar props: type
- var barType = ctx.type;
- var isMouseDown = false;
- var isMouseout = true;
- var timeoutId = void 0;
- function start(e) {
- /* istanbul ignore if */
- if (3 == e.which) {
- return;
- }
- // set class hook
- parent.setClassHook('cliking' + barType + type + 'Button', true);
- e.stopImmediatePropagation();
- e.preventDefault();
- isMouseout = false;
- parent.scrollBy(defineProperty({}, 'd' + ctx.bar.axis.toLowerCase(), stepWithDirection));
- eventCenter(document, touchObj.touchend, endPress, false);
- if (touchObj.touchstart == 'mousedown') {
- var elm = ctx.$refs[type];
- eventCenter(elm, 'mouseenter', enter, false);
- eventCenter(elm, 'mouseleave', leave, false);
- }
- clearTimeout(timeoutId);
- timeoutId = setTimeout(function () /* istanbul ignore next */{
- isMouseDown = true;
- ref(pressing, window);
- }, 500);
- }
- function pressing() /* istanbul ignore next */{
- if (isMouseDown && !isMouseout) {
- parent.scrollBy(defineProperty({}, 'd' + ctx.bar.axis.toLowerCase(), mousedownStepWithDirection), false);
- ref(pressing, window);
- }
- }
- function endPress() {
- clearTimeout(timeoutId);
- isMouseDown = false;
- eventCenter(document, touchObj.touchend, endPress, false, 'off');
- if (touchObj.touchstart == 'mousedown') {
- var elm = ctx.$refs[type];
- eventCenter(elm, 'mouseenter', enter, false, 'off');
- eventCenter(elm, 'mouseleave', leave, false, 'off');
- }
- parent.setClassHook('cliking' + barType + type + 'Button', false);
- }
- function enter() /* istanbul ignore next */{
- isMouseout = false;
- pressing();
- }
- function leave() /* istanbul ignore next */{
- isMouseout = true;
- }
- return start;
- }
- }
- };
- function getBarData(vm, type) {
- var axis = scrollMap[type].axis;
- /** type.charAt(0) = vBar/hBar */
- var barType = type.charAt(0) + 'Bar';
- var hideBar = !vm.bar[barType].state.size || !vm.mergedOptions.scrollPanel['scrolling' + axis] || vm.refreshLoad && type !== 'vertical' || vm.mergedOptions.bar.disable;
- var keepShowRail = vm.mergedOptions.rail.keepShow;
- if (hideBar && !keepShowRail) {
- return null;
- }
- return {
- hideBar: hideBar,
- props: {
- type: type,
- ops: {
- bar: vm.mergedOptions.bar,
- rail: vm.mergedOptions.rail,
- scrollButton: vm.mergedOptions.scrollButton
- },
- state: vm.bar[barType].state,
- hideBar: hideBar
- },
- on: {
- setBarDrag: vm.setBarDrag
- },
- ref: type + 'Bar',
- key: type
- };
- }
- /**
- * create bars
- *
- * @param {any} size
- * @param {any} type
- */
- function createBar(h, vm) {
- var verticalBarProps = getBarData(vm, 'vertical');
- var horizontalBarProps = getBarData(vm, 'horizontal');
- // set class hooks
- vm.setClassHook('hasVBar', !!(verticalBarProps && !verticalBarProps.hideBar));
- vm.setClassHook('hasHBar', !!(horizontalBarProps && !horizontalBarProps.hideBar));
- return [verticalBarProps ? h('bar', _extends({}, verticalBarProps, {
- props: _extends({ otherBarHide: !horizontalBarProps }, verticalBarProps.props)
- })) : null, horizontalBarProps ? h('bar', _extends({}, horizontalBarProps, {
- props: _extends({ otherBarHide: !verticalBarProps }, horizontalBarProps.props)
- })) : null];
- }
- /**
- * This is like a HOC, It extracts the common parts of the
- * native-mode, slide-mode and mix-mode.
- * Each mode must implement the following methods:
- * 1. refreshInternalStatus : use to refresh the component
- * 2. destroy : Destroy some registryed events before component destroy.
- * 3. updateBarStateAndEmitEvent: use to update bar states and emit events.
- */
- var createComponent = function createComponent(_ref) {
- var _render = _ref.render,
- components = _ref.components,
- mixins = _ref.mixins;
- return {
- name: 'vueScroll',
- props: {
- ops: { type: Object }
- },
- components: components,
- mixins: [api].concat(toConsumableArray([].concat(mixins))),
- created: function created() {
- var _this = this;
- /**
- * Begin to merge options
- */
- var _gfc = mergeObject(this.$vuescrollConfig || {}, {});
- var ops = mergeObject(baseConfig, _gfc);
- this.$options.propsData.ops = this.$options.propsData.ops || {};
- Object.keys(this.$options.propsData.ops).forEach(function (key) {
- {
- defineReactive(_this.mergedOptions, key, _this.$options.propsData.ops);
- }
- });
- // from ops to mergedOptions
- mergeObject(ops, this.mergedOptions);
- this._isVuescrollRoot = true;
- this.renderError = validateOps(this.mergedOptions);
- },
- render: function render(h) {
- var vm = this;
- if (vm.renderError) {
- return h('div', [[vm.$slots['default']]]);
- }
- if (!vm.touchManager) vm.touchManager = new touchManager();
- // vuescroll data
- var data = {
- style: {
- height: vm.vuescroll.state.height,
- width: vm.vuescroll.state.width,
- padding: 0,
- position: 'relative',
- overflow: 'hidden'
- },
- class: _extends({ __vuescroll: true }, vm.classHooks)
- };
- var touchObj = vm.touchManager.getTouchObject();
- if (touchObj) {
- var _data$on;
- data.on = (_data$on = {}, defineProperty(_data$on, touchObj.touchenter, function () {
- vm.vuescroll.state.pointerLeave = false;
- vm.updateBarStateAndEmitEvent();
- vm.setClassHook('mouseEnter', true);
- }), defineProperty(_data$on, touchObj.touchleave, function () {
- vm.vuescroll.state.pointerLeave = true;
- vm.hideBar();
- vm.setClassHook('mouseEnter', false);
- }), defineProperty(_data$on, touchObj.touchmove, function () /* istanbul ignore next */{
- vm.vuescroll.state.pointerLeave = false;
- vm.updateBarStateAndEmitEvent();
- }), _data$on);
- }
- var ch = [_render(h, vm)].concat(toConsumableArray(createBar(h, vm)));
- var _customContainer = this.$slots['scroll-container'];
- if (_customContainer) {
- return insertChildrenIntoSlot(h, _customContainer, ch, data);
- }
- return h(
- 'div',
- data,
- [ch]
- );
- },
- mounted: function mounted() {
- var _this2 = this;
- if (!this.renderError) {
- this.initVariables();
- this.initWatchOpsChange();
- // Call external merged Api
- this.refreshInternalStatus();
- this.updatedCbs.push(function () {
- _this2.scrollToAnchor();
- // need to reflow to deal with the
- // latest thing.
- _this2.updateBarStateAndEmitEvent();
- });
- }
- },
- updated: function updated() {
- var _this3 = this;
- this.updatedCbs.forEach(function (cb) {
- cb.call(_this3);
- });
- // Clear
- this.updatedCbs = [];
- },
- beforeDestroy: function beforeDestroy() {
- if (this.destroy) {
- this.destroy();
- }
- },
- /** ------------------------------- Computed ----------------------------- */
- computed: {
- scrollPanelElm: function scrollPanelElm() {
- return this.$refs['scrollPanel']._isVue ? this.$refs['scrollPanel'].$el : this.$refs['scrollPanel'];
- }
- },
- data: function data() {
- return {
- vuescroll: {
- state: {
- isDragging: false,
- pointerLeave: true,
- isRailHover: false,
- /** Default sizeStrategies */
- height: '100%',
- width: '100%',
- // current size strategy
- currentSizeStrategy: 'percent',
- currentScrollState: null,
- currentScrollInfo: null
- }
- },
- bar: {
- vBar: {
- state: {
- posValue: 0,
- size: 0,
- opacity: 0
- }
- },
- hBar: {
- state: {
- posValue: 0,
- size: 0,
- opacity: 0
- }
- }
- },
- mergedOptions: {
- vuescroll: {},
- scrollPanel: {},
- scrollContent: {},
- rail: {},
- bar: {}
- },
- updatedCbs: [],
- renderError: false,
- classHooks: {
- hasVBar: false,
- hasHBar: false,
- vBarVisible: false,
- hBarVisible: false,
- vBarDragging: false,
- hBarDragging: false,
- clikingVerticalStartButton: false,
- clikingVerticalEndButton: false,
- clikingHorizontalStartButton: false,
- clikingHorizontalEndButton: false,
- mouseEnter: false
- }
- };
- },
- /** ------------------------------- Methods -------------------------------- */
- methods: {
- /** ------------------------ Handlers --------------------------- */
- scrollingComplete: function scrollingComplete() {
- this.updateBarStateAndEmitEvent('handle-scroll-complete');
- },
- setBarDrag: function setBarDrag(val) {
- /* istanbul ignore next */
- this.vuescroll.state.isDragging = val;
- },
- setClassHook: function setClassHook(name, value) {
- this.classHooks[name] = value;
- },
- /** ------------------------ Some Helpers --------------------------- */
- /*
- * To have a good ux, instead of hiding bar immediately, we hide bar
- * after some seconds by using this simple debounce-hidebar method.
- */
- showAndDefferedHideBar: function showAndDefferedHideBar(forceHideBar) {
- var _this4 = this;
- this.showBar();
- if (this.timeoutId) {
- clearTimeout(this.timeoutId);
- this.timeoutId = 0;
- }
- this.timeoutId = setTimeout(function () {
- _this4.timeoutId = 0;
- _this4.hideBar(forceHideBar);
- }, this.mergedOptions.bar.showDelay);
- },
- showBar: function showBar() {
- var opacity = this.mergedOptions.bar.opacity;
- this.bar.vBar.state.opacity = opacity;
- this.bar.hBar.state.opacity = opacity;
- },
- hideBar: function hideBar(forceHideBar) {
- var _vuescroll$state = this.vuescroll.state,
- isDragging = _vuescroll$state.isDragging,
- isRailHover = _vuescroll$state.isRailHover;
- /* istanbul ignore next */
- if (isDragging || isRailHover) {
- return;
- }
- if (forceHideBar && !this.mergedOptions.bar.keepShow) {
- this.bar.hBar.state.opacity = 0;
- this.bar.vBar.state.opacity = 0;
- }
- // add isDragging condition
- // to prevent from hiding bar while dragging the bar
- if (!this.mergedOptions.bar.keepShow && !this.vuescroll.state.isDragging) {
- this.bar.vBar.state.opacity = 0;
- this.bar.hBar.state.opacity = 0;
- }
- },
- useNumbericSize: function useNumbericSize() {
- this.vuescroll.state.currentSizeStrategy = 'number';
- var _mergedOptions$scroll = this.mergedOptions.scrollPanel,
- maxHeight = _mergedOptions$scroll.maxHeight,
- maxWidth = _mergedOptions$scroll.maxWidth;
- var _$el$parentNode = this.$el.parentNode,
- parentClientHeight = _$el$parentNode.clientHeight,
- parentClientWidth = _$el$parentNode.clientWidth;
- var _scrollPanelElm = this.scrollPanelElm,
- scrollHeight = _scrollPanelElm.scrollHeight,
- scrollWidth = _scrollPanelElm.scrollWidth;
- var width = void 0;
- var height = void 0;
- if (maxHeight || maxWidth) {
- height = scrollHeight <= maxHeight ? undefined : maxHeight;
- width = scrollWidth <= maxWidth ? undefined : maxWidth;
- } else {
- height = parentClientHeight;
- width = parentClientWidth;
- }
- this.vuescroll.state.height = height ? height + 'px' : undefined;
- this.vuescroll.state.width = width ? width + 'px' : undefined;
- },
- usePercentSize: function usePercentSize() {
- this.vuescroll.state.currentSizeStrategy = 'percent';
- this.vuescroll.state.height = '100%';
- this.vuescroll.state.width = '100%';
- },
- // Set its size to be equal to its parentNode
- setVsSize: function setVsSize() {
- var sizeStrategy = this.mergedOptions.vuescroll.sizeStrategy;
- var _mergedOptions$scroll2 = this.mergedOptions.scrollPanel,
- maxHeight = _mergedOptions$scroll2.maxHeight,
- maxWidth = _mergedOptions$scroll2.maxWidth;
- var _scrollPanelElm2 = this.scrollPanelElm,
- clientHeight = _scrollPanelElm2.clientHeight,
- clientWidth = _scrollPanelElm2.clientWidth;
- if (sizeStrategy == 'number' || maxHeight && clientHeight > maxHeight || maxWidth && clientWidth > maxWidth) {
- this.useNumbericSize();
- } else if (sizeStrategy == 'percent' && clientHeight != maxHeight && clientWidth != maxWidth) {
- this.usePercentSize();
- }
- },
- /** ------------------------ Init --------------------------- */
- initWatchOpsChange: function initWatchOpsChange() {
- var _this5 = this;
- var watchOpts = {
- deep: true,
- sync: true
- };
- this.$watch('mergedOptions', function () {
- setTimeout(function () {
- if (_this5.isSmallChangeThisTick) {
- _this5.isSmallChangeThisTick = false;
- _this5.updateBarStateAndEmitEvent('options-change');
- return;
- }
- _this5.refreshInternalStatus();
- }, 0);
- }, watchOpts);
- /**
- * We also watch `small` changes, and when small changes happen, we send
- * a signal to vuescroll, to tell it:
- * 1. we don't need to registry resize
- * 2. we don't need to registry scroller.
- */
- smallChangeArray.forEach(function (opts) {
- _this5.$watch(opts, function () {
- _this5.isSmallChangeThisTick = true;
- }, watchOpts);
- });
- },
- // scrollTo hash-anchor while mounted component have mounted.
- scrollToAnchor: function scrollToAnchor() /* istanbul ignore next */{
- var validateHashSelector = function validateHashSelector(hash) {
- return (/^#[a-zA-Z_]\d*$/.test(hash)
- );
- };
- var hash = window.location.hash;
- if (!hash || (hash = hash.slice(hash.lastIndexOf('#'))) && !validateHashSelector(hash)) {
- return;
- }
- var elm = document.querySelector(hash);
- if (!isChildInParent(elm, this.$el) || this.mergedOptions.scrollPanel.initialScrollY || this.mergedOptions.scrollPanel.initialScrollX) {
- return;
- }
- this.scrollIntoView(elm);
- }
- /** ------------------------ Registry Resize --------------------------- */
- }
- };
- };
- // begin importing
- var scrollPanel = {
- name: 'scrollPanel',
- props: { ops: { type: Object, required: true } },
- methods: {
- // trigger scrollPanel options initialScrollX,
- // initialScrollY
- updateInitialScroll: function updateInitialScroll() {
- var x = 0;
- var y = 0;
- var parent = getRealParent(this);
- if (this.ops.initialScrollX) {
- x = this.ops.initialScrollX;
- }
- if (this.ops.initialScrollY) {
- y = this.ops.initialScrollY;
- }
- if (x || y) {
- parent.scrollTo({ x: x, y: y });
- }
- }
- },
- mounted: function mounted() {
- var _this = this;
- setTimeout(function () {
- if (!_this._isDestroyed) {
- _this.updateInitialScroll();
- }
- }, 0);
- },
- render: function render(h) {
- // eslint-disable-line
- var data = {
- class: ['__panel'],
- style: {
- position: 'relative',
- boxSizing: 'border-box'
- }
- };
- var parent = getRealParent(this);
- var _customPanel = parent.$slots['scroll-panel'];
- if (_customPanel) {
- return insertChildrenIntoSlot(h, _customPanel, this.$slots.default, data);
- }
- return h(
- 'div',
- data,
- [[this.$slots.default]]
- );
- }
- };
- /**
- * Init following things
- * 1. Component
- * 2. Render
- * 3. Config
- */
- function _install(core, render) {
- var _components;
- var extraConfigs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
- var extraValidators = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
- var components = (_components = {}, defineProperty(_components, scrollPanel.name, scrollPanel), defineProperty(_components, bar.name, bar), _components);
- var opts = {};
- opts.components = components;
- opts.render = render;
- opts.mixins = core;
- var comp = createComponent(opts);
- // Init Config
- extendOpts(extraConfigs, extraValidators);
- return comp;
- }
- /**
- * Get the children of parent those are in viewport
- */
- function getCurrentViewportDom(parent, container) {
- var children = parent.children;
- var domFragment = [];
- var isCurrentview = function isCurrentview(dom) {
- var _dom$getBoundingClien = dom.getBoundingClientRect(),
- left = _dom$getBoundingClien.left,
- top = _dom$getBoundingClien.top,
- width = _dom$getBoundingClien.width,
- height = _dom$getBoundingClien.height;
- var _container$getBoundin = container.getBoundingClientRect(),
- parentLeft = _container$getBoundin.left,
- parentTop = _container$getBoundin.top,
- parentHeight = _container$getBoundin.height,
- parentWidth = _container$getBoundin.width;
- if (left - parentLeft + width > 0 && left - parentLeft < parentWidth && top - parentTop + height > 0 && top - parentTop < parentHeight) {
- return true;
- }
- return false;
- };
- for (var i = 0; i < children.length; i++) {
- var dom = children.item(i);
- if (isCurrentview(dom) && !dom.isResizeElm) {
- domFragment.push(dom);
- }
- }
- return domFragment;
- }
- /**
- * Compatible to scroller's animation function
- */
- function createEasingFunction(easing, easingPattern) {
- return function (time) {
- return easingPattern(easing, time);
- };
- }
- /**
- * Calculate the easing pattern
- * @link https://github.com/cferdinandi/smooth-scroll/blob/master/src/js/smooth-scroll.js
- * modified by wangyi7099
- * @param {String} type Easing pattern
- * @param {Number} time Time animation should take to complete
- * @returns {Number}
- */
- function easingPattern(easing, time) {
- var pattern = null;
- /* istanbul ignore next */
- {
- // Default Easing Patterns
- if (easing === 'easeInQuad') pattern = time * time; // accelerating from zero velocity
- if (easing === 'easeOutQuad') pattern = time * (2 - time); // decelerating to zero velocity
- if (easing === 'easeInOutQuad') pattern = time < 0.5 ? 2 * time * time : -1 + (4 - 2 * time) * time; // acceleration until halfway, then deceleration
- if (easing === 'easeInCubic') pattern = time * time * time; // accelerating from zero velocity
- if (easing === 'easeOutCubic') pattern = --time * time * time + 1; // decelerating to zero velocity
- if (easing === 'easeInOutCubic') pattern = time < 0.5 ? 4 * time * time * time : (time - 1) * (2 * time - 2) * (2 * time - 2) + 1; // acceleration until halfway, then deceleration
- if (easing === 'easeInQuart') pattern = time * time * time * time; // accelerating from zero velocity
- if (easing === 'easeOutQuart') pattern = 1 - --time * time * time * time; // decelerating to zero velocity
- if (easing === 'easeInOutQuart') pattern = time < 0.5 ? 8 * time * time * time * time : 1 - 8 * --time * time * time * time; // acceleration until halfway, then deceleration
- if (easing === 'easeInQuint') pattern = time * time * time * time * time; // accelerating from zero velocity
- if (easing === 'easeOutQuint') pattern = 1 + --time * time * time * time * time; // decelerating to zero velocity
- if (easing === 'easeInOutQuint') pattern = time < 0.5 ? 16 * time * time * time * time * time : 1 + 16 * --time * time * time * time * time; // acceleration until halfway, then deceleration
- }
- return pattern || time; // no easing, no acceleration
- }
- function noop() {
- return true;
- }
- /* istanbul ignore next */
- var now = Date.now || function () {
- return new Date().getTime();
- };
- var ScrollControl = function () {
- function ScrollControl() {
- classCallCheck(this, ScrollControl);
- this.init();
- this.isRunning = false;
- }
- createClass(ScrollControl, [{
- key: 'pause',
- value: function pause() {
- /* istanbul ignore if */
- if (!this.isRunning) return;
- this.isPaused = true;
- }
- }, {
- key: 'stop',
- value: function stop() {
- this.isStopped = true;
- }
- }, {
- key: 'continue',
- value: function _continue() {
- /* istanbul ignore if */
- if (!this.isPaused) return;
- this.isPaused = false;
- this.ts = now() - this.percent * this.spd;
- this.execScroll();
- }
- }, {
- key: 'startScroll',
- value: function startScroll(st, ed, spd) {
- var stepCb = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : noop;
- var completeCb = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : noop;
- var vertifyCb = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : noop;
- var easingMethod = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : noop;
- var df = ed - st;
- var dir = df > 0 ? -1 : 1;
- var nt = now();
- if (!this.isRunning) {
- this.init();
- }
- if (dir != this.dir || nt - this.ts > 200) {
- this.ts = nt;
- this.dir = dir;
- this.st = st;
- this.ed = ed;
- this.df = df;
- } /* istanbul ignore next */else {
- this.df += df;
- }
- this.spd = spd;
- this.completeCb = completeCb;
- this.vertifyCb = vertifyCb;
- this.stepCb = stepCb;
- this.easingMethod = easingMethod;
- if (!this.isRunning) this.execScroll();
- }
- }, {
- key: 'execScroll',
- value: function execScroll() {
- var _this = this;
- if (!this.df) return;
- var percent = this.percent || 0;
- this.percent = 0;
- this.isRunning = true;
- var loop = function loop() {
- /* istanbul ignore if */
- if (!_this.isRunning || !_this.vertifyCb(percent) || _this.isStopped) {
- _this.isRunning = false;
- return;
- }
- percent = (now() - _this.ts) / _this.spd;
- if (_this.isPaused) {
- _this.percent = percent;
- _this.isRunning = false;
- return;
- }
- if (percent < 1) {
- var value = _this.st + _this.df * _this.easingMethod(percent);
- _this.stepCb(value);
- _this.ref(loop);
- } else {
- // trigger complete
- _this.stepCb(_this.st + _this.df);
- _this.completeCb();
- _this.isRunning = false;
- }
- };
- this.ref(loop);
- }
- }, {
- key: 'init',
- value: function init() {
- this.st = 0;
- this.ed = 0;
- this.df = 0;
- this.spd = 0;
- this.ts = 0;
- this.dir = 0;
- this.ref = requestAnimationFrame(window);
- this.isPaused = false;
- this.isStopped = false;
- }
- }]);
- return ScrollControl;
- }();
- function scrollTo(elm, x, y) {
- var speed = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 300;
- var easing = arguments[4];
- var scrollingComplete = arguments[5];
- var scrollLeft = void 0,
- scrollTop = void 0,
- scrollHeight = void 0,
- scrollWidth = void 0,
- clientWidth = void 0,
- clientHeight = void 0;
- var _elm = elm,
- nodeType = _elm.nodeType;
- var scrollX = new ScrollControl();
- var scrollY = new ScrollControl();
- if (!nodeType) {
- warn('You must pass a dom for the first param, ' + 'for window scrolling, ' + 'you can pass document as the first param.');
- return;
- }
- if (nodeType == 9) {
- // document
- elm = elm.scrollingElement;
- }
- var _elm2 = elm;
- scrollLeft = _elm2.scrollLeft;
- scrollTop = _elm2.scrollTop;
- scrollHeight = _elm2.scrollHeight;
- scrollWidth = _elm2.scrollWidth;
- clientWidth = _elm2.clientWidth;
- clientHeight = _elm2.clientHeight;
- if (typeof x === 'undefined') {
- x = scrollLeft;
- } else {
- x = getNumericValue(x, scrollWidth - clientWidth);
- }
- if (typeof y === 'undefined') {
- y = scrollTop;
- } else {
- y = getNumericValue(y, scrollHeight - clientHeight);
- }
- var easingMethod = createEasingFunction(easing, easingPattern);
- scrollX.startScroll(scrollLeft, x, speed, function (dx) {
- elm.scrollLeft = dx;
- }, scrollingComplete, undefined, easingMethod);
- scrollY.startScroll(scrollTop, y, speed, function (dy) {
- elm.scrollTop = dy;
- }, scrollingComplete, undefined, easingMethod);
- }
- var api$1 = {
- mounted: function mounted() {
- // registry scroll
- this.scrollX = new ScrollControl();
- this.scrollY = new ScrollControl();
- },
- methods: {
- nativeStop: function nativeStop() {
- this.scrollX.stop();
- this.scrollY.stop();
- },
- nativePause: function nativePause() {
- this.scrollX.pause();
- this.scrollY.pause();
- },
- nativeContinue: function nativeContinue() {
- this.scrollX.continue();
- this.scrollY.continue();
- },
- nativeScrollTo: function nativeScrollTo(x, y, speed, easing) {
- if (speed === false) ; else if (typeof speed === 'undefined') {
- speed = this.mergedOptions.scrollPanel.speed;
- }
- var elm = this.scrollPanelElm;
- var scrollTop = elm.scrollTop,
- scrollLeft = elm.scrollLeft,
- scrollWidth = elm.scrollWidth,
- clientWidth = elm.clientWidth,
- scrollHeight = elm.scrollHeight,
- clientHeight = elm.clientHeight;
- if (typeof x === 'undefined') {
- x = scrollLeft;
- } else {
- x = getNumericValue(x, scrollWidth - clientWidth);
- }
- if (typeof y === 'undefined') {
- y = scrollTop;
- } else {
- y = getNumericValue(y, scrollHeight - clientHeight);
- }
- if (speed) {
- easing = easing || this.mergedOptions.scrollPanel.easing;
- var easingMethod = createEasingFunction(easing, easingPattern);
- if (x != scrollLeft) {
- this.scrollX.startScroll(scrollLeft, x, speed, function (x) {
- elm.scrollLeft = x;
- }, this.scrollingComplete.bind(this), undefined, easingMethod);
- }
- if (y != scrollTop) {
- this.scrollY.startScroll(scrollTop, y, speed, function (y) {
- elm.scrollTop = y;
- }, this.scrollingComplete.bind(this), undefined, easingMethod);
- }
- } else {
- elm.scrollTop = y;
- elm.scrollLeft = x;
- }
- },
- getCurrentviewDomNative: function getCurrentviewDomNative() {
- var parent = this.scrollContentElm;
- var domFragment = getCurrentViewportDom(parent, this.$el);
- return domFragment;
- }
- }
- };
- function getPanelData(context) {
- // scrollPanel data start
- var data = {
- ref: 'scrollPanel',
- style: {
- height: '100%',
- overflowY: 'scroll',
- overflowX: 'scroll'
- },
- class: [],
- nativeOn: {
- '&scroll': context.handleScroll
- },
- props: {
- ops: context.mergedOptions.scrollPanel
- }
- };
- context.scrollYEnable = true;
- context.scrollXEnable = true;
- data.nativeOn.DOMMouseScroll = data.nativeOn.mousewheel = context.onMouseWheel;
- var _context$mergedOption = context.mergedOptions.scrollPanel,
- scrollingY = _context$mergedOption.scrollingY,
- scrollingX = _context$mergedOption.scrollingX;
- if (!context.bar.hBar.state.size || !scrollingX) {
- context.scrollXEnable = false;
- data.style.overflowX = 'hidden';
- }
- if (!context.bar.vBar.state.size || !scrollingY) {
- context.scrollYEnable = false;
- data.style.overflowY = 'hidden';
- }
- var gutter = getGutter();
- /* istanbul ignore if */
- if (!gutter) {
- createHideBarStyle();
- data.class.push('__hidebar');
- if (isIos()) {
- data.style['-webkit-overflow-scrolling'] = 'touch';
- }
- } else {
- // hide system bar by use a negative value px
- // gutter should be 0 when manually disable scrollingX #14
- if (context.bar.vBar.state.size && context.mergedOptions.scrollPanel.scrollingY) {
- if (context.mergedOptions.scrollPanel.verticalNativeBarPos == 'right') {
- data.style.marginRight = '-' + gutter + 'px';
- } /* istanbul ignore next */else {
- data.style.marginLeft = '-' + gutter + 'px';
- }
- }
- if (context.bar.hBar.state.size && context.mergedOptions.scrollPanel.scrollingX) {
- data.style.height = 'calc(100% + ' + gutter + 'px)';
- }
- }
- // clear legency styles of slide mode...
- data.style.transformOrigin = '';
- data.style.transform = '';
- return data;
- }
- /**
- * create a scrollPanel
- *
- * @param {any} size
- * @param {any} context
- * @returns
- */
- function createPanel(h, context) {
- var data = {};
- data = getPanelData(context);
- return h(
- 'scrollPanel',
- data,
- [getPanelChildren(h, context)]
- );
- }
- function getPanelChildren(h, context) {
- var viewStyle = {
- position: 'relative',
- 'box-sizing': 'border-box',
- 'min-width': '100%',
- 'min-height': '100%'
- };
- var data = {
- style: viewStyle,
- ref: 'scrollContent',
- class: '__view'
- };
- var _customContent = context.$slots['scroll-content'];
- if (context.mergedOptions.scrollPanel.scrollingX) {
- viewStyle.width = getComplitableStyle('width', 'fit-content');
- } else {
- data.style['width'] = '100%';
- }
- if (context.mergedOptions.scrollPanel.padding) {
- data.style.paddingRight = context.mergedOptions.rail.size;
- }
- if (_customContent) {
- return insertChildrenIntoSlot(h, _customContent, context.$slots.default, data);
- }
- return h(
- 'div',
- data,
- [context.$slots.default]
- );
- }
- // detect content size change
- function installResizeDetection(element, callback) {
- return injectObject(element, callback);
- }
- function injectObject(element, callback) {
- if (element.hasResized) {
- return;
- }
- var OBJECT_STYLE = 'display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; padding: 0; margin: 0; opacity: 0; z-index: -1000; pointer-events: none;';
- // define a wrap due to ie's zIndex bug
- var objWrap = document.createElement('div');
- objWrap.style.cssText = OBJECT_STYLE;
- var object = document.createElement('object');
- object.style.cssText = OBJECT_STYLE;
- object.type = 'text/html';
- object.tabIndex = -1;
- object.onload = function () {
- eventCenter(object.contentDocument.defaultView, 'resize', callback);
- };
- // https://github.com/wnr/element-resize-detector/blob/aafe9f7ea11d1eebdab722c7c5b86634e734b9b8/src/detection-strategy/object.js#L159
- if (!isIE()) {
- object.data = 'about:blank';
- }
- objWrap.isResizeElm = true;
- objWrap.appendChild(object);
- element.appendChild(objWrap);
- if (isIE()) {
- object.data = 'about:blank';
- }
- return function destroy() {
- if (object.contentDocument) {
- eventCenter(object.contentDocument.defaultView, 'resize', callback, 'off');
- }
- element.removeChild(objWrap);
- element.hasResized = false;
- };
- }
- /**
- * These mixes is exclusive for native mode
- */
- var update = {
- methods: {
- updateNativeModeBarState: function updateNativeModeBarState() {
- var container = this.scrollPanelElm;
- var isPercent = this.vuescroll.state.currentSizeStrategy == 'percent';
- var _vuescroll$state = this.vuescroll.state,
- width = _vuescroll$state.width,
- height = _vuescroll$state.height;
- var clientWidth = isPercent || !width ? container.clientWidth : width.slice(0, -2); // xxxpx ==> xxx
- var clientHeight = isPercent || !height ? container.clientHeight : height.slice(0, -2);
- var heightPercentage = clientHeight / container.scrollHeight;
- var widthPercentage = clientWidth / container.scrollWidth;
- this.bar.vBar.state.posValue = container.scrollTop * 100 / clientHeight;
- this.bar.hBar.state.posValue = container.scrollLeft * 100 / clientWidth;
- this.bar.vBar.state.size = heightPercentage < 1 ? heightPercentage : 0;
- this.bar.hBar.state.size = widthPercentage < 1 ? widthPercentage : 0;
- },
- getNativePosition: function getNativePosition() {
- return {
- scrollTop: this.scrollPanelElm.scrollTop,
- scrollLeft: this.scrollPanelElm.scrollLeft
- };
- },
- css: function css(dom, style) /* istanbul ignore next */{
- return window.getComputedStyle(dom)[style];
- },
- checkScrollable: function checkScrollable(e, deltaX, deltaY) /* istanbul ignore next */{
- var scrollable = false;
- // check mouse point scrollable.
- var dom = e.target ? e.target : e;
- while (dom && dom.nodeType == 1 && dom !== this.scrollPanelElm.parentNode && !/^BODY|HTML/.test(dom.nodeName)) {
- var ov = this.css(dom, 'overflow') || '';
- if (/scroll|auto/.test(ov)) {
- var _getScrollProcess = this.getScrollProcess(dom),
- v = _getScrollProcess.v,
- h = _getScrollProcess.h;
- var isScrollX = this.css(dom, 'overflowX') !== 'hidden';
- var isScrollY = this.css(dom, 'overflowY') !== 'hidden';
- if (isScrollX && (deltaX < 0 && h > 0 || deltaX > 0 && h < 1) || isScrollY && (deltaY < 0 && v > 0 || deltaY > 0 && v < 1)) {
- scrollable = dom == this.scrollPanelElm;
- break;
- }
- }
- dom = dom.parentNode ? dom.parentNode : false;
- }
- return scrollable;
- },
- onMouseWheel: function onMouseWheel(event) /* istanbul ignore next */{
- var _mergedOptions$vuescr = this.mergedOptions.vuescroll,
- isReverse = _mergedOptions$vuescr.wheelDirectionReverse,
- duration = _mergedOptions$vuescr.wheelScrollDuration,
- checkShiftKey = _mergedOptions$vuescr.checkShiftKey,
- locking = _mergedOptions$vuescr.locking,
- deltaPercent = _mergedOptions$vuescr.deltaPercent;
- var deltaX = void 0;
- var deltaY = void 0;
- if (event.wheelDelta) {
- if (event.deltaY || event.deltaX) {
- deltaX = event.deltaX * deltaPercent;
- deltaY = event.deltaY * deltaPercent;
- if (locking) {
- if (Math.abs(event.deltaX) > Math.abs(event.deltaY)) {
- deltaY = 0;
- } else {
- deltaX = 0;
- }
- }
- } else {
- deltaX = 0;
- deltaY = -1 * event.wheelDelta / 2;
- }
- } else if (event.detail) {
- deltaY = deltaX = event.detail * 16;
- // horizontal scroll
- if (event.axis == 1) {
- deltaY = 0;
- } else if (event.axis == 2) {
- // vertical scroll
- deltaX = 0;
- }
- }
- if (checkShiftKey && event.shiftKey) {
- // swap value
- deltaX ^= deltaY;
- deltaY ^= deltaX;
- deltaX ^= deltaY;
- }
- if (isReverse) {
- deltaX ^= deltaY;
- deltaY ^= deltaX;
- deltaX ^= deltaY;
- }
- if (this.checkScrollable(event, deltaX, deltaY)) {
- event.stopPropagation();
- event.preventDefault();
- this.scrollBy({ dx: deltaX, dy: deltaY }, duration);
- }
- }
- },
- computed: {
- scrollContentElm: function scrollContentElm() {
- return this.$refs['scrollContent']._isVue ? this.$refs['scrollContent'].$el : this.$refs['scrollContent'];
- }
- }
- };
- var mixins = [api$1, update];
- var core = {
- mixins: mixins,
- methods: {
- destroy: function destroy() {
- /* istanbul ignore next */
- if (this.destroyResize) {
- this.destroyResize();
- }
- },
- getCurrentviewDom: function getCurrentviewDom() {
- return this.getCurrentviewDomNative();
- },
- internalScrollTo: function internalScrollTo(destX, destY, animate, easing) {
- this.nativeScrollTo(destX, destY, animate, easing);
- },
- internalStop: function internalStop() {
- this.nativeStop();
- },
- internalPause: function internalPause() {
- this.nativePause();
- },
- internalContinue: function internalContinue() {
- this.nativeContinue();
- },
- handleScroll: function handleScroll(nativeEvent) {
- this.updateBarStateAndEmitEvent('handle-scroll', nativeEvent);
- },
- updateBarStateAndEmitEvent: function updateBarStateAndEmitEvent(eventType) {
- var nativeEvent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
- this.updateNativeModeBarState();
- if (eventType) {
- this.emitEvent(eventType, nativeEvent);
- }
- if (this.mergedOptions.bar.onlyShowBarOnScroll) {
- if (eventType == 'handle-scroll' || eventType == 'handle-resize' || eventType == 'refresh-status' || eventType == 'window-resize' || eventType == 'options-change') {
- this.showAndDefferedHideBar(true /* forceHideBar: true */);
- }
- } else {
- this.showAndDefferedHideBar();
- }
- },
- getScrollProcess: function getScrollProcess(elm) {
- var _ref = elm || this.scrollPanelElm,
- scrollHeight = _ref.scrollHeight,
- scrollWidth = _ref.scrollWidth,
- clientHeight = _ref.clientHeight,
- clientWidth = _ref.clientWidth,
- scrollTop = _ref.scrollTop,
- scrollLeft = _ref.scrollLeft;
- var v = Math.min(scrollTop / (scrollHeight - clientHeight || 1), 1);
- var h = Math.min(scrollLeft / (scrollWidth - clientWidth || 1), 1);
- return {
- v: v,
- h: h
- };
- },
- emitEvent: function emitEvent(eventType) {
- var nativeEvent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
- var _scrollPanelElm = this.scrollPanelElm,
- scrollTop = _scrollPanelElm.scrollTop,
- scrollLeft = _scrollPanelElm.scrollLeft;
- var vertical = {
- type: 'vertical'
- };
- var horizontal = {
- type: 'horizontal'
- };
- var _getScrollProcess = this.getScrollProcess(),
- v = _getScrollProcess.v,
- h = _getScrollProcess.h;
- vertical.process = v;
- horizontal.process = h;
- vertical['barSize'] = this.bar.vBar.state.size;
- horizontal['barSize'] = this.bar.hBar.state.size;
- vertical['scrollTop'] = scrollTop;
- horizontal['scrollLeft'] = scrollLeft;
- this.$emit(eventType, vertical, horizontal, nativeEvent);
- },
- initVariables: function initVariables() {
- this.$el._isVuescroll = true;
- },
- refreshInternalStatus: function refreshInternalStatus() {
- // 1.set vuescroll height or width according to
- // sizeStrategy
- this.setVsSize();
- // 2. registry resize event
- this.registryResize();
- // 3. update scrollbar's height/width
- this.updateBarStateAndEmitEvent('refresh-status');
- },
- registryResize: function registryResize() {
- var _this = this;
- var resizeEnable = this.mergedOptions.vuescroll.detectResize;
- /* istanbul ignore next */
- if (this.destroyResize && resizeEnable) {
- return;
- }
- if (this.destroyResize) {
- this.destroyResize();
- }
- if (!resizeEnable) {
- return;
- }
- var contentElm = this.scrollContentElm;
- var vm = this;
- var handleWindowResize = function handleWindowResize() /* istanbul ignore next */{
- vm.updateBarStateAndEmitEvent('window-resize');
- };
- var handleDomResize = function handleDomResize() {
- var currentSize = {};
- currentSize['width'] = _this.scrollPanelElm.scrollWidth;
- currentSize['height'] = _this.scrollPanelElm.scrollHeight;
- _this.updateBarStateAndEmitEvent('handle-resize', currentSize);
- // Since content sie changes, we should tell parent to set
- // correct size to fit content's size
- _this.setVsSize();
- };
- window.addEventListener('resize', handleWindowResize, false);
- var destroyDomResize = installResizeDetection(contentElm, handleDomResize);
- var destroyWindowResize = function destroyWindowResize() {
- window.removeEventListener('resize', handleWindowResize, false);
- };
- this.destroyResize = function () {
- destroyWindowResize();
- destroyDomResize();
- _this.destroyResize = null;
- };
- },
- getPosition: function getPosition() {
- return this.getNativePosition();
- }
- }
- };
- var config = {
- vuescroll: {
- wheelScrollDuration: 0,
- wheelDirectionReverse: false,
- checkShiftKey: true,
- deltaPercent: 1
- }
- };
- var component = _install(core, createPanel, [config]);
- function install(Vue) {
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- Vue.component(opts.name || component.name, component);
- Vue.prototype.$vuescrollConfig = opts.ops || {};
- }
- var Vuescroll = _extends({
- install: install,
- version: '4.18.1',
- refreshAll: refreshAll,
- scrollTo: scrollTo
- }, component);
- /* istanbul ignore if */
- if (typeof window !== 'undefined' && window.Vue) {
- window.Vue.use(Vuescroll);
- }
- return Vuescroll;
- })));
|