| 1 |
define([ |
| 2 |
"dojo", |
| 3 |
"dijit", |
| 4 |
"dojox", |
| 5 |
"dijit/_editor/_Plugin", |
| 6 |
"dijit/form/DropDownButton", |
| 7 |
"dojo/_base/connect", |
| 8 |
"dojo/_base/declare", |
| 9 |
"dojo/i18n", |
| 10 |
"dojox/editor/plugins/_SmileyPalette", |
| 11 |
"dojox/html/format", |
| 12 |
"dojo/i18n!dojox/editor/plugins/nls/Smiley" |
| 13 |
], function(dojo, dijit, dojox, _Plugin) { |
| 14 |
|
| 15 |
dojo.experimental("dojox.editor.plugins.Smiley"); |
| 16 |
|
| 17 |
var Smiley = dojo.declare("dojox.editor.plugins.Smiley", _Plugin, { |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
iconClassPrefix: "dijitAdditionalEditorIcon", |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
emoticonMarker: '[]', |
| 36 |
|
| 37 |
emoticonImageClass: 'dojoEditorEmoticon', |
| 38 |
|
| 39 |
_initButton: function(){ |
| 40 |
this.dropDown = new dojox.editor.plugins._SmileyPalette(); |
| 41 |
this.connect(this.dropDown, "onChange", function(ascii){ |
| 42 |
this.button.closeDropDown(); |
| 43 |
this.editor.focus(); |
| 44 |
|
| 45 |
ascii = this.emoticonMarker.charAt(0) + ascii + this.emoticonMarker.charAt(1); |
| 46 |
this.editor.execCommand("inserthtml", ascii); |
| 47 |
}); |
| 48 |
this.i18n = dojo.i18n.getLocalization("dojox.editor.plugins", "Smiley"); |
| 49 |
this.button = new dijit.form.DropDownButton({ |
| 50 |
label: this.i18n.smiley, |
| 51 |
showLabel: false, |
| 52 |
iconClass: this.iconClassPrefix + " " + this.iconClassPrefix + "Smiley", |
| 53 |
tabIndex: "-1", |
| 54 |
dropDown: this.dropDown |
| 55 |
}); |
| 56 |
this.emoticonImageRegexp = new RegExp("class=(\"|\')" + this.emoticonImageClass + "(\"|\')"); |
| 57 |
}, |
| 58 |
|
| 59 |
updateState: function(){ |
| 60 |
|
| 61 |
|
| 62 |
this.button.set("disabled", this.get("disabled")); |
| 63 |
}, |
| 64 |
|
| 65 |
setEditor: function(editor){ |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
this.editor = editor; |
| 71 |
this._initButton(); |
| 72 |
this.editor.contentPreFilters.push(dojo.hitch(this, this._preFilterEntities)); |
| 73 |
this.editor.contentPostFilters.push(dojo.hitch(this, this._postFilterEntities)); |
| 74 |
|
| 75 |
if(dojo.isFF){ |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
var deleteHandler = dojo.hitch(this, function(){ |
| 80 |
var editor = this.editor; |
| 81 |
|
| 82 |
|
| 83 |
setTimeout(function(){ |
| 84 |
if(editor.editNode){ |
| 85 |
dojo.style(editor.editNode, "opacity", "0.99"); |
| 86 |
|
| 87 |
|
| 88 |
setTimeout(function(){if(editor.editNode) { dojo.style(editor.editNode, "opacity", "");} }, 0); |
| 89 |
} |
| 90 |
}, 0); |
| 91 |
return true; |
| 92 |
}) |
| 93 |
this.editor.onLoadDeferred.addCallback(dojo.hitch(this, function(){ |
| 94 |
this.editor.addKeyHandler(dojo.keys.DELETE, false, false, deleteHandler); |
| 95 |
this.editor.addKeyHandler(dojo.keys.BACKSPACE, false, false, deleteHandler); |
| 96 |
})); |
| 97 |
} |
| 98 |
}, |
| 99 |
|
| 100 |
_preFilterEntities: function( value){ |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
return value.replace(/\[([^\]]*)\]/g, dojo.hitch(this, this._decode)); |
| 111 |
}, |
| 112 |
|
| 113 |
_postFilterEntities: function( value){ |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
return value.replace(/<img [^>]*>/gi, dojo.hitch(this, this._encode)); |
| 123 |
}, |
| 124 |
|
| 125 |
_decode: function(str, ascii){ |
| 126 |
|
| 127 |
|
| 128 |
var emoticon = dojox.editor.plugins.Emoticon.fromAscii(ascii); |
| 129 |
return emoticon ? emoticon.imgHtml(this.emoticonImageClass) : str; |
| 130 |
}, |
| 131 |
|
| 132 |
_encode: function(str){ |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
if(str.search(this.emoticonImageRegexp) > -1){ |
| 139 |
return this.emoticonMarker.charAt(0) + str.replace(/(<img [^>]*)alt="([^"]*)"([^>]*>)/, "$2") + this.emoticonMarker.charAt(1); |
| 140 |
} |
| 141 |
else{ |
| 142 |
return str; |
| 143 |
} |
| 144 |
} |
| 145 |
}); |
| 146 |
|
| 147 |
|
| 148 |
dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){ |
| 149 |
if(o.plugin){ return; } |
| 150 |
if(o.args.name === "smiley"){ |
| 151 |
o.plugin = new Smiley(); |
| 152 |
} |
| 153 |
}); |
| 154 |
|
| 155 |
return Smiley; |
| 156 |
|
| 157 |
}); |