1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
1422 |
alexandre_ |
11 |
|
|
|
12 |
|
1318 |
alexandre_ |
13 |
dojo.provide("dojo.widget.RichText");
|
|
|
14 |
dojo.require("dojo.widget.*");
|
|
|
15 |
dojo.require("dojo.html.*");
|
|
|
16 |
dojo.require("dojo.html.layout");
|
|
|
17 |
dojo.require("dojo.html.selection");
|
|
|
18 |
dojo.require("dojo.event.*");
|
|
|
19 |
dojo.require("dojo.string.extras");
|
|
|
20 |
dojo.require("dojo.uri.Uri");
|
|
|
21 |
dojo.require("dojo.Deferred");
|
|
|
22 |
if (!djConfig["useXDomain"] || djConfig["allowXdRichTextSave"]) {
|
|
|
23 |
if (dojo.hostenv.post_load_) {
|
|
|
24 |
(function () {
|
|
|
25 |
var savetextarea = dojo.doc().createElement("textarea");
|
|
|
26 |
savetextarea.id = "dojo.widget.RichText.savedContent";
|
|
|
27 |
savetextarea.style = "display:none;position:absolute;top:-100px;left:-100px;height:3px;width:3px;overflow:hidden;";
|
|
|
28 |
dojo.body().appendChild(savetextarea);
|
|
|
29 |
})();
|
|
|
30 |
} else {
|
|
|
31 |
try {
|
|
|
32 |
dojo.doc().write("<textarea id=\"dojo.widget.RichText.savedContent\" " + "style=\"display:none;position:absolute;top:-100px;left:-100px;height:3px;width:3px;overflow:hidden;\"></textarea>");
|
|
|
33 |
}
|
|
|
34 |
catch (e) {
|
|
|
35 |
}
|
|
|
36 |
}
|
|
|
37 |
}
|
|
|
38 |
dojo.widget.defineWidget("dojo.widget.RichText", dojo.widget.HtmlWidget, function () {
|
|
|
39 |
this.contentPreFilters = [];
|
|
|
40 |
this.contentPostFilters = [];
|
|
|
41 |
this.contentDomPreFilters = [];
|
|
|
42 |
this.contentDomPostFilters = [];
|
|
|
43 |
this.editingAreaStyleSheets = [];
|
|
|
44 |
if (dojo.render.html.moz) {
|
|
|
45 |
this.contentPreFilters.push(this._fixContentForMoz);
|
|
|
46 |
}
|
|
|
47 |
this._keyHandlers = {};
|
|
|
48 |
if (dojo.Deferred) {
|
|
|
49 |
this.onLoadDeferred = new dojo.Deferred();
|
|
|
50 |
}
|
|
|
51 |
}, {inheritWidth:false, focusOnLoad:false, saveName:"", styleSheets:"", _content:"", height:"", minHeight:"1em", isClosed:true, isLoaded:false, useActiveX:false, relativeImageUrls:false, _SEPARATOR:"@@**%%__RICHTEXTBOUNDRY__%%**@@", onLoadDeferred:null, fillInTemplate:function () {
|
|
|
52 |
dojo.event.topic.publish("dojo.widget.RichText::init", this);
|
|
|
53 |
this.open();
|
|
|
54 |
dojo.event.connect(this, "onKeyPressed", this, "afterKeyPress");
|
|
|
55 |
dojo.event.connect(this, "onKeyPress", this, "keyPress");
|
|
|
56 |
dojo.event.connect(this, "onKeyDown", this, "keyDown");
|
|
|
57 |
dojo.event.connect(this, "onKeyUp", this, "keyUp");
|
|
|
58 |
this.setupDefaultShortcuts();
|
|
|
59 |
}, setupDefaultShortcuts:function () {
|
|
|
60 |
var ctrl = this.KEY_CTRL;
|
|
|
61 |
var exec = function (cmd, arg) {
|
|
|
62 |
return arguments.length == 1 ? function () {
|
|
|
63 |
this.execCommand(cmd);
|
|
|
64 |
} : function () {
|
|
|
65 |
this.execCommand(cmd, arg);
|
|
|
66 |
};
|
|
|
67 |
};
|
|
|
68 |
this.addKeyHandler("b", ctrl, exec("bold"));
|
|
|
69 |
this.addKeyHandler("i", ctrl, exec("italic"));
|
|
|
70 |
this.addKeyHandler("u", ctrl, exec("underline"));
|
|
|
71 |
this.addKeyHandler("a", ctrl, exec("selectall"));
|
|
|
72 |
this.addKeyHandler("s", ctrl, function () {
|
|
|
73 |
this.save(true);
|
|
|
74 |
});
|
|
|
75 |
this.addKeyHandler("1", ctrl, exec("formatblock", "h1"));
|
|
|
76 |
this.addKeyHandler("2", ctrl, exec("formatblock", "h2"));
|
|
|
77 |
this.addKeyHandler("3", ctrl, exec("formatblock", "h3"));
|
|
|
78 |
this.addKeyHandler("4", ctrl, exec("formatblock", "h4"));
|
|
|
79 |
this.addKeyHandler("\\", ctrl, exec("insertunorderedlist"));
|
|
|
80 |
if (!dojo.render.html.ie) {
|
|
|
81 |
this.addKeyHandler("Z", ctrl, exec("redo"));
|
|
|
82 |
}
|
|
|
83 |
}, events:["onBlur", "onFocus", "onKeyPress", "onKeyDown", "onKeyUp", "onClick"], open:function (element) {
|
|
|
84 |
if (this.onLoadDeferred.fired >= 0) {
|
|
|
85 |
this.onLoadDeferred = new dojo.Deferred();
|
|
|
86 |
}
|
|
|
87 |
var h = dojo.render.html;
|
|
|
88 |
if (!this.isClosed) {
|
|
|
89 |
this.close();
|
|
|
90 |
}
|
|
|
91 |
dojo.event.topic.publish("dojo.widget.RichText::open", this);
|
|
|
92 |
this._content = "";
|
|
|
93 |
if ((arguments.length == 1) && (element["nodeName"])) {
|
|
|
94 |
this.domNode = element;
|
|
|
95 |
}
|
|
|
96 |
if ((this.domNode["nodeName"]) && (this.domNode.nodeName.toLowerCase() == "textarea")) {
|
|
|
97 |
this.textarea = this.domNode;
|
|
|
98 |
var html = this._preFilterContent(this.textarea.value);
|
|
|
99 |
this.domNode = dojo.doc().createElement("div");
|
|
|
100 |
dojo.html.copyStyle(this.domNode, this.textarea);
|
|
|
101 |
var tmpFunc = dojo.lang.hitch(this, function () {
|
|
|
102 |
with (this.textarea.style) {
|
|
|
103 |
display = "block";
|
|
|
104 |
position = "absolute";
|
|
|
105 |
left = top = "-1000px";
|
|
|
106 |
if (h.ie) {
|
|
|
107 |
this.__overflow = overflow;
|
|
|
108 |
overflow = "hidden";
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
});
|
|
|
112 |
if (h.ie) {
|
|
|
113 |
setTimeout(tmpFunc, 10);
|
|
|
114 |
} else {
|
|
|
115 |
tmpFunc();
|
|
|
116 |
}
|
|
|
117 |
if (!h.safari) {
|
|
|
118 |
dojo.html.insertBefore(this.domNode, this.textarea);
|
|
|
119 |
}
|
|
|
120 |
if (this.textarea.form) {
|
|
|
121 |
dojo.event.connect("before", this.textarea.form, "onsubmit", dojo.lang.hitch(this, function () {
|
|
|
122 |
this.textarea.value = this.getEditorContent();
|
|
|
123 |
}));
|
|
|
124 |
}
|
|
|
125 |
var editor = this;
|
|
|
126 |
dojo.event.connect(this, "postCreate", function () {
|
|
|
127 |
dojo.html.insertAfter(editor.textarea, editor.domNode);
|
|
|
128 |
});
|
|
|
129 |
} else {
|
|
|
130 |
var html = this._preFilterContent(dojo.string.trim(this.domNode.innerHTML));
|
|
|
131 |
}
|
|
|
132 |
if (html == "") {
|
|
|
133 |
html = " ";
|
|
|
134 |
}
|
|
|
135 |
var content = dojo.html.getContentBox(this.domNode);
|
|
|
136 |
this._oldHeight = content.height;
|
|
|
137 |
this._oldWidth = content.width;
|
|
|
138 |
this._firstChildContributingMargin = this._getContributingMargin(this.domNode, "top");
|
|
|
139 |
this._lastChildContributingMargin = this._getContributingMargin(this.domNode, "bottom");
|
|
|
140 |
this.savedContent = html;
|
|
|
141 |
this.domNode.innerHTML = "";
|
|
|
142 |
this.editingArea = dojo.doc().createElement("div");
|
|
|
143 |
this.domNode.appendChild(this.editingArea);
|
|
|
144 |
if ((this.domNode["nodeName"]) && (this.domNode.nodeName == "LI")) {
|
|
|
145 |
this.domNode.innerHTML = " <br>";
|
|
|
146 |
}
|
|
|
147 |
if (this.saveName != "" && (!djConfig["useXDomain"] || djConfig["allowXdRichTextSave"])) {
|
|
|
148 |
var saveTextarea = dojo.doc().getElementById("dojo.widget.RichText.savedContent");
|
|
|
149 |
if (saveTextarea.value != "") {
|
|
|
150 |
var datas = saveTextarea.value.split(this._SEPARATOR);
|
|
|
151 |
for (var i = 0; i < datas.length; i++) {
|
|
|
152 |
var data = datas[i].split(":");
|
|
|
153 |
if (data[0] == this.saveName) {
|
|
|
154 |
html = data[1];
|
|
|
155 |
datas.splice(i, 1);
|
|
|
156 |
break;
|
|
|
157 |
}
|
|
|
158 |
}
|
|
|
159 |
}
|
|
|
160 |
dojo.event.connect("before", window, "onunload", this, "_saveContent");
|
|
|
161 |
}
|
|
|
162 |
if (h.ie70 && this.useActiveX) {
|
|
|
163 |
dojo.debug("activeX in ie70 is not currently supported, useActiveX is ignored for now.");
|
|
|
164 |
this.useActiveX = false;
|
|
|
165 |
}
|
|
|
166 |
if (this.useActiveX && h.ie) {
|
|
|
167 |
var self = this;
|
|
|
168 |
setTimeout(function () {
|
|
|
169 |
self._drawObject(html);
|
|
|
170 |
}, 0);
|
|
|
171 |
} else {
|
|
|
172 |
if (h.ie || this._safariIsLeopard() || h.opera) {
|
|
|
173 |
this.iframe = dojo.doc().createElement("iframe");
|
|
|
174 |
this.iframe.src = "javascript:void(0)";
|
|
|
175 |
this.editorObject = this.iframe;
|
|
|
176 |
with (this.iframe.style) {
|
|
|
177 |
border = "0";
|
|
|
178 |
width = "100%";
|
|
|
179 |
}
|
|
|
180 |
this.iframe.frameBorder = 0;
|
|
|
181 |
this.editingArea.appendChild(this.iframe);
|
|
|
182 |
this.window = this.iframe.contentWindow;
|
|
|
183 |
this.document = this.window.document;
|
|
|
184 |
this.document.open();
|
|
|
185 |
this.document.write("<html><head><style>body{margin:0;padding:0;border:0;overflow:hidden;}</style></head><body><div></div></body></html>");
|
|
|
186 |
this.document.close();
|
|
|
187 |
this.editNode = this.document.body.firstChild;
|
|
|
188 |
this.editNode.contentEditable = true;
|
|
|
189 |
with (this.iframe.style) {
|
|
|
190 |
if (h.ie70) {
|
|
|
191 |
if (this.height) {
|
|
|
192 |
height = this.height;
|
|
|
193 |
}
|
|
|
194 |
if (this.minHeight) {
|
|
|
195 |
minHeight = this.minHeight;
|
|
|
196 |
}
|
|
|
197 |
} else {
|
|
|
198 |
height = this.height ? this.height : this.minHeight;
|
|
|
199 |
}
|
|
|
200 |
}
|
|
|
201 |
var formats = ["p", "pre", "address", "h1", "h2", "h3", "h4", "h5", "h6", "ol", "div", "ul"];
|
|
|
202 |
var localhtml = "";
|
|
|
203 |
for (var i in formats) {
|
|
|
204 |
if (formats[i].charAt(1) != "l") {
|
|
|
205 |
localhtml += "<" + formats[i] + "><span>content</span></" + formats[i] + ">";
|
|
|
206 |
} else {
|
|
|
207 |
localhtml += "<" + formats[i] + "><li>content</li></" + formats[i] + ">";
|
|
|
208 |
}
|
|
|
209 |
}
|
|
|
210 |
with (this.editNode.style) {
|
|
|
211 |
position = "absolute";
|
|
|
212 |
left = "-2000px";
|
|
|
213 |
top = "-2000px";
|
|
|
214 |
}
|
|
|
215 |
this.editNode.innerHTML = localhtml;
|
|
|
216 |
var node = this.editNode.firstChild;
|
|
|
217 |
while (node) {
|
|
|
218 |
dojo.withGlobal(this.window, "selectElement", dojo.html.selection, [node.firstChild]);
|
|
|
219 |
var nativename = node.tagName.toLowerCase();
|
|
|
220 |
this._local2NativeFormatNames[nativename] = this.queryCommandValue("formatblock");
|
|
|
221 |
this._native2LocalFormatNames[this._local2NativeFormatNames[nativename]] = nativename;
|
|
|
222 |
node = node.nextSibling;
|
|
|
223 |
}
|
|
|
224 |
with (this.editNode.style) {
|
|
|
225 |
position = "";
|
|
|
226 |
left = "";
|
|
|
227 |
top = "";
|
|
|
228 |
}
|
|
|
229 |
this.editNode.innerHTML = html;
|
|
|
230 |
if (this.height) {
|
|
|
231 |
this.document.body.style.overflowY = "scroll";
|
|
|
232 |
}
|
|
|
233 |
dojo.lang.forEach(this.events, function (e) {
|
|
|
234 |
dojo.event.connect(this.editNode, e.toLowerCase(), this, e);
|
|
|
235 |
}, this);
|
|
|
236 |
this.onLoad();
|
|
|
237 |
} else {
|
|
|
238 |
this._drawIframe(html);
|
|
|
239 |
this.editorObject = this.iframe;
|
|
|
240 |
}
|
|
|
241 |
}
|
|
|
242 |
if (this.domNode.nodeName == "LI") {
|
|
|
243 |
this.domNode.lastChild.style.marginTop = "-1.2em";
|
|
|
244 |
}
|
|
|
245 |
dojo.html.addClass(this.domNode, "RichTextEditable");
|
|
|
246 |
this.isClosed = false;
|
|
|
247 |
}, _hasCollapseableMargin:function (element, side) {
|
|
|
248 |
if (dojo.html.getPixelValue(element, "border-" + side + "-width", false)) {
|
|
|
249 |
return false;
|
|
|
250 |
} else {
|
|
|
251 |
if (dojo.html.getPixelValue(element, "padding-" + side, false)) {
|
|
|
252 |
return false;
|
|
|
253 |
} else {
|
|
|
254 |
return true;
|
|
|
255 |
}
|
|
|
256 |
}
|
|
|
257 |
}, _getContributingMargin:function (element, topOrBottom) {
|
|
|
258 |
if (topOrBottom == "top") {
|
|
|
259 |
var siblingAttr = "previousSibling";
|
|
|
260 |
var childSiblingAttr = "nextSibling";
|
|
|
261 |
var childAttr = "firstChild";
|
|
|
262 |
var marginProp = "margin-top";
|
|
|
263 |
var siblingMarginProp = "margin-bottom";
|
|
|
264 |
} else {
|
|
|
265 |
var siblingAttr = "nextSibling";
|
|
|
266 |
var childSiblingAttr = "previousSibling";
|
|
|
267 |
var childAttr = "lastChild";
|
|
|
268 |
var marginProp = "margin-bottom";
|
|
|
269 |
var siblingMarginProp = "margin-top";
|
|
|
270 |
}
|
|
|
271 |
var elementMargin = dojo.html.getPixelValue(element, marginProp, false);
|
|
|
272 |
function isSignificantNode(element) {
|
|
|
273 |
return !(element.nodeType == 3 && dojo.string.isBlank(element.data)) && dojo.html.getStyle(element, "display") != "none" && !dojo.html.isPositionAbsolute(element);
|
|
|
274 |
}
|
|
|
275 |
var childMargin = 0;
|
|
|
276 |
var child = element[childAttr];
|
|
|
277 |
while (child) {
|
|
|
278 |
while ((!isSignificantNode(child)) && child[childSiblingAttr]) {
|
|
|
279 |
child = child[childSiblingAttr];
|
|
|
280 |
}
|
|
|
281 |
childMargin = Math.max(childMargin, dojo.html.getPixelValue(child, marginProp, false));
|
|
|
282 |
if (!this._hasCollapseableMargin(child, topOrBottom)) {
|
|
|
283 |
break;
|
|
|
284 |
}
|
|
|
285 |
child = child[childAttr];
|
|
|
286 |
}
|
|
|
287 |
if (!this._hasCollapseableMargin(element, topOrBottom)) {
|
|
|
288 |
return parseInt(childMargin);
|
|
|
289 |
}
|
|
|
290 |
var contextMargin = 0;
|
|
|
291 |
var sibling = element[siblingAttr];
|
|
|
292 |
while (sibling) {
|
|
|
293 |
if (isSignificantNode(sibling)) {
|
|
|
294 |
contextMargin = dojo.html.getPixelValue(sibling, siblingMarginProp, false);
|
|
|
295 |
break;
|
|
|
296 |
}
|
|
|
297 |
sibling = sibling[siblingAttr];
|
|
|
298 |
}
|
|
|
299 |
if (!sibling) {
|
|
|
300 |
contextMargin = dojo.html.getPixelValue(element.parentNode, marginProp, false);
|
|
|
301 |
}
|
|
|
302 |
if (childMargin > elementMargin) {
|
|
|
303 |
return parseInt(Math.max((childMargin - elementMargin) - contextMargin, 0));
|
|
|
304 |
} else {
|
|
|
305 |
return 0;
|
|
|
306 |
}
|
|
|
307 |
}, _drawIframe:function (html) {
|
|
|
308 |
var oldMoz = Boolean(dojo.render.html.moz && (typeof window.XML == "undefined"));
|
|
|
309 |
if (!this.iframe) {
|
|
|
310 |
var currentDomain = (new dojo.uri.Uri(dojo.doc().location)).host;
|
|
|
311 |
this.iframe = dojo.doc().createElement("iframe");
|
|
|
312 |
with (this.iframe) {
|
|
|
313 |
style.border = "none";
|
|
|
314 |
style.lineHeight = "0";
|
|
|
315 |
style.verticalAlign = "bottom";
|
|
|
316 |
scrolling = this.height ? "auto" : "no";
|
|
|
317 |
}
|
|
|
318 |
}
|
|
|
319 |
if (djConfig["useXDomain"] && !djConfig["dojoRichTextFrameUrl"]) {
|
|
|
320 |
dojo.debug("dojo.widget.RichText: When using cross-domain Dojo builds," + " please save src/widget/templates/richtextframe.html to your domain and set djConfig.dojoRichTextFrameUrl" + " to the path on your domain to richtextframe.html");
|
|
|
321 |
}
|
|
|
322 |
this.iframe.src = (djConfig["dojoRichTextFrameUrl"] || dojo.uri.moduleUri("dojo.widget", "templates/richtextframe.html")) + ((dojo.doc().domain != currentDomain) ? ("#" + dojo.doc().domain) : "");
|
|
|
323 |
this.iframe.width = this.inheritWidth ? this._oldWidth : "100%";
|
|
|
324 |
if (this.height) {
|
|
|
325 |
this.iframe.style.height = this.height;
|
|
|
326 |
} else {
|
|
|
327 |
var height = this._oldHeight;
|
|
|
328 |
if (this._hasCollapseableMargin(this.domNode, "top")) {
|
|
|
329 |
height += this._firstChildContributingMargin;
|
|
|
330 |
}
|
|
|
331 |
if (this._hasCollapseableMargin(this.domNode, "bottom")) {
|
|
|
332 |
height += this._lastChildContributingMargin;
|
|
|
333 |
}
|
|
|
334 |
this.iframe.height = height;
|
|
|
335 |
}
|
|
|
336 |
var tmpContent = dojo.doc().createElement("div");
|
|
|
337 |
tmpContent.innerHTML = html;
|
|
|
338 |
this.editingArea.appendChild(tmpContent);
|
|
|
339 |
if (this.relativeImageUrls) {
|
|
|
340 |
var imgs = tmpContent.getElementsByTagName("img");
|
|
|
341 |
for (var i = 0; i < imgs.length; i++) {
|
|
|
342 |
imgs[i].src = (new dojo.uri.Uri(dojo.global().location, imgs[i].src)).toString();
|
|
|
343 |
}
|
|
|
344 |
html = tmpContent.innerHTML;
|
|
|
345 |
}
|
|
|
346 |
var firstChild = dojo.html.firstElement(tmpContent);
|
|
|
347 |
var lastChild = dojo.html.lastElement(tmpContent);
|
|
|
348 |
if (firstChild) {
|
|
|
349 |
firstChild.style.marginTop = this._firstChildContributingMargin + "px";
|
|
|
350 |
}
|
|
|
351 |
if (lastChild) {
|
|
|
352 |
lastChild.style.marginBottom = this._lastChildContributingMargin + "px";
|
|
|
353 |
}
|
|
|
354 |
this.editingArea.appendChild(this.iframe);
|
|
|
355 |
if (dojo.render.html.safari) {
|
|
|
356 |
this.iframe.src = this.iframe.src;
|
|
|
357 |
}
|
|
|
358 |
var _iframeInitialized = false;
|
|
|
359 |
var ifrFunc = dojo.lang.hitch(this, function () {
|
|
|
360 |
if (!_iframeInitialized) {
|
|
|
361 |
_iframeInitialized = true;
|
|
|
362 |
} else {
|
|
|
363 |
return;
|
|
|
364 |
}
|
|
|
365 |
if (!this.editNode) {
|
|
|
366 |
if (this.iframe.contentWindow) {
|
|
|
367 |
this.window = this.iframe.contentWindow;
|
|
|
368 |
this.document = this.iframe.contentWindow.document;
|
|
|
369 |
} else {
|
|
|
370 |
if (this.iframe.contentDocument) {
|
|
|
371 |
this.window = this.iframe.contentDocument.window;
|
|
|
372 |
this.document = this.iframe.contentDocument;
|
|
|
373 |
}
|
|
|
374 |
}
|
|
|
375 |
var getStyle = (function (domNode) {
|
|
|
376 |
return function (style) {
|
|
|
377 |
return dojo.html.getStyle(domNode, style);
|
|
|
378 |
};
|
|
|
379 |
})(this.domNode);
|
|
|
380 |
var font = getStyle("font-weight") + " " + getStyle("font-size") + " " + getStyle("font-family");
|
|
|
381 |
var lineHeight = "1.0";
|
|
|
382 |
var lineHeightStyle = dojo.html.getUnitValue(this.domNode, "line-height");
|
|
|
383 |
if (lineHeightStyle.value && lineHeightStyle.units == "") {
|
|
|
384 |
lineHeight = lineHeightStyle.value;
|
|
|
385 |
}
|
|
|
386 |
dojo.html.insertCssText("body,html{background:transparent;padding:0;margin:0;}" + "body{top:0;left:0;right:0;" + (((this.height) || (dojo.render.html.opera)) ? "" : "position:fixed;") + "font:" + font + ";" + "min-height:" + this.minHeight + ";" + "line-height:" + lineHeight + "}" + "p{margin: 1em 0 !important;}" + "body > *:first-child{padding-top:0 !important;margin-top:" + this._firstChildContributingMargin + "px !important;}" + "body > *:last-child{padding-bottom:0 !important;margin-bottom:" + this._lastChildContributingMargin + "px !important;}" + "li > ul:-moz-first-node, li > ol:-moz-first-node{padding-top:1.2em;}\n" + "li{min-height:1.2em;}" + "", this.document);
|
|
|
387 |
dojo.html.removeNode(tmpContent);
|
|
|
388 |
this.document.body.innerHTML = html;
|
|
|
389 |
if (oldMoz || dojo.render.html.safari) {
|
|
|
390 |
this.document.designMode = "on";
|
|
|
391 |
}
|
|
|
392 |
this.onLoad();
|
|
|
393 |
} else {
|
|
|
394 |
dojo.html.removeNode(tmpContent);
|
|
|
395 |
this.editNode.innerHTML = html;
|
|
|
396 |
this.onDisplayChanged();
|
|
|
397 |
}
|
|
|
398 |
});
|
|
|
399 |
if (this.editNode) {
|
|
|
400 |
ifrFunc();
|
|
|
401 |
} else {
|
|
|
402 |
if (dojo.render.html.moz) {
|
|
|
403 |
this.iframe.onload = function () {
|
|
|
404 |
setTimeout(ifrFunc, 250);
|
|
|
405 |
};
|
|
|
406 |
} else {
|
|
|
407 |
this.iframe.onload = ifrFunc;
|
|
|
408 |
}
|
|
|
409 |
}
|
|
|
410 |
}, _applyEditingAreaStyleSheets:function () {
|
|
|
411 |
var files = [];
|
|
|
412 |
if (this.styleSheets) {
|
|
|
413 |
files = this.styleSheets.split(";");
|
|
|
414 |
this.styleSheets = "";
|
|
|
415 |
}
|
|
|
416 |
files = files.concat(this.editingAreaStyleSheets);
|
|
|
417 |
this.editingAreaStyleSheets = [];
|
|
|
418 |
if (files.length > 0) {
|
|
|
419 |
for (var i = 0; i < files.length; i++) {
|
|
|
420 |
var url = files[i];
|
|
|
421 |
if (url) {
|
|
|
422 |
this.addStyleSheet(dojo.uri.dojoUri(url));
|
|
|
423 |
}
|
|
|
424 |
}
|
|
|
425 |
}
|
|
|
426 |
}, addStyleSheet:function (uri) {
|
|
|
427 |
var url = uri.toString();
|
|
|
428 |
if (dojo.lang.find(this.editingAreaStyleSheets, url) > -1) {
|
|
|
429 |
dojo.debug("dojo.widget.RichText.addStyleSheet: Style sheet " + url + " is already applied to the editing area!");
|
|
|
430 |
return;
|
|
|
431 |
}
|
|
|
432 |
if (url.charAt(0) == "." || (url.charAt(0) != "/" && !uri.host)) {
|
|
|
433 |
url = (new dojo.uri.Uri(dojo.global().location, url)).toString();
|
|
|
434 |
}
|
|
|
435 |
this.editingAreaStyleSheets.push(url);
|
|
|
436 |
if (this.document.createStyleSheet) {
|
|
|
437 |
this.document.createStyleSheet(url);
|
|
|
438 |
} else {
|
|
|
439 |
var head = this.document.getElementsByTagName("head")[0];
|
|
|
440 |
var stylesheet = this.document.createElement("link");
|
|
|
441 |
with (stylesheet) {
|
|
|
442 |
rel = "stylesheet";
|
|
|
443 |
type = "text/css";
|
|
|
444 |
href = url;
|
|
|
445 |
}
|
|
|
446 |
head.appendChild(stylesheet);
|
|
|
447 |
}
|
|
|
448 |
}, removeStyleSheet:function (uri) {
|
|
|
449 |
var url = uri.toString();
|
|
|
450 |
if (url.charAt(0) == "." || (url.charAt(0) != "/" && !uri.host)) {
|
|
|
451 |
url = (new dojo.uri.Uri(dojo.global().location, url)).toString();
|
|
|
452 |
}
|
|
|
453 |
var index = dojo.lang.find(this.editingAreaStyleSheets, url);
|
|
|
454 |
if (index == -1) {
|
|
|
455 |
dojo.debug("dojo.widget.RichText.removeStyleSheet: Style sheet " + url + " is not applied to the editing area so it can not be removed!");
|
|
|
456 |
return;
|
|
|
457 |
}
|
|
|
458 |
delete this.editingAreaStyleSheets[index];
|
|
|
459 |
var links = this.document.getElementsByTagName("link");
|
|
|
460 |
for (var i = 0; i < links.length; i++) {
|
|
|
461 |
if (links[i].href == url) {
|
|
|
462 |
if (dojo.render.html.ie) {
|
|
|
463 |
links[i].href = "";
|
|
|
464 |
}
|
|
|
465 |
dojo.html.removeNode(links[i]);
|
|
|
466 |
break;
|
|
|
467 |
}
|
|
|
468 |
}
|
|
|
469 |
}, _drawObject:function (html) {
|
|
|
470 |
this.object = dojo.html.createExternalElement(dojo.doc(), "object");
|
|
|
471 |
with (this.object) {
|
|
|
472 |
classid = "clsid:2D360201-FFF5-11D1-8D03-00A0C959BC0A";
|
|
|
473 |
width = this.inheritWidth ? this._oldWidth : "100%";
|
|
|
474 |
style.height = this.height ? this.height : (this._oldHeight + "px");
|
|
|
475 |
Scrollbars = this.height ? true : false;
|
|
|
476 |
Appearance = this._activeX.appearance.flat;
|
|
|
477 |
}
|
|
|
478 |
this.editorObject = this.object;
|
|
|
479 |
this.editingArea.appendChild(this.object);
|
|
|
480 |
this.object.attachEvent("DocumentComplete", dojo.lang.hitch(this, "onLoad"));
|
|
|
481 |
dojo.lang.forEach(this.events, function (e) {
|
|
|
482 |
this.object.attachEvent(e.toLowerCase(), dojo.lang.hitch(this, e));
|
|
|
483 |
}, this);
|
|
|
484 |
this.object.DocumentHTML = "<!doctype HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">" + "<html><title></title>" + "<style type=\"text/css\">" + " body,html { padding: 0; margin: 0; }" + (this.height ? "" : " body, { overflow: hidden; }") + "</style>" + "<body><div>" + html + "<div></body></html>";
|
|
|
485 |
this._cacheLocalBlockFormatNames();
|
|
|
486 |
}, _local2NativeFormatNames:{}, _native2LocalFormatNames:{}, _cacheLocalBlockFormatNames:function () {
|
|
|
487 |
if (!this._native2LocalFormatNames["p"]) {
|
|
|
488 |
var obj = this.object;
|
|
|
489 |
var error = false;
|
|
|
490 |
if (!obj) {
|
|
|
491 |
try {
|
|
|
492 |
obj = dojo.html.createExternalElement(dojo.doc(), "object");
|
|
|
493 |
obj.classid = "clsid:2D360201-FFF5-11D1-8D03-00A0C959BC0A";
|
|
|
494 |
dojo.body().appendChild(obj);
|
|
|
495 |
obj.DocumentHTML = "<html><head></head><body></body></html>";
|
|
|
496 |
}
|
|
|
497 |
catch (e) {
|
|
|
498 |
error = true;
|
|
|
499 |
}
|
|
|
500 |
}
|
|
|
501 |
try {
|
|
|
502 |
var oNamesParm = new ActiveXObject("DEGetBlockFmtNamesParam.DEGetBlockFmtNamesParam");
|
|
|
503 |
obj.ExecCommand(this._activeX.command["getblockformatnames"], 0, oNamesParm);
|
|
|
504 |
var vbNamesArray = new VBArray(oNamesParm.Names);
|
|
|
505 |
var localFormats = vbNamesArray.toArray();
|
|
|
506 |
var nativeFormats = ["p", "pre", "address", "h1", "h2", "h3", "h4", "h5", "h6", "ol", "ul", "", "", "", "", "div"];
|
|
|
507 |
for (var i = 0; i < nativeFormats.length; ++i) {
|
|
|
508 |
if (nativeFormats[i].length > 0) {
|
|
|
509 |
this._local2NativeFormatNames[localFormats[i]] = nativeFormats[i];
|
|
|
510 |
this._native2LocalFormatNames[nativeFormats[i]] = localFormats[i];
|
|
|
511 |
}
|
|
|
512 |
}
|
|
|
513 |
}
|
|
|
514 |
catch (e) {
|
|
|
515 |
error = true;
|
|
|
516 |
}
|
|
|
517 |
if (obj && !this.object) {
|
|
|
518 |
dojo.body().removeChild(obj);
|
|
|
519 |
}
|
|
|
520 |
}
|
|
|
521 |
return !error;
|
|
|
522 |
}, _isResized:function () {
|
|
|
523 |
return false;
|
|
|
524 |
}, onLoad:function (e) {
|
|
|
525 |
this.isLoaded = true;
|
|
|
526 |
if (this.object) {
|
|
|
527 |
this.document = this.object.DOM;
|
|
|
528 |
this.window = this.document.parentWindow;
|
|
|
529 |
this.editNode = this.document.body.firstChild;
|
|
|
530 |
this.editingArea.style.height = this.height ? this.height : this.minHeight;
|
|
|
531 |
if (!this.height) {
|
|
|
532 |
this.connect(this, "onDisplayChanged", "_updateHeight");
|
|
|
533 |
}
|
|
|
534 |
this.window._frameElement = this.object;
|
|
|
535 |
} else {
|
|
|
536 |
if (this.iframe && !dojo.render.html.ie) {
|
|
|
537 |
this.editNode = this.document.body;
|
|
|
538 |
if (!this.height) {
|
|
|
539 |
this.connect(this, "onDisplayChanged", "_updateHeight");
|
|
|
540 |
}
|
|
|
541 |
try {
|
|
|
542 |
this.document.execCommand("useCSS", false, true);
|
|
|
543 |
this.document.execCommand("styleWithCSS", false, false);
|
|
|
544 |
}
|
|
|
545 |
catch (e2) {
|
|
|
546 |
}
|
|
|
547 |
if (dojo.render.html.safari) {
|
|
|
548 |
this.connect(this.editNode, "onblur", "onBlur");
|
|
|
549 |
this.connect(this.editNode, "onfocus", "onFocus");
|
|
|
550 |
this.connect(this.editNode, "onclick", "onFocus");
|
|
|
551 |
this.interval = setInterval(dojo.lang.hitch(this, "onDisplayChanged"), 750);
|
|
|
552 |
} else {
|
|
|
553 |
if (dojo.render.html.mozilla || dojo.render.html.opera) {
|
|
|
554 |
var doc = this.document;
|
|
|
555 |
var addListener = dojo.event.browser.addListener;
|
|
|
556 |
var self = this;
|
|
|
557 |
dojo.lang.forEach(this.events, function (e) {
|
|
|
558 |
var l = addListener(self.document, e.substr(2).toLowerCase(), dojo.lang.hitch(self, e));
|
|
|
559 |
if (e == "onBlur") {
|
|
|
560 |
var unBlur = {unBlur:function (e) {
|
|
|
561 |
dojo.event.browser.removeListener(doc, "blur", l);
|
|
|
562 |
}};
|
|
|
563 |
dojo.event.connect("before", self, "close", unBlur, "unBlur");
|
|
|
564 |
}
|
|
|
565 |
});
|
|
|
566 |
}
|
|
|
567 |
}
|
|
|
568 |
} else {
|
|
|
569 |
if (dojo.render.html.ie) {
|
|
|
570 |
if (!this.height) {
|
|
|
571 |
this.connect(this, "onDisplayChanged", "_updateHeight");
|
|
|
572 |
}
|
|
|
573 |
this.editNode.style.zoom = 1;
|
|
|
574 |
}
|
|
|
575 |
}
|
|
|
576 |
}
|
|
|
577 |
this._applyEditingAreaStyleSheets();
|
|
|
578 |
if (this.focusOnLoad) {
|
|
|
579 |
this.focus();
|
|
|
580 |
}
|
|
|
581 |
this.onDisplayChanged(e);
|
|
|
582 |
if (this.onLoadDeferred) {
|
|
|
583 |
this.onLoadDeferred.callback(true);
|
|
|
584 |
}
|
|
|
585 |
}, onKeyDown:function (e) {
|
|
|
586 |
if ((!e) && (this.object)) {
|
|
|
587 |
e = dojo.event.browser.fixEvent(this.window.event);
|
|
|
588 |
}
|
|
|
589 |
if ((dojo.render.html.ie) && (e.keyCode == e.KEY_TAB)) {
|
|
|
590 |
e.preventDefault();
|
|
|
591 |
e.stopPropagation();
|
|
|
592 |
this.execCommand((e.shiftKey ? "outdent" : "indent"));
|
|
|
593 |
} else {
|
|
|
594 |
if (dojo.render.html.ie) {
|
|
|
595 |
if ((65 <= e.keyCode) && (e.keyCode <= 90)) {
|
|
|
596 |
e.charCode = e.keyCode;
|
|
|
597 |
this.onKeyPress(e);
|
|
|
598 |
}
|
|
|
599 |
}
|
|
|
600 |
}
|
|
|
601 |
}, onKeyUp:function (e) {
|
|
|
602 |
return;
|
|
|
603 |
}, KEY_CTRL:1, onKeyPress:function (e) {
|
|
|
604 |
if ((!e) && (this.object)) {
|
|
|
605 |
e = dojo.event.browser.fixEvent(this.window.event);
|
|
|
606 |
}
|
|
|
607 |
var modifiers = e.ctrlKey ? this.KEY_CTRL : 0;
|
|
|
608 |
if (this._keyHandlers[e.key]) {
|
|
|
609 |
var handlers = this._keyHandlers[e.key], i = 0, handler;
|
|
|
610 |
while (handler = handlers[i++]) {
|
|
|
611 |
if (modifiers == handler.modifiers) {
|
|
|
612 |
e.preventDefault();
|
|
|
613 |
handler.handler.call(this);
|
|
|
614 |
break;
|
|
|
615 |
}
|
|
|
616 |
}
|
|
|
617 |
}
|
|
|
618 |
dojo.lang.setTimeout(this, this.onKeyPressed, 1, e);
|
|
|
619 |
}, addKeyHandler:function (key, modifiers, handler) {
|
|
|
620 |
if (!(this._keyHandlers[key] instanceof Array)) {
|
|
|
621 |
this._keyHandlers[key] = [];
|
|
|
622 |
}
|
|
|
623 |
this._keyHandlers[key].push({modifiers:modifiers || 0, handler:handler});
|
|
|
624 |
}, onKeyPressed:function (e) {
|
|
|
625 |
this.onDisplayChanged();
|
|
|
626 |
}, onClick:function (e) {
|
|
|
627 |
this.onDisplayChanged(e);
|
|
|
628 |
}, onBlur:function (e) {
|
|
|
629 |
}, _initialFocus:true, onFocus:function (e) {
|
|
|
630 |
if ((dojo.render.html.mozilla) && (this._initialFocus)) {
|
|
|
631 |
this._initialFocus = false;
|
|
|
632 |
if (dojo.string.trim(this.editNode.innerHTML) == " ") {
|
|
|
633 |
this.placeCursorAtStart();
|
|
|
634 |
}
|
|
|
635 |
}
|
|
|
636 |
}, blur:function () {
|
|
|
637 |
if (this.iframe) {
|
|
|
638 |
this.window.blur();
|
|
|
639 |
} else {
|
|
|
640 |
if (this.object) {
|
|
|
641 |
this.document.body.blur();
|
|
|
642 |
} else {
|
|
|
643 |
if (this.editNode) {
|
|
|
644 |
this.editNode.blur();
|
|
|
645 |
}
|
|
|
646 |
}
|
|
|
647 |
}
|
|
|
648 |
}, focus:function () {
|
|
|
649 |
if (this.iframe && !dojo.render.html.ie) {
|
|
|
650 |
this.window.focus();
|
|
|
651 |
} else {
|
|
|
652 |
if (this.object) {
|
|
|
653 |
this.document.focus();
|
|
|
654 |
} else {
|
|
|
655 |
if (this.editNode && this.editNode.focus) {
|
|
|
656 |
this.editNode.focus();
|
|
|
657 |
} else {
|
|
|
658 |
dojo.debug("Have no idea how to focus into the editor!");
|
|
|
659 |
}
|
|
|
660 |
}
|
|
|
661 |
}
|
|
|
662 |
}, onDisplayChanged:function (e) {
|
|
|
663 |
}, _activeX:{command:{bold:5000, italic:5023, underline:5048, justifycenter:5024, justifyleft:5025, justifyright:5026, cut:5003, copy:5002, paste:5032, "delete":5004, undo:5049, redo:5033, removeformat:5034, selectall:5035, unlink:5050, indent:5018, outdent:5031, insertorderedlist:5030, insertunorderedlist:5051, inserttable:5022, insertcell:5019, insertcol:5020, insertrow:5021, deletecells:5005, deletecols:5006, deleterows:5007, mergecells:5029, splitcell:5047, setblockformat:5043, getblockformat:5011, getblockformatnames:5012, setfontname:5044, getfontname:5013, setfontsize:5045, getfontsize:5014, setbackcolor:5042, getbackcolor:5010, setforecolor:5046, getforecolor:5015, findtext:5008, font:5009, hyperlink:5016, image:5017, lockelement:5027, makeabsolute:5028, sendbackward:5036, bringforward:5037, sendbelowtext:5038, bringabovetext:5039, sendtoback:5040, bringtofront:5041, properties:5052}, ui:{"default":0, prompt:1, noprompt:2}, status:{notsupported:0, disabled:1, enabled:3, latched:7, ninched:11}, appearance:{flat:0, inset:1}, state:{unchecked:0, checked:1, gray:2}}, _normalizeCommand:function (cmd) {
|
|
|
664 |
var drh = dojo.render.html;
|
|
|
665 |
var command = cmd.toLowerCase();
|
|
|
666 |
if (command == "formatblock") {
|
|
|
667 |
if (drh.safari) {
|
|
|
668 |
command = "heading";
|
|
|
669 |
}
|
|
|
670 |
} else {
|
|
|
671 |
if (this.object) {
|
|
|
672 |
switch (command) {
|
|
|
673 |
case "createlink":
|
|
|
674 |
command = "hyperlink";
|
|
|
675 |
break;
|
|
|
676 |
case "insertimage":
|
|
|
677 |
command = "image";
|
|
|
678 |
break;
|
|
|
679 |
}
|
|
|
680 |
} else {
|
|
|
681 |
if (command == "hilitecolor" && !drh.mozilla) {
|
|
|
682 |
command = "backcolor";
|
|
|
683 |
}
|
|
|
684 |
}
|
|
|
685 |
}
|
|
|
686 |
return command;
|
|
|
687 |
}, _safariIsLeopard:function () {
|
|
|
688 |
var gt420 = false;
|
|
|
689 |
if (dojo.render.html.safari) {
|
|
|
690 |
var tmp = dojo.render.html.UA.split("AppleWebKit/")[1];
|
|
|
691 |
var ver = parseFloat(tmp.split(" ")[0]);
|
|
|
692 |
if (ver >= 420) {
|
|
|
693 |
gt420 = true;
|
|
|
694 |
}
|
|
|
695 |
}
|
|
|
696 |
return gt420;
|
|
|
697 |
}, queryCommandAvailable:function (command) {
|
|
|
698 |
var ie = 1;
|
|
|
699 |
var mozilla = 1 << 1;
|
|
|
700 |
var safari = 1 << 2;
|
|
|
701 |
var opera = 1 << 3;
|
|
|
702 |
var safari420 = 1 << 4;
|
|
|
703 |
var gt420 = this._safariIsLeopard();
|
|
|
704 |
function isSupportedBy(browsers) {
|
|
|
705 |
return {ie:Boolean(browsers & ie), mozilla:Boolean(browsers & mozilla), safari:Boolean(browsers & safari), safari420:Boolean(browsers & safari420), opera:Boolean(browsers & opera)};
|
|
|
706 |
}
|
|
|
707 |
var supportedBy = null;
|
|
|
708 |
switch (command.toLowerCase()) {
|
|
|
709 |
case "bold":
|
|
|
710 |
case "italic":
|
|
|
711 |
case "underline":
|
|
|
712 |
case "subscript":
|
|
|
713 |
case "superscript":
|
|
|
714 |
case "fontname":
|
|
|
715 |
case "fontsize":
|
|
|
716 |
case "forecolor":
|
|
|
717 |
case "hilitecolor":
|
|
|
718 |
case "justifycenter":
|
|
|
719 |
case "justifyfull":
|
|
|
720 |
case "justifyleft":
|
|
|
721 |
case "justifyright":
|
|
|
722 |
case "delete":
|
|
|
723 |
case "selectall":
|
|
|
724 |
supportedBy = isSupportedBy(mozilla | ie | safari | opera);
|
|
|
725 |
break;
|
|
|
726 |
case "createlink":
|
|
|
727 |
case "unlink":
|
|
|
728 |
case "removeformat":
|
|
|
729 |
case "inserthorizontalrule":
|
|
|
730 |
case "insertimage":
|
|
|
731 |
case "insertorderedlist":
|
|
|
732 |
case "insertunorderedlist":
|
|
|
733 |
case "indent":
|
|
|
734 |
case "outdent":
|
|
|
735 |
case "formatblock":
|
|
|
736 |
case "inserthtml":
|
|
|
737 |
case "undo":
|
|
|
738 |
case "redo":
|
|
|
739 |
case "strikethrough":
|
|
|
740 |
supportedBy = isSupportedBy(mozilla | ie | opera | safari420);
|
|
|
741 |
break;
|
|
|
742 |
case "blockdirltr":
|
|
|
743 |
case "blockdirrtl":
|
|
|
744 |
case "dirltr":
|
|
|
745 |
case "dirrtl":
|
|
|
746 |
case "inlinedirltr":
|
|
|
747 |
case "inlinedirrtl":
|
|
|
748 |
supportedBy = isSupportedBy(ie);
|
|
|
749 |
break;
|
|
|
750 |
case "cut":
|
|
|
751 |
case "copy":
|
|
|
752 |
case "paste":
|
|
|
753 |
supportedBy = isSupportedBy(ie | mozilla | safari420);
|
|
|
754 |
break;
|
|
|
755 |
case "inserttable":
|
|
|
756 |
supportedBy = isSupportedBy(mozilla | (this.object ? ie : 0));
|
|
|
757 |
break;
|
|
|
758 |
case "insertcell":
|
|
|
759 |
case "insertcol":
|
|
|
760 |
case "insertrow":
|
|
|
761 |
case "deletecells":
|
|
|
762 |
case "deletecols":
|
|
|
763 |
case "deleterows":
|
|
|
764 |
case "mergecells":
|
|
|
765 |
case "splitcell":
|
|
|
766 |
supportedBy = isSupportedBy(this.object ? ie : 0);
|
|
|
767 |
break;
|
|
|
768 |
default:
|
|
|
769 |
return false;
|
|
|
770 |
}
|
|
|
771 |
return (dojo.render.html.ie && supportedBy.ie) || (dojo.render.html.mozilla && supportedBy.mozilla) || (dojo.render.html.safari && supportedBy.safari) || (gt420 && supportedBy.safari420) || (dojo.render.html.opera && supportedBy.opera);
|
|
|
772 |
}, execCommand:function (command, argument) {
|
|
|
773 |
var returnValue;
|
|
|
774 |
this.focus();
|
|
|
775 |
command = this._normalizeCommand(command);
|
|
|
776 |
if (argument != undefined) {
|
|
|
777 |
if (command == "heading") {
|
|
|
778 |
throw new Error("unimplemented");
|
|
|
779 |
} else {
|
|
|
780 |
if (command == "formatblock") {
|
|
|
781 |
if (this.object) {
|
|
|
782 |
argument = this._native2LocalFormatNames[argument];
|
|
|
783 |
} else {
|
|
|
784 |
if (dojo.render.html.ie) {
|
|
|
785 |
argument = "<" + argument + ">";
|
|
|
786 |
}
|
|
|
787 |
}
|
|
|
788 |
}
|
|
|
789 |
}
|
|
|
790 |
}
|
|
|
791 |
if (this.object) {
|
|
|
792 |
switch (command) {
|
|
|
793 |
case "hilitecolor":
|
|
|
794 |
command = "setbackcolor";
|
|
|
795 |
break;
|
|
|
796 |
case "forecolor":
|
|
|
797 |
case "backcolor":
|
|
|
798 |
case "fontsize":
|
|
|
799 |
case "fontname":
|
|
|
800 |
command = "set" + command;
|
|
|
801 |
break;
|
|
|
802 |
case "formatblock":
|
|
|
803 |
command = "setblockformat";
|
|
|
804 |
}
|
|
|
805 |
if (command == "strikethrough") {
|
|
|
806 |
command = "inserthtml";
|
|
|
807 |
var range = this.document.selection.createRange();
|
|
|
808 |
if (!range.htmlText) {
|
|
|
809 |
return;
|
|
|
810 |
}
|
|
|
811 |
argument = range.htmlText.strike();
|
|
|
812 |
} else {
|
|
|
813 |
if (command == "inserthorizontalrule") {
|
|
|
814 |
command = "inserthtml";
|
|
|
815 |
argument = "<hr>";
|
|
|
816 |
}
|
|
|
817 |
}
|
|
|
818 |
if (command == "inserthtml") {
|
|
|
819 |
var range = this.document.selection.createRange();
|
|
|
820 |
if (this.document.selection.type.toUpperCase() == "CONTROL") {
|
|
|
821 |
for (var i = 0; i < range.length; i++) {
|
|
|
822 |
range.item(i).outerHTML = argument;
|
|
|
823 |
}
|
|
|
824 |
} else {
|
|
|
825 |
range.pasteHTML(argument);
|
|
|
826 |
range.select();
|
|
|
827 |
}
|
|
|
828 |
returnValue = true;
|
|
|
829 |
} else {
|
|
|
830 |
if (arguments.length == 1) {
|
|
|
831 |
returnValue = this.object.ExecCommand(this._activeX.command[command], this._activeX.ui.noprompt);
|
|
|
832 |
} else {
|
|
|
833 |
returnValue = this.object.ExecCommand(this._activeX.command[command], this._activeX.ui.noprompt, argument);
|
|
|
834 |
}
|
|
|
835 |
}
|
|
|
836 |
} else {
|
|
|
837 |
if (command == "inserthtml") {
|
|
|
838 |
if (dojo.render.html.ie) {
|
|
|
839 |
var insertRange = this.document.selection.createRange();
|
|
|
840 |
insertRange.pasteHTML(argument);
|
|
|
841 |
insertRange.select();
|
|
|
842 |
return true;
|
|
|
843 |
} else {
|
|
|
844 |
return this.document.execCommand(command, false, argument);
|
|
|
845 |
}
|
|
|
846 |
} else {
|
|
|
847 |
if ((command == "unlink") && (this.queryCommandEnabled("unlink")) && (dojo.render.html.mozilla)) {
|
|
|
848 |
var selection = this.window.getSelection();
|
|
|
849 |
var selectionRange = selection.getRangeAt(0);
|
|
|
850 |
var selectionStartContainer = selectionRange.startContainer;
|
|
|
851 |
var selectionStartOffset = selectionRange.startOffset;
|
|
|
852 |
var selectionEndContainer = selectionRange.endContainer;
|
|
|
853 |
var selectionEndOffset = selectionRange.endOffset;
|
|
|
854 |
var a = dojo.withGlobal(this.window, "getAncestorElement", dojo.html.selection, ["a"]);
|
|
|
855 |
dojo.withGlobal(this.window, "selectElement", dojo.html.selection, [a]);
|
|
|
856 |
returnValue = this.document.execCommand("unlink", false, null);
|
|
|
857 |
var selectionRange = this.document.createRange();
|
|
|
858 |
selectionRange.setStart(selectionStartContainer, selectionStartOffset);
|
|
|
859 |
selectionRange.setEnd(selectionEndContainer, selectionEndOffset);
|
|
|
860 |
selection.removeAllRanges();
|
|
|
861 |
selection.addRange(selectionRange);
|
|
|
862 |
return returnValue;
|
|
|
863 |
} else {
|
|
|
864 |
if ((command == "hilitecolor") && (dojo.render.html.mozilla)) {
|
|
|
865 |
this.document.execCommand("useCSS", false, false);
|
|
|
866 |
returnValue = this.document.execCommand(command, false, argument);
|
|
|
867 |
this.document.execCommand("useCSS", false, true);
|
|
|
868 |
} else {
|
|
|
869 |
if ((dojo.render.html.ie) && ((command == "backcolor") || (command == "forecolor"))) {
|
|
|
870 |
argument = arguments.length > 1 ? argument : null;
|
|
|
871 |
returnValue = this.document.execCommand(command, false, argument);
|
|
|
872 |
} else {
|
|
|
873 |
argument = arguments.length > 1 ? argument : null;
|
|
|
874 |
if (argument || command != "createlink") {
|
|
|
875 |
returnValue = this.document.execCommand(command, false, argument);
|
|
|
876 |
}
|
|
|
877 |
}
|
|
|
878 |
}
|
|
|
879 |
}
|
|
|
880 |
}
|
|
|
881 |
}
|
|
|
882 |
this.onDisplayChanged();
|
|
|
883 |
return returnValue;
|
|
|
884 |
}, queryCommandEnabled:function (command) {
|
|
|
885 |
command = this._normalizeCommand(command);
|
|
|
886 |
if (this.object) {
|
|
|
887 |
switch (command) {
|
|
|
888 |
case "hilitecolor":
|
|
|
889 |
command = "setbackcolor";
|
|
|
890 |
break;
|
|
|
891 |
case "forecolor":
|
|
|
892 |
case "backcolor":
|
|
|
893 |
case "fontsize":
|
|
|
894 |
case "fontname":
|
|
|
895 |
command = "set" + command;
|
|
|
896 |
break;
|
|
|
897 |
case "formatblock":
|
|
|
898 |
command = "setblockformat";
|
|
|
899 |
break;
|
|
|
900 |
case "strikethrough":
|
|
|
901 |
command = "bold";
|
|
|
902 |
break;
|
|
|
903 |
case "inserthorizontalrule":
|
|
|
904 |
return true;
|
|
|
905 |
}
|
|
|
906 |
if (typeof this._activeX.command[command] == "undefined") {
|
|
|
907 |
return false;
|
|
|
908 |
}
|
|
|
909 |
var status = this.object.QueryStatus(this._activeX.command[command]);
|
|
|
910 |
return ((status != this._activeX.status.notsupported) && (status != this._activeX.status.disabled));
|
|
|
911 |
} else {
|
|
|
912 |
if (dojo.render.html.mozilla) {
|
|
|
913 |
if (command == "unlink") {
|
|
|
914 |
return dojo.withGlobal(this.window, "hasAncestorElement", dojo.html.selection, ["a"]);
|
|
|
915 |
} else {
|
|
|
916 |
if (command == "inserttable") {
|
|
|
917 |
return true;
|
|
|
918 |
}
|
|
|
919 |
}
|
|
|
920 |
}
|
|
|
921 |
var elem = (dojo.render.html.ie) ? this.document.selection.createRange() : this.document;
|
|
|
922 |
return elem.queryCommandEnabled(command);
|
|
|
923 |
}
|
|
|
924 |
}, queryCommandState:function (command) {
|
|
|
925 |
command = this._normalizeCommand(command);
|
|
|
926 |
if (this.object) {
|
|
|
927 |
if (command == "forecolor") {
|
|
|
928 |
command = "setforecolor";
|
|
|
929 |
} else {
|
|
|
930 |
if (command == "backcolor") {
|
|
|
931 |
command = "setbackcolor";
|
|
|
932 |
} else {
|
|
|
933 |
if (command == "strikethrough") {
|
|
|
934 |
return dojo.withGlobal(this.window, "hasAncestorElement", dojo.html.selection, ["strike"]);
|
|
|
935 |
} else {
|
|
|
936 |
if (command == "inserthorizontalrule") {
|
|
|
937 |
return false;
|
|
|
938 |
}
|
|
|
939 |
}
|
|
|
940 |
}
|
|
|
941 |
}
|
|
|
942 |
if (typeof this._activeX.command[command] == "undefined") {
|
|
|
943 |
return null;
|
|
|
944 |
}
|
|
|
945 |
var status = this.object.QueryStatus(this._activeX.command[command]);
|
|
|
946 |
return ((status == this._activeX.status.latched) || (status == this._activeX.status.ninched));
|
|
|
947 |
} else {
|
|
|
948 |
return this.document.queryCommandState(command);
|
|
|
949 |
}
|
|
|
950 |
}, queryCommandValue:function (command) {
|
|
|
951 |
command = this._normalizeCommand(command);
|
|
|
952 |
if (this.object) {
|
|
|
953 |
switch (command) {
|
|
|
954 |
case "forecolor":
|
|
|
955 |
case "backcolor":
|
|
|
956 |
case "fontsize":
|
|
|
957 |
case "fontname":
|
|
|
958 |
command = "get" + command;
|
|
|
959 |
return this.object.execCommand(this._activeX.command[command], this._activeX.ui.noprompt);
|
|
|
960 |
case "formatblock":
|
|
|
961 |
var retvalue = this.object.execCommand(this._activeX.command["getblockformat"], this._activeX.ui.noprompt);
|
|
|
962 |
if (retvalue) {
|
|
|
963 |
return this._local2NativeFormatNames[retvalue];
|
|
|
964 |
}
|
|
|
965 |
}
|
|
|
966 |
} else {
|
|
|
967 |
if (dojo.render.html.ie && command == "formatblock") {
|
|
|
968 |
return this._local2NativeFormatNames[this.document.queryCommandValue(command)] || this.document.queryCommandValue(command);
|
|
|
969 |
}
|
|
|
970 |
return this.document.queryCommandValue(command);
|
|
|
971 |
}
|
|
|
972 |
}, placeCursorAtStart:function () {
|
|
|
973 |
this.focus();
|
|
|
974 |
if (dojo.render.html.moz && this.editNode.firstChild && this.editNode.firstChild.nodeType != dojo.dom.TEXT_NODE) {
|
|
|
975 |
dojo.withGlobal(this.window, "selectElementChildren", dojo.html.selection, [this.editNode.firstChild]);
|
|
|
976 |
} else {
|
|
|
977 |
dojo.withGlobal(this.window, "selectElementChildren", dojo.html.selection, [this.editNode]);
|
|
|
978 |
}
|
|
|
979 |
dojo.withGlobal(this.window, "collapse", dojo.html.selection, [true]);
|
|
|
980 |
}, placeCursorAtEnd:function () {
|
|
|
981 |
this.focus();
|
|
|
982 |
if (dojo.render.html.moz && this.editNode.lastChild && this.editNode.lastChild.nodeType != dojo.dom.TEXT_NODE) {
|
|
|
983 |
dojo.withGlobal(this.window, "selectElementChildren", dojo.html.selection, [this.editNode.lastChild]);
|
|
|
984 |
} else {
|
|
|
985 |
dojo.withGlobal(this.window, "selectElementChildren", dojo.html.selection, [this.editNode]);
|
|
|
986 |
}
|
|
|
987 |
dojo.withGlobal(this.window, "collapse", dojo.html.selection, [false]);
|
|
|
988 |
}, replaceEditorContent:function (html) {
|
|
|
989 |
html = this._preFilterContent(html);
|
|
|
990 |
if (this.isClosed) {
|
|
|
991 |
this.domNode.innerHTML = html;
|
|
|
992 |
} else {
|
|
|
993 |
if (this.window && this.window.getSelection && !dojo.render.html.moz) {
|
|
|
994 |
this.editNode.innerHTML = html;
|
|
|
995 |
} else {
|
|
|
996 |
if ((this.window && this.window.getSelection) || (this.document && this.document.selection)) {
|
|
|
997 |
this.execCommand("selectall");
|
|
|
998 |
if (dojo.render.html.moz && !html) {
|
|
|
999 |
html = " ";
|
|
|
1000 |
}
|
|
|
1001 |
this.execCommand("inserthtml", html);
|
|
|
1002 |
}
|
|
|
1003 |
}
|
|
|
1004 |
}
|
|
|
1005 |
}, _preFilterContent:function (html) {
|
|
|
1006 |
var ec = html;
|
|
|
1007 |
dojo.lang.forEach(this.contentPreFilters, function (ef) {
|
|
|
1008 |
ec = ef(ec);
|
|
|
1009 |
});
|
|
|
1010 |
if (this.contentDomPreFilters.length > 0) {
|
|
|
1011 |
var dom = dojo.doc().createElement("div");
|
|
|
1012 |
dom.style.display = "none";
|
|
|
1013 |
dojo.body().appendChild(dom);
|
|
|
1014 |
dom.innerHTML = ec;
|
|
|
1015 |
dojo.lang.forEach(this.contentDomPreFilters, function (ef) {
|
|
|
1016 |
dom = ef(dom);
|
|
|
1017 |
});
|
|
|
1018 |
ec = dom.innerHTML;
|
|
|
1019 |
dojo.body().removeChild(dom);
|
|
|
1020 |
}
|
|
|
1021 |
return ec;
|
|
|
1022 |
}, _postFilterContent:function (html) {
|
|
|
1023 |
var ec = html;
|
|
|
1024 |
if (this.contentDomPostFilters.length > 0) {
|
|
|
1025 |
var dom = this.document.createElement("div");
|
|
|
1026 |
dom.innerHTML = ec;
|
|
|
1027 |
dojo.lang.forEach(this.contentDomPostFilters, function (ef) {
|
|
|
1028 |
dom = ef(dom);
|
|
|
1029 |
});
|
|
|
1030 |
ec = dom.innerHTML;
|
|
|
1031 |
}
|
|
|
1032 |
dojo.lang.forEach(this.contentPostFilters, function (ef) {
|
|
|
1033 |
ec = ef(ec);
|
|
|
1034 |
});
|
|
|
1035 |
return ec;
|
|
|
1036 |
}, _lastHeight:0, _updateHeight:function () {
|
|
|
1037 |
if (!this.isLoaded) {
|
|
|
1038 |
return;
|
|
|
1039 |
}
|
|
|
1040 |
if (this.height) {
|
|
|
1041 |
return;
|
|
|
1042 |
}
|
|
|
1043 |
var height = dojo.html.getBorderBox(this.editNode).height;
|
|
|
1044 |
if (!height) {
|
|
|
1045 |
height = dojo.html.getBorderBox(this.document.body).height;
|
|
|
1046 |
}
|
|
|
1047 |
if (height == 0) {
|
|
|
1048 |
dojo.debug("Can not figure out the height of the editing area!");
|
|
|
1049 |
return;
|
|
|
1050 |
}
|
|
|
1051 |
this._lastHeight = height;
|
|
|
1052 |
this.editorObject.style.height = this._lastHeight + "px";
|
|
|
1053 |
this.window.scrollTo(0, 0);
|
|
|
1054 |
}, _saveContent:function (e) {
|
|
|
1055 |
var saveTextarea = dojo.doc().getElementById("dojo.widget.RichText.savedContent");
|
|
|
1056 |
saveTextarea.value += this._SEPARATOR + this.saveName + ":" + this.getEditorContent();
|
|
|
1057 |
}, getEditorContent:function () {
|
|
|
1058 |
var ec = "";
|
|
|
1059 |
try {
|
|
|
1060 |
ec = (this._content.length > 0) ? this._content : this.editNode.innerHTML;
|
|
|
1061 |
if (dojo.string.trim(ec) == " ") {
|
|
|
1062 |
ec = "";
|
|
|
1063 |
}
|
|
|
1064 |
}
|
|
|
1065 |
catch (e) {
|
|
|
1066 |
}
|
|
|
1067 |
if (dojo.render.html.ie && !this.object) {
|
|
|
1068 |
var re = new RegExp("(?:<p> </p>[\n\r]*)+$", "i");
|
|
|
1069 |
ec = ec.replace(re, "");
|
|
|
1070 |
}
|
|
|
1071 |
ec = this._postFilterContent(ec);
|
|
|
1072 |
if (this.relativeImageUrls) {
|
|
|
1073 |
var siteBase = dojo.global().location.protocol + "//" + dojo.global().location.host;
|
|
|
1074 |
var pathBase = dojo.global().location.pathname;
|
|
|
1075 |
if (pathBase.match(/\/$/)) {
|
|
|
1076 |
} else {
|
|
|
1077 |
var pathParts = pathBase.split("/");
|
|
|
1078 |
if (pathParts.length) {
|
|
|
1079 |
pathParts.pop();
|
|
|
1080 |
}
|
|
|
1081 |
pathBase = pathParts.join("/") + "/";
|
|
|
1082 |
}
|
|
|
1083 |
var sameSite = new RegExp("(<img[^>]* src=[\"'])(" + siteBase + "(" + pathBase + ")?)", "ig");
|
|
|
1084 |
ec = ec.replace(sameSite, "$1");
|
|
|
1085 |
}
|
|
|
1086 |
return ec;
|
|
|
1087 |
}, close:function (save, force) {
|
|
|
1088 |
if (this.isClosed) {
|
|
|
1089 |
return false;
|
|
|
1090 |
}
|
|
|
1091 |
if (arguments.length == 0) {
|
|
|
1092 |
save = true;
|
|
|
1093 |
}
|
|
|
1094 |
this._content = this._postFilterContent(this.editNode.innerHTML);
|
|
|
1095 |
var changed = (this.savedContent != this._content);
|
|
|
1096 |
if (this.interval) {
|
|
|
1097 |
clearInterval(this.interval);
|
|
|
1098 |
}
|
|
|
1099 |
if (dojo.render.html.ie && !this.object) {
|
|
|
1100 |
dojo.event.browser.clean(this.editNode);
|
|
|
1101 |
}
|
|
|
1102 |
if (this.iframe) {
|
|
|
1103 |
delete this.iframe;
|
|
|
1104 |
}
|
|
|
1105 |
if (this.textarea) {
|
|
|
1106 |
with (this.textarea.style) {
|
|
|
1107 |
position = "";
|
|
|
1108 |
left = top = "";
|
|
|
1109 |
if (dojo.render.html.ie) {
|
|
|
1110 |
overflow = this.__overflow;
|
|
|
1111 |
this.__overflow = null;
|
|
|
1112 |
}
|
|
|
1113 |
}
|
|
|
1114 |
if (save) {
|
|
|
1115 |
this.textarea.value = this._content;
|
|
|
1116 |
} else {
|
|
|
1117 |
this.textarea.value = this.savedContent;
|
|
|
1118 |
}
|
|
|
1119 |
dojo.html.removeNode(this.domNode);
|
|
|
1120 |
this.domNode = this.textarea;
|
|
|
1121 |
} else {
|
|
|
1122 |
if (save) {
|
|
|
1123 |
if (dojo.render.html.moz) {
|
|
|
1124 |
var nc = dojo.doc().createElement("span");
|
|
|
1125 |
this.domNode.appendChild(nc);
|
|
|
1126 |
nc.innerHTML = this.editNode.innerHTML;
|
|
|
1127 |
} else {
|
|
|
1128 |
this.domNode.innerHTML = this._content;
|
|
|
1129 |
}
|
|
|
1130 |
} else {
|
|
|
1131 |
this.domNode.innerHTML = this.savedContent;
|
|
|
1132 |
}
|
|
|
1133 |
}
|
|
|
1134 |
dojo.html.removeClass(this.domNode, "RichTextEditable");
|
|
|
1135 |
this.isClosed = true;
|
|
|
1136 |
this.isLoaded = false;
|
|
|
1137 |
delete this.editNode;
|
|
|
1138 |
if (this.window._frameElement) {
|
|
|
1139 |
this.window._frameElement = null;
|
|
|
1140 |
}
|
|
|
1141 |
this.window = null;
|
|
|
1142 |
this.document = null;
|
|
|
1143 |
this.object = null;
|
|
|
1144 |
this.editingArea = null;
|
|
|
1145 |
this.editorObject = null;
|
|
|
1146 |
return changed;
|
|
|
1147 |
}, destroyRendering:function () {
|
|
|
1148 |
}, destroy:function () {
|
|
|
1149 |
this.destroyRendering();
|
|
|
1150 |
if (!this.isClosed) {
|
|
|
1151 |
this.close(false);
|
|
|
1152 |
}
|
|
|
1153 |
dojo.widget.RichText.superclass.destroy.call(this);
|
|
|
1154 |
}, connect:function (targetObj, targetFunc, thisFunc) {
|
|
|
1155 |
dojo.event.connect(targetObj, targetFunc, this, thisFunc);
|
|
|
1156 |
}, disconnect:function (targetObj, targetFunc, thisFunc) {
|
|
|
1157 |
dojo.event.disconnect(targetObj, targetFunc, this, thisFunc);
|
|
|
1158 |
}, disconnectAllWithRoot:function (targetObj) {
|
|
|
1159 |
dojo.deprecated("disconnectAllWithRoot", "is deprecated. No need to disconnect manually", "0.5");
|
|
|
1160 |
}, _fixContentForMoz:function (html) {
|
|
|
1161 |
html = html.replace(/<strong([ \>])/gi, "<b$1");
|
|
|
1162 |
html = html.replace(/<\/strong>/gi, "</b>");
|
|
|
1163 |
html = html.replace(/<em([ \>])/gi, "<i$1");
|
|
|
1164 |
html = html.replace(/<\/em>/gi, "</i>");
|
|
|
1165 |
return html;
|
|
|
1166 |
}});
|
|
|
1167 |
|