Created
March 2, 2014 14:13
-
-
Save babakhani/9307097 to your computer and use it in GitHub Desktop.
Convert English digit to Persian digit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Convert English Numbers to Persian in a web page | |
Behnam Emamian(www.BehnamEmamian.com) | |
*/ | |
String.prototype.toPersianDigit = function (a) { | |
return this.replace(/\d+/g, function (digit) { | |
var enDigitArr = [], peDigitArr = []; | |
for (var i = 0; i < digit.length; i++) { | |
enDigitArr.push(digit.charCodeAt(i)); | |
} | |
for (var j = 0; j < enDigitArr.length; j++) { | |
peDigitArr.push(String.fromCharCode(enDigitArr[j] + ((!!a && a == true) ? 1584 : 1728))); | |
} | |
return peDigitArr.join(''); | |
}); | |
}; | |
function TraceNodes(Node) { | |
if (Node.nodeType == 3) //TextNode | |
Node.nodeValue = Node.nodeValue.toPersianDigit(); | |
else | |
for (var i = 0; i < Node.childNodes.length; i++) | |
TraceNodes(Node.childNodes[i]); | |
} | |
TraceNodes(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment