From 6152e8f51140e06104fba3bdb9af5a116764947d Mon Sep 17 00:00:00 2001 From: Bra1n Date: Mon, 7 Feb 2011 23:50:30 +0100 Subject: [PATCH 01/12] fixed page history direction search for duplicate entries --- js/jquery.mobile.navigation.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/jquery.mobile.navigation.js b/js/jquery.mobile.navigation.js index d688b6c6..48d07e58 100644 --- a/js/jquery.mobile.navigation.js +++ b/js/jquery.mobile.navigation.js @@ -287,6 +287,9 @@ // guess if it came from the history menu if( fromHashChange ){ + // determine new page index + var newActiveIndex = null; + // 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 @@ -297,10 +300,13 @@ //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 != null ? newActiveIndex : urlHistory.activeIndex ); + //if it's a back, use reverse animation if( back ){ reverse = true; From 86befdeaed73bea60754cc0f2b189208635eec82 Mon Sep 17 00:00:00 2001 From: John Bender Date: Fri, 25 Feb 2011 22:44:08 -0800 Subject: [PATCH 02/12] removed unused var/global from navigation --- js/jquery.mobile.navigation.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/jquery.mobile.navigation.js b/js/jquery.mobile.navigation.js index 48d07e58..6041ac67 100644 --- a/js/jquery.mobile.navigation.js +++ b/js/jquery.mobile.navigation.js @@ -294,7 +294,6 @@ $.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 From 20dce2ce4294c4036ed057902d7f02c3c3086b4a Mon Sep 17 00:00:00 2001 From: John Bender Date: Fri, 25 Feb 2011 23:20:56 -0800 Subject: [PATCH 03/12] small refactor to simplify newActiveIndex tracking --- js/jquery.mobile.navigation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/jquery.mobile.navigation.js b/js/jquery.mobile.navigation.js index 6041ac67..58b549a1 100644 --- a/js/jquery.mobile.navigation.js +++ b/js/jquery.mobile.navigation.js @@ -288,7 +288,7 @@ if( fromHashChange ){ // determine new page index - var newActiveIndex = null; + var newActiveIndex; // check if url is in history and if it's ahead or behind current page $.each( urlHistory.stack, function( i ){ @@ -304,7 +304,7 @@ }); // save new page index - urlHistory.activeIndex = ( newActiveIndex != null ? newActiveIndex : urlHistory.activeIndex ); + urlHistory.activeIndex = newActiveIndex ? newActiveIndex : urlHistory.activeIndex; //if it's a back, use reverse animation if( back ){ From 86eceb03fc0e02644d542e702d915cffee087426 Mon Sep 17 00:00:00 2001 From: John Bender Date: Fri, 25 Feb 2011 23:22:05 -0800 Subject: [PATCH 04/12] added two helpers and tests for proper url stack history traversal --- tests/jquery.testHelper.js | 10 ++++++++++ tests/unit/listview/.#listview_core.js | 1 + tests/unit/navigation/index.html | 18 ++++++++++++++++++ tests/unit/navigation/navigation_core.js | 16 ++++++++++++++++ 4 files changed, 45 insertions(+) create mode 120000 tests/unit/listview/.#listview_core.js diff --git a/tests/jquery.testHelper.js b/tests/jquery.testHelper.js index b1d94bad..244de4e1 100644 --- a/tests/jquery.testHelper.js +++ b/tests/jquery.testHelper.js @@ -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); \ No newline at end of file diff --git a/tests/unit/listview/.#listview_core.js b/tests/unit/listview/.#listview_core.js new file mode 120000 index 00000000..a59dd872 --- /dev/null +++ b/tests/unit/listview/.#listview_core.js @@ -0,0 +1 @@ +johnbender@john-benders-macbook-pro.local.504 \ No newline at end of file diff --git a/tests/unit/navigation/index.html b/tests/unit/navigation/index.html index 44f9a100..f12cb6d4 100644 --- a/tests/unit/navigation/index.html +++ b/tests/unit/navigation/index.html @@ -94,5 +94,23 @@
+ + + + +
+
+

Dialog

