jquery.scrollbar.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(4($){$.J=$.J||{};$.J.9={7:{16:\'y\',m:11,1l:1y,1m:11,1i:w,c:w,d:w}};$.13.1K=4(12){F 7=$.1E({},$.J.9.7,12);p.1G(4(){$(p).17(\'1f\',1L 15($(p),7))});G p};$.13.1H=4(19){G $(p).17(\'1f\').X(19)};4 15($i,7){F W=p,$j=$i.t(".j"),$s=$i.t(".s"),$9=$i.t(".1I"),$L=$9.t(".1M"),$8=$9.t(".1N"),b=0,a=0,6=0,k=0,c=0,l=1,d=0,Y=0,n=0,D=0,A=7.16===\'x\',P="14"1C g.1w,r=A?"z":"1x",f=A?"1D":"1z";4 1t(){W.X();Z();G W}p.X=4(R){S=r.1T(0).26()+r.25(1).1O();b=$j[0][\'K\'+S];a=$s[0][\'22\'+S];2(b<=0)b=1;2(a<=0)a=1;k=b/a;c=7.c||b;d=h.I(c,h.H(0,(7.d||(c*k))));2(d<1d)d=1d;2(7.d){F x=c-d;2(x==0)x=1;l=(a-b)/x}v{l=a/c}2(k<1&&!D){23(R){1b"28":6=a-b;1a;1b"29":6=h.I(a-b,h.H(0,6));1a;27:6=1v(R,10)||0}}v{$9.1c()}1e()};4 1g(){2(k<1&&$9.18(":20")){$j.z($j.z()-10);$9.21();2(!n)n=$8.K()[f]}}4 1u(){2(k<1&&$9.18(":1S")){$j.z($j.z()+10);$9.1c()}}4 1e(){$8.e(f,6/(l==0?1:l));$s.e(f,-6);n=$8.K()[f];$9.e(r,c);$L.e(r,c);$8.e(r,d)}4 Z(){2(P){$j[0].14=4(5){2(1===5.O.1V){M(5.O[0]);5.1Z()}}}v{$8.u("1Y",M);$L.u("B",C)}2(7.m&&E.T){$i[0].T("1W",m,w);$i[0].T("24",m,w)}v 2(7.m){$i[0].1X=m}$i.1U(1g,1u)}4 M(5){n=A?5.1p:5.1h;Y=1v($8.e(f),10)||0;D=1;2(P){g.1k=4(5){5.1o();C(5.O[0])};g.1s=q}v{$(g).u("1j",C);$(g).u("B",q);$8.u("B",q)}}4 m(5){2(k<1){F o=5||E.5,1r=o.1q?o.1q/1P:-o.1R/3;6-=1r*7.1l;6=h.I((a-b),h.H(0,6));$8.e(f,6/(l==0?1:l));$s.e(f,-6);2(7.1m||(6!==(a-b)&&6!==0)){o=$.5.2a(o);o.1o()}}}4 C(5){E.1n?E.1n().1F():g.1A.1B();2(k<1){U=A?5.1p:5.1h;V=U-n;2(7.1i){V=n-U}Q=h.I((c-d),h.H(0,Y+V));6=Q*l;$8.e(f,Q);$s.e(f,-6)}}4 q(){D=0;$(g).N("1j",C);$(g).N("B",q);$8.N("B",q);g.1k=g.1s=1J}G 1t()}})(1Q);',62,135,'||if||function|event|contentPosition|options|thumb|scrollbar|contentSize|viewportSize|trackSize|thumbSize|css|posiLabel|document|Math|container|viewport|contentRatio|trackRatio|wheel|mousePosition|eventObject|this|end|sizeLabel|overview|find|bind|else|false|||width|isHorizontal|mouseup|drag|isdraging|window|var|return|max|min|tiny|offset|track|start|unbind|touches|hasTouchEvents|thumbPositionNew|scrollTo|sizeLabelCap|addEventListener|mousePositionNew|thumbPositionDelta|self|update|thumbPosition|setEvents||true|params|fn|ontouchstart|Scrollbar|axis|data|is|sScroll|break|case|hide|40|setSize|tsb|checkshow|pageY|scrollInvert|mousemove|ontouchmove|wheelSpeed|wheelLock|getSelection|preventDefault|pageX|wheelDelta|wheelSpeedDelta|ontouchend|initialize|checkhide|parseInt|documentElement|height|60|top|selection|empty|in|left|extend|removeAllRanges|each|welivebar_update|scb_scrollbar|null|welivebar|new|scb_tracker|scb_mover|toLowerCase|120|jQuery|detail|visible|charAt|hover|length|DOMMouseScroll|onmousewheel|mousedown|stopPropagation|hidden|show|scroll|switch|mousewheel|slice|toUpperCase|default|bottom|relative|fix'.split('|'),0,{}))
  2. (function($) {
  3. $.tiny = $.tiny || {};
  4. $.tiny.scrollbar = {
  5. options: {
  6. axis: 'y',
  7. wheel: true,
  8. wheelSpeed: 60,
  9. wheelLock: true,
  10. scrollInvert: false,
  11. trackSize: false,
  12. thumbSize: false
  13. }
  14. };
  15. $.fn.welivebar = function(params) {
  16. var options = $.extend({}, $.tiny.scrollbar.options, params);
  17. this.each(function() {
  18. $(this).data('tsb', new Scrollbar($(this), options))
  19. });
  20. return this
  21. };
  22. $.fn.welivebar_update = function(sScroll) {
  23. return $(this).data('tsb').update(sScroll)
  24. };
  25. function Scrollbar($container, options) {
  26. var self = this,
  27. $viewport = $container.find(".viewport"),
  28. $overview = $container.find(".overview"),
  29. $scrollbar = $container.find(".scb_scrollbar"),
  30. $track = $scrollbar.find(".scb_tracker"),
  31. $thumb = $scrollbar.find(".scb_mover"),
  32. viewportSize = 0,
  33. contentSize = 0,
  34. contentPosition = 0,
  35. contentRatio = 0,
  36. trackSize = 0,
  37. trackRatio = 1,
  38. thumbSize = 0,
  39. thumbPosition = 0,
  40. mousePosition = 0,
  41. isdraging = 0,
  42. isHorizontal = options.axis === 'x',
  43. hasTouchEvents = "ontouchstart" in document.documentElement,
  44. sizeLabel = isHorizontal ? "width" : "height",
  45. posiLabel = isHorizontal ? "left" : "top";
  46. function initialize() {
  47. self.update();
  48. setEvents();
  49. return self
  50. }
  51. this.update = function(scrollTo) {
  52. sizeLabelCap = sizeLabel.charAt(0).toUpperCase() + sizeLabel.slice(1).toLowerCase();
  53. viewportSize = $viewport[0]['offset' + sizeLabelCap];
  54. contentSize = $overview[0]['scroll' + sizeLabelCap];
  55. if (viewportSize <= 0) viewportSize = 1;
  56. if (contentSize <= 0) contentSize = 1;
  57. contentRatio = viewportSize / contentSize;
  58. trackSize = options.trackSize || viewportSize;
  59. thumbSize = Math.min(trackSize, Math.max(0, (options.thumbSize || (trackSize * contentRatio))));
  60. if (thumbSize < 40) thumbSize = 40;
  61. if (options.thumbSize) {
  62. var x = trackSize - thumbSize;
  63. if (x == 0) x = 1;
  64. trackRatio = (contentSize - viewportSize) / x
  65. } else {
  66. trackRatio = contentSize / trackSize
  67. } if (contentRatio < 1 && !isdraging) {
  68. switch (scrollTo) {
  69. case "bottom":
  70. contentPosition = contentSize - viewportSize;
  71. break;
  72. case "relative":
  73. contentPosition = Math.min(contentSize - viewportSize, Math.max(0, contentPosition));
  74. break;
  75. default:
  76. contentPosition = parseInt(scrollTo, 10) || 0
  77. }
  78. } else {
  79. $scrollbar.hide()
  80. }
  81. checkshow();
  82. setSize()
  83. };
  84. function checkshow() {
  85. if (contentRatio < 1 && $scrollbar.is(":hidden")) {
  86. $viewport.width($viewport.width());
  87. $scrollbar.show();
  88. if (!mousePosition) mousePosition = $thumb.offset()[posiLabel]
  89. }
  90. }
  91. function checkhide() {
  92. if (contentRatio < 1 && $scrollbar.is(":visible")) {
  93. $viewport.width($viewport.width());
  94. $scrollbar.hide()
  95. }
  96. }
  97. function setSize() {
  98. $thumb.css(posiLabel, contentPosition / (trackRatio == 0 ? 1 : trackRatio));
  99. $overview.css(posiLabel, -contentPosition);
  100. mousePosition = $thumb.offset()[posiLabel];
  101. $scrollbar.css(sizeLabel, trackSize);
  102. $track.css(sizeLabel, trackSize);
  103. $thumb.css(sizeLabel, thumbSize)
  104. }
  105. function setEvents() {
  106. if (hasTouchEvents) {
  107. $viewport[0].ontouchstart = function(event) {
  108. if (1 === event.touches.length) {
  109. start(event.touches[0]);
  110. event.stopPropagation()
  111. }
  112. }
  113. } else {
  114. $thumb.bind("mousedown", start);
  115. $track.bind("mouseup", drag)
  116. } if (options.wheel && window.addEventListener) {
  117. $container[0].addEventListener("DOMMouseScroll", wheel, false);
  118. $container[0].addEventListener("mousewheel", wheel, false)
  119. } else if (options.wheel) {
  120. $container[0].onmousewheel = wheel
  121. }
  122. }
  123. function start(event) {
  124. mousePosition = isHorizontal ? event.pageX : event.pageY;
  125. thumbPosition = parseInt($thumb.css(posiLabel), 10) || 0;
  126. isdraging = 1;
  127. if (hasTouchEvents) {
  128. document.ontouchmove = function(event) {
  129. event.preventDefault();
  130. drag(event.touches[0])
  131. };
  132. document.ontouchend = end
  133. } else {
  134. $(document).bind("mousemove", drag);
  135. $(document).bind("mouseup", end);
  136. $thumb.bind("mouseup", end)
  137. }
  138. }
  139. function wheel(event) {
  140. if (contentRatio < 1) {
  141. var eventObject = event || window.event,
  142. wheelSpeedDelta = eventObject.wheelDelta ? eventObject.wheelDelta / 120 : -eventObject.detail / 3;
  143. contentPosition -= wheelSpeedDelta * options.wheelSpeed;
  144. contentPosition = Math.min((contentSize - viewportSize), Math.max(0, contentPosition));
  145. $thumb.css(posiLabel, contentPosition / (trackRatio == 0 ? 1 : trackRatio));
  146. $overview.css(posiLabel, -contentPosition);
  147. if (options.wheelLock || (contentPosition !== (contentSize - viewportSize) && contentPosition !== 0)) {
  148. eventObject = $.event.fix(eventObject);
  149. eventObject.preventDefault()
  150. }
  151. }
  152. }
  153. function drag(event) {
  154. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  155. if (contentRatio < 1) {
  156. mousePositionNew = isHorizontal ? event.pageX : event.pageY;
  157. thumbPositionDelta = mousePositionNew - mousePosition;
  158. if (options.scrollInvert) {
  159. thumbPositionDelta = mousePosition - mousePositionNew
  160. }
  161. thumbPositionNew = Math.min((trackSize - thumbSize), Math.max(0, thumbPosition + thumbPositionDelta));
  162. contentPosition = thumbPositionNew * trackRatio;
  163. $thumb.css(posiLabel, thumbPositionNew);
  164. $overview.css(posiLabel, -contentPosition)
  165. }
  166. }
  167. function end() {
  168. isdraging = 0;
  169. $(document).unbind("mousemove", drag);
  170. $(document).unbind("mouseup", end);
  171. $thumb.unbind("mouseup", end);
  172. document.ontouchmove = document.ontouchend = null
  173. }
  174. return initialize()
  175. }
  176. })(jQuery);