vuescroll.js 167 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121
  1. /*
  2. * Vuescroll v4.18.1
  3. * (c) 2018-2023 Yi(Yves) Wang
  4. * Released under the MIT License
  5. * Github: https://github.com/YvesCoding/vuescroll
  6. * Website: http://vuescrolljs.yvescoding.me/
  7. */
  8. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('vue')) :
  10. typeof define === 'function' && define.amd ? define(['vue'], factory) :
  11. (global = global || self, global.vuescroll = factory(global.Vue));
  12. }(this, (function (Vue) { 'use strict';
  13. Vue = Vue && Object.prototype.hasOwnProperty.call(Vue, 'default') ? Vue['default'] : Vue;
  14. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  15. return typeof obj;
  16. } : function (obj) {
  17. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  18. };
  19. var classCallCheck = function (instance, Constructor) {
  20. if (!(instance instanceof Constructor)) {
  21. throw new TypeError("Cannot call a class as a function");
  22. }
  23. };
  24. var createClass = function () {
  25. function defineProperties(target, props) {
  26. for (var i = 0; i < props.length; i++) {
  27. var descriptor = props[i];
  28. descriptor.enumerable = descriptor.enumerable || false;
  29. descriptor.configurable = true;
  30. if ("value" in descriptor) descriptor.writable = true;
  31. Object.defineProperty(target, descriptor.key, descriptor);
  32. }
  33. }
  34. return function (Constructor, protoProps, staticProps) {
  35. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  36. if (staticProps) defineProperties(Constructor, staticProps);
  37. return Constructor;
  38. };
  39. }();
  40. var defineProperty = function (obj, key, value) {
  41. if (key in obj) {
  42. Object.defineProperty(obj, key, {
  43. value: value,
  44. enumerable: true,
  45. configurable: true,
  46. writable: true
  47. });
  48. } else {
  49. obj[key] = value;
  50. }
  51. return obj;
  52. };
  53. var _extends = Object.assign || function (target) {
  54. for (var i = 1; i < arguments.length; i++) {
  55. var source = arguments[i];
  56. for (var key in source) {
  57. if (Object.prototype.hasOwnProperty.call(source, key)) {
  58. target[key] = source[key];
  59. }
  60. }
  61. }
  62. return target;
  63. };
  64. var toConsumableArray = function (arr) {
  65. if (Array.isArray(arr)) {
  66. for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
  67. return arr2;
  68. } else {
  69. return Array.from(arr);
  70. }
  71. };
  72. function isIE() {
  73. /* istanbul ignore if */
  74. if (isServer()) return false;
  75. var agent = navigator.userAgent.toLowerCase();
  76. return agent.indexOf('msie') !== -1 || agent.indexOf('trident') !== -1 || agent.indexOf(' edge/') !== -1;
  77. }
  78. var isIos = function isIos() {
  79. /* istanbul ignore if */
  80. if (isServer()) return false;
  81. var u = navigator.userAgent;
  82. return !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  83. };
  84. /* istanbul ignore next */
  85. var isServer = function isServer() {
  86. return Vue.prototype.$isServer;
  87. };
  88. var touchManager = function () {
  89. function touchManager() {
  90. classCallCheck(this, touchManager);
  91. }
  92. createClass(touchManager, [{
  93. key: 'getEventObject',
  94. value: function getEventObject(originEvent) {
  95. return this.touchObject ? this.isTouch ? originEvent.touches : [originEvent] : null;
  96. }
  97. }, {
  98. key: 'getTouchObject',
  99. value: function getTouchObject() /* istanbul ignore next */{
  100. if (isServer()) return null;
  101. this.isTouch = false;
  102. var agent = navigator.userAgent,
  103. platform = navigator.platform,
  104. touchObject = {};
  105. touchObject.touch = !!('ontouchstart' in window && !window.opera || 'msmaxtouchpoints' in window.navigator || 'maxtouchpoints' in window.navigator || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0);
  106. touchObject.nonDeskTouch = touchObject.touch && !/win32/i.test(platform) || touchObject.touch && /win32/i.test(platform) && /mobile/i.test(agent);
  107. 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';
  108. switch (touchObject.eventType) {
  109. case 'mouse':
  110. touchObject.touchstart = 'mousedown';
  111. touchObject.touchend = 'mouseup';
  112. touchObject.touchmove = 'mousemove';
  113. touchObject.touchenter = 'mouseenter';
  114. touchObject.touchmove = 'mousemove';
  115. touchObject.touchleave = 'mouseleave';
  116. break;
  117. case 'touch':
  118. touchObject.touchstart = 'touchstart';
  119. touchObject.touchend = 'touchend';
  120. touchObject.touchmove = 'touchmove';
  121. touchObject.touchcancel = 'touchcancel';
  122. touchObject.touchenter = 'touchstart';
  123. touchObject.touchmove = 'touchmove';
  124. touchObject.touchleave = 'touchend';
  125. this.isTouch = true;
  126. break;
  127. case 'mstouchpoints':
  128. touchObject.touchstart = 'MSPointerDown';
  129. touchObject.touchend = 'MSPointerUp';
  130. touchObject.touchmove = 'MSPointerMove';
  131. touchObject.touchcancel = 'MSPointerCancel';
  132. touchObject.touchenter = 'MSPointerDown';
  133. touchObject.touchmove = 'MSPointerMove';
  134. touchObject.touchleave = 'MSPointerUp';
  135. break;
  136. case 'touchpoints':
  137. touchObject.touchstart = 'pointerdown';
  138. touchObject.touchend = 'pointerup';
  139. touchObject.touchmove = 'pointermove';
  140. touchObject.touchcancel = 'pointercancel';
  141. touchObject.touchenter = 'pointerdown';
  142. touchObject.touchmove = 'pointermove';
  143. touchObject.touchleave = 'pointerup';
  144. break;
  145. }
  146. return this.touchObject = touchObject;
  147. }
  148. }]);
  149. return touchManager;
  150. }();
  151. /**
  152. * ZoomManager
  153. * Get the browser zoom ratio
  154. */
  155. var ZoomManager = function () {
  156. function ZoomManager() {
  157. var _this = this;
  158. classCallCheck(this, ZoomManager);
  159. this.originPixelRatio = this.getRatio();
  160. this.lastPixelRatio = this.originPixelRatio;
  161. window.addEventListener('resize', function () {
  162. _this.lastPixelRatio = _this.getRatio();
  163. });
  164. }
  165. createClass(ZoomManager, [{
  166. key: 'getRatio',
  167. value: function getRatio() {
  168. var ratio = 0;
  169. var screen = window.screen;
  170. var ua = navigator.userAgent.toLowerCase();
  171. if (window.devicePixelRatio !== undefined) {
  172. ratio = window.devicePixelRatio;
  173. } else if (~ua.indexOf('msie')) {
  174. if (screen.deviceXDPI && screen.logicalXDPI) {
  175. ratio = screen.deviceXDPI / screen.logicalXDPI;
  176. }
  177. } else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
  178. ratio = window.outerWidth / window.innerWidth;
  179. }
  180. if (ratio) {
  181. ratio = Math.round(ratio * 100);
  182. }
  183. return ratio;
  184. }
  185. }, {
  186. key: 'getRatioBetweenPreAndCurrent',
  187. value: function getRatioBetweenPreAndCurrent() {
  188. return this.originPixelRatio / this.lastPixelRatio;
  189. }
  190. }]);
  191. return ZoomManager;
  192. }();
  193. function deepCopy(from, to, shallow) {
  194. if (shallow && isUndef(to)) {
  195. return from;
  196. }
  197. if (isArray(from)) {
  198. to = [];
  199. from.forEach(function (item, index) {
  200. to[index] = deepCopy(item, to[index]);
  201. });
  202. } else if (from) {
  203. if (!isPlainObj(from)) {
  204. return from;
  205. }
  206. to = {};
  207. for (var key in from) {
  208. to[key] = _typeof(from[key]) === 'object' ? deepCopy(from[key], to[key]) : from[key];
  209. }
  210. }
  211. return to;
  212. }
  213. function mergeObject(from, to, force, shallow) {
  214. if (shallow && isUndef(to)) {
  215. return from;
  216. }
  217. to = to || {};
  218. if (isArray(from)) {
  219. if (!isArray(to) && force) {
  220. to = [];
  221. }
  222. if (isArray(to)) {
  223. from.forEach(function (item, index) {
  224. to[index] = mergeObject(item, to[index], force, shallow);
  225. });
  226. }
  227. } else if (from) {
  228. if (!isPlainObj(from)) {
  229. if (force) {
  230. to = from;
  231. }
  232. } else {
  233. for (var key in from) {
  234. if (_typeof(from[key]) === 'object') {
  235. if (isUndef(to[key])) {
  236. to[key] = deepCopy(from[key], to[key], shallow);
  237. } else {
  238. mergeObject(from[key], to[key], force, shallow);
  239. }
  240. } else {
  241. if (isUndef(to[key]) || force) to[key] = from[key];
  242. }
  243. }
  244. }
  245. }
  246. return to;
  247. }
  248. function defineReactive(target, key, source, souceKey) {
  249. /* istanbul ignore if */
  250. if (!source[key] && typeof source !== 'function') {
  251. return;
  252. }
  253. souceKey = souceKey || key;
  254. Object.defineProperty(target, key, {
  255. get: function get() {
  256. return source[souceKey];
  257. },
  258. configurable: true
  259. });
  260. }
  261. var scrollBarWidth = void 0;
  262. var zoomManager = void 0;
  263. function getGutter() {
  264. /* istanbul ignore next */
  265. if (isServer()) return 0;
  266. if (!zoomManager) {
  267. zoomManager = new ZoomManager();
  268. }
  269. if (scrollBarWidth !== undefined) return scrollBarWidth * zoomManager.getRatioBetweenPreAndCurrent();
  270. var outer = document.createElement('div');
  271. outer.style.visibility = 'hidden';
  272. outer.style.width = '100px';
  273. outer.style.position = 'absolute';
  274. outer.style.top = '-9999px';
  275. document.body.appendChild(outer);
  276. var widthNoScroll = outer.offsetWidth;
  277. outer.style.overflow = 'scroll';
  278. var inner = document.createElement('div');
  279. inner.style.width = '100%';
  280. outer.appendChild(inner);
  281. var widthWithScroll = inner.offsetWidth;
  282. outer.parentNode.removeChild(outer);
  283. scrollBarWidth = widthNoScroll - widthWithScroll;
  284. // multi the browser zoom
  285. if (!zoomManager) {
  286. zoomManager = new ZoomManager();
  287. }
  288. return scrollBarWidth * zoomManager.getRatioBetweenPreAndCurrent();
  289. }
  290. function eventCenter(dom, eventName, hander) {
  291. var capture = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  292. var type = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'on';
  293. type == 'on' ? dom.addEventListener(eventName, hander, capture) : dom.removeEventListener(eventName, hander, capture);
  294. }
  295. var error = function error(msg) {
  296. console.error('[vuescroll] ' + msg);
  297. };
  298. var warn = function warn(msg) {
  299. console.warn('[vuescroll] ' + msg);
  300. };
  301. function isChildInParent(child, parent) {
  302. var flag = false;
  303. if (!child || !parent) {
  304. return flag;
  305. }
  306. while (child.parentNode !== parent && child.parentNode.nodeType !== 9 && !child.parentNode._isVuescroll) {
  307. child = child.parentNode;
  308. }
  309. if (child.parentNode == parent) {
  310. flag = true;
  311. }
  312. return flag;
  313. }
  314. function getPrefix(global) {
  315. var docStyle = document.documentElement.style;
  316. var engine;
  317. /* istanbul ignore if */
  318. if (global.opera && Object.prototype.toString.call(opera) === '[object Opera]') {
  319. engine = 'presto';
  320. } /* istanbul ignore next */else if ('MozAppearance' in docStyle) {
  321. engine = 'gecko';
  322. } else if ('WebkitAppearance' in docStyle) {
  323. engine = 'webkit';
  324. } /* istanbul ignore next */else if (typeof navigator.cpuClass === 'string') {
  325. engine = 'trident';
  326. }
  327. var vendorPrefix = {
  328. trident: 'ms',
  329. gecko: 'moz',
  330. webkit: 'webkit',
  331. presto: 'O'
  332. }[engine];
  333. return vendorPrefix;
  334. }
  335. function getComplitableStyle(property, value) {
  336. /* istanbul ignore if */
  337. if (isServer()) return false;
  338. var compatibleValue = '-' + getPrefix(window) + '-' + value;
  339. var testElm = document.createElement('div');
  340. testElm.style[property] = compatibleValue;
  341. if (testElm.style[property] == compatibleValue) {
  342. return compatibleValue;
  343. }
  344. /* istanbul ignore next */
  345. return false;
  346. }
  347. /**
  348. * Insert children into user-passed slot at vnode level
  349. */
  350. function insertChildrenIntoSlot(h) {
  351. var parentVnode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  352. var childVNode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  353. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  354. var swapChildren = arguments[4];
  355. /* istanbul ignore if */
  356. if (parentVnode && parentVnode.length > 1) {
  357. return swapChildren ? [].concat(toConsumableArray(childVNode), toConsumableArray(parentVnode)) : [].concat(toConsumableArray(parentVnode), toConsumableArray(childVNode));
  358. }
  359. parentVnode = parentVnode[0];
  360. var _getVnodeInfo = getVnodeInfo(parentVnode),
  361. ch = _getVnodeInfo.ch,
  362. tag = _getVnodeInfo.tag,
  363. isComponent = _getVnodeInfo.isComponent;
  364. if (isComponent) {
  365. parentVnode.data = mergeObject({ attrs: parentVnode.componentOptions.propsData }, parentVnode.data, false, // force: false
  366. true // shallow: true
  367. );
  368. }
  369. ch = swapChildren ? [].concat(toConsumableArray(childVNode), toConsumableArray(ch)) : [].concat(toConsumableArray(ch), toConsumableArray(childVNode));
  370. delete parentVnode.data.slot;
  371. return h(tag, mergeObject(data, parentVnode.data, false, true), ch);
  372. }
  373. /**
  374. * Get the info of a vnode,
  375. * vnode must be parentVnode
  376. */
  377. function getVnodeInfo(vnode) {
  378. if (!vnode || vnode.length > 1) return {};
  379. vnode = vnode[0] ? vnode[0] : vnode;
  380. var isComponent = !!vnode.componentOptions;
  381. var ch = void 0;
  382. var tag = void 0;
  383. if (isComponent) {
  384. ch = vnode.componentOptions.children || [];
  385. tag = vnode.componentOptions.tag;
  386. } else {
  387. ch = vnode.children || [];
  388. tag = vnode.tag;
  389. }
  390. return {
  391. isComponent: isComponent,
  392. ch: ch,
  393. tag: tag
  394. };
  395. }
  396. /**
  397. * Get the vuescroll instance instead of
  398. * user pass component like slot.
  399. */
  400. function getRealParent(ctx) {
  401. var parent = ctx.$parent;
  402. if (!parent._isVuescrollRoot && parent) {
  403. parent = parent.$parent;
  404. }
  405. return parent;
  406. }
  407. var isArray = function isArray(_) {
  408. return Array.isArray(_);
  409. };
  410. var isPlainObj = function isPlainObj(_) {
  411. return Object.prototype.toString.call(_) == '[object Object]';
  412. };
  413. var isUndef = function isUndef(_) {
  414. return typeof _ === 'undefined';
  415. };
  416. function getNumericValue(distance, size) {
  417. var number = void 0;
  418. if (!(number = /(-?\d+(?:\.\d+?)?)%$/.exec(distance))) {
  419. number = distance - 0;
  420. } else {
  421. number = number[1] - 0;
  422. number = size * number / 100;
  423. }
  424. return number;
  425. }
  426. function createStyle(styleId, cssText) {
  427. /* istanbul ignore if */
  428. if (isServer() || document.getElementById(styleId)) {
  429. return;
  430. }
  431. var head = document.head || doc.getElementsByTagName('head')[0];
  432. var style = document.createElement('style');
  433. style.id = styleId;
  434. style.type = 'text/css';
  435. /* istanbul ignore if */
  436. if (style.styleSheet) {
  437. style.styleSheet.cssText = cssText;
  438. } else {
  439. style.appendChild(document.createTextNode(cssText));
  440. }
  441. head.appendChild(style);
  442. }
  443. // Hide the ios native scrollbar.
  444. function createHideBarStyle() {
  445. /* istanbul ignore next */
  446. {
  447. var cssText = '.__hidebar::-webkit-scrollbar {\n width: 0;\n height: 0;\n }';
  448. createStyle('vuescroll-hide-ios-bar', cssText);
  449. }
  450. }
  451. // create slide mode style
  452. function createSlideModeStyle() {
  453. var cssText = '\n @-webkit-keyframes loading-rotate {\n to {\n -webkit-transform: rotate(1turn);\n transform: rotate(1turn);\n }\n }\n\n @keyframes loading-rotate {\n to {\n -webkit-transform: rotate(1turn);\n transform: rotate(1turn);\n }\n }\n\n @-webkit-keyframes loading-wipe {\n 0% {\n stroke-dasharray: 1, 200;\n stroke-dashoffset: 0;\n }\n 50% {\n stroke-dasharray: 90, 150;\n stroke-dashoffset: -40px;\n }\n to {\n stroke-dasharray: 90, 150;\n stroke-dashoffset: -120px;\n }\n }\n\n @keyframes loading-wipe {\n 0% {\n stroke-dasharray: 1, 200;\n stroke-dashoffset: 0;\n }\n 50% {\n stroke-dasharray: 90, 150;\n stroke-dashoffset: -40px;\n }\n to {\n stroke-dasharray: 90, 150;\n stroke-dashoffset: -120px;\n }\n }\n\n .__vuescroll .__refresh,\n .__vuescroll .__load {\n position: absolute;\n width: 100%;\n color: black;\n height: 50px;\n line-height: 50px;\n text-align: center;\n font-size: 16px;\n }\n .__vuescroll .__refresh svg,\n .__vuescroll .__load svg {\n margin-right: 10px;\n width: 25px;\n height: 25px;\n vertical-align: sub;\n }\n .__vuescroll .__refresh svg.active,\n .__vuescroll .__load svg.active {\n transition: all 0.2s;\n }\n .__vuescroll .__refresh svg.active.deactive,\n .__vuescroll .__load svg.active.deactive {\n transform: rotateZ(180deg);\n }\n .__vuescroll .__refresh svg path,\n .__vuescroll .__refresh svg rect,\n .__vuescroll .__load svg path,\n .__vuescroll .__load svg rect {\n fill: #20a0ff;\n }\n .__vuescroll .__refresh svg.start,\n .__vuescroll .__load svg.start {\n stroke: #343640;\n stroke-width: 4;\n stroke-linecap: round;\n -webkit-animation: loading-rotate 2s linear infinite;\n animation: loading-rotate 2s linear infinite;\n }\n .__vuescroll .__refresh svg.start .bg-path,\n .__vuescroll .__load svg.start .bg-path {\n stroke: #f2f2f2;\n fill: none;\n }\n .__vuescroll .__refresh svg.start .active-path,\n .__vuescroll .__load svg.start .active-path {\n stroke: #20a0ff;\n fill: none;\n stroke-dasharray: 90, 150;\n stroke-dashoffset: 0;\n -webkit-animation: loading-wipe 1.5s ease-in-out infinite;\n animation: loading-wipe 1.5s ease-in-out infinite;\n }\n ';
  454. createStyle('vuescroll-silde-mode-style', cssText);
  455. }
  456. var api = {
  457. mounted: function mounted() {
  458. vsInstances[this._uid] = this;
  459. },
  460. beforeDestroy: function beforeDestroy() {
  461. delete vsInstances[this._uid];
  462. },
  463. methods: {
  464. // public api
  465. scrollTo: function scrollTo(_ref, speed, easing) {
  466. var x = _ref.x,
  467. y = _ref.y;
  468. // istanbul ignore if
  469. if (speed === true || typeof speed == 'undefined') {
  470. speed = this.mergedOptions.scrollPanel.speed;
  471. }
  472. this.internalScrollTo(x, y, speed, easing);
  473. },
  474. scrollBy: function scrollBy(_ref2, speed, easing) {
  475. var _ref2$dx = _ref2.dx,
  476. dx = _ref2$dx === undefined ? 0 : _ref2$dx,
  477. _ref2$dy = _ref2.dy,
  478. dy = _ref2$dy === undefined ? 0 : _ref2$dy;
  479. var _getPosition = this.getPosition(),
  480. _getPosition$scrollLe = _getPosition.scrollLeft,
  481. scrollLeft = _getPosition$scrollLe === undefined ? 0 : _getPosition$scrollLe,
  482. _getPosition$scrollTo = _getPosition.scrollTop,
  483. scrollTop = _getPosition$scrollTo === undefined ? 0 : _getPosition$scrollTo;
  484. if (dx) {
  485. scrollLeft += getNumericValue(dx, this.scrollPanelElm.scrollWidth - this.$el.clientWidth);
  486. }
  487. if (dy) {
  488. scrollTop += getNumericValue(dy, this.scrollPanelElm.scrollHeight - this.$el.clientHeight);
  489. }
  490. this.internalScrollTo(scrollLeft, scrollTop, speed, easing);
  491. },
  492. scrollIntoView: function scrollIntoView(elm) {
  493. var animate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  494. var parentElm = this.$el;
  495. if (typeof elm === 'string') {
  496. elm = parentElm.querySelector(elm);
  497. }
  498. if (!isChildInParent(elm, parentElm)) {
  499. warn('The element or selector you passed is not the element of Vuescroll, please pass the element that is in Vuescroll to scrollIntoView API. ');
  500. return;
  501. }
  502. // parent elm left, top
  503. var _$el$getBoundingClien = this.$el.getBoundingClientRect(),
  504. left = _$el$getBoundingClien.left,
  505. top = _$el$getBoundingClien.top;
  506. // child elm left, top
  507. var _elm$getBoundingClien = elm.getBoundingClientRect(),
  508. childLeft = _elm$getBoundingClien.left,
  509. childTop = _elm$getBoundingClien.top;
  510. var diffX = left - childLeft;
  511. var diffY = top - childTop;
  512. this.scrollBy({
  513. dx: -diffX,
  514. dy: -diffY
  515. }, animate);
  516. },
  517. refresh: function refresh() {
  518. this.refreshInternalStatus();
  519. // refresh again to keep status is correct
  520. this.$nextTick(this.refreshInternalStatus);
  521. }
  522. }
  523. };
  524. /** Public Api */
  525. /**
  526. * Refresh all
  527. */
  528. var vsInstances = {};
  529. function refreshAll() {
  530. for (var vs in vsInstances) {
  531. vsInstances[vs].refresh();
  532. }
  533. }
  534. var baseConfig = {
  535. // vuescroll
  536. vuescroll: {
  537. // vuescroll's size(height/width) should be a percent(100%)
  538. // or be a number that is equal to its parentNode's width or
  539. // height ?
  540. sizeStrategy: 'percent',
  541. /** Whether to detect dom resize or not */
  542. detectResize: true,
  543. /** Enable locking to the main axis if user moves only slightly on one of them at start */
  544. locking: true
  545. },
  546. scrollPanel: {
  547. // when component mounted.. it will automatically scrolls.
  548. initialScrollY: false,
  549. initialScrollX: false,
  550. // feat: #11
  551. scrollingX: true,
  552. scrollingY: true,
  553. speed: 300,
  554. easing: undefined,
  555. // Sometimes, the nativebar maybe on the left,
  556. // See https://github.com/YvesCoding/vuescroll/issues/64
  557. verticalNativeBarPos: 'right',
  558. maxHeight: undefined,
  559. maxWidth: undefined
  560. },
  561. //
  562. rail: {
  563. background: '#01a99a',
  564. opacity: 0,
  565. border: 'none',
  566. /** Rail's size(Height/Width) , default -> 6px */
  567. size: '6px',
  568. /** Specify rail's border-radius, or the border-radius of rail and bar will be equal to the rail's size. default -> false **/
  569. specifyBorderRadius: false,
  570. /** Rail the distance from the two ends of the X axis and Y axis. **/
  571. gutterOfEnds: null,
  572. /** Rail the distance from the side of container. **/
  573. gutterOfSide: '2px',
  574. /** Whether to keep rail show or not, default -> false, event content height is not enough */
  575. keepShow: false
  576. },
  577. bar: {
  578. /** How long to hide bar after mouseleave, default -> 500 */
  579. showDelay: 500,
  580. /** Specify bar's border-radius, or the border-radius of rail and bar will be equal to the rail's size. default -> false **/
  581. specifyBorderRadius: false,
  582. /** Whether to show bar on scrolling, default -> true */
  583. onlyShowBarOnScroll: true,
  584. /** Whether to keep show or not, default -> false */
  585. keepShow: false,
  586. /** Bar's background , default -> #00a650 */
  587. background: 'rgb(3, 185, 118)',
  588. /** Bar's opacity, default -> 1 */
  589. opacity: 1,
  590. /** bar's size(Height/Width) , default -> 6px */
  591. size: '6px',
  592. minSize: 0,
  593. disable: false
  594. },
  595. scrollButton: {
  596. enable: false,
  597. background: 'rgb(3, 185, 118)',
  598. opacity: 1,
  599. step: 180,
  600. mousedownStep: 30
  601. }
  602. };
  603. /**
  604. * validate the options
  605. * @export
  606. * @param {any} ops
  607. */
  608. function validateOps(ops) {
  609. var renderError = false;
  610. var scrollPanel = ops.scrollPanel;
  611. var _ops$bar = ops.bar,
  612. vBar = _ops$bar.vBar,
  613. hBar = _ops$bar.hBar;
  614. var _ops$rail = ops.rail,
  615. vRail = _ops$rail.vRail,
  616. hRail = _ops$rail.hRail;
  617. // validate scrollPanel
  618. var initialScrollY = scrollPanel['initialScrollY'];
  619. var initialScrollX = scrollPanel['initialScrollX'];
  620. if (initialScrollY && !String(initialScrollY).match(/^\d+(\.\d+)?(%)?$/)) {
  621. 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`.');
  622. }
  623. if (initialScrollX && !String(initialScrollX).match(/^\d+(\.\d+)?(%)?$/)) {
  624. 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`.');
  625. }
  626. // validate deprecated vBar/hBar vRail/hRail
  627. if (vBar || hBar || vRail || hRail) {
  628. warn('The options: vRail, hRail, vBar, hBar have been deprecated since v4.7.0,' + 'please use corresponing rail/bar instead!');
  629. }
  630. if (_extraValidate) {
  631. _extraValidate = [].concat(_extraValidate);
  632. _extraValidate.forEach(function (hasError) {
  633. if (hasError(ops)) {
  634. renderError = true;
  635. }
  636. });
  637. }
  638. return renderError;
  639. }
  640. var _extraValidate = null;
  641. var extendOpts = function extendOpts(extraOpts, extraValidate) {
  642. extraOpts = [].concat(extraOpts);
  643. extraOpts.forEach(function (opts) {
  644. mergeObject(opts, baseConfig);
  645. });
  646. _extraValidate = extraValidate;
  647. };
  648. // all modes
  649. var modes = ['slide', 'native'];
  650. // do nothing
  651. var NOOP = function NOOP() {};
  652. // some small changes.
  653. var smallChangeArray = ['mergedOptions.vuescroll.pullRefresh.tips', 'mergedOptions.vuescroll.pushLoad.tips', 'mergedOptions.vuescroll.scroller.disable', 'mergedOptions.rail', 'mergedOptions.bar'];
  654. // refresh/load dom ref/key...
  655. var __REFRESH_DOM_NAME = 'refreshDom';
  656. var __LOAD_DOM_NAME = 'loadDom';
  657. var scrollMap = {
  658. vertical: {
  659. size: 'height',
  660. opsSize: 'width',
  661. posName: 'top',
  662. opposName: 'bottom',
  663. sidePosName: 'right',
  664. page: 'pageY',
  665. scroll: 'scrollTop',
  666. scrollSize: 'scrollHeight',
  667. offset: 'offsetHeight',
  668. client: 'clientY',
  669. axis: 'Y',
  670. scrollButton: {
  671. start: 'top',
  672. end: 'bottom'
  673. }
  674. },
  675. horizontal: {
  676. size: 'width',
  677. opsSize: 'height',
  678. posName: 'left',
  679. opposName: 'right',
  680. sidePosName: 'bottom',
  681. page: 'pageX',
  682. scroll: 'scrollLeft',
  683. scrollSize: 'scrollWidth',
  684. offset: 'offsetWidth',
  685. client: 'clientX',
  686. axis: 'X',
  687. scrollButton: {
  688. start: 'left',
  689. end: 'right'
  690. }
  691. }
  692. };
  693. function requestAnimationFrame(global) {
  694. // Check for request animation Frame support
  695. var requestFrame = global.requestAnimationFrame || global.webkitRequestAnimationFrame || global.mozRequestAnimationFrame || global.oRequestAnimationFrame;
  696. var isNative = !!requestFrame;
  697. if (requestFrame && !/requestAnimationFrame\(\)\s*\{\s*\[native code\]\s*\}/i.test(requestFrame.toString())) {
  698. isNative = false;
  699. }
  700. if (isNative) {
  701. return function (callback, root) {
  702. requestFrame(callback, root);
  703. };
  704. }
  705. var TARGET_FPS = 60;
  706. var requests = {};
  707. var rafHandle = 1;
  708. var intervalHandle = null;
  709. var lastActive = +new Date();
  710. return function (callback) {
  711. var callbackHandle = rafHandle++;
  712. // Store callback
  713. requests[callbackHandle] = callback;
  714. // Create timeout at first request
  715. if (intervalHandle === null) {
  716. intervalHandle = setInterval(function () {
  717. var time = +new Date();
  718. var currentRequests = requests;
  719. // Reset data structure before executing callbacks
  720. requests = {};
  721. for (var key in currentRequests) {
  722. if (currentRequests.hasOwnProperty(key)) {
  723. currentRequests[key](time);
  724. lastActive = time;
  725. }
  726. }
  727. // Disable the timeout when nothing happens for a certain
  728. // period of time
  729. if (time - lastActive > 2500) {
  730. clearInterval(intervalHandle);
  731. intervalHandle = null;
  732. }
  733. }, 1000 / TARGET_FPS);
  734. }
  735. return callbackHandle;
  736. };
  737. }
  738. var colorCache = {};
  739. var rgbReg = /rgb\(/;
  740. var extractRgbColor = /rgb\((.*)\)/;
  741. // Transform a common color int oa `rgbA` color
  742. function getRgbAColor(color, opacity) {
  743. var id = color + '&' + opacity;
  744. if (colorCache[id]) {
  745. return colorCache[id];
  746. }
  747. var div = document.createElement('div');
  748. div.style.background = color;
  749. document.body.appendChild(div);
  750. var computedColor = window.getComputedStyle(div).backgroundColor;
  751. document.body.removeChild(div);
  752. /* istanbul ignore if */
  753. if (!rgbReg.test(computedColor)) {
  754. return color;
  755. }
  756. return colorCache[id] = 'rgba(' + extractRgbColor.exec(computedColor)[1] + ', ' + opacity + ')';
  757. }
  758. var bar = {
  759. name: 'bar',
  760. props: {
  761. ops: Object,
  762. state: Object,
  763. hideBar: Boolean,
  764. otherBarHide: Boolean,
  765. type: String
  766. },
  767. computed: {
  768. bar: function bar() {
  769. return scrollMap[this.type];
  770. },
  771. barSize: function barSize() {
  772. return Math.max(this.state.size, this.ops.bar.minSize);
  773. },
  774. barRatio: function barRatio() {
  775. return (1 - this.barSize) / (1 - this.state.size);
  776. }
  777. },
  778. render: function render(h) {
  779. var _style, _style2, _barStyle;
  780. var vm = this;
  781. /** Get rgbA format background color */
  782. var railBackgroundColor = getRgbAColor(vm.ops.rail.background, vm.ops.rail.opacity);
  783. if (!this.touchManager) {
  784. this.touchManager = new touchManager();
  785. }
  786. /** Rail Data */
  787. var railSize = vm.ops.rail.size;
  788. var endPos = vm.otherBarHide ? 0 : railSize;
  789. var touchObj = vm.touchManager.getTouchObject();
  790. var rail = {
  791. class: '__rail-is-' + vm.type,
  792. style: (_style = {
  793. position: 'absolute',
  794. 'z-index': '1',
  795. borderRadius: vm.ops.rail.specifyBorderRadius || railSize,
  796. background: railBackgroundColor,
  797. border: vm.ops.rail.border
  798. }, 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)
  799. };
  800. if (touchObj) {
  801. var _rail$on;
  802. rail.on = (_rail$on = {}, defineProperty(_rail$on, touchObj.touchenter, function () {
  803. vm.setRailHover();
  804. }), defineProperty(_rail$on, touchObj.touchleave, function () {
  805. vm.setRailLeave();
  806. }), _rail$on);
  807. }
  808. // left space for scroll button
  809. var buttonSize = vm.ops.scrollButton.enable ? railSize : 0;
  810. var barWrapper = {
  811. class: '__bar-wrap-is-' + vm.type,
  812. style: (_style2 = {
  813. position: 'absolute',
  814. borderRadius: vm.ops.rail.specifyBorderRadius || railSize
  815. }, defineProperty(_style2, vm.bar.posName, buttonSize), defineProperty(_style2, vm.bar.opposName, buttonSize), _style2),
  816. on: {}
  817. };
  818. var scrollDistance = vm.state.posValue * vm.state.size;
  819. var pos = scrollDistance * vm.barRatio / vm.barSize;
  820. var opacity = vm.state.opacity;
  821. var parent = getRealParent(this);
  822. // set class hook
  823. parent.setClassHook(this.type == 'vertical' ? 'vBarVisible' : 'hBarVisible', !!opacity);
  824. /** Scrollbar style */
  825. var barStyle = (_barStyle = {
  826. cursor: 'pointer',
  827. position: 'absolute',
  828. margin: 'auto',
  829. transition: 'opacity 0.5s',
  830. 'user-select': 'none',
  831. 'border-radius': 'inherit'
  832. }, 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);
  833. var bar = {
  834. style: barStyle,
  835. class: '__bar-is-' + vm.type,
  836. ref: 'thumb',
  837. on: {}
  838. };
  839. if (vm.type == 'vertical') {
  840. barWrapper.style.width = '100%';
  841. // Let bar to be on the center.
  842. bar.style.left = 0;
  843. bar.style.right = 0;
  844. } else {
  845. barWrapper.style.height = '100%';
  846. bar.style.top = 0;
  847. bar.style.bottom = 0;
  848. }
  849. /* istanbul ignore next */
  850. {
  851. var _touchObj = this.touchManager.getTouchObject();
  852. bar.on[_touchObj.touchstart] = this.createBarEvent();
  853. barWrapper.on[_touchObj.touchstart] = this.createTrackEvent();
  854. }
  855. return h(
  856. 'div',
  857. rail,
  858. [this.createScrollbarButton(h, 'start'), this.hideBar ? null : h(
  859. 'div',
  860. barWrapper,
  861. [h('div', bar)]
  862. ), this.createScrollbarButton(h, 'end')]
  863. );
  864. },
  865. data: function data() {
  866. return {
  867. isBarDragging: false
  868. };
  869. },
  870. methods: {
  871. setRailHover: function setRailHover() {
  872. var parent = getRealParent(this);
  873. var state = parent.vuescroll.state;
  874. if (!state.isRailHover) {
  875. state.isRailHover = true;
  876. parent.showBar();
  877. }
  878. },
  879. setRailLeave: function setRailLeave() {
  880. var parent = getRealParent(this);
  881. var state = parent.vuescroll.state;
  882. state.isRailHover = false;
  883. parent.hideBar();
  884. },
  885. setBarDrag: function setBarDrag(val) /* istanbul ignore next */{
  886. this.$emit('setBarDrag', this.isBarDragging = val);
  887. var parent = getRealParent(this);
  888. // set class hook
  889. parent.setClassHook(this.type == 'vertical' ? 'vBarDragging' : 'hBarDragging', !!val);
  890. },
  891. createBarEvent: function createBarEvent() {
  892. var ctx = this;
  893. var parent = getRealParent(ctx);
  894. var touchObj = ctx.touchManager.getTouchObject();
  895. function mousedown(e) /* istanbul ignore next */{
  896. var event = ctx.touchManager.getEventObject(e);
  897. if (!event) return;
  898. e.stopImmediatePropagation();
  899. e.preventDefault();
  900. event = event[0];
  901. document.onselectstart = function () {
  902. return false;
  903. };
  904. ctx.axisStartPos = event[ctx.bar.client] - ctx.$refs['thumb'].getBoundingClientRect()[ctx.bar.posName];
  905. // Tell parent that the mouse has been down.
  906. ctx.setBarDrag(true);
  907. eventCenter(document, touchObj.touchmove, mousemove);
  908. eventCenter(document, touchObj.touchend, mouseup);
  909. }
  910. function mousemove(e) /* istanbul ignore next */{
  911. if (!ctx.axisStartPos) {
  912. return;
  913. }
  914. var event = ctx.touchManager.getEventObject(e);
  915. if (!event) return;
  916. event = event[0];
  917. var thubmParent = ctx.$refs.thumb.parentNode;
  918. var delta = event[ctx.bar.client] - thubmParent.getBoundingClientRect()[ctx.bar.posName];
  919. delta = delta / ctx.barRatio;
  920. var percent = (delta - ctx.axisStartPos) / thubmParent[ctx.bar.offset];
  921. parent.scrollTo(defineProperty({}, ctx.bar.axis.toLowerCase(), parent.scrollPanelElm[ctx.bar.scrollSize] * percent), false);
  922. }
  923. function mouseup() /* istanbul ignore next */{
  924. ctx.setBarDrag(false);
  925. parent.hideBar();
  926. document.onselectstart = null;
  927. ctx.axisStartPos = 0;
  928. eventCenter(document, touchObj.touchmove, mousemove, false, 'off');
  929. eventCenter(document, touchObj.touchend, mouseup, false, 'off');
  930. }
  931. return mousedown;
  932. },
  933. createTrackEvent: function createTrackEvent() {
  934. var ctx = this;
  935. return function handleClickTrack(e) {
  936. var parent = getRealParent(ctx);
  937. var _ctx$bar = ctx.bar,
  938. client = _ctx$bar.client,
  939. offset = _ctx$bar.offset,
  940. posName = _ctx$bar.posName,
  941. axis = _ctx$bar.axis;
  942. var thumb = ctx.$refs['thumb'];
  943. e.preventDefault();
  944. e.stopImmediatePropagation();
  945. /* istanbul ignore if */
  946. if (!thumb) return;
  947. var barOffset = thumb[offset];
  948. var event = ctx.touchManager.getEventObject(e)[0];
  949. var percent = (event[client] - e.currentTarget.getBoundingClientRect()[posName] - barOffset / 2) / (e.currentTarget[offset] - barOffset);
  950. parent.scrollTo(defineProperty({}, axis.toLowerCase(), percent * 100 + '%'));
  951. };
  952. },
  953. // Scrollbuton relative things...
  954. createScrollbarButton: function createScrollbarButton(h, type /* start or end */) {
  955. var _style3;
  956. var barContext = this;
  957. if (!barContext.ops.scrollButton.enable) {
  958. return null;
  959. }
  960. var size = barContext.ops.rail.size;
  961. var _barContext$ops$scrol = barContext.ops.scrollButton,
  962. opacity = _barContext$ops$scrol.opacity,
  963. background = _barContext$ops$scrol.background;
  964. var borderColor = getRgbAColor(background, opacity);
  965. var wrapperProps = {
  966. class: ['__bar-button', '__bar-button-is-' + barContext.type + '-' + type],
  967. 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),
  968. ref: type
  969. };
  970. var innerProps = {
  971. class: '__bar-button-inner',
  972. style: {
  973. border: 'calc(' + size + ' / 2.5) solid transparent',
  974. width: '0',
  975. height: '0',
  976. margin: 'auto',
  977. position: 'absolute',
  978. top: '0',
  979. bottom: '0',
  980. right: '0',
  981. left: '0'
  982. },
  983. on: {}
  984. };
  985. if (barContext.type == 'vertical') {
  986. if (type == 'start') {
  987. innerProps.style['border-bottom-color'] = borderColor;
  988. innerProps.style['transform'] = 'translateY(-25%)';
  989. } else {
  990. innerProps.style['border-top-color'] = borderColor;
  991. innerProps.style['transform'] = 'translateY(25%)';
  992. }
  993. } else {
  994. if (type == 'start') {
  995. innerProps.style['border-right-color'] = borderColor;
  996. innerProps.style['transform'] = 'translateX(-25%)';
  997. } else {
  998. innerProps.style['border-left-color'] = borderColor;
  999. innerProps.style['transform'] = 'translateX(25%)';
  1000. }
  1001. }
  1002. /* istanbul ignore next */
  1003. {
  1004. var touchObj = this.touchManager.getTouchObject();
  1005. innerProps.on[touchObj.touchstart] = this.createScrollButtonEvent(type, touchObj);
  1006. }
  1007. return h(
  1008. 'div',
  1009. wrapperProps,
  1010. [h('div', innerProps)]
  1011. );
  1012. },
  1013. createScrollButtonEvent: function createScrollButtonEvent(type, touchObj) {
  1014. var ctx = this;
  1015. var parent = getRealParent(ctx);
  1016. var _ctx$ops$scrollButton = ctx.ops.scrollButton,
  1017. step = _ctx$ops$scrollButton.step,
  1018. mousedownStep = _ctx$ops$scrollButton.mousedownStep;
  1019. var stepWithDirection = type == 'start' ? -step : step;
  1020. var mousedownStepWithDirection = type == 'start' ? -mousedownStep : mousedownStep;
  1021. var ref = requestAnimationFrame(window);
  1022. // bar props: type
  1023. var barType = ctx.type;
  1024. var isMouseDown = false;
  1025. var isMouseout = true;
  1026. var timeoutId = void 0;
  1027. function start(e) {
  1028. /* istanbul ignore if */
  1029. if (3 == e.which) {
  1030. return;
  1031. }
  1032. // set class hook
  1033. parent.setClassHook('cliking' + barType + type + 'Button', true);
  1034. e.stopImmediatePropagation();
  1035. e.preventDefault();
  1036. isMouseout = false;
  1037. parent.scrollBy(defineProperty({}, 'd' + ctx.bar.axis.toLowerCase(), stepWithDirection));
  1038. eventCenter(document, touchObj.touchend, endPress, false);
  1039. if (touchObj.touchstart == 'mousedown') {
  1040. var elm = ctx.$refs[type];
  1041. eventCenter(elm, 'mouseenter', enter, false);
  1042. eventCenter(elm, 'mouseleave', leave, false);
  1043. }
  1044. clearTimeout(timeoutId);
  1045. timeoutId = setTimeout(function () /* istanbul ignore next */{
  1046. isMouseDown = true;
  1047. ref(pressing, window);
  1048. }, 500);
  1049. }
  1050. function pressing() /* istanbul ignore next */{
  1051. if (isMouseDown && !isMouseout) {
  1052. parent.scrollBy(defineProperty({}, 'd' + ctx.bar.axis.toLowerCase(), mousedownStepWithDirection), false);
  1053. ref(pressing, window);
  1054. }
  1055. }
  1056. function endPress() {
  1057. clearTimeout(timeoutId);
  1058. isMouseDown = false;
  1059. eventCenter(document, touchObj.touchend, endPress, false, 'off');
  1060. if (touchObj.touchstart == 'mousedown') {
  1061. var elm = ctx.$refs[type];
  1062. eventCenter(elm, 'mouseenter', enter, false, 'off');
  1063. eventCenter(elm, 'mouseleave', leave, false, 'off');
  1064. }
  1065. parent.setClassHook('cliking' + barType + type + 'Button', false);
  1066. }
  1067. function enter() /* istanbul ignore next */{
  1068. isMouseout = false;
  1069. pressing();
  1070. }
  1071. function leave() /* istanbul ignore next */{
  1072. isMouseout = true;
  1073. }
  1074. return start;
  1075. }
  1076. }
  1077. };
  1078. function getBarData(vm, type) {
  1079. var axis = scrollMap[type].axis;
  1080. /** type.charAt(0) = vBar/hBar */
  1081. var barType = type.charAt(0) + 'Bar';
  1082. var hideBar = !vm.bar[barType].state.size || !vm.mergedOptions.scrollPanel['scrolling' + axis] || vm.refreshLoad && type !== 'vertical' || vm.mergedOptions.bar.disable;
  1083. var keepShowRail = vm.mergedOptions.rail.keepShow;
  1084. if (hideBar && !keepShowRail) {
  1085. return null;
  1086. }
  1087. return {
  1088. hideBar: hideBar,
  1089. props: {
  1090. type: type,
  1091. ops: {
  1092. bar: vm.mergedOptions.bar,
  1093. rail: vm.mergedOptions.rail,
  1094. scrollButton: vm.mergedOptions.scrollButton
  1095. },
  1096. state: vm.bar[barType].state,
  1097. hideBar: hideBar
  1098. },
  1099. on: {
  1100. setBarDrag: vm.setBarDrag
  1101. },
  1102. ref: type + 'Bar',
  1103. key: type
  1104. };
  1105. }
  1106. /**
  1107. * create bars
  1108. *
  1109. * @param {any} size
  1110. * @param {any} type
  1111. */
  1112. function createBar(h, vm) {
  1113. var verticalBarProps = getBarData(vm, 'vertical');
  1114. var horizontalBarProps = getBarData(vm, 'horizontal');
  1115. // set class hooks
  1116. vm.setClassHook('hasVBar', !!(verticalBarProps && !verticalBarProps.hideBar));
  1117. vm.setClassHook('hasHBar', !!(horizontalBarProps && !horizontalBarProps.hideBar));
  1118. return [verticalBarProps ? h('bar', _extends({}, verticalBarProps, {
  1119. props: _extends({ otherBarHide: !horizontalBarProps }, verticalBarProps.props)
  1120. })) : null, horizontalBarProps ? h('bar', _extends({}, horizontalBarProps, {
  1121. props: _extends({ otherBarHide: !verticalBarProps }, horizontalBarProps.props)
  1122. })) : null];
  1123. }
  1124. /**
  1125. * This is like a HOC, It extracts the common parts of the
  1126. * native-mode, slide-mode and mix-mode.
  1127. * Each mode must implement the following methods:
  1128. * 1. refreshInternalStatus : use to refresh the component
  1129. * 2. destroy : Destroy some registryed events before component destroy.
  1130. * 3. updateBarStateAndEmitEvent: use to update bar states and emit events.
  1131. */
  1132. var createComponent = function createComponent(_ref) {
  1133. var _render = _ref.render,
  1134. components = _ref.components,
  1135. mixins = _ref.mixins;
  1136. return {
  1137. name: 'vueScroll',
  1138. props: {
  1139. ops: { type: Object }
  1140. },
  1141. components: components,
  1142. mixins: [api].concat(toConsumableArray([].concat(mixins))),
  1143. created: function created() {
  1144. var _this = this;
  1145. /**
  1146. * Begin to merge options
  1147. */
  1148. var _gfc = mergeObject(this.$vuescrollConfig || {}, {});
  1149. var ops = mergeObject(baseConfig, _gfc);
  1150. this.$options.propsData.ops = this.$options.propsData.ops || {};
  1151. Object.keys(this.$options.propsData.ops).forEach(function (key) {
  1152. {
  1153. defineReactive(_this.mergedOptions, key, _this.$options.propsData.ops);
  1154. }
  1155. });
  1156. // from ops to mergedOptions
  1157. mergeObject(ops, this.mergedOptions);
  1158. this._isVuescrollRoot = true;
  1159. this.renderError = validateOps(this.mergedOptions);
  1160. },
  1161. render: function render(h) {
  1162. var vm = this;
  1163. if (vm.renderError) {
  1164. return h('div', [[vm.$slots['default']]]);
  1165. }
  1166. if (!vm.touchManager) vm.touchManager = new touchManager();
  1167. // vuescroll data
  1168. var data = {
  1169. style: {
  1170. height: vm.vuescroll.state.height,
  1171. width: vm.vuescroll.state.width,
  1172. padding: 0,
  1173. position: 'relative',
  1174. overflow: 'hidden'
  1175. },
  1176. class: _extends({ __vuescroll: true }, vm.classHooks)
  1177. };
  1178. var touchObj = vm.touchManager.getTouchObject();
  1179. if (touchObj) {
  1180. var _data$on;
  1181. data.on = (_data$on = {}, defineProperty(_data$on, touchObj.touchenter, function () {
  1182. vm.vuescroll.state.pointerLeave = false;
  1183. vm.updateBarStateAndEmitEvent();
  1184. vm.setClassHook('mouseEnter', true);
  1185. }), defineProperty(_data$on, touchObj.touchleave, function () {
  1186. vm.vuescroll.state.pointerLeave = true;
  1187. vm.hideBar();
  1188. vm.setClassHook('mouseEnter', false);
  1189. }), defineProperty(_data$on, touchObj.touchmove, function () /* istanbul ignore next */{
  1190. vm.vuescroll.state.pointerLeave = false;
  1191. vm.updateBarStateAndEmitEvent();
  1192. }), _data$on);
  1193. }
  1194. var ch = [_render(h, vm)].concat(toConsumableArray(createBar(h, vm)));
  1195. var _customContainer = this.$slots['scroll-container'];
  1196. if (_customContainer) {
  1197. return insertChildrenIntoSlot(h, _customContainer, ch, data);
  1198. }
  1199. return h(
  1200. 'div',
  1201. data,
  1202. [ch]
  1203. );
  1204. },
  1205. mounted: function mounted() {
  1206. var _this2 = this;
  1207. if (!this.renderError) {
  1208. this.initVariables();
  1209. this.initWatchOpsChange();
  1210. // Call external merged Api
  1211. this.refreshInternalStatus();
  1212. this.updatedCbs.push(function () {
  1213. _this2.scrollToAnchor();
  1214. // need to reflow to deal with the
  1215. // latest thing.
  1216. _this2.updateBarStateAndEmitEvent();
  1217. });
  1218. }
  1219. },
  1220. updated: function updated() {
  1221. var _this3 = this;
  1222. this.updatedCbs.forEach(function (cb) {
  1223. cb.call(_this3);
  1224. });
  1225. // Clear
  1226. this.updatedCbs = [];
  1227. },
  1228. beforeDestroy: function beforeDestroy() {
  1229. if (this.destroy) {
  1230. this.destroy();
  1231. }
  1232. },
  1233. /** ------------------------------- Computed ----------------------------- */
  1234. computed: {
  1235. scrollPanelElm: function scrollPanelElm() {
  1236. return this.$refs['scrollPanel']._isVue ? this.$refs['scrollPanel'].$el : this.$refs['scrollPanel'];
  1237. }
  1238. },
  1239. data: function data() {
  1240. return {
  1241. vuescroll: {
  1242. state: {
  1243. isDragging: false,
  1244. pointerLeave: true,
  1245. isRailHover: false,
  1246. /** Default sizeStrategies */
  1247. height: '100%',
  1248. width: '100%',
  1249. // current size strategy
  1250. currentSizeStrategy: 'percent',
  1251. currentScrollState: null,
  1252. currentScrollInfo: null
  1253. }
  1254. },
  1255. bar: {
  1256. vBar: {
  1257. state: {
  1258. posValue: 0,
  1259. size: 0,
  1260. opacity: 0
  1261. }
  1262. },
  1263. hBar: {
  1264. state: {
  1265. posValue: 0,
  1266. size: 0,
  1267. opacity: 0
  1268. }
  1269. }
  1270. },
  1271. mergedOptions: {
  1272. vuescroll: {},
  1273. scrollPanel: {},
  1274. scrollContent: {},
  1275. rail: {},
  1276. bar: {}
  1277. },
  1278. updatedCbs: [],
  1279. renderError: false,
  1280. classHooks: {
  1281. hasVBar: false,
  1282. hasHBar: false,
  1283. vBarVisible: false,
  1284. hBarVisible: false,
  1285. vBarDragging: false,
  1286. hBarDragging: false,
  1287. clikingVerticalStartButton: false,
  1288. clikingVerticalEndButton: false,
  1289. clikingHorizontalStartButton: false,
  1290. clikingHorizontalEndButton: false,
  1291. mouseEnter: false
  1292. }
  1293. };
  1294. },
  1295. /** ------------------------------- Methods -------------------------------- */
  1296. methods: {
  1297. /** ------------------------ Handlers --------------------------- */
  1298. scrollingComplete: function scrollingComplete() {
  1299. this.updateBarStateAndEmitEvent('handle-scroll-complete');
  1300. },
  1301. setBarDrag: function setBarDrag(val) {
  1302. /* istanbul ignore next */
  1303. this.vuescroll.state.isDragging = val;
  1304. },
  1305. setClassHook: function setClassHook(name, value) {
  1306. this.classHooks[name] = value;
  1307. },
  1308. /** ------------------------ Some Helpers --------------------------- */
  1309. /*
  1310. * To have a good ux, instead of hiding bar immediately, we hide bar
  1311. * after some seconds by using this simple debounce-hidebar method.
  1312. */
  1313. showAndDefferedHideBar: function showAndDefferedHideBar(forceHideBar) {
  1314. var _this4 = this;
  1315. this.showBar();
  1316. if (this.timeoutId) {
  1317. clearTimeout(this.timeoutId);
  1318. this.timeoutId = 0;
  1319. }
  1320. this.timeoutId = setTimeout(function () {
  1321. _this4.timeoutId = 0;
  1322. _this4.hideBar(forceHideBar);
  1323. }, this.mergedOptions.bar.showDelay);
  1324. },
  1325. showBar: function showBar() {
  1326. var opacity = this.mergedOptions.bar.opacity;
  1327. this.bar.vBar.state.opacity = opacity;
  1328. this.bar.hBar.state.opacity = opacity;
  1329. },
  1330. hideBar: function hideBar(forceHideBar) {
  1331. var _vuescroll$state = this.vuescroll.state,
  1332. isDragging = _vuescroll$state.isDragging,
  1333. isRailHover = _vuescroll$state.isRailHover;
  1334. /* istanbul ignore next */
  1335. if (isDragging || isRailHover) {
  1336. return;
  1337. }
  1338. if (forceHideBar && !this.mergedOptions.bar.keepShow) {
  1339. this.bar.hBar.state.opacity = 0;
  1340. this.bar.vBar.state.opacity = 0;
  1341. }
  1342. // add isDragging condition
  1343. // to prevent from hiding bar while dragging the bar
  1344. if (!this.mergedOptions.bar.keepShow && !this.vuescroll.state.isDragging) {
  1345. this.bar.vBar.state.opacity = 0;
  1346. this.bar.hBar.state.opacity = 0;
  1347. }
  1348. },
  1349. useNumbericSize: function useNumbericSize() {
  1350. this.vuescroll.state.currentSizeStrategy = 'number';
  1351. var _mergedOptions$scroll = this.mergedOptions.scrollPanel,
  1352. maxHeight = _mergedOptions$scroll.maxHeight,
  1353. maxWidth = _mergedOptions$scroll.maxWidth;
  1354. var _$el$parentNode = this.$el.parentNode,
  1355. parentClientHeight = _$el$parentNode.clientHeight,
  1356. parentClientWidth = _$el$parentNode.clientWidth;
  1357. var _scrollPanelElm = this.scrollPanelElm,
  1358. scrollHeight = _scrollPanelElm.scrollHeight,
  1359. scrollWidth = _scrollPanelElm.scrollWidth;
  1360. var width = void 0;
  1361. var height = void 0;
  1362. if (maxHeight || maxWidth) {
  1363. height = scrollHeight <= maxHeight ? undefined : maxHeight;
  1364. width = scrollWidth <= maxWidth ? undefined : maxWidth;
  1365. } else {
  1366. height = parentClientHeight;
  1367. width = parentClientWidth;
  1368. }
  1369. this.vuescroll.state.height = height ? height + 'px' : undefined;
  1370. this.vuescroll.state.width = width ? width + 'px' : undefined;
  1371. },
  1372. usePercentSize: function usePercentSize() {
  1373. this.vuescroll.state.currentSizeStrategy = 'percent';
  1374. this.vuescroll.state.height = '100%';
  1375. this.vuescroll.state.width = '100%';
  1376. },
  1377. // Set its size to be equal to its parentNode
  1378. setVsSize: function setVsSize() {
  1379. var sizeStrategy = this.mergedOptions.vuescroll.sizeStrategy;
  1380. var _mergedOptions$scroll2 = this.mergedOptions.scrollPanel,
  1381. maxHeight = _mergedOptions$scroll2.maxHeight,
  1382. maxWidth = _mergedOptions$scroll2.maxWidth;
  1383. var _scrollPanelElm2 = this.scrollPanelElm,
  1384. clientHeight = _scrollPanelElm2.clientHeight,
  1385. clientWidth = _scrollPanelElm2.clientWidth;
  1386. if (sizeStrategy == 'number' || maxHeight && clientHeight > maxHeight || maxWidth && clientWidth > maxWidth) {
  1387. this.useNumbericSize();
  1388. } else if (sizeStrategy == 'percent' && clientHeight != maxHeight && clientWidth != maxWidth) {
  1389. this.usePercentSize();
  1390. }
  1391. },
  1392. /** ------------------------ Init --------------------------- */
  1393. initWatchOpsChange: function initWatchOpsChange() {
  1394. var _this5 = this;
  1395. var watchOpts = {
  1396. deep: true,
  1397. sync: true
  1398. };
  1399. this.$watch('mergedOptions', function () {
  1400. setTimeout(function () {
  1401. if (_this5.isSmallChangeThisTick) {
  1402. _this5.isSmallChangeThisTick = false;
  1403. _this5.updateBarStateAndEmitEvent('options-change');
  1404. return;
  1405. }
  1406. _this5.refreshInternalStatus();
  1407. }, 0);
  1408. }, watchOpts);
  1409. /**
  1410. * We also watch `small` changes, and when small changes happen, we send
  1411. * a signal to vuescroll, to tell it:
  1412. * 1. we don't need to registry resize
  1413. * 2. we don't need to registry scroller.
  1414. */
  1415. smallChangeArray.forEach(function (opts) {
  1416. _this5.$watch(opts, function () {
  1417. _this5.isSmallChangeThisTick = true;
  1418. }, watchOpts);
  1419. });
  1420. },
  1421. // scrollTo hash-anchor while mounted component have mounted.
  1422. scrollToAnchor: function scrollToAnchor() /* istanbul ignore next */{
  1423. var validateHashSelector = function validateHashSelector(hash) {
  1424. return (/^#[a-zA-Z_]\d*$/.test(hash)
  1425. );
  1426. };
  1427. var hash = window.location.hash;
  1428. if (!hash || (hash = hash.slice(hash.lastIndexOf('#'))) && !validateHashSelector(hash)) {
  1429. return;
  1430. }
  1431. var elm = document.querySelector(hash);
  1432. if (!isChildInParent(elm, this.$el) || this.mergedOptions.scrollPanel.initialScrollY || this.mergedOptions.scrollPanel.initialScrollX) {
  1433. return;
  1434. }
  1435. this.scrollIntoView(elm);
  1436. }
  1437. /** ------------------------ Registry Resize --------------------------- */
  1438. }
  1439. };
  1440. };
  1441. // begin importing
  1442. var scrollPanel = {
  1443. name: 'scrollPanel',
  1444. props: { ops: { type: Object, required: true } },
  1445. methods: {
  1446. // trigger scrollPanel options initialScrollX,
  1447. // initialScrollY
  1448. updateInitialScroll: function updateInitialScroll() {
  1449. var x = 0;
  1450. var y = 0;
  1451. var parent = getRealParent(this);
  1452. if (this.ops.initialScrollX) {
  1453. x = this.ops.initialScrollX;
  1454. }
  1455. if (this.ops.initialScrollY) {
  1456. y = this.ops.initialScrollY;
  1457. }
  1458. if (x || y) {
  1459. parent.scrollTo({ x: x, y: y });
  1460. }
  1461. }
  1462. },
  1463. mounted: function mounted() {
  1464. var _this = this;
  1465. setTimeout(function () {
  1466. if (!_this._isDestroyed) {
  1467. _this.updateInitialScroll();
  1468. }
  1469. }, 0);
  1470. },
  1471. render: function render(h) {
  1472. // eslint-disable-line
  1473. var data = {
  1474. class: ['__panel'],
  1475. style: {
  1476. position: 'relative',
  1477. boxSizing: 'border-box'
  1478. }
  1479. };
  1480. var parent = getRealParent(this);
  1481. var _customPanel = parent.$slots['scroll-panel'];
  1482. if (_customPanel) {
  1483. return insertChildrenIntoSlot(h, _customPanel, this.$slots.default, data);
  1484. }
  1485. return h(
  1486. 'div',
  1487. data,
  1488. [[this.$slots.default]]
  1489. );
  1490. }
  1491. };
  1492. /**
  1493. * Init following things
  1494. * 1. Component
  1495. * 2. Render
  1496. * 3. Config
  1497. */
  1498. function _install(core, render) {
  1499. var _components;
  1500. var extraConfigs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  1501. var extraValidators = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
  1502. var components = (_components = {}, defineProperty(_components, scrollPanel.name, scrollPanel), defineProperty(_components, bar.name, bar), _components);
  1503. var opts = {};
  1504. opts.components = components;
  1505. opts.render = render;
  1506. opts.mixins = core;
  1507. var comp = createComponent(opts);
  1508. // Init Config
  1509. extendOpts(extraConfigs, extraValidators);
  1510. return comp;
  1511. }
  1512. /**
  1513. * Get the children of parent those are in viewport
  1514. */
  1515. function getCurrentViewportDom(parent, container) {
  1516. var children = parent.children;
  1517. var domFragment = [];
  1518. var isCurrentview = function isCurrentview(dom) {
  1519. var _dom$getBoundingClien = dom.getBoundingClientRect(),
  1520. left = _dom$getBoundingClien.left,
  1521. top = _dom$getBoundingClien.top,
  1522. width = _dom$getBoundingClien.width,
  1523. height = _dom$getBoundingClien.height;
  1524. var _container$getBoundin = container.getBoundingClientRect(),
  1525. parentLeft = _container$getBoundin.left,
  1526. parentTop = _container$getBoundin.top,
  1527. parentHeight = _container$getBoundin.height,
  1528. parentWidth = _container$getBoundin.width;
  1529. if (left - parentLeft + width > 0 && left - parentLeft < parentWidth && top - parentTop + height > 0 && top - parentTop < parentHeight) {
  1530. return true;
  1531. }
  1532. return false;
  1533. };
  1534. for (var i = 0; i < children.length; i++) {
  1535. var dom = children.item(i);
  1536. if (isCurrentview(dom) && !dom.isResizeElm) {
  1537. domFragment.push(dom);
  1538. }
  1539. }
  1540. return domFragment;
  1541. }
  1542. /**
  1543. * Compatible to scroller's animation function
  1544. */
  1545. function createEasingFunction(easing, easingPattern) {
  1546. return function (time) {
  1547. return easingPattern(easing, time);
  1548. };
  1549. }
  1550. /**
  1551. * Calculate the easing pattern
  1552. * @link https://github.com/cferdinandi/smooth-scroll/blob/master/src/js/smooth-scroll.js
  1553. * modified by wangyi7099
  1554. * @param {String} type Easing pattern
  1555. * @param {Number} time Time animation should take to complete
  1556. * @returns {Number}
  1557. */
  1558. function easingPattern(easing, time) {
  1559. var pattern = null;
  1560. /* istanbul ignore next */
  1561. {
  1562. // Default Easing Patterns
  1563. if (easing === 'easeInQuad') pattern = time * time; // accelerating from zero velocity
  1564. if (easing === 'easeOutQuad') pattern = time * (2 - time); // decelerating to zero velocity
  1565. if (easing === 'easeInOutQuad') pattern = time < 0.5 ? 2 * time * time : -1 + (4 - 2 * time) * time; // acceleration until halfway, then deceleration
  1566. if (easing === 'easeInCubic') pattern = time * time * time; // accelerating from zero velocity
  1567. if (easing === 'easeOutCubic') pattern = --time * time * time + 1; // decelerating to zero velocity
  1568. 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
  1569. if (easing === 'easeInQuart') pattern = time * time * time * time; // accelerating from zero velocity
  1570. if (easing === 'easeOutQuart') pattern = 1 - --time * time * time * time; // decelerating to zero velocity
  1571. if (easing === 'easeInOutQuart') pattern = time < 0.5 ? 8 * time * time * time * time : 1 - 8 * --time * time * time * time; // acceleration until halfway, then deceleration
  1572. if (easing === 'easeInQuint') pattern = time * time * time * time * time; // accelerating from zero velocity
  1573. if (easing === 'easeOutQuint') pattern = 1 + --time * time * time * time * time; // decelerating to zero velocity
  1574. 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
  1575. }
  1576. return pattern || time; // no easing, no acceleration
  1577. }
  1578. function noop() {
  1579. return true;
  1580. }
  1581. /* istanbul ignore next */
  1582. var now = Date.now || function () {
  1583. return new Date().getTime();
  1584. };
  1585. var ScrollControl = function () {
  1586. function ScrollControl() {
  1587. classCallCheck(this, ScrollControl);
  1588. this.init();
  1589. this.isRunning = false;
  1590. }
  1591. createClass(ScrollControl, [{
  1592. key: 'pause',
  1593. value: function pause() {
  1594. /* istanbul ignore if */
  1595. if (!this.isRunning) return;
  1596. this.isPaused = true;
  1597. }
  1598. }, {
  1599. key: 'stop',
  1600. value: function stop() {
  1601. this.isStopped = true;
  1602. }
  1603. }, {
  1604. key: 'continue',
  1605. value: function _continue() {
  1606. /* istanbul ignore if */
  1607. if (!this.isPaused) return;
  1608. this.isPaused = false;
  1609. this.ts = now() - this.percent * this.spd;
  1610. this.execScroll();
  1611. }
  1612. }, {
  1613. key: 'startScroll',
  1614. value: function startScroll(st, ed, spd) {
  1615. var stepCb = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : noop;
  1616. var completeCb = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : noop;
  1617. var vertifyCb = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : noop;
  1618. var easingMethod = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : noop;
  1619. var df = ed - st;
  1620. var dir = df > 0 ? -1 : 1;
  1621. var nt = now();
  1622. if (!this.isRunning) {
  1623. this.init();
  1624. }
  1625. if (dir != this.dir || nt - this.ts > 200) {
  1626. this.ts = nt;
  1627. this.dir = dir;
  1628. this.st = st;
  1629. this.ed = ed;
  1630. this.df = df;
  1631. } /* istanbul ignore next */else {
  1632. this.df += df;
  1633. }
  1634. this.spd = spd;
  1635. this.completeCb = completeCb;
  1636. this.vertifyCb = vertifyCb;
  1637. this.stepCb = stepCb;
  1638. this.easingMethod = easingMethod;
  1639. if (!this.isRunning) this.execScroll();
  1640. }
  1641. }, {
  1642. key: 'execScroll',
  1643. value: function execScroll() {
  1644. var _this = this;
  1645. if (!this.df) return;
  1646. var percent = this.percent || 0;
  1647. this.percent = 0;
  1648. this.isRunning = true;
  1649. var loop = function loop() {
  1650. /* istanbul ignore if */
  1651. if (!_this.isRunning || !_this.vertifyCb(percent) || _this.isStopped) {
  1652. _this.isRunning = false;
  1653. return;
  1654. }
  1655. percent = (now() - _this.ts) / _this.spd;
  1656. if (_this.isPaused) {
  1657. _this.percent = percent;
  1658. _this.isRunning = false;
  1659. return;
  1660. }
  1661. if (percent < 1) {
  1662. var value = _this.st + _this.df * _this.easingMethod(percent);
  1663. _this.stepCb(value);
  1664. _this.ref(loop);
  1665. } else {
  1666. // trigger complete
  1667. _this.stepCb(_this.st + _this.df);
  1668. _this.completeCb();
  1669. _this.isRunning = false;
  1670. }
  1671. };
  1672. this.ref(loop);
  1673. }
  1674. }, {
  1675. key: 'init',
  1676. value: function init() {
  1677. this.st = 0;
  1678. this.ed = 0;
  1679. this.df = 0;
  1680. this.spd = 0;
  1681. this.ts = 0;
  1682. this.dir = 0;
  1683. this.ref = requestAnimationFrame(window);
  1684. this.isPaused = false;
  1685. this.isStopped = false;
  1686. }
  1687. }]);
  1688. return ScrollControl;
  1689. }();
  1690. function scrollTo(elm, x, y) {
  1691. var speed = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 300;
  1692. var easing = arguments[4];
  1693. var scrollingComplete = arguments[5];
  1694. var scrollLeft = void 0,
  1695. scrollTop = void 0,
  1696. scrollHeight = void 0,
  1697. scrollWidth = void 0,
  1698. clientWidth = void 0,
  1699. clientHeight = void 0;
  1700. var _elm = elm,
  1701. nodeType = _elm.nodeType;
  1702. var scrollX = new ScrollControl();
  1703. var scrollY = new ScrollControl();
  1704. if (!nodeType) {
  1705. warn('You must pass a dom for the first param, ' + 'for window scrolling, ' + 'you can pass document as the first param.');
  1706. return;
  1707. }
  1708. if (nodeType == 9) {
  1709. // document
  1710. elm = elm.scrollingElement;
  1711. }
  1712. var _elm2 = elm;
  1713. scrollLeft = _elm2.scrollLeft;
  1714. scrollTop = _elm2.scrollTop;
  1715. scrollHeight = _elm2.scrollHeight;
  1716. scrollWidth = _elm2.scrollWidth;
  1717. clientWidth = _elm2.clientWidth;
  1718. clientHeight = _elm2.clientHeight;
  1719. if (typeof x === 'undefined') {
  1720. x = scrollLeft;
  1721. } else {
  1722. x = getNumericValue(x, scrollWidth - clientWidth);
  1723. }
  1724. if (typeof y === 'undefined') {
  1725. y = scrollTop;
  1726. } else {
  1727. y = getNumericValue(y, scrollHeight - clientHeight);
  1728. }
  1729. var easingMethod = createEasingFunction(easing, easingPattern);
  1730. scrollX.startScroll(scrollLeft, x, speed, function (dx) {
  1731. elm.scrollLeft = dx;
  1732. }, scrollingComplete, undefined, easingMethod);
  1733. scrollY.startScroll(scrollTop, y, speed, function (dy) {
  1734. elm.scrollTop = dy;
  1735. }, scrollingComplete, undefined, easingMethod);
  1736. }
  1737. var nativeApi = {
  1738. mounted: function mounted() {
  1739. // registry scroll
  1740. this.scrollX = new ScrollControl();
  1741. this.scrollY = new ScrollControl();
  1742. },
  1743. methods: {
  1744. nativeStop: function nativeStop() {
  1745. this.scrollX.stop();
  1746. this.scrollY.stop();
  1747. },
  1748. nativePause: function nativePause() {
  1749. this.scrollX.pause();
  1750. this.scrollY.pause();
  1751. },
  1752. nativeContinue: function nativeContinue() {
  1753. this.scrollX.continue();
  1754. this.scrollY.continue();
  1755. },
  1756. nativeScrollTo: function nativeScrollTo(x, y, speed, easing) {
  1757. if (speed === false) ; else if (typeof speed === 'undefined') {
  1758. speed = this.mergedOptions.scrollPanel.speed;
  1759. }
  1760. var elm = this.scrollPanelElm;
  1761. var scrollTop = elm.scrollTop,
  1762. scrollLeft = elm.scrollLeft,
  1763. scrollWidth = elm.scrollWidth,
  1764. clientWidth = elm.clientWidth,
  1765. scrollHeight = elm.scrollHeight,
  1766. clientHeight = elm.clientHeight;
  1767. if (typeof x === 'undefined') {
  1768. x = scrollLeft;
  1769. } else {
  1770. x = getNumericValue(x, scrollWidth - clientWidth);
  1771. }
  1772. if (typeof y === 'undefined') {
  1773. y = scrollTop;
  1774. } else {
  1775. y = getNumericValue(y, scrollHeight - clientHeight);
  1776. }
  1777. if (speed) {
  1778. easing = easing || this.mergedOptions.scrollPanel.easing;
  1779. var easingMethod = createEasingFunction(easing, easingPattern);
  1780. if (x != scrollLeft) {
  1781. this.scrollX.startScroll(scrollLeft, x, speed, function (x) {
  1782. elm.scrollLeft = x;
  1783. }, this.scrollingComplete.bind(this), undefined, easingMethod);
  1784. }
  1785. if (y != scrollTop) {
  1786. this.scrollY.startScroll(scrollTop, y, speed, function (y) {
  1787. elm.scrollTop = y;
  1788. }, this.scrollingComplete.bind(this), undefined, easingMethod);
  1789. }
  1790. } else {
  1791. elm.scrollTop = y;
  1792. elm.scrollLeft = x;
  1793. }
  1794. },
  1795. getCurrentviewDomNative: function getCurrentviewDomNative() {
  1796. var parent = this.scrollContentElm;
  1797. var domFragment = getCurrentViewportDom(parent, this.$el);
  1798. return domFragment;
  1799. }
  1800. }
  1801. };
  1802. function getPanelData(context) {
  1803. // scrollPanel data start
  1804. var data = {
  1805. ref: 'scrollPanel',
  1806. style: {
  1807. height: '100%',
  1808. overflowY: 'scroll',
  1809. overflowX: 'scroll'
  1810. },
  1811. class: [],
  1812. nativeOn: {
  1813. '&scroll': context.handleScroll
  1814. },
  1815. props: {
  1816. ops: context.mergedOptions.scrollPanel
  1817. }
  1818. };
  1819. context.scrollYEnable = true;
  1820. context.scrollXEnable = true;
  1821. data.nativeOn.DOMMouseScroll = data.nativeOn.mousewheel = context.onMouseWheel;
  1822. var _context$mergedOption = context.mergedOptions.scrollPanel,
  1823. scrollingY = _context$mergedOption.scrollingY,
  1824. scrollingX = _context$mergedOption.scrollingX;
  1825. if (!context.bar.hBar.state.size || !scrollingX) {
  1826. context.scrollXEnable = false;
  1827. data.style.overflowX = 'hidden';
  1828. }
  1829. if (!context.bar.vBar.state.size || !scrollingY) {
  1830. context.scrollYEnable = false;
  1831. data.style.overflowY = 'hidden';
  1832. }
  1833. var gutter = getGutter();
  1834. /* istanbul ignore if */
  1835. if (!gutter) {
  1836. createHideBarStyle();
  1837. data.class.push('__hidebar');
  1838. if (isIos()) {
  1839. data.style['-webkit-overflow-scrolling'] = 'touch';
  1840. }
  1841. } else {
  1842. // hide system bar by use a negative value px
  1843. // gutter should be 0 when manually disable scrollingX #14
  1844. if (context.bar.vBar.state.size && context.mergedOptions.scrollPanel.scrollingY) {
  1845. if (context.mergedOptions.scrollPanel.verticalNativeBarPos == 'right') {
  1846. data.style.marginRight = '-' + gutter + 'px';
  1847. } /* istanbul ignore next */else {
  1848. data.style.marginLeft = '-' + gutter + 'px';
  1849. }
  1850. }
  1851. if (context.bar.hBar.state.size && context.mergedOptions.scrollPanel.scrollingX) {
  1852. data.style.height = 'calc(100% + ' + gutter + 'px)';
  1853. }
  1854. }
  1855. // clear legency styles of slide mode...
  1856. data.style.transformOrigin = '';
  1857. data.style.transform = '';
  1858. return data;
  1859. }
  1860. /**
  1861. * create a scrollPanel
  1862. *
  1863. * @param {any} size
  1864. * @param {any} context
  1865. * @returns
  1866. */
  1867. function createPanel(h, context) {
  1868. var data = {};
  1869. data = getPanelData(context);
  1870. return h(
  1871. 'scrollPanel',
  1872. data,
  1873. [getPanelChildren(h, context)]
  1874. );
  1875. }
  1876. function getPanelChildren(h, context) {
  1877. var viewStyle = {
  1878. position: 'relative',
  1879. 'box-sizing': 'border-box',
  1880. 'min-width': '100%',
  1881. 'min-height': '100%'
  1882. };
  1883. var data = {
  1884. style: viewStyle,
  1885. ref: 'scrollContent',
  1886. class: '__view'
  1887. };
  1888. var _customContent = context.$slots['scroll-content'];
  1889. if (context.mergedOptions.scrollPanel.scrollingX) {
  1890. viewStyle.width = getComplitableStyle('width', 'fit-content');
  1891. } else {
  1892. data.style['width'] = '100%';
  1893. }
  1894. if (context.mergedOptions.scrollPanel.padding) {
  1895. data.style.paddingRight = context.mergedOptions.rail.size;
  1896. }
  1897. if (_customContent) {
  1898. return insertChildrenIntoSlot(h, _customContent, context.$slots.default, data);
  1899. }
  1900. return h(
  1901. 'div',
  1902. data,
  1903. [context.$slots.default]
  1904. );
  1905. }
  1906. function getPanelData$1(context) {
  1907. // scrollPanel data start
  1908. var data = {
  1909. ref: 'scrollPanel',
  1910. style: {
  1911. 'user-select': 'none',
  1912. '-webkit-user-select': 'none',
  1913. 'min-width': '100%',
  1914. 'min-height': '100%'
  1915. },
  1916. class: [],
  1917. props: {
  1918. ops: context.mergedOptions.scrollPanel
  1919. }
  1920. };
  1921. data.class.push('__slide');
  1922. /* istanbul ignore if */
  1923. if (isIos()) {
  1924. data.style = defineProperty({}, '-webkit-overflow-scrolling', 'touch');
  1925. }
  1926. if (context.mergedOptions.vuescroll.renderMethod == 'transform') {
  1927. data.style['transform-origin'] = 'left top 0px';
  1928. }
  1929. var _context$mergedOption = context.mergedOptions.scrollPanel,
  1930. scrollingX = _context$mergedOption.scrollingX,
  1931. scrollingY = _context$mergedOption.scrollingY,
  1932. padding = _context$mergedOption.padding;
  1933. if (scrollingX && !context.refreshLoad) {
  1934. var width = getComplitableStyle('width', 'fit-content');
  1935. if (width) {
  1936. data.style['width'] = width;
  1937. } /* istanbul ignore next */else {
  1938. data['display'] = 'inline-block';
  1939. }
  1940. }
  1941. /* istanbul ignore if */
  1942. if (!scrollingX) {
  1943. data.class.push('x-hidden');
  1944. }
  1945. /* istanbul ignore if */
  1946. if (!scrollingY) {
  1947. data.class.push('y-hidden');
  1948. }
  1949. if (padding) {
  1950. data.style.paddingRight = context.mergedOptions.rail.size;
  1951. }
  1952. return data;
  1953. }
  1954. function getPanelChildren$1(h, context) {
  1955. var renderChildren = getVnodeInfo(context.$slots['scroll-panel']).ch || context.$slots.default;
  1956. var finalChildren = [];
  1957. /* istanbul ignore if */
  1958. if (!renderChildren) {
  1959. context.$slots.default = renderChildren = [];
  1960. }
  1961. // handle refresh
  1962. if (context.mergedOptions.vuescroll.pullRefresh.enable) {
  1963. finalChildren.push(h(
  1964. 'div',
  1965. {
  1966. 'class': '__refresh',
  1967. style: { visibility: context.refrehDomVisiable ? '' : 'hidden' },
  1968. ref: __REFRESH_DOM_NAME,
  1969. key: __REFRESH_DOM_NAME
  1970. },
  1971. [createTipDom(h, context, 'refresh', context.pullRefreshTip)]
  1972. ));
  1973. }
  1974. finalChildren.push(renderChildren);
  1975. // handle load
  1976. if (context.mergedOptions.vuescroll.pushLoad.enable) {
  1977. finalChildren.push(h(
  1978. 'div',
  1979. {
  1980. ref: __LOAD_DOM_NAME,
  1981. key: __LOAD_DOM_NAME,
  1982. 'class': '__load',
  1983. style: { visibility: context.loadDomVisiable ? '' : 'hidden' }
  1984. },
  1985. [createTipDom(h, context, 'load', context.pushLoadTip)]
  1986. ));
  1987. }
  1988. return finalChildren;
  1989. }
  1990. // Create load or refresh tip dom of each stages
  1991. function createTipDom(h, context, type, tip) {
  1992. var stage = context.vuescroll.state[type + 'Stage'];
  1993. var dom = null;
  1994. // Return user specified animation dom
  1995. /* istanbul ignore if */
  1996. if (dom = context.$slots[type + '-' + stage]) {
  1997. return dom;
  1998. }
  1999. switch (stage) {
  2000. // The dom will show at deactive stage
  2001. case 'deactive':
  2002. case 'active':
  2003. {
  2004. var className = 'active';
  2005. if (stage == 'deactive') {
  2006. className += ' deactive';
  2007. }
  2008. dom = h(
  2009. 'svg',
  2010. {
  2011. 'class': className,
  2012. attrs: { version: '1.1',
  2013. xmlns: 'http://www.w3.org/2000/svg',
  2014. xmlnsXlink: 'http://www.w3.org/1999/xlink',
  2015. x: '0px',
  2016. y: '0px',
  2017. viewBox: '0 0 1000 1000',
  2018. 'enable-background': 'new 0 0 1000 1000',
  2019. xmlSpace: 'preserve'
  2020. }
  2021. },
  2022. [h('metadata', [' Svg Vector Icons : http://www.sfont.cn ']), h('g', [h(
  2023. 'g',
  2024. {
  2025. attrs: { transform: 'matrix(1 0 0 -1 0 1008)' }
  2026. },
  2027. [h('path', {
  2028. attrs: { d: 'M10,543l490,455l490-455L885,438L570,735.5V18H430v717.5L115,438L10,543z' }
  2029. })]
  2030. )])]
  2031. );
  2032. }
  2033. break;
  2034. case 'start':
  2035. dom = h(
  2036. 'svg',
  2037. {
  2038. attrs: { viewBox: '0 0 50 50' },
  2039. 'class': 'start' },
  2040. [h('circle', {
  2041. attrs: { stroke: 'true', cx: '25', cy: '25', r: '20' },
  2042. 'class': 'bg-path' }), h('circle', {
  2043. attrs: { cx: '25', cy: '25', r: '20' },
  2044. 'class': 'active-path' })]
  2045. );
  2046. break;
  2047. case 'beforeDeactive':
  2048. dom = h(
  2049. 'svg',
  2050. {
  2051. attrs: {
  2052. viewBox: '0 0 1024 1024',
  2053. version: '1.1',
  2054. xmlns: 'http://www.w3.org/2000/svg',
  2055. 'p-id': '3562'
  2056. }
  2057. },
  2058. [h('path', {
  2059. attrs: {
  2060. d: 'M512 0C229.706831 0 0 229.667446 0 512s229.667446 512 512 512c282.293169 0 512-229.667446 512-512S794.332554 0 512 0z m282.994215 353.406031L433.2544 715.145846a31.484062 31.484062 0 0 1-22.275938 9.231754h-0.4096a31.586462 31.586462 0 0 1-22.449231-9.814646L228.430769 546.327631a31.507692 31.507692 0 0 1 45.701908-43.386093l137.4208 144.785724L750.442338 308.854154a31.507692 31.507692 0 1 1 44.551877 44.551877z',
  2061. fill: '',
  2062. 'p-id': '3563'
  2063. }
  2064. })]
  2065. );
  2066. break;
  2067. }
  2068. return [dom, tip];
  2069. }
  2070. /**
  2071. * create a scrollPanel
  2072. *
  2073. * @param {any} size
  2074. * @param {any} context
  2075. * @returns
  2076. */
  2077. function createPanel$1(h, context) {
  2078. var data = getPanelData$1(context);
  2079. return h(
  2080. 'scrollPanel',
  2081. data,
  2082. [getPanelChildren$1(h, context)]
  2083. );
  2084. }
  2085. // begin importing
  2086. /**
  2087. * create a scrollPanel
  2088. *
  2089. * @param {any} size
  2090. * @param {any} vm
  2091. * @returns
  2092. */
  2093. function createPanel$2(h, vm) {
  2094. if (vm.mode == 'native') {
  2095. return createPanel(h, vm);
  2096. } else if (vm.mode == 'slide') {
  2097. return createPanel$1(h, vm);
  2098. }
  2099. }
  2100. // detect content size change
  2101. function installResizeDetection(element, callback) {
  2102. return injectObject(element, callback);
  2103. }
  2104. function injectObject(element, callback) {
  2105. if (element.hasResized) {
  2106. return;
  2107. }
  2108. 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;';
  2109. // define a wrap due to ie's zIndex bug
  2110. var objWrap = document.createElement('div');
  2111. objWrap.style.cssText = OBJECT_STYLE;
  2112. var object = document.createElement('object');
  2113. object.style.cssText = OBJECT_STYLE;
  2114. object.type = 'text/html';
  2115. object.tabIndex = -1;
  2116. object.onload = function () {
  2117. eventCenter(object.contentDocument.defaultView, 'resize', callback);
  2118. };
  2119. // https://github.com/wnr/element-resize-detector/blob/aafe9f7ea11d1eebdab722c7c5b86634e734b9b8/src/detection-strategy/object.js#L159
  2120. if (!isIE()) {
  2121. object.data = 'about:blank';
  2122. }
  2123. objWrap.isResizeElm = true;
  2124. objWrap.appendChild(object);
  2125. element.appendChild(objWrap);
  2126. if (isIE()) {
  2127. object.data = 'about:blank';
  2128. }
  2129. return function destroy() {
  2130. if (object.contentDocument) {
  2131. eventCenter(object.contentDocument.defaultView, 'resize', callback, 'off');
  2132. }
  2133. element.removeChild(objWrap);
  2134. element.hasResized = false;
  2135. };
  2136. }
  2137. var slideApi = {
  2138. methods: {
  2139. slideScrollTo: function slideScrollTo(x, y, speed, easing) {
  2140. var _getPosition = this.getPosition(),
  2141. scrollLeft = _getPosition.scrollLeft,
  2142. scrollTop = _getPosition.scrollTop;
  2143. x = getNumericValue(x || scrollLeft, this.scroller.__maxScrollLeft);
  2144. y = getNumericValue(y || scrollTop, this.scroller.__maxScrollTop);
  2145. this.scroller.scrollTo(x, y, speed > 0, undefined, false, speed, easing);
  2146. },
  2147. zoomBy: function zoomBy(factor, animate, originLeft, originTop, callback) {
  2148. if (!this.scroller) {
  2149. warn('zoomBy and zoomTo are only for slide mode!');
  2150. return;
  2151. }
  2152. this.scroller.zoomBy(factor, animate, originLeft, originTop, callback);
  2153. },
  2154. zoomTo: function zoomTo(level) {
  2155. var animate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2156. var originLeft = arguments[2];
  2157. var originTop = arguments[3];
  2158. var callback = arguments[4];
  2159. if (!this.scroller) {
  2160. warn('zoomBy and zoomTo are only for slide mode!');
  2161. return;
  2162. }
  2163. this.scroller.zoomTo(level, animate, originLeft, originTop, callback);
  2164. },
  2165. getCurrentPage: function getCurrentPage() {
  2166. if (!this.scroller || !this.mergedOptions.vuescroll.paging) {
  2167. warn('getCurrentPage and goToPage are only for slide mode and paging is enble!');
  2168. return;
  2169. }
  2170. return this.scroller.getCurrentPage();
  2171. },
  2172. goToPage: function goToPage(dest) {
  2173. var animate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2174. if (!this.scroller || !this.mergedOptions.vuescroll.paging) {
  2175. warn('getCurrentPage and goToPage are only for slide mode and paging is enble!');
  2176. return;
  2177. }
  2178. this.scroller.goToPage(dest, animate);
  2179. },
  2180. triggerRefreshOrLoad: function triggerRefreshOrLoad(type) {
  2181. if (!this.scroller) {
  2182. warn('You can only use triggerRefreshOrLoad in slide mode!');
  2183. return;
  2184. }
  2185. var isRefresh = this.mergedOptions.vuescroll.pullRefresh.enable;
  2186. var isLoad = this.mergedOptions.vuescroll.pushLoad.enable;
  2187. if (type == 'refresh' && !isRefresh) {
  2188. warn('refresh must be enabled!');
  2189. return;
  2190. } else if (type == 'load' && !isLoad) {
  2191. warn('load must be enabled and content\'s height > container\'s height!');
  2192. return;
  2193. } else if (type !== 'refresh' && type !== 'load') {
  2194. warn('param must be one of load and refresh!');
  2195. return;
  2196. }
  2197. /* istanbul ignore if */
  2198. if (this.vuescroll.state[type + 'Stage'] == 'start') {
  2199. return;
  2200. }
  2201. this.scroller.triggerRefreshOrLoad(type);
  2202. return true;
  2203. },
  2204. getCurrentviewDomSlide: function getCurrentviewDomSlide() {
  2205. var parent = this.scrollPanelElm;
  2206. var domFragment = getCurrentViewportDom(parent, this.$el);
  2207. return domFragment;
  2208. }
  2209. }
  2210. };
  2211. var api$1 = {
  2212. // mix slide and nitive modes apis.
  2213. mixins: [slideApi, nativeApi],
  2214. methods: {
  2215. // private api
  2216. internalScrollTo: function internalScrollTo(destX, destY, speed, easing) {
  2217. if (this.mode == 'native') {
  2218. this.nativeScrollTo(destX, destY, speed, easing);
  2219. }
  2220. // for non-native we use scroller's scorllTo
  2221. else if (this.mode == 'slide') {
  2222. this.slideScrollTo(destX, destY, speed, easing);
  2223. }
  2224. },
  2225. stop: function stop() {
  2226. this.nativeStop();
  2227. },
  2228. pause: function pause() {
  2229. this.nativePause();
  2230. },
  2231. continue: function _continue() {
  2232. this.nativeContinue();
  2233. },
  2234. getCurrentviewDom: function getCurrentviewDom() {
  2235. return this.mode == 'slide' ? this.getCurrentviewDomSlide() : this.getCurrentviewDomNative();
  2236. }
  2237. }
  2238. };
  2239. /*
  2240. * Scroller
  2241. * http://github.com/zynga/scroller
  2242. *
  2243. * Copyright 2011, Zynga Inc.
  2244. * Licensed under the MIT License.
  2245. * https://raw.github.com/zynga/scroller/master/MIT-LICENSE.txt
  2246. *
  2247. * Based on the work of: Unify Project (unify-project.org)
  2248. * http://unify-project.org
  2249. * Copyright 2011, Deutsche Telekom AG
  2250. * License: MIT + Apache (V2)
  2251. */
  2252. var time = Date.now || function () {
  2253. return +new Date();
  2254. };
  2255. var desiredFrames = 60;
  2256. var millisecondsPerSecond = 1000;
  2257. var running = {};
  2258. var counter = 1;
  2259. var core = { effect: {} };
  2260. var global = null;
  2261. if (typeof window !== 'undefined') {
  2262. global = window;
  2263. } else {
  2264. global = {};
  2265. }
  2266. core.effect.Animate = {
  2267. /**
  2268. * A requestAnimationFrame wrapper / polyfill.
  2269. *
  2270. * @param callback {Function} The callback to be invoked before the next repaint.
  2271. * @param root {HTMLElement} The root element for the repaint
  2272. */
  2273. requestAnimationFrame: requestAnimationFrame(global),
  2274. /**
  2275. * Stops the given animation.
  2276. *
  2277. * @param id {Integer} Unique animation ID
  2278. * @return {Boolean} Whether the animation was stopped (aka, was running before)
  2279. */
  2280. stop: function stop(id) {
  2281. var cleared = running[id] != null;
  2282. if (cleared) {
  2283. running[id] = null;
  2284. }
  2285. return cleared;
  2286. },
  2287. /**
  2288. * Whether the given animation is still running.
  2289. *
  2290. * @param id {Integer} Unique animation ID
  2291. * @return {Boolean} Whether the animation is still running
  2292. */
  2293. isRunning: function isRunning(id) {
  2294. return running[id] != null;
  2295. },
  2296. /**
  2297. * Start the animation.
  2298. *
  2299. * @param stepCallback {Function} Pointer to function which is executed on every step.
  2300. * Signature of the method should be `function(percent, now, virtual) { return continueWithAnimation; }`
  2301. * @param verifyCallback {Function} Executed before every animation step.
  2302. * Signature of the method should be `function() { return continueWithAnimation; }`
  2303. * @param completedCallback {Function}
  2304. * Signature of the method should be `function(droppedFrames, finishedAnimation) {}`
  2305. * @param duration {Integer} Milliseconds to run the animation
  2306. * @param easingMethod {Function} Pointer to easing function
  2307. * Signature of the method should be `function(percent) { return modifiedValue; }`
  2308. * @param root {Element ? document.body} Render root, when available. Used for internal
  2309. * usage of requestAnimationFrame.
  2310. * @return {Integer} Identifier of animation. Can be used to stop it any time.
  2311. */
  2312. start: function start(stepCallback, verifyCallback, completedCallback, duration, easingMethod, root) {
  2313. var start = time();
  2314. var lastFrame = start;
  2315. var percent = 0;
  2316. var dropCounter = 0;
  2317. var id = counter++;
  2318. if (!root) {
  2319. root = document.body;
  2320. }
  2321. // Compacting running db automatically every few new animations
  2322. if (id % 20 === 0) {
  2323. var newRunning = {};
  2324. for (var usedId in running) {
  2325. newRunning[usedId] = true;
  2326. }
  2327. running = newRunning;
  2328. }
  2329. // This is the internal step method which is called every few milliseconds
  2330. var step = function step(virtual) {
  2331. // Normalize virtual value
  2332. var render = virtual !== true;
  2333. // Get current time
  2334. var now = time();
  2335. // Verification is executed before next animation step
  2336. if (!running[id] || verifyCallback && !verifyCallback(id)) {
  2337. running[id] = null;
  2338. completedCallback && completedCallback(desiredFrames - dropCounter / ((now - start) / millisecondsPerSecond), id, false);
  2339. return;
  2340. }
  2341. // For the current rendering to apply let's update omitted steps in memory.
  2342. // This is important to bring internal state variables up-to-date with progress in time.
  2343. if (render) {
  2344. var droppedFrames = Math.round((now - lastFrame) / (millisecondsPerSecond / desiredFrames)) - 1;
  2345. for (var j = 0; j < Math.min(droppedFrames, 4); j++) {
  2346. step(true);
  2347. dropCounter++;
  2348. }
  2349. }
  2350. if (!running[id]) {
  2351. return;
  2352. }
  2353. // Compute percent value
  2354. if (duration) {
  2355. percent = (now - start) / duration;
  2356. if (percent > 1) {
  2357. percent = 1;
  2358. }
  2359. }
  2360. // Execute step callback, then...
  2361. var value = easingMethod ? easingMethod(percent) : percent;
  2362. if ((stepCallback(value, now, render) === false || percent === 1) && render) {
  2363. running[id] = null;
  2364. completedCallback && completedCallback(desiredFrames - dropCounter / ((now - start) / millisecondsPerSecond), id, percent === 1 || duration == null);
  2365. } else if (render) {
  2366. lastFrame = now;
  2367. core.effect.Animate.requestAnimationFrame(step, root);
  2368. }
  2369. };
  2370. // Mark as running
  2371. running[id] = true;
  2372. // Init first step
  2373. core.effect.Animate.requestAnimationFrame(step, root);
  2374. // Return unique animation ID
  2375. return id;
  2376. }
  2377. };
  2378. /*
  2379. * Scroller
  2380. * http://github.com/zynga/scroller
  2381. *
  2382. * modified by wangyi7099
  2383. *
  2384. * Copyright 2011, Zynga Inc.
  2385. * Licensed under the MIT License.
  2386. * https://raw.github.com/zynga/scroller/master/MIT-LICENSE.txt
  2387. *
  2388. * Based on the work of: Unify Project (unify-project.org)
  2389. * http://unify-project.org
  2390. * Copyright 2011, Deutsche Telekom AG
  2391. * License: MIT + Apache (V2)
  2392. */
  2393. var animatingMethod = null;
  2394. var noAnimatingMethod = null;
  2395. function Scroller(callback, options) {
  2396. this.__callback = callback;
  2397. this.options = {
  2398. /** Enable scrolling on x-axis */
  2399. scrollingX: true,
  2400. /** Enable scrolling on y-axis */
  2401. scrollingY: true,
  2402. /** Enable animations for deceleration, snap back, zooming and scrolling */
  2403. animating: true,
  2404. /** duration for animations triggered by scrollTo/zoomTo */
  2405. animationDuration: 250,
  2406. /** Enable bouncing (content can be slowly moved outside and jumps back after releasing) */
  2407. bouncing: {
  2408. top: 100,
  2409. bottom: 100,
  2410. left: 100,
  2411. right: 100
  2412. },
  2413. /** Enable locking to the main axis if user moves only slightly on one of them at start */
  2414. locking: true,
  2415. /** Enable pagination mode (switching between full page content panes) */
  2416. paging: false,
  2417. /** Enable snapping of content to a configured pixel grid */
  2418. snapping: false,
  2419. /** Enable zooming of content via API, fingers and mouse wheel */
  2420. zooming: false,
  2421. /** Minimum zoom level */
  2422. minZoom: 0.5,
  2423. /** Maximum zoom level */
  2424. maxZoom: 3,
  2425. /** Multiply or decrease scrolling speed **/
  2426. speedMultiplier: 1,
  2427. /** Callback that is fired on the later of touch end or deceleration end,
  2428. provided that another scrolling action has not begun. Used to know
  2429. when to fade out a scrollbar. */
  2430. scrollingComplete: NOOP,
  2431. animatingEasing: 'easeOutCubic',
  2432. noAnimatingEasing: 'easeInOutCubic',
  2433. /** This configures the amount of change applied to deceleration when reaching boundaries **/
  2434. penetrationDeceleration: 0.03,
  2435. /** This configures the amount of change applied to acceleration when reaching boundaries **/
  2436. penetrationAcceleration: 0.08
  2437. };
  2438. for (var key in options) {
  2439. this.options[key] = options[key];
  2440. }
  2441. animatingMethod = createEasingFunction(this.options.animatingEasing, easingPattern);
  2442. noAnimatingMethod = createEasingFunction(this.options.noAnimatingEasing, easingPattern);
  2443. }
  2444. var members = {
  2445. /*
  2446. ---------------------------------------------------------------------------
  2447. INTERNAL FIELDS :: STATUS
  2448. ---------------------------------------------------------------------------
  2449. */
  2450. /** {Boolean} Whether only a single finger is used in touch handling */
  2451. __isSingleTouch: false,
  2452. /** {Boolean} Whether a touch event sequence is in progress */
  2453. __isTracking: false,
  2454. /** {Boolean} Whether a deceleration animation went to completion. */
  2455. __didDecelerationComplete: false,
  2456. /**
  2457. * {Boolean} Whether a gesture zoom/rotate event is in progress. Activates when
  2458. * a gesturestart event happens. This has higher priority than dragging.
  2459. */
  2460. __isGesturing: false,
  2461. /**
  2462. * {Boolean} Whether the user has moved by such a distance that we have enabled
  2463. * dragging mode. Hint: It's only enabled after some pixels of movement to
  2464. * not interrupt with clicks etc.
  2465. */
  2466. __isDragging: false,
  2467. /**
  2468. * {Boolean} Not touching and dragging anymore, and smoothly animating the
  2469. * touch sequence using deceleration.
  2470. */
  2471. __isDecelerating: false,
  2472. /**
  2473. * {Boolean} Smoothly animating the currently configured change
  2474. */
  2475. __isAnimating: false,
  2476. /*
  2477. ---------------------------------------------------------------------------
  2478. INTERNAL FIELDS :: DIMENSIONS
  2479. ---------------------------------------------------------------------------
  2480. */
  2481. /** {Integer} Available outer left position (from document perspective) */
  2482. __clientLeft: 0,
  2483. /** {Integer} Available outer top position (from document perspective) */
  2484. __clientTop: 0,
  2485. /** {Integer} Available outer width */
  2486. __clientWidth: 0,
  2487. /** {Integer} Available outer height */
  2488. __clientHeight: 0,
  2489. /** {Integer} Outer width of content */
  2490. __contentWidth: 0,
  2491. /** {Integer} Outer height of content */
  2492. __contentHeight: 0,
  2493. /** {Integer} Snapping width for content */
  2494. __snapWidth: 100,
  2495. /** {Integer} Snapping height for content */
  2496. __snapHeight: 100,
  2497. /** {Integer} Height to assign to refresh area */
  2498. __refreshHeight: null,
  2499. /** {Integer} Height to assign to refresh area */
  2500. __loadHeight: null,
  2501. /** {Boolean} Whether the refresh process is enabled when the event is released now */
  2502. __refreshActive: false,
  2503. /** {Function} Callback to execute on activation. This is for signalling the user about a refresh is about to happen when he release */
  2504. __refreshActivate: null,
  2505. __refreshBeforeDeactivate: null,
  2506. /** {Function} Callback to execute on deactivation. This is for signalling the user about the refresh being cancelled */
  2507. __refreshDeactivate: null,
  2508. /** {Function} Callback to execute to start the actual refresh. Call {@link #refreshFinish} when done */
  2509. __refreshStart: null,
  2510. __loadActive: null,
  2511. __loadActivate: null,
  2512. __loadBeforeDeactivate: null,
  2513. __loadDeactivate: null,
  2514. __loadStart: null,
  2515. /** {Number} Zoom level */
  2516. __zoomLevel: 1,
  2517. /** {Number} Scroll position on x-axis */
  2518. __scrollLeft: 0,
  2519. /** {Number} Scroll position on y-axis */
  2520. __scrollTop: 0,
  2521. /** {Integer} Maximum allowed scroll position on x-axis */
  2522. __maxScrollLeft: 0,
  2523. /** {Integer} Maximum allowed scroll position on y-axis */
  2524. __maxScrollTop: 0,
  2525. /* {Number} Scheduled left position (final position when animating) */
  2526. __scheduledLeft: 0,
  2527. /* {Number} Scheduled top position (final position when animating) */
  2528. __scheduledTop: 0,
  2529. /* {Number} Scheduled zoom level (final scale when animating) */
  2530. __scheduledZoom: 0,
  2531. /**
  2532. * current page
  2533. */
  2534. __currentPageX: null,
  2535. __currentPageY: null,
  2536. /**
  2537. * total page
  2538. */
  2539. __totalXPage: null,
  2540. __totalYPage: null,
  2541. /*
  2542. ---------------------------------------------------------------------------
  2543. INTERNAL FIELDS :: LAST POSITIONS
  2544. ---------------------------------------------------------------------------
  2545. */
  2546. /** whether the scroller is disabled or not */
  2547. __disable: false,
  2548. /** {Number} Left position of finger at start */
  2549. __lastTouchLeft: null,
  2550. /** {Number} Top position of finger at start */
  2551. __lastTouchTop: null,
  2552. /** {Date} Timestamp of last move of finger. Used to limit tracking range for deceleration speed. */
  2553. __lastTouchMove: null,
  2554. /** {Array} List of positions, uses three indexes for each state: left, top, timestamp */
  2555. __positions: null,
  2556. /*
  2557. ---------------------------------------------------------------------------
  2558. INTERNAL FIELDS :: DECELERATION SUPPORT
  2559. ---------------------------------------------------------------------------
  2560. */
  2561. /** {Integer} Minimum left scroll position during deceleration */
  2562. __minDecelerationScrollLeft: null,
  2563. /** {Integer} Minimum top scroll position during deceleration */
  2564. __minDecelerationScrollTop: null,
  2565. /** {Integer} Maximum left scroll position during deceleration */
  2566. __maxDecelerationScrollLeft: null,
  2567. /** {Integer} Maximum top scroll position during deceleration */
  2568. __maxDecelerationScrollTop: null,
  2569. /** {Number} Current factor to modify horizontal scroll position with on every step */
  2570. __decelerationVelocityX: null,
  2571. /** {Number} Current factor to modify vertical scroll position with on every step */
  2572. __decelerationVelocityY: null,
  2573. /*
  2574. ---------------------------------------------------------------------------
  2575. PUBLIC API
  2576. ---------------------------------------------------------------------------
  2577. */
  2578. /**
  2579. * Configures the dimensions of the client (outer) and content (inner) elements.
  2580. * Requires the available space for the outer element and the outer size of the inner element.
  2581. * All values which are falsy (null or zero etc.) are ignored and the old value is kept.
  2582. *
  2583. * @param clientWidth {Integer ? null} Inner width of outer element
  2584. * @param clientHeight {Integer ? null} Inner height of outer element
  2585. * @param contentWidth {Integer ? null} Outer width of inner element
  2586. * @param contentHeight {Integer ? null} Outer height of inner element
  2587. */
  2588. setDimensions: function setDimensions(clientWidth, clientHeight, contentWidth, contentHeight, animate) {
  2589. var noScroll = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
  2590. var self = this;
  2591. // Only update values which are defined
  2592. if (clientWidth === +clientWidth) {
  2593. self.__clientWidth = clientWidth;
  2594. }
  2595. if (clientHeight === +clientHeight) {
  2596. self.__clientHeight = clientHeight;
  2597. }
  2598. if (contentWidth === +contentWidth) {
  2599. self.__contentWidth = contentWidth;
  2600. }
  2601. if (contentHeight === +contentHeight) {
  2602. self.__contentHeight = contentHeight;
  2603. }
  2604. // Refresh maximums
  2605. self.__computeScrollMax();
  2606. if (!noScroll) {
  2607. // Refresh scroll position
  2608. self.scrollTo(self.__scrollLeft, self.__scrollTop, animate);
  2609. }
  2610. },
  2611. /**
  2612. * Sets the client coordinates in relation to the document.
  2613. *
  2614. * @param left {Integer ? 0} Left position of outer element
  2615. * @param top {Integer ? 0} Top position of outer element
  2616. */
  2617. setPosition: function setPosition(left, top) {
  2618. var self = this;
  2619. self.__clientLeft = left || 0;
  2620. self.__clientTop = top || 0;
  2621. },
  2622. /**
  2623. * Configures the snapping (when snapping is active)
  2624. *
  2625. * @param width {Integer} Snapping width
  2626. * @param height {Integer} Snapping height
  2627. */
  2628. setSnapSize: function setSnapSize(width, height) {
  2629. var self = this;
  2630. self.__snapWidth = width;
  2631. self.__snapHeight = height;
  2632. },
  2633. /**
  2634. * Activates pull-to-refresh. A special zone on the top of the list to start a list refresh whenever
  2635. * the user event is released during visibility of this zone. This was introduced by some apps on iOS like
  2636. * the official Twitter client.
  2637. *
  2638. * @param height {Integer} Height of pull-to-refresh zone on top of rendered list
  2639. * @param activateCallback {Function} Callback to execute on activation. This is for signalling the user about a refresh is about to happen when he release.
  2640. * @param deactivateCallback {Function} Callback to execute on deactivation. This is for signalling the user about the refresh being cancelled.
  2641. * @param startCallback {Function} Callback to execute to start the real async refresh action. Call {@link #finishPullToRefresh} after finish of refresh.
  2642. */
  2643. activatePullToRefresh: function activatePullToRefresh(height, _ref) {
  2644. var activateCallback = _ref.activateCallback,
  2645. deactivateCallback = _ref.deactivateCallback,
  2646. startCallback = _ref.startCallback,
  2647. beforeDeactivateCallback = _ref.beforeDeactivateCallback,
  2648. beforeDeactiveEnd = _ref.beforeDeactiveEnd;
  2649. var self = this;
  2650. self.__refreshHeight = height;
  2651. self.__refreshActivate = activateCallback;
  2652. self.__refreshBeforeDeactivate = beforeDeactivateCallback;
  2653. self.__refreshBeforeDeactiveEnd = beforeDeactiveEnd;
  2654. self.__refreshDeactivate = deactivateCallback;
  2655. self.__refreshStart = startCallback;
  2656. },
  2657. activatePushToLoad: function activatePushToLoad(height, _ref2) {
  2658. var activateCallback = _ref2.activateCallback,
  2659. deactivateCallback = _ref2.deactivateCallback,
  2660. startCallback = _ref2.startCallback,
  2661. beforeDeactivateCallback = _ref2.beforeDeactivateCallback,
  2662. beforeDeactiveEnd = _ref2.beforeDeactiveEnd;
  2663. var self = this;
  2664. self.__loadHeight = height;
  2665. self.__loadActivate = activateCallback;
  2666. self.__loadBeforeDeactivate = beforeDeactivateCallback;
  2667. self.__loadBeforeDeactiveEnd = beforeDeactiveEnd;
  2668. self.__loadDeactivate = deactivateCallback;
  2669. self.__loadStart = startCallback;
  2670. },
  2671. /**
  2672. * Starts pull-to-refresh manually.
  2673. */
  2674. triggerRefreshOrLoad: function triggerRefreshOrLoad() {
  2675. var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'refresh';
  2676. var wasDecelerating = this.__isDecelerating;
  2677. if (wasDecelerating) {
  2678. core.effect.Animate.stop(wasDecelerating);
  2679. this.__isDecelerating = false;
  2680. }
  2681. // Use publish instead of scrollTo to allow scrolling to out of boundary position
  2682. // We don't need to normalize scrollLeft, zoomLevel, etc. here because we only y-scrolling when pull-to-refresh is enabled
  2683. if (type == 'refresh') {
  2684. if (this.__refreshActive || this.__refreshBeforeDeactiveStarted) return;
  2685. this.__publish(this.__scrollLeft, -this.__refreshHeight, this.__zoomLevel, true);
  2686. if (this.__refreshStart) {
  2687. this.__refreshStart();
  2688. this.__refreshActive = true;
  2689. }
  2690. } else if (type == 'load') {
  2691. if (this.__loadActive || this.__loadBeforeDeactiveStarted) return;
  2692. this.__publish(this.__scrollLeft, this.__maxScrollTop + this.__loadHeight, this.__zoomLevel, true);
  2693. if (this.__loadStart) {
  2694. this.__loadStart();
  2695. this.__loadActive = true;
  2696. }
  2697. }
  2698. },
  2699. /**
  2700. * Signalizes that pull-to-refresh is finished.
  2701. */
  2702. finishRefreshOrLoad: function finishRefreshOrLoad() {
  2703. var self = this;
  2704. if (self.__refreshActive) {
  2705. self.__refreshActive = false;
  2706. var endRefreshActive = function endRefreshActive() {
  2707. if (self.__refreshBeforeDeactiveEnd) {
  2708. self.__refreshBeforeDeactiveEnd();
  2709. }
  2710. self.__refreshBeforeDeactiveStarted = true;
  2711. self.scrollTo(self.__scrollLeft, self.__scrollTop, true);
  2712. };
  2713. if (self.__refreshBeforeDeactivate) {
  2714. self.__refreshBeforeDeactivate(endRefreshActive);
  2715. } else {
  2716. endRefreshActive();
  2717. }
  2718. }
  2719. if (self.__loadActive) {
  2720. self.__loadActive = false;
  2721. var endLoadActive = function endLoadActive() {
  2722. if (self.__loadBeforeDeactiveEnd) {
  2723. self.__loadBeforeDeactiveEnd();
  2724. }
  2725. self.__loadBeforeDeactiveStarted = true;
  2726. self.scrollTo(self.__scrollLeft, self.__scrollTop, true);
  2727. };
  2728. if (self.__loadBeforeDeactivate) {
  2729. self.__loadBeforeDeactivate(endLoadActive);
  2730. } else {
  2731. endLoadActive();
  2732. }
  2733. }
  2734. },
  2735. /**
  2736. * Returns the scroll position and zooming values
  2737. *
  2738. * @return {Map} `left` and `top` scroll position and `zoom` level
  2739. */
  2740. getValues: function getValues() {
  2741. var self = this;
  2742. return {
  2743. left: self.__scrollLeft,
  2744. top: self.__scrollTop,
  2745. zoom: self.__zoomLevel
  2746. };
  2747. },
  2748. /**
  2749. * Returns the maximum scroll values
  2750. *
  2751. * @return {Map} `left` and `top` maximum scroll values
  2752. */
  2753. getScrollMax: function getScrollMax() {
  2754. var self = this;
  2755. return {
  2756. left: self.__maxScrollLeft,
  2757. top: self.__maxScrollTop
  2758. };
  2759. },
  2760. /**
  2761. * Zooms to the given level. Supports optional animation. Zooms
  2762. * the center when no coordinates are given.
  2763. *
  2764. * @param level {Number} Level to zoom to
  2765. * @param animate {Boolean ? false} Whether to use animation
  2766. * @param originLeft {Number ? null} Zoom in at given left coordinate
  2767. * @param originTop {Number ? null} Zoom in at given top coordinate
  2768. * @param callback {Function ? null} A callback that gets fired when the zoom is complete.
  2769. */
  2770. zoomTo: function zoomTo(level, animate, originLeft, originTop, callback) {
  2771. var self = this;
  2772. if (!self.options.zooming) {
  2773. throw new Error('Zooming is not enabled!');
  2774. }
  2775. // Add callback if exists
  2776. if (callback) {
  2777. self.__zoomComplete = callback;
  2778. }
  2779. // Stop deceleration
  2780. if (self.__isDecelerating) {
  2781. core.effect.Animate.stop(self.__isDecelerating);
  2782. self.__isDecelerating = false;
  2783. }
  2784. var oldLevel = self.__zoomLevel;
  2785. // Normalize input origin to center of viewport if not defined
  2786. if (originLeft == null) {
  2787. originLeft = self.__clientWidth / 2;
  2788. }
  2789. if (originTop == null) {
  2790. originTop = self.__clientHeight / 2;
  2791. }
  2792. // Limit level according to configuration
  2793. level = Math.max(Math.min(level, self.options.maxZoom), self.options.minZoom);
  2794. // Recompute maximum values while temporary tweaking maximum scroll ranges
  2795. self.__computeScrollMax(level);
  2796. // Recompute left and top coordinates based on new zoom level
  2797. var left = (originLeft + self.__scrollLeft) * level / oldLevel - originLeft;
  2798. var top = (originTop + self.__scrollTop) * level / oldLevel - originTop;
  2799. // Limit x-axis
  2800. if (left > self.__maxScrollLeft) {
  2801. left = self.__maxScrollLeft;
  2802. } else if (left < 0) {
  2803. left = 0;
  2804. }
  2805. // Limit y-axis
  2806. if (top > self.__maxScrollTop) {
  2807. top = self.__maxScrollTop;
  2808. } else if (top < 0) {
  2809. top = 0;
  2810. }
  2811. // Push values out
  2812. self.__publish(left, top, level, animate);
  2813. },
  2814. /**
  2815. * Zooms the content by the given factor.
  2816. *
  2817. * @param factor {Number} Zoom by given factor
  2818. * @param animate {Boolean ? false} Whether to use animation
  2819. * @param originLeft {Number ? 0} Zoom in at given left coordinate
  2820. * @param originTop {Number ? 0} Zoom in at given top coordinate
  2821. * @param callback {Function ? null} A callback that gets fired when the zoom is complete.
  2822. */
  2823. zoomBy: function zoomBy(factor, animate, originLeft, originTop, callback) {
  2824. var self = this;
  2825. self.zoomTo(self.__zoomLevel * factor, animate, originLeft, originTop, callback);
  2826. },
  2827. /**
  2828. * Scrolls to the given position. Respect limitations and snapping automatically.
  2829. *
  2830. * @param left {Number?null} Horizontal scroll position, keeps current if value is <code>null</code>
  2831. * @param top {Number?null} Vertical scroll position, keeps current if value is <code>null</code>
  2832. * @param animate {Boolean?false} Whether the scrolling should happen using an animation
  2833. * @param zoom {Number?null} Zoom level to go to
  2834. */
  2835. scrollTo: function scrollTo(left, top, animate, zoom, force, speed, easing) {
  2836. var self = this;
  2837. // Stop deceleration
  2838. if (self.__isDecelerating) {
  2839. core.effect.Animate.stop(self.__isDecelerating);
  2840. self.__isDecelerating = false;
  2841. }
  2842. // Correct coordinates based on new zoom level
  2843. if (zoom != null && zoom !== self.__zoomLevel) {
  2844. if (!self.options.zooming) {
  2845. throw new Error('Zooming is not enabled!');
  2846. }
  2847. left *= zoom;
  2848. top *= zoom;
  2849. // Recompute maximum values while temporary tweaking maximum scroll ranges
  2850. self.__computeScrollMax(zoom);
  2851. } else {
  2852. // Keep zoom when not defined
  2853. zoom = self.__zoomLevel;
  2854. }
  2855. if (!self.options.scrollingX && !force) {
  2856. left = self.__scrollLeft;
  2857. } else {
  2858. if (self.options.paging) {
  2859. left = Math.round(left / self.__clientWidth) * self.__clientWidth;
  2860. } else if (self.options.snapping) {
  2861. left = Math.round(left / self.__snapWidth) * self.__snapWidth;
  2862. }
  2863. }
  2864. if (!self.options.scrollingY && !force) {
  2865. top = self.__scrollTop;
  2866. } else {
  2867. if (self.options.paging) {
  2868. top = Math.round(top / self.__clientHeight) * self.__clientHeight;
  2869. } else if (self.options.snapping) {
  2870. top = Math.round(top / self.__snapHeight) * self.__snapHeight;
  2871. }
  2872. }
  2873. if (!force) {
  2874. // Limit for allowed ranges
  2875. left = Math.max(Math.min(self.__maxScrollLeft, left), 0);
  2876. top = Math.max(Math.min(self.__maxScrollTop, top), 0);
  2877. }
  2878. // Don't animate when no change detected, still call publish to make sure
  2879. // that rendered position is really in-sync with internal data
  2880. if (left === self.__scrollLeft && top === self.__scrollTop) {
  2881. animate = false;
  2882. }
  2883. // Publish new values
  2884. if (!self.__isTracking) {
  2885. self.__publish(left, top, zoom, animate, speed, easing);
  2886. }
  2887. },
  2888. /**
  2889. * Scroll by the given offset
  2890. *
  2891. * @param left {Number ? 0} Scroll x-axis by given offset
  2892. * @param top {Number ? 0} Scroll x-axis by given offset
  2893. * @param animate {Boolean ? false} Whether to animate the given change
  2894. */
  2895. scrollBy: function scrollBy(left, top, animate) {
  2896. var self = this;
  2897. var startLeft = self.__isAnimating ? self.__scheduledLeft : self.__scrollLeft;
  2898. var startTop = self.__isAnimating ? self.__scheduledTop : self.__scrollTop;
  2899. self.scrollTo(startLeft + (left || 0), startTop + (top || 0), animate);
  2900. },
  2901. getCurrentPage: function getCurrentPage() {
  2902. this.__computePage();
  2903. return {
  2904. x: this.__currentPageX,
  2905. y: this.__currentPageY
  2906. };
  2907. },
  2908. goToPage: function goToPage(_ref3, animate) {
  2909. var x = _ref3.x,
  2910. y = _ref3.y;
  2911. if (isNaN(x)) {
  2912. x = 1;
  2913. }
  2914. if (isNaN(y)) {
  2915. y = 1;
  2916. }
  2917. this.scrollTo((x - 1) * this.__clientWidth, (y - 1) * this.__clientHeight, animate);
  2918. },
  2919. /*
  2920. ---------------------------------------------------------------------------
  2921. EVENT CALLBACKS
  2922. ---------------------------------------------------------------------------
  2923. */
  2924. /**
  2925. * Mouse wheel handler for zooming support
  2926. */
  2927. doMouseZoom: function doMouseZoom(wheelDelta, timeStamp, pageX, pageY) {
  2928. var self = this;
  2929. var change = wheelDelta > 0 ? 0.97 : 1.03;
  2930. return self.zoomTo(self.__zoomLevel * change, false, pageX - self.__clientLeft, pageY - self.__clientTop);
  2931. },
  2932. /**
  2933. * Touch start handler for scrolling support
  2934. */
  2935. doTouchStart: function doTouchStart(touches, timeStamp) {
  2936. // Array-like check is enough here
  2937. if (touches.length == null) {
  2938. throw new Error('Invalid touch list: ' + touches);
  2939. }
  2940. if (timeStamp instanceof Date) {
  2941. timeStamp = timeStamp.valueOf();
  2942. }
  2943. if (typeof timeStamp !== 'number') {
  2944. throw new Error('Invalid timestamp value: ' + timeStamp);
  2945. }
  2946. var self = this;
  2947. // Reset interruptedAnimation flag
  2948. self.__interruptedAnimation = true;
  2949. // Stop deceleration
  2950. if (self.__isDecelerating) {
  2951. core.effect.Animate.stop(self.__isDecelerating);
  2952. self.__isDecelerating = false;
  2953. self.__interruptedAnimation = true;
  2954. }
  2955. // Stop animation
  2956. if (self.__isAnimating) {
  2957. core.effect.Animate.stop(self.__isAnimating);
  2958. self.__isAnimating = false;
  2959. self.__interruptedAnimation = true;
  2960. }
  2961. // Use center point when dealing with two fingers
  2962. var currentTouchLeft, currentTouchTop;
  2963. var isSingleTouch = touches.length === 1;
  2964. if (isSingleTouch) {
  2965. currentTouchLeft = touches[0].pageX;
  2966. currentTouchTop = touches[0].pageY;
  2967. } else {
  2968. currentTouchLeft = Math.abs(touches[0].pageX + touches[1].pageX) / 2;
  2969. currentTouchTop = Math.abs(touches[0].pageY + touches[1].pageY) / 2;
  2970. }
  2971. // Store initial positions
  2972. self.__initialTouchLeft = currentTouchLeft;
  2973. self.__initialTouchTop = currentTouchTop;
  2974. // Store current zoom level
  2975. self.__zoomLevelStart = self.__zoomLevel;
  2976. // Store initial touch positions
  2977. self.__lastTouchLeft = currentTouchLeft;
  2978. self.__lastTouchTop = currentTouchTop;
  2979. // Store initial move time stamp
  2980. self.__lastTouchMove = timeStamp;
  2981. // Reset initial scale
  2982. self.__lastScale = 1;
  2983. // Reset locking flags
  2984. self.__enableScrollX = !isSingleTouch && self.options.scrollingX;
  2985. self.__enableScrollY = !isSingleTouch && self.options.scrollingY;
  2986. // Reset tracking flag
  2987. self.__isTracking = true;
  2988. // Reset deceleration complete flag
  2989. self.__didDecelerationComplete = false;
  2990. // Dragging starts directly with two fingers, otherwise lazy with an offset
  2991. self.__isDragging = !isSingleTouch;
  2992. // Some features are in multi touch scenarios
  2993. self.__isSingleTouch = isSingleTouch;
  2994. // Clearing data structure
  2995. self.__positions = [];
  2996. },
  2997. /**
  2998. * Touch move handler for scrolling support
  2999. */
  3000. doTouchMove: function doTouchMove(touches, timeStamp, scale) {
  3001. // Array-like check is enough here
  3002. if (touches.length == null) {
  3003. throw new Error('Invalid touch list: ' + touches);
  3004. }
  3005. if (timeStamp instanceof Date) {
  3006. timeStamp = timeStamp.valueOf();
  3007. }
  3008. if (typeof timeStamp !== 'number') {
  3009. throw new Error('Invalid timestamp value: ' + timeStamp);
  3010. }
  3011. var self = this;
  3012. // Ignore event when tracking is not enabled (event might be outside of element)
  3013. if (!self.__isTracking) {
  3014. return;
  3015. }
  3016. var currentTouchLeft, currentTouchTop;
  3017. // Compute move based around of center of fingers
  3018. if (touches.length === 2) {
  3019. currentTouchLeft = Math.abs(touches[0].pageX + touches[1].pageX) / 2;
  3020. currentTouchTop = Math.abs(touches[0].pageY + touches[1].pageY) / 2;
  3021. } else {
  3022. currentTouchLeft = touches[0].pageX;
  3023. currentTouchTop = touches[0].pageY;
  3024. }
  3025. var positions = self.__positions;
  3026. // Are we already is dragging mode?
  3027. if (self.__isDragging) {
  3028. // Compute move distance
  3029. var moveX = currentTouchLeft - self.__lastTouchLeft;
  3030. var moveY = currentTouchTop - self.__lastTouchTop;
  3031. // Read previous scroll position and zooming
  3032. var scrollLeft = self.__scrollLeft;
  3033. var scrollTop = self.__scrollTop;
  3034. var level = self.__zoomLevel;
  3035. // Work with scaling
  3036. if (scale != null && self.options.zooming) {
  3037. var oldLevel = level;
  3038. // Recompute level based on previous scale and new scale
  3039. level = level / self.__lastScale * scale;
  3040. // Limit level according to configuration
  3041. level = Math.max(Math.min(level, self.options.maxZoom), self.options.minZoom);
  3042. // Only do further compution when change happened
  3043. if (oldLevel !== level) {
  3044. // Compute relative event position to container
  3045. var currentTouchLeftRel = currentTouchLeft - self.__clientLeft;
  3046. var currentTouchTopRel = currentTouchTop - self.__clientTop;
  3047. // Recompute left and top coordinates based on new zoom level
  3048. scrollLeft = (currentTouchLeftRel + scrollLeft) * level / oldLevel - currentTouchLeftRel;
  3049. scrollTop = (currentTouchTopRel + scrollTop) * level / oldLevel - currentTouchTopRel;
  3050. // Recompute max scroll values
  3051. self.__computeScrollMax(level);
  3052. }
  3053. }
  3054. var bouncing = self.options.bouncing;
  3055. if (self.__enableScrollX) {
  3056. scrollLeft -= moveX * this.options.speedMultiplier;
  3057. var maxScrollLeft = self.__maxScrollLeft;
  3058. if (scrollLeft > maxScrollLeft || scrollLeft < 0) {
  3059. scrollLeft += moveX / 2 * this.options.speedMultiplier;
  3060. // fix scrollLeft
  3061. scrollLeft = Math.min(Math.max(-bouncing.left, scrollLeft), maxScrollLeft + bouncing.right);
  3062. }
  3063. }
  3064. // Compute new vertical scroll position
  3065. if (self.__enableScrollY) {
  3066. scrollTop -= moveY * this.options.speedMultiplier;
  3067. var maxScrollTop = self.__maxScrollTop;
  3068. if (scrollTop > maxScrollTop || scrollTop < 0) {
  3069. scrollTop += moveY / 2 * this.options.speedMultiplier;
  3070. // fix scrollTop
  3071. scrollTop = Math.min(Math.max(-bouncing.top, scrollTop), maxScrollTop + bouncing.bottom);
  3072. // Trigger pull to refresh or push to load
  3073. if (!self.__enableScrollX && (self.__refreshHeight != null || self.__loadHeight != null)) {
  3074. if (!self.__refreshActive && scrollTop <= -self.__refreshHeight) {
  3075. self.__refreshActive = true;
  3076. if (self.__refreshActivate) {
  3077. self.__refreshActivate();
  3078. }
  3079. } else if (self.__refreshActive && scrollTop > -self.__refreshHeight) {
  3080. self.__refreshActive = false;
  3081. if (self.__refreshDeactivate) {
  3082. self.__refreshDeactivate();
  3083. }
  3084. }
  3085. // handle for push-load
  3086. else if (!self.__loadActive && scrollTop >= self.__maxScrollTop + self.__loadHeight && self.__loadHeight > 0) {
  3087. self.__loadActive = true;
  3088. if (self.__loadActivate) {
  3089. self.__loadActivate();
  3090. }
  3091. } else if (self.__loadActive && scrollTop < self.__maxScrollTop + self.__loadHeight) {
  3092. self.__loadActive = false;
  3093. if (self.__loadDeactivate) {
  3094. self.__loadDeactivate();
  3095. }
  3096. }
  3097. }
  3098. }
  3099. }
  3100. // Keep list from growing infinitely (holding min 10, max 20 measure points)
  3101. if (positions.length > 60) {
  3102. positions.splice(0, 30);
  3103. }
  3104. // Track scroll movement for decleration
  3105. positions.push(scrollLeft, scrollTop, timeStamp);
  3106. // Sync scroll position
  3107. self.__publish(scrollLeft, scrollTop, level);
  3108. // Otherwise figure out whether we are switching into dragging mode now.
  3109. } else {
  3110. var minimumTrackingForScroll = self.options.locking ? 3 : 0;
  3111. var minimumTrackingForDrag = 5;
  3112. var distanceX = Math.abs(currentTouchLeft - self.__initialTouchLeft);
  3113. var distanceY = Math.abs(currentTouchTop - self.__initialTouchTop);
  3114. self.__enableScrollX = self.options.scrollingX && distanceX >= minimumTrackingForScroll;
  3115. self.__enableScrollY = self.options.scrollingY && distanceY >= minimumTrackingForScroll;
  3116. positions.push(self.__scrollLeft, self.__scrollTop, timeStamp);
  3117. self.__isDragging = (self.__enableScrollX || self.__enableScrollY) && (distanceX >= minimumTrackingForDrag || distanceY >= minimumTrackingForDrag);
  3118. if (self.__isDragging) {
  3119. self.__interruptedAnimation = false;
  3120. }
  3121. }
  3122. // Update last touch positions and time stamp for next event
  3123. self.__lastTouchLeft = currentTouchLeft;
  3124. self.__lastTouchTop = currentTouchTop;
  3125. self.__lastTouchMove = timeStamp;
  3126. self.__lastScale = scale;
  3127. },
  3128. /**
  3129. * Touch end handler for scrolling support
  3130. */
  3131. doTouchEnd: function doTouchEnd(timeStamp) {
  3132. if (timeStamp instanceof Date) {
  3133. timeStamp = timeStamp.valueOf();
  3134. }
  3135. if (typeof timeStamp !== 'number') {
  3136. throw new Error('Invalid timestamp value: ' + timeStamp);
  3137. }
  3138. var self = this;
  3139. // Ignore event when tracking is not enabled (no touchstart event on element)
  3140. // This is required as this listener ('touchmove') sits on the document and not on the element itself.
  3141. if (!self.__isTracking) {
  3142. return;
  3143. }
  3144. // Not touching anymore (when two finger hit the screen there are two touch end events)
  3145. self.__isTracking = false;
  3146. // Be sure to reset the dragging flag now. Here we also detect whether
  3147. // the finger has moved fast enough to switch into a deceleration animation.
  3148. if (self.__isDragging) {
  3149. // Reset dragging flag
  3150. self.__isDragging = false;
  3151. // Start deceleration
  3152. // Verify that the last move detected was in some relevant time frame
  3153. if (self.__isSingleTouch && self.options.animating && timeStamp - self.__lastTouchMove <= 100) {
  3154. // Then figure out what the scroll position was about 100ms ago
  3155. var positions = self.__positions;
  3156. var endPos = positions.length - 1;
  3157. var startPos = endPos;
  3158. // Move pointer to position measured 100ms ago
  3159. for (var i = endPos; i > 0 && positions[i] > self.__lastTouchMove - 100; i -= 3) {
  3160. startPos = i;
  3161. }
  3162. // If start and stop position is identical in a 100ms timeframe,
  3163. // we cannot compute any useful deceleration.
  3164. if (startPos !== endPos) {
  3165. // Compute relative movement between these two points
  3166. var timeOffset = positions[endPos] - positions[startPos];
  3167. var movedLeft = self.__scrollLeft - positions[startPos - 2];
  3168. var movedTop = self.__scrollTop - positions[startPos - 1];
  3169. // Based on 50ms compute the movement to apply for each render step
  3170. self.__decelerationVelocityX = movedLeft / timeOffset * (1000 / 60);
  3171. self.__decelerationVelocityY = movedTop / timeOffset * (1000 / 60);
  3172. // How much velocity is required to start the deceleration
  3173. var minVelocityToStartDeceleration = self.options.paging || self.options.snapping ? 4 : 1;
  3174. // Verify that we have enough velocity to start deceleration
  3175. if (Math.abs(self.__decelerationVelocityX) > minVelocityToStartDeceleration || Math.abs(self.__decelerationVelocityY) > minVelocityToStartDeceleration) {
  3176. // Deactivate pull-to-refresh when decelerating
  3177. if (!self.__refreshActive && !self.__loadActive) {
  3178. self.__startDeceleration(timeStamp);
  3179. }
  3180. } else {
  3181. self.__scrollComplete();
  3182. }
  3183. } else {
  3184. self.__scrollComplete();
  3185. }
  3186. } else if (timeStamp - self.__lastTouchMove > 100) {
  3187. self.__scrollComplete();
  3188. }
  3189. }
  3190. // If this was a slower move it is per default non decelerated, but this
  3191. // still means that we want snap back to the bounds which is done here.
  3192. // This is placed outside the condition above to improve edge case stability
  3193. // e.g. touchend fired without enabled dragging. This should normally do not
  3194. // have modified the scroll positions or even showed the scrollbars though.
  3195. if (!self.__isDecelerating) {
  3196. if (self.__refreshActive && self.__refreshStart) {
  3197. // Use publish instead of scrollTo to allow scrolling to out of boundary position
  3198. // We don't need to normalize scrollLeft, zoomLevel, etc. here because we only y-scrolling when pull-to-refresh is enabled
  3199. self.__publish(self.__scrollLeft, -self.__refreshHeight, self.__zoomLevel, true);
  3200. if (self.__refreshStart) {
  3201. self.__refreshStart();
  3202. }
  3203. } else if (self.__loadActive && self.__loadStart) {
  3204. // Use publish instead of scrollTo to allow scrolling to out of boundary position
  3205. // We don't need to normalize scrollLeft, zoomLevel, etc. here because we only y-scrolling when pull-to-refresh is enabled
  3206. self.__publish(self.__scrollLeft, self.__maxScrollTop + self.__loadHeight, self.__zoomLevel, true);
  3207. if (self.__loadStart) {
  3208. self.__loadStart();
  3209. }
  3210. } else {
  3211. if (self.__interruptedAnimation || self.__isDragging) {
  3212. self.__scrollComplete();
  3213. }
  3214. self.scrollTo(self.__scrollLeft, self.__scrollTop, true, self.__zoomLevel);
  3215. // Directly signalize deactivation (nothing todo on refresh?)
  3216. if (self.__refreshActive) {
  3217. self.__refreshActive = false;
  3218. if (self.__refreshDeactivate) {
  3219. self.__refreshDeactivate();
  3220. }
  3221. } else if (self.__loadActive) {
  3222. self.__loadActive = false;
  3223. if (self.__loadDeactivate) {
  3224. self.__loadDeactivate();
  3225. }
  3226. }
  3227. }
  3228. }
  3229. // Fully cleanup list
  3230. self.__positions.length = 0;
  3231. },
  3232. /** Handle for scroll/publish */
  3233. onScroll: NOOP,
  3234. stop: function stop() {
  3235. var self = this;
  3236. self.__disable = true;
  3237. },
  3238. start: function start() {
  3239. var self = this;
  3240. self.__disable = true;
  3241. },
  3242. /*
  3243. ---------------------------------------------------------------------------
  3244. PRIVATE API
  3245. ---------------------------------------------------------------------------
  3246. */
  3247. /**
  3248. * Applies the scroll position to the content element
  3249. *
  3250. * @param left {Number} Left scroll position
  3251. * @param top {Number} Top scroll position
  3252. * @param animate {Boolean?false} Whether animation should be used to move to the new coordinates
  3253. */
  3254. __publish: function __publish(left, top, zoom, animate, speed, easing) {
  3255. var self = this;
  3256. if (self.__disable) {
  3257. return;
  3258. }
  3259. if (isNaN(left)) {
  3260. left = this.__scrollLeft;
  3261. }
  3262. if (isNaN(top)) {
  3263. top = this.__scrollTop;
  3264. }
  3265. // Remember whether we had an animation, then we try to continue based on the current "drive" of the animation
  3266. var wasAnimating = self.__isAnimating;
  3267. if (wasAnimating) {
  3268. core.effect.Animate.stop(wasAnimating);
  3269. self.__isAnimating = false;
  3270. }
  3271. if (animate && (self.options.animating || speed)) {
  3272. // Keep scheduled positions for scrollBy/zoomBy functionality
  3273. self.__scheduledLeft = left;
  3274. self.__scheduledTop = top;
  3275. self.__scheduledZoom = zoom;
  3276. var oldLeft = self.__scrollLeft;
  3277. var oldTop = self.__scrollTop;
  3278. var oldZoom = self.__zoomLevel;
  3279. var diffLeft = left - oldLeft;
  3280. var diffTop = top - oldTop;
  3281. var diffZoom = zoom - oldZoom;
  3282. var step = function step(percent, now, render) {
  3283. if (render) {
  3284. self.__scrollLeft = oldLeft + diffLeft * percent;
  3285. self.__scrollTop = oldTop + diffTop * percent;
  3286. self.__zoomLevel = oldZoom + diffZoom * percent;
  3287. // Push values out
  3288. if (self.__callback) {
  3289. self.__callback(self.__scrollLeft, self.__scrollTop, self.__zoomLevel);
  3290. self.onScroll();
  3291. }
  3292. }
  3293. };
  3294. var verify = function verify(id) {
  3295. return self.__isAnimating === id;
  3296. };
  3297. var completed = function completed(renderedFramesPerSecond, animationId, wasFinished) {
  3298. if (animationId === self.__isAnimating) {
  3299. self.__isAnimating = false;
  3300. }
  3301. if (self.__didDecelerationComplete || wasFinished) {
  3302. self.__scrollComplete();
  3303. }
  3304. if (self.options.zooming) {
  3305. self.__computeScrollMax();
  3306. if (self.__zoomComplete) {
  3307. self.__zoomComplete();
  3308. self.__zoomComplete = null;
  3309. }
  3310. }
  3311. if (self.__refreshBeforeDeactiveStarted) {
  3312. self.__refreshBeforeDeactiveStarted = false;
  3313. if (self.__refreshDeactivate) self.__refreshDeactivate();
  3314. }
  3315. if (self.__loadBeforeDeactiveStarted) {
  3316. self.__loadBeforeDeactiveStarted = false;
  3317. if (self.__loadDeactivate) self.__loadDeactivate();
  3318. }
  3319. };
  3320. var easingFunction = animatingMethod;
  3321. if (easing) {
  3322. easingFunction = createEasingFunction(easing, easingPattern);
  3323. }
  3324. // When continuing based on previous animation we choose an ease-out animation instead of ease-in-out
  3325. self.__isAnimating = core.effect.Animate.start(step, verify, completed, speed || self.options.animationDuration, wasAnimating ? easingFunction : noAnimatingMethod);
  3326. } else {
  3327. self.__scheduledLeft = self.__scrollLeft = left;
  3328. self.__scheduledTop = self.__scrollTop = top;
  3329. self.__scheduledZoom = self.__zoomLevel = zoom;
  3330. // Push values out
  3331. if (self.__callback) {
  3332. self.__callback(left, top, zoom);
  3333. self.onScroll();
  3334. }
  3335. // Fix max scroll ranges
  3336. if (self.options.zooming) {
  3337. self.__computeScrollMax();
  3338. if (self.__zoomComplete) {
  3339. self.__zoomComplete();
  3340. self.__zoomComplete = null;
  3341. }
  3342. }
  3343. if (self.__refreshBeforeDeactiveStarted) {
  3344. self.__refreshBeforeDeactiveStarted = false;
  3345. if (self.__refreshDeactivate) self.__refreshDeactivate();
  3346. }
  3347. if (self.__loadBeforeDeactiveStarted) {
  3348. self.__loadBeforeDeactiveStarted = false;
  3349. if (self.__loadDeactivate) self.__loadDeactivate();
  3350. }
  3351. }
  3352. },
  3353. /**
  3354. * Recomputes scroll minimum values based on client dimensions and content dimensions.
  3355. */
  3356. __computeScrollMax: function __computeScrollMax(zoomLevel) {
  3357. var self = this;
  3358. if (zoomLevel == null) {
  3359. zoomLevel = self.__zoomLevel;
  3360. }
  3361. self.__maxScrollLeft = Math.max(self.__contentWidth * zoomLevel - self.__clientWidth, 0);
  3362. self.__maxScrollTop = Math.max(self.__contentHeight * zoomLevel - self.__clientHeight, 0);
  3363. },
  3364. /** compute current page total page */
  3365. __computePage: function __computePage() {
  3366. var self = this;
  3367. var clientWidth = self.__clientWidth;
  3368. var clientHeight = self.__clientHeight;
  3369. var left = self.__scrollLeft;
  3370. var top = self.__scrollTop;
  3371. self.__totalXPage = Math.ceil(self.__contentWidth / clientWidth);
  3372. self.__currentPageX = Math.ceil(left / clientWidth + 1);
  3373. self.__totalYPage = Math.ceil(self.__contentHeight / clientHeight);
  3374. self.__currentPageY = Math.ceil(top / clientHeight + 1);
  3375. },
  3376. /** complete scroll*/
  3377. __scrollComplete: function __scrollComplete() {
  3378. var self = this;
  3379. self.options.scrollingComplete();
  3380. },
  3381. /*
  3382. ---------------------------------------------------------------------------
  3383. ANIMATION (DECELERATION) SUPPORT
  3384. ---------------------------------------------------------------------------
  3385. */
  3386. /**
  3387. * Called when a touch sequence end and the speed of the finger was high enough
  3388. * to switch into deceleration mode.
  3389. */
  3390. __startDeceleration: function __startDeceleration() {
  3391. var self = this;
  3392. if (self.options.paging) {
  3393. var scrollLeft = Math.max(Math.min(self.__scrollLeft, self.__maxScrollLeft), 0);
  3394. var scrollTop = Math.max(Math.min(self.__scrollTop, self.__maxScrollTop), 0);
  3395. var clientWidth = self.__clientWidth;
  3396. var clientHeight = self.__clientHeight;
  3397. // We limit deceleration not to the min/max values of the allowed range, but to the size of the visible client area.
  3398. // Each page should have exactly the size of the client area.
  3399. self.__minDecelerationScrollLeft = Math.floor(scrollLeft / clientWidth) * clientWidth;
  3400. self.__minDecelerationScrollTop = Math.floor(scrollTop / clientHeight) * clientHeight;
  3401. self.__maxDecelerationScrollLeft = Math.ceil(scrollLeft / clientWidth) * clientWidth;
  3402. self.__maxDecelerationScrollTop = Math.ceil(scrollTop / clientHeight) * clientHeight;
  3403. } else {
  3404. self.__minDecelerationScrollLeft = 0;
  3405. self.__minDecelerationScrollTop = 0;
  3406. self.__maxDecelerationScrollLeft = self.__maxScrollLeft;
  3407. self.__maxDecelerationScrollTop = self.__maxScrollTop;
  3408. }
  3409. // Wrap class method
  3410. var step = function step(percent, now, render) {
  3411. self.__stepThroughDeceleration(render);
  3412. };
  3413. // How much velocity is required to keep the deceleration running
  3414. var minVelocityToKeepDecelerating = self.options.snapping ? 4 : 0.001;
  3415. // Detect whether it's still worth to continue animating steps
  3416. // If we are already slow enough to not being user perceivable anymore, we stop the whole process here.
  3417. var verify = function verify() {
  3418. var shouldContinue = Math.abs(self.__decelerationVelocityX) >= minVelocityToKeepDecelerating || Math.abs(self.__decelerationVelocityY) >= minVelocityToKeepDecelerating;
  3419. if (!shouldContinue) {
  3420. self.__didDecelerationComplete = true;
  3421. }
  3422. return shouldContinue;
  3423. };
  3424. var completed = function completed() {
  3425. if (!self.__isDecelerating) {
  3426. return;
  3427. }
  3428. self.__isDecelerating = false;
  3429. if (self.__didDecelerationComplete) {
  3430. self.__scrollComplete();
  3431. }
  3432. // Animate to grid when snapping is active, otherwise just fix out-of-boundary positions
  3433. self.scrollTo(self.__scrollLeft, self.__scrollTop, self.options.snapping);
  3434. };
  3435. // Start animation and switch on flag
  3436. self.__isDecelerating = core.effect.Animate.start(step, verify, completed);
  3437. },
  3438. /**
  3439. * Called on every step of the animation
  3440. *
  3441. * @param inMemory {Boolean?false} Whether to not render the current step, but keep it in memory only. Used internally only!
  3442. */
  3443. __stepThroughDeceleration: function __stepThroughDeceleration(render) {
  3444. var self = this;
  3445. var bouncing = self.options.bouncing;
  3446. var minLeft = self.__minDecelerationScrollLeft;
  3447. var maxLeft = self.__maxDecelerationScrollLeft;
  3448. var minTop = self.__minDecelerationScrollTop;
  3449. var maxTop = self.__maxDecelerationScrollTop;
  3450. // Add deceleration to scroll position
  3451. var scrollLeft = self.__scrollLeft + self.__decelerationVelocityX;
  3452. var scrollTop = self.__scrollTop + self.__decelerationVelocityY;
  3453. var bounceX = scrollLeft < minLeft || scrollLeft > maxLeft;
  3454. var bounceY = scrollTop < minTop || scrollTop > maxTop;
  3455. // fix scrollLeft and scrollTop
  3456. var fixedScrollLeft = Math.min(Math.max(minLeft - bouncing.left, scrollLeft), maxLeft + bouncing.right);
  3457. var fixedScrollTop = Math.min(Math.max(minTop - bouncing.top, scrollTop), maxTop + bouncing.bottom);
  3458. //
  3459. // UPDATE SCROLL POSITION
  3460. //
  3461. if (render) {
  3462. self.__publish(fixedScrollLeft, fixedScrollTop, self.__zoomLevel);
  3463. } else {
  3464. self.__scrollLeft = scrollLeft;
  3465. self.__scrollTop = scrollTop;
  3466. }
  3467. //
  3468. // SLOW DOWN
  3469. //
  3470. // Slow down velocity on every iteration
  3471. if (!self.options.paging) {
  3472. // This is the factor applied to every iteration of the animation
  3473. // to slow down the process. This should emulate natural behavior where
  3474. // objects slow down when the initiator of the movement is removed
  3475. var frictionFactor = 0.95;
  3476. self.__decelerationVelocityX *= frictionFactor;
  3477. self.__decelerationVelocityY *= frictionFactor;
  3478. }
  3479. //
  3480. // BOUNCING SUPPORT
  3481. //
  3482. var scrollOutsideX = 0;
  3483. var scrollOutsideY = 0;
  3484. // This configures the amount of change applied to deceleration/acceleration when reaching boundaries
  3485. var penetrationDeceleration = self.options.penetrationDeceleration;
  3486. var penetrationAcceleration = self.options.penetrationAcceleration;
  3487. if (bounceX) {
  3488. // Check limits
  3489. if (scrollLeft < self.__minDecelerationScrollLeft) {
  3490. scrollOutsideX = self.__minDecelerationScrollLeft - scrollLeft;
  3491. } else if (scrollLeft > self.__maxDecelerationScrollLeft) {
  3492. scrollOutsideX = self.__maxDecelerationScrollLeft - scrollLeft;
  3493. }
  3494. }
  3495. if (bounceY) {
  3496. if (scrollTop < self.__minDecelerationScrollTop) {
  3497. scrollOutsideY = self.__minDecelerationScrollTop - scrollTop;
  3498. } else if (scrollTop > self.__maxDecelerationScrollTop) {
  3499. scrollOutsideY = self.__maxDecelerationScrollTop - scrollTop;
  3500. }
  3501. }
  3502. if (scrollOutsideX !== 0) {
  3503. if (scrollOutsideX * self.__decelerationVelocityX <= 0) {
  3504. self.__decelerationVelocityX += scrollOutsideX * penetrationDeceleration;
  3505. if (scrollOutsideX < 0 && -scrollOutsideX >= bouncing.right && self.__decelerationVelocityX > 0) {
  3506. self.__decelerationVelocityX = -bouncing.right / 2;
  3507. }
  3508. if (scrollOutsideX > 0 && scrollOutsideX >= bouncing.left && self.__decelerationVelocityX < 0) {
  3509. self.__decelerationVelocityX = bouncing.left / 2;
  3510. }
  3511. } else {
  3512. self.__decelerationVelocityX = scrollOutsideX * penetrationAcceleration;
  3513. }
  3514. }
  3515. if (scrollOutsideY !== 0) {
  3516. if (scrollOutsideY * self.__decelerationVelocityY <= 0) {
  3517. self.__decelerationVelocityY += scrollOutsideY * penetrationDeceleration;
  3518. if (scrollOutsideY < 0 && -scrollOutsideY >= bouncing.bottom && self.__decelerationVelocityY > 0) {
  3519. self.__decelerationVelocityY = -bouncing.bottom / 2;
  3520. }
  3521. if (scrollOutsideY > 0 && scrollOutsideY >= bouncing.top && self.__decelerationVelocityY < 0) {
  3522. self.__decelerationVelocityY = bouncing.top / 2;
  3523. }
  3524. } else {
  3525. self.__decelerationVelocityY = scrollOutsideY * penetrationAcceleration / 2;
  3526. }
  3527. }
  3528. }
  3529. };
  3530. // Copy over members to prototype
  3531. for (var key in members) {
  3532. Scroller.prototype[key] = members[key];
  3533. }
  3534. /* DOM-based rendering (Uses 3D when available, falls back on margin when transform not available) */
  3535. function render(content, global, suffix, type) {
  3536. if (type == 'position') {
  3537. return function (left, top) {
  3538. content.style.left = -left + 'px';
  3539. content.style.top = -top + 'px';
  3540. };
  3541. }
  3542. var vendorPrefix = getPrefix(global);
  3543. var helperElem = document.createElement('div');
  3544. var undef;
  3545. var perspectiveProperty = vendorPrefix + 'Perspective';
  3546. var transformProperty = 'transform'; //vendorPrefix + 'Transform';
  3547. if (helperElem.style[perspectiveProperty] !== undef) {
  3548. return function (left, top, zoom) {
  3549. content.style[transformProperty] = 'translate3d(' + -left + suffix + ',' + -top + suffix + ',0) scale(' + zoom + ')';
  3550. };
  3551. } else if (helperElem.style[transformProperty] !== undef) {
  3552. return function (left, top, zoom) {
  3553. content.style[transformProperty] = 'translate(' + -left + suffix + ',' + -top + suffix + ') scale(' + zoom + ')';
  3554. };
  3555. }
  3556. }
  3557. var touch = new touchManager();
  3558. function listenContainer(container, scroller, eventCallback, zooming, preventDefault, preventDefaultOnMove) {
  3559. var destroy = null;
  3560. var mousedown = false;
  3561. var touchObj = touch.getTouchObject();
  3562. function touchstart(e) {
  3563. var event = touch.getEventObject(e);
  3564. // Don't react if initial down happens on a form element
  3565. if (event[0] && event[0].target && event[0].target.tagName.match(/input|textarea|select/i) || scroller.__disable) {
  3566. return;
  3567. }
  3568. eventCallback('mousedown');
  3569. mousedown = true;
  3570. scroller.doTouchStart(event, e.timeStamp);
  3571. if (preventDefault) {
  3572. e.preventDefault();
  3573. }
  3574. e.stopPropagation();
  3575. // here , we want to manully prevent default, so we
  3576. // set passive to false
  3577. // see https://developer.mozilla.org/zh-CN/docs/Web/API/EventTarget/addEventListener
  3578. document.addEventListener(touchObj.touchmove, touchmove, {
  3579. passive: false
  3580. });
  3581. }
  3582. function touchmove(e) {
  3583. if (scroller.__disable || !mousedown) return;
  3584. var event = touch.getEventObject(e);
  3585. eventCallback('mousemove');
  3586. scroller.doTouchMove(event, e.timeStamp, e.scale);
  3587. if (preventDefaultOnMove) {
  3588. e.preventDefault();
  3589. }
  3590. }
  3591. function touchend(e) {
  3592. eventCallback('mouseup');
  3593. mousedown = false;
  3594. scroller.doTouchEnd(e.timeStamp);
  3595. document.removeEventListener(touchObj.touchmove, touchmove);
  3596. }
  3597. function touchcancel(e) {
  3598. scroller.doTouchEnd(e.timeStamp);
  3599. }
  3600. function zoomHandle(e) {
  3601. scroller.doMouseZoom(e.detail ? e.detail * -120 : e.wheelDelta, e.timeStamp, e.pageX, e.pageY);
  3602. }
  3603. container.addEventListener(touchObj.touchstart, touchstart, false);
  3604. document.addEventListener(touchObj.touchend, touchend, false);
  3605. document.addEventListener(touchObj.touchcancel, touchcancel, false);
  3606. if (zooming && !touch.isTouch) {
  3607. container.addEventListener(navigator.userAgent.indexOf('Firefox') > -1 ? 'DOMMouseScroll' : 'mousewheel', zoomHandle, false);
  3608. }
  3609. destroy = function destroy() {
  3610. container.removeEventListener(touchObj.touchstart, touchstart, false);
  3611. document.removeEventListener(touchObj.touchend, touchend, false);
  3612. document.removeEventListener(touchObj.touchcancel, touchcancel, false);
  3613. container.removeEventListener(navigator.userAgent.indexOf('Firefox') > -1 ? 'DOMMouseScroll' : 'mousewheel', zoomHandle, false);
  3614. };
  3615. // handle __publish event
  3616. scroller.onScroll = function () {
  3617. eventCallback('onscroll');
  3618. };
  3619. return destroy;
  3620. }
  3621. /**
  3622. * These mixes is exclusive for slide mode
  3623. */
  3624. createSlideModeStyle();
  3625. /**
  3626. * @description refresh and load callback
  3627. */
  3628. function createStateCallbacks(type, stageType, vm, tipDom) {
  3629. var listeners = vm.$listeners;
  3630. var activateCallback = function activateCallback() {
  3631. vm.vuescroll.state[stageType] = 'active';
  3632. vm.$emit(type + '-activate', vm, tipDom);
  3633. };
  3634. var deactivateCallback = function deactivateCallback() {
  3635. vm.vuescroll.state[stageType] = 'deactive';
  3636. vm.$emit(type + '-deactivate', vm, tipDom);
  3637. };
  3638. var beforeDeactiveEnd = function beforeDeactiveEnd() {
  3639. vm.vuescroll.state[stageType] = 'beforeDeactiveEnd';
  3640. vm.$emit(type + '-before-deactivate-end', vm, tipDom);
  3641. };
  3642. var startCallback = function startCallback() {
  3643. vm.vuescroll.state[stageType] = 'start';
  3644. setTimeout(function () {
  3645. vm.scroller.finishRefreshOrLoad();
  3646. }, 2000); // Default start stage duration
  3647. };
  3648. // let beforeDeactivateCallback = done => {
  3649. // vm.vuescroll.state[stageType] = 'beforeDeactive';
  3650. // setTimeout(function() {
  3651. // done();
  3652. // }, 500); // Default before-deactivated stage duration
  3653. // };
  3654. var beforeDeactivateCallback = void 0;
  3655. /* istanbul ignore if */
  3656. if (listeners[type + '-before-deactivate']) {
  3657. beforeDeactivateCallback = function beforeDeactivateCallback(done) {
  3658. vm.vuescroll.state[stageType] = 'beforeDeactive';
  3659. vm.$emit(type + '-before-deactivate', vm, tipDom, done.bind(vm.scroller));
  3660. };
  3661. }
  3662. /* istanbul ignore if */
  3663. if (listeners[type + '-start']) {
  3664. startCallback = function startCallback() {
  3665. vm.vuescroll.state[stageType] = 'start';
  3666. vm.$emit(type + '-start', vm, tipDom, vm.scroller.finishRefreshOrLoad.bind(vm.scroller));
  3667. };
  3668. }
  3669. return {
  3670. activateCallback: activateCallback,
  3671. deactivateCallback: deactivateCallback,
  3672. startCallback: startCallback,
  3673. beforeDeactivateCallback: beforeDeactivateCallback,
  3674. beforeDeactiveEnd: beforeDeactiveEnd
  3675. };
  3676. }
  3677. var slideMix = {
  3678. mounted: function mounted() {
  3679. this.vsMounted = true;
  3680. },
  3681. computed: {
  3682. pullRefreshTip: function pullRefreshTip() {
  3683. return this.mergedOptions.vuescroll.pullRefresh.tips[this.vuescroll.state.refreshStage];
  3684. },
  3685. pushLoadTip: function pushLoadTip() {
  3686. return this.mergedOptions.vuescroll.pushLoad.tips[this.vuescroll.state.loadStage];
  3687. },
  3688. refreshLoad: function refreshLoad() {
  3689. return this.mergedOptions.vuescroll.pullRefresh.enable || this.mergedOptions.vuescroll.pushLoad.enable;
  3690. },
  3691. refrehDomVisiable: function refrehDomVisiable() {
  3692. return this.vsMounted && this.outTheTopBoundary;
  3693. },
  3694. loadDomVisiable: function loadDomVisiable() {
  3695. return this.vsMounted && this.outTheBottomBoundary;
  3696. }
  3697. },
  3698. data: function data() {
  3699. return {
  3700. vuescroll: {
  3701. state: {
  3702. /** Default tips of refresh and load */
  3703. refreshStage: 'deactive',
  3704. loadStage: 'deactive'
  3705. }
  3706. },
  3707. vsMounted: false,
  3708. outTheTopBoundary: false,
  3709. outTheBottomBoundary: false
  3710. };
  3711. },
  3712. methods: {
  3713. // Update:
  3714. // 1. update height/width
  3715. // 2. update refresh or load
  3716. updateScroller: function updateScroller() {
  3717. this.updateDimesion();
  3718. this.registryRefreshLoad();
  3719. },
  3720. updateDimesion: function updateDimesion() {
  3721. var clientWidth = this.$el.clientWidth;
  3722. var clientHeight = this.$el.clientHeight;
  3723. var contentWidth = this.scrollPanelElm.scrollWidth;
  3724. var contentHeight = this.scrollPanelElm.scrollHeight;
  3725. var refreshHeight = 0;
  3726. var loadHeight = 0;
  3727. // If the refresh option is true,let's give a "margin-top" style to
  3728. // the refresh-tip dom. let it to be invisible when doesn't trigger
  3729. // refresh.
  3730. if (this.mergedOptions.vuescroll.pullRefresh.enable) {
  3731. if (this.vsMounted) {
  3732. var refreshDom = this.$refs[__REFRESH_DOM_NAME].elm || this.$refs[__REFRESH_DOM_NAME];
  3733. refreshHeight = refreshDom.offsetHeight;
  3734. refreshDom.style.marginTop = -refreshHeight + 'px';
  3735. }
  3736. }
  3737. if (this.mergedOptions.vuescroll.pushLoad.enable) {
  3738. if (this.vsMounted) {
  3739. var loadDom = this.$refs[__LOAD_DOM_NAME].elm || this.$refs[__LOAD_DOM_NAME];
  3740. loadHeight = loadDom.offsetHeight;
  3741. contentHeight -= loadHeight;
  3742. loadDom.style.bottom = '-' + loadHeight + 'px';
  3743. }
  3744. }
  3745. if (this.scroller) {
  3746. this.scroller.setDimensions(clientWidth, clientHeight, contentWidth, contentHeight, false);
  3747. }
  3748. },
  3749. registryRefreshLoad: function registryRefreshLoad() {
  3750. // registry refresh
  3751. if (this.mergedOptions.vuescroll.pullRefresh.enable) {
  3752. this.registryEvent('refresh');
  3753. }
  3754. // registry load
  3755. if (this.mergedOptions.vuescroll.pushLoad.enable) {
  3756. this.registryEvent('load');
  3757. }
  3758. },
  3759. registryScroller: function registryScroller() {
  3760. var _this = this;
  3761. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  3762. _ref$left = _ref.left,
  3763. left = _ref$left === undefined ? 0 : _ref$left,
  3764. _ref$top = _ref.top,
  3765. top = _ref$top === undefined ? 0 : _ref$top,
  3766. _ref$zoom = _ref.zoom,
  3767. zoom = _ref$zoom === undefined ? 1 : _ref$zoom;
  3768. var _mergedOptions$vuescr = this.mergedOptions.vuescroll.scroller,
  3769. preventDefault = _mergedOptions$vuescr.preventDefault,
  3770. preventDefaultOnMove = _mergedOptions$vuescr.preventDefaultOnMove;
  3771. var _mergedOptions$vuescr2 = this.mergedOptions.vuescroll,
  3772. paging = _mergedOptions$vuescr2.paging,
  3773. snapping = _mergedOptions$vuescr2.snapping.enable,
  3774. renderMethod = _mergedOptions$vuescr2.renderMethod,
  3775. zooming = _mergedOptions$vuescr2.zooming,
  3776. locking = _mergedOptions$vuescr2.locking;
  3777. // disale zooming when refresh or load enabled
  3778. zooming = !this.refreshLoad && !paging && !snapping && zooming;
  3779. var _mergedOptions$scroll = this.mergedOptions.scrollPanel,
  3780. scrollingY = _mergedOptions$scroll.scrollingY,
  3781. scrollingX = _mergedOptions$scroll.scrollingX;
  3782. var scrollingComplete = this.scrollingComplete.bind(this);
  3783. // Initialize Scroller
  3784. this.scroller = new Scroller(render(this.scrollPanelElm, window, 'px', renderMethod), _extends({}, this.mergedOptions.vuescroll.scroller, {
  3785. zooming: zooming,
  3786. scrollingY: scrollingY,
  3787. scrollingX: scrollingX && !this.refreshLoad,
  3788. animationDuration: this.mergedOptions.scrollPanel.speed,
  3789. paging: paging,
  3790. snapping: snapping,
  3791. scrollingComplete: scrollingComplete,
  3792. locking: locking
  3793. }));
  3794. this.scroller.__disable = this.mergedOptions.vuescroll.scroller.disable;
  3795. this.scroller.__scrollLeft = left;
  3796. this.scroller.__scrollTop = top;
  3797. this.scroller.__zoomLevel = zoom;
  3798. // Set snap
  3799. if (snapping) {
  3800. this.scroller.setSnapSize(this.mergedOptions.vuescroll.snapping.width, this.mergedOptions.vuescroll.snapping.height);
  3801. }
  3802. var rect = this.$el.getBoundingClientRect();
  3803. this.scroller.setPosition(rect.left + this.$el.clientLeft, rect.top + this.$el.clientTop);
  3804. // Get destroy callback
  3805. var cb = listenContainer(this.$el, this.scroller, function (eventType) {
  3806. // Thie is to dispatch the event from the scroller.
  3807. // to let vuescroll refresh the dom
  3808. switch (eventType) {
  3809. case 'mousedown':
  3810. _this.vuescroll.state.isDragging = true;
  3811. break;
  3812. case 'onscroll':
  3813. {
  3814. /**
  3815. * Trigger auto load
  3816. */
  3817. var stage = _this.vuescroll.state['loadStage'];
  3818. var _mergedOptions$vuescr3 = _this.mergedOptions.vuescroll.pushLoad,
  3819. enable = _mergedOptions$vuescr3.enable,
  3820. auto = _mergedOptions$vuescr3.auto,
  3821. autoLoadDistance = _mergedOptions$vuescr3.autoLoadDistance;
  3822. var _scroller = _this.scroller,
  3823. __scrollTop = _scroller.__scrollTop,
  3824. __maxScrollTop = _scroller.__maxScrollTop;
  3825. if (stage != 'start' && enable && auto && !_this.lockAutoLoad && // auto load debounce
  3826. autoLoadDistance >= __maxScrollTop - __scrollTop && __scrollTop > 0) {
  3827. _this.lockAutoLoad = true;
  3828. _this.triggerRefreshOrLoad('load');
  3829. }
  3830. if (autoLoadDistance < __maxScrollTop - __scrollTop) {
  3831. _this.lockAutoLoad = false;
  3832. }
  3833. _this.handleScroll(false);
  3834. }
  3835. break;
  3836. case 'mouseup':
  3837. _this.vuescroll.state.isDragging = false;
  3838. break;
  3839. }
  3840. }, zooming, preventDefault, preventDefaultOnMove);
  3841. this.updateScroller();
  3842. return cb;
  3843. },
  3844. updateSlideModeBarState: function updateSlideModeBarState() {
  3845. // update slide mode scrollbars' state
  3846. var heightPercentage = void 0,
  3847. widthPercentage = void 0;
  3848. var vuescroll = this.$el;
  3849. var scroller = this.scroller;
  3850. var outerLeft = 0;
  3851. var outerTop = 0;
  3852. var _$el = this.$el,
  3853. clientWidth = _$el.clientWidth,
  3854. clientHeight = _$el.clientHeight;
  3855. var contentWidth = clientWidth + this.scroller.__maxScrollLeft;
  3856. var contentHeight = clientHeight + this.scroller.__maxScrollTop;
  3857. // We should add the the height or width that is
  3858. // out of horizontal bountry to the total length
  3859. /* istanbul ignore if */
  3860. if (scroller.__scrollLeft < 0) {
  3861. outerLeft = -scroller.__scrollLeft;
  3862. } /* istanbul ignore next */else if (scroller.__scrollLeft > scroller.__maxScrollLeft) {
  3863. outerLeft = scroller.__scrollLeft - scroller.__maxScrollLeft;
  3864. }
  3865. // out of vertical bountry
  3866. if (scroller.__scrollTop < 0) {
  3867. outerTop = -scroller.__scrollTop;
  3868. this.outTheBottomBoundary = false;
  3869. this.outTheTopBoundary = true;
  3870. } else if (scroller.__scrollTop > scroller.__maxScrollTop) {
  3871. outerTop = scroller.__scrollTop - scroller.__maxScrollTop;
  3872. this.outTheTopBoundary = false;
  3873. this.outTheBottomBoundary = true;
  3874. } else {
  3875. this.outTheTopBoundary = this.outTheBottomBoundary = false;
  3876. }
  3877. heightPercentage = clientHeight / (contentHeight + outerTop);
  3878. widthPercentage = clientWidth / (contentWidth + outerLeft);
  3879. var scrollTop = Math.min(Math.max(0, scroller.__scrollTop), scroller.__maxScrollTop);
  3880. var scrollLeft = Math.min(Math.max(0, scroller.__scrollLeft), scroller.__maxScrollLeft);
  3881. this.bar.vBar.state.posValue = (scrollTop + outerTop) * 100 / vuescroll.clientHeight;
  3882. this.bar.hBar.state.posValue = (scrollLeft + outerLeft) * 100 / vuescroll.clientWidth;
  3883. /* istanbul ignore if */
  3884. if (scroller.__scrollLeft < 0) {
  3885. this.bar.hBar.state.posValue = 0;
  3886. }
  3887. if (scroller.__scrollTop < 0) {
  3888. this.bar.vBar.state.posValue = 0;
  3889. }
  3890. this.bar.vBar.state.size = heightPercentage < 1 ? heightPercentage : 0;
  3891. this.bar.hBar.state.size = widthPercentage < 1 ? widthPercentage : 0;
  3892. },
  3893. registryEvent: function registryEvent(type) {
  3894. var domName = type == 'refresh' ? __REFRESH_DOM_NAME : __LOAD_DOM_NAME;
  3895. var activateFunc = type == 'refresh' ? this.scroller.activatePullToRefresh : this.scroller.activatePushToLoad;
  3896. var stageType = type == 'refresh' ? 'refreshStage' : 'loadStage';
  3897. var tipDom = this.$refs[domName].elm || this.$refs[domName];
  3898. var cbs = createStateCallbacks(type, stageType, this, tipDom);
  3899. var height = tipDom.offsetHeight;
  3900. activateFunc.bind(this.scroller)(height, cbs);
  3901. },
  3902. getSlidePosition: function getSlidePosition() {
  3903. return {
  3904. scrollLeft: this.scroller.__scrollLeft,
  3905. scrollTop: this.scroller.__scrollTop
  3906. };
  3907. }
  3908. }
  3909. };
  3910. /**
  3911. * These mixes is exclusive for native mode
  3912. */
  3913. var nativeMix = {
  3914. methods: {
  3915. updateNativeModeBarState: function updateNativeModeBarState() {
  3916. var container = this.scrollPanelElm;
  3917. var isPercent = this.vuescroll.state.currentSizeStrategy == 'percent';
  3918. var _vuescroll$state = this.vuescroll.state,
  3919. width = _vuescroll$state.width,
  3920. height = _vuescroll$state.height;
  3921. var clientWidth = isPercent || !width ? container.clientWidth : width.slice(0, -2); // xxxpx ==> xxx
  3922. var clientHeight = isPercent || !height ? container.clientHeight : height.slice(0, -2);
  3923. var heightPercentage = clientHeight / container.scrollHeight;
  3924. var widthPercentage = clientWidth / container.scrollWidth;
  3925. this.bar.vBar.state.posValue = container.scrollTop * 100 / clientHeight;
  3926. this.bar.hBar.state.posValue = container.scrollLeft * 100 / clientWidth;
  3927. this.bar.vBar.state.size = heightPercentage < 1 ? heightPercentage : 0;
  3928. this.bar.hBar.state.size = widthPercentage < 1 ? widthPercentage : 0;
  3929. },
  3930. getNativePosition: function getNativePosition() {
  3931. return {
  3932. scrollTop: this.scrollPanelElm.scrollTop,
  3933. scrollLeft: this.scrollPanelElm.scrollLeft
  3934. };
  3935. },
  3936. css: function css(dom, style) /* istanbul ignore next */{
  3937. return window.getComputedStyle(dom)[style];
  3938. },
  3939. checkScrollable: function checkScrollable(e, deltaX, deltaY) /* istanbul ignore next */{
  3940. var scrollable = false;
  3941. // check mouse point scrollable.
  3942. var dom = e.target ? e.target : e;
  3943. while (dom && dom.nodeType == 1 && dom !== this.scrollPanelElm.parentNode && !/^BODY|HTML/.test(dom.nodeName)) {
  3944. var ov = this.css(dom, 'overflow') || '';
  3945. if (/scroll|auto/.test(ov)) {
  3946. var _getScrollProcess = this.getScrollProcess(dom),
  3947. v = _getScrollProcess.v,
  3948. h = _getScrollProcess.h;
  3949. var isScrollX = this.css(dom, 'overflowX') !== 'hidden';
  3950. var isScrollY = this.css(dom, 'overflowY') !== 'hidden';
  3951. if (isScrollX && (deltaX < 0 && h > 0 || deltaX > 0 && h < 1) || isScrollY && (deltaY < 0 && v > 0 || deltaY > 0 && v < 1)) {
  3952. scrollable = dom == this.scrollPanelElm;
  3953. break;
  3954. }
  3955. }
  3956. dom = dom.parentNode ? dom.parentNode : false;
  3957. }
  3958. return scrollable;
  3959. },
  3960. onMouseWheel: function onMouseWheel(event) /* istanbul ignore next */{
  3961. var _mergedOptions$vuescr = this.mergedOptions.vuescroll,
  3962. isReverse = _mergedOptions$vuescr.wheelDirectionReverse,
  3963. duration = _mergedOptions$vuescr.wheelScrollDuration,
  3964. checkShiftKey = _mergedOptions$vuescr.checkShiftKey,
  3965. locking = _mergedOptions$vuescr.locking,
  3966. deltaPercent = _mergedOptions$vuescr.deltaPercent;
  3967. var deltaX = void 0;
  3968. var deltaY = void 0;
  3969. if (event.wheelDelta) {
  3970. if (event.deltaY || event.deltaX) {
  3971. deltaX = event.deltaX * deltaPercent;
  3972. deltaY = event.deltaY * deltaPercent;
  3973. if (locking) {
  3974. if (Math.abs(event.deltaX) > Math.abs(event.deltaY)) {
  3975. deltaY = 0;
  3976. } else {
  3977. deltaX = 0;
  3978. }
  3979. }
  3980. } else {
  3981. deltaX = 0;
  3982. deltaY = -1 * event.wheelDelta / 2;
  3983. }
  3984. } else if (event.detail) {
  3985. deltaY = deltaX = event.detail * 16;
  3986. // horizontal scroll
  3987. if (event.axis == 1) {
  3988. deltaY = 0;
  3989. } else if (event.axis == 2) {
  3990. // vertical scroll
  3991. deltaX = 0;
  3992. }
  3993. }
  3994. if (checkShiftKey && event.shiftKey) {
  3995. // swap value
  3996. deltaX ^= deltaY;
  3997. deltaY ^= deltaX;
  3998. deltaX ^= deltaY;
  3999. }
  4000. if (isReverse) {
  4001. deltaX ^= deltaY;
  4002. deltaY ^= deltaX;
  4003. deltaX ^= deltaY;
  4004. }
  4005. if (this.checkScrollable(event, deltaX, deltaY)) {
  4006. event.stopPropagation();
  4007. event.preventDefault();
  4008. this.scrollBy({ dx: deltaX, dy: deltaY }, duration);
  4009. }
  4010. }
  4011. },
  4012. computed: {
  4013. scrollContentElm: function scrollContentElm() {
  4014. return this.$refs['scrollContent']._isVue ? this.$refs['scrollContent'].$el : this.$refs['scrollContent'];
  4015. }
  4016. }
  4017. };
  4018. var update = [slideMix, nativeMix];
  4019. var mixins = [api$1].concat(toConsumableArray(update));
  4020. var core$1 = {
  4021. mixins: mixins,
  4022. mounted: function mounted() {
  4023. if (!this._isDestroyed && !this.renderError) {
  4024. if (this.mode == 'slide') {
  4025. this.updatedCbs.push(this.updateScroller);
  4026. }
  4027. this.$watch('mergedOptions.vuescroll.scroller.disable', {
  4028. sync: true,
  4029. handler: function handler(newVal) {
  4030. if (this.scroller) {
  4031. this.scroller.__disable = newVal;
  4032. }
  4033. }
  4034. });
  4035. }
  4036. },
  4037. computed: {
  4038. mode: function mode() {
  4039. return this.mergedOptions.vuescroll.mode;
  4040. }
  4041. },
  4042. methods: {
  4043. destroy: function destroy() {
  4044. if (this.destroyScroller) {
  4045. this.scroller.stop();
  4046. this.destroyScroller();
  4047. this.destroyScroller = null;
  4048. }
  4049. /* istanbul ignore next */
  4050. if (this.destroyResize) {
  4051. this.destroyResize();
  4052. }
  4053. },
  4054. handleScroll: function handleScroll(nativeEvent) {
  4055. this.updateBarStateAndEmitEvent('handle-scroll', nativeEvent);
  4056. },
  4057. updateBarStateAndEmitEvent: function updateBarStateAndEmitEvent(eventType) {
  4058. var nativeEvent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  4059. if (this.mode == 'native') {
  4060. this.updateNativeModeBarState();
  4061. } else if (this.mode == 'slide') {
  4062. /* istanbul ignore if */
  4063. if (!this.scroller) {
  4064. return;
  4065. }
  4066. this.updateSlideModeBarState();
  4067. }
  4068. if (eventType) {
  4069. this.emitEvent(eventType, nativeEvent);
  4070. }
  4071. if (this.mergedOptions.bar.onlyShowBarOnScroll) {
  4072. if (eventType == 'handle-scroll' || eventType == 'handle-resize' || eventType == 'refresh-status' || eventType == 'window-resize' || eventType == 'options-change') {
  4073. this.showAndDefferedHideBar(true /* forceHideBar: true */);
  4074. }
  4075. } else {
  4076. this.showAndDefferedHideBar();
  4077. }
  4078. },
  4079. getScrollProcess: function getScrollProcess() {
  4080. var _scrollPanelElm = this.scrollPanelElm,
  4081. scrollHeight = _scrollPanelElm.scrollHeight,
  4082. scrollWidth = _scrollPanelElm.scrollWidth,
  4083. clientHeight = _scrollPanelElm.clientHeight,
  4084. clientWidth = _scrollPanelElm.clientWidth,
  4085. scrollTop = _scrollPanelElm.scrollTop,
  4086. scrollLeft = _scrollPanelElm.scrollLeft;
  4087. if (this.mode == 'slide') {
  4088. scrollHeight = this.scroller.__contentHeight;
  4089. scrollWidth = this.scroller.__contentWidth;
  4090. scrollTop = this.scroller.__scrollTop;
  4091. scrollLeft = this.scroller.__scrollLeft;
  4092. clientHeight = this.$el.clientHeight;
  4093. clientWidth = this.$el.clientWidth;
  4094. }
  4095. var v = Math.min(scrollTop / (scrollHeight - clientHeight || 1), 1);
  4096. var h = Math.min(scrollLeft / (scrollWidth - clientWidth || 1), 1);
  4097. return {
  4098. v: v,
  4099. h: h
  4100. };
  4101. },
  4102. emitEvent: function emitEvent(eventType) {
  4103. var nativeEvent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  4104. var _scrollPanelElm2 = this.scrollPanelElm,
  4105. scrollTop = _scrollPanelElm2.scrollTop,
  4106. scrollLeft = _scrollPanelElm2.scrollLeft;
  4107. var vertical = {
  4108. type: 'vertical'
  4109. };
  4110. var horizontal = {
  4111. type: 'horizontal'
  4112. };
  4113. var _getScrollProcess = this.getScrollProcess(),
  4114. v = _getScrollProcess.v,
  4115. h = _getScrollProcess.h;
  4116. vertical['process'] = v;
  4117. horizontal['process'] = h;
  4118. vertical['barSize'] = this.bar.vBar.state.size;
  4119. horizontal['barSize'] = this.bar.hBar.state.size;
  4120. vertical['scrollTop'] = scrollTop;
  4121. horizontal['scrollLeft'] = scrollLeft;
  4122. this.$emit(eventType, vertical, horizontal, nativeEvent);
  4123. },
  4124. initVariables: function initVariables() {
  4125. this.lastMode = this.mode;
  4126. this.$el._isVuescroll = true;
  4127. },
  4128. refreshMode: function refreshMode() {
  4129. var initPos = void 0;
  4130. if (this.scroller) {
  4131. initPos = this.scroller.getValues();
  4132. }
  4133. if (this.destroyScroller) {
  4134. this.scroller.stop();
  4135. this.destroyScroller();
  4136. this.destroyScroller = null;
  4137. }
  4138. if (this.mode == 'slide') {
  4139. this.destroyScroller = this.registryScroller(initPos);
  4140. } else if (this.mode == 'native') {
  4141. // remove the legacy transform style attribute
  4142. this.scrollPanelElm.style.transform = '';
  4143. this.scrollPanelElm.style.transformOrigin = '';
  4144. }
  4145. },
  4146. refreshInternalStatus: function refreshInternalStatus() {
  4147. // 1.set vuescroll height or width according to
  4148. // sizeStrategy
  4149. this.setVsSize();
  4150. // 2. registry resize event
  4151. this.registryResize();
  4152. // 3. registry scroller if mode is 'slide'
  4153. // or remove 'transform origin' is the mode is not `slide`
  4154. this.refreshMode();
  4155. // 4. update scrollbar's height/width
  4156. this.updateBarStateAndEmitEvent('refresh-status');
  4157. },
  4158. registryResize: function registryResize() {
  4159. var _this = this;
  4160. var resizeEnable = this.mergedOptions.vuescroll.detectResize;
  4161. var modeChanged = false;
  4162. if (this.lastMode != this.mode) {
  4163. modeChanged = true;
  4164. this.lastMode = this.mode;
  4165. }
  4166. /* istanbul ignore next */
  4167. if (this.destroyResize && resizeEnable && !modeChanged) {
  4168. return;
  4169. }
  4170. if (this.destroyResize) {
  4171. this.destroyResize();
  4172. }
  4173. if (!resizeEnable) {
  4174. return;
  4175. }
  4176. var contentElm = null;
  4177. if (this.mode == 'slide') {
  4178. contentElm = this.scrollPanelElm;
  4179. } else if (this.mode == 'native') {
  4180. // scrollContent maybe a vue-component or a pure-dom
  4181. contentElm = this.scrollContentElm;
  4182. }
  4183. var vm = this;
  4184. var handleWindowResize = function handleWindowResize() /* istanbul ignore next */{
  4185. vm.updateBarStateAndEmitEvent('window-resize');
  4186. if (vm.mode == 'slide') {
  4187. vm.updatedCbs.push(vm.updateScroller);
  4188. vm.$forceUpdate();
  4189. }
  4190. };
  4191. var handleDomResize = function handleDomResize() {
  4192. var currentSize = {};
  4193. if (_this.mode == 'slide') {
  4194. currentSize['width'] = _this.scroller.__contentWidth;
  4195. currentSize['height'] = _this.scroller.__contentHeight;
  4196. _this.updateBarStateAndEmitEvent('handle-resize', currentSize);
  4197. // update scroller should after rendering
  4198. _this.updatedCbs.push(_this.updateScroller);
  4199. _this.$forceUpdate();
  4200. } else if (_this.mode == 'native') {
  4201. currentSize['width'] = _this.scrollPanelElm.scrollWidth;
  4202. currentSize['height'] = _this.scrollPanelElm.scrollHeight;
  4203. _this.updateBarStateAndEmitEvent('handle-resize', currentSize);
  4204. }
  4205. // Since content sie changes, we should tell parent to set
  4206. // correct size to fit content's size
  4207. _this.setVsSize();
  4208. };
  4209. window.addEventListener('resize', handleWindowResize, false);
  4210. var destroyDomResize = installResizeDetection(contentElm, handleDomResize);
  4211. var destroyWindowResize = function destroyWindowResize() {
  4212. window.removeEventListener('resize', handleWindowResize, false);
  4213. };
  4214. this.destroyResize = function () {
  4215. destroyWindowResize();
  4216. destroyDomResize();
  4217. _this.destroyResize = null;
  4218. };
  4219. },
  4220. getPosition: function getPosition() {
  4221. if (this.mode == 'slide') {
  4222. return this.getSlidePosition();
  4223. } else if (this.mode == 'native') {
  4224. return this.getNativePosition();
  4225. }
  4226. }
  4227. }
  4228. };
  4229. /**
  4230. * The slide mode config
  4231. */
  4232. var config = {
  4233. // vuescroll
  4234. vuescroll: {
  4235. // position or transform
  4236. renderMethod: 'transform',
  4237. // pullRefresh or pushLoad is only for the slide mode...
  4238. pullRefresh: {
  4239. enable: false,
  4240. tips: {
  4241. deactive: 'Pull to Refresh',
  4242. active: 'Release to Refresh',
  4243. start: 'Refreshing...',
  4244. beforeDeactive: 'Refresh Successfully!'
  4245. }
  4246. },
  4247. pushLoad: {
  4248. enable: false,
  4249. tips: {
  4250. deactive: 'Push to Load',
  4251. active: 'Release to Load',
  4252. start: 'Loading...',
  4253. beforeDeactive: 'Load Successfully!'
  4254. },
  4255. auto: false,
  4256. autoLoadDistance: 0
  4257. },
  4258. paging: false,
  4259. zooming: true,
  4260. snapping: {
  4261. enable: false,
  4262. width: 100,
  4263. height: 100
  4264. },
  4265. /* some scroller options */
  4266. scroller: {
  4267. /** Enable bouncing (content can be slowly moved outside and jumps back after releasing) */
  4268. bouncing: {
  4269. top: 100,
  4270. bottom: 100,
  4271. left: 100,
  4272. right: 100
  4273. },
  4274. /** Minimum zoom level */
  4275. minZoom: 0.5,
  4276. /** Maximum zoom level */
  4277. maxZoom: 3,
  4278. /** Multiply or decrease scrolling speed **/
  4279. speedMultiplier: 1,
  4280. /** This configures the amount of change applied to deceleration when reaching boundaries **/
  4281. penetrationDeceleration: 0.03,
  4282. /** This configures the amount of change applied to acceleration when reaching boundaries **/
  4283. penetrationAcceleration: 0.08,
  4284. /** Whether call e.preventDefault event when sliding the content or not */
  4285. preventDefault: false,
  4286. /** Whether call preventDefault when (mouse/touch)move*/
  4287. preventDefaultOnMove: true,
  4288. disable: false
  4289. }
  4290. }
  4291. };
  4292. /**
  4293. * validate the options
  4294. * @export
  4295. * @param {any} ops
  4296. */
  4297. function configValidator(ops) {
  4298. var renderError = false;
  4299. var vuescroll = ops.vuescroll;
  4300. // validate pushLoad, pullReresh, snapping
  4301. if (vuescroll.paging == vuescroll.snapping.enable && vuescroll.paging && (vuescroll.pullRefresh || vuescroll.pushLoad)) {
  4302. error('paging, snapping, (pullRefresh with pushLoad) can only one of them to be true.');
  4303. }
  4304. return renderError;
  4305. }
  4306. var config$1 = {
  4307. vuescroll: {
  4308. wheelScrollDuration: 0,
  4309. wheelDirectionReverse: false,
  4310. checkShiftKey: true,
  4311. deltaPercent: 1
  4312. }
  4313. };
  4314. var config$2 = {
  4315. // vuescroll
  4316. vuescroll: {
  4317. mode: 'native'
  4318. }
  4319. };
  4320. /**
  4321. * validate the options
  4322. * @export
  4323. * @param {any} ops
  4324. */
  4325. function configValidator$1(ops) {
  4326. var renderError = false;
  4327. var vuescroll = ops.vuescroll;
  4328. // validate modes
  4329. if (!~modes.indexOf(vuescroll.mode)) {
  4330. error('Unknown mode: ' + vuescroll.mode + ',the vuescroll\'s option "mode" should be one of the ' + modes);
  4331. renderError = true;
  4332. }
  4333. return renderError;
  4334. }
  4335. var configs = [config$2, config, config$1];
  4336. var configValidators = [configValidator$1, configValidator];
  4337. var component = _install(core$1, createPanel$2, configs, configValidators);
  4338. function install(Vue) {
  4339. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  4340. Vue.component(opts.name || component.name, component);
  4341. Vue.prototype.$vuescrollConfig = opts.ops || {};
  4342. }
  4343. var Vuescroll = _extends({
  4344. install: install,
  4345. version: '4.18.1',
  4346. refreshAll: refreshAll,
  4347. scrollTo: scrollTo
  4348. }, component);
  4349. /* istanbul ignore if */
  4350. if (typeof window !== 'undefined' && window.Vue) {
  4351. window.Vue.use(Vuescroll);
  4352. }
  4353. return Vuescroll;
  4354. })));