SayeyeZohor Posted November 28, 2019 Share Posted November 28, 2019 hi how to add javascript code in onload page with unigui? <script> $(document).ready(function () { ConvertNumberToPersion(); }); function ConvertNumberToPersion() { persian = { 0: '۰', 1: '۱', 2: '۲', 3: '۳', 4: '۴', 5: '۵', 6: '۶', 7: '۷', 8: '۸', 9: '۹' }; function traverse(el) { if (el.nodeType == 3) { var list = el.data.match(/[0-9]/g); if (list != null && list.length != 0) { for (var i = 0; i < list.length; i++) el.data = el.data.replace(list[i], persian[list[i]]); } } for (var i = 0; i < el.childNodes.length; i++) { traverse(el.childNodes[i]); } } traverse(document.body); } </script> Link to comment Share on other sites More sharing options...
Sherzod Posted November 28, 2019 Share Posted November 28, 2019 24 minutes ago, SayeyeZohor said: how to add javascript code in onload page with unigui? Hi, Once again in brief, what do you want to achieve? Link to comment Share on other sites More sharing options...
SayeyeZohor Posted November 28, 2019 Author Share Posted November 28, 2019 10 hours ago, Sherzod said: Hi, Once again in brief, what do you want to achieve? hi, i want to Convert all of numbers in html to persian number sample: 2: '۲' and use this script in onload webpage <script> $(document).ready(function () { ConvertNumberToPersion(); }); function ConvertNumberToPersion() { persian = { 0: '۰', 1: '۱', 2: '۲', 3: '۳', 4: '۴', 5: '۵', 6: '۶', 7: '۷', 8: '۸', 9: '۹' }; function traverse(el) { if (el.nodeType == 3) { var list = el.data.match(/[0-9]/g); if (list != null && list.length != 0) { for (var i = 0; i < list.length; i++) el.data = el.data.replace(list[i], persian[list[i]]); } } for (var i = 0; i < el.childNodes.length; i++) { traverse(el.childNodes[i]); } } traverse(document.body); } </script> @Sherzod Link to comment Share on other sites More sharing options...
Sherzod Posted November 28, 2019 Share Posted November 28, 2019 Ok, I will try to analyze this. Link to comment Share on other sites More sharing options...
SayeyeZohor Posted November 28, 2019 Author Share Posted November 28, 2019 1 hour ago, Sherzod said: Ok, I will try to analyze this. tnx Link to comment Share on other sites More sharing options...
Sherzod Posted November 29, 2019 Share Posted November 29, 2019 9 hours ago, SayeyeZohor said: i want to Convert all of numbers in html to persian number Hello, Sorry, Can you make a specific example for your case? Link to comment Share on other sites More sharing options...
SayeyeZohor Posted November 29, 2019 Author Share Posted November 29, 2019 6 hours ago, Sherzod said: Hello, Sorry, Can you make a specific example for your case? Sample.rar Link to comment Share on other sites More sharing options...
Sherzod Posted November 29, 2019 Share Posted November 29, 2019 26 minutes ago, SayeyeZohor said: Sample.rar OK, try to use like this: function window.afterrender(sender, eOpts) { Ext.onReady(function() { ConvertNumberToPersion(); }); function ConvertNumberToPersion() { persian = { 0: '۰', 1: '۱', 2: '۲', 3: '۳', 4: '۴', 5: '۵', 6: '۶', 7: '۷', 8: '۸', 9: '۹' }; function traverse(el) { if (el.nodeType == 3) { var list = el.data.match(/[0-9]/g); if (list != null && list.length != 0) { for (var i = 0; i < list.length; i++) el.data = el.data.replace(list[i], persian[list[i]]); } } for (var i = 0; i < el.childNodes.length; i++) { traverse(el.childNodes[i]); } } traverse(document.body); } } Link to comment Share on other sites More sharing options...
SayeyeZohor Posted November 29, 2019 Author Share Posted November 29, 2019 10 minutes ago, Sherzod said: OK, try to use like this: function window.afterrender(sender, eOpts) { Ext.onReady(function() { ConvertNumberToPersion(); }); function ConvertNumberToPersion() { persian = { 0: '۰', 1: '۱', 2: '۲', 3: '۳', 4: '۴', 5: '۵', 6: '۶', 7: '۷', 8: '۸', 9: '۹' }; function traverse(el) { if (el.nodeType == 3) { var list = el.data.match(/[0-9]/g); if (list != null && list.length != 0) { for (var i = 0; i < list.length; i++) el.data = el.data.replace(list[i], persian[list[i]]); } } for (var i = 0; i < el.childNodes.length; i++) { traverse(el.childNodes[i]); } } traverse(document.body); } } hi are you test this code? working? Link to comment Share on other sites More sharing options...
Sherzod Posted November 29, 2019 Share Posted November 29, 2019 1 minute ago, SayeyeZohor said: hi are you test this code? working? On your demo testcase, yes, it works. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now