mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-04-06 07:30:58 +00:00
Merge branch 'master' of github.com:jquery/jquery-mobile
This commit is contained in:
commit
2ec76dffe4
2 changed files with 71 additions and 57 deletions
|
|
@ -17,39 +17,9 @@ $.widget( "mobile.listview", $.mobile.widget, {
|
|||
},
|
||||
|
||||
_create: function() {
|
||||
var parentID = this.element.closest( ".ui-page" ).attr( "id" ),
|
||||
o = this.options;
|
||||
var o = this.options;
|
||||
|
||||
//if it's a nested list, chunk it into ui-page items, recurse through them and call listview on each individual ul
|
||||
$( this.element.find( "ul,ol" ).get().reverse() ).each(function( i ) {
|
||||
var list = $( this ),
|
||||
id = parentID + "&" + jQuery.mobile.subPageUrlKey + "=listview-" + i,
|
||||
parent = list.parent(),
|
||||
title = parent.contents()[ 0 ].nodeValue,
|
||||
theme = list.data( "theme" ) || o.theme,
|
||||
countTheme = list.data( "count-theme" ) || o.countTheme;
|
||||
|
||||
list.wrap( "<div class='ui-page'><div class='ui-content'></div></div>" )
|
||||
.parent()
|
||||
.before( "<div class='ui-header ui-bar-" + o.headerTheme + "'><h1>" +
|
||||
title + "</h1><a href='#' class='ui-back' data-icon='arrow-l'>Back</a></div>" )
|
||||
.parent()
|
||||
.attr({
|
||||
id: id,
|
||||
"data-theme": theme,
|
||||
"data-count-theme": countTheme
|
||||
})
|
||||
.appendTo( "body" )
|
||||
.fixHeaderFooter()
|
||||
.find( ".ui-header a.ui-back" )
|
||||
.buttonMarkup()
|
||||
.click(function() {
|
||||
history.go(-1);
|
||||
return false;
|
||||
});
|
||||
|
||||
parent.html( "<a href='#" + id + "'>" + title + "</a>" );
|
||||
}).listview();
|
||||
this._createSubPages();
|
||||
|
||||
//create listview markup
|
||||
this.element
|
||||
|
|
@ -146,23 +116,8 @@ $.widget( "mobile.listview", $.mobile.widget, {
|
|||
.end()
|
||||
.find( "p,ul,dl" )
|
||||
.addClass( "ui-li-desc" );
|
||||
|
||||
// JS fallback for auto-numbering for OL elements
|
||||
if( !$.support.cssPseudoElement && this.element.is('ol') ){
|
||||
var counter = 1;
|
||||
this.element.find('li').each(function(){
|
||||
if( $(this).is('.ui-li-grouping') ){
|
||||
//reset counter when a grouping heading is encountered
|
||||
counter = 1;
|
||||
}
|
||||
else {
|
||||
$(this)
|
||||
.find('.ui-link-inherit:first')
|
||||
.addClass('ui-li-jsnumbering')
|
||||
.prepend('<span class="ui-li-dec">' + counter++ + '. </span>');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this._numberItems();
|
||||
|
||||
//tapping the whole LI triggers ajaxClick on the first link
|
||||
this.element.find( "li:has(a)" ).live( "tap", function(event) {
|
||||
|
|
@ -171,6 +126,60 @@ $.widget( "mobile.listview", $.mobile.widget, {
|
|||
return false;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_createSubPages: function() {
|
||||
var parentId = this.element.closest( ".ui-page" ).attr( "id" ),
|
||||
o = this.options;
|
||||
$( this.element.find( "ul,ol" ).get().reverse() ).each(function( i ) {
|
||||
var list = $( this ),
|
||||
id = parentId + "&" + $.mobile.subPageUrlKey + "=listview-" + i,
|
||||
parent = list.parent(),
|
||||
title = parent.contents()[ 0 ].nodeValue,
|
||||
theme = list.data( "theme" ) || o.theme,
|
||||
countTheme = list.data( "count-theme" ) || o.countTheme;
|
||||
|
||||
list.wrap( "<div class='ui-page'><div class='ui-content'></div></div>" )
|
||||
.parent()
|
||||
.before( "<div class='ui-header ui-bar-" + o.headerTheme + "'><h1>" +
|
||||
title + "</h1><a href='#' class='ui-back' data-icon='arrow-l'>Back</a></div>" )
|
||||
.parent()
|
||||
.attr({
|
||||
id: id,
|
||||
"data-theme": theme,
|
||||
"data-count-theme": countTheme
|
||||
})
|
||||
.appendTo( "body" )
|
||||
.fixHeaderFooter()
|
||||
.find( ".ui-header a.ui-back" )
|
||||
.buttonMarkup()
|
||||
.click(function() {
|
||||
history.go(-1);
|
||||
return false;
|
||||
});
|
||||
|
||||
parent.html( "<a href='#" + id + "'>" + title + "</a>" );
|
||||
}).listview();
|
||||
},
|
||||
|
||||
// JS fallback for auto-numbering for OL elements
|
||||
_numberItems: function() {
|
||||
if ( $.support.cssPseudoElement || !this.element.is( "ol" ) ) {
|
||||
return;
|
||||
}
|
||||
var counter = 1;
|
||||
this.element.find( ".ui-li-dec" ).remove();
|
||||
this.element.find( "li:visible" ).each(function() {
|
||||
if( $( this ).is( ".ui-li-grouping" ) ) {
|
||||
//reset counter when a grouping heading is encountered
|
||||
counter = 1;
|
||||
} else {
|
||||
$( this )
|
||||
.find( ".ui-link-inherit:first" )
|
||||
.addClass( "ui-li-jsnumbering" )
|
||||
.prepend( "<span class='ui-li-dec'>" + (counter++) + ". </span>" );
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -3,26 +3,31 @@
|
|||
$.mobile.listview.prototype.options.filter = false;
|
||||
|
||||
$( ":mobile-listview" ).live( "listviewcreate", function() {
|
||||
var list = $( this );
|
||||
if ( !list.data( "listview" ).options.filter ) {
|
||||
var list = $( this ),
|
||||
listview = list.data( "listview" );
|
||||
if ( !listview.options.filter ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var wrapper = $( "<form>", { 'class': "ui-listview-filter ui-bar-c"} ),
|
||||
var wrapper = $( "<form>", { "class": "ui-listview-filter ui-bar-c" } ),
|
||||
|
||||
search = $( "<input>", { placeholder: "Filter results...", "data-type": "search" })
|
||||
.bind('keyup change', function() {
|
||||
var val = this.value;
|
||||
search = $( "<input>", {
|
||||
placeholder: "Filter results...",
|
||||
"data-type": "search"
|
||||
})
|
||||
.bind( "keyup change", function() {
|
||||
var val = this.value.toLowerCase();;
|
||||
list.children().show();
|
||||
if ( val ) {
|
||||
list.children().filter(function() {
|
||||
return $( this ).text().indexOf( val ) === -1;
|
||||
return $( this ).text().toLowerCase().indexOf( val ) === -1;
|
||||
}).hide();
|
||||
}
|
||||
|
||||
listview._numberItems();
|
||||
})
|
||||
.appendTo( wrapper )
|
||||
.customTextInput();
|
||||
|
||||
|
||||
wrapper.insertBefore( list );
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue