Source

mobile-demo-set / static / scrollview / sv-test-02.html

Full commit
<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Scrollview Test 02 - Scrollview Events Test</title>
	<link rel="stylesheet"  href="../../css/themes/default/"/>
	<link rel="stylesheet" href="jquery.mobile.scrollview.css" />
	<link rel="stylesheet" href="../../docs/_assets/css/jqm-docs.css"/>
    <style>
#evtCatcher {
	border: solid 1px black;
	background-color: #FF9;
	padding: 10px;	
	height: 300px;
}
#evtCatcher .ui-scrollview-view {
	padding: 10px;
}
	</style>
	<script src="../../js/jquery.js"></script>
	<script src="../../js/"></script>
	<script src="../../docs/lists/docs/docs.js"></script>
	<script src="jquery.easing.1.3.js"></script>
	<script src="jquery.mobile.scrollview.js"></script>
	<!-- script src="scrollview.js"></script -->
	<script>
$("[ data-role=page]").live("pageshow", function(event) {
	var $page = $(this);
	$page.find("[data-scroll]:not(.ui-scrollview-clip)").each(function(){
		var $this = $(this);
		// XXX: Remove this check for ui-scrolllistview once we've
		//      integrated list divider support into the main scrollview class.
		if ($this.hasClass("ui-scrolllistview"))
			$this.scrolllistview();
		else
		{
			var st = $this.data("scroll") + "";
			var paging = st && st.search(/^[xy]p$/) != -1;
			var dir = st && st.search(/^[xy]/) != -1 ? st.charAt(0) : null;

			var opts = {};
			if (dir)
				opts.direction = dir;
			if (paging)
				opts.pagingEnabled = true;

			$this.scrollview(opts);
		}
	});

	changeDelayFormElementClick();
});

function changeScrollMethod()
{
	var val = $("#s_method").val();
	var $sv = $("#evtCatcher").scrollview("scrollTo", 0, 0);
	if (val === "scroll") {
		$sv.css("overflow", "scroll");
	}
	else {
		$sv.css("overflow", "hidden");
	}
	$sv.data("scrollview").options.scrollMethod = val;
}

function changeDelayFormElementClick()
{
	$("#evtCatcher").data("scrollview").options.delayedClickEnabled = ($("#s_delay").val() === "yes");
}

var cb_hd_pd,
    cb_hd_sp,
    cb_hm_pd,
    cb_hm_sp,
    cb_hu_pd,
    cb_hu_sp;

var hd = $.mobile.scrollview.prototype._handleDragStart;
var hm = $.mobile.scrollview.prototype._handleDragMove;
var hu = $.mobile.scrollview.prototype._handleDragStop;

function getDummyEvent(o)
{
	return { target: o.target, _pd: false, _sp: false, preventDefault: function(){ this._pd = true; }, stopPropagation: function(){ this._sp = true; }};
}

function updateEvent(e, cb_pd, cb_sp)
{
	if (cb_pd.checked)
		e.preventDefault();
	if (cb_sp.checked)
		e.stopPropagation();
}

$.mobile.scrollview.prototype._handleDragStart = function(e,x,y)
{
	hd.call(this, getDummyEvent(e), x, y);
	updateEvent(e, cb_hd_pd, cb_hd_sp);
};

$.mobile.scrollview.prototype._handleDragMove = function(e,x,y)
{
	hm.call(this, getDummyEvent(e), x, y);
	updateEvent(e, cb_hm_pd, cb_hm_sp);
};

$.mobile.scrollview.prototype._handleDragStop = function(e)
{
	hu.call(this, getDummyEvent(e));
	updateEvent(e, cb_hu_pd, cb_hu_sp);
};

$(function(){
	cb_hd_pd = $("#cb_hd_pd")[0];
	cb_hd_sp = $("#cb_hd_sp")[0];
	cb_hm_pd = $("#cb_hm_pd")[0];
	cb_hm_sp = $("#cb_hm_sp")[0];
	cb_hu_pd = $("#cb_hu_pd")[0];
	cb_hu_sp = $("#cb_hu_sp")[0];
});
	</script>
	</head>
	<body>
