/* * 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('[type="search"],[data-type="search"]'), theme: input.data("theme") || "c" }, options); $('label[for='+input.attr('id')+']').addClass('ui-input-text'); input.addClass('ui-input-text ui-body-'+ o.theme); 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('').focus(); input.trigger('change'); clearbtn.addClass('ui-input-clear-hidden'); 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-shadow-inset'); } input .focus(function(){ focusedEl.addClass('ui-focus'); }) .blur(function(){ focusedEl.removeClass('ui-focus'); }); //autogrow if ( input.is('textarea') ) { var extraLineHeight = 15, keyupTimeoutBuffer = 100, keyup = function() { var scrollHeight = input[0].scrollHeight, clientHeight = input[0].clientHeight; if ( clientHeight < scrollHeight ) { input.css({ height: (scrollHeight + extraLineHeight) }); } }, keyupTimeout; input.keyup(function() { clearTimeout( keyupTimeout ); keyupTimeout = setTimeout( keyup, keyupTimeoutBuffer ); }); } }); }; })(jQuery);