Debian Codegraph @

dojox/editor/plugins/EntityPalette.js

raw symbols SCIP
1 define([
2 "dojo",
3 "dijit",
4 "dojox",
5 "dijit/_Widget",
6 "dijit/_TemplatedMixin",
7 "dijit/_PaletteMixin",
8 "dojo/_base/connect",
9 "dojo/_base/declare",
10 "dojo/i18n",
11 "dojo/i18n!dojox/editor/plugins/nls/latinEntities"
12 ], function(dojo, dijit, dojox, _Widget, _TemplatedMixin, _PaletteMixin) {
13
14 dojo.experimental("dojox.editor.plugins.EntityPalette");
15
16 var EntityPalette = dojo.declare("dojox.editor.plugins.EntityPalette", [_Widget, _TemplatedMixin, _PaletteMixin], {
17 // summary:
18 // A keyboard accessible HTML entity-picking widget (for inserting symbol characters)
19 // description:
20 // Grid showing various entities, so the user can pick a certain entity.
21 // Can be used standalone, or as a popup.
22
23 // templateString: [protected] String
24 // The basic template used to render the palette.
25 // Should generally be over-ridden to define different classes.
26 templateString: '<div class="dojoxEntityPalette">\n' +
27 ' <table>\n' +
28 ' <tbody>\n' +
29 ' <tr>\n' +
30 ' <td>\n' +
31 ' <table class="dijitPaletteTable">\n' +
32 ' <tbody dojoAttachPoint="gridNode"></tbody>\n' +
33 ' </table>\n' +
34 ' </td>\n' +
35 ' </tr>\n' +
36 ' <tr>\n' +
37 ' <td>\n'+
38 ' <table dojoAttachPoint="previewPane" class="dojoxEntityPalettePreviewTable">\n' +
39 ' <tbody>\n' +
40 ' <tr>\n' +
41 ' <th class="dojoxEntityPalettePreviewHeader">Preview</th>\n' +
42 ' <th class="dojoxEntityPalettePreviewHeader" dojoAttachPoint="codeHeader">Code</th>\n' +
43 ' <th class="dojoxEntityPalettePreviewHeader" dojoAttachPoint="entityHeader">Name</th>\n' +
44 ' <th class="dojoxEntityPalettePreviewHeader">Description</th>\n' +
45 ' </tr>\n' +
46 ' <tr>\n' +
47 ' <td class="dojoxEntityPalettePreviewDetailEntity" dojoAttachPoint="previewNode"></td>\n' +
48 ' <td class="dojoxEntityPalettePreviewDetail" dojoAttachPoint="codeNode"></td>\n' +
49 ' <td class="dojoxEntityPalettePreviewDetail" dojoAttachPoint="entityNode"></td>\n' +
50 ' <td class="dojoxEntityPalettePreviewDetail" dojoAttachPoint="descNode"></td>\n' +
51 ' </tr>\n' +
52 ' </tbody>\n' +
53 ' </table>\n' +
54 ' </td>\n' +
55 ' </tr>\n' +
56 ' </tbody>\n' +
57 ' </table>\n' +
58 '</div>',
59
60
61 baseClass: "dojoxEntityPalette",
62
63 // showPreview: [public] Boolean
64 // Whether the preview pane will be displayed, to show details about the selected entity.
65 showPreview: true,
66
67 // showCode: [public] Boolean
68 // Show the character code for the entity.
69 showCode: false,
70
71 // showEntityName: [public] Boolean
72 // Show the entity name for the entity.
73 showEntityName: false,
74
75 // palette: [public] String
76 // The symbol pallete to display. The only current one is 'latin'.
77 palette: "latin",
78
79 dyeClass: 'dojox.editor.plugins.LatinEntity',
80
81 // domNodeClass [protected] String
82 paletteClass: 'editorLatinEntityPalette',
83
84 cellClass: "dojoxEntityPaletteCell",
85
86 postMixInProperties: function(){
87 // summary:
88 // Convert hash of entities into two-dimensional rows/columns table (array of arrays)
89 var choices = dojo.i18n.getLocalization("dojox.editor.plugins", "latinEntities");
90 var numChoices = 0;
91 var entityKey;
92 for(entityKey in choices){numChoices++;}
93 var choicesPerRow = Math.floor(Math.sqrt(numChoices));
94 var numRows = choicesPerRow;
95 var currChoiceIdx = 0;
96 var rows = [];
97 var row = [];
98 for(entityKey in choices){
99 currChoiceIdx++;
100 row.push(entityKey);
101 if(currChoiceIdx % numRows === 0){
102 rows.push(row);
103 row = [];
104 }
105 }
106 if(row.length > 0){
107 rows.push(row);
108 }
109 this._palette = rows;
110 },
111
112 buildRendering: function(){
113 // summary:
114 // Instantiate the template, which makes a skeleton table which we'll insert the entities
115 this.inherited(arguments);
116
117 var i18n = dojo.i18n.getLocalization("dojox.editor.plugins", "latinEntities");
118
119 this._preparePalette(
120 this._palette,
121 i18n
122 );
123
124 var cells = dojo.query(".dojoxEntityPaletteCell", this.gridNode);
125 dojo.forEach(cells, function(cellNode){
126 this.connect(cellNode, "onmouseenter", "_onCellMouseEnter");
127 }, this);
128 },
129
130 _onCellMouseEnter: function(e){
131 // summary:
132 // Simple function to handle updating the display at the bottom of
133 // the palette.
134 // e:
135 // The event.
136 // tags:
137 // private
138 this._displayDetails(e.target);
139 },
140
141 postCreate: function(){
142 this.inherited(arguments);
143
144 // Show the code and entity name (if enabled to do so.)
145 dojo.style(this.codeHeader, "display", this.showCode?"":"none");
146 dojo.style(this.codeNode, "display", this.showCode?"":"none");
147 dojo.style(this.entityHeader, "display", this.showEntityName?"":"none");
148 dojo.style(this.entityNode, "display", this.showEntityName?"":"none");
149
150 if(!this.showPreview){
151 dojo.style(this.previewNode,"display","none");
152 }
153 },
154
155 _setCurrent: function(/*DOMNode*/ node){
156 // summary:
157 // Called when a entity is hovered or focused.
158 // description:
159 // Removes highlight of the old entity, and highlights
160 // the new entity.
161 // tags:
162 // protected
163 this.inherited(arguments);
164 if(this.showPreview){
165 this._displayDetails(node);
166 }
167 },
168
169 _displayDetails: function(/*DOMNode*/ cell){
170 // summary:
171 // Display the details of the currently focused entity in the preview pane
172 var dye = this._getDye(cell);
173 if(dye){
174 var ehtml = dye.getValue();
175 var ename = dye._alias;
176 this.previewNode.innerHTML=ehtml;
177 this.codeNode.innerHTML="&amp;#"+parseInt(ehtml.charCodeAt(0), 10)+";";
178 this.entityNode.innerHTML="&amp;"+ename+";";
179 var i18n = dojo.i18n.getLocalization("dojox.editor.plugins", "latinEntities");
180 this.descNode.innerHTML=i18n[ename].replace("\n", "<br>");
181
182 }else{
183 this.previewNode.innerHTML="";
184 this.codeNode.innerHTML="";
185 this.entityNode.innerHTML="";
186 this.descNode.innerHTML="";
187 }
188 }
189 });
190
191 EntityPalette.LatinEntity = dojo.declare("dojox.editor.plugins.LatinEntity",
192 null,
193 {
194 // summary:
195 // Represents a character.
196 // Initialized using an alias for the character (like cent) rather
197 // than with the character itself.
198
199 constructor: function(/*String*/ alias){
200 // summary:
201 // Construct JS object representing an entity (associated w/a cell
202 // in the palette)
203 // value: String
204 // alias name: 'cent', 'pound' ..
205
206 this._alias = alias;
207 },
208
209 getValue: function(){
210 // summary:
211 // Returns HTML representing the character, like &amp;
212 return "&" + this._alias + ";";
213 },
214
215 fillCell: function(/*DOMNode*/ cell){
216 // Deal with entities that have keys which are reserved words.
217 cell.innerHTML = this.getValue();
218 }
219 });
220
221 return EntityPalette;
222
223 });