Editor.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: cclcore
  4. //
  5. // (C) Copyright IBM Corp. 2012
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. dojo.provide("bidi.dojo.editor.Editor");
  9. dojo.require("dijit.Editor");
  10. dojo.declare(
  11. "bidi.dojo.editor.Editor",
  12. dijit.Editor,
  13. {
  14. _userList: false,
  15. textDir: "",
  16. constructor: function(params){
  17. if (params.plugins){
  18. this._userList = true;
  19. }
  20. },
  21. postCreate: function(){
  22. var direction = dojo.getComputedStyle(this.domNode).direction;
  23. if (!this._userList){
  24. if ("ltr" == direction){
  25. this.plugins=["undo","redo","|","cut","copy","paste","|","bold","italic","underline","strikethrough","|",
  26. "insertOrderedList","insertUnorderedList","indent","outdent","|","justifyLeft","justifyCenter","justifyRight","justifyFull"
  27. ];
  28. }
  29. else if ("rtl" == direction){
  30. this.plugins=["undo","redo","|","cut","copy","paste","|","bold","italic","underline","strikethrough","|",
  31. "insertOrderedList","insertUnorderedList","indent","outdent","|","justifyRight","justifyCenter","justifyLeft","justifyFull"
  32. ];
  33. }
  34. }
  35. this.inherited(arguments);
  36. this._setTextDir();
  37. },
  38. execCommand: function(cmd){
  39. // summary:
  40. // Main handler for executing any commands to the editor, like paste, bold, etc.
  41. // Overrides dijit.Editor.execCommand().
  42. var implFunc = "_" + cmd + "Impl";
  43. if(this.customUndo && (cmd=='undo' || cmd=='redo')){
  44. return this[cmd]();
  45. }
  46. else{
  47. var r;
  48. if(this[implFunc]){
  49. if(this.customUndo){
  50. this.endEditing();
  51. this._beginEditing();
  52. }
  53. r = this[implFunc](arguments);
  54. if(this.customUndo){
  55. this._endEditing();
  56. }
  57. }
  58. else{
  59. r = this.inherited('execCommand', arguments);
  60. }
  61. return r;
  62. }
  63. },
  64. _setTextDir: function(){
  65. if (this.editNode){
  66. dojo.attr(this.editNode, "dir", (this.isTextDirLeftToRight()? "ltr" : "rtl"));
  67. }
  68. },
  69. isTextDirLeftToRight: function(){
  70. // summary:
  71. // Returns default text direction.
  72. // Default text direction is defined by textDir attribute provided that it contains one of
  73. // "ltr" or "rtl" values. In other cases default text direction is the same, as orientation
  74. // of the editor.
  75. if(!this.textDir){
  76. return this._isLeftToRight();
  77. }
  78. var textDir = this.textDir.toUpperCase();
  79. if (textDir == "LTR"){
  80. return true;
  81. }else if(textDir == "RTL"){
  82. return false;
  83. }else{
  84. return this.isLeftToRight();
  85. }
  86. },
  87. _isLeftToRight: function(){
  88. if (!this.editNode){
  89. return true;
  90. }
  91. var direction = dojo.getComputedStyle(this.domNode).direction;
  92. return ("ltr" == direction);
  93. }
  94. }
  95. );