Merge branch 'master' into fastclick

This commit is contained in:
Kin Blas 2011-02-28 09:41:40 -08:00
commit b8c73e2599
11 changed files with 170 additions and 29 deletions

View file

@ -3,7 +3,7 @@
* Copyright (c) jQuery Project
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*/
*/
(function($, undefined ) {
$.widget( "mobile.checkboxradio", $.mobile.widget, {
options: {
@ -30,17 +30,17 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
icon: this.element.parents( "[data-type='horizontal']" ).length ? undefined : uncheckedicon,
shadow: false
});
// wrap the input + label in a div
// wrap the input + label in a div
input
.add( label )
.wrapAll( "<div class='ui-" + inputtype +"'></div>" );
label.bind({
mouseover: function() {
if( $(this).parent().is('.ui-disabled') ){ return false; }
},
"touchmove": function( event ){
var oe = event.originalEvent.touches[0];
if( label.data("movestart") ){
@ -53,8 +53,13 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
label.data("movestart", [ parseFloat( oe.pageX ), parseFloat( oe.pageY ) ]);
}
},
"touchend mouseup": function( event ){
if ( input.is( ":disabled" ) ){
event.preventDefault();
return;
}
label.removeData("movestart");
if( label.data("etype") && label.data("etype") !== event.type || label.data("moved") ){
label.removeData("etype").removeData("moved");
@ -69,46 +74,46 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
self._updateAll();
event.preventDefault();
},
click: false
});
input
.bind({
mousedown: function(){
this._cacheVals();
},
click: function(){
self._updateAll();
},
focus: function() {
label.addClass( "ui-focus" );
focus: function() {
label.addClass( "ui-focus" );
},
blur: function() {
label.removeClass( "ui-focus" );
}
});
this.refresh();
},
_cacheVals: function(){
this._getInputSet().each(function(){
$(this).data("cacheVal", $(this).is(":checked") );
});
});
},
//returns either a set of radios with the same name attribute, or a single checkbox
_getInputSet: function(){
return this.element.closest( "form,fieldset,[data-role='page']" )
.find( "input[name='"+ this.element.attr( "name" ) +"'][type='"+ this.element.attr( "type" ) +"']" );
},
_updateAll: function(){
this._getInputSet().each(function(){
var dVal = $(this).data("cacheVal");
@ -118,7 +123,7 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
})
.checkboxradio( "refresh" );
},
refresh: function( ){
var input = this.element,
label = input.closest("form,fieldset,[data-role='page']").find("label[for='" + input.attr( "id" ) + "']"),
@ -126,18 +131,18 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
icon = label.find( ".ui-icon" ),
checkedicon = "ui-icon-" + inputtype + "-on",
uncheckedicon = "ui-icon-" + inputtype + "-off";
if ( input[0].checked ) {
label.addClass( "ui-btn-active" );
icon.addClass( checkedicon );
icon.removeClass( uncheckedicon );
} else {
label.removeClass( "ui-btn-active" );
label.removeClass( "ui-btn-active" );
icon.removeClass( checkedicon );
icon.addClass( uncheckedicon );
}
if( input.is( ":disabled" ) ){
this.disable();
}
@ -145,11 +150,11 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
this.enable();
}
},
disable: function(){
this.element.attr("disabled",true).parent().addClass("ui-disabled");
},
enable: function(){
this.element.attr("disabled",false).parent().removeClass("ui-disabled");
}

View file

@ -20,7 +20,12 @@
//add dialogs, set data-url attrs
$pages.add( "[data-role='dialog']" ).each(function(){
$(this).attr( "data-url", $(this).attr( "id" ));
var $this = $(this);
// unless the data url is already set set it to the id
if( !$this.data('url') ){
$this.attr( "data-url", $this.attr( "id" ) );
}
});
//define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback)

View file

@ -225,6 +225,7 @@
else{
// defer execution for consistency between webkit/non webkit
setTimeout(callback, 0);
return $(this);
}
};
@ -287,20 +288,25 @@
// guess if it came from the history menu
if( fromHashChange ){
// determine new page index
var newActiveIndex;
// check if url is in history and if it's ahead or behind current page
$.each( urlHistory.stack, function( i ){
//if the url is in the stack, it's a forward or a back
if( this.url === url ){
urlIndex = i;
//define back and forward by whether url is older or newer than current page
back = i < urlHistory.activeIndex;
//forward set to opposite of back
forward = !back;
//reset activeIndex to this one
urlHistory.activeIndex = i;
newActiveIndex = i;
}
});
// save new page index
urlHistory.activeIndex = newActiveIndex ? newActiveIndex : urlHistory.activeIndex;
//if it's a back, use reverse animation
if( back ){
reverse = true;

View file

@ -53,6 +53,16 @@
} else {
setTimeout($.testHelper.hideActivePageWhenComplete, 500);
}
},
openPage: function(hash){
location.href = location.href.split('#')[0] + hash;
},
sequence: function(fns, interval){
$.each(fns, function(i, fn){
setTimeout(fn, i * interval);
});
}
};
})(jQuery);

