vuescroll-slide.js 152 KB

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