Permalink
Browse files

Merge branch 'master' of github.com:gseguin/jquery-mobile

  • Loading branch information...
2 parents ae7d62a + fc369ee commit b06b70b7afe298d8b8cae8eeb10a8b29b5e6f7aa Ghislain Seguin committed May 19, 2011
View
@@ -54,6 +54,16 @@
//error response message - appears when an Ajax page request fails
pageLoadErrorMessage: "Error Loading Page",
+ //configure meta viewport tag's content attr:
+ //note: this feature is deprecated in A4 in favor of adding
+ //the meta viewport element directly in the markup
+ metaViewportContent: "width=device-width, initial-scale=1",
+
+ //Keeps track of the number of lists per page UID
+ //This allows support for multiple nested list in the same page
+ //https://github.com/jquery/jquery-mobile/issues/1617
+ listCountPerPage: {},
+
//support conditions that must be met in order to proceed
//default enhanced qualifications are media query support OR IE 7+
gradeA: function(){
View
@@ -25,6 +25,11 @@
//add mobile, initial load "rendering" classes to docEl
$html.addClass( "ui-mobile ui-mobile-rendering" );
+ //define & prepend meta viewport tag, if content is defined
+ //NOTE: this is now deprecated. We recommend placing the meta viewport element in
+ //the markup from the start.
+ $.mobile.metaViewportContent && !$head.find( "meta[name='viewport']" ).length ? $( "<meta>", { name: "viewport", content: $.mobile.metaViewportContent}).prependTo( $head ) : undefined;
+
//loading div which appears during Ajax requests
//will not appear if $.mobile.loadingMessage is false
var $loader = $.mobile.loadingMessage ? $( "<div class='ui-loader ui-body-a ui-corner-all'>" + "<span class='ui-icon ui-icon-loading spin'></span>" + "<h1>" + $.mobile.loadingMessage + "</h1>" + "</div>" ) : undefined;
@@ -43,10 +43,16 @@ $.widget( "mobile.listview", $.mobile.widget, {
});
},
- _removeCorners: function( li ) {
+ _removeCorners: function( li, which ) {
+ which = which || ["top", "bottom"];
+ var classes = {
+ top: "ui-corner-top ui-corner-tr ui-corner-tl",
+ bottom: "ui-corner-bottom ui-corner-br ui-corner-bl"
+ };
+ var classesToRemove = $.map(which, function(pos) { return classes[pos];}).join(" ");
li
.add( li.find(".ui-btn-inner, .ui-li-link-alt, .ui-li-thumb") )
- .removeClass( "ui-corner-top ui-corner-bottom ui-corner-br ui-corner-bl ui-corner-tr ui-corner-tl" );
+ .removeClass( classesToRemove );
},
refresh: function( create ) {
@@ -163,7 +169,9 @@ $.widget( "mobile.listview", $.mobile.widget, {
if(item.prev().prev().length){
self._removeCorners( item.prev() );
- }
+ } else if (item.prev().length) {
+ self._removeCorners( item.prev(), ["bottom"]);
+ }
}
}
@@ -194,18 +202,25 @@ $.widget( "mobile.listview", $.mobile.widget, {
var parentList = this.element,
parentPage = parentList.closest( ".ui-page" ),
parentId = parentPage.jqmData( "url" ),
+ listCountPerPage = $.mobile.listCountPerPage,
+ listIdInPage,
o = this.options,
dns = "data-" + $.mobile.ns,
self = this,
persistentFooterID = parentPage.find( ":jqmData(role='footer')" ).jqmData( "id" );
+ if (typeof(listCountPerPage[parentPage[0][ $.expando ]]) === 'undefined') {
+ listCountPerPage[parentPage[0][ $.expando ]] = -1;
+ }
+ listIdInPage = ++listCountPerPage[parentPage[0][ $.expando ]];
+
$( parentList.find( "li>ul, li>ol" ).toArray().reverse() ).each(function( i ) {
var list = $( this ),
parent = list.parent(),
nodeEls = $( list.prevAll().toArray().reverse() ),
nodeEls = nodeEls.length ? nodeEls : $( "<span>" + $.trim(parent.contents()[ 0 ].nodeValue) + "</span>" ),
title = nodeEls.first().text(),//url limits to first 30 chars of text
- id = parentId + "&" + $.mobile.subPageUrlKey + "=" + self._idStringEscape(title + " " + i),
+ id = parentId + "&" + $.mobile.subPageUrlKey + "=" + self._idStringEscape(title + " " + listIdInPage + " " + i),
theme = list.jqmData( "theme" ) || o.theme,
countTheme = list.jqmData( "counttheme" ) || parentList.jqmData( "counttheme" ) || o.countTheme,
newPage = list.detach()
@@ -3,7 +3,9 @@
*/
(function($){
var mobilePage = undefined,
- libName = 'jquery.mobile.init.js',
+ mobileSelect = undefined,
+ metaViewportContentDefault = $.mobile.metaViewportContent,
+ libName = 'jquery.mobile.init.js',
coreLib = 'jquery.mobile.core.js',
extendFn = $.extend,
setGradeA = function(value) { $.mobile.gradeA = function(){ return value; }; },
@@ -37,13 +39,18 @@
// the event before the test check below
$(document).one("mobileinit", function(){
mobilePage = $.mobile.page;
+ mobileSelect = $.mobile.selectmenu;
});
// NOTE for the following two tests see index html for the binding
test( "mobile.page is available when mobile init is fired", function(){
ok(mobilePage !== undefined, "$.mobile.page is defined");
});
+ test( "mobile.selectmenu is available when mobile init is fired", function(){
+ ok(mobileSelect !== undefined, "$.mobile.selectmenu is defined");
+ });
+
$.testHelper.excludeFileProtocol(function(){
asyncTest( "loading the init library triggers mobilinit on the document", function(){
var initFired = false;
@@ -76,7 +83,32 @@
ok($("html").hasClass("ui-mobile"));
});
-
+ var findMeta = function(){
+ return $("head meta[name='viewport']");
+ },
+ setViewPortContent = function(){
+ $.testHelper.reloadLib( libName );
+ };
+
+ test( "meta viewport element not added to head when not defined on mobile", function(){
+ $.mobile.metaViewportContent = null;
+ findMeta().remove();
+ setViewPortContent();
+ same( findMeta().length, 0);
+ });
+
+ test( "meta viewport element is added to head when defined on mobile and no meta already exists", function(){
+ findMeta().remove();
+ setViewPortContent();
+ same( findMeta().length, 1);
+ });
+
+ test( "meta viewport element is not added to head when defined on mobile and a meta already exists", function(){
+ findMeta().remove();
+ $( '<meta name="viewport" content="width=device-width">').prependTo("head");
+ setViewPortContent();
+ same( findMeta().length, 1);
+ });
var findFirstPage = function() {
return $(":jqmData(role='page')").first();
@@ -223,5 +223,10 @@ <h2 id="qunit-userAgent"></h2>
</div>
</div>
+<!-- Programmatically generated list items !-->
+<div data-nstest-role="page" id="programmatically-generated-list">
+ <ul data-nstest-role="listview" data-nstest-inset="true" id="programmatically-generated-list-items"></ul>
+</div>
+
</body>
</html>
@@ -306,4 +306,37 @@
}, 1000);
});
+ module( "Programmatically generated list items", {
+ setup: function(){
+ var item,
+ data = [
+ {id: 1,
+ label: "Item 1"
+ },
+ {id: 2,
+ label: "Item 2"
+ },
+ {id: 3,
+ label: "Item 3"
+ },
+ {id: 4,
+ label: "Item 4"
+ }
+ ];
+
+ $.testHelper.openPage("#programmatically-generated-list");
+
+ for (var i = 0, len = data.length; i < len; i++) {
+ item = $('<li id="myItem' + data[i].id + '">');
+ label = $("<strong>" + data[i].label + "</strong>").appendTo(item);
+ $('#programmatically-generated-list-items').append(item);
+ $('#programmatically-generated-list-items').listview('refresh');
+ }
+ }
+ });
+
+ test( "Corner styling issue (#1470)", function() {
+ ok(!$('#programmatically-generated-list-items li:first-child').hasClass("ui-corner-bottom"), "First list item should not have class ui-corner-bottom");
+ });
+
})(jQuery);

0 comments on commit b06b70b

Please sign in to comment.