View file

@ -0,0 +1,29 @@
/*
* mobile page unit tests
*/
(function($){
module('jquery.mobile.forms.checkboxradio.js');
test( "widget can be disabled and enabled", function(){
var input = $("#checkbox-1");
var button = input.parent().find(".ui-btn");
input.checkboxradio("disable");
input.checkboxradio("enable");
ok(!input.attr("disabled"), "start input as enabled");
ok(!input.parent().hasClass("ui-disabled"), "no disabled styles");
ok(!input.attr("checked"), "not checked before click");
button.trigger("mouseup");
ok(input.attr("checked"), "checked after click");
ok(button.hasClass("ui-btn-active"), "active styles after click");
button.trigger("mouseup");
input.checkboxradio("disable");
ok(input.attr("disabled"), "input disabled");
ok(input.parent().hasClass("ui-disabled"), "disabled styles");
ok(!input.attr("checked"), "not checked before click");
button.trigger("mouseup");
ok(!input.attr("checked"), "not checked after click");
ok(!button.hasClass("ui-btn-active"), "no active styles after click");
});
})(jQuery);

View file

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>jQuery Mobile Page Test Suite</title>
<script type="text/javascript" src="../../../js/jquery.js"></script>
<script type="text/javascript" src="../../../js/"></script>
<script type="text/javascript" src="../../../tests/jquery.testHelper.js"></script>
<link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/>
<script type="text/javascript" src="../../../external/qunit.js"></script>
<script type="text/javascript" src="checkboxradio_core.js"></script>
</head>
<body>
<h1 id="qunit-header">jQuery Mobile Page Test Suite</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests">
</ol>
<div id="qunit-fixture">
<div data-role="page">
<div data-role="content">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<legend>Agree to the terms:</legend>
<input type="checkbox" name="checkbox-1" id="checkbox-1" class="custom" />
<label for="checkbox-1">I agree</label>
</fieldset>
</div>
</div>
</div>
</body>
</html>

View file

@ -25,7 +25,10 @@
<ol id="qunit-tests">
</ol>
<div data-role="page">
<div data-role="page" id="foo">
</div>
<div data-role="page" id="bar" data-url="bak">
</div>
</body>

View file

@ -1,7 +1,6 @@
/*
* mobile init tests
*/
(function($){
var mobilePage = undefined, mobileSelect = undefined,
libName = 'jquery.mobile.init.js',
@ -121,5 +120,13 @@
stop();
$.testHelper.reloadLib(libName);
});
test( "pages without a data-url attribute have it set to their id", function(){
same($("#foo").data('url'), "foo");
});
test( "pages with a data-url attribute are left with the original value", function(){
same($("#bar").data('url'), "bak");
});
});
})(jQuery);

View file

@ -94,5 +94,23 @@
<div id="no-trans-dialog" data-role="page">
</div>
<div id="dup-history-first" data-role="page">
<a href="#dup-history-second" data-transition="slideup" data-role="button" >
Page 2
</a>
</div>
<div id="dup-history-second" data-role="page">
<a href="#dup-history-first" data-transition="slideup" data-role="button">
Page 1
</a>
<a href="#dup-history-dialog" data-role="button" data-transition="pop" data-rel="dialog">Dialog</a>
</div>
<div id="dup-history-dialog" data-role="dialog">
<div data-role="header" data-position="inline">
<h1>Dialog</h1>
</div>
</div>
</body>
</html>

View file

@ -228,5 +228,21 @@
test( "data url works when role and url are reversed on the page element", function(){
testDataUrlHash("#reverse-attr-data-url a", /^#foo\/bar\/reverse.html$/);
});
asyncTest( "last entry choosen amongst multiple identical url history stack entries on hash change", function(){
$.testHelper.openPage("#dup-history-first");
$.testHelper.sequence([
function(){ $("#dup-history-first a").click(); },
function(){ $("#dup-history-second a:first").click(); },
function(){ $("#dup-history-first a").click(); },
function(){ $("#dup-history-second a:last").click(); },
function(){ $("#dup-history-dialog .ui-icon-delete").click(); },
function(){
// third page because the first opened page is manual hash manip
same($.mobile.urlHistory.activeIndex, 3, "should be the third page in the stack");
start();
}], 1000);
});
})(jQuery);

View file

@ -146,4 +146,9 @@
start();
}, 900);
});
test( "animationComplete return value", function(){
$.fn.animationComplete = animationCompleteFn;
equals($("#foo").animationComplete(function(){})[0], $("#foo")[0]);
});
})(jQuery);