Skip to content

Instantly share code, notes, and snippets.

@babakhani
Last active February 6, 2020 12:20
Show Gist options
  • Save babakhani/91336a371808894ddf60 to your computer and use it in GitHub Desktop.
Save babakhani/91336a371808894ddf60 to your computer and use it in GitHub Desktop.
Check first char of input, if first char was persian char then set direction rtl to input.
app.directive('smartInputDirection', function () {
return {
restrict: "EA",
link: function ($scope, element, attrs) {
element.keyup(function () {
var thiVal = $(this).val().charAt(0)
, p = /^[\u0600-\u06FF\s]+$/;
if (p.test(thiVal)) {
element.css({
direction: 'rtl'
});
} else {
element.css({
direction: 'ltr'
});
}
});
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment