vuescroll-slide.js 144 KB

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