+
+
diff --git a/tests/unit/navigation/navigation_core.js b/tests/unit/navigation/navigation_core.js index 84defe33..e8257ff5 100644 --- a/tests/unit/navigation/navigation_core.js +++ b/tests/unit/navigation/navigation_core.js @@ -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); From 598668a2a1b7889f951c8a00724fa0ddff1287dc Mon Sep 17 00:00:00 2001 From: John Bender Date: Sat, 26 Feb 2011 01:15:04 -0800 Subject: [PATCH 05/12] removed spurious file --- tests/unit/listview/.#listview_core.js | 1 - 1 file changed, 1 deletion(-) delete mode 120000 tests/unit/listview/.#listview_core.js diff --git a/tests/unit/listview/.#listview_core.js b/tests/unit/listview/.#listview_core.js deleted file mode 120000 index a59dd872..00000000 --- a/tests/unit/listview/.#listview_core.js +++ /dev/null @@ -1 +0,0 @@ -johnbender@john-benders-macbook-pro.local.504 \ No newline at end of file From c828cf1f64139585005df467945adff2c9ede2e8 Mon Sep 17 00:00:00 2001 From: Bra1n Date: Sat, 26 Feb 2011 23:25:07 -0800 Subject: [PATCH 06/12] prevent setting the data url on pages where it is already set --- js/jquery.mobile.init.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/js/jquery.mobile.init.js b/js/jquery.mobile.init.js index 500f52b5..619f9e04 100644 --- a/js/jquery.mobile.init.js +++ b/js/jquery.mobile.init.js @@ -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) From b246fb48faa62b43c900a3390b7e870f95c51e98 Mon Sep 17 00:00:00 2001 From: John Bender Date: Sat, 26 Feb 2011 23:27:41 -0800 Subject: [PATCH 07/12] tests for data url init default --- tests/unit/init/index.html | 5 ++++- tests/unit/init/init_core.js | 11 +++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/unit/init/index.html b/tests/unit/init/index.html index 27001694..eab3e057 100644 --- a/tests/unit/init/index.html +++ b/tests/unit/init/index.html @@ -25,7 +25,10 @@
-
+
+
+ +
diff --git a/tests/unit/init/init_core.js b/tests/unit/init/init_core.js index 4af57e19..f1312af3 100644 --- a/tests/unit/init/init_core.js +++ b/tests/unit/init/init_core.js @@ -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); From 2abdbf3416d3545db1a56437f9846aafb8e86cf7 Mon Sep 17 00:00:00 2001 From: John Bender Date: Sat, 26 Feb 2011 23:29:14 -0800 Subject: [PATCH 08/12] white space in the init core test --- tests/unit/init/init_core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/init/init_core.js b/tests/unit/init/init_core.js index f1312af3..e7bfd09f 100644 --- a/tests/unit/init/init_core.js +++ b/tests/unit/init/init_core.js @@ -128,5 +128,5 @@ test( "pages with a data-url attribute are left with the original value", function(){ same($("#bar").data('url'), "bak"); }); -}); + }); })(jQuery); From 2bb94172cf637ddb685e55da40f1104e28d7ca13 Mon Sep 17 00:00:00 2001 From: Martin Kou Date: Fri, 11 Feb 2011 10:26:37 -0800 Subject: [PATCH 09/12] Fixed checkboxradio disable issue. --- js/jquery.mobile.forms.checkboxradio.js | 5 ++ .../unit/checkboxradio/checkboxradio_core.js | 27 ++++++++ tests/unit/checkboxradio/index.html | 61 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 tests/unit/checkboxradio/checkboxradio_core.js create mode 100644 tests/unit/checkboxradio/index.html diff --git a/js/jquery.mobile.forms.checkboxradio.js b/js/jquery.mobile.forms.checkboxradio.js index 61d37588..dcf4831b 100644 --- a/js/jquery.mobile.forms.checkboxradio.js +++ b/js/jquery.mobile.forms.checkboxradio.js @@ -55,6 +55,11 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, { }, "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"); diff --git a/tests/unit/checkboxradio/checkboxradio_core.js b/tests/unit/checkboxradio/checkboxradio_core.js new file mode 100644 index 00000000..222b70d1 --- /dev/null +++ b/tests/unit/checkboxradio/checkboxradio_core.js @@ -0,0 +1,27 @@ +/* + * mobile page unit tests + */ +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"); +}); diff --git a/tests/unit/checkboxradio/index.html b/tests/unit/checkboxradio/index.html new file mode 100644 index 00000000..4226db16 --- /dev/null +++ b/tests/unit/checkboxradio/index.html @@ -0,0 +1,61 @@ + + + + + jQuery Mobile Page Test Suite + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

