Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Textinput: clear button not optional for Search.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspermdegroot committed Nov 20, 2012
1 parent 93651b4 commit 489262c
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions js/widgets/forms/textinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ $.widget( "mobile.textinput", $.mobile.widget, {
theme = o.theme || $.mobile.getInheritedTheme( this.element, "c" ),
themeclass = " ui-body-" + theme,
miniclass = o.mini ? " ui-mini" : "",
isSearch = input.is( "[type='search'], :jqmData(type='search')" ),
focusedEl,
clearbtn,
clearBtnText = o.clearSearchButtonText || o.clearBtnText;
Expand Down Expand Up @@ -58,20 +59,14 @@ $.widget( "mobile.textinput", $.mobile.widget, {
input[0].setAttribute( "autocomplete", "off" );
}

var searchNeedsIcon = input.is( "[type='search'], :jqmData(type='search')" ),
searchNeedsClearBtn = searchNeedsIcon && !input.is( ":jqmData(clear-btn='false')" ),
searchNeedsIconNoBtn = searchNeedsIcon && !searchNeedsClearBtn,
textNeedsClearBtn = input.is( "[type='text'], textarea" ) && !!o.clearBtn,
needsClearBtn = textNeedsClearBtn || ( searchNeedsIcon && searchNeedsClearBtn );

//"search" and "text" input widgets
if ( searchNeedsIcon ) {
if ( isSearch ) {
focusedEl = input.wrap( "<div class='ui-input-search ui-shadow-inset ui-btn-corner-all ui-btn-shadow ui-icon-searchfield" + themeclass + miniclass + "'></div>" ).parent();
} else if ( textNeedsClearBtn ) {
} else if ( !!o.clearBtn && !isSearch ) {
focusedEl = input.wrap( "<div class='ui-input-text ui-shadow-inset ui-corner-all ui-btn-shadow" + themeclass + miniclass + "'></div>" ).parent();
}

if( needsClearBtn ) {
if( !!o.clearBtn || isSearch ) {
clearbtn = $( "<a href='#' class='ui-input-clear' title='" + clearBtnText + "'>" + clearBtnText + "</a>" )
.bind( "click", function( event ) {
input
Expand All @@ -94,7 +89,7 @@ $.widget( "mobile.textinput", $.mobile.widget, {

input.bind( "paste cut keyup focus change blur", toggleClear );
}
else if( !searchNeedsIconNoBtn ) { //special case
else if( !o.clearBtn && !isSearch ) {
input.addClass( "ui-corner-all ui-shadow-inset" + themeclass + miniclass );
}

Expand Down

0 comments on commit 489262c

Please sign in to comment.