Debian Codegraph @

dojox/editor/plugins/InsertEntity.js

raw symbols SCIP
1 define([
2 "dojo",
3 "dijit",
4 "dojox",
5 "dijit/_editor/_Plugin",
6 "dijit/TooltipDialog",
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, _Plugin) {
15
16 var InsertEntity = dojo.declare("dojox.editor.plugins.InsertEntity", _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 //
25 // - insertEntity - inserts the selected HTML entity character
26
27 // iconClassPrefix: [const] String
28 // The CSS class name for the button node is formed from `iconClassPrefix` and `command`
29 iconClassPrefix: "dijitAdditionalEditorIcon",
30
31 _initButton: function(){
32 // summary:
33 // Over-ride for creation of the save button.
34 this.dropDown = new dojox.editor.plugins.EntityPalette({showCode: this.showCode, showEntityName: this.showEntityName});
35 this.connect(this.dropDown, "onChange", function(entity){
36 this.button.closeDropDown();
37 this.editor.focus();
38 this.editor.execCommand("inserthtml",entity);
39 });
40 var strings = dojo.i18n.getLocalization("dojox.editor.plugins", "InsertEntity");
41 this.button = new dijit.form.DropDownButton({
42 label: strings["insertEntity"],
43 showLabel: false,
44 iconClass: this.iconClassPrefix + " " + this.iconClassPrefix + "InsertEntity",
45 tabIndex: "-1",
46 dropDown: this.dropDown
47 });
48 },
49
50 updateState: function(){
51 // summary:
52 // Over-ride for button state control for disabled to work.
53 this.button.set("disabled", this.get("disabled"));
54 },
55
56 setEditor: function(editor){
57 // summary:
58 // Over-ride for the setting of the editor.
59 // editor: Object
60 // The editor to configure for this plugin to use.
61 this.editor = editor;
62 this._initButton();
63
64 this.editor.addKeyHandler("s", true, true, dojo.hitch(this, function(){
65 this.button.openDropDown();
66 this.dropDown.focus();
67 }));
68
69 editor.contentPreFilters.push(this._preFilterEntities);
70 editor.contentPostFilters.push(this._postFilterEntities);
71 },
72
73 _preFilterEntities: function(s/*String content passed in*/){
74 // summary:
75 // A function to filter out entity characters into their UTF-8 character form
76 // displayed in the editor. It gets registered with the preFilters
77 // of the editor.
78 // tags:
79 // private.
80 return dojox.html.entities.decode(s, dojox.html.entities.latin);
81 },
82
83 _postFilterEntities: function(s/*String content passed in*/){
84 // summary:
85 // A function to filter out entity characters into encoded form so they
86 // are properly displayed in the editor. It gets registered with the
87 // postFilters of the editor.
88 // tags:
89 // private.
90 return dojox.html.entities.encode(s, dojox.html.entities.latin);
91 }
92 });
93
94 // Register this plugin.
95 dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
96 if(o.plugin){ return; }
97 var name = o.args.name? o.args.name.toLowerCase() : "";
98 if(name === "insertentity"){
99 o.plugin = new InsertEntity({
100 showCode: ("showCode" in o.args)?o.args.showCode:false,
101 showEntityName: ("showEntityName" in o.args)?o.args.showEntityName:false
102 });
103 }
104 });
105
106 return InsertEntity;
107 });