Editor2.js
上传用户:kimgenplus
上传日期:2016-06-05
资源大小:20877k
文件大小:24k
源码类别:

OA系统

开发平台:

Java

  1. /*
  2. Copyright (c) 2004-2006, The Dojo Foundation
  3. All Rights Reserved.
  4. Licensed under the Academic Free License version 2.1 or above OR the
  5. modified BSD license. For more information on Dojo licensing, see:
  6. http://dojotoolkit.org/community/licensing.shtml
  7. */
  8. dojo.provide("dojo.widget.Editor2");
  9. dojo.require("dojo.io.*");
  10. dojo.require("dojo.widget.RichText");
  11. dojo.require("dojo.widget.Editor2Toolbar");
  12. dojo.require("dojo.uri.cache");
  13. dojo.widget.Editor2Manager = new dojo.widget.HandlerManager;
  14. dojo.lang.mixin(dojo.widget.Editor2Manager, {_currentInstance:null, commandState:{Disabled:0, Latched:1, Enabled:2}, getCurrentInstance:function () {
  15. return this._currentInstance;
  16. }, setCurrentInstance:function (inst) {
  17. this._currentInstance = inst;
  18. }, getCommand:function (editor, name) {
  19. var oCommand;
  20. name = name.toLowerCase();
  21. for (var i = 0; i < this._registeredHandlers.length; i++) {
  22. oCommand = this._registeredHandlers[i](editor, name);
  23. if (oCommand) {
  24. return oCommand;
  25. }
  26. }
  27. switch (name) {
  28.   case "htmltoggle":
  29. oCommand = new dojo.widget.Editor2BrowserCommand(editor, name);
  30. break;
  31.   case "formatblock":
  32. oCommand = new dojo.widget.Editor2FormatBlockCommand(editor, name);
  33. break;
  34.   case "anchor":
  35. oCommand = new dojo.widget.Editor2Command(editor, name);
  36. break;
  37.   case "createlink":
  38. oCommand = new dojo.widget.Editor2DialogCommand(editor, name, {contentFile:"dojo.widget.Editor2Plugin.CreateLinkDialog", contentClass:"Editor2CreateLinkDialog", title:"Insert/Edit Link", width:"300px", height:"200px"});
  39. break;
  40.   case "insertimage":
  41. oCommand = new dojo.widget.Editor2DialogCommand(editor, name, {contentFile:"dojo.widget.Editor2Plugin.InsertImageDialog", contentClass:"Editor2InsertImageDialog", title:"Insert/Edit Image", width:"400px", height:"270px"});
  42. break;
  43.   default:
  44. var curtInst = this.getCurrentInstance();
  45. if ((curtInst && curtInst.queryCommandAvailable(name)) || (!curtInst && dojo.widget.Editor2.prototype.queryCommandAvailable(name))) {
  46. oCommand = new dojo.widget.Editor2BrowserCommand(editor, name);
  47. } else {
  48. dojo.debug("dojo.widget.Editor2Manager.getCommand: Unknown command " + name);
  49. return;
  50. }
  51. }
  52. return oCommand;
  53. }, destroy:function () {
  54. this._currentInstance = null;
  55. dojo.widget.HandlerManager.prototype.destroy.call(this);
  56. }});
  57. dojo.addOnUnload(dojo.widget.Editor2Manager, "destroy");
  58. dojo.lang.declare("dojo.widget.Editor2Command", null, function (editor, name) {
  59. this._editor = editor;
  60. this._updateTime = 0;
  61. this._name = name;
  62. }, {_text:"Unknown", execute:function (para) {
  63. dojo.unimplemented("dojo.widget.Editor2Command.execute");
  64. }, getText:function () {
  65. return this._text;
  66. }, getState:function () {
  67. return dojo.widget.Editor2Manager.commandState.Enabled;
  68. }, destroy:function () {
  69. }});
  70. dojo.widget.Editor2BrowserCommandNames = {"bold":"Bold", "copy":"Copy", "cut":"Cut", "Delete":"Delete", "indent":"Indent", "inserthorizontalrule":"Horizental Rule", "insertorderedlist":"Numbered List", "insertunorderedlist":"Bullet List", "italic":"Italic", "justifycenter":"Align Center", "justifyfull":"Justify", "justifyleft":"Align Left", "justifyright":"Align Right", "outdent":"Outdent", "paste":"Paste", "redo":"Redo", "removeformat":"Remove Format", "selectall":"Select All", "strikethrough":"Strikethrough", "subscript":"Subscript", "superscript":"Superscript", "underline":"Underline", "undo":"Undo", "unlink":"Remove Link", "createlink":"Create Link", "insertimage":"Insert Image", "htmltoggle":"HTML Source", "forecolor":"Foreground Color", "hilitecolor":"Background Color", "plainformatblock":"Paragraph Style", "formatblock":"Paragraph Style", "fontsize":"Font Size", "fontname":"Font Name"};
  71. dojo.lang.declare("dojo.widget.Editor2BrowserCommand", dojo.widget.Editor2Command, function (editor, name) {
  72. var text = dojo.widget.Editor2BrowserCommandNames[name.toLowerCase()];
  73. if (text) {
  74. this._text = text;
  75. }
  76. }, {execute:function (para) {
  77. this._editor.execCommand(this._name, para);
  78. }, getState:function () {
  79. if (this._editor._lastStateTimestamp > this._updateTime || this._state == undefined) {
  80. this._updateTime = this._editor._lastStateTimestamp;
  81. try {
  82. if (this._editor.queryCommandEnabled(this._name)) {
  83. if (this._editor.queryCommandState(this._name)) {
  84. this._state = dojo.widget.Editor2Manager.commandState.Latched;
  85. } else {
  86. this._state = dojo.widget.Editor2Manager.commandState.Enabled;
  87. }
  88. } else {
  89. this._state = dojo.widget.Editor2Manager.commandState.Disabled;
  90. }
  91. }
  92. catch (e) {
  93. this._state = dojo.widget.Editor2Manager.commandState.Enabled;
  94. }
  95. }
  96. return this._state;
  97. }, getValue:function () {
  98. try {
  99. return this._editor.queryCommandValue(this._name);
  100. }
  101. catch (e) {
  102. }
  103. }});
  104. dojo.lang.declare("dojo.widget.Editor2FormatBlockCommand", dojo.widget.Editor2BrowserCommand, {});
  105. dojo.require("dojo.widget.FloatingPane");
  106. dojo.widget.defineWidget("dojo.widget.Editor2Dialog", [dojo.widget.HtmlWidget, dojo.widget.FloatingPaneBase, dojo.widget.ModalDialogBase], {templateString:"<div id="${this.widgetId}" class="dojoFloatingPane">nt<span dojoattachpoint="tabStartOuter" dojoonfocus="trapTabs" dojoonblur="clearTrap"ttabindex="0"></span>nt<span dojoattachpoint="tabStart" dojoonfocus="trapTabs" dojoonblur="clearTrap" tabindex="0"></span>nt<div dojoAttachPoint="titleBar" class="dojoFloatingPaneTitleBar"  style="display:none">nt  t<img dojoAttachPoint="titleBarIcon"  class="dojoFloatingPaneTitleBarIcon">ntt<div dojoAttachPoint="closeAction" dojoAttachEvent="onClick:hide"n   t  ttclass="dojoFloatingPaneCloseIcon"></div>ntt<div dojoAttachPoint="restoreAction" dojoAttachEvent="onClick:restoreWindow"n   t  ttclass="dojoFloatingPaneRestoreIcon"></div>ntt<div dojoAttachPoint="maximizeAction" dojoAttachEvent="onClick:maximizeWindow"n   t  ttclass="dojoFloatingPaneMaximizeIcon"></div>ntt<div dojoAttachPoint="minimizeAction" dojoAttachEvent="onClick:minimizeWindow"n   t  ttclass="dojoFloatingPaneMinimizeIcon"></div>nt  t<div dojoAttachPoint="titleBarText" class="dojoFloatingPaneTitleText">${this.title}</div>nt</div>nnt<div id="${this.widgetId}_container" dojoAttachPoint="containerNode" class="dojoFloatingPaneClient"></div>nt<span dojoattachpoint="tabEnd" dojoonfocus="trapTabs" dojoonblur="clearTrap" tabindex="0"></span>nt<span dojoattachpoint="tabEndOuter" dojoonfocus="trapTabs" dojoonblur="clearTrap" tabindex="0"></span>nt<div dojoAttachPoint="resizeBar" class="dojoFloatingPaneResizebar" style="display:none"></div>n</div>n", modal:true, width:"", height:"", windowState:"minimized", displayCloseAction:true, contentFile:"", contentClass:"", fillInTemplate:function (args, frag) {
  107. this.fillInFloatingPaneTemplate(args, frag);
  108. dojo.widget.Editor2Dialog.superclass.fillInTemplate.call(this, args, frag);
  109. }, postCreate:function () {
  110. if (this.contentFile) {
  111. dojo.require(this.contentFile);
  112. }
  113. if (this.modal) {
  114. dojo.widget.ModalDialogBase.prototype.postCreate.call(this);
  115. } else {
  116. with (this.domNode.style) {
  117. zIndex = 999;
  118. display = "none";
  119. }
  120. }
  121. dojo.widget.FloatingPaneBase.prototype.postCreate.apply(this, arguments);
  122. dojo.widget.Editor2Dialog.superclass.postCreate.call(this);
  123. if (this.width && this.height) {
  124. with (this.domNode.style) {
  125. width = this.width;
  126. height = this.height;
  127. }
  128. }
  129. }, createContent:function () {
  130. if (!this.contentWidget && this.contentClass) {
  131. this.contentWidget = dojo.widget.createWidget(this.contentClass);
  132. this.addChild(this.contentWidget);
  133. }
  134. }, show:function () {
  135. if (!this.contentWidget) {
  136. dojo.widget.Editor2Dialog.superclass.show.apply(this, arguments);
  137. this.createContent();
  138. dojo.widget.Editor2Dialog.superclass.hide.call(this);
  139. }
  140. if (!this.contentWidget || !this.contentWidget.loadContent()) {
  141. return;
  142. }
  143. this.showFloatingPane();
  144. dojo.widget.Editor2Dialog.superclass.show.apply(this, arguments);
  145. if (this.modal) {
  146. this.showModalDialog();
  147. }
  148. if (this.modal) {
  149. this.bg.style.zIndex = this.domNode.style.zIndex - 1;
  150. }
  151. }, onShow:function () {
  152. dojo.widget.Editor2Dialog.superclass.onShow.call(this);
  153. this.onFloatingPaneShow();
  154. }, closeWindow:function () {
  155. this.hide();
  156. dojo.widget.Editor2Dialog.superclass.closeWindow.apply(this, arguments);
  157. }, hide:function () {
  158. if (this.modal) {
  159. this.hideModalDialog();
  160. }
  161. dojo.widget.Editor2Dialog.superclass.hide.call(this);
  162. }, checkSize:function () {
  163. if (this.isShowing()) {
  164. if (this.modal) {
  165. this._sizeBackground();
  166. }
  167. this.placeModalDialog();
  168. this.onResized();
  169. }
  170. }});
  171. dojo.widget.defineWidget("dojo.widget.Editor2DialogContent", dojo.widget.HtmlWidget, {widgetsInTemplate:true, loadContent:function () {
  172. return true;
  173. }, cancel:function () {
  174. this.parent.hide();
  175. }});
  176. dojo.lang.declare("dojo.widget.Editor2DialogCommand", dojo.widget.Editor2BrowserCommand, function (editor, name, dialogParas) {
  177. this.dialogParas = dialogParas;
  178. }, {execute:function () {
  179. if (!this.dialog) {
  180. if (!this.dialogParas.contentFile || !this.dialogParas.contentClass) {
  181. alert("contentFile and contentClass should be set for dojo.widget.Editor2DialogCommand.dialogParas!");
  182. return;
  183. }
  184. this.dialog = dojo.widget.createWidget("Editor2Dialog", this.dialogParas);
  185. dojo.body().appendChild(this.dialog.domNode);
  186. dojo.event.connect(this, "destroy", this.dialog, "destroy");
  187. }
  188. this.dialog.show();
  189. }, getText:function () {
  190. return this.dialogParas.title || dojo.widget.Editor2DialogCommand.superclass.getText.call(this);
  191. }});
  192. dojo.widget.Editor2ToolbarGroups = {};
  193. dojo.widget.defineWidget("dojo.widget.Editor2", dojo.widget.RichText, function () {
  194. this._loadedCommands = {};
  195. }, {toolbarAlwaysVisible:false, toolbarWidget:null, scrollInterval:null, toolbarTemplatePath:dojo.uri.cache.set(dojo.uri.moduleUri("dojo.widget", "templates/EditorToolbarOneline.html"), "<div class="EditorToolbarDomNode EditorToolbarSmallBg">nt<table cellpadding="1" cellspacing="0" border="0">ntt<tbody>nttt<tr valign="top" align="left">ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="htmltoggle">ntttttt<span class="dojoE2TBIcon" nttttttstyle="background-image: none; width: 30px;" >&lt;h&gt;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="copy">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Copy">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="paste">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Paste">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="undo">ntttttt<!-- FIXME: should we have the text "undo" here? -->ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Undo">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="redo">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Redo">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td isSpacer="true">nttttt<span class="iconContainer">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Sep"tstyle="width: 5px; min-width: 5px;"></span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="createlink">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Link">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="insertimage">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Image">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="inserthorizontalrule">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_HorizontalLine ">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="bold">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Bold">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="italic">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Italic">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="underline">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Underline">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="strikethrough">ntttttt<span ntttttttclass="dojoE2TBIcon dojoE2TBIcon_StrikeThrough">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td isSpacer="true">nttttt<span class="iconContainer">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Sep" ntttttttstyle="width: 5px; min-width: 5px;"></span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="insertunorderedlist">ntttttt<span ntttttttclass="dojoE2TBIcon dojoE2TBIcon_BulletedList">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="insertorderedlist">ntttttt<span ntttttttclass="dojoE2TBIcon dojoE2TBIcon_NumberedList">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td isSpacer="true">nttttt<span class="iconContainer">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Sep" style="width: 5px; min-width: 5px;"></span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="indent">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Indent" ntttttttunselectable="on">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="outdent">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Outdent" ntttttttunselectable="on">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td isSpacer="true">nttttt<span class="iconContainer">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Sep" style="width: 5px; min-width: 5px;"></span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="forecolor">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_TextColor" ntttttttunselectable="on">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="hilitecolor">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_BackgroundColor" ntttttttunselectable="on">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td isSpacer="true">nttttt<span class="iconContainer">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Sep" style="width: 5px; min-width: 5px;"></span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="justifyleft">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_LeftJustify">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="justifycenter">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_CenterJustify">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="justifyright">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_RightJustify">&nbsp;</span>nttttt</span>ntttt</td>ntttt<td>nttttt<span class="iconContainer dojoEditorToolbarItem" dojoETItemName="justifyfull">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_BlockJustify">&nbsp;</span>nttttt</span>ntttt</td>tntttt<td>nttttt<select class="dojoEditorToolbarItem" dojoETItemName="plainformatblock">ntttttt<!-- FIXME: using "p" here inserts a paragraph in most cases! -->ntttttt<option value="">-- format --</option>ntttttt<option value="p">Normal</option>ntttttt<option value="pre">Fixed Font</option>ntttttt<option value="h1">Main Heading</option>ntttttt<option value="h2">Section Heading</option>ntttttt<option value="h3">Sub-Heading</option>ntttttt<!-- <option value="blockquote">Block Quote</option> -->nttttt</select>ntttt</td>ntttt<td><!-- uncomment to enable save button -->nttttt<!-- save -->nttttt<!--span class="iconContainer dojoEditorToolbarItem" dojoETItemName="save">ntttttt<span class="dojoE2TBIcon dojoE2TBIcon_Save">&nbsp;</span>nttttt</span-->ntttt</td>ntttt<td width="*">&nbsp;</td>nttt</tr>ntt</tbody>nt</table>n</div>n"), toolbarTemplateCssPath:null, toolbarPlaceHolder:"", _inSourceMode:false, _htmlEditNode:null, toolbarGroup:"", shareToolbar:false, contextMenuGroupSet:"", editorOnLoad:function () {
  196. dojo.event.topic.publish("dojo.widget.Editor2::preLoadingToolbar", this);
  197. if (this.toolbarAlwaysVisible) {
  198. dojo.require("dojo.widget.Editor2Plugin.AlwaysShowToolbar");
  199. }
  200. if (this.toolbarWidget) {
  201. this.toolbarWidget.show();
  202. dojo.html.insertBefore(this.toolbarWidget.domNode, this.domNode.firstChild);
  203. } else {
  204. if (this.shareToolbar) {
  205. dojo.deprecated("Editor2:shareToolbar is deprecated in favor of toolbarGroup", "0.5");
  206. this.toolbarGroup = "defaultDojoToolbarGroup";
  207. }
  208. if (this.toolbarGroup) {
  209. if (dojo.widget.Editor2ToolbarGroups[this.toolbarGroup]) {
  210. this.toolbarWidget = dojo.widget.Editor2ToolbarGroups[this.toolbarGroup];
  211. }
  212. }
  213. if (!this.toolbarWidget) {
  214. var tbOpts = {shareGroup:this.toolbarGroup, parent:this};
  215. tbOpts.templateString = dojo.uri.cache.get(this.toolbarTemplatePath);
  216. if (this.toolbarTemplateCssPath) {
  217. tbOpts.templateCssPath = this.toolbarTemplateCssPath;
  218. tbOpts.templateCssString = dojo.uri.cache.get(this.toolbarTemplateCssPath);
  219. }
  220. if (this.toolbarPlaceHolder) {
  221. this.toolbarWidget = dojo.widget.createWidget("Editor2Toolbar", tbOpts, dojo.byId(this.toolbarPlaceHolder), "after");
  222. } else {
  223. this.toolbarWidget = dojo.widget.createWidget("Editor2Toolbar", tbOpts, this.domNode.firstChild, "before");
  224. }
  225. if (this.toolbarGroup) {
  226. dojo.widget.Editor2ToolbarGroups[this.toolbarGroup] = this.toolbarWidget;
  227. }
  228. dojo.event.connect(this, "close", this.toolbarWidget, "hide");
  229. this.toolbarLoaded();
  230. }
  231. }
  232. dojo.event.topic.registerPublisher("Editor2.clobberFocus", this, "clobberFocus");
  233. dojo.event.topic.subscribe("Editor2.clobberFocus", this, "setBlur");
  234. dojo.event.topic.publish("dojo.widget.Editor2::onLoad", this);
  235. }, toolbarLoaded:function () {
  236. }, registerLoadedPlugin:function (obj) {
  237. if (!this.loadedPlugins) {
  238. this.loadedPlugins = [];
  239. }
  240. this.loadedPlugins.push(obj);
  241. }, unregisterLoadedPlugin:function (obj) {
  242. for (var i in this.loadedPlugins) {
  243. if (this.loadedPlugins[i] === obj) {
  244. delete this.loadedPlugins[i];
  245. return;
  246. }
  247. }
  248. dojo.debug("dojo.widget.Editor2.unregisterLoadedPlugin: unknow plugin object: " + obj);
  249. }, execCommand:function (command, argument) {
  250. switch (command.toLowerCase()) {
  251.   case "htmltoggle":
  252. this.toggleHtmlEditing();
  253. break;
  254.   default:
  255. dojo.widget.Editor2.superclass.execCommand.apply(this, arguments);
  256. }
  257. }, queryCommandEnabled:function (command, argument) {
  258. switch (command.toLowerCase()) {
  259.   case "htmltoggle":
  260. return true;
  261.   default:
  262. if (this._inSourceMode) {
  263. return false;
  264. }
  265. return dojo.widget.Editor2.superclass.queryCommandEnabled.apply(this, arguments);
  266. }
  267. }, queryCommandState:function (command, argument) {
  268. switch (command.toLowerCase()) {
  269.   case "htmltoggle":
  270. return this._inSourceMode;
  271.   default:
  272. return dojo.widget.Editor2.superclass.queryCommandState.apply(this, arguments);
  273. }
  274. }, onClick:function (e) {
  275. dojo.widget.Editor2.superclass.onClick.call(this, e);
  276. if (dojo.widget.PopupManager) {
  277. if (!e) {
  278. e = this.window.event;
  279. }
  280. dojo.widget.PopupManager.onClick(e);
  281. }
  282. }, clobberFocus:function () {
  283. }, toggleHtmlEditing:function () {
  284. if (this === dojo.widget.Editor2Manager.getCurrentInstance()) {
  285. if (!this._inSourceMode) {
  286. var html = this.getEditorContent();
  287. this._inSourceMode = true;
  288. if (!this._htmlEditNode) {
  289. this._htmlEditNode = dojo.doc().createElement("textarea");
  290. dojo.html.insertAfter(this._htmlEditNode, this.editorObject);
  291. }
  292. this._htmlEditNode.style.display = "";
  293. this._htmlEditNode.style.width = "100%";
  294. this._htmlEditNode.style.height = dojo.html.getBorderBox(this.editNode).height + "px";
  295. this._htmlEditNode.value = html;
  296. with (this.editorObject.style) {
  297. position = "absolute";
  298. left = "-2000px";
  299. top = "-2000px";
  300. }
  301. } else {
  302. this._inSourceMode = false;
  303. this._htmlEditNode.blur();
  304. with (this.editorObject.style) {
  305. position = "";
  306. left = "";
  307. top = "";
  308. }
  309. var html = this._htmlEditNode.value;
  310. dojo.lang.setTimeout(this, "replaceEditorContent", 1, html);
  311. this._htmlEditNode.style.display = "none";
  312. this.focus();
  313. }
  314. this.onDisplayChanged(null, true);
  315. }
  316. }, setFocus:function () {
  317. if (dojo.widget.Editor2Manager.getCurrentInstance() === this) {
  318. return;
  319. }
  320. this.clobberFocus();
  321. dojo.widget.Editor2Manager.setCurrentInstance(this);
  322. }, setBlur:function () {
  323. }, saveSelection:function () {
  324. this._bookmark = null;
  325. this._bookmark = dojo.withGlobal(this.window, dojo.html.selection.getBookmark);
  326. }, restoreSelection:function () {
  327. if (this._bookmark) {
  328. this.focus();
  329. dojo.withGlobal(this.window, "moveToBookmark", dojo.html.selection, [this._bookmark]);
  330. this._bookmark = null;
  331. } else {
  332. dojo.debug("restoreSelection: no saved selection is found!");
  333. }
  334. }, _updateToolbarLastRan:null, _updateToolbarTimer:null, _updateToolbarFrequency:500, updateToolbar:function (force) {
  335. if ((!this.isLoaded) || (!this.toolbarWidget)) {
  336. return;
  337. }
  338. var diff = new Date() - this._updateToolbarLastRan;
  339. if ((!force) && (this._updateToolbarLastRan) && ((diff < this._updateToolbarFrequency))) {
  340. clearTimeout(this._updateToolbarTimer);
  341. var _this = this;
  342. this._updateToolbarTimer = setTimeout(function () {
  343. _this.updateToolbar();
  344. }, this._updateToolbarFrequency / 2);
  345. return;
  346. } else {
  347. this._updateToolbarLastRan = new Date();
  348. }
  349. if (dojo.widget.Editor2Manager.getCurrentInstance() !== this) {
  350. return;
  351. }
  352. this.toolbarWidget.update();
  353. }, destroy:function (finalize) {
  354. this._htmlEditNode = null;
  355. dojo.event.disconnect(this, "close", this.toolbarWidget, "hide");
  356. if (!finalize) {
  357. this.toolbarWidget.destroy();
  358. }
  359. dojo.widget.Editor2.superclass.destroy.call(this);
  360. }, _lastStateTimestamp:0, onDisplayChanged:function (e, forceUpdate) {
  361. this._lastStateTimestamp = (new Date()).getTime();
  362. dojo.widget.Editor2.superclass.onDisplayChanged.call(this, e);
  363. this.updateToolbar(forceUpdate);
  364. }, onLoad:function () {
  365. try {
  366. dojo.widget.Editor2.superclass.onLoad.call(this);
  367. }
  368. catch (e) {
  369. dojo.debug(e);
  370. }
  371. this.editorOnLoad();
  372. }, onFocus:function () {
  373. dojo.widget.Editor2.superclass.onFocus.call(this);
  374. this.setFocus();
  375. }, getEditorContent:function () {
  376. if (this._inSourceMode) {
  377. return this._htmlEditNode.value;
  378. }
  379. return dojo.widget.Editor2.superclass.getEditorContent.call(this);
  380. }, replaceEditorContent:function (html) {
  381. if (this._inSourceMode) {
  382. this._htmlEditNode.value = html;
  383. return;
  384. }
  385. dojo.widget.Editor2.superclass.replaceEditorContent.apply(this, arguments);
  386. }, getCommand:function (name) {
  387. if (this._loadedCommands[name]) {
  388. return this._loadedCommands[name];
  389. }
  390. var cmd = dojo.widget.Editor2Manager.getCommand(this, name);
  391. this._loadedCommands[name] = cmd;
  392. return cmd;
  393. }, shortcuts:[["bold"], ["italic"], ["underline"], ["selectall", "a"], ["insertunorderedlist", "\"]], setupDefaultShortcuts:function () {
  394. var exec = function (cmd) {
  395. return function () {
  396. cmd.execute();
  397. };
  398. };
  399. var self = this;
  400. dojo.lang.forEach(this.shortcuts, function (item) {
  401. var cmd = self.getCommand(item[0]);
  402. if (cmd) {
  403. self.addKeyHandler(item[1] ? item[1] : item[0].charAt(0), item[2] == undefined ? self.KEY_CTRL : item[2], exec(cmd));
  404. }
  405. });
  406. }});