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;
822 dir = sy > 0 ? 1 : -1;
824 if ( !this._gesture_timer ) {
825 this._gesture_count = 1;
826 this._gesture_dir = dir;
828 this._gesture_timer = setTimeout( function () {
835 if ( this._gesture_dir !== dir ) {
840 this._gesture_count++;
842 if ( this._gesture_count === 3 ) {
844 this.scrollTo( 0, 0, this.options.overshootDuration );
846 this.scrollTo( 0, -( this._getViewHeight() - this._$clip.height() ),
847 this.options.overshootDuration );
857 _enableTracking: function () {
858 this._dragging = true;
861 _disableTracking: function () {
862 this._dragging = false;
865 _showScrollBars: function ( interval ) {
866 var vclass = "ui-scrollbar-visible",
869 if ( !this.options.showScrollBars ) {
872 if ( this._scrollbar_showed ) {
876 if ( this._$vScrollBar ) {
877 this._$vScrollBar.addClass( vclass );
879 if ( this._$hScrollBar ) {
880 this._$hScrollBar.addClass( vclass );
883 this._scrollbar_showed = true;
886 setTimeout( function () {
887 self._hideScrollBars();
892 _hideScrollBars: function () {
893 var vclass = "ui-scrollbar-visible";
895 if ( !this.options.showScrollBars ) {
898 if ( !this._scrollbar_showed ) {
902 if ( this._$vScrollBar ) {
903 this._$vScrollBar.removeClass( vclass );
905 if ( this._$hScrollBar ) {
906 this._$hScrollBar.removeClass( vclass );
909 this._scrollbar_showed = false;
912 _setOverflowIndicator: function ( dir ) {
914 this._opacity_top = "0";
915 this._opacity_bottom = "0.8";
916 } else if ( dir === 0 ) {
917 this._opacity_top = "0.8";
918 this._opacity_bottom = "0";
920 this._opacity_top = "0.5";
921 this._opacity_bottom = "0.5";
925 _showOverflowIndicator: function () {
926 if ( !this.options.overflowEnable || !this._overflowAvail || this._softkeyboard ) {
930 this._overflow_top.animate( { opacity: this._opacity_top }, 300 );
931 this._overflow_bottom.animate( { opacity: this._opacity_bottom }, 300 );
933 this._overflow_showed = true;
936 _hideOverflowIndicator: function () {
937 if ( !this.options.overflowEnable || !this._overflowAvail || this._softkeyboard ) {
941 if ( this._overflow_showed === false ) {
945 this._overflow_top.animate( { opacity: 0 }, 300 );
946 this._overflow_bottom.animate( { opacity: 0 }, 300 );
948 this._overflow_showed = false;
949 this._setOverflowIndicator();
952 _add_event: function () {
957 if ( this.options.eventType === "mouse" ) {
958 this._dragEvt = "mousedown mousemove mouseup click mousewheel";
960 this._dragCB = function ( e ) {
963 return self._handleDragStart( e,
964 e.clientX, e.clientY );
967 return self._handleDragMove( e,
968 e.clientX, e.clientY );
971 return self._handleDragStop( e );
974 return !self._didDrag;
977 var old = self.getScrollPosition();
978 self.scrollTo( -old.x,
979 -(old.y - e.originalEvent.wheelDelta) );
984 this._dragEvt = "touchstart touchmove touchend click";
986 this._dragCB = function ( e ) {
987 var touches = e.originalEvent.touches;
991 if ( touches.length != 1) {
995 return self._handleDragStart( e,
996 touches[0].pageX, touches[0].pageY );
999 if ( touches.length != 1) {
1003 return self._handleDragMove( e,
1004 touches[0].pageX, touches[0].pageY );
1007 if ( touches.length != 0) {
1011 return self._handleDragStop( e );
1014 return !self._didDrag;
1019 $v.bind( this._dragEvt, this._dragCB );
1021 $v.bind( "keydown", function ( e ) {
1024 scroll_top = $( window ).scrollTop() - window.screenTop,
1027 if ( e.keyCode == 9 ) {
1031 elem = $c.find(".ui-focus");
1033 if ( elem === undefined ) {
1037 elem_top = elem.offset().top - scroll_top;
1038 screen_h = $c.offset().top + $c.height() - elem.height();
1040 if ( self._softkeyboard ) {
1041 screen_h -= self._softkeyboardHeight;
1044 if ( ( elem_top < $c.offset().top ) || ( elem_top > screen_h ) ) {
1045 self.scrollTo( 0, self._sy -
1046 ( elem_top - $c.offset().top - elem.height() ) );
1052 $v.bind( "keyup", function ( e ) {
1056 scroll_top = $( window ).scrollTop() - window.screenTop,
1059 if ( e.keyCode != 9 ) {
1065 input = $( this ).find(":input");
1067 for ( i = 0; i < input.length; i++ ) {
1068 if ( !$( input[i] ).hasClass("ui-focus") ) {
1072 if ( i + 1 == input.length ) {
1073 elem = $( input[0] );
1075 elem = $( input[i + 1] );
1078 elem_top = elem.offset().top - scroll_top;
1079 screen_h = $c.offset().top + $c.height() - elem.height();
1081 if ( self._softkeyboard ) {
1082 screen_h -= self._softkeyboardHeight;
1085 if ( ( elem_top < 0 ) || ( elem_top > screen_h ) ) {
1086 self.scrollTo( 0, self._sy - elem_top +
1087 elem.height() + $c.offset().top, 0);
1098 $c.bind( "updatelayout", function ( e ) {
1101 view_h = self._getViewHeight();
1103 if ( !$c.height() || !view_h ) {
1104 self.scrollTo( 0, 0, 0 );
1108 sy = $c.height() - view_h;
1109 vh = view_h - self._view_height;
1111 self._view_height = view_h;
1113 if ( vh == 0 || vh > $c.height() / 2 ) {
1118 self.scrollTo( 0, 0, 0 );
1119 } else if ( self._sy - sy <= -vh ) {
1120 self.scrollTo( 0, self._sy,
1121 self.options.snapbackDuration );
1122 } else if ( self._sy - sy <= vh + self.options.moveThreshold ) {
1123 self.scrollTo( 0, sy,
1124 self.options.snapbackDuration );
1128 $( window ).bind( "resize", function ( e ) {
1130 view_h = self._getViewHeight();
1132 if ( $(".ui-page-active").get(0) !== $c.closest(".ui-page").get(0) ) {
1136 if ( !$c.height() || !view_h ) {
1140 focused = $c.find(".ui-focus");
1143 focused.trigger("resize.scrollview");
1146 /* calibration - after triggered throttledresize */
1147 setTimeout( function () {
1148 if ( self._sy < $c.height() - self._getViewHeight() ) {
1149 self.scrollTo( 0, $c.height() - self._getViewHeight(),
1150 self.options.overshootDuration );
1154 self._view_height = view_h;
1157 $( window ).bind( "vmouseout", function ( e ) {
1158 var drag_stop = false;
1160 if ( $(".ui-page-active").get(0) !== $c.closest(".ui-page").get(0) ) {
1164 if ( !self._dragging ) {
1168 if ( e.pageX < 0 || e.pageX > $( window ).width() ) {
1172 if ( e.pageY < 0 || e.pageY > $( window ).height() ) {
1177 self._hideScrollBars();
1178 self._hideOverflowIndicator();
1179 self._disableTracking();
1183 this._softkeyboard = false;
1184 this._softkeyboardHeight = 0;
1186 window.addEventListener( "softkeyboardchange", function ( e ) {
1187 if ( $(".ui-page-active").get(0) !== $c.closest(".ui-page").get(0) ) {
1191 self._softkeyboard = ( e.state === "on" ? true : false );
1192 self._softkeyboardHeight = parseInt( e.height ) *
1193 ( $( window ).width() / window.screen.availWidth );
1196 $c.closest(".ui-page")
1197 .bind( "pageshow", function ( e ) {
1198 /* should be called after pagelayout */
1199 setTimeout( function () {
1200 self._view_height = self._getViewHeight();
1201 self._set_scrollbar_size();
1202 self._setScrollPosition( self._sx, self._sy );
1203 self._showScrollBars( 2000 );
1208 _add_scrollbar: function () {
1209 var $c = this._$clip,
1210 prefix = "<div class=\"ui-scrollbar ui-scrollbar-",
1211 suffix = "\"><div class=\"ui-scrollbar-track\"><div class=\"ui-scrollbar-thumb\"></div></div></div>";
1213 if ( !this.options.showScrollBars ) {
1217 if ( this._vTracker ) {
1218 $c.append( prefix + "y" + suffix );
1219 this._$vScrollBar = $c.children(".ui-scrollbar-y");
1221 if ( this._hTracker ) {
1222 $c.append( prefix + "x" + suffix );
1223 this._$hScrollBar = $c.children(".ui-scrollbar-x");
1226 this._scrollbar_showed = false;
1229 _add_scroll_jump: function () {
1230 var $c = this._$clip,
1235 if ( !this.options.scrollJump ) {
1239 if ( this._vTracker ) {
1240 top_btn = $( '<div class="ui-scroll-jump-top-bg">' +
1241 '<div data-role="button" data-inline="true" data-icon="scrolltop" data-style="box"></div></div>' );
1242 $c.append( top_btn ).trigger("create");
1244 top_btn.bind( "vclick", function () {
1245 self.scrollTo( 0, 0, self.options.overshootDuration );
1249 if ( this._hTracker ) {
1250 left_btn = $( '<div class="ui-scroll-jump-left-bg">' +
1251 '<div data-role="button" data-inline="true" data-icon="scrollleft" data-style="box"></div></div>' );
1252 $c.append( left_btn ).trigger("create");
1254 left_btn.bind( "vclick", function () {
1255 self.scrollTo( 0, 0, self.options.overshootDuration );
1260 _add_overflow_indicator: function () {
1261 if ( !this.options.overflowEnable ) {
1265 this._overflow_top = $( '<div class="ui-overflow-indicator-top"></div>' );
1266 this._overflow_bottom = $( '<div class="ui-overflow-indicator-bottom"></div>' );
1268 this._$clip.append( this._overflow_top );
1269 this._$clip.append( this._overflow_bottom );
1271 this._opacity_top = "0.5";
1272 this._opacity_bottom = "0.5";
1273 this._overflow_showed = false;
1276 _set_scrollbar_size: function () {
1277 var $c = this._$clip,
1285 if ( !this.options.showScrollBars ) {
1289 if ( this._hTracker ) {
1292 this._maxX = cw - vw;
1294 if ( this._maxX > 0 ) {
1297 if ( this._$hScrollBar && vw ) {
1298 thumb = this._$hScrollBar.find(".ui-scrollbar-thumb");
1299 thumb.css( "width", (cw >= vw ? "0" :
1300 (Math.floor(cw / vw * 100) || 1) + "%") );
1304 if ( this._vTracker ) {
1306 vh = this._getViewHeight();
1307 this._maxY = ch - vh;
1309 if ( this._maxY > 0 ) {
1312 if ( this._$vScrollBar && vh ) {
1313 thumb = this._$vScrollBar.find(".ui-scrollbar-thumb");
1314 thumb.css( "height", (ch >= vh ? "0" :
1315 (Math.floor(ch / vh * 100) || 1) + "%") );
1317 this._overflowAvail = !!thumb.height();
1323 $.extend( MomentumTracker.prototype, {
1324 start: function ( pos, speed, duration, minPos, maxPos ) {
1325 var tstate = ( pos < minPos || pos > maxPos ) ?
1326 tstates.snapback : tstates.scrolling,
1329 this.state = ( speed !== 0 ) ? tstate : tstates.done;
1332 this.duration = ( this.state === tstates.snapback ) ?
1333 this.options.snapbackDuration : duration;
1334 this.minPos = minPos;
1335 this.maxPos = maxPos;
1337 this.fromPos = ( this.state === tstates.snapback ) ? this.pos : 0;
1338 pos_temp = ( this.pos < this.minPos ) ? this.minPos : this.maxPos;
1339 this.toPos = ( this.state === tstates.snapback ) ? pos_temp : 0;
1341 this.startTime = getCurrentTime();
1344 reset: function () {
1345 this.state = tstates.done;
1354 update: function ( overshootEnable ) {
1355 var state = this.state,
1356 cur_time = getCurrentTime(),
1357 duration = this.duration,
1358 elapsed = cur_time - this.startTime,
1363 if ( state === tstates.done ) {
1367 elapsed = elapsed > duration ? duration : elapsed;
1369 this.remained = duration - elapsed;
1371 if ( state === tstates.scrolling || state === tstates.overshot ) {
1373 ( 1 - $.easing[this.easing]( elapsed / duration,
1374 elapsed, 0, 1, duration ) );
1378 didOverShoot = ( state === tstates.scrolling ) &&
1379 ( x < this.minPos || x > this.maxPos );
1381 if ( didOverShoot ) {
1382 x = ( x < this.minPos ) ? this.minPos : this.maxPos;
1387 if ( state === tstates.overshot ) {
1388 if ( !overshootEnable ) {
1389 this.state = tstates.done;
1391 if ( elapsed >= duration ) {
1392 this.state = tstates.snapback;
1393 this.fromPos = this.pos;
1394 this.toPos = ( x < this.minPos ) ?
1395 this.minPos : this.maxPos;
1396 this.duration = this.options.snapbackDuration;
1397 this.startTime = cur_time;
1400 } else if ( state === tstates.scrolling ) {
1401 if ( didOverShoot && overshootEnable ) {
1402 this.state = tstates.overshot;
1403 this.speed = dx / 2;
1404 this.duration = this.options.overshootDuration;
1405 this.startTime = cur_time;
1406 } else if ( elapsed >= duration ) {
1407 this.state = tstates.done;
1410 } else if ( state === tstates.snapback ) {
1411 if ( elapsed >= duration ) {
1412 this.pos = this.toPos;
1413 this.state = tstates.done;
1415 this.pos = this.fromPos + (( this.toPos - this.fromPos ) *
1416 $.easing[this.easing]( elapsed / duration,
1417 elapsed, 0, 1, duration ));
1425 return this.state === tstates.done;
1428 isMin: function () {
1429 return this.pos === this.minPos;
1432 isMax: function () {
1433 return this.pos === this.maxPos;
1436 isAvail: function () {
1437 return !( this.minPos === this.maxPos );
1440 getRemained: function () {
1441 return this.remained;
1444 getPosition: function () {
1449 $( document ).bind( 'pagecreate create', function ( e ) {
1450 var $page = $( e.target ),
1451 content_scroll = $page.find(".ui-content").jqmData("scroll");
1453 /* content scroll */
1454 if ( $.support.scrollview === undefined ) {
1455 $.support.scrollview = true;
1458 if ( $.support.scrollview === true && content_scroll === undefined ) {
1459 content_scroll = "y";
1462 if ( content_scroll !== "y" ) {
1463 content_scroll = "none";
1466 $page.find(".ui-content").attr( "data-scroll", content_scroll );
1468 $page.find(":jqmData(scroll)").not(".ui-scrollview-clip").each( function () {
1469 if ( $( this ).hasClass("ui-scrolllistview") ) {
1470 $( this ).scrolllistview();
1472 var st = $( this ).jqmData("scroll"),
1473 dir = st && ( st.search(/^[xy]/) !== -1 ) ? st : null,
1474 content = $(this).hasClass("ui-content"),
1477 if ( st === "none" ) {
1482 direction: dir || undefined,
1483 overflowEnable: content,
1484 scrollMethod: $( this ).jqmData("scroll-method") || undefined,
1485 scrollJump: $( this ).jqmData("scroll-jump") || undefined
1488 $( this ).scrollview( opts );
1493 $( document ).bind( 'pageshow', function ( e ) {
1494 var $page = $( e.target ),
1495 scroll = $page.find(".ui-content").jqmData("scroll");
1497 if ( scroll === "y" ) {
1498 resizePageContentHeight( e.target );
1502 }( jQuery, window, document ) );
1504 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
1506 //>>excludeEnd("jqmBuildExclude");