InsertEntity.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.editor.plugins.InsertEntity"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.editor.plugins.InsertEntity"] = true;
  8. dojo.provide("dojox.editor.plugins.InsertEntity");
  9. dojo.require("dijit.TooltipDialog");
  10. dojo.require("dijit._editor._Plugin");
  11. dojo.require("dijit.form.Button");
  12. dojo.require("dojox.html.entities");
  13. dojo.require("dojox.editor.plugins.EntityPalette");
  14. dojo.require("dojo.i18n");
  15. dojo.requireLocalization("dojox.editor.plugins", "InsertEntity", null, "ROOT,ar,bg,ca,cs,da,de,el,es,fi,fr,he,hr,hu,it,ja,kk,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw");
  16. dojo.declare("dojox.editor.plugins.InsertEntity",dijit._editor._Plugin,{
  17. // summary:
  18. // This plugin allows the user to select from standard Symbols (HTML Entities)
  19. // to insert at the current cursor position. It binds to the key pattern:
  20. // ctrl-shift-s for opening the insert symbol dropdown.
  21. //
  22. // description:
  23. // The commands provided by this plugin are:
  24. // * insertEntity - inserts the selected HTML entity character
  25. // iconClassPrefix: [const] String
  26. // The CSS class name for the button node is formed from `iconClassPrefix` and `command`
  27. iconClassPrefix: "dijitAdditionalEditorIcon",
  28. _initButton: function(){
  29. // summary:
  30. // Over-ride for creation of the save button.
  31. this.dropDown = new dojox.editor.plugins.EntityPalette({showCode: this.showCode, showEntityName: this.showEntityName});
  32. this.connect(this.dropDown, "onChange", function(entity){
  33. this.button.closeDropDown();
  34. this.editor.focus();
  35. this.editor.execCommand("inserthtml",entity);
  36. });
  37. var strings = dojo.i18n.getLocalization("dojox.editor.plugins", "InsertEntity");
  38. this.button = new dijit.form.DropDownButton({
  39. label: strings["insertEntity"],
  40. showLabel: false,
  41. iconClass: this.iconClassPrefix + " " + this.iconClassPrefix + "InsertEntity",
  42. tabIndex: "-1",
  43. dropDown: this.dropDown
  44. });
  45. },
  46. updateState: function(){
  47. // summary:
  48. // Over-ride for button state control for disabled to work.
  49. this.button.set("disabled", this.get("disabled"));
  50. },
  51. setEditor: function(editor){
  52. // summary:
  53. // Over-ride for the setting of the editor.
  54. // editor: Object
  55. // The editor to configure for this plugin to use.
  56. this.editor = editor;
  57. this._initButton();
  58. this.editor.addKeyHandler("s", true, true, dojo.hitch(this, function(){
  59. this.button.openDropDown();
  60. this.dropDown.focus();
  61. }));
  62. editor.contentPreFilters.push(this._preFilterEntities);
  63. editor.contentPostFilters.push(this._postFilterEntities);
  64. },
  65. _preFilterEntities: function(s/*String content passed in*/){
  66. // summary:
  67. // A function to filter out entity characters into their UTF-8 character form
  68. // displayed in the editor. It gets registered with the preFilters
  69. // of the editor.
  70. // tags:
  71. // private.
  72. return dojox.html.entities.decode(s, dojox.html.entities.latin);
  73. },
  74. _postFilterEntities: function(s/*String content passed in*/){
  75. // summary:
  76. // A function to filter out entity characters into encoded form so they
  77. // are properly displayed in the editor. It gets registered with the
  78. // postFilters of the editor.
  79. // tags:
  80. // private.
  81. return dojox.html.entities.encode(s, dojox.html.entities.latin);
  82. }
  83. });
  84. // Register this plugin.
  85. dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
  86. if(o.plugin){ return; }
  87. var name = o.args.name? o.args.name.toLowerCase() : "";
  88. if(name === "insertentity"){
  89. o.plugin = new dojox.editor.plugins.InsertEntity({
  90. showCode: ("showCode" in o.args)?o.args.showCode:false,
  91. showEntityName: ("showEntityName" in o.args)?o.args.showEntityName:false
  92. });
  93. }
  94. });
  95. }