jQuery Mobile Page Test Suite

+

+

+
    +
+ +
+
+
+
+
+ Agree to the terms: + + +
+
+
+
+ + From 58b16a94b6f212ead8771a83a29973d02683792f Mon Sep 17 00:00:00 2001 From: John Bender Date: Sat, 26 Feb 2011 23:59:17 -0800 Subject: [PATCH 10/12] small refactor to disable check for checkbox radio --- js/jquery.mobile.forms.checkboxradio.js | 52 ++++++++++++------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/js/jquery.mobile.forms.checkboxradio.js b/js/jquery.mobile.forms.checkboxradio.js index dcf4831b..18d14d98 100644 --- a/js/jquery.mobile.forms.checkboxradio.js +++ b/js/jquery.mobile.forms.checkboxradio.js @@ -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( "
" ); - + 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,13 +53,13 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, { label.data("movestart", [ parseFloat( oe.pageX ), parseFloat( oe.pageY ) ]); } }, - + "touchend mouseup": function( event ){ - if ( input.is( ":disabled" ) ) - { + 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"); @@ -74,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"); @@ -123,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" ) + "']"), @@ -131,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(); } @@ -150,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"); } From 09f571986525dd353a80d9f205fb8969cf37edff Mon Sep 17 00:00:00 2001 From: John Bender Date: Sun, 27 Feb 2011 00:00:14 -0800 Subject: [PATCH 11/12] moved checkbox tests under immediate function and simplified fixture html --- .../unit/checkboxradio/checkboxradio_core.js | 44 ++++++++++--------- tests/unit/checkboxradio/index.html | 26 +---------- 2 files changed, 24 insertions(+), 46 deletions(-) diff --git a/tests/unit/checkboxradio/checkboxradio_core.js b/tests/unit/checkboxradio/checkboxradio_core.js index 222b70d1..490c55c7 100644 --- a/tests/unit/checkboxradio/checkboxradio_core.js +++ b/tests/unit/checkboxradio/checkboxradio_core.js @@ -1,27 +1,29 @@ /* * mobile page unit tests */ -module('jquery.mobile.forms.checkboxradio.js'); +(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"); + 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"); + 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"); -}); + 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); \ No newline at end of file diff --git a/tests/unit/checkboxradio/index.html b/tests/unit/checkboxradio/index.html index 4226db16..3117aa6e 100644 --- a/tests/unit/checkboxradio/index.html +++ b/tests/unit/checkboxradio/index.html @@ -5,33 +5,9 @@ jQuery Mobile Page Test Suite - - - - - - - - - - - - - - - - - - - - - - - - + - From df21c701b520f8d4dc79971b97681c6f07ccbe3b Mon Sep 17 00:00:00 2001 From: Martin Kou Date: Fri, 11 Feb 2011 10:21:00 -0800 Subject: [PATCH 12/12] Fixed animationComplete return value bug. --- js/jquery.mobile.navigation.js | 1 + tests/unit/navigation/navigation_transitions.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/js/jquery.mobile.navigation.js b/js/jquery.mobile.navigation.js index 58b549a1..323866b0 100644 --- a/js/jquery.mobile.navigation.js +++ b/js/jquery.mobile.navigation.js @@ -225,6 +225,7 @@ else{ // defer execution for consistency between webkit/non webkit setTimeout(callback, 0); + return $(this); } }; diff --git a/tests/unit/navigation/navigation_transitions.js b/tests/unit/navigation/navigation_transitions.js index 65179d0e..73a4cd82 100644 --- a/tests/unit/navigation/navigation_transitions.js +++ b/tests/unit/navigation/navigation_transitions.js @@ -146,4 +146,9 @@ start(); }, 900); }); + + test( "animationComplete return value", function(){ + $.fn.animationComplete = animationCompleteFn; + equals($("#foo").animationComplete(function(){})[0], $("#foo")[0]); + }); })(jQuery);