Skip to content

Instantly share code, notes, and snippets.

@farhadi
Created January 25, 2012 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farhadi/1675256 to your computer and use it in GitHub Desktop.
Save farhadi/1675256 to your computer and use it in GitHub Desktop.
jQuery plugin to automatically set direction on input/textarea fields.
(function($) {
$.fn.autodir = function() {
return this.each(function() {
$(this).on('keypress keyup change', function() {
$(this).css('direction', $(this).val().match(/^[^a-z]*[^\x00-\x7E]/ig) ? 'rtl' : 'ltr');
}).keyup();
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment