1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Implements scroll by javascript
6 define( [ ], function ( ) {
7 //>>excludeEnd("jqmBuildExclude");
10 * jQuery Mobile Framework : scrollview plugin
11 * Copyright (c) 2010 Adobe Systems Incorporated - Kin Blas (jblas@adobe.com)
12 * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
13 * Note: Code is in draft form and is subject to change
14 * Modified by Koeun Choi <koeun.choi@samsung.com>
15 * Modified by Minkyu Kang <mk7.kang@samsung.com>
18 (function ( $, window, document, undefined ) {
20 function resizePageContentHeight( page ) {
21 var $page = $( page ),
22 $content = $page.children(".ui-content"),
23 hh = $page.children(".ui-header").outerHeight() || 0,
24 fh = $page.children(".ui-footer").outerHeight() || 0,
25 pt = parseFloat( $content.css("padding-top") ),
26 pb = parseFloat( $content.css("padding-bottom") ),
27 wh = $( window ).height();
29 $content.height( wh - (hh + fh) - (pt + pb) );
32 function MomentumTracker( options ) {
33 this.options = $.extend( {}, options );
34 this.easing = "easeOutQuad";
45 function getCurrentTime() {
49 jQuery.widget( "tizen.scrollview", jQuery.mobile.widget, {
51 direction: null, // "x", "y", or null for both.
54 scrollDuration: 1000, // Duration of the scrolling animation in msecs.
55 overshootDuration: 250, // Duration of the overshoot animation in msecs.
56 snapbackDuration: 500, // Duration of the snapback animation in msecs.
58 moveThreshold: 30, // User must move this many pixels in any direction to trigger a scroll.
59 moveIntervalThreshold: 150, // Time between mousemoves must not exceed this threshold.
61 scrollMethod: "translate", // "translate", "position"
62 startEventName: "scrollstart",
63 updateEventName: "scrollupdate",
64 stopEventName: "scrollstop",
66 eventType: $.support.touch ? "touch" : "mouse",
69 overshootEnable: false,
70 outerScrollEnable: false,
75 _getViewHeight: function () {
76 return this._$view.height();
79 _getViewWidth: function () {
80 return this._$view.width();
83 _makePositioned: function ( $ele ) {
84 if ( $ele.css("position") === "static" ) {
85 $ele.css( "position", "relative" );
89 _create: function () {
93 this._$clip = $( this.element ).addClass("ui-scrollview-clip");
95 if ( this._$clip.children(".ui-scrollview-view").length ) {
96 this._$view = this._$clip.children(".ui-scrollview-view");
98 this._$view = this._$clip.wrapInner("<div></div>").children()
99 .addClass("ui-scrollview-view");
102 if ( this.options.scrollMethod === "translate" ) {
103 if ( this._$view.css("transform") === undefined ) {
104 this.options.scrollMethod = "position";
108 this._$clip.css( "overflow", "hidden" );
109 this._makePositioned( this._$clip );
111 this._makePositioned( this._$view );
112 this._$view.css( { left: 0, top: 0 } );
114 this._view_height = this._getViewHeight();
119 direction = this.options.direction;
121 this._hTracker = ( direction !== "y" ) ?
122 new MomentumTracker( this.options ) : null;
123 this._vTracker = ( direction !== "x" ) ?
124 new MomentumTracker( this.options ) : null;
126 this._timerInterval = this.options.timerInterval;
129 this._timerCB = function () {
130 self._handleMomentumScroll();
134 this._add_scrollbar();
135 this._add_scroll_jump();
136 this._add_overflow_indicator();
139 _startMScroll: function ( speedX, speedY ) {
140 var keepGoing = false,
141 duration = this.options.scrollDuration,
147 this._$clip.trigger( this.options.startEventName );
150 c = this._$clip.width();
151 v = this._getViewWidth();
153 if ( (( this._sx === 0 && speedX > 0 ) ||
154 ( this._sx === -(v - c) && speedX < 0 )) &&
159 ht.start( this._sx, speedX,
160 duration, (v > c) ? -(v - c) : 0, 0 );
161 keepGoing = !ht.done();
165 c = this._$clip.height();
166 v = this._getViewHeight();
168 if ( (( this._sy === 0 && speedY > 0 ) ||
169 ( this._sy === -(v - c) && speedY < 0 )) &&
174 vt.start( this._sy, speedY,
175 duration, (v > c) ? -(v - c) : 0, 0 );
176 keepGoing = keepGoing || !vt.done();
180 this._timerID = setTimeout( this._timerCB, this._timerInterval );
186 _stopMScroll: function () {
187 if ( this._timerID ) {
188 this._$clip.trigger( this.options.stopEventName );
189 clearTimeout( this._timerID );
193 if ( this._vTracker ) {
194 this._vTracker.reset();
197 if ( this._hTracker ) {
198 this._hTracker.reset();
201 this._hideScrollBars();
202 this._hideOverflowIndicator();
205 _handleMomentumScroll: function () {
206 var keepGoing = false,
214 if ( this._outerScrolling ) {
219 vt.update( this.options.overshootEnable );
220 y = vt.getPosition();
221 keepGoing = !vt.done();
223 if ( vt.getRemained() > this.options.overshootDuration ) {
224 scroll_height = this._getViewHeight() - this._$clip.height();
226 if ( !vt.isAvail() ) {
227 if ( this._speedY > 0 ) {
228 this._outerScroll( vt.getRemained() / 3, scroll_height );
230 this._outerScroll( y - vt.getRemained() / 3, scroll_height );
232 } else if ( vt.isMin() ) {
233 this._outerScroll( y - vt.getRemained() / 3, scroll_height );
235 } else if ( vt.isMax() ) {
236 this._outerScroll( vt.getRemained() / 3, scroll_height );
242 ht.update( this.options.overshootEnable );
243 x = ht.getPosition();
244 keepGoing = keepGoing || !ht.done();
247 this._setScrollPosition( x, y );
248 this._$clip.trigger( this.options.updateEventName,
249 [ { x: x, y: y } ] );
252 this._timerID = setTimeout( this._timerCB, this._timerInterval );
258 _setElementTransform: function ( $ele, x, y, duration ) {
262 if ( !duration || duration === undefined ) {
265 transition = "-webkit-transform " + duration / 1000 + "s ease-out";
268 if ( $.support.cssTransform3d ) {
269 translate = "translate3d(" + x + "," + y + ", 0px)";
271 translate = "translate(" + x + "," + y + ")";
275 "-moz-transform": translate,
276 "-webkit-transform": translate,
277 "-ms-transform": translate,
278 "-o-transform": translate,
279 "transform": translate,
280 "-webkit-transition": transition
284 _setEndEffect: function ( dir ) {
285 var scroll_height = this._getViewHeight() - this._$clip.height();
287 if ( this._softkeyboard ) {
288 if ( this._effect_dir ) {
289 this._outerScroll( -scroll_height - this._softkeyboardHeight,
292 this._outerScroll( this._softkeyboardHeight, scroll_height );
297 if ( dir === "in" ) {
298 if ( this._endEffect ) {
302 this._endEffect = true;
303 this._setOverflowIndicator( this._effect_dir );
304 this._showOverflowIndicator();
305 } else if ( dir === "out" ) {
306 if ( !this._endEffect ) {
310 this._endEffect = false;
312 this._endEffect = false;
313 this._setOverflowIndicator();
314 this._showOverflowIndicator();
318 _setCalibration: function ( x, y ) {
319 if ( this.options.overshootEnable ) {
325 var $v = this._$view,
327 dirLock = this._directionLock,
331 if ( dirLock !== "y" && this._hTracker ) {
332 scroll_width = $v.width() - $c.width();
336 } else if ( x < -scroll_width ) {
337 this._sx = -scroll_width;
342 if ( scroll_width < 0 ) {
347 if ( dirLock !== "x" && this._vTracker ) {
348 scroll_height = this._getViewHeight() - $c.height();
353 this._effect_dir = 0;
354 this._setEndEffect( "in" );
355 } else if ( y < -scroll_height ) {
356 this._sy = -scroll_height;
358 this._effect_dir = 1;
359 this._setEndEffect( "in" );
361 if ( this._endEffect && this._sy !== y ) {
362 this._setEndEffect();
368 if ( scroll_height < 0 ) {
374 _setScrollPosition: function ( x, y, duration ) {
375 var $v = this._$view,
376 sm = this.options.scrollMethod,
377 $vsb = this._$vScrollBar,
378 $hsb = this._$hScrollBar,
381 this._setCalibration( x, y );
386 if ( sm === "translate" ) {
387 this._setElementTransform( $v, x + "px", y + "px", duration );
389 $v.css( {left: x + "px", top: y + "px"} );
393 $sbt = $vsb.find(".ui-scrollbar-thumb");
395 if ( sm === "translate" ) {
396 this._setElementTransform( $sbt, "0px",
397 -y / this._getViewHeight() * $sbt.parent().height() + "px",
400 $sbt.css( "top", -y / this._getViewHeight() * 100 + "%" );
405 $sbt = $hsb.find(".ui-scrollbar-thumb");
407 if ( sm === "translate" ) {
408 this._setElementTransform( $sbt,
409 -x / $v.width() * $sbt.parent().width() + "px", "0px",
412 $sbt.css("left", -x / $v.width() * 100 + "%");
417 _outerScroll: function ( y, scroll_height ) {
419 top = $( window ).scrollTop() - window.screenTop,
421 duration = this.options.snapbackDuration,
422 start = getCurrentTime(),
425 if ( !this.options.outerScrollEnable ) {
429 if ( this._$clip.jqmData("scroll") !== "y" ) {
433 if ( this._outerScrolling ) {
438 sy = ( window.screenTop ? window.screenTop : -y );
439 } else if ( y < -scroll_height ) {
440 sy = -y - scroll_height;
445 tfunc = function () {
446 var elapsed = getCurrentTime() - start;
448 if ( elapsed >= duration ) {
449 window.scrollTo( 0, top + sy );
450 self._outerScrolling = undefined;
454 ec = $.easing.easeOutQuad( elapsed / duration,
455 elapsed, 0, 1, duration );
457 window.scrollTo( 0, top + ( sy * ec ) );
458 self._outerScrolling = setTimeout( tfunc, self._timerInterval );
461 this._outerScrolling = setTimeout( tfunc, self._timerInterval );
464 _scrollTo: function ( x, y, duration ) {
466 start = getCurrentTime(),
467 efunc = $.easing.easeOutQuad,
477 tfunc = function () {
478 var elapsed = getCurrentTime() - start,
481 if ( elapsed >= duration ) {
483 self._setScrollPosition( x, y );
485 ec = efunc( elapsed / duration, elapsed, 0, 1, duration );
487 self._setScrollPosition( sx + ( dx * ec ), sy + ( dy * ec ) );
488 self._timerID = setTimeout( tfunc, self._timerInterval );
492 this._timerID = setTimeout( tfunc, this._timerInterval );
495 scrollTo: function ( x, y, duration ) {
497 this._didDrag = false;
499 if ( !duration || this.options.scrollMethod === "translate" ) {
500 this._setScrollPosition( x, y, duration );
502 this._scrollTo( x, y, duration );
506 getScrollPosition: function () {
507 return { x: -this._sx, y: -this._sy };
510 skipDragging: function ( value ) {
511 this._skip_dragging = value;
514 _getScrollHierarchy: function () {
518 this._$clip.parents( ".ui-scrollview-clip").each( function () {
519 d = $( this ).jqmData("scrollview");
527 _getAncestorByDirection: function ( dir ) {
528 var svh = this._getScrollHierarchy(),
535 svdir = sv.options.direction;
537 if (!svdir || svdir === dir) {
544 _handleDragStart: function ( e, ex, ey ) {
547 this._didDrag = false;
548 this._skip_dragging = false;
550 var target = $( e.target ),
553 svdir = this.options.direction;
555 /* should prevent the default behavior when click the button */
556 this._is_button = target.is( '.ui-btn' ) ||
557 target.is( '.ui-btn-text' ) ||
558 target.is( '.ui-btn-inner' ) ||
559 target.is( '.ui-btn-inner .ui-icon' );
561 /* should prevent the default behavior when click the slider */
562 if ( target.parents('.ui-slider').length || target.is('.ui-slider') ) {
563 this._skip_dragging = true;
567 if ( target.is('textarea') ) {
568 target.bind( "scroll", function () {
569 self._skip_dragging = true;
570 target.unbind("scroll");
575 * We need to prevent the default behavior to
576 * suppress accidental selection of text, etc.
578 this._is_inputbox = target.is(':input') ||
579 target.parents(':input').length > 0;
581 if ( this._is_inputbox ) {
582 target.one( "resize.scrollview", function () {
583 if ( ey > $c.height() ) {
584 self.scrollTo( -ex, self._sy - ey + $c.height(),
585 self.options.snapbackDuration );
590 if ( this.options.eventType === "mouse" && !this._is_inputbox && !this._is_button ) {
597 this._doSnapBackX = false;
598 this._doSnapBackY = false;
601 this._directionLock = "";
604 this._enableTracking();
606 this._set_scrollbar_size();
609 _propagateDragMove: function ( sv, e, ex, ey, dir ) {
610 this._hideScrollBars();
611 this._hideOverflowIndicator();
612 this._disableTracking();
613 sv._handleDragStart( e, ex, ey );
614 sv._directionLock = dir;
615 sv._didDrag = this._didDrag;
618 _handleDragMove: function ( e, ex, ey ) {
619 if ( this._skip_dragging ) {
623 if ( !this._dragging ) {
627 if ( !this._is_inputbox && !this._is_button ) {
631 var mt = this.options.moveThreshold,
632 dx = ex - this._lastX,
633 dy = ey - this._lastY,
634 svdir = this.options.direction,
644 this._lastMove = getCurrentTime();
646 if ( !this._directionLock ) {
650 if ( x < mt && y < mt ) {
654 if ( x < y && (x / y) < 0.5 ) {
656 } else if ( x > y && (y / x) < 0.5 ) {
660 if ( svdir && dir && svdir !== dir ) {
662 * This scrollview can't handle the direction the user
663 * is attempting to scroll. Find an ancestor scrollview
664 * that can handle the request.
667 sv = this._getAncestorByDirection( dir );
669 this._propagateDragMove( sv, e, ex, ey, dir );
674 this._directionLock = svdir || (dir || "none");
679 dirLock = this._directionLock;
681 if ( dirLock !== "y" && this._hTracker ) {
686 this._doSnapBackX = false;
688 scope = ( newX > 0 || newX < this._maxX );
690 if ( scope && dirLock === "x" ) {
691 sv = this._getAncestorByDirection("x");
693 this._setScrollPosition( newX > 0 ?
694 0 : this._maxX, newY );
695 this._propagateDragMove( sv, e, ex, ey, dir );
699 newX = x + ( dx / 2 );
700 this._doSnapBackX = true;
704 if ( dirLock !== "x" && this._vTracker ) {
705 if ( Math.abs( this._startY - ey ) < mt && dirLock !== "xy" ) {
713 this._doSnapBackY = false;
715 scope = ( newY > 0 || newY < this._maxY );
717 if ( scope && dirLock === "y" ) {
718 sv = this._getAncestorByDirection("y");
720 this._setScrollPosition( newX,
721 newY > 0 ? 0 : this._maxY );
722 this._propagateDragMove( sv, e, ex, ey, dir );
726 newY = y + ( dy / 2 );
727 this._doSnapBackY = true;
731 if ( this.options.overshootEnable === false ) {
732 this._doSnapBackX = false;
733 this._doSnapBackY = false;
739 this._setScrollPosition( newX, newY );
741 if ( this._didDrag === false ) {
742 this._didDrag = true;
743 this._showScrollBars();
744 this._showOverflowIndicator();
746 this._$clip.parents(".ui-scrollview-clip").each( function () {
747 $( this ).scrollview( "skipDragging", true );
752 _handleDragStop: function ( e ) {
755 if ( this._skip_dragging ) {
759 var l = this._lastMove,
760 t = getCurrentTime(),
761 doScroll = (l && (t - l) <= this.options.moveIntervalThreshold),
762 sx = ( this._hTracker && this._speedX && doScroll ) ?
763 this._speedX : ( this._doSnapBackX ? 1 : 0 ),
764 sy = ( this._vTracker && this._speedY && doScroll ) ?
765 this._speedY : ( this._doSnapBackY ? 1 : 0 ),
766 svdir = this.options.direction,
771 if ( !this._setGestureScroll( sx, sy ) ) {
772 this._startMScroll( sx, sy );
775 this._hideScrollBars();
776 this._hideOverflowIndicator();
779 this._disableTracking();
781 if ( this._endEffect ) {
782 setTimeout( function () {
783 self._setEndEffect( "out" );
784 self._hideScrollBars();
785 self._hideOverflowIndicator();
789 return !this._didDrag;
792 _setGestureScroll: function ( sx, sy ) {
794 reset = function () {
795 clearTimeout( self._gesture_timer );
796 self._gesture_dir = 0;
797 self._gesture_timer = undefined;
810 if ( Math.abs( sx ) > Math.abs( sy ) ) {
811 dir = sx > 0 ? direction.left : direction.right;
813 dir = sy > 0 ? direction.top : direction.bottom;
816 if ( !this._gesture_timer ) {
817 this._gesture_dir = dir;
819 this._gesture_timer = setTimeout( function () {
826 if ( this._gesture_dir !== dir ) {
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 ) {
1001 scroll_top = $( window ).scrollTop() - window.screenTop,
1004 if ( e.keyCode == 9 ) {
1008 elem = $c.find(".ui-focus");
1010 if ( elem === undefined ) {
1014 elem_top = elem.offset().top - scroll_top;
1015 screen_h = $c.offset().top + $c.height() - elem.height();
1017 if ( self._softkeyboard ) {
1018 screen_h -= self._softkeyboardHeight;
1021 if ( ( elem_top < $c.offset().top ) || ( elem_top > screen_h ) ) {
1022 self.scrollTo( 0, self._sy -
1023 ( elem_top - $c.offset().top - elem.height() ) );
1029 $v.bind( "keyup", function ( e ) {
1033 scroll_top = $( window ).scrollTop() - window.screenTop,
1036 if ( e.keyCode != 9 ) {
1042 input = $( this ).find(":input");
1044 for ( i = 0; i < input.length; i++ ) {
1045 if ( !$( input[i] ).hasClass("ui-focus") ) {
1049 if ( i + 1 == input.length ) {
1050 elem = $( input[0] );
1052 elem = $( input[i + 1] );
1055 elem_top = elem.offset().top - scroll_top;
1056 screen_h = $c.offset().top + $c.height() - elem.height();
1058 if ( self._softkeyboard ) {
1059 screen_h -= self._softkeyboardHeight;
1062 if ( ( elem_top < 0 ) || ( elem_top > screen_h ) ) {
1063 self.scrollTo( 0, self._sy - elem_top +
1064 elem.height() + $c.offset().top, 0);
1075 $c.bind( "updatelayout", function ( e ) {
1078 view_h = self._getViewHeight();
1080 if ( !$c.height() || !view_h ) {
1081 self.scrollTo( 0, 0, 0 );
1085 sy = $c.height() - view_h;
1086 vh = view_h - self._view_height;
1088 self._view_height = view_h;
1090 if ( vh == 0 || vh > $c.height() / 2 ) {
1095 self.scrollTo( 0, 0, 0 );
1096 } else if ( self._sy - sy <= -vh ) {
1097 self.scrollTo( 0, self._sy,
1098 self.options.snapbackDuration );
1099 } else if ( self._sy - sy <= vh + self.options.moveThreshold ) {
1100 self.scrollTo( 0, sy,
1101 self.options.snapbackDuration );
1105 $( window ).bind( "resize", function ( e ) {
1107 view_h = self._getViewHeight();
1109 if ( $(".ui-page-active").get(0) !== $c.closest(".ui-page").get(0) ) {
1113 if ( !$c.height() || !view_h ) {
1117 focused = $c.find(".ui-focus");
1120 focused.trigger("resize.scrollview");
1123 /* calibration - after triggered throttledresize */
1124 setTimeout( function () {
1125 if ( self._sy < $c.height() - self._getViewHeight() ) {
1126 self.scrollTo( 0, $c.height() - self._getViewHeight(),
1127 self.options.overshootDuration );
1131 self._view_height = view_h;
1134 $( window ).bind( "vmouseout", function ( e ) {
1135 var drag_stop = false;
1137 if ( $(".ui-page-active").get(0) !== $c.closest(".ui-page").get(0) ) {
1141 if ( !self._dragging ) {
1145 if ( e.pageX < 0 || e.pageX > $( window ).width() ) {
1149 if ( e.pageY < 0 || e.pageY > $( window ).height() ) {
1154 self._hideScrollBars();
1155 self._hideOverflowIndicator();
1156 self._disableTracking();
1160 this._softkeyboard = false;
1161 this._softkeyboardHeight = 0;
1163 window.addEventListener( "softkeyboardchange", function ( e ) {
1164 if ( $(".ui-page-active").get(0) !== $c.closest(".ui-page").get(0) ) {
1168 self._softkeyboard = ( e.state === "on" ? true : false );
1169 self._softkeyboardHeight = parseInt( e.height ) *
1170 ( $( window ).width() / window.screen.availWidth );
1173 $c.closest(".ui-page")
1174 .bind( "pageshow", function ( e ) {
1175 /* should be called after pagelayout */
1176 setTimeout( function () {
1177 self._view_height = self._getViewHeight();
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 || vh === 0 ) {
1289 if ( ( this._$vScrollBar && vh ) || vh === 0 ) {
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 ) );
1481 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
1483 //>>excludeEnd("jqmBuildExclude");