vuescroll.js 156 KB

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