InsertEntity.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. define("dojox/editor/plugins/InsertEntity", [
  2. "dojo",
  3. "dijit",
  4. "dojox",
  5. "dijit/TooltipDialog",
  6. "dijit/_editor/_Plugin",
  7. "dijit/form/DropDownButton",
  8. "dojo/_base/connect",
  9. "dojo/_base/declare",
  10. "dojo/i18n",
  11. "dojox/html/entities",
  12. "dojox/editor/plugins/EntityPalette",
  13. "dojo/i18n!dojox/editor/plugins/nls/InsertEntity"
  14. ], function(dojo, dijit, dojox) {
  15. dojo.declare("dojox.editor.plugins.InsertEntity",dijit._editor._Plugin,{
  16. // summary:
  17. // This plugin allows the user to select from standard Symbols (HTML Entities)
  18. // to insert at the current cursor position. It binds to the key pattern:
  19. // ctrl-shift-s for opening the insert symbol dropdown.
  20. //
  21. // description:
  22. // The commands provided by this plugin are:
  23. // * insertEntity - inserts the selected HTML entity character
  24. // iconClassPrefix: [const] String
  25. // The CSS class name for the button node is formed from `iconClassPrefix` and `command`
  26. iconClassPrefix: "dijitAdditionalEditorIcon",
  27. _initButton: function(){
  28. // summary:
  29. // Over-ride for creation of the save button.
  30. this.dropDown = new dojox.editor.plugins.EntityPalette({showCode: this.showCode, showEntityName: this.showEntityName});
  31. this.connect(this.dropDown, "onChange", function(entity){
  32. this.button.closeDropDown();
  33. this.editor.focus();
  34. this.editor.execCommand("inserthtml",entity);
  35. });
  36. var strings = dojo.i18n.getLocalization("dojox.editor.plugins", "InsertEntity");
  37. this.button = new dijit.form.DropDownButton({
  38. label: strings["insertEntity"],
  39. showLabel: false,
  40. iconClass: this.iconClassPrefix + " " + this.iconClassPrefix + "InsertEntity",
  41. tabIndex: "-1",
  42. dropDown: this.dropDown
  43. });
  44. },
  45. updateState: function(){
  46. // summary:
  47. // Over-ride for button state control for disabled to work.
  48. this.button.set("disabled", this.get("disabled"));
  49. },
  50. setEditor: function(editor){
  51. // summary:
  52. // Over-ride for the setting of the editor.
  53. // editor: Object
  54. // The editor to configure for this plugin to use.
  55. this.editor = editor;
  56. this._initButton();
  57. this.editor.addKeyHandler("s", true, true, dojo.hitch(this, function(){
  58. this.button.openDropDown();
  59. this.dropDown.focus();
  60. }));
  61. editor.contentPreFilters.push(this._preFilterEntities);
  62. editor.contentPostFilters.push(this._postFilterEntities);
  63. },
  64. _preFilterEntities: function(s/*String content passed in*/){
  65. // summary:
  66. // A function to filter out entity characters into their UTF-8 character form
  67. // displayed in the editor. It gets registered with the preFilters
  68. // of the editor.
  69. // tags:
  70. // private.
  71. return dojox.html.entities.decode(s, dojox.html.entities.latin);
  72. },
  73. _postFilterEntities: function(s/*String content passed in*/){
  74. // summary:
  75. // A function to filter out entity characters into encoded form so they
  76. // are properly displayed in the editor. It gets registered with the
  77. // postFilters of the editor.
  78. // tags:
  79. // private.
  80. return dojox.html.entities.encode(s, dojox.html.entities.latin);
  81. }
  82. });
  83. // Register this plugin.
  84. dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
  85. if(o.plugin){ return; }
  86. var name = o.args.name? o.args.name.toLowerCase() : "";
  87. if(name === "insertentity"){
  88. o.plugin = new dojox.editor.plugins.InsertEntity({
  89. showCode: ("showCode" in o.args)?o.args.showCode:false,
  90. showEntityName: ("showEntityName" in o.args)?o.args.showEntityName:false
  91. });
  92. }
  93. });
  94. return dojox.editor.plugins.InsertEntity;
  95. });