| 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 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
iconClassPrefix: "dijitAdditionalEditorIcon", |
| 30 |
|
| 31 |
_initButton: function(){ |
| 32 |
|
| 33 |
|
| 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 |
|
| 52 |
|
| 53 |
this.button.set("disabled", this.get("disabled")); |
| 54 |
}, |
| 55 |
|
| 56 |
setEditor: function(editor){ |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 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){ |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
return dojox.html.entities.decode(s, dojox.html.entities.latin); |
| 81 |
}, |
| 82 |
|
| 83 |
_postFilterEntities: function(s){ |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
return dojox.html.entities.encode(s, dojox.html.entities.latin); |
| 91 |
} |
| 92 |
}); |
| 93 |
|
| 94 |
|
| 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 |
}); |