| 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 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 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 |
|
| 64 |
|
| 65 |
showPreview: true, |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
showCode: false, |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
showEntityName: false, |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
palette: "latin", |
| 78 |
|
| 79 |
dyeClass: 'dojox.editor.plugins.LatinEntity', |
| 80 |
|
| 81 |
|
| 82 |
paletteClass: 'editorLatinEntityPalette', |
| 83 |
|
| 84 |
cellClass: "dojoxEntityPaletteCell", |
| 85 |
|
| 86 |
postMixInProperties: function(){ |
| 87 |
|
| 88 |
|
| 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 |
|
| 114 |
|
| 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 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
this._displayDetails(e.target); |
| 139 |
}, |
| 140 |
|
| 141 |
postCreate: function(){ |
| 142 |
this.inherited(arguments); |
| 143 |
|
| 144 |
|
| 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( node){ |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
this.inherited(arguments); |
| 164 |
if(this.showPreview){ |
| 165 |
this._displayDetails(node); |
| 166 |
} |
| 167 |
}, |
| 168 |
|
| 169 |
_displayDetails: function( cell){ |
| 170 |
|
| 171 |
|
| 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="&#"+parseInt(ehtml.charCodeAt(0), 10)+";"; |
| 178 |
this.entityNode.innerHTML="&"+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 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
constructor: function( alias){ |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
this._alias = alias; |
| 207 |
}, |
| 208 |
|
| 209 |
getValue: function(){ |
| 210 |
|
| 211 |
|
| 212 |
return "&" + this._alias + ";"; |
| 213 |
}, |
| 214 |
|
| 215 |
fillCell: function( cell){ |
| 216 |
|
| 217 |
cell.innerHTML = this.getValue(); |
| 218 |
} |
| 219 |
}); |
| 220 |
|
| 221 |
return EntityPalette; |
| 222 |
|
| 223 |
}); |