BidiSupport.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. define("dojox/charting/widget/BidiSupport", ["dojo/dom", "dojo/_base/lang", "dojo/_base/html", "dojo/_base/array", "dojo/_base/connect", "dojo/query",
  2. "dijit/_BidiSupport", "../BidiSupport", "dijit/registry", "./Chart", "./Legend"],
  3. function(dom, lang, html, arrayUtil, hub, query, dBidi, cBidi, widgetManager, Chart, Legend){
  4. // patch only if present
  5. if( Legend ){
  6. lang.extend(Legend, {
  7. // summary:
  8. // Add support for bidi scripts in legend.
  9. // description:
  10. // Since dojox.charting.widget.Legend inherits from _Widget use the bidi support
  11. // that introduced there.
  12. postMixInProperties: function(){
  13. // summary:
  14. // Connect the setter of textDir legend to setTextDir of the chart,
  15. // so _setTextDirAttr of the legend will be called after setTextDir of the chart is called.
  16. // tags:
  17. // private
  18. // find the chart that is the owner of this legend, use it's
  19. // textDir
  20. if(!this.chart){
  21. if(!this.chartRef){ return; }
  22. var chart = widgetManager.byId(this.chartRef);
  23. if(!chart){
  24. var node = dom.byId(this.chartRef);
  25. if(node){
  26. chart = widgetManager.byNode(node);
  27. }else{
  28. return;
  29. }
  30. }
  31. this.textDir = chart.chart.textDir;
  32. hub.connect(chart.chart, "setTextDir", this, "_setTextDirAttr");
  33. }else{
  34. this.textDir = this.chart.textDir;
  35. hub.connect(this.chart, "setTextDir", this, "_setTextDirAttr");
  36. }
  37. },
  38. _setTextDirAttr: function(/*String*/ textDir){
  39. // summary:
  40. // Setter for textDir.
  41. // description:
  42. // Users shouldn't call this function; they should be calling
  43. // set('textDir', value)
  44. // tags:
  45. // private
  46. // only if new textDir is different from the old one
  47. if(validateTextDir(textDir) != null){
  48. if(this.textDir != textDir){
  49. this._set("textDir", textDir);
  50. // get array of all the labels
  51. var legendLabels = query(".dojoxLegendText", this._tr);
  52. // for every label calculate it's new dir.
  53. arrayUtil.forEach(legendLabels, function(label){
  54. label.dir = this.getTextDir(label.innerHTML, label.dir);
  55. }, this);
  56. }
  57. }
  58. }
  59. });
  60. }
  61. // patch only if present
  62. if( Chart ){
  63. lang.extend( Chart ,{
  64. postMixInProperties: function(){
  65. // set initial textDir of the chart, if passed in the creation use that value
  66. // else use default value, following the GUI direction, this.chart doesn't exist yet
  67. // so can't use set("textDir", textDir). This passed to this.chart in it's future creation.
  68. this.textDir = this.params["textDir"] ? this.params["textDir"] : this.params["dir"];
  69. },
  70. _setTextDirAttr: function(/*String*/ textDir){
  71. if(validateTextDir(textDir) != null){
  72. this._set("textDir", textDir);
  73. this.chart.setTextDir(textDir);
  74. }
  75. }
  76. });
  77. }
  78. function validateTextDir(textDir){
  79. return /^(ltr|rtl|auto)$/.test(textDir) ? textDir : null;
  80. }
  81. });