/* * jQuery Mobile Framework : "customTextInput" plugin for text inputs, textareas (based on code from Filament Group,Inc) * Copyright (c) jQuery Project * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses. * Note: Code is in draft form and is subject to change */ (function($){ jQuery.fn.customTextInput = function(options){ return $(this).each(function(){ var input = $(this); var o = $.extend({ search: input.is('[data-role="search"]') //defaultTheme: "a" }, options); $('label[for='+input.attr('id')+']').addClass('ui-input-text'); input.addClass('ui-input-text'); var focusedEl = input; //"search" input widget if(o.search){ focusedEl = input.wrap('
').parent(); var clearbtn = $('clear text') .buttonMarkup({icon: 'delete', iconpos: 'notext', corners:true, shadow:true}) .click(function(){ input.val(''); toggleClear(); return false; }) .appendTo(focusedEl); function toggleClear(){ if(input.val() == ''){ clearbtn.addClass('ui-input-clear-hidden'); } else{ clearbtn.removeClass('ui-input-clear-hidden'); } } toggleClear(); input.keyup(toggleClear); } else{ input.addClass('ui-corner-all ui-body-c'); } input .focus(function(){ focusedEl.addClass('ui-focus'); }) .blur(function(){ focusedEl.removeClass('ui-focus'); }); //autogrow if(input.is('textarea')){ input.keydown(function(){ if( input[0].offsetHeight < input[0].scrollHeight ){ input.css({height: input[0].scrollHeight + 10 }); } }) } }); }; })(jQuery);