<div data-role="page">
      <div data-role="header">
    <h1>Scroll View Events Test</h1>
  </div>
      <!-- /header -->
      
      <div data-role="content">
    <h3>Test</h3>
    <p>This page wraps the _handleDragStart, _handleDragMove, and _handleDragStop events of the scrollview widget so that the checkboxes below can determine how the native event is treated. You can use this page to figure out what events need to be caught and what special treatment is necessary to prevent native scrolling. You can also test the effect of that treatment on form elements within the sample scrollview.</p>
    <div data-role="fieldcontain">
        <label for="s_method" class="select">Scrolling Method:</label>
        <select name="s_method" id="s_method" onchange="changeScrollMethod();">
            <option value="translate" selected="selected">CSS3 Transform/Translate</option>
            <option value="position">CSS Top/Left Positioning</option>
            <option value="scroll">scrollTop/scrollLeft</option>
        </select>
    </div>

    <div data-role="fieldcontain">
        <label for="s_delay" class="select">Delay Form Element Click:</label>
        <select name="s_delay" id="s_delay" onchange="changeDelayFormElementClick();">
            <option value="yes">Yes</option>
            <option value="no" selected="selected">No</option>
        </select>
    </div>

    <div  data-role="fieldcontain">
          <fieldset data-role="controlgroup">
        <input type="checkbox" name="cb_hd_pd" id="cb_hd_pd" checked="checked" />
        <label for="cb_hd_pd">touchstart - Prevent Default</label>
        <input type="checkbox" name="cb_hd_sp" id="cb_hd_sp" checked="checked" />
        <label for="cb_hd_sp">touchstart - Stop Propagation</label>
        <input type="checkbox" name="cb_hm_pd" id="cb_hm_pd" checked="checked" />
        <label for="cb_hm_pd">touchmove - Prevent Default</label>
        <input type="checkbox" name="cb_hm_sp" id="cb_hm_sp" />
        <label for="cb_hm_sp">touchmove - Stop Propagation</label>
        <input type="checkbox" name="cb_hu_pd" id="cb_hu_pd" />
        <label for="cb_hu_pd">touchstop - Prevent Default</label>
        <input type="checkbox" name="cb_hu_sp" id="cb_hu_sp" />
        <label for="cb_hu_sp">touchstop - Stop Propagation</label>
      </fieldset>
        </div>
    <div id="evtCatcher" data-scroll="y">
<div  data-role="fieldcontain">
    <label for="tf1">Textfield</label>
    <input type="text" name="tf1" id="tf1" />
</div>
<div  data-role="fieldcontain">
    <label for="ta1">Textarea</label>
    <textarea name="ta1" id="ta1" rows="5" cols="10"></textarea>
</div>
<div  data-role="fieldcontain">
    <label for="ta1">Select</label>
    <select name="s1" id="s1">
    	<option value="1" selected="selected">Option 1</option>
    	<option value="2">Option 2</option>
    	<option value="3">Option 3</option>
    	<option value="4">Option 4</option>
    	<option value="5">Option 5</option>
    </select>
</div>
<div  data-role="fieldcontain">
    <label for="ta1">Button</label>
    <input type="button" name="b1" id="b1" value="Button" />
</div>
<div  data-role="fieldcontain">
          <fieldset data-role="controlgroup">
        <input type="checkbox" name="cb1" id="cb1" />
        <label for="cb1">Checkbox 1</label>
        <input type="checkbox" name="cb2" id="cb2" />
        <label for="cb2">Checkbox 2</label>
        </fieldset>
</div>

          <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui.Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
          <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui.Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
          <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui.Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
          <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui.Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
          <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui.Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
          <p>&nbsp;</p>
          <p></p>
        </div>
        <h3>Disabling Native Scrolling</h3>
        <p>In order to get faux scrolling to work, we need to prevent the native viewport scrolling from happening. Unfortunately the way you prevent this from happening differs on some mobile webkit platforms. Below is a table that shows what event needs to be caught, and what methods (preventDefault() and/or stopPropagation()) need to be called on that event to prevent native scrolling.<table border="1">
    	<tr><th>Device/OS</th><th>D-PD</th><th>D-SP</th><th>M-PD</th><th>M-SP</th><th>U-PD</th><th>U-SP</th></tr>
    	<tr><th>iOS 3.2</th><th></th><th></th>
    	<th>X</th><th></th><th></th><th></th></tr>
    	<tr><th>DroidX/Android 2.2</th>
    	<th>X</th><th></th><th></th><th></th><th></th><th></th></tr>
    	<tr><th>HTC Incredible/Android 2.1</th>
    	<th>X</th>
    	<th>X</th><th></th><th></th><th></th><th></th></tr>
    	<tr><th>BB Torch/OS 6</th><th></th><th></th>
    	<th>X</th>
    	<th></th><th></th><th></th></tr>
    </table>
<h4>Notes</h4>
<ul>
<li>The HTC Incredible seems to have a bug that triggers occassionally, where timers will be suspended until the viewport is scrolled.</li>
<li>On Android devices, calling preventDefault() on the touchstart event, prevents form elements from getting click events and focus.</li>
<li>On iOS, clicking and dragging within a form element (like textfield/textarea) will always cause the viewport to scroll, event if preventDefault() and stopPropagation() are called on both touchstart and touchmove events.</li>
</ul>
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui.Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui.Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui.Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui.Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui.Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
    <p>&nbsp;</p>
    <p></p>
  </div>
      <!-- /content --> 
    </div>
<!-- /page -->

</body>
</html>