2010-09-10 22:23:13 +00:00
|
|
|
/*
|
2010-11-10 00:55:52 +00:00
|
|
|
* jQuery Mobile Framework : "textinput" plugin for text inputs, textareas
|
2010-09-10 22:23:13 +00:00
|
|
|
* Copyright (c) jQuery Project
|
2010-11-20 03:47:47 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
|
* http://jquery.org/license
|
2010-09-10 22:23:13 +00:00
|
|
|
*/
|
2011-06-29 01:20:52 +00:00
|
|
|
|
|
|
|
|
(function( $, undefined ) {
|
|
|
|
|
|
This commit decouples all widgets from the page plugin so that they can be used ad-hoc.
- Internally, each plugin self-initializes by binding to the pagecreate event.
- Unit tests have been added and adjusted to support some internal changes involved in this commit.
- In the process, the portions of the page plugin that were used to enhance the header,content,and footer sections of a native-app style page layout are now located in jquery.mobile.page.sections.js.
- No public API options have changed, except that the page plugin no longer has options for keepNative, and degradeInputs, as plugins now handle these internally (keepNative was never documented, and degradeInputs only affected slider, so it lives there now. Page options related to the page sections are now located in the page.sections script, but they are still configurable via the page plugin's options api.
- Make, Ant, and index files are updated with a new load order for all JS files.
2011-07-19 23:05:35 +00:00
|
|
|
//auto self-init widgets
|
2011-07-26 18:22:08 +00:00
|
|
|
var initSelector = "input[type='text'], input[type='search'], :jqmData(type='search'), input[type='number'], :jqmData(type='number'), input[type='password'], input[type='email'], input[type='url'], input[type='tel'], textarea";
|
|
|
|
|
|
2011-07-22 13:05:55 +00:00
|
|
|
$( document ).bind( "pagecreate create", function( e ){
|
2011-07-26 18:22:08 +00:00
|
|
|
$( initSelector, e.target )
|
This commit decouples all widgets from the page plugin so that they can be used ad-hoc.
- Internally, each plugin self-initializes by binding to the pagecreate event.
- Unit tests have been added and adjusted to support some internal changes involved in this commit.
- In the process, the portions of the page plugin that were used to enhance the header,content,and footer sections of a native-app style page layout are now located in jquery.mobile.page.sections.js.
- No public API options have changed, except that the page plugin no longer has options for keepNative, and degradeInputs, as plugins now handle these internally (keepNative was never documented, and degradeInputs only affected slider, so it lives there now. Page options related to the page sections are now located in the page.sections script, but they are still configurable via the page plugin's options api.
- Make, Ant, and index files are updated with a new load order for all JS files.
2011-07-19 23:05:35 +00:00
|
|
|
.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
|
|
|
|
|
.textinput();
|
|
|
|
|
});
|
|
|
|
|
|
2010-11-05 01:32:13 +00:00
|
|
|
$.widget( "mobile.textinput", $.mobile.widget, {
|
|
|
|
|
options: {
|
2011-07-26 18:22:08 +00:00
|
|
|
theme: null,
|
|
|
|
|
initSelector: initSelector
|
2010-11-05 01:32:13 +00:00
|
|
|
},
|
2011-06-29 01:20:52 +00:00
|
|
|
|
|
|
|
|
_create: function() {
|
|
|
|
|
|
2010-11-05 01:32:13 +00:00
|
|
|
var input = this.element,
|
2010-11-05 01:59:03 +00:00
|
|
|
o = this.options,
|
|
|
|
|
theme = o.theme,
|
2011-06-29 01:20:52 +00:00
|
|
|
themedParent, themeclass, themeLetter, focusedEl, clearbtn;
|
|
|
|
|
|
2010-11-05 01:59:03 +00:00
|
|
|
if ( !theme ) {
|
2011-06-29 01:20:52 +00:00
|
|
|
themedParent = this.element.closest( "[class*='ui-bar-'],[class*='ui-body-']" );
|
|
|
|
|
themeLetter = themedParent.length && /ui-(bar|body)-([a-z])/.exec( themedParent.attr( "class" ) );
|
|
|
|
|
theme = themeLetter && themeLetter[2] || "c";
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-05 01:59:03 +00:00
|
|
|
themeclass = " ui-body-" + theme;
|
2011-06-29 01:20:52 +00:00
|
|
|
|
|
|
|
|
$( "label[for='" + input.attr( "id" ) + "']" ).addClass( "ui-input-text" );
|
|
|
|
|
|
|
|
|
|
input.addClass("ui-input-text ui-body-"+ o.theme );
|
|
|
|
|
|
|
|
|
|
focusedEl = input;
|
2011-07-20 16:59:20 +00:00
|
|
|
|
|
|
|
|
// XXX: Temporary workaround for issue 785. Turn off autocorrect and
|
|
|
|
|
// autocomplete since the popup they use can't be dismissed by
|
|
|
|
|
// the user. Note that we test for the presence of the feature
|
|
|
|
|
// by looking for the autocorrect property on the input element.
|
|
|
|
|
if ( typeof input[0].autocorrect !== "undefined" ) {
|
|
|
|
|
// Set the attribute instead of the property just in case there
|
|
|
|
|
// is code that attempts to make modifications via HTML.
|
|
|
|
|
input[0].setAttribute( "autocorrect", "off" );
|
|
|
|
|
input[0].setAttribute( "autocomplete", "off" );
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-29 01:20:52 +00:00
|
|
|
|
2010-10-06 03:54:51 +00:00
|
|
|
//"search" input widget
|
2011-06-29 01:20:52 +00:00
|
|
|
if ( input.is( "[type='search'],:jqmData(type='search')" ) ) {
|
|
|
|
|
|
|
|
|
|
focusedEl = input.wrap( "<div class='ui-input-search ui-shadow-inset ui-btn-corner-all ui-btn-shadow ui-icon-searchfield" + themeclass + "'></div>" ).parent();
|
|
|
|
|
clearbtn = $( "<a href='#' class='ui-input-clear' title='clear text'>clear text</a>" )
|
|
|
|
|
.tap(function( event ) {
|
|
|
|
|
input.val( "" ).focus();
|
|
|
|
|
input.trigger( "change" );
|
|
|
|
|
clearbtn.addClass( "ui-input-clear-hidden" );
|
|
|
|
|
event.preventDefault();
|
2010-10-06 03:54:51 +00:00
|
|
|
})
|
2011-06-29 01:20:52 +00:00
|
|
|
.appendTo( focusedEl )
|
|
|
|
|
.buttonMarkup({
|
|
|
|
|
icon: "delete",
|
|
|
|
|
iconpos: "notext",
|
|
|
|
|
corners: true,
|
|
|
|
|
shadow: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function toggleClear() {
|
|
|
|
|
if ( !input.val() ) {
|
|
|
|
|
clearbtn.addClass( "ui-input-clear-hidden" );
|
|
|
|
|
} else {
|
|
|
|
|
clearbtn.removeClass( "ui-input-clear-hidden" );
|
2010-10-06 03:54:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-06-29 01:20:52 +00:00
|
|
|
|
2010-10-06 03:54:51 +00:00
|
|
|
toggleClear();
|
2011-06-29 01:20:52 +00:00
|
|
|
|
|
|
|
|
input.keyup( toggleClear )
|
|
|
|
|
.focus( toggleClear );
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
input.addClass( "ui-corner-all ui-shadow-inset" + themeclass );
|
2010-09-19 22:34:50 +00:00
|
|
|
}
|
2011-06-29 01:20:52 +00:00
|
|
|
|
|
|
|
|
input.focus(function() {
|
|
|
|
|
focusedEl.addClass( "ui-focus" );
|
2010-09-10 22:23:13 +00:00
|
|
|
})
|
|
|
|
|
.blur(function(){
|
2011-06-29 01:20:52 +00:00
|
|
|
focusedEl.removeClass( "ui-focus" );
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Autogrow
|
|
|
|
|
if ( input.is( "textarea" ) ) {
|
2010-10-18 19:51:49 +00:00
|
|
|
var extraLineHeight = 15,
|
|
|
|
|
keyupTimeoutBuffer = 100,
|
|
|
|
|
keyup = function() {
|
2011-06-29 01:20:52 +00:00
|
|
|
var scrollHeight = input[ 0 ].scrollHeight,
|
|
|
|
|
clientHeight = input[ 0 ].clientHeight;
|
|
|
|
|
|
2010-10-18 19:51:49 +00:00
|
|
|
if ( clientHeight < scrollHeight ) {
|
2011-06-29 01:20:52 +00:00
|
|
|
input.css({
|
|
|
|
|
height: (scrollHeight + extraLineHeight)
|
|
|
|
|
});
|
2010-10-18 19:51:49 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
keyupTimeout;
|
2011-06-29 01:20:52 +00:00
|
|
|
|
2010-10-18 19:51:49 +00:00
|
|
|
input.keyup(function() {
|
|
|
|
|
clearTimeout( keyupTimeout );
|
|
|
|
|
keyupTimeout = setTimeout( keyup, keyupTimeoutBuffer );
|
|
|
|
|
});
|
|
|
|
|
}
|
2010-11-05 01:32:13 +00:00
|
|
|
},
|
2011-06-29 01:20:52 +00:00
|
|
|
|
2010-11-05 01:32:13 +00:00
|
|
|
disable: function(){
|
2011-06-29 01:20:52 +00:00
|
|
|
( this.element.attr( "disabled", true ).is( "[type='search'],:jqmData(type='search')" ) ?
|
|
|
|
|
this.element.parent() : this.element ).addClass( "ui-disabled" );
|
2010-11-05 01:32:13 +00:00
|
|
|
},
|
2011-06-29 01:20:52 +00:00
|
|
|
|
2010-11-05 01:32:13 +00:00
|
|
|
enable: function(){
|
2011-06-29 01:20:52 +00:00
|
|
|
( this.element.attr( "disabled", false).is( "[type='search'],:jqmData(type='search')" ) ?
|
|
|
|
|
this.element.parent() : this.element ).removeClass( "ui-disabled" );
|
2010-11-05 01:32:13 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})( jQuery );
|