Skip to content

Instantly share code, notes, and snippets.

@unicornist
Last active August 29, 2015 14:04
Show Gist options
  • Save unicornist/35baed068db1dea8ea54 to your computer and use it in GitHub Desktop.
Save unicornist/35baed068db1dea8ea54 to your computer and use it in GitHub Desktop.
function setAutoDirection(jqueryNodeList, defaultDirection) {
jqueryNodeList.keyup(function (e) {
var val = e.target.value || e.target.placeholder;
e.target.dir = val ? ((val.charCodeAt(0) >= 0x0600 && val.charCodeAt(0) <= 0x06FF) ? "rtl" : "ltr") : defaultDirection || "rtl";
});
}
// ---------------- USAGE ---------------- //
setAutoDirection($("input[type=text]")); // default: "rtl"
setAutoDirection($("input[type=text]"), "ltr"); // default: "ltr"
@mirsaeedi
Copy link

Babak, you transformed the code very nicely 👍 Its very clean & short

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment