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: true,
75 _getViewHeight: function () {
76 return this._$view.height();
79 _makePositioned: function ( $ele ) {
80 if ( $ele.css("position") === "static" ) {
81 $ele.css( "position", "relative" );
85 _create: function () {
89 this._$clip = $( this.element ).addClass("ui-scrollview-clip");
91 if ( this._$clip.children(".ui-scrollview-view").length ) {
92 this._$view = this._$clip.children(".ui-scrollview-view");
94 this._$view = this._$clip.wrapInner("<div></div>").children()
95 .addClass("ui-scrollview-view");
98 if ( this.options.scrollMethod === "translate" ) {
99 if ( this._$view.css("transform") === undefined ) {
100 this.options.scrollMethod = "position";
104 this._$clip.css( "overflow", "hidden" );
105 this._makePositioned( this._$clip );
107 this._makePositioned( this._$view );
108 this._$view.css( { left: 0, top: 0 } );
110 this._view_height = this._getViewHeight();
115 direction = this.options.direction;
117 this._hTracker = ( direction !== "y" ) ?
118 new MomentumTracker( this.options ) : null;
119 this._vTracker = ( direction !== "x" ) ?
120 new MomentumTracker( this.options ) : null;
122 this._timerInterval = this.options.timerInterval;
125 this._timerCB = function () {
126 self._handleMomentumScroll();
130 this._add_scrollbar();
131 this._add_scroll_jump();
132 this._add_overflow_indicator();
135 _startMScroll: function ( speedX, speedY ) {
136 var keepGoing = false,
137 duration = this.options.scrollDuration,
143 this._$clip.trigger( this.options.startEventName );
146 c = this._$clip.width();
147 v = this._$view.width();
149 if ( (( this._sx === 0 && speedX > 0 ) ||
150 ( this._sx === -(v - c) && speedX < 0 )) &&
155 ht.start( this._sx, speedX,
156 duration, (v > c) ? -(v - c) : 0, 0 );
157 keepGoing = !ht.done();
161 c = this._$clip.height();
162 v = this._getViewHeight();
164 if ( (( this._sy === 0 && speedY > 0 ) ||
165 ( this._sy === -(v - c) && speedY < 0 )) &&
170 vt.start( this._sy, speedY,
171 duration, (v > c) ? -(v - c) : 0, 0 );
172 keepGoing = keepGoing || !vt.done();
176 this._timerID = setTimeout( this._timerCB, this._timerInterval );
182 _stopMScroll: function () {
183 if ( this._timerID ) {
184 this._$clip.trigger( this.options.stopEventName );
185 clearTimeout( this._timerID );
189 if ( this._vTracker ) {
190 this._vTracker.reset();
193 if ( this._hTracker ) {
194 this._hTracker.reset();
197 this._hideScrollBars();
198 this._hideOverflowIndicator();
201 _handleMomentumScroll: function () {
202 var keepGoing = false,
207 end_effect = function ( dir ) {
208 setTimeout( function () {
209 self._effect_dir = dir;
210 self._setEndEffect( "in" );
213 setTimeout( function () {
214 self._setEndEffect( "out" );
220 if ( this._outerScrolling ) {
225 vt.update( this.options.overshootEnable );
226 y = vt.getPosition();
227 keepGoing = !vt.done();
229 if ( vt.getRemained() > this.options.overshootDuration ) {
230 scroll_height = this._getViewHeight() - this._$clip.height();
232 if ( !vt.isAvail() ) {
233 if ( this._speedY > 0 ) {
234 this._outerScroll( vt.getRemained() / 3, scroll_height );
236 this._outerScroll( y - vt.getRemained() / 3, scroll_height );
238 } else if ( vt.isMin() ) {
239 this._outerScroll( y - vt.getRemained() / 3, scroll_height );
241 if ( scroll_height > 0 ) {
244 } else if ( vt.isMax() ) {
245 this._outerScroll( vt.getRemained() / 3, scroll_height );
247 if ( scroll_height > 0 ) {
255 ht.update( this.options.overshootEnable );
256 x = ht.getPosition();
257 keepGoing = keepGoing || !ht.done();
260 this._setScrollPosition( x, y );
261 this._$clip.trigger( this.options.updateEventName,
262 [ { x: x, y: y } ] );
265 this._timerID = setTimeout( this._timerCB, this._timerInterval );
271 _setElementTransform: function ( $ele, x, y, duration ) {
275 if ( !duration || duration === undefined ) {
278 transition = "-webkit-transform " + duration / 1000 + "s ease-out";
281 if ( $.support.cssTransform3d ) {
282 translate = "translate3d(" + x + "," + y + ", 0px)";
284 translate = "translate(" + x + "," + y + ")";
288 "-moz-transform": translate,
289 "-webkit-transform": translate,
290 "-ms-transform": translate,
291 "-o-transform": translate,
292 "transform": translate,
293 "-webkit-transition": transition
297 _setEndEffect: function ( dir ) {
298 var scroll_height = this._getViewHeight() - this._$clip.height();
300 if ( this._softkeyboard ) {
301 if ( this._effect_dir ) {
302 this._outerScroll( -scroll_height - this._softkeyboardHeight,
305 this._outerScroll( this._softkeyboardHeight, scroll_height );
310 if ( dir === "in" ) {
311 if ( this._endEffect ) {
315 this._endEffect = true;
316 this._setOverflowIndicator( this._effect_dir );
317 this._showOverflowIndicator();
318 } else if ( dir === "out" ) {
319 if ( !this._endEffect ) {
323 this._endEffect = false;
325 this._endEffect = false;
326 this._setOverflowIndicator();
327 this._showOverflowIndicator();
331 _setCalibration: function ( x, y ) {
332 if ( this.options.overshootEnable ) {
338 var $v = this._$view,
340 dirLock = this._directionLock,
344 if ( dirLock !== "y" && this._hTracker ) {
345 scroll_width = $v.width() - $c.width();
349 } else if ( x < -scroll_width ) {
350 this._sx = -scroll_width;
355 if ( scroll_width < 0 ) {
360 if ( dirLock !== "x" && this._vTracker ) {
361 scroll_height = this._getViewHeight() - $c.height();
366 if ( this._didDrag && scroll_height > 0 ) {
367 this._effect_dir = 0;
368 this._setEndEffect( "in" );
370 } else if ( y < -scroll_height ) {
371 this._sy = -scroll_height;
373 if ( this._didDrag && scroll_height > 0 ) {
374 this._effect_dir = 1;
375 this._setEndEffect( "in" );
378 if ( this._endEffect && this._sy !== y ) {
379 this._setEndEffect();
385 if ( scroll_height < 0 ) {
391 _setScrollPosition: function ( x, y, duration ) {
392 var $v = this._$view,
393 sm = this.options.scrollMethod,
394 $vsb = this._$vScrollBar,
395 $hsb = this._$hScrollBar,
398 this._setCalibration( x, y );
403 if ( sm === "translate" ) {
404 this._setElementTransform( $v, x + "px", y + "px", duration );
406 $v.css( {left: x + "px", top: y + "px"} );
410 $sbt = $vsb.find(".ui-scrollbar-thumb");
412 if ( sm === "translate" ) {
413 this._setElementTransform( $sbt, "0px",
414 -y / this._getViewHeight() * $sbt.parent().height() + "px",
417 $sbt.css( "top", -y / this._getViewHeight() * 100 + "%" );
422 $sbt = $hsb.find(".ui-scrollbar-thumb");
424 if ( sm === "translate" ) {
425 this._setElementTransform( $sbt,
426 -x / $v.width() * $sbt.parent().width() + "px", "0px",
429 $sbt.css("left", -x / $v.width() * 100 + "%");
434 _outerScroll: function ( y, scroll_height ) {
436 top = $( window ).scrollTop() - window.screenTop,
438 duration = this.options.snapbackDuration,
439 start = getCurrentTime(),
442 if ( !this.options.outerScrollEnable ) {
446 if ( this._$clip.jqmData("scroll") !== "y" ) {
450 if ( this._outerScrolling ) {
455 sy = ( window.screenTop ? window.screenTop : -y );
456 } else if ( y < -scroll_height ) {
457 sy = -y - scroll_height;
462 tfunc = function () {
463 var elapsed = getCurrentTime() - start;
465 if ( elapsed >= duration ) {
466 window.scrollTo( 0, top + sy );
467 self._outerScrolling = undefined;
471 ec = $.easing.easeOutQuad( elapsed / duration,
472 elapsed, 0, 1, duration );
474 window.scrollTo( 0, top + ( sy * ec ) );
475 self._outerScrolling = setTimeout( tfunc, self._timerInterval );
478 this._outerScrolling = setTimeout( tfunc, self._timerInterval );
481 _scrollTo: function ( x, y, duration ) {
483 start = getCurrentTime(),
484 efunc = $.easing.easeOutQuad,
494 tfunc = function () {
495 var elapsed = getCurrentTime() - start,
498 if ( elapsed >= duration ) {
500 self._setScrollPosition( x, y );
502 ec = efunc( elapsed / duration, elapsed, 0, 1, duration );
504 self._setScrollPosition( sx + ( dx * ec ), sy + ( dy * ec ) );
505 self._timerID = setTimeout( tfunc, self._timerInterval );
509 this._timerID = setTimeout( tfunc, this._timerInterval );
512 scrollTo: function ( x, y, duration ) {
514 this._didDrag = false;
516 if ( !duration || this.options.scrollMethod === "translate" ) {
517 this._setScrollPosition( x, y, duration );
519 this._scrollTo( x, y, duration );
523 getScrollPosition: function () {
524 return { x: -this._sx, y: -this._sy };
527 skipDragging: function ( value ) {
528 this._skip_dragging = value;
531 _getScrollHierarchy: function () {
535 this._$clip.parents( ".ui-scrollview-clip").each( function () {
536 d = $( this ).jqmData("scrollview");
544 _getAncestorByDirection: function ( dir ) {
545 var svh = this._getScrollHierarchy(),
552 svdir = sv.options.direction;
554 if (!svdir || svdir === dir) {
561 _handleDragStart: function ( e, ex, ey ) {
564 this._didDrag = false;
565 this._skip_dragging = false;
567 var target = $( e.target ),
570 svdir = this.options.direction;
572 /* should prevent the default behavior when click the button */
573 this._is_button = target.is( '.ui-btn' ) ||
574 target.is( '.ui-btn-text' ) ||
575 target.is( '.ui-btn-inner' ) ||
576 target.is( '.ui-btn-inner .ui-icon' );
578 /* should prevent the default behavior when click the slider */
579 if ( target.parents('.ui-slider').length || target.is('.ui-slider') ) {
580 this._skip_dragging = true;
584 if ( target.is('textarea') ) {
585 target.bind( "scroll", function () {
586 self._skip_dragging = true;
587 target.unbind("scroll");
592 * We need to prevent the default behavior to
593 * suppress accidental selection of text, etc.
595 this._is_inputbox = target.is(':input') ||
596 target.parents(':input').length > 0;
598 if ( this._is_inputbox ) {
599 target.one( "resize.scrollview", function () {
600 if ( ey > $c.height() ) {
601 self.scrollTo( -ex, self._sy - ey + $c.height(),
602 self.options.snapbackDuration );
607 if ( this.options.eventType === "mouse" && !this._is_inputbox && !this._is_button ) {
614 this._doSnapBackX = false;
615 this._doSnapBackY = false;
618 this._directionLock = "";
621 this._enableTracking();
623 this._set_scrollbar_size();
626 _propagateDragMove: function ( sv, e, ex, ey, dir ) {
627 this._hideScrollBars();
628 this._hideOverflowIndicator();
629 this._disableTracking();
630 sv._handleDragStart( e, ex, ey );
631 sv._directionLock = dir;
632 sv._didDrag = this._didDrag;
635 _handleDragMove: function ( e, ex, ey ) {
636 if ( this._skip_dragging ) {
640 if ( !this._dragging ) {
644 if ( !this._is_inputbox && !this._is_button ) {
648 var mt = this.options.moveThreshold,
649 dx = ex - this._lastX,
650 dy = ey - this._lastY,
651 svdir = this.options.direction,
661 this._lastMove = getCurrentTime();
663 if ( !this._directionLock ) {
667 if ( x < mt && y < mt ) {
671 if ( x < y && (x / y) < 0.5 ) {
673 } else if ( x > y && (y / x) < 0.5 ) {
677 if ( svdir && dir && svdir !== dir ) {
679 * This scrollview can't handle the direction the user
680 * is attempting to scroll. Find an ancestor scrollview
681 * that can handle the request.
684 sv = this._getAncestorByDirection( dir );
686 this._propagateDragMove( sv, e, ex, ey, dir );
691 this._directionLock = svdir || (dir || "none");
696 dirLock = this._directionLock;
698 if ( dirLock !== "y" && this._hTracker ) {
703 this._doSnapBackX = false;
705 scope = ( newX > 0 || newX < this._maxX );
707 if ( scope && dirLock === "x" ) {
708 sv = this._getAncestorByDirection("x");
710 this._setScrollPosition( newX > 0 ?
711 0 : this._maxX, newY );
712 this._propagateDragMove( sv, e, ex, ey, dir );
716 newX = x + ( dx / 2 );
717 this._doSnapBackX = true;
721 if ( dirLock !== "x" && this._vTracker ) {
722 if ( Math.abs( this._startY - ey ) < mt && dirLock !== "xy" ) {
730 this._doSnapBackY = false;
732 scope = ( newY > 0 || newY < this._maxY );
734 if ( scope && dirLock === "y" ) {
735 sv = this._getAncestorByDirection("y");
737 this._setScrollPosition( newX,
738 newY > 0 ? 0 : this._maxY );
739 this._propagateDragMove( sv, e, ex, ey, dir );
743 newY = y + ( dy / 2 );
744 this._doSnapBackY = true;
748 if ( this.options.overshootEnable === false ) {
749 this._doSnapBackX = false;
750 this._doSnapBackY = false;
756 this._setScrollPosition( newX, newY );
758 if ( this._didDrag === false ) {
759 this._didDrag = true;
760 this._showScrollBars();
761 this._showOverflowIndicator();
763 this._$clip.parents(".ui-scrollview-clip").each( function () {
764 $( this ).scrollview( "skipDragging", true );
769 _handleDragStop: function ( e ) {
772 if ( this._skip_dragging ) {
776 var l = this._lastMove,
777 t = getCurrentTime(),
778 doScroll = (l && (t - l) <= this.options.moveIntervalThreshold),
779 sx = ( this._hTracker && this._speedX && doScroll ) ?
780 this._speedX : ( this._doSnapBackX ? 1 : 0 ),
781 sy = ( this._vTracker && this._speedY && doScroll ) ?
782 this._speedY : ( this._doSnapBackY ? 1 : 0 ),
783 svdir = this.options.direction,
788 if ( !this._setGestureScroll( sx, sy ) ) {
789 this._startMScroll( sx, sy );
792 this._hideScrollBars();
793 this._hideOverflowIndicator();
796 this._disableTracking();
798 if ( this._endEffect ) {
799 setTimeout( function () {
800 self._setEndEffect( "out" );
801 self._hideScrollBars();
802 self._hideOverflowIndicator();
806 return !this._didDrag;
809 _setGestureScroll: function ( sx, sy ) {
811 reset = function () {
812 clearTimeout( self._gesture_timer );
813 self._gesture_dir = 0;
814 self._gesture_count = 0;
815 self._gesture_timer = undefined;
828 if ( Math.abs( sx ) > Math.abs( sy ) ) {
829 dir = sx > 0 ? direction.left : direction.right;
831 dir = sy > 0 ? direction.top : direction.bottom;
834 if ( !this._gesture_timer ) {
835 this._gesture_count = 1;
836 this._gesture_dir = dir;
838 this._gesture_timer = setTimeout( function () {
845 if ( this._gesture_dir !== dir ) {
850 this._gesture_count++;
852 if ( this._gesture_count === 3 ) {
855 this.scrollTo( this._sx, 0, this.options.overshootDuration );
857 case direction.bottom:
858 this.scrollTo( this._sx, -( this._getViewHeight() - this._$clip.height() ),
859 this.options.overshootDuration );
862 this.scrollTo( 0, this._sy, this.options.overshootDuration );
864 case direction.right:
865 this.scrollTo( -( this._$view.width() - this._$clip.width() ), this._sy,
866 this.options.overshootDuration );
871 this._didDrag = true;
879 _enableTracking: function () {
880 this._dragging = true;
883 _disableTracking: function () {
884 this._dragging = false;
887 _showScrollBars: function ( interval ) {
888 var vclass = "ui-scrollbar-visible",
891 if ( !this.options.showScrollBars ) {
894 if ( this._scrollbar_showed ) {
898 if ( this._$vScrollBar ) {
899 this._$vScrollBar.addClass( vclass );
901 if ( this._$hScrollBar ) {
902 this._$hScrollBar.addClass( vclass );
905 this._scrollbar_showed = true;
908 setTimeout( function () {
909 self._hideScrollBars();
914 _hideScrollBars: function () {
915 var vclass = "ui-scrollbar-visible";
917 if ( !this.options.showScrollBars ) {
920 if ( !this._scrollbar_showed ) {
924 if ( this._$vScrollBar ) {
925 this._$vScrollBar.removeClass( vclass );
927 if ( this._$hScrollBar ) {
928 this._$hScrollBar.removeClass( vclass );
931 this._scrollbar_showed = false;
934 _setOverflowIndicator: function ( dir ) {
936 this._opacity_top = "0";
937 this._opacity_bottom = "0.8";
938 } else if ( dir === 0 ) {
939 this._opacity_top = "0.8";
940 this._opacity_bottom = "0";
942 this._opacity_top = "0.5";
943 this._opacity_bottom = "0.5";
947 _showOverflowIndicator: function () {
948 if ( !this.options.overflowEnable || !this._overflowAvail || this._softkeyboard ) {
952 this._overflow_top.animate( { opacity: this._opacity_top }, 300 );
953 this._overflow_bottom.animate( { opacity: this._opacity_bottom }, 300 );
955 this._overflow_showed = true;
958 _hideOverflowIndicator: function () {
959 if ( !this.options.overflowEnable || !this._overflowAvail || this._softkeyboard ) {
963 if ( this._overflow_showed === false ) {
967 this._overflow_top.animate( { opacity: 0 }, 300 );
968 this._overflow_bottom.animate( { opacity: 0 }, 300 );
970 this._overflow_showed = false;
971 this._setOverflowIndicator();
974 _add_event: function () {
979 if ( this.options.eventType === "mouse" ) {
980 this._dragEvt = "mousedown mousemove mouseup click mousewheel";
982 this._dragCB = function ( e ) {
985 return self._handleDragStart( e,
986 e.clientX, e.clientY );
989 return self._handleDragMove( e,
990 e.clientX, e.clientY );
993 return self._handleDragStop( e );
996 return !self._didDrag;
999 var old = self.getScrollPosition();
1000 self.scrollTo( -old.x,
1001 -(old.y - e.originalEvent.wheelDelta) );
1006 this._dragEvt = "touchstart touchmove touchend click";
1008 this._dragCB = function ( e ) {
1009 var touches = e.originalEvent.touches;
1013 if ( touches.length != 1) {
1017 return self._handleDragStart( e,
1018 touches[0].pageX, touches[0].pageY );
1021 if ( touches.length != 1) {
1025 return self._handleDragMove( e,
1026 touches[0].pageX, touches[0].pageY );
1029 if ( touches.length != 0) {
1033 return self._handleDragStop( e );
1036 return !self._didDrag;
1041 $v.bind( this._dragEvt, this._dragCB );
1043 $v.bind( "keydown", function ( e ) {
1046 scroll_top = $( window ).scrollTop() - window.screenTop,
1049 if ( e.keyCode == 9 ) {
1053 elem = $c.find(".ui-focus");
1055 if ( elem === undefined ) {
1059 elem_top = elem.offset().top - scroll_top;
1060 screen_h = $c.offset().top + $c.height() - elem.height();
1062 if ( self._softkeyboard ) {
1063 screen_h -= self._softkeyboardHeight;
1066 if ( ( elem_top < $c.offset().top ) || ( elem_top > screen_h ) ) {
1067 self.scrollTo( 0, self._sy -
1068 ( elem_top - $c.offset().top - elem.height() ) );
1074 $v.bind( "keyup", function ( e ) {
1078 scroll_top = $( window ).scrollTop() - window.screenTop,
1081 if ( e.keyCode != 9 ) {
1087 input = $( this ).find(":input");
1089 for ( i = 0; i < input.length; i++ ) {
1090 if ( !$( input[i] ).hasClass("ui-focus") ) {
1094 if ( i + 1 == input.length ) {
1095 elem = $( input[0] );
1097 elem = $( input[i + 1] );
1100 elem_top = elem.offset().top - scroll_top;
1101 screen_h = $c.offset().top + $c.height() - elem.height();
1103 if ( self._softkeyboard ) {
1104 screen_h -= self._softkeyboardHeight;
1107 if ( ( elem_top < 0 ) || ( elem_top > screen_h ) ) {
1108 self.scrollTo( 0, self._sy - elem_top +
1109 elem.height() + $c.offset().top, 0);
1120 $c.bind( "updatelayout", function ( e ) {
1123 view_h = self._getViewHeight();
1125 if ( !$c.height() || !view_h ) {
1126 self.scrollTo( 0, 0, 0 );
1130 sy = $c.height() - view_h;
1131 vh = view_h - self._view_height;
1133 self._view_height = view_h;
1135 if ( vh == 0 || vh > $c.height() / 2 ) {
1140 self.scrollTo( 0, 0, 0 );
1141 } else if ( self._sy - sy <= -vh ) {
1142 self.scrollTo( 0, self._sy,
1143 self.options.snapbackDuration );
1144 } else if ( self._sy - sy <= vh + self.options.moveThreshold ) {
1145 self.scrollTo( 0, sy,
1146 self.options.snapbackDuration );
1150 $( window ).bind( "resize", function ( e ) {
1152 view_h = self._getViewHeight();
1154 if ( $(".ui-page-active").get(0) !== $c.closest(".ui-page").get(0) ) {
1158 if ( !$c.height() || !view_h ) {
1162 focused = $c.find(".ui-focus");
1165 focused.trigger("resize.scrollview");
1168 /* calibration - after triggered throttledresize */
1169 setTimeout( function () {
1170 if ( self._sy < $c.height() - self._getViewHeight() ) {
1171 self.scrollTo( 0, $c.height() - self._getViewHeight(),
1172 self.options.overshootDuration );
1176 self._view_height = view_h;
1179 $( window ).bind( "vmouseout", function ( e ) {
1180 var drag_stop = false;
1182 if ( $(".ui-page-active").get(0) !== $c.closest(".ui-page").get(0) ) {
1186 if ( !self._dragging ) {
1190 if ( e.pageX < 0 || e.pageX > $( window ).width() ) {
1194 if ( e.pageY < 0 || e.pageY > $( window ).height() ) {
1199 self._hideScrollBars();
1200 self._hideOverflowIndicator();
1201 self._disableTracking();
1205 this._softkeyboard = false;
1206 this._softkeyboardHeight = 0;
1208 window.addEventListener( "softkeyboardchange", function ( e ) {
1209 if ( $(".ui-page-active").get(0) !== $c.closest(".ui-page").get(0) ) {
1213 self._softkeyboard = ( e.state === "on" ? true : false );
1214 self._softkeyboardHeight = parseInt( e.height ) *
1215 ( $( window ).width() / window.screen.availWidth );
1218 $c.closest(".ui-page")
1219 .bind( "pageshow", function ( e ) {
1220 /* should be called after pagelayout */
1221 setTimeout( function () {
1222 self._view_height = self._getViewHeight();
1223 self._set_scrollbar_size();
1224 self._setScrollPosition( self._sx, self._sy );
1225 self._showScrollBars( 2000 );
1230 _add_scrollbar: function () {
1231 var $c = this._$clip,
1232 prefix = "<div class=\"ui-scrollbar ui-scrollbar-",
1233 suffix = "\"><div class=\"ui-scrollbar-track\"><div class=\"ui-scrollbar-thumb\"></div></div></div>";
1235 if ( !this.options.showScrollBars ) {
1239 if ( this._vTracker ) {
1240 $c.append( prefix + "y" + suffix );
1241 this._$vScrollBar = $c.children(".ui-scrollbar-y");
1243 if ( this._hTracker ) {
1244 $c.append( prefix + "x" + suffix );
1245 this._$hScrollBar = $c.children(".ui-scrollbar-x");
1248 this._scrollbar_showed = false;
1251 _add_scroll_jump: function () {
1252 var $c = this._$clip,
1257 if ( !this.options.scrollJump ) {
1261 if ( this._vTracker ) {
1262 top_btn = $( '<div class="ui-scroll-jump-top-bg">' +
1263 '<div data-role="button" data-inline="true" data-icon="scrolltop" data-style="box"></div></div>' );
1264 $c.append( top_btn ).trigger("create");
1266 top_btn.bind( "vclick", function () {
1267 self.scrollTo( 0, 0, self.options.overshootDuration );
1271 if ( this._hTracker ) {
1272 left_btn = $( '<div class="ui-scroll-jump-left-bg">' +
1273 '<div data-role="button" data-inline="true" data-icon="scrollleft" data-style="box"></div></div>' );
1274 $c.append( left_btn ).trigger("create");
1276 left_btn.bind( "vclick", function () {
1277 self.scrollTo( 0, 0, self.options.overshootDuration );
1282 _add_overflow_indicator: function () {
1283 if ( !this.options.overflowEnable ) {
1287 this._overflow_top = $( '<div class="ui-overflow-indicator-top"></div>' );
1288 this._overflow_bottom = $( '<div class="ui-overflow-indicator-bottom"></div>' );
1290 this._$clip.append( this._overflow_top );
1291 this._$clip.append( this._overflow_bottom );
1293 this._opacity_top = "0.5";
1294 this._opacity_bottom = "0.5";
1295 this._overflow_showed = false;
1298 _set_scrollbar_size: function () {
1299 var $c = this._$clip,
1307 if ( !this.options.showScrollBars ) {
1311 if ( this._hTracker ) {
1314 this._maxX = cw - vw;
1316 if ( this._maxX > 0 ) {
1319 if ( this._$hScrollBar && vw ) {
1320 thumb = this._$hScrollBar.find(".ui-scrollbar-thumb");
1321 thumb.css( "width", (cw >= vw ? "0" :
1322 (Math.floor(cw / vw * 100) || 1) + "%") );
1326 if ( this._vTracker ) {
1328 vh = this._getViewHeight();
1329 this._maxY = ch - vh;
1331 if ( this._maxY > 0 ) {
1334 if ( this._$vScrollBar && vh ) {
1335 thumb = this._$vScrollBar.find(".ui-scrollbar-thumb");
1336 thumb.css( "height", (ch >= vh ? "0" :
1337 (Math.floor(ch / vh * 100) || 1) + "%") );
1339 this._overflowAvail = !!thumb.height();
1345 $.extend( MomentumTracker.prototype, {
1346 start: function ( pos, speed, duration, minPos, maxPos ) {
1347 var tstate = ( pos < minPos || pos > maxPos ) ?
1348 tstates.snapback : tstates.scrolling,
1351 this.state = ( speed !== 0 ) ? tstate : tstates.done;
1354 this.duration = ( this.state === tstates.snapback ) ?
1355 this.options.snapbackDuration : duration;
1356 this.minPos = minPos;
1357 this.maxPos = maxPos;
1359 this.fromPos = ( this.state === tstates.snapback ) ? this.pos : 0;
1360 pos_temp = ( this.pos < this.minPos ) ? this.minPos : this.maxPos;
1361 this.toPos = ( this.state === tstates.snapback ) ? pos_temp : 0;
1363 this.startTime = getCurrentTime();
1366 reset: function () {
1367 this.state = tstates.done;
1376 update: function ( overshootEnable ) {
1377 var state = this.state,
1378 cur_time = getCurrentTime(),
1379 duration = this.duration,
1380 elapsed = cur_time - this.startTime,
1385 if ( state === tstates.done ) {
1389 elapsed = elapsed > duration ? duration : elapsed;
1391 this.remained = duration - elapsed;
1393 if ( state === tstates.scrolling || state === tstates.overshot ) {
1395 ( 1 - $.easing[this.easing]( elapsed / duration,
1396 elapsed, 0, 1, duration ) );
1400 didOverShoot = ( state === tstates.scrolling ) &&
1401 ( x < this.minPos || x > this.maxPos );
1403 if ( didOverShoot ) {
1404 x = ( x < this.minPos ) ? this.minPos : this.maxPos;
1409 if ( state === tstates.overshot ) {
1410 if ( !overshootEnable ) {
1411 this.state = tstates.done;
1413 if ( elapsed >= duration ) {
1414 this.state = tstates.snapback;
1415 this.fromPos = this.pos;
1416 this.toPos = ( x < this.minPos ) ?
1417 this.minPos : this.maxPos;
1418 this.duration = this.options.snapbackDuration;
1419 this.startTime = cur_time;
1422 } else if ( state === tstates.scrolling ) {
1423 if ( didOverShoot && overshootEnable ) {
1424 this.state = tstates.overshot;
1425 this.speed = dx / 2;
1426 this.duration = this.options.overshootDuration;
1427 this.startTime = cur_time;
1428 } else if ( elapsed >= duration ) {
1429 this.state = tstates.done;
1432 } else if ( state === tstates.snapback ) {
1433 if ( elapsed >= duration ) {
1434 this.pos = this.toPos;
1435 this.state = tstates.done;
1437 this.pos = this.fromPos + (( this.toPos - this.fromPos ) *
1438 $.easing[this.easing]( elapsed / duration,
1439 elapsed, 0, 1, duration ));
1447 return this.state === tstates.done;
1450 isMin: function () {
1451 return this.pos === this.minPos;
1454 isMax: function () {
1455 return this.pos === this.maxPos;
1458 isAvail: function () {
1459 return !( this.minPos === this.maxPos );
1462 getRemained: function () {
1463 return this.remained;
1466 getPosition: function () {
1471 $( document ).bind( 'pagecreate create', function ( e ) {
1472 var $page = $( e.target ),
1473 content_scroll = $page.find(".ui-content").jqmData("scroll");
1475 /* content scroll */
1476 if ( $.support.scrollview === undefined ) {
1477 $.support.scrollview = true;
1480 if ( $.support.scrollview === true && content_scroll === undefined ) {
1481 content_scroll = "y";
1484 if ( content_scroll !== "y" ) {
1485 content_scroll = "none";
1488 $page.find(".ui-content").attr( "data-scroll", content_scroll );
1490 $page.find(":jqmData(scroll)").not(".ui-scrollview-clip").each( function () {
1491 if ( $( this ).hasClass("ui-scrolllistview") ) {
1492 $( this ).scrolllistview();
1494 var st = $( this ).jqmData("scroll"),
1495 dir = st && ( st.search(/^[xy]/) !== -1 ) ? st : null,
1496 content = $(this).hasClass("ui-content"),
1499 if ( st === "none" ) {
1504 direction: dir || undefined,
1505 overflowEnable: content,
1506 scrollMethod: $( this ).jqmData("scroll-method") || undefined,
1507 scrollJump: $( this ).jqmData("scroll-jump") || undefined
1510 $( this ).scrollview( opts );
1515 $( document ).bind( 'pageshow', function ( e ) {
1516 var $page = $( e.target ),
1517 scroll = $page.find(".ui-content").jqmData("scroll");
1519 if ( scroll === "y" ) {
1520 resizePageContentHeight( e.target );
1524 }( jQuery, window, document ) );
1526 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
1528 //>>excludeEnd("jqmBuildExclude");