2 * jQuery Mobile Framework : scrollview plugin
3 * Copyright (c) 2010 Adobe Systems Incorporated - Kin Blas (jblas@adobe.com)
4 * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
5 * Note: Code is in draft form and is subject to change
6 * Modified by Koeun Choi <koeun.choi@samsung.com>
7 * Modified by Minkyu Kang <mk7.kang@samsung.com>
10 (function ( $, window, document, undefined ) {
12 function resizePageContentHeight( page ) {
13 var $page = $( page ),
14 $content = $page.children(".ui-content"),
15 hh = $page.children(".ui-header").outerHeight() || 0,
16 fh = $page.children(".ui-footer").outerHeight() || 0,
17 pt = parseFloat( $content.css("padding-top") ),
18 pb = parseFloat( $content.css("padding-bottom") ),
19 wh = $( window ).height();
21 $content.height( wh - (hh + fh) - (pt + pb) );
24 function MomentumTracker( options ) {
25 this.options = $.extend( {}, options );
26 this.easing = "easeOutQuad";
37 function getCurrentTime() {
41 jQuery.widget( "tizen.scrollview", jQuery.mobile.widget, {
43 direction: null, // "x", "y", or null for both.
46 scrollDuration: 1000, // Duration of the scrolling animation in msecs.
47 overshootDuration: 250, // Duration of the overshoot animation in msecs.
48 snapbackDuration: 500, // Duration of the snapback animation in msecs.
50 moveThreshold: 30, // User must move this many pixels in any direction to trigger a scroll.
51 moveIntervalThreshold: 150, // Time between mousemoves must not exceed this threshold.
53 scrollMethod: "translate", // "translate", "position"
54 startEventName: "scrollstart",
55 updateEventName: "scrollupdate",
56 stopEventName: "scrollstop",
58 eventType: $.support.touch ? "touch" : "mouse",
61 overshootEnable: false,
62 outerScrollEnable: true,
67 _getViewHeight: function () {
68 return this._$view.height() + this._view_offset;
71 _makePositioned: function ( $ele ) {
72 if ( $ele.css("position") === "static" ) {
73 $ele.css( "position", "relative" );
77 _create: function () {
81 this._$clip = $( this.element ).addClass("ui-scrollview-clip");
83 if ( this._$clip.children(".ui-scrollview-view").length ) {
84 this._$view = this._$clip.children(".ui-scrollview-view");
86 this._$view = this._$clip.wrapInner("<div></div>").children()
87 .addClass("ui-scrollview-view");
90 if ( this.options.scrollMethod === "translate" ) {
91 if ( this._$view.css("transform") === undefined ) {
92 this.options.scrollMethod = "position";
96 this._$clip.css( "overflow", "hidden" );
97 this._makePositioned( this._$clip );
99 this._makePositioned( this._$view );
100 this._$view.css( { left: 0, top: 0 } );
102 this._view_offset = this._$view.offset().top - this._$clip.offset().top;
103 this._view_height = this._getViewHeight();
108 direction = this.options.direction;
110 this._hTracker = ( direction !== "y" ) ?
111 new MomentumTracker( this.options ) : null;
112 this._vTracker = ( direction !== "x" ) ?
113 new MomentumTracker( this.options ) : null;
115 this._timerInterval = this.options.timerInterval;
118 this._timerCB = function () {
119 self._handleMomentumScroll();
123 this._add_scrollbar();
124 this._add_scroll_jump();
125 this._add_overflow_indicator();
128 _startMScroll: function ( speedX, speedY ) {
129 var keepGoing = false,
130 duration = this.options.scrollDuration,
136 this._$clip.trigger( this.options.startEventName );
139 c = this._$clip.width();
140 v = this._$view.width();
142 if ( (( this._sx === 0 && speedX > 0 ) ||
143 ( this._sx === -(v - c) && speedX < 0 )) &&
148 ht.start( this._sx, speedX,
149 duration, (v > c) ? -(v - c) : 0, 0 );
150 keepGoing = !ht.done();
154 c = this._$clip.height();
155 v = this._getViewHeight();
157 if ( (( this._sy === 0 && speedY > 0 ) ||
158 ( this._sy === -(v - c) && speedY < 0 )) &&
163 vt.start( this._sy, speedY,
164 duration, (v > c) ? -(v - c) : 0, 0 );
165 keepGoing = keepGoing || !vt.done();
169 this._timerID = setTimeout( this._timerCB, this._timerInterval );
175 _stopMScroll: function () {
176 if ( this._timerID ) {
177 this._$clip.trigger( this.options.stopEventName );
178 clearTimeout( this._timerID );
182 if ( this._vTracker ) {
183 this._vTracker.reset();
186 if ( this._hTracker ) {
187 this._hTracker.reset();
190 this._hideScrollBars();
191 this._hideOverflowIndicator();
194 _handleMomentumScroll: function () {
195 var keepGoing = false,
200 end_effect = function ( dir ) {
201 setTimeout( function () {
202 self._effect_dir = dir;
203 self._setEndEffect( "in" );
206 setTimeout( function () {
207 self._setEndEffect( "out" );
213 if ( this._outerScrolling ) {
218 vt.update( this.options.overshootEnable );
219 y = vt.getPosition();
220 keepGoing = !vt.done();
222 if ( vt.getRemained() > this.options.overshootDuration ) {
223 scroll_height = this._getViewHeight() - this._$clip.height();
225 if ( !vt.isAvail() ) {
226 if ( this._speedY > 0 ) {
227 this._outerScroll( vt.getRemained() / 3, scroll_height );
229 this._outerScroll( y - vt.getRemained() / 3, scroll_height );
231 } else if ( vt.isMin() ) {
232 this._outerScroll( y - vt.getRemained() / 3, scroll_height );
234 if ( scroll_height > 0 ) {
237 } else if ( vt.isMax() ) {
238 this._outerScroll( vt.getRemained() / 3, scroll_height );
240 if ( scroll_height > 0 ) {
248 ht.update( this.options.overshootEnable );
249 x = ht.getPosition();
250 keepGoing = keepGoing || !ht.done();
253 this._setScrollPosition( x, y );
254 this._$clip.trigger( this.options.updateEventName,
255 [ { x: x, y: y } ] );
258 this._timerID = setTimeout( this._timerCB, this._timerInterval );
264 _setElementTransform: function ( $ele, x, y, duration ) {
268 if ( !duration || duration === undefined ) {
271 transition = "-webkit-transform " + duration / 1000 + "s ease-out";
274 if ( $.support.cssTransform3d ) {
275 translate = "translate3d(" + x + "," + y + ", 0px)";
277 translate = "translate(" + x + "," + y + ")";
281 "-moz-transform": translate,
282 "-webkit-transform": translate,
283 "-ms-transform": translate,
284 "-o-transform": translate,
285 "transform": translate,
286 "-webkit-transition": transition
290 _setEndEffect: function ( dir ) {
291 var scroll_height = this._getViewHeight() - this._$clip.height();
293 if ( this._softkeyboard ) {
294 if ( this._effect_dir ) {
295 this._outerScroll( -scroll_height - this._softkeyboardHeight,
298 this._outerScroll( this._softkeyboardHeight, scroll_height );
303 if ( dir === "in" ) {
304 if ( this._endEffect ) {
308 this._endEffect = true;
309 this._setOverflowIndicator( this._effect_dir );
310 this._showOverflowIndicator();
311 } else if ( dir === "out" ) {
312 if ( !this._endEffect ) {
316 this._endEffect = false;
318 this._endEffect = false;
319 this._setOverflowIndicator();
320 this._showOverflowIndicator();
324 _setCalibration: function ( x, y ) {
325 if ( this.options.overshootEnable ) {
331 var $v = this._$view,
333 dirLock = this._directionLock,
337 if ( dirLock !== "y" && this._hTracker ) {
338 scroll_width = $v.width() - $c.width();
342 } else if ( x < -scroll_width ) {
343 this._sx = -scroll_width;
348 if ( scroll_width < 0 ) {
353 if ( dirLock !== "x" && this._vTracker ) {
354 scroll_height = this._getViewHeight() - $c.height();
359 if ( this._didDrag && scroll_height > 0 ) {
360 this._effect_dir = 0;
361 this._setEndEffect( "in" );
363 } else if ( y < -scroll_height ) {
364 this._sy = -scroll_height;
366 if ( this._didDrag && scroll_height > 0 ) {
367 this._effect_dir = 1;
368 this._setEndEffect( "in" );
371 if ( this._endEffect && this._sy !== y ) {
372 this._setEndEffect();
378 if ( scroll_height < 0 ) {
384 _setScrollPosition: function ( x, y, duration ) {
385 var $v = this._$view,
386 sm = this.options.scrollMethod,
387 $vsb = this._$vScrollBar,
388 $hsb = this._$hScrollBar,
391 this._setCalibration( x, y );
396 if ( sm === "translate" ) {
397 this._setElementTransform( $v, x + "px", y + "px", duration );
399 $v.css( {left: x + "px", top: y + "px"} );
403 $sbt = $vsb.find(".ui-scrollbar-thumb");
405 if ( sm === "translate" ) {
406 this._setElementTransform( $sbt, "0px",
407 -y / this._getViewHeight() * $sbt.parent().height() + "px",
410 $sbt.css( "top", -y / this._getViewHeight() * 100 + "%" );
415 $sbt = $hsb.find(".ui-scrollbar-thumb");
417 if ( sm === "translate" ) {
418 this._setElementTransform( $sbt,
419 -x / $v.width() * $sbt.parent().width() + "px", "0px",
422 $sbt.css("left", -x / $v.width() * 100 + "%");
427 _outerScroll: function ( y, scroll_height ) {
429 top = $( window ).scrollTop() - window.screenTop,
431 duration = this.options.snapbackDuration,
432 start = getCurrentTime(),
435 if ( !this.options.outerScrollEnable ) {
439 if ( this._$clip.jqmData("scroll") !== "y" ) {
443 if ( this._outerScrolling ) {
448 sy = ( window.screenTop ? window.screenTop : -y );
449 } else if ( y < -scroll_height ) {
450 sy = -y - scroll_height;
455 tfunc = function () {
456 var elapsed = getCurrentTime() - start;
458 if ( elapsed >= duration ) {
459 window.scrollTo( 0, top + sy );
460 self._outerScrolling = undefined;
464 ec = $.easing.easeOutQuad( elapsed / duration,
465 elapsed, 0, 1, duration );
467 window.scrollTo( 0, top + ( sy * ec ) );
468 self._outerScrolling = setTimeout( tfunc, self._timerInterval );
471 this._outerScrolling = setTimeout( tfunc, self._timerInterval );
474 _scrollTo: function ( x, y, duration ) {
476 start = getCurrentTime(),
477 efunc = $.easing.easeOutQuad,
487 tfunc = function () {
488 var elapsed = getCurrentTime() - start,
491 if ( elapsed >= duration ) {
493 self._setScrollPosition( x, y );
495 ec = efunc( elapsed / duration, elapsed, 0, 1, duration );
497 self._setScrollPosition( sx + ( dx * ec ), sy + ( dy * ec ) );
498 self._timerID = setTimeout( tfunc, self._timerInterval );
502 this._timerID = setTimeout( tfunc, this._timerInterval );
505 scrollTo: function ( x, y, duration ) {
508 if ( !duration || this.options.scrollMethod === "translate" ) {
509 this._setScrollPosition( x, y, duration );
511 this._scrollTo( x, y, duration );
515 getScrollPosition: function () {
516 return { x: -this._sx, y: -this._sy };
519 _getScrollHierarchy: function () {
523 this._$clip.parents( ".ui-scrollview-clip").each( function () {
524 d = $( this ).jqmData("scrollview");
532 _getAncestorByDirection: function ( dir ) {
533 var svh = this._getScrollHierarchy(),
540 svdir = sv.options.direction;
542 if (!svdir || svdir === dir) {
549 _handleDragStart: function ( e, ex, ey ) {
552 this._didDrag = false;
553 this._skip_dragging = false;
555 var target = $( e.target ),
558 svdir = this.options.direction;
560 /* should prevent the default behavior when click the button */
561 this._is_button = target.is( '.ui-btn' ) ||
562 target.is( '.ui-btn-text' ) ||
563 target.is( '.ui-btn-inner' ) ||
564 target.is( '.ui-btn-inner .ui-icon' );
566 /* should prevent the default behavior when click the slider */
567 if ( target.parents('.ui-slider').length || target.is('.ui-slider') ) {
568 this._skip_dragging = true;
573 * We need to prevent the default behavior to
574 * suppress accidental selection of text, etc.
576 this._is_inputbox = target.is(':input') ||
577 target.parents(':input').length > 0;
579 if ( this._is_inputbox ) {
580 target.one( "resize.scrollview", function () {
581 if ( ey > $c.height() ) {
582 self.scrollTo( -ex, self._sy - ey + $c.height(),
583 self.options.snapbackDuration );
588 if ( this.options.eventType === "mouse" && !this._is_inputbox && !this._is_button ) {
595 this._doSnapBackX = false;
596 this._doSnapBackY = false;
599 this._directionLock = "";
602 this._enableTracking();
604 this._set_scrollbar_size();
607 _propagateDragMove: function ( sv, e, ex, ey, dir ) {
608 this._hideScrollBars();
609 this._hideOverflowIndicator();
610 this._disableTracking();
611 sv._handleDragStart( e, ex, ey );
612 sv._directionLock = dir;
613 sv._didDrag = this._didDrag;
616 _handleDragMove: function ( e, ex, ey ) {
617 if ( this._skip_dragging ) {
621 if ( !this._dragging ) {
625 if ( !this._is_inputbox && !this._is_button ) {
629 var mt = this.options.moveThreshold,
630 dx = ex - this._lastX,
631 dy = ey - this._lastY,
632 svdir = this.options.direction,
642 this._lastMove = getCurrentTime();
644 if ( !this._directionLock ) {
648 if ( x < mt && y < mt ) {
652 if ( x < y && (x / y) < 0.5 ) {
654 } else if ( x > y && (y / x) < 0.5 ) {
658 if ( svdir && dir && svdir !== dir ) {
660 * This scrollview can't handle the direction the user
661 * is attempting to scroll. Find an ancestor scrollview
662 * that can handle the request.
665 sv = this._getAncestorByDirection( dir );
667 this._propagateDragMove( sv, e, ex, ey, dir );
672 this._directionLock = svdir || (dir || "none");
677 dirLock = this._directionLock;
679 if ( dirLock !== "y" && this._hTracker ) {
684 this._doSnapBackX = false;
686 scope = ( newX > 0 || newX < this._maxX );
688 if ( scope && dirLock === "x" ) {
689 sv = this._getAncestorByDirection("x");
691 this._setScrollPosition( newX > 0 ?
692 0 : this._maxX, newY );
693 this._propagateDragMove( sv, e, ex, ey, dir );
697 newX = x + ( dx / 2 );
698 this._doSnapBackX = true;
702 if ( dirLock !== "x" && this._vTracker ) {
703 if ( Math.abs( this._startY - ey ) < mt && dirLock !== "xy" ) {
711 this._doSnapBackY = false;
713 scope = ( newY > 0 || newY < this._maxY );
715 if ( scope && dirLock === "y" ) {
716 sv = this._getAncestorByDirection("y");
718 this._setScrollPosition( newX,
719 newY > 0 ? 0 : this._maxY );
720 this._propagateDragMove( sv, e, ex, ey, dir );
724 newY = y + ( dy / 2 );
725 this._doSnapBackY = true;
729 if ( this.options.overshootEnable === false ) {
730 this._doSnapBackX = false;
731 this._doSnapBackY = false;
737 this._setScrollPosition( newX, newY );
739 if ( this._didDrag === false ) {
740 this._didDrag = true;
741 this._showScrollBars();
742 this._showOverflowIndicator();
746 _handleDragStop: function ( e ) {
749 if ( this._skip_dragging ) {
753 var l = this._lastMove,
754 t = getCurrentTime(),
755 doScroll = (l && (t - l) <= this.options.moveIntervalThreshold),
756 sx = ( this._hTracker && this._speedX && doScroll ) ?
757 this._speedX : ( this._doSnapBackX ? 1 : 0 ),
758 sy = ( this._vTracker && this._speedY && doScroll ) ?
759 this._speedY : ( this._doSnapBackY ? 1 : 0 ),
760 svdir = this.options.direction,
765 if ( !this._setGestureScroll( sx, sy ) ) {
766 this._startMScroll( sx, sy );
769 this._hideScrollBars();
770 this._hideOverflowIndicator();
773 this._disableTracking();
775 if ( this._endEffect ) {
776 setTimeout( function () {
777 self._setEndEffect( "out" );
778 self._hideScrollBars();
779 self._hideOverflowIndicator();
783 return !this._didDrag;
786 _setGestureScroll: function ( sx, sy ) {
788 reset = function () {
789 clearTimeout( self._gesture_timer );
790 self._gesture_dir = 0;
791 self._gesture_count = 0;
792 self._gesture_timer = undefined;
799 dir = sy > 0 ? 1 : -1;
801 if ( !this._gesture_timer ) {
802 this._gesture_count = 1;
803 this._gesture_dir = dir;
805 this._gesture_timer = setTimeout( function () {
812 if ( this._gesture_dir !== dir ) {
817 this._gesture_count++;
819 if ( this._gesture_count === 3 ) {
821 this.scrollTo( 0, 0, this.options.overshootDuration );
823 this.scrollTo( 0, -( this._getViewHeight() - this._$clip.height() ),
824 this.options.overshootDuration );
834 _enableTracking: function () {
835 this._dragging = true;
838 _disableTracking: function () {
839 this._dragging = false;
842 _showScrollBars: function ( interval ) {
843 var vclass = "ui-scrollbar-visible",
846 if ( !this.options.showScrollBars ) {
849 if ( this._scrollbar_showed ) {
853 if ( this._$vScrollBar ) {
854 this._$vScrollBar.addClass( vclass );
856 if ( this._$hScrollBar ) {
857 this._$hScrollBar.addClass( vclass );
860 this._scrollbar_showed = true;
863 setTimeout( function () {
864 self._hideScrollBars();
869 _hideScrollBars: function () {
870 var vclass = "ui-scrollbar-visible";
872 if ( !this.options.showScrollBars ) {
875 if ( !this._scrollbar_showed ) {
879 if ( this._$vScrollBar ) {
880 this._$vScrollBar.removeClass( vclass );
882 if ( this._$hScrollBar ) {
883 this._$hScrollBar.removeClass( vclass );
886 this._scrollbar_showed = false;
889 _setOverflowIndicator: function ( dir ) {
891 this._opacity_top = "0";
892 this._opacity_bottom = "0.8";
893 } else if ( dir === 0 ) {
894 this._opacity_top = "0.8";
895 this._opacity_bottom = "0";
897 this._opacity_top = "0.5";
898 this._opacity_bottom = "0.5";
902 _showOverflowIndicator: function () {
903 if ( !this.options.overflowEnable || !this._overflowAvail || this._softkeyboard ) {
907 this._overflow_top.animate( { opacity: this._opacity_top }, 300 );
908 this._overflow_bottom.animate( { opacity: this._opacity_bottom }, 300 );
910 this._overflow_showed = true;
913 _hideOverflowIndicator: function () {
914 if ( !this.options.overflowEnable || !this._overflowAvail || this._softkeyboard ) {
918 if ( this._overflow_showed === false ) {
922 this._overflow_top.animate( { opacity: 0 }, 300 );
923 this._overflow_bottom.animate( { opacity: 0 }, 300 );
925 this._overflow_showed = false;
926 this._setOverflowIndicator();
929 _add_event: function () {
934 if ( this.options.eventType === "mouse" ) {
935 this._dragEvt = "mousedown mousemove mouseup click mousewheel";
937 this._dragCB = function ( e ) {
940 return self._handleDragStart( e,
941 e.clientX, e.clientY );
944 return self._handleDragMove( e,
945 e.clientX, e.clientY );
948 return self._handleDragStop( e );
951 return !self._didDrag;
954 var old = self.getScrollPosition();
955 self.scrollTo( -old.x,
956 -(old.y - e.originalEvent.wheelDelta) );
961 this._dragEvt = "touchstart touchmove touchend click";
963 this._dragCB = function ( e ) {
964 var touches = e.originalEvent.touches;
968 if ( touches.length != 1) {
972 return self._handleDragStart( e,
973 touches[0].pageX, touches[0].pageY );
976 if ( touches.length != 1) {
980 return self._handleDragMove( e,
981 touches[0].pageX, touches[0].pageY );
984 if ( touches.length != 0) {
988 return self._handleDragStop( e );
991 return !self._didDrag;
996 $v.bind( this._dragEvt, this._dragCB );
998 $v.bind( "keydown", function ( e ) {
1003 if ( e.keyCode == 9 ) {
1007 elem = $c.find(".ui-focus");
1009 if ( elem === undefined ) {
1013 elem_top = elem.offset().top;
1014 screen_h = $c.offset().top + $c.height() - elem.height();
1016 if ( self._softkeyboard ) {
1017 screen_h -= self._softkeyboardHeight;
1020 if ( ( elem_top < 0 ) || ( elem_top > screen_h ) ) {
1021 self.scrollTo( 0, self._sy - elem_top +
1022 elem.height() + $c.offset().top, 0);
1028 $v.bind( "keyup", function ( e ) {
1034 if ( e.keyCode != 9 ) {
1040 input = $( this ).find(":input");
1042 for ( i = 0; i < input.length; i++ ) {
1043 if ( !$( input[i] ).hasClass("ui-focus") ) {
1047 if ( i + 1 == input.length ) {
1048 elem = $( input[0] );
1050 elem = $( input[i + 1] );
1053 elem_top = elem.offset().top;
1054 screen_h = $c.offset().top + $c.height() - elem.height();
1056 if ( self._softkeyboard ) {
1057 screen_h -= self._softkeyboardHeight;
1060 if ( ( elem_top < 0 ) || ( elem_top > screen_h ) ) {
1061 self.scrollTo( 0, self._sy - elem_top +
1062 elem.height() + $c.offset().top, 0);
1073 $c.bind( "updatelayout", function ( e ) {
1076 view_h = self._getViewHeight();
1078 if ( !$c.height() || !view_h ) {
1079 self.scrollTo( 0, 0, 0 );
1083 sy = $c.height() - view_h;
1084 vh = view_h - self._view_height;
1086 self._view_height = view_h;
1088 if ( vh == 0 || vh > $c.height() / 2 ) {
1093 self.scrollTo( 0, 0, 0 );
1094 } else if ( self._sy - sy <= -vh ) {
1095 self.scrollTo( 0, self._sy,
1096 self.options.snapbackDuration );
1097 } else if ( self._sy - sy <= vh + self.options.moveThreshold ) {
1098 self.scrollTo( 0, sy,
1099 self.options.snapbackDuration );
1103 $( window ).bind( "resize", function ( e ) {
1105 view_h = self._getViewHeight();
1107 if ( $(".ui-page-active").get(0) !== $c.closest(".ui-page").get(0) ) {
1111 if ( !$c.height() || !view_h ) {
1115 focused = $c.find(".ui-focus");
1118 focused.trigger("resize.scrollview");
1121 /* calibration - after triggered throttledresize */
1122 setTimeout( function () {
1123 if ( self._sy < $c.height() - self._getViewHeight() ) {
1124 self.scrollTo( 0, $c.height() - self._getViewHeight(),
1125 self.options.overshootDuration );
1129 self._view_height = view_h;
1132 $( window ).bind( "vmouseout", function ( e ) {
1133 var drag_stop = false;
1135 if ( $(".ui-page-active").get(0) !== $c.closest(".ui-page").get(0) ) {
1139 if ( !self._dragging ) {
1143 if ( e.pageX < 0 || e.pageX > $( window ).width() ) {
1147 if ( e.pageY < 0 || e.pageY > $( window ).height() ) {
1152 self._hideScrollBars();
1153 self._hideOverflowIndicator();
1154 self._disableTracking();
1158 this._softkeyboard = false;
1159 this._softkeyboardHeight = 0;
1161 window.addEventListener( "softkeyboardchange", function ( e ) {
1162 if ( $(".ui-page-active").get(0) !== $c.closest(".ui-page").get(0) ) {
1166 self._softkeyboard = ( e.state === "on" ? true : false );
1167 self._softkeyboardHeight = e.height;
1170 $c.closest(".ui-page")
1171 .one( "pageshow", function ( e ) {
1172 self._view_offset = self._$view.offset().top - self._$clip.offset().top;
1173 self._view_height = self._getViewHeight();
1175 .bind( "pageshow", function ( e ) {
1176 /* should be called after pagelayout */
1177 setTimeout( function () {
1178 self._set_scrollbar_size();
1179 self._setScrollPosition( self._sx, self._sy );
1180 self._showScrollBars( 2000 );
1185 _add_scrollbar: function () {
1186 var $c = this._$clip,
1187 prefix = "<div class=\"ui-scrollbar ui-scrollbar-",
1188 suffix = "\"><div class=\"ui-scrollbar-track\"><div class=\"ui-scrollbar-thumb\"></div></div></div>";
1190 if ( !this.options.showScrollBars ) {
1194 if ( this._vTracker ) {
1195 $c.append( prefix + "y" + suffix );
1196 this._$vScrollBar = $c.children(".ui-scrollbar-y");
1198 if ( this._hTracker ) {
1199 $c.append( prefix + "x" + suffix );
1200 this._$hScrollBar = $c.children(".ui-scrollbar-x");
1203 this._scrollbar_showed = false;
1206 _add_scroll_jump: function () {
1207 var $c = this._$clip,
1212 if ( !this.options.scrollJump ) {
1216 if ( this._vTracker ) {
1217 top_btn = $( '<div class="ui-scroll-jump-top-bg">' +
1218 '<div data-role="button" data-inline="true" data-icon="scrolltop" data-style="box"></div></div>' );
1219 $c.append( top_btn ).trigger("create");
1221 top_btn.bind( "vclick", function () {
1222 self.scrollTo( 0, 0, self.options.overshootDuration );
1226 if ( this._hTracker ) {
1227 left_btn = $( '<div class="ui-scroll-jump-left-bg">' +
1228 '<div data-role="button" data-inline="true" data-icon="scrollleft" data-style="box"></div></div>' );
1229 $c.append( left_btn ).trigger("create");
1231 left_btn.bind( "vclick", function () {
1232 self.scrollTo( 0, 0, self.options.overshootDuration );
1237 _add_overflow_indicator: function () {
1238 if ( !this.options.overflowEnable ) {
1242 this._overflow_top = $( '<div class="ui-overflow-indicator-top"></div>' );
1243 this._overflow_bottom = $( '<div class="ui-overflow-indicator-bottom"></div>' );
1245 this._$clip.append( this._overflow_top );
1246 this._$clip.append( this._overflow_bottom );
1248 this._opacity_top = "0.5";
1249 this._opacity_bottom = "0.5";
1250 this._overflow_showed = false;
1253 _set_scrollbar_size: function () {
1254 var $c = this._$clip,
1262 if ( !this.options.showScrollBars ) {
1266 if ( this._hTracker ) {
1269 this._maxX = cw - vw;
1271 if ( this._maxX > 0 ) {
1274 if ( this._$hScrollBar && vw ) {
1275 thumb = this._$hScrollBar.find(".ui-scrollbar-thumb");
1276 thumb.css( "width", (cw >= vw ? "0" :
1277 (Math.floor(cw / vw * 100) || 1) + "%") );
1281 if ( this._vTracker ) {
1283 vh = this._getViewHeight();
1284 this._maxY = ch - vh;
1286 if ( this._maxY > 0 ) {
1289 if ( this._$vScrollBar && vh ) {
1290 thumb = this._$vScrollBar.find(".ui-scrollbar-thumb");
1291 thumb.css( "height", (ch >= vh ? "0" :
1292 (Math.floor(ch / vh * 100) || 1) + "%") );
1294 this._overflowAvail = !!thumb.height();
1300 $.extend( MomentumTracker.prototype, {
1301 start: function ( pos, speed, duration, minPos, maxPos ) {
1302 var tstate = ( pos < minPos || pos > maxPos ) ?
1303 tstates.snapback : tstates.scrolling,
1306 this.state = ( speed !== 0 ) ? tstate : tstates.done;
1309 this.duration = ( this.state === tstates.snapback ) ?
1310 this.options.snapbackDuration : duration;
1311 this.minPos = minPos;
1312 this.maxPos = maxPos;
1314 this.fromPos = ( this.state === tstates.snapback ) ? this.pos : 0;
1315 pos_temp = ( this.pos < this.minPos ) ? this.minPos : this.maxPos;
1316 this.toPos = ( this.state === tstates.snapback ) ? pos_temp : 0;
1318 this.startTime = getCurrentTime();
1321 reset: function () {
1322 this.state = tstates.done;
1331 update: function ( overshootEnable ) {
1332 var state = this.state,
1333 cur_time = getCurrentTime(),
1334 duration = this.duration,
1335 elapsed = cur_time - this.startTime,
1340 if ( state === tstates.done ) {
1344 elapsed = elapsed > duration ? duration : elapsed;
1346 this.remained = duration - elapsed;
1348 if ( state === tstates.scrolling || state === tstates.overshot ) {
1350 ( 1 - $.easing[this.easing]( elapsed / duration,
1351 elapsed, 0, 1, duration ) );
1355 didOverShoot = ( state === tstates.scrolling ) &&
1356 ( x < this.minPos || x > this.maxPos );
1358 if ( didOverShoot ) {
1359 x = ( x < this.minPos ) ? this.minPos : this.maxPos;
1364 if ( state === tstates.overshot ) {
1365 if ( !overshootEnable ) {
1366 this.state = tstates.done;
1368 if ( elapsed >= duration ) {
1369 this.state = tstates.snapback;
1370 this.fromPos = this.pos;
1371 this.toPos = ( x < this.minPos ) ?
1372 this.minPos : this.maxPos;
1373 this.duration = this.options.snapbackDuration;
1374 this.startTime = cur_time;
1377 } else if ( state === tstates.scrolling ) {
1378 if ( didOverShoot && overshootEnable ) {
1379 this.state = tstates.overshot;
1380 this.speed = dx / 2;
1381 this.duration = this.options.overshootDuration;
1382 this.startTime = cur_time;
1383 } else if ( elapsed >= duration ) {
1384 this.state = tstates.done;
1387 } else if ( state === tstates.snapback ) {
1388 if ( elapsed >= duration ) {
1389 this.pos = this.toPos;
1390 this.state = tstates.done;
1392 this.pos = this.fromPos + (( this.toPos - this.fromPos ) *
1393 $.easing[this.easing]( elapsed / duration,
1394 elapsed, 0, 1, duration ));
1402 return this.state === tstates.done;
1405 isMin: function () {
1406 return this.pos === this.minPos;
1409 isMax: function () {
1410 return this.pos === this.maxPos;
1413 isAvail: function () {
1414 return !( this.minPos === this.maxPos );
1417 getRemained: function () {
1418 return this.remained;
1421 getPosition: function () {
1426 $( document ).bind( 'pagecreate create', function ( e ) {
1427 var $page = $( e.target ),
1428 content_scroll = $page.find(".ui-content").jqmData("scroll");
1430 /* content scroll */
1431 if ( $.support.scrollview === undefined ) {
1432 $.support.scrollview = true;
1435 if ( $.support.scrollview === true && content_scroll === undefined ) {
1436 content_scroll = "y";
1439 if ( content_scroll !== "y" ) {
1440 content_scroll = "none";
1443 $page.find(".ui-content").attr( "data-scroll", content_scroll );
1445 $page.find(":jqmData(scroll)").not(".ui-scrollview-clip").each( function () {
1446 if ( $( this ).hasClass("ui-scrolllistview") ) {
1447 $( this ).scrolllistview();
1449 var st = $( this ).jqmData("scroll"),
1450 dir = st && ( st.search(/^[xy]/) !== -1 ) ? st : null,
1451 content = $(this).hasClass("ui-content"),
1454 if ( st === "none" ) {
1459 direction: dir || undefined,
1460 overflowEnable: content,
1461 scrollMethod: $( this ).jqmData("scroll-method") || undefined,
1462 scrollJump: $( this ).jqmData("scroll-jump") || undefined
1465 $( this ).scrollview( opts );
1470 $( document ).bind( 'pageshow', function ( e ) {
1471 var $page = $( e.target ),
1472 scroll = $page.find(".ui-content").jqmData("scroll");
1474 if ( scroll === "y" ) {
1475 resizePageContentHeight( e.target );
1479 }( jQuery, window, document ) );