2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:21:17 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2000-05-10 09:30:13 +04:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2000-05-10 09:30:13 +04:00
|
|
|
*
|
2001-09-26 02:53:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2000-05-10 09:30:13 +04:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-26 02:53:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998-1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-05-10 09:30:13 +04:00
|
|
|
*
|
2001-03-22 03:59:29 +03:00
|
|
|
* Contributor(s):
|
2004-04-18 18:21:17 +04:00
|
|
|
* Sammy Ford (sford@swbell.net)
|
|
|
|
* Dan Haddix (dan6992@hotmail.com)
|
|
|
|
* John Ratke (jratke@owc.net)
|
|
|
|
* Ryan Cassin (rcassin@supernova.org)
|
|
|
|
* Daniel Glazman (glazman@netscape.com)
|
2001-09-26 02:53:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:21:17 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-26 02:53:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:21:17 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-26 02:53:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:21:17 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-26 02:53:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-05-10 09:30:13 +04:00
|
|
|
|
|
|
|
/* Main Composer window UI control */
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var gComposerWindowControllerID = 0;
|
2000-05-10 09:30:13 +04:00
|
|
|
var prefAuthorString = "";
|
2002-09-13 23:47:38 +04:00
|
|
|
|
2002-10-03 08:07:10 +04:00
|
|
|
const kDisplayModeNormal = 0;
|
|
|
|
const kDisplayModeAllTags = 1;
|
|
|
|
const kDisplayModeSource = 2;
|
|
|
|
const kDisplayModePreview = 3;
|
|
|
|
const kDisplayModeMenuIDs = ["viewNormalMode", "viewAllTagsMode", "viewSourceMode", "viewPreviewMode"];
|
|
|
|
const kDisplayModeTabIDS = ["NormalModeButton", "TagModeButton", "SourceModeButton", "PreviewModeButton"];
|
2002-09-18 23:42:38 +04:00
|
|
|
const kNormalStyleSheet = "chrome://editor/content/EditorContent.css";
|
|
|
|
const kAllTagsStyleSheet = "chrome://editor/content/EditorAllTags.css";
|
|
|
|
const kParagraphMarksStyleSheet = "chrome://editor/content/EditorParagraphMarks.css";
|
2002-11-13 01:52:55 +03:00
|
|
|
|
2002-09-18 23:42:38 +04:00
|
|
|
const kTextMimeType = "text/plain";
|
|
|
|
const kHTMLMimeType = "text/html";
|
2002-09-13 23:47:38 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
|
|
|
|
|
2002-09-13 23:47:38 +04:00
|
|
|
var gPreviousNonSourceDisplayMode = 1;
|
|
|
|
var gEditorDisplayMode = -1;
|
2002-11-13 01:52:55 +03:00
|
|
|
var gDocWasModified = false; // Check if clean document, if clean then unload when user "Opens"
|
2000-05-12 18:46:25 +04:00
|
|
|
var gContentWindow = 0;
|
|
|
|
var gSourceContentWindow = 0;
|
2003-06-13 16:55:17 +04:00
|
|
|
var gSourceTextEditor = null;
|
2000-05-12 18:46:25 +04:00
|
|
|
var gContentWindowDeck;
|
|
|
|
var gFormatToolbar;
|
2000-08-10 07:43:09 +04:00
|
|
|
var gFormatToolbarHidden = false;
|
2002-10-03 08:07:10 +04:00
|
|
|
var gViewFormatToolbar;
|
2002-08-17 01:37:24 +04:00
|
|
|
var gColorObj = { LastTextColor:"", LastBackgroundColor:"", LastHighlightColor:"",
|
|
|
|
Type:"", SelectedType:"", NoDefault:false, Cancel:false,
|
|
|
|
HighlightColor:"", BackgroundColor:"", PageColor:"",
|
|
|
|
TextColor:"", TableColor:"", CellColor:""
|
|
|
|
};
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
var gDefaultTextColor = "";
|
|
|
|
var gDefaultBackgroundColor = "";
|
2002-01-09 16:51:37 +03:00
|
|
|
var gCSSPrefListener;
|
2005-01-12 22:11:48 +03:00
|
|
|
var gEditorToolbarPrefListener;
|
|
|
|
var gReturnInParagraphPrefListener;
|
2001-11-30 03:06:33 +03:00
|
|
|
var gPrefs;
|
2003-03-21 11:36:28 +03:00
|
|
|
var gLocalFonts = null;
|
2000-09-06 03:21:22 +04:00
|
|
|
|
2002-10-16 12:07:35 +04:00
|
|
|
var gLastFocusNode = null;
|
|
|
|
var gLastFocusNodeWasSelected = false;
|
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
// These must be kept in synch with the XUL <options> lists
|
2002-08-17 01:37:24 +04:00
|
|
|
var gFontSizeNames = ["xx-small","x-small","small","medium","large","x-large","xx-large"];
|
2000-05-10 09:30:13 +04:00
|
|
|
|
|
|
|
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
|
|
|
|
2003-03-04 15:12:29 +03:00
|
|
|
const kEditorToolbarPrefs = "editor.toolbars.showbutton.";
|
2005-01-12 22:11:48 +03:00
|
|
|
const kUseCssPref = "editor.use_css";
|
|
|
|
const kCRInParagraphsPref = "editor.CR_creates_new_p";
|
2003-03-04 15:12:29 +03:00
|
|
|
|
2006-01-05 01:34:34 +03:00
|
|
|
function getEngineWebBrowserPrint()
|
|
|
|
{
|
|
|
|
return content.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Components.interfaces.nsIWebBrowserPrint);
|
|
|
|
}
|
|
|
|
|
2003-03-14 18:23:53 +03:00
|
|
|
function ShowHideToolbarSeparators(toolbar) {
|
|
|
|
var childNodes = toolbar.childNodes;
|
|
|
|
var separator = null;
|
|
|
|
var hideSeparator = true;
|
|
|
|
for (var i = 0; childNodes[i].localName != "spacer"; i++) {
|
|
|
|
if (childNodes[i].localName == "toolbarseparator") {
|
|
|
|
if (separator)
|
|
|
|
separator.hidden = true;
|
|
|
|
separator = childNodes[i];
|
|
|
|
} else if (!childNodes[i].hidden) {
|
|
|
|
if (separator)
|
|
|
|
separator.hidden = hideSeparator;
|
|
|
|
separator = null;
|
|
|
|
hideSeparator = false;
|
|
|
|
}
|
|
|
|
}
|
2003-03-04 15:12:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function ShowHideToolbarButtons()
|
|
|
|
{
|
2006-04-04 11:59:57 +04:00
|
|
|
var array = gPrefs.getChildList(kEditorToolbarPrefs, {});
|
2003-03-14 18:23:53 +03:00
|
|
|
for (var i in array) {
|
|
|
|
var prefName = array[i];
|
|
|
|
var id = prefName.substr(kEditorToolbarPrefs.length) + "Button";
|
|
|
|
var button = document.getElementById(id);
|
|
|
|
if (button)
|
|
|
|
button.hidden = !gPrefs.getBoolPref(prefName);
|
|
|
|
}
|
|
|
|
ShowHideToolbarSeparators(document.getElementById("EditToolbar"));
|
|
|
|
ShowHideToolbarSeparators(document.getElementById("FormatToolbar"));
|
2003-03-04 15:12:29 +03:00
|
|
|
}
|
|
|
|
|
2005-01-12 22:11:48 +03:00
|
|
|
function nsPrefListener(prefName)
|
2003-03-04 15:12:29 +03:00
|
|
|
{
|
2005-01-12 22:11:48 +03:00
|
|
|
this.startup(prefName);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// implements nsIObserver
|
2005-01-12 22:11:48 +03:00
|
|
|
nsPrefListener.prototype =
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2005-01-12 22:11:48 +03:00
|
|
|
domain: "",
|
|
|
|
startup: function(prefName)
|
2004-01-22 00:15:44 +03:00
|
|
|
{
|
2005-01-12 22:11:48 +03:00
|
|
|
this.domain = prefName;
|
2004-01-22 00:15:44 +03:00
|
|
|
try {
|
2005-02-25 23:46:35 +03:00
|
|
|
var pbi = pref.QueryInterface(Components.interfaces.nsIPrefBranch2);
|
2004-01-22 00:15:44 +03:00
|
|
|
pbi.addObserver(this.domain, this, false);
|
|
|
|
} catch(ex) {
|
|
|
|
dump("Failed to observe prefs: " + ex + "\n");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
shutdown: function()
|
|
|
|
{
|
|
|
|
try {
|
2005-02-25 23:46:35 +03:00
|
|
|
var pbi = pref.QueryInterface(Components.interfaces.nsIPrefBranch2);
|
2004-01-22 00:15:44 +03:00
|
|
|
pbi.removeObserver(this.domain, this);
|
|
|
|
} catch(ex) {
|
|
|
|
dump("Failed to remove pref observers: " + ex + "\n");
|
|
|
|
}
|
|
|
|
},
|
2002-01-09 16:51:37 +03:00
|
|
|
observe: function(subject, topic, prefName)
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
if (!IsHTMLEditor())
|
2002-08-21 03:59:19 +04:00
|
|
|
return;
|
2002-01-09 16:51:37 +03:00
|
|
|
// verify that we're changing a button pref
|
|
|
|
if (topic != "nsPref:changed") return;
|
2005-01-12 22:11:48 +03:00
|
|
|
|
2006-04-04 11:59:57 +04:00
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
if (prefName == kUseCssPref)
|
2005-01-12 22:11:48 +03:00
|
|
|
{
|
|
|
|
var cmd = document.getElementById("cmd_highlight");
|
|
|
|
if (cmd) {
|
2006-04-04 11:59:57 +04:00
|
|
|
var useCSS = gPrefs.getBoolPref(prefName);
|
|
|
|
|
2005-01-12 22:11:48 +03:00
|
|
|
if (useCSS && editor) {
|
|
|
|
var mixedObj = {};
|
|
|
|
var state = editor.getHighlightColorState(mixedObj);
|
|
|
|
cmd.setAttribute("state", state);
|
|
|
|
cmd.collapsed = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cmd.setAttribute("state", "transparent");
|
|
|
|
cmd.collapsed = true;
|
|
|
|
}
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2005-01-12 22:11:48 +03:00
|
|
|
if (editor)
|
|
|
|
editor.isCSSEnabled = useCSS;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2006-04-04 11:59:57 +04:00
|
|
|
}
|
|
|
|
else if (prefName.substr(0, kEditorToolbarPrefs.length) == kEditorToolbarPrefs)
|
2005-01-12 22:11:48 +03:00
|
|
|
{
|
2006-04-04 11:59:57 +04:00
|
|
|
var id = prefName.substr(kEditorToolbarPrefs.length) + "Button";
|
|
|
|
var button = document.getElementById(id);
|
|
|
|
if (button) {
|
|
|
|
button.hidden = !gPrefs.getBoolPref(prefName);
|
|
|
|
ShowHideToolbarSeparators(button.parentNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (editor && (prefName == kCRInParagraphsPref))
|
|
|
|
editor.returnInParagraphCreatesNewParagraph = gPrefs.getBoolPref(prefName);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function AfterHighlightColorChange()
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
if (!IsHTMLEditor())
|
2002-08-21 03:59:19 +04:00
|
|
|
return;
|
2002-07-13 02:28:30 +04:00
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
var button = document.getElementById("cmd_highlight");
|
|
|
|
if (button) {
|
2002-08-17 01:37:24 +04:00
|
|
|
var mixedObj = {};
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
var state = GetCurrentEditor().getHighlightColorState(mixedObj);
|
|
|
|
button.setAttribute("state", state);
|
|
|
|
onHighlightColorChange();
|
|
|
|
} catch (e) {}
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
function EditorOnLoad()
|
|
|
|
{
|
|
|
|
// See if argument was passed.
|
|
|
|
if ( window.arguments && window.arguments[0] ) {
|
2001-03-22 03:59:29 +03:00
|
|
|
// Opened via window.openDialog with URL as argument.
|
2000-05-10 09:30:13 +04:00
|
|
|
// Put argument where EditorStartup expects it.
|
2002-03-07 03:05:09 +03:00
|
|
|
document.getElementById( "args" ).setAttribute( "value", window.arguments[0] );
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2001-08-15 12:40:18 +04:00
|
|
|
// get default character set if provided
|
|
|
|
if ("arguments" in window && window.arguments.length > 1 && window.arguments[1]) {
|
|
|
|
if (window.arguments[1].indexOf("charset=") != -1) {
|
|
|
|
var arrayArgComponents = window.arguments[1].split("=");
|
|
|
|
if (arrayArgComponents) {
|
|
|
|
// Put argument where EditorStartup expects it.
|
|
|
|
document.getElementById( "args" ).setAttribute("charset", arrayArgComponents[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-15 09:31:32 +04:00
|
|
|
window.tryToClose = EditorCanClose;
|
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
// Continue with normal startup.
|
2002-11-13 01:52:55 +03:00
|
|
|
EditorStartup();
|
2003-06-13 16:55:17 +04:00
|
|
|
|
|
|
|
// Initialize our source text <editor>
|
|
|
|
try {
|
|
|
|
gSourceContentWindow = document.getElementById("content-source");
|
|
|
|
gSourceContentWindow.makeEditable("text", false);
|
|
|
|
gSourceTextEditor = gSourceContentWindow.getEditor(gSourceContentWindow.contentWindow);
|
|
|
|
gSourceTextEditor.QueryInterface(Components.interfaces.nsIPlaintextEditor);
|
|
|
|
gSourceTextEditor.enableUndo(false);
|
|
|
|
gSourceTextEditor.rootElement.style.fontFamily = "-moz-fixed";
|
|
|
|
gSourceTextEditor.rootElement.style.whiteSpace = "pre";
|
|
|
|
gSourceTextEditor.rootElement.style.margin = 0;
|
|
|
|
var controller = Components.classes["@mozilla.org/embedcomp/base-command-controller;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIControllerContext);
|
|
|
|
controller.init(null);
|
|
|
|
controller.setCommandContext(gSourceContentWindow);
|
|
|
|
gSourceContentWindow.contentWindow.controllers.insertControllerAt(0, controller);
|
|
|
|
var commandTable = controller.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Components.interfaces.nsIControllerCommandTable);
|
|
|
|
commandTable.registerCommand("cmd_find", nsFindCommand);
|
|
|
|
commandTable.registerCommand("cmd_findNext", nsFindAgainCommand);
|
|
|
|
commandTable.registerCommand("cmd_findPrev", nsFindAgainCommand);
|
|
|
|
} catch (e) { dump("makeEditable failed: "+e+"\n"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
const gSourceTextListener =
|
|
|
|
{
|
|
|
|
NotifyDocumentCreated: function NotifyDocumentCreated() {},
|
|
|
|
NotifyDocumentWillBeDestroyed: function NotifyDocumentWillBeDestroyed() {},
|
|
|
|
NotifyDocumentStateChanged: function NotifyDocumentStateChanged(isChanged)
|
|
|
|
{
|
|
|
|
window.updateCommands("save");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const gSourceTextObserver =
|
|
|
|
{
|
|
|
|
observe: function observe(aSubject, aTopic, aData)
|
|
|
|
{
|
|
|
|
// we currently only use this to update undo
|
|
|
|
window.updateCommands("undo");
|
|
|
|
}
|
|
|
|
};
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
function TextEditorOnLoad()
|
|
|
|
{
|
|
|
|
// See if argument was passed.
|
|
|
|
if ( window.arguments && window.arguments[0] ) {
|
2001-03-22 03:59:29 +03:00
|
|
|
// Opened via window.openDialog with URL as argument.
|
2000-05-10 09:30:13 +04:00
|
|
|
// Put argument where EditorStartup expects it.
|
2002-03-07 03:05:09 +03:00
|
|
|
document.getElementById( "args" ).setAttribute( "value", window.arguments[0] );
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
// Continue with normal startup.
|
2002-11-13 01:52:55 +03:00
|
|
|
EditorStartup();
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2002-02-08 02:44:32 +03:00
|
|
|
// This should be called by all editor users when they close their window
|
|
|
|
// or other similar "done with editor" actions, like recycling a Mail Composer window.
|
|
|
|
function EditorCleanup()
|
|
|
|
{
|
|
|
|
SwitchInsertCharToAnotherEditorOrClose();
|
|
|
|
}
|
|
|
|
|
2001-08-15 12:32:55 +04:00
|
|
|
var DocumentReloadListener =
|
|
|
|
{
|
|
|
|
NotifyDocumentCreated: function() {},
|
|
|
|
NotifyDocumentWillBeDestroyed: function() {},
|
|
|
|
|
|
|
|
NotifyDocumentStateChanged:function( isNowDirty )
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
try {
|
|
|
|
// unregister the listener to prevent multiple callbacks
|
|
|
|
editor.removeDocumentStateListener( DocumentReloadListener );
|
2001-08-15 12:32:55 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var charset = editor.documentCharacterSet;
|
2001-08-15 12:32:55 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
// update the META charset with the current presentation charset
|
|
|
|
editor.documentCharacterSet = charset;
|
|
|
|
|
|
|
|
} catch (e) {}
|
2001-08-15 12:32:55 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2002-04-16 17:30:40 +04:00
|
|
|
function addEditorClickEventListener()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
var bodyelement = GetBodyElement();
|
|
|
|
if (bodyelement)
|
|
|
|
bodyelement.addEventListener("click", EditorClick, false);
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
// implements nsIObserver
|
|
|
|
var gEditorDocumentObserver =
|
|
|
|
{
|
|
|
|
observe: function(aSubject, aTopic, aData)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
// Should we allow this even if NOT the focused editor?
|
|
|
|
var commandManager = GetCurrentCommandManager();
|
|
|
|
if (commandManager != aSubject)
|
|
|
|
return;
|
2002-07-13 02:28:30 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
switch(aTopic)
|
2002-10-08 00:13:09 +04:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
case "obs_documentCreated":
|
|
|
|
// Just for convenience
|
|
|
|
gContentWindow = window.content;
|
2002-10-08 00:13:09 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
// Get state to see if document creation succeeded
|
|
|
|
var params = newCommandParams();
|
|
|
|
if (!params)
|
|
|
|
return;
|
2002-10-08 00:13:09 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
commandManager.getCommandState(aTopic, gContentWindow, params);
|
|
|
|
var errorStringId = 0;
|
|
|
|
var editorStatus = params.getLongValue("state_data");
|
|
|
|
if (!editor && editorStatus == nsIEditingSession.eEditorOK)
|
|
|
|
{
|
|
|
|
dump("\n ****** NO EDITOR BUT NO EDITOR ERROR REPORTED ******* \n\n");
|
2003-12-21 07:04:33 +03:00
|
|
|
editorStatus = nsIEditingSession.eEditorErrorUnknown;
|
2002-11-13 01:52:55 +03:00
|
|
|
}
|
2002-10-08 00:13:09 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
switch (editorStatus)
|
|
|
|
{
|
|
|
|
case nsIEditingSession.eEditorErrorCantEditFramesets:
|
|
|
|
errorStringId = "CantEditFramesetMsg";
|
|
|
|
break;
|
|
|
|
case nsIEditingSession.eEditorErrorCantEditMimeType:
|
|
|
|
errorStringId = "CantEditMimeTypeMsg";
|
|
|
|
break;
|
2003-12-21 07:04:33 +03:00
|
|
|
case nsIEditingSession.eEditorErrorUnknown:
|
2002-11-13 01:52:55 +03:00
|
|
|
errorStringId = "CantEditDocumentMsg";
|
|
|
|
break;
|
|
|
|
// Note that for "eEditorErrorFileNotFound,
|
|
|
|
// network code popped up an alert dialog, so we don't need to
|
|
|
|
}
|
|
|
|
if (errorStringId)
|
|
|
|
AlertWithTitle("", GetString(errorStringId));
|
|
|
|
} catch(e) { dump("EXCEPTION GETTING obs_documentCreated state "+e+"\n"); }
|
|
|
|
|
|
|
|
// We have a bad editor -- nsIEditingSession will rebuild an editor
|
|
|
|
// with a blank page, so simply abort here
|
|
|
|
if (editorStatus)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!("InsertCharWindow" in window))
|
|
|
|
window.InsertCharWindow = null;
|
2000-06-28 18:58:36 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
editor.QueryInterface(nsIEditorStyleSheets);
|
2001-01-18 03:59:18 +03:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
// and extra styles for showing anchors, table borders, smileys, etc
|
|
|
|
editor.addOverrideStyleSheet(kNormalStyleSheet);
|
2002-10-08 00:13:09 +04:00
|
|
|
} catch (e) {}
|
2002-09-13 23:47:38 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
// Things for just the Web Composer application
|
|
|
|
if (IsWebComposer())
|
|
|
|
{
|
2006-04-04 11:59:57 +04:00
|
|
|
editor.returnInParagraphCreatesNewParagraph = gPrefs.getBoolPref(kCRInParagraphsPref);
|
2005-01-12 22:11:48 +03:00
|
|
|
|
2003-06-13 16:55:17 +04:00
|
|
|
// Set focus to content window if not a mail composer
|
|
|
|
// Race conditions prevent us from setting focus here
|
|
|
|
// when loading a url into blank window
|
|
|
|
setTimeout(SetFocusOnStartup, 0);
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
// Call EditorSetDefaultPrefsAndDoctype first so it gets the default author before initing toolbars
|
|
|
|
EditorSetDefaultPrefsAndDoctype();
|
|
|
|
|
|
|
|
// We may load a text document into an html editor,
|
|
|
|
// so be sure editortype is set correctly
|
|
|
|
// XXX We really should use the "real" plaintext editor for this!
|
|
|
|
if (editor.contentsMIMEType == "text/plain")
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
GetCurrentEditorElement().editortype = "text";
|
|
|
|
} catch (e) { dump (e)+"\n"; }
|
|
|
|
|
|
|
|
// Hide or disable UI not used for plaintext editing
|
|
|
|
HideItem("FormatToolbar");
|
|
|
|
HideItem("EditModeToolbar");
|
|
|
|
HideItem("formatMenu");
|
|
|
|
HideItem("tableMenu");
|
|
|
|
HideItem("menu_validate");
|
|
|
|
HideItem("sep_validate");
|
|
|
|
HideItem("previewButton");
|
|
|
|
HideItem("imageButton");
|
|
|
|
HideItem("linkButton");
|
|
|
|
HideItem("namedAnchorButton");
|
|
|
|
HideItem("hlineButton");
|
2002-11-15 18:52:47 +03:00
|
|
|
HideItem("tableButton");
|
2002-11-13 01:52:55 +03:00
|
|
|
|
2003-05-28 23:53:50 +04:00
|
|
|
HideItem("fileExportToText");
|
|
|
|
HideItem("previewInBrowser");
|
|
|
|
|
|
|
|
/* XXX When paste actually converts formatted rich text to pretty formatted plain text
|
|
|
|
and pasteNoFormatting is fixed to paste the text without formatting (what paste
|
|
|
|
currently does), then this item shouldn't be hidden: */
|
|
|
|
HideItem("menu_pasteNoFormatting");
|
|
|
|
|
|
|
|
HideItem("cmd_viewFormatToolbar");
|
|
|
|
HideItem("cmd_viewEditModeToolbar");
|
|
|
|
|
|
|
|
HideItem("viewSep1");
|
|
|
|
HideItem("viewNormalMode");
|
|
|
|
HideItem("viewAllTagsMode");
|
|
|
|
HideItem("viewSourceMode");
|
|
|
|
HideItem("viewPreviewMode");
|
|
|
|
|
|
|
|
HideItem("structSpacer");
|
2002-11-13 01:52:55 +03:00
|
|
|
|
|
|
|
// Hide everything in "Insert" except for "Symbols"
|
|
|
|
var menuPopup = document.getElementById("insertMenuPopup");
|
|
|
|
if (menuPopup)
|
|
|
|
{
|
|
|
|
var children = menuPopup.childNodes;
|
|
|
|
for (var i=0; i < children.length; i++)
|
|
|
|
{
|
|
|
|
var item = children.item(i);
|
|
|
|
if (item.id != "insertChars")
|
2002-11-19 18:51:56 +03:00
|
|
|
item.hidden = true;
|
2002-11-13 01:52:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-10-08 00:13:09 +04:00
|
|
|
|
2002-12-06 00:24:09 +03:00
|
|
|
// Set window title
|
2002-11-13 01:52:55 +03:00
|
|
|
UpdateWindowTitle();
|
2002-09-16 21:42:30 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
// We must wait until document is created to get proper Url
|
|
|
|
// (Windows may load with local file paths)
|
|
|
|
SetSaveAndPublishUI(GetDocumentUrl());
|
2002-10-05 21:35:36 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
// Start in "Normal" edit mode
|
|
|
|
SetDisplayMode(kDisplayModeNormal);
|
|
|
|
}
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
// Add mouse click watcher if right type of editor
|
|
|
|
if (IsHTMLEditor())
|
|
|
|
{
|
|
|
|
addEditorClickEventListener();
|
2002-04-16 17:30:40 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
// Force color widgets to update
|
|
|
|
onFontColorChange();
|
|
|
|
onBackgroundColorChange();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "cmd_setDocumentModified":
|
|
|
|
window.updateCommands("save");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "obs_documentWillBeDestroyed":
|
|
|
|
dump("obs_documentWillBeDestroyed notification\n");
|
|
|
|
break;
|
|
|
|
|
2002-11-27 03:35:09 +03:00
|
|
|
case "obs_documentLocationChanged":
|
|
|
|
// Ignore this when editor doesn't exist,
|
|
|
|
// which happens once when page load starts
|
|
|
|
if (editor)
|
|
|
|
try {
|
|
|
|
editor.updateBaseURL();
|
|
|
|
} catch(e) { dump (e); }
|
|
|
|
break;
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
case "cmd_bold":
|
|
|
|
// Update all style items
|
2003-01-22 03:50:47 +03:00
|
|
|
// cmd_bold is a proxy; see EditorSharedStartup (above) for details
|
2002-11-13 01:52:55 +03:00
|
|
|
window.updateCommands("style");
|
2003-01-22 03:50:47 +03:00
|
|
|
window.updateCommands("undo");
|
2002-11-13 01:52:55 +03:00
|
|
|
break;
|
|
|
|
}
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
2002-11-13 01:52:55 +03:00
|
|
|
}
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-11-22 02:53:50 +03:00
|
|
|
function SetFocusOnStartup()
|
|
|
|
{
|
|
|
|
gContentWindow.focus();
|
|
|
|
}
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
function EditorStartup()
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2004-10-14 08:54:03 +04:00
|
|
|
var ds = GetCurrentEditorElement().docShell;
|
2005-07-09 04:14:48 +04:00
|
|
|
ds.useErrorPages = false;
|
2004-10-14 08:54:03 +04:00
|
|
|
var root = ds.QueryInterface(Components.interfaces.nsIDocShellTreeItem).
|
|
|
|
rootTreeItem.QueryInterface(Components.interfaces.nsIDocShell);
|
|
|
|
|
|
|
|
root.QueryInterface(Components.interfaces.nsIDocShell).appType =
|
2004-10-14 03:16:58 +04:00
|
|
|
Components.interfaces.nsIDocShell.APP_TYPE_EDITOR;
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var is_HTMLEditor = IsHTMLEditor();
|
|
|
|
if (is_HTMLEditor)
|
2000-05-12 06:37:40 +04:00
|
|
|
{
|
|
|
|
// XUL elements we use when switching from normal editor to edit source
|
2000-05-12 18:46:25 +04:00
|
|
|
gContentWindowDeck = document.getElementById("ContentWindowDeck");
|
|
|
|
gFormatToolbar = document.getElementById("FormatToolbar");
|
2002-10-03 08:07:10 +04:00
|
|
|
gViewFormatToolbar = document.getElementById("viewFormatToolbar");
|
2000-05-12 06:37:40 +04:00
|
|
|
}
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2000-08-24 04:28:20 +04:00
|
|
|
// set up our global prefs object
|
|
|
|
GetPrefsService();
|
2001-03-22 03:59:29 +03:00
|
|
|
|
|
|
|
// Startup also used by other editor users, such as Message Composer
|
2000-08-10 07:43:09 +04:00
|
|
|
EditorSharedStartup();
|
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
// Commands specific to the Composer Application window,
|
2001-05-18 10:42:37 +04:00
|
|
|
// (i.e., not embedded editors)
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
// such as file-related commands, HTML Source editing, Edit Modes...
|
|
|
|
SetupComposerWindowCommands();
|
2000-05-15 07:05:56 +04:00
|
|
|
|
2003-03-04 15:12:29 +03:00
|
|
|
ShowHideToolbarButtons();
|
2005-01-12 22:11:48 +03:00
|
|
|
gEditorToolbarPrefListener = new nsPrefListener(kEditorToolbarPrefs);
|
2003-03-04 15:12:29 +03:00
|
|
|
|
2005-01-12 22:11:48 +03:00
|
|
|
gCSSPrefListener = new nsPrefListener(kUseCssPref);
|
|
|
|
gReturnInParagraphPrefListener = new nsPrefListener(kCRInParagraphsPref);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2002-08-14 17:12:52 +04:00
|
|
|
// hide Highlight button if we are in an HTML editor with CSS mode off
|
2005-01-12 22:11:48 +03:00
|
|
|
// and tell the editor if a CR in a paragraph creates a new paragraph
|
2002-08-14 17:12:52 +04:00
|
|
|
var cmd = document.getElementById("cmd_highlight");
|
|
|
|
if (cmd) {
|
2006-04-04 11:59:57 +04:00
|
|
|
var useCSS = gPrefs.getBoolPref(kUseCssPref);
|
2002-11-13 01:52:55 +03:00
|
|
|
if (!useCSS && is_HTMLEditor) {
|
2002-11-19 18:51:56 +03:00
|
|
|
cmd.collapsed = true;
|
2002-08-14 17:12:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
// Get url for editor content and load it.
|
2002-11-13 01:52:55 +03:00
|
|
|
// the editor gets instantiated by the edittingSession when the URL has finished loading.
|
2000-05-10 09:30:13 +04:00
|
|
|
var url = document.getElementById("args").getAttribute("value");
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
var charset = document.getElementById("args").getAttribute("charset");
|
|
|
|
var contentViewer = GetCurrentEditorElement().docShell.contentViewer;
|
|
|
|
contentViewer.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
|
|
|
|
contentViewer.defaultCharacterSet = charset;
|
|
|
|
contentViewer.forceCharacterSet = charset;
|
|
|
|
} catch (e) {}
|
|
|
|
EditorLoadUrl(url);
|
|
|
|
}
|
2002-02-20 05:17:46 +03:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
function EditorLoadUrl(url)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (url)
|
|
|
|
GetCurrentEditorElement().webNavigation.loadURI(url, // uri string
|
|
|
|
nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE, // load flags
|
|
|
|
null, // referrer
|
|
|
|
null, // post-data stream
|
|
|
|
null);
|
|
|
|
} catch (e) { dump(" EditorLoadUrl failed: "+e+"\n"); }
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
// This should be called by all Composer types
|
2000-05-15 07:05:56 +04:00
|
|
|
function EditorSharedStartup()
|
|
|
|
{
|
2001-05-09 09:23:37 +04:00
|
|
|
// Just for convenience
|
2002-11-13 01:52:55 +03:00
|
|
|
gContentWindow = window.content;
|
2002-08-07 04:06:41 +04:00
|
|
|
|
|
|
|
// Set up the mime type and register the commands.
|
2003-03-20 18:37:42 +03:00
|
|
|
if (IsHTMLEditor())
|
2002-08-07 04:06:41 +04:00
|
|
|
SetupHTMLEditorCommands();
|
|
|
|
else
|
|
|
|
SetupTextEditorCommands();
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
// add observer to be called when document is really done loading
|
|
|
|
// and is modified
|
|
|
|
// Note: We're really screwed if we fail to install this observer!
|
|
|
|
try {
|
|
|
|
var commandManager = GetCurrentCommandManager();
|
|
|
|
commandManager.addCommandObserver(gEditorDocumentObserver, "obs_documentCreated");
|
|
|
|
commandManager.addCommandObserver(gEditorDocumentObserver, "cmd_setDocumentModified");
|
|
|
|
commandManager.addCommandObserver(gEditorDocumentObserver, "obs_documentWillBeDestroyed");
|
2002-11-27 03:35:09 +03:00
|
|
|
commandManager.addCommandObserver(gEditorDocumentObserver, "obs_documentLocationChanged");
|
2002-11-13 01:52:55 +03:00
|
|
|
|
|
|
|
// Until nsIControllerCommandGroup-based code is implemented,
|
|
|
|
// we will observe just the bold command to trigger update of
|
|
|
|
// all toolbar style items
|
|
|
|
commandManager.addCommandObserver(gEditorDocumentObserver, "cmd_bold");
|
|
|
|
} catch (e) { dump(e); }
|
2002-08-07 04:06:41 +04:00
|
|
|
|
2001-11-15 18:28:24 +03:00
|
|
|
var isMac = (GetOS() == gMac);
|
2000-05-15 07:05:56 +04:00
|
|
|
|
2000-07-01 04:37:38 +04:00
|
|
|
// Set platform-specific hints for how to select cells
|
|
|
|
// Mac uses "Cmd", all others use "Ctrl"
|
2001-11-15 18:28:24 +03:00
|
|
|
var tableKey = GetString(isMac ? "XulKeyMac" : "TableSelectKey");
|
2000-07-15 01:58:50 +04:00
|
|
|
var dragStr = tableKey+GetString("Drag");
|
|
|
|
var clickStr = tableKey+GetString("Click");
|
2000-07-01 04:37:38 +04:00
|
|
|
|
2001-11-15 18:28:24 +03:00
|
|
|
var delStr = GetString(isMac ? "Clear" : "Del");
|
2000-07-01 04:37:38 +04:00
|
|
|
|
2000-07-15 01:58:50 +04:00
|
|
|
SafeSetAttribute("menu_SelectCell", "acceltext", clickStr);
|
|
|
|
SafeSetAttribute("menu_SelectRow", "acceltext", dragStr);
|
|
|
|
SafeSetAttribute("menu_SelectColumn", "acceltext", dragStr);
|
|
|
|
SafeSetAttribute("menu_SelectAllCells", "acceltext", dragStr);
|
2000-07-01 04:37:38 +04:00
|
|
|
// And add "Del" or "Clear"
|
2000-07-15 01:58:50 +04:00
|
|
|
SafeSetAttribute("menu_DeleteCellContents", "acceltext", delStr);
|
2000-07-01 04:37:38 +04:00
|
|
|
|
2001-08-10 07:47:37 +04:00
|
|
|
// Set text for indent, outdent keybinding
|
2000-08-10 07:43:09 +04:00
|
|
|
|
2000-05-15 07:05:56 +04:00
|
|
|
// hide UI that we don't have components for
|
2000-07-12 03:41:22 +04:00
|
|
|
RemoveInapplicableUIElements();
|
2000-08-24 04:28:20 +04:00
|
|
|
|
2001-11-30 03:06:33 +03:00
|
|
|
gPrefs = GetPrefs();
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2000-09-06 03:21:22 +04:00
|
|
|
// Use browser colors as initial values for editor's default colors
|
|
|
|
var BrowserColors = GetDefaultBrowserColors();
|
|
|
|
if (BrowserColors)
|
2000-08-24 04:28:20 +04:00
|
|
|
{
|
2000-09-06 03:21:22 +04:00
|
|
|
gDefaultTextColor = BrowserColors.TextColor;
|
|
|
|
gDefaultBackgroundColor = BrowserColors.BackgroundColor;
|
|
|
|
}
|
2001-03-24 03:58:52 +03:00
|
|
|
|
|
|
|
// For new window, no default last-picked colors
|
|
|
|
gColorObj.LastTextColor = "";
|
|
|
|
gColorObj.LastBackgroundColor = "";
|
2002-01-09 16:51:37 +03:00
|
|
|
gColorObj.LastHighlightColor = "";
|
2000-09-06 03:21:22 +04:00
|
|
|
}
|
2000-08-24 04:28:20 +04:00
|
|
|
|
2002-01-18 23:52:23 +03:00
|
|
|
// This method is only called by Message composer when recycling a compose window
|
|
|
|
function EditorResetFontAndColorAttributes()
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
2004-09-02 16:18:16 +04:00
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
editor.rebuildDocumentFromSource("");
|
|
|
|
// Because the selection is now collapsed, the following line
|
|
|
|
// clears the typing state to discontinue all inline styles
|
|
|
|
editor.removeAllInlineProperties();
|
2002-11-13 01:52:55 +03:00
|
|
|
document.getElementById("cmd_fontFace").setAttribute("state", "");
|
|
|
|
gColorObj.LastTextColor = "";
|
|
|
|
gColorObj.LastBackgroundColor = "";
|
|
|
|
gColorObj.LastHighlightColor = "";
|
|
|
|
document.getElementById("cmd_fontColor").setAttribute("state", "");
|
|
|
|
document.getElementById("cmd_backgroundColor").setAttribute("state", "");
|
|
|
|
UpdateDefaultColors();
|
|
|
|
} catch (e) {}
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function EditorShutdown()
|
|
|
|
{
|
2005-01-12 22:11:48 +03:00
|
|
|
gEditorToolbarPrefListener.shutdown();
|
2004-01-22 00:15:44 +03:00
|
|
|
gCSSPrefListener.shutdown();
|
2005-01-12 22:11:48 +03:00
|
|
|
gReturnInParagraphPrefListener.shutdown();
|
2003-03-04 15:12:29 +03:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
var commandManager = GetCurrentCommandManager();
|
|
|
|
commandManager.removeCommandObserver(gEditorDocumentObserver, "obs_documentCreated");
|
|
|
|
commandManager.removeCommandObserver(gEditorDocumentObserver, "obs_documentWillBeDestroyed");
|
2002-11-27 03:35:09 +03:00
|
|
|
commandManager.removeCommandObserver(gEditorDocumentObserver, "obs_documentLocationChanged");
|
2002-11-13 01:52:55 +03:00
|
|
|
} catch (e) { dump (e); }
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2000-07-15 01:58:50 +04:00
|
|
|
function SafeSetAttribute(nodeID, attributeName, attributeValue)
|
|
|
|
{
|
|
|
|
var theNode = document.getElementById(nodeID);
|
|
|
|
if (theNode)
|
|
|
|
theNode.setAttribute(attributeName, attributeValue);
|
|
|
|
}
|
|
|
|
|
2000-08-30 06:44:18 +04:00
|
|
|
function DocumentHasBeenSaved()
|
2000-08-01 18:17:48 +04:00
|
|
|
{
|
2000-09-02 03:04:03 +04:00
|
|
|
var fileurl = "";
|
2000-08-30 06:44:18 +04:00
|
|
|
try {
|
2002-02-15 09:07:40 +03:00
|
|
|
fileurl = GetDocumentUrl();
|
2000-08-30 06:44:18 +04:00
|
|
|
} catch (e) {
|
|
|
|
return false;
|
2000-08-01 18:17:48 +04:00
|
|
|
}
|
2000-08-30 06:44:18 +04:00
|
|
|
|
2002-02-15 09:07:40 +03:00
|
|
|
if (!fileurl || IsUrlAboutBlank(fileurl))
|
2000-08-30 06:44:18 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// We have a file URL already
|
|
|
|
return true;
|
2000-08-01 18:17:48 +04:00
|
|
|
}
|
|
|
|
|
Composer Publishing fixes: Add support to not upload images (b=134001,r=akkana, sr=kin), Don't save site data if not successfully published (b=132604, r=akkana, sr=kin), improve error handling (b=126258, r=andreww, sr=dveditz), Make 'CheckAndSaveDocument' do publishing for remote url (b=126450, r=brade, sr=kin), Save command should publish if remote file (b=132634, r=brade,sr=kin), Fix FTP publishing (b=133823, r=brade, sr=kin) all are: a=asa, adt1.0.0+
2002-04-04 19:14:32 +04:00
|
|
|
function CheckAndSaveDocument(command, allowDontSave)
|
2000-08-08 01:12:18 +04:00
|
|
|
{
|
2002-07-10 00:24:37 +04:00
|
|
|
var document;
|
Composer Publishing fixes: Add support to not upload images (b=134001,r=akkana, sr=kin), Don't save site data if not successfully published (b=132604, r=akkana, sr=kin), improve error handling (b=126258, r=andreww, sr=dveditz), Make 'CheckAndSaveDocument' do publishing for remote url (b=126450, r=brade, sr=kin), Save command should publish if remote file (b=132634, r=brade,sr=kin), Fix FTP publishing (b=133823, r=brade, sr=kin) all are: a=asa, adt1.0.0+
2002-04-04 19:14:32 +04:00
|
|
|
try {
|
2002-07-10 00:24:37 +04:00
|
|
|
// if we don't have an editor or an document, bail
|
2002-11-13 01:52:55 +03:00
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
document = editor.document;
|
2002-07-10 00:24:37 +04:00
|
|
|
if (!document)
|
Composer Publishing fixes: Add support to not upload images (b=134001,r=akkana, sr=kin), Don't save site data if not successfully published (b=132604, r=akkana, sr=kin), improve error handling (b=126258, r=andreww, sr=dveditz), Make 'CheckAndSaveDocument' do publishing for remote url (b=126450, r=brade, sr=kin), Save command should publish if remote file (b=132634, r=brade,sr=kin), Fix FTP publishing (b=133823, r=brade, sr=kin) all are: a=asa, adt1.0.0+
2002-04-04 19:14:32 +04:00
|
|
|
return true;
|
|
|
|
} catch (e) { return true; }
|
2002-03-27 05:04:43 +03:00
|
|
|
|
2003-06-13 16:55:17 +04:00
|
|
|
if (!IsDocumentModified() && !IsHTMLSourceChanged())
|
2000-08-08 01:12:18 +04:00
|
|
|
return true;
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2001-03-28 11:09:16 +04:00
|
|
|
// call window.focus, since we need to pop up a dialog
|
|
|
|
// and therefore need to be visible (to prevent user confusion)
|
2003-06-13 16:55:17 +04:00
|
|
|
top.document.commandDispatcher.focusedWindow.focus();
|
2001-03-28 11:09:16 +04:00
|
|
|
|
Composer Publishing fixes: Add support to not upload images (b=134001,r=akkana, sr=kin), Don't save site data if not successfully published (b=132604, r=akkana, sr=kin), improve error handling (b=126258, r=andreww, sr=dveditz), Make 'CheckAndSaveDocument' do publishing for remote url (b=126450, r=brade, sr=kin), Save command should publish if remote file (b=132634, r=brade,sr=kin), Fix FTP publishing (b=133823, r=brade, sr=kin) all are: a=asa, adt1.0.0+
2002-04-04 19:14:32 +04:00
|
|
|
var scheme = GetScheme(GetDocumentUrl());
|
|
|
|
var doPublish = (scheme && scheme != "file");
|
|
|
|
|
|
|
|
var strID;
|
|
|
|
switch (command)
|
|
|
|
{
|
|
|
|
case "cmd_close":
|
|
|
|
strID = "BeforeClosing";
|
|
|
|
break;
|
|
|
|
case "cmd_preview":
|
|
|
|
strID = "BeforePreview";
|
|
|
|
break;
|
|
|
|
case "cmd_editSendPage":
|
|
|
|
strID = "SendPageReason";
|
|
|
|
break;
|
|
|
|
case "cmd_validate":
|
|
|
|
strID = "BeforeValidate";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var reasonToSave = strID ? GetString(strID) : "";
|
|
|
|
|
2002-07-10 00:24:37 +04:00
|
|
|
var title = document.title;
|
2000-08-31 16:44:56 +04:00
|
|
|
if (!title)
|
2000-09-06 03:21:22 +04:00
|
|
|
title = GetString("untitled");
|
2001-03-22 03:59:29 +03:00
|
|
|
|
Composer Publishing fixes: Add support to not upload images (b=134001,r=akkana, sr=kin), Don't save site data if not successfully published (b=132604, r=akkana, sr=kin), improve error handling (b=126258, r=andreww, sr=dveditz), Make 'CheckAndSaveDocument' do publishing for remote url (b=126450, r=brade, sr=kin), Save command should publish if remote file (b=132634, r=brade,sr=kin), Fix FTP publishing (b=133823, r=brade, sr=kin) all are: a=asa, adt1.0.0+
2002-04-04 19:14:32 +04:00
|
|
|
var dialogTitle = GetString(doPublish ? "PublishPage" : "SaveDocument");
|
2002-08-09 05:44:23 +04:00
|
|
|
var dialogMsg = GetString(doPublish ? "PublishPrompt" : "SaveFilePrompt");
|
2000-08-08 01:12:18 +04:00
|
|
|
dialogMsg = (dialogMsg.replace(/%title%/,title)).replace(/%reason%/,reasonToSave);
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
var promptService = GetPromptService();
|
|
|
|
if (!promptService)
|
|
|
|
return false;
|
2001-05-18 10:42:37 +04:00
|
|
|
|
2000-08-08 01:12:18 +04:00
|
|
|
var result = {value:0};
|
Composer Publishing fixes: Add support to not upload images (b=134001,r=akkana, sr=kin), Don't save site data if not successfully published (b=132604, r=akkana, sr=kin), improve error handling (b=126258, r=andreww, sr=dveditz), Make 'CheckAndSaveDocument' do publishing for remote url (b=126450, r=brade, sr=kin), Save command should publish if remote file (b=132634, r=brade,sr=kin), Fix FTP publishing (b=133823, r=brade, sr=kin) all are: a=asa, adt1.0.0+
2002-04-04 19:14:32 +04:00
|
|
|
var promptFlags = promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1;
|
|
|
|
var button1Title = null;
|
|
|
|
var button3Title = null;
|
|
|
|
|
|
|
|
if (doPublish)
|
|
|
|
{
|
|
|
|
promptFlags += promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0;
|
|
|
|
button1Title = GetString("Publish");
|
|
|
|
button3Title = GetString("DontPublish");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
promptFlags += promptService.BUTTON_TITLE_SAVE * promptService.BUTTON_POS_0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If allowing "Don't..." button, add that
|
|
|
|
if (allowDontSave)
|
|
|
|
promptFlags += doPublish ?
|
|
|
|
(promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2)
|
|
|
|
: (promptService.BUTTON_TITLE_DONT_SAVE * promptService.BUTTON_POS_2);
|
2002-04-05 22:15:13 +04:00
|
|
|
|
|
|
|
result = promptService.confirmEx(window, dialogTitle, dialogMsg, promptFlags,
|
|
|
|
button1Title, null, button3Title, null, {value:0});
|
2002-04-05 12:13:27 +04:00
|
|
|
|
2002-04-05 22:15:13 +04:00
|
|
|
if (result == 0)
|
2001-07-07 00:03:41 +04:00
|
|
|
{
|
|
|
|
// Save, but first finish HTML source mode
|
2003-06-13 16:55:17 +04:00
|
|
|
if (IsHTMLSourceChanged()) {
|
2002-07-23 09:30:16 +04:00
|
|
|
try {
|
|
|
|
FinishHTMLSource();
|
|
|
|
} catch (e) { return false;}
|
|
|
|
}
|
2001-07-07 00:03:41 +04:00
|
|
|
|
Composer Publishing fixes: Add support to not upload images (b=134001,r=akkana, sr=kin), Don't save site data if not successfully published (b=132604, r=akkana, sr=kin), improve error handling (b=126258, r=andreww, sr=dveditz), Make 'CheckAndSaveDocument' do publishing for remote url (b=126450, r=brade, sr=kin), Save command should publish if remote file (b=132634, r=brade,sr=kin), Fix FTP publishing (b=133823, r=brade, sr=kin) all are: a=asa, adt1.0.0+
2002-04-04 19:14:32 +04:00
|
|
|
if (doPublish)
|
|
|
|
{
|
|
|
|
// We save the command the user wanted to do in a global
|
|
|
|
// and return as if user canceled because publishing is asynchronous
|
|
|
|
// This command will be fired when publishing finishes
|
|
|
|
gCommandAfterPublishing = command;
|
|
|
|
goDoCommand("cmd_publish");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save to local disk
|
2002-07-10 00:24:37 +04:00
|
|
|
var contentsMIMEType;
|
2002-11-13 01:52:55 +03:00
|
|
|
if (IsHTMLEditor())
|
2002-09-18 23:42:38 +04:00
|
|
|
contentsMIMEType = kHTMLMimeType;
|
2002-07-10 00:24:37 +04:00
|
|
|
else
|
2002-09-18 23:42:38 +04:00
|
|
|
contentsMIMEType = kTextMimeType;
|
2002-07-10 00:24:37 +04:00
|
|
|
var success = SaveDocument(false, false, contentsMIMEType);
|
2001-07-07 00:03:41 +04:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2002-04-05 22:15:13 +04:00
|
|
|
if (result == 2) // "Don't Save"
|
2001-07-07 00:03:41 +04:00
|
|
|
return true;
|
2000-09-06 03:21:22 +04:00
|
|
|
|
2002-04-05 22:15:13 +04:00
|
|
|
// Default or result == 1 (Cancel)
|
2000-09-06 03:21:22 +04:00
|
|
|
return false;
|
2000-08-08 01:12:18 +04:00
|
|
|
}
|
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
// --------------------------- File menu ---------------------------
|
|
|
|
|
|
|
|
|
|
|
|
// used by openLocation. see openLocation.js for additional notes.
|
|
|
|
function delayedOpenWindow(chrome, flags, url)
|
|
|
|
{
|
2002-03-27 05:04:43 +03:00
|
|
|
dump("setting timeout\n");
|
2001-01-17 02:12:22 +03:00
|
|
|
setTimeout("window.openDialog('"+chrome+"','_blank','"+flags+"','"+url+"')", 10);
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function EditorNewPlaintext()
|
|
|
|
{
|
|
|
|
window.openDialog( "chrome://editor/content/TextEditorAppShell.xul",
|
|
|
|
"_blank",
|
|
|
|
"chrome,dialog=no,all",
|
|
|
|
"about:blank");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for changes to document and allow saving before closing
|
|
|
|
// This is hooked up to the OS's window close widget (e.g., "X" for Windows)
|
|
|
|
function EditorCanClose()
|
|
|
|
{
|
|
|
|
// Returns FALSE only if user cancels save action
|
2000-07-12 03:41:22 +04:00
|
|
|
|
2000-08-30 06:44:18 +04:00
|
|
|
// "true" means allow "Don't Save" button
|
Composer Publishing fixes: Add support to not upload images (b=134001,r=akkana, sr=kin), Don't save site data if not successfully published (b=132604, r=akkana, sr=kin), improve error handling (b=126258, r=andreww, sr=dveditz), Make 'CheckAndSaveDocument' do publishing for remote url (b=126450, r=brade, sr=kin), Save command should publish if remote file (b=132634, r=brade,sr=kin), Fix FTP publishing (b=133823, r=brade, sr=kin) all are: a=asa, adt1.0.0+
2002-04-04 19:14:32 +04:00
|
|
|
var canClose = CheckAndSaveDocument("cmd_close", true);
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
|
|
|
|
// This is our only hook into closing via the "X" in the caption
|
|
|
|
// or "Quit" (or other paths?)
|
|
|
|
// so we must shift association to another
|
|
|
|
// editor or close any non-modal windows now
|
2001-01-18 03:59:18 +03:00
|
|
|
if (canClose && "InsertCharWindow" in window && window.InsertCharWindow)
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
SwitchInsertCharToAnotherEditorOrClose();
|
|
|
|
|
|
|
|
return canClose;
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------- View menu ---------------------------
|
|
|
|
|
|
|
|
function EditorSetDocumentCharacterSet(aCharset)
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
editor.documentCharacterSet = aCharset;
|
2002-02-15 09:07:40 +03:00
|
|
|
var docUrl = GetDocumentUrl();
|
|
|
|
if( !IsUrlAboutBlank(docUrl))
|
2000-07-21 03:22:57 +04:00
|
|
|
{
|
2001-08-15 12:32:55 +04:00
|
|
|
// reloading the document will reverse any changes to the META charset,
|
|
|
|
// we need to put them back in, which is achieved by a dedicated listener
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.addDocumentStateListener( DocumentReloadListener );
|
|
|
|
EditorLoadUrl(docUrl);
|
2000-07-21 03:22:57 +04:00
|
|
|
}
|
2002-11-13 01:52:55 +03:00
|
|
|
} catch (e) {}
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2000-07-17 05:12:10 +04:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
function updateCharsetPopupMenu(menuPopup)
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
if (IsDocumentModified() && !IsDocumentEmpty())
|
2000-07-17 05:12:10 +04:00
|
|
|
{
|
|
|
|
for (var i = 0; i < menuPopup.childNodes.length; i++)
|
|
|
|
{
|
|
|
|
var menuItem = menuPopup.childNodes[i];
|
2001-11-15 18:28:24 +03:00
|
|
|
menuItem.setAttribute('disabled', 'true');
|
2000-07-17 05:12:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-05-10 09:30:13 +04:00
|
|
|
|
|
|
|
// --------------------------- Text style ---------------------------
|
|
|
|
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
function onParagraphFormatChange(paraMenuList, commandID)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2001-03-29 01:16:44 +04:00
|
|
|
if (!paraMenuList)
|
|
|
|
return;
|
|
|
|
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
var commandNode = document.getElementById(commandID);
|
2000-05-10 09:30:13 +04:00
|
|
|
var state = commandNode.getAttribute("state");
|
|
|
|
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
// force match with "normal"
|
|
|
|
if (state == "body")
|
|
|
|
state = "";
|
2001-03-22 03:59:29 +03:00
|
|
|
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
if (state == "mixed")
|
|
|
|
{
|
|
|
|
//Selection is the "mixed" ( > 1 style) state
|
|
|
|
paraMenuList.selectedItem = null;
|
2001-03-22 03:59:29 +03:00
|
|
|
paraMenuList.setAttribute("label",GetString('Mixed'));
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var menuPopup = document.getElementById("ParagraphPopup");
|
|
|
|
var menuItems = menuPopup.childNodes;
|
2000-09-06 03:21:22 +04:00
|
|
|
for (var i=0; i < menuItems.length; i++)
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
{
|
|
|
|
var menuItem = menuItems.item(i);
|
2001-04-05 01:52:25 +04:00
|
|
|
if ("value" in menuItem && menuItem.value == state)
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
{
|
|
|
|
paraMenuList.selectedItem = menuItem;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
function onFontFaceChange(fontFaceMenuList, commandID)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
var commandNode = document.getElementById(commandID);
|
|
|
|
var state = commandNode.getAttribute("state");
|
|
|
|
|
|
|
|
if (state == "mixed")
|
|
|
|
{
|
|
|
|
//Selection is the "mixed" ( > 1 style) state
|
|
|
|
fontFaceMenuList.selectedItem = null;
|
2001-03-22 03:59:29 +03:00
|
|
|
fontFaceMenuList.setAttribute("label",GetString('Mixed'));
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var menuPopup = document.getElementById("FontFacePopup");
|
|
|
|
var menuItems = menuPopup.childNodes;
|
2000-09-06 03:21:22 +04:00
|
|
|
for (var i=0; i < menuItems.length; i++)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
var menuItem = menuItems.item(i);
|
2001-04-05 01:52:25 +04:00
|
|
|
if (menuItem.getAttribute("label") && ("value" in menuItem && menuItem.value.toLowerCase() == state.toLowerCase()))
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
fontFaceMenuList.selectedItem = menuItem;
|
|
|
|
break;
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorSelectFontSize()
|
|
|
|
{
|
|
|
|
var select = document.getElementById("FontSizeSelect");
|
|
|
|
if (select)
|
2001-03-22 03:59:29 +03:00
|
|
|
{
|
2000-05-10 09:30:13 +04:00
|
|
|
if (select.selectedIndex == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
EditorSetFontSize(gFontSizeNames[select.selectedIndex]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
function onFontSizeChange(fontSizeMenulist, commandID)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
// If we don't match anything, set to "0 (normal)"
|
|
|
|
var newIndex = 2;
|
2001-03-22 03:59:29 +03:00
|
|
|
var size = fontSizeMenulist.getAttribute("size");
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
if ( size == "mixed")
|
|
|
|
{
|
|
|
|
// No single type selected
|
|
|
|
newIndex = -1;
|
|
|
|
}
|
2001-03-22 03:59:29 +03:00
|
|
|
else
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
{
|
2000-09-06 03:21:22 +04:00
|
|
|
for (var i = 0; i < gFontSizeNames.length; i++)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
if( gFontSizeNames[i] == size )
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
newIndex = i;
|
|
|
|
break;
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
if (fontSizeMenulist.selectedIndex != newIndex)
|
|
|
|
fontSizeMenulist.selectedIndex = newIndex;
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function EditorSetFontSize(size)
|
|
|
|
{
|
2001-03-22 03:59:29 +03:00
|
|
|
if( size == "0" || size == "normal" ||
|
2000-05-10 09:30:13 +04:00
|
|
|
size == "medium" )
|
|
|
|
{
|
2002-07-10 00:24:37 +04:00
|
|
|
EditorRemoveTextProperty("font", "size");
|
2001-03-22 03:59:29 +03:00
|
|
|
// Also remove big and small,
|
2000-10-09 18:55:04 +04:00
|
|
|
// else it will seem like size isn't changing correctly
|
2002-07-10 00:24:37 +04:00
|
|
|
EditorRemoveTextProperty("small", "");
|
|
|
|
EditorRemoveTextProperty("big", "");
|
2000-05-10 09:30:13 +04:00
|
|
|
} else {
|
|
|
|
// Temp: convert from new CSS size strings to old HTML size strings
|
|
|
|
switch (size)
|
|
|
|
{
|
|
|
|
case "xx-small":
|
|
|
|
case "x-small":
|
|
|
|
size = "-2";
|
|
|
|
break;
|
|
|
|
case "small":
|
|
|
|
size = "-1";
|
|
|
|
break;
|
|
|
|
case "large":
|
|
|
|
size = "+1";
|
|
|
|
break;
|
|
|
|
case "x-large":
|
|
|
|
size = "+2";
|
|
|
|
break;
|
|
|
|
case "xx-large":
|
|
|
|
size = "+3";
|
|
|
|
break;
|
|
|
|
}
|
2002-07-10 00:24:37 +04:00
|
|
|
EditorSetTextProperty("font", "size", size);
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
2000-05-12 18:46:25 +04:00
|
|
|
gContentWindow.focus();
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2000-10-09 18:55:04 +04:00
|
|
|
function initFontFaceMenu(menuPopup)
|
|
|
|
{
|
2003-03-21 11:36:28 +03:00
|
|
|
initLocalFontFaceMenu(menuPopup);
|
|
|
|
|
2000-10-09 18:55:04 +04:00
|
|
|
if (menuPopup)
|
|
|
|
{
|
|
|
|
var children = menuPopup.childNodes;
|
|
|
|
if (!children) return;
|
|
|
|
|
2002-08-17 01:37:24 +04:00
|
|
|
var firstHas = { value: false };
|
|
|
|
var anyHas = { value: false };
|
|
|
|
var allHas = { value: false };
|
2000-10-09 18:55:04 +04:00
|
|
|
|
|
|
|
// we need to set or clear the checkmark for each menu item since the selection
|
|
|
|
// may be in a new location from where it was when the menu was previously opened
|
|
|
|
|
|
|
|
// Fixed width (second menu item) is special case: old TT ("teletype") attribute
|
2002-07-10 00:24:37 +04:00
|
|
|
EditorGetTextProperty("tt", "", "", firstHas, anyHas, allHas);
|
2000-10-09 18:55:04 +04:00
|
|
|
children[1].setAttribute("checked", allHas.value);
|
2003-04-17 11:35:55 +04:00
|
|
|
|
|
|
|
if (!anyHas.value)
|
|
|
|
EditorGetTextProperty("font", "face", "", firstHas, anyHas, allHas);
|
|
|
|
|
|
|
|
children[0].setAttribute("checked", !anyHas.value);
|
2000-10-09 18:55:04 +04:00
|
|
|
|
|
|
|
// Skip over default, TT, and separator
|
2001-02-27 01:02:07 +03:00
|
|
|
for (var i = 3; i < children.length; i++)
|
2000-10-09 18:55:04 +04:00
|
|
|
{
|
|
|
|
var menuItem = children[i];
|
2001-03-22 03:59:29 +03:00
|
|
|
var faceType = menuItem.getAttribute("value");
|
2001-02-27 01:02:07 +03:00
|
|
|
|
2000-10-09 18:55:04 +04:00
|
|
|
if (faceType)
|
|
|
|
{
|
2002-07-10 00:24:37 +04:00
|
|
|
EditorGetTextProperty("font", "face", faceType, firstHas, anyHas, allHas);
|
2000-10-09 18:55:04 +04:00
|
|
|
|
2003-03-21 11:36:28 +03:00
|
|
|
// Check the menuitem only if all of selection has the face
|
|
|
|
if (allHas.value)
|
|
|
|
{
|
|
|
|
menuItem.setAttribute("checked", "true");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// in case none match, make sure we've cleared the checkmark
|
|
|
|
menuItem.removeAttribute("checked");
|
2000-10-09 18:55:04 +04:00
|
|
|
}
|
|
|
|
}
|
2001-03-22 03:59:29 +03:00
|
|
|
}
|
2000-10-09 18:55:04 +04:00
|
|
|
}
|
|
|
|
|
2003-04-16 11:07:10 +04:00
|
|
|
const kFixedFontFaceMenuItems = 7; // number of fixed font face menuitems
|
|
|
|
|
2003-03-21 11:36:28 +03:00
|
|
|
function initLocalFontFaceMenu(menuPopup)
|
|
|
|
{
|
|
|
|
if (!gLocalFonts)
|
|
|
|
{
|
|
|
|
// Build list of all local fonts once per editor
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var enumerator = Components.classes["@mozilla.org/gfx/fontenumerator;1"]
|
|
|
|
.getService(Components.interfaces.nsIFontEnumerator);
|
|
|
|
var localFontCount = { value: 0 }
|
|
|
|
gLocalFonts = enumerator.EnumerateAllFonts(localFontCount);
|
2003-04-16 11:07:10 +04:00
|
|
|
}
|
|
|
|
catch(e) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
var useRadioMenuitems = (menuPopup.parentNode.localName == "menu"); // don't do this for menulists
|
|
|
|
if (menuPopup.childNodes.length == kFixedFontFaceMenuItems)
|
|
|
|
{
|
|
|
|
if (gLocalFonts.length == 0) {
|
|
|
|
menuPopup.childNodes[kFixedFontFaceMenuItems - 1].hidden = true;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < gLocalFonts.length; ++i)
|
|
|
|
{
|
|
|
|
if (gLocalFonts[i] != "")
|
2003-03-21 11:36:28 +03:00
|
|
|
{
|
2003-04-16 11:07:10 +04:00
|
|
|
var itemNode = document.createElementNS(XUL_NS, "menuitem");
|
|
|
|
itemNode.setAttribute("label", gLocalFonts[i]);
|
|
|
|
itemNode.setAttribute("value", gLocalFonts[i]);
|
|
|
|
if (useRadioMenuitems) {
|
2003-03-21 11:36:28 +03:00
|
|
|
itemNode.setAttribute("type", "radio");
|
|
|
|
itemNode.setAttribute("name", "2");
|
2003-04-23 12:25:34 +04:00
|
|
|
itemNode.setAttribute("observes", "cmd_renderedHTMLEnabler");
|
2003-03-21 11:36:28 +03:00
|
|
|
}
|
2003-04-16 11:07:10 +04:00
|
|
|
menuPopup.appendChild(itemNode);
|
2003-03-21 11:36:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-09 18:55:04 +04:00
|
|
|
function initFontSizeMenu(menuPopup)
|
|
|
|
{
|
|
|
|
if (menuPopup)
|
|
|
|
{
|
|
|
|
var children = menuPopup.childNodes;
|
|
|
|
if (!children) return;
|
|
|
|
|
2002-08-17 01:37:24 +04:00
|
|
|
var firstHas = { value: false };
|
|
|
|
var anyHas = { value: false };
|
|
|
|
var allHas = { value: false };
|
2000-10-09 18:55:04 +04:00
|
|
|
|
|
|
|
var sizeWasFound = false;
|
|
|
|
|
|
|
|
// we need to set or clear the checkmark for each menu item since the selection
|
|
|
|
// may be in a new location from where it was when the menu was previously opened
|
|
|
|
|
|
|
|
// First 2 items add <small> and <big> tags
|
|
|
|
// While it would be better to show the number of levels,
|
|
|
|
// at least this tells user if either of them are set
|
|
|
|
var menuItem = children[0];
|
|
|
|
if (menuItem)
|
|
|
|
{
|
2002-07-10 00:24:37 +04:00
|
|
|
EditorGetTextProperty("small", "", "", firstHas, anyHas, allHas);
|
2000-10-09 18:55:04 +04:00
|
|
|
menuItem.setAttribute("checked", allHas.value);
|
|
|
|
sizeWasFound = anyHas.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
menuItem = children[1];
|
|
|
|
if (menuItem)
|
|
|
|
{
|
2002-07-10 00:24:37 +04:00
|
|
|
EditorGetTextProperty("big", "", "", firstHas, anyHas, allHas);
|
2000-10-09 18:55:04 +04:00
|
|
|
menuItem.setAttribute("checked", allHas.value);
|
|
|
|
sizeWasFound |= anyHas.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fixed size items start after menu separator
|
|
|
|
var menuIndex = 3;
|
|
|
|
// Index of the medium (default) item
|
|
|
|
var mediumIndex = 5;
|
|
|
|
|
|
|
|
// Scan through all supported "font size" attribute values
|
|
|
|
for (var i = -2; i <= 3; i++)
|
|
|
|
{
|
|
|
|
menuItem = children[menuIndex];
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2000-10-09 18:55:04 +04:00
|
|
|
// Skip over medium since it'll be set below.
|
2001-03-22 03:59:29 +03:00
|
|
|
// If font size=0 is actually set, we'll toggle it off below if
|
2000-10-09 18:55:04 +04:00
|
|
|
// we enter this loop in this case.
|
|
|
|
if (menuItem && (i != 0))
|
|
|
|
{
|
|
|
|
var sizeString = (i <= 0) ? String(i) : ("+" + String(i));
|
2002-07-10 00:24:37 +04:00
|
|
|
EditorGetTextProperty("font", "size", sizeString, firstHas, anyHas, allHas);
|
2000-10-09 18:55:04 +04:00
|
|
|
// Check the item only if all of selection has the size...
|
|
|
|
menuItem.setAttribute("checked", allHas.value);
|
|
|
|
// ...but remember if ANY of of selection had size set
|
|
|
|
sizeWasFound |= anyHas.value;
|
2001-03-22 03:59:29 +03:00
|
|
|
}
|
2000-10-09 18:55:04 +04:00
|
|
|
menuIndex++;
|
|
|
|
}
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2000-10-09 18:55:04 +04:00
|
|
|
// if no size was found, then check default (medium)
|
|
|
|
// note that no item is checked in the case of "mixed" selection
|
|
|
|
children[mediumIndex].setAttribute("checked", !sizeWasFound);
|
2001-03-22 03:59:29 +03:00
|
|
|
}
|
2003-04-16 11:07:10 +04:00
|
|
|
}
|
2000-10-09 18:55:04 +04:00
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
function onHighlightColorChange()
|
|
|
|
{
|
|
|
|
var commandNode = document.getElementById("cmd_highlight");
|
|
|
|
if (commandNode)
|
|
|
|
{
|
|
|
|
var color = commandNode.getAttribute("state");
|
|
|
|
var button = document.getElementById("HighlightColorButton");
|
|
|
|
if (button)
|
|
|
|
{
|
|
|
|
// No color set - get color set on page or other defaults
|
|
|
|
if (!color)
|
|
|
|
color = "transparent" ;
|
|
|
|
|
|
|
|
button.setAttribute("style", "background-color:"+color+" !important");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-08-14 17:12:52 +04:00
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
function onFontColorChange()
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
var commandNode = document.getElementById("cmd_fontColor");
|
2000-08-31 16:44:56 +04:00
|
|
|
if (commandNode)
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
{
|
2000-08-31 16:44:56 +04:00
|
|
|
var color = commandNode.getAttribute("state");
|
|
|
|
var button = document.getElementById("TextColorButton");
|
|
|
|
if (button)
|
|
|
|
{
|
|
|
|
// No color set - get color set on page or other defaults
|
|
|
|
if (!color)
|
|
|
|
color = gDefaultTextColor;
|
2001-03-22 03:59:29 +03:00
|
|
|
button.setAttribute("style", "background-color:"+color);
|
2000-08-31 16:44:56 +04:00
|
|
|
}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
}
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2000-08-31 16:44:56 +04:00
|
|
|
function onBackgroundColorChange()
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2000-08-31 16:44:56 +04:00
|
|
|
var commandNode = document.getElementById("cmd_backgroundColor");
|
|
|
|
if (commandNode)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2000-08-31 16:44:56 +04:00
|
|
|
var color = commandNode.getAttribute("state");
|
|
|
|
var button = document.getElementById("BackgroundColorButton");
|
|
|
|
if (button)
|
|
|
|
{
|
|
|
|
if (!color)
|
|
|
|
color = gDefaultBackgroundColor;
|
2000-09-06 03:21:22 +04:00
|
|
|
|
2001-03-22 03:59:29 +03:00
|
|
|
button.setAttribute("style", "background-color:"+color);
|
2000-08-31 16:44:56 +04:00
|
|
|
}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
}
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2002-01-05 23:40:05 +03:00
|
|
|
// Call this when user changes text and/or background colors of the page
|
|
|
|
function UpdateDefaultColors()
|
|
|
|
{
|
|
|
|
var BrowserColors = GetDefaultBrowserColors();
|
|
|
|
var bodyelement = GetBodyElement();
|
|
|
|
var defTextColor = gDefaultTextColor;
|
|
|
|
var defBackColor = gDefaultBackgroundColor;
|
|
|
|
|
|
|
|
if (bodyelement)
|
|
|
|
{
|
|
|
|
var color = bodyelement.getAttribute("text");
|
|
|
|
if (color)
|
|
|
|
gDefaultTextColor = color;
|
|
|
|
else if (BrowserColors)
|
|
|
|
gDefaultTextColor = BrowserColors.TextColor;
|
|
|
|
|
|
|
|
color = bodyelement.getAttribute("bgcolor");
|
|
|
|
if (color)
|
|
|
|
gDefaultBackgroundColor = color;
|
|
|
|
else if (BrowserColors)
|
|
|
|
gDefaultBackgroundColor = BrowserColors.BackgroundColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trigger update on toolbar
|
|
|
|
if (defTextColor != gDefaultTextColor)
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
goUpdateCommandState("cmd_fontColor");
|
2002-01-05 23:40:05 +03:00
|
|
|
onFontColorChange();
|
|
|
|
}
|
|
|
|
if (defBackColor != gDefaultBackgroundColor)
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
goUpdateCommandState("cmd_backgroundColor");
|
2002-01-05 23:40:05 +03:00
|
|
|
onBackgroundColorChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
function GetBackgroundElementWithColor()
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
var editor = GetCurrentTableEditor();
|
|
|
|
if (!editor)
|
|
|
|
return null;
|
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
gColorObj.Type = "";
|
|
|
|
gColorObj.PageColor = "";
|
|
|
|
gColorObj.TableColor = "";
|
|
|
|
gColorObj.CellColor = "";
|
|
|
|
gColorObj.BackgroundColor = "";
|
2002-08-16 02:40:18 +04:00
|
|
|
gColorObj.SelectedType = "";
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-08-17 01:37:24 +04:00
|
|
|
var tagNameObj = { value: "" };
|
2002-07-10 00:24:37 +04:00
|
|
|
var element;
|
2002-07-13 02:28:30 +04:00
|
|
|
try {
|
2002-11-13 01:52:55 +03:00
|
|
|
element = editor.getSelectedOrParentTableElement(tagNameObj, {value:0});
|
2002-07-13 02:28:30 +04:00
|
|
|
}
|
|
|
|
catch(e) {}
|
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
if (element && tagNameObj && tagNameObj.value)
|
|
|
|
{
|
2002-01-09 16:51:37 +03:00
|
|
|
gColorObj.BackgroundColor = GetHTMLOrCSSStyleValue(element, "bgcolor", "background-color");
|
|
|
|
gColorObj.BackgroundColor = ConvertRGBColorIntoHEXColor(gColorObj.BackgroundColor);
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
if (tagNameObj.value.toLowerCase() == "td")
|
|
|
|
{
|
|
|
|
gColorObj.Type = "Cell";
|
|
|
|
gColorObj.CellColor = gColorObj.BackgroundColor;
|
2001-03-22 03:59:29 +03:00
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
// Get any color that might be on parent table
|
|
|
|
var table = GetParentTable(element);
|
2002-01-09 16:51:37 +03:00
|
|
|
gColorObj.TableColor = GetHTMLOrCSSStyleValue(table, "bgcolor", "background-color");
|
|
|
|
gColorObj.TableColor = ConvertRGBColorIntoHEXColor(gColorObj.TableColor);
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gColorObj.Type = "Table";
|
|
|
|
gColorObj.TableColor = gColorObj.BackgroundColor;
|
|
|
|
}
|
2002-08-16 02:40:18 +04:00
|
|
|
gColorObj.SelectedType = gColorObj.Type;
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-04 11:59:57 +04:00
|
|
|
var IsCSSPrefChecked = gPrefs.getBoolPref(kUseCssPref);
|
2002-11-13 01:52:55 +03:00
|
|
|
if (IsCSSPrefChecked && IsHTMLEditor())
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
var selection = editor.selection;
|
2002-01-09 16:51:37 +03:00
|
|
|
if (selection)
|
|
|
|
{
|
|
|
|
element = selection.focusNode;
|
2002-11-13 01:52:55 +03:00
|
|
|
while (!editor.nodeIsBlock(element))
|
2002-01-09 16:51:37 +03:00
|
|
|
element = element.parentNode;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
element = GetBodyElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
element = GetBodyElement();
|
|
|
|
}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
if (element)
|
|
|
|
{
|
|
|
|
gColorObj.Type = "Page";
|
2002-01-09 16:51:37 +03:00
|
|
|
gColorObj.BackgroundColor = GetHTMLOrCSSStyleValue(element, "bgcolor", "background-color");
|
|
|
|
if (gColorObj.BackgroundColor == "")
|
|
|
|
{
|
|
|
|
gColorObj.BackgroundColor = "transparent";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gColorObj.BackgroundColor = ConvertRGBColorIntoHEXColor(gColorObj.BackgroundColor);
|
|
|
|
}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
gColorObj.PageColor = gColorObj.BackgroundColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return element;
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2001-02-07 10:52:02 +03:00
|
|
|
function SetSmiley(smileyText)
|
|
|
|
{
|
2002-07-13 02:28:30 +04:00
|
|
|
try {
|
2002-11-13 01:52:55 +03:00
|
|
|
GetCurrentEditor().insertText(smileyText);
|
2002-07-13 02:28:30 +04:00
|
|
|
gContentWindow.focus();
|
|
|
|
}
|
|
|
|
catch(e) {}
|
2001-02-07 10:52:02 +03:00
|
|
|
}
|
|
|
|
|
2001-03-24 03:58:52 +03:00
|
|
|
function EditorSelectColor(colorType, mouseEvent)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
if (!editor || !gColorObj)
|
2001-03-24 03:58:52 +03:00
|
|
|
return;
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
|
2001-03-24 03:58:52 +03:00
|
|
|
// Shift + mouse click automatically applies last color, if available
|
|
|
|
var useLastColor = mouseEvent ? ( mouseEvent.button == 0 && mouseEvent.shiftKey ) : false;
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
var element;
|
|
|
|
var table;
|
|
|
|
var currentColor = "";
|
2000-09-06 03:21:22 +04:00
|
|
|
var commandNode;
|
2001-03-22 03:59:29 +03:00
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
if (!colorType)
|
|
|
|
colorType = "";
|
|
|
|
|
|
|
|
if (colorType == "Text")
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
gColorObj.Type = colorType;
|
2000-05-10 09:30:13 +04:00
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
// Get color from command node state
|
2000-09-06 03:21:22 +04:00
|
|
|
commandNode = document.getElementById("cmd_fontColor");
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
currentColor = commandNode.getAttribute("state");
|
2003-04-07 12:11:21 +04:00
|
|
|
currentColor = ConvertRGBColorIntoHEXColor(currentColor);
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
gColorObj.TextColor = currentColor;
|
2001-03-24 03:58:52 +03:00
|
|
|
|
|
|
|
if (useLastColor && gColorObj.LastTextColor )
|
|
|
|
gColorObj.TextColor = gColorObj.LastTextColor;
|
|
|
|
else
|
|
|
|
useLastColor = false;
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
}
|
2002-01-09 16:51:37 +03:00
|
|
|
else if (colorType == "Highlight")
|
|
|
|
{
|
|
|
|
gColorObj.Type = colorType;
|
|
|
|
|
|
|
|
// Get color from command node state
|
|
|
|
commandNode = document.getElementById("cmd_highlight");
|
|
|
|
currentColor = commandNode.getAttribute("state");
|
2003-04-07 12:11:21 +04:00
|
|
|
currentColor = ConvertRGBColorIntoHEXColor(currentColor);
|
2002-01-09 16:51:37 +03:00
|
|
|
gColorObj.HighlightColor = currentColor;
|
|
|
|
|
|
|
|
if (useLastColor && gColorObj.LastHighlightColor )
|
|
|
|
gColorObj.HighlightColor = gColorObj.LastHighlightColor;
|
|
|
|
else
|
|
|
|
useLastColor = false;
|
|
|
|
}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
element = GetBackgroundElementWithColor();
|
|
|
|
if (!element)
|
|
|
|
return;
|
2000-05-10 09:30:13 +04:00
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
// Get the table if we found a cell
|
|
|
|
if (gColorObj.Type == "Table")
|
|
|
|
table = element;
|
|
|
|
else if (gColorObj.Type == "Cell")
|
|
|
|
table = GetParentTable(element);
|
2000-05-10 09:30:13 +04:00
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
// Save to avoid resetting if not necessary
|
|
|
|
currentColor = gColorObj.BackgroundColor;
|
2000-05-10 09:30:13 +04:00
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
if (colorType == "TableOrCell" || colorType == "Cell")
|
|
|
|
{
|
|
|
|
if (gColorObj.Type == "Cell")
|
|
|
|
gColorObj.Type = colorType;
|
|
|
|
else if (gColorObj.Type != "Table")
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (colorType == "Table" && gColorObj.Type == "Page")
|
|
|
|
return;
|
2001-03-22 03:59:29 +03:00
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
if (colorType == "" && gColorObj.Type == "Cell")
|
|
|
|
{
|
|
|
|
// Using empty string for requested type means
|
|
|
|
// we can let user select cell or table
|
|
|
|
gColorObj.Type = "TableOrCell";
|
|
|
|
}
|
2001-03-29 01:16:44 +04:00
|
|
|
|
|
|
|
if (useLastColor && gColorObj.LastBackgroundColor )
|
|
|
|
gColorObj.BackgroundColor = gColorObj.LastBackgroundColor;
|
|
|
|
else
|
|
|
|
useLastColor = false;
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
}
|
|
|
|
// Save the type we are really requesting
|
|
|
|
colorType = gColorObj.Type;
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2001-03-29 01:16:44 +04:00
|
|
|
if (!useLastColor)
|
|
|
|
{
|
|
|
|
// Avoid the JS warning
|
|
|
|
gColorObj.NoDefault = false;
|
2001-01-04 04:30:17 +03:00
|
|
|
|
2001-03-29 01:16:44 +04:00
|
|
|
// Launch the ColorPicker dialog
|
|
|
|
// TODO: Figure out how to position this under the color buttons on the toolbar
|
|
|
|
window.openDialog("chrome://editor/content/EdColorPicker.xul", "_blank", "chrome,close,titlebar,modal", "", gColorObj);
|
2000-08-30 06:44:18 +04:00
|
|
|
|
2001-03-29 01:16:44 +04:00
|
|
|
// User canceled the dialog
|
|
|
|
if (gColorObj.Cancel)
|
|
|
|
return;
|
|
|
|
}
|
2000-08-30 06:44:18 +04:00
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
if (gColorObj.Type == "Text")
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
{
|
|
|
|
if (currentColor != gColorObj.TextColor)
|
2001-03-29 01:16:44 +04:00
|
|
|
{
|
2001-07-11 03:57:04 +04:00
|
|
|
if (gColorObj.TextColor)
|
2002-07-10 00:24:37 +04:00
|
|
|
EditorSetTextProperty("font", "color", gColorObj.TextColor);
|
2001-07-11 03:57:04 +04:00
|
|
|
else
|
2002-07-10 00:24:37 +04:00
|
|
|
EditorRemoveTextProperty("font", "color");
|
2001-03-29 01:16:44 +04:00
|
|
|
}
|
2000-08-31 16:44:56 +04:00
|
|
|
// Update the command state (this will trigger color button update)
|
2002-11-13 01:52:55 +03:00
|
|
|
goUpdateCommandState("cmd_fontColor");
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
}
|
2002-01-09 16:51:37 +03:00
|
|
|
else if (gColorObj.Type == "Highlight")
|
|
|
|
{
|
|
|
|
if (currentColor != gColorObj.HighlightColor)
|
|
|
|
{
|
|
|
|
if (gColorObj.HighlightColor)
|
2002-07-10 00:24:37 +04:00
|
|
|
EditorSetTextProperty("font", "bgcolor", gColorObj.HighlightColor);
|
2002-01-09 16:51:37 +03:00
|
|
|
else
|
2002-07-10 00:24:37 +04:00
|
|
|
EditorRemoveTextProperty("font", "bgcolor");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
// Update the command state (this will trigger color button update)
|
2002-11-13 01:52:55 +03:00
|
|
|
goUpdateCommandState("cmd_highlight");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
else if (element)
|
|
|
|
{
|
2002-03-15 18:33:29 +03:00
|
|
|
if (gColorObj.Type == "Table")
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
{
|
|
|
|
// Set background on a table
|
|
|
|
// Note that we shouldn't trust "currentColor" because of "TableOrCell" behavior
|
|
|
|
if (table)
|
|
|
|
{
|
|
|
|
var bgcolor = table.getAttribute("bgcolor");
|
|
|
|
if (bgcolor != gColorObj.BackgroundColor)
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
2000-08-31 16:44:56 +04:00
|
|
|
if (gColorObj.BackgroundColor)
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.setAttributeOrEquivalent(table, "bgcolor", gColorObj.BackgroundColor, false);
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
else
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.removeAttributeOrEquivalent(table, "bgcolor", false);
|
|
|
|
} catch (e) {}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
}
|
2001-03-22 03:59:29 +03:00
|
|
|
}
|
2002-11-13 01:52:55 +03:00
|
|
|
else if (currentColor != gColorObj.BackgroundColor && IsHTMLEditor())
|
2001-08-10 07:47:37 +04:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.beginTransaction();
|
2002-07-13 02:28:30 +04:00
|
|
|
try
|
2001-08-10 07:47:37 +04:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.setBackgroundColor(gColorObj.BackgroundColor);
|
2002-07-13 02:28:30 +04:00
|
|
|
|
|
|
|
if (gColorObj.Type == "Page" && gColorObj.BackgroundColor)
|
2001-08-10 07:47:37 +04:00
|
|
|
{
|
2002-07-13 02:28:30 +04:00
|
|
|
// Set all page colors not explicitly set,
|
|
|
|
// else you can end up with unreadable pages
|
|
|
|
// because viewer's default colors may not be same as page author's
|
|
|
|
var bodyelement = GetBodyElement();
|
|
|
|
if (bodyelement)
|
2002-03-15 18:33:29 +03:00
|
|
|
{
|
2002-07-13 02:28:30 +04:00
|
|
|
var defColors = GetDefaultBrowserColors();
|
|
|
|
if (defColors)
|
|
|
|
{
|
|
|
|
if (!bodyelement.getAttribute("text"))
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.setAttributeOrEquivalent(bodyelement, "text", defColors.TextColor, false);
|
2002-07-13 02:28:30 +04:00
|
|
|
|
|
|
|
// The following attributes have no individual CSS declaration counterparts
|
|
|
|
// Getting rid of them in favor of CSS implies CSS rules management
|
|
|
|
if (!bodyelement.getAttribute("link"))
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.setAttribute(bodyelement, "link", defColors.LinkColor);
|
2002-07-13 02:28:30 +04:00
|
|
|
|
|
|
|
if (!bodyelement.getAttribute("alink"))
|
2003-10-15 05:56:12 +04:00
|
|
|
editor.setAttribute(bodyelement, "alink", defColors.ActiveLinkColor);
|
2002-07-13 02:28:30 +04:00
|
|
|
|
|
|
|
if (!bodyelement.getAttribute("vlink"))
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.setAttribute(bodyelement, "vlink", defColors.VisitedLinkColor);
|
2002-07-13 02:28:30 +04:00
|
|
|
}
|
2001-08-10 07:47:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-07-13 02:28:30 +04:00
|
|
|
catch(e) {}
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.endTransaction();
|
2001-08-10 07:47:37 +04:00
|
|
|
}
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
goUpdateCommandState("cmd_backgroundColor");
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
}
|
2001-05-09 09:23:37 +04:00
|
|
|
gContentWindow.focus();
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
function GetParentTable(element)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
var node = element;
|
|
|
|
while (node)
|
|
|
|
{
|
2001-05-09 09:23:37 +04:00
|
|
|
if (node.nodeName.toLowerCase() == "table")
|
|
|
|
return node;
|
|
|
|
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetParentTableCell(element)
|
|
|
|
{
|
|
|
|
var node = element;
|
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
if (node.nodeName.toLowerCase() == "td" || node.nodeName.toLowerCase() == "th")
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
return node;
|
2000-05-10 09:30:13 +04:00
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
return node;
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2002-03-17 23:39:16 +03:00
|
|
|
function EditorDblClick(event)
|
|
|
|
{
|
2003-04-01 10:12:51 +04:00
|
|
|
// We check event.explicitOriginalTarget here because .target will never
|
|
|
|
// be a textnode (bug 193689)
|
|
|
|
if (event.explicitOriginalTarget)
|
2002-03-26 23:52:06 +03:00
|
|
|
{
|
|
|
|
// Only bring up properties if clicked on an element or selected link
|
|
|
|
var element;
|
|
|
|
try {
|
2003-04-01 10:12:51 +04:00
|
|
|
element = event.explicitOriginalTarget.QueryInterface(
|
|
|
|
Components.interfaces.nsIDOMElement);
|
2002-03-26 23:52:06 +03:00
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
// We use "href" instead of "a" to not be fooled by named anchor
|
|
|
|
if (!element)
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
element = GetCurrentEditor().getSelectedElement("href");
|
|
|
|
} catch (e) {}
|
2002-03-26 23:52:06 +03:00
|
|
|
|
|
|
|
if (element)
|
|
|
|
{
|
|
|
|
goDoCommand("cmd_objectProperties");
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
2002-03-17 23:39:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function EditorClick(event)
|
|
|
|
{
|
2002-04-16 17:30:40 +04:00
|
|
|
if (!event)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.detail == 2)
|
|
|
|
{
|
|
|
|
EditorDblClick(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-10-08 00:13:09 +04:00
|
|
|
// For Web Composer: In Show All Tags Mode,
|
2002-03-17 23:39:16 +03:00
|
|
|
// single click selects entire element,
|
|
|
|
// except for body and table elements
|
2003-04-01 10:12:51 +04:00
|
|
|
if (IsWebComposer() && event.explicitOriginalTarget && IsHTMLEditor() &&
|
|
|
|
gEditorDisplayMode == kDisplayModeAllTags)
|
2002-03-17 23:39:16 +03:00
|
|
|
{
|
2002-07-13 02:28:30 +04:00
|
|
|
try
|
|
|
|
{
|
2003-04-01 10:12:51 +04:00
|
|
|
// We check event.explicitOriginalTarget here because .target will never
|
|
|
|
// be a textnode (bug 193689)
|
|
|
|
var element = event.explicitOriginalTarget.QueryInterface(
|
|
|
|
Components.interfaces.nsIDOMElement);
|
2002-07-13 02:28:30 +04:00
|
|
|
var name = element.localName.toLowerCase();
|
|
|
|
if (name != "body" && name != "table" &&
|
|
|
|
name != "td" && name != "th" && name != "caption" && name != "tr")
|
|
|
|
{
|
2003-04-01 10:12:51 +04:00
|
|
|
GetCurrentEditor().selectElement(event.explicitOriginalTarget);
|
2002-07-13 02:28:30 +04:00
|
|
|
event.preventDefault();
|
2002-03-17 23:39:16 +03:00
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-22 03:59:29 +03:00
|
|
|
/*TODO: We need an oncreate hook to do enabling/disabling for the
|
|
|
|
Format menu. There should be code like this for the
|
2000-09-06 03:21:22 +04:00
|
|
|
object-specific "Properties" item
|
2000-05-10 09:30:13 +04:00
|
|
|
*/
|
|
|
|
// For property dialogs, we want the selected element,
|
2000-09-06 03:21:22 +04:00
|
|
|
// but will accept a parent link, list, or table cell if inside one
|
|
|
|
function GetObjectForProperties()
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
if (!editor || !IsHTMLEditor())
|
2002-08-21 03:59:19 +04:00
|
|
|
return null;
|
2002-07-13 02:28:30 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var element;
|
|
|
|
try {
|
|
|
|
element = editor.getSelectedElement("");
|
|
|
|
} catch (e) {}
|
2000-09-07 09:39:27 +04:00
|
|
|
if (element)
|
|
|
|
return element;
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2001-03-22 03:59:29 +03:00
|
|
|
// Find nearest parent of selection anchor node
|
2000-09-07 09:39:27 +04:00
|
|
|
// that is a link, list, table cell, or table
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var anchorNode
|
2000-09-07 09:39:27 +04:00
|
|
|
var node;
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
anchorNode = editor.selection.anchorNode;
|
|
|
|
if (anchorNode.firstChild)
|
|
|
|
{
|
|
|
|
// Start at actual selected node
|
|
|
|
var offset = editor.selection.anchorOffset;
|
|
|
|
// Note: If collapsed, offset points to element AFTER caret,
|
|
|
|
// thus node may be null
|
|
|
|
node = anchorNode.childNodes.item(offset);
|
|
|
|
}
|
|
|
|
if (!node)
|
|
|
|
node = anchorNode;
|
|
|
|
} catch (e) {}
|
2000-09-07 09:39:27 +04:00
|
|
|
|
|
|
|
while (node)
|
|
|
|
{
|
2000-09-22 09:13:34 +04:00
|
|
|
if (node.nodeName)
|
2000-09-07 09:39:27 +04:00
|
|
|
{
|
2000-09-22 09:13:34 +04:00
|
|
|
var nodeName = node.nodeName.toLowerCase();
|
2000-09-07 09:39:27 +04:00
|
|
|
|
|
|
|
// Done when we hit the body
|
2000-09-22 09:13:34 +04:00
|
|
|
if (nodeName == "body") break;
|
2000-09-07 09:39:27 +04:00
|
|
|
|
2000-09-22 09:13:34 +04:00
|
|
|
if ((nodeName == "a" && node.href) ||
|
|
|
|
nodeName == "ol" || nodeName == "ul" || nodeName == "dl" ||
|
|
|
|
nodeName == "td" || nodeName == "th" ||
|
|
|
|
nodeName == "table")
|
2000-09-07 09:39:27 +04:00
|
|
|
{
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
return null;
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function SetEditMode(mode)
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
if (!IsHTMLEditor())
|
2002-08-21 03:59:19 +04:00
|
|
|
return;
|
2002-07-13 02:28:30 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var bodyElement = GetBodyElement();
|
|
|
|
if (!bodyElement)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2002-07-13 02:28:30 +04:00
|
|
|
dump("SetEditMode: We don't have a body node!\n");
|
|
|
|
return;
|
|
|
|
}
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
// must have editor if here!
|
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
// Switch the UI mode before inserting contents
|
|
|
|
// so user can't type in source window while new window is being filled
|
|
|
|
var previousMode = gEditorDisplayMode;
|
|
|
|
if (!SetDisplayMode(mode))
|
|
|
|
return;
|
|
|
|
|
2002-09-18 23:42:38 +04:00
|
|
|
if (mode == kDisplayModeSource)
|
2002-07-13 02:28:30 +04:00
|
|
|
{
|
|
|
|
// Display the DOCTYPE as a non-editable string above edit area
|
|
|
|
var domdoc;
|
2002-11-13 01:52:55 +03:00
|
|
|
try { domdoc = editor.document; } catch (e) { dump( e + "\n");}
|
2002-07-13 02:28:30 +04:00
|
|
|
if (domdoc)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2002-07-13 02:28:30 +04:00
|
|
|
var doctypeNode = document.getElementById("doctype-text");
|
|
|
|
var dt = domdoc.doctype;
|
|
|
|
if (doctypeNode)
|
2001-02-27 01:02:07 +03:00
|
|
|
{
|
2002-07-13 02:28:30 +04:00
|
|
|
if (dt)
|
2001-02-27 01:02:07 +03:00
|
|
|
{
|
2002-11-19 18:51:56 +03:00
|
|
|
doctypeNode.collapsed = false;
|
2002-07-13 02:28:30 +04:00
|
|
|
var doctypeText = "<!DOCTYPE " + domdoc.doctype.name;
|
|
|
|
if (dt.publicId)
|
|
|
|
doctypeText += " PUBLIC \"" + domdoc.doctype.publicId;
|
|
|
|
if (dt.systemId)
|
|
|
|
doctypeText += " "+"\"" + dt.systemId;
|
|
|
|
doctypeText += "\">"
|
|
|
|
doctypeNode.setAttribute("value", doctypeText);
|
2001-02-27 01:02:07 +03:00
|
|
|
}
|
2002-07-13 02:28:30 +04:00
|
|
|
else
|
2002-11-19 18:51:56 +03:00
|
|
|
doctypeNode.collapsed = true;
|
2001-02-27 01:02:07 +03:00
|
|
|
}
|
2002-07-13 02:28:30 +04:00
|
|
|
}
|
|
|
|
// Get the entire document's source string
|
2000-08-31 02:49:08 +04:00
|
|
|
|
2002-12-14 01:12:10 +03:00
|
|
|
var flags = (editor.documentCharacterSet == "ISO-8859-1")
|
2006-03-28 20:44:55 +04:00
|
|
|
? kOutputEncodeLatin1Entities
|
|
|
|
: kOutputEncodeBasicEntities;
|
2002-12-17 03:41:25 +03:00
|
|
|
try {
|
|
|
|
var encodeEntity = gPrefs.getCharPref("editor.encode_entity");
|
|
|
|
switch (encodeEntity) {
|
2006-03-28 20:44:55 +04:00
|
|
|
case "basic" : flags = kOutputEncodeBasicEntities; break;
|
|
|
|
case "latin1" : flags = kOutputEncodeLatin1Entities; break;
|
|
|
|
case "html" : flags = kOutputEncodeHTMLEntities; break;
|
2002-12-17 03:41:25 +03:00
|
|
|
case "none" : flags = 0; break;
|
|
|
|
}
|
|
|
|
} catch (e) { }
|
2001-08-10 07:47:37 +04:00
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
try {
|
|
|
|
var prettyPrint = gPrefs.getBoolPref("editor.prettyprint");
|
|
|
|
if (prettyPrint)
|
2006-03-28 20:44:55 +04:00
|
|
|
flags |= kOutputFormatted;
|
2001-08-10 07:47:37 +04:00
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
} catch (e) {}
|
2000-08-31 02:49:08 +04:00
|
|
|
|
2006-03-28 20:44:55 +04:00
|
|
|
flags |= kOutputLFLineBreak;
|
2002-11-13 01:52:55 +03:00
|
|
|
var source = editor.outputToString(kHTMLMimeType, flags);
|
2002-07-13 02:28:30 +04:00
|
|
|
var start = source.search(/<html/i);
|
|
|
|
if (start == -1) start = 0;
|
2003-06-13 16:55:17 +04:00
|
|
|
gSourceTextEditor.insertText(source.slice(start));
|
|
|
|
gSourceTextEditor.resetModificationCount();
|
|
|
|
gSourceTextEditor.addDocumentStateListener(gSourceTextListener);
|
|
|
|
gSourceTextEditor.enableUndo(true);
|
|
|
|
gSourceContentWindow.commandManager.addCommandObserver(gSourceTextObserver, "cmd_undo");
|
|
|
|
gSourceContentWindow.contentWindow.focus();
|
|
|
|
goDoCommand("cmd_moveTop");
|
2002-07-13 02:28:30 +04:00
|
|
|
}
|
2002-09-18 23:42:38 +04:00
|
|
|
else if (previousMode == kDisplayModeSource)
|
2002-07-13 02:28:30 +04:00
|
|
|
{
|
|
|
|
// Only rebuild document if a change was made in source window
|
2003-06-13 16:55:17 +04:00
|
|
|
if (IsHTMLSourceChanged())
|
2000-05-12 06:37:40 +04:00
|
|
|
{
|
2002-07-24 07:35:40 +04:00
|
|
|
// Reduce the undo count so we don't use too much memory
|
|
|
|
// during multiple uses of source window
|
|
|
|
// (reinserting entire doc caches all nodes)
|
|
|
|
try {
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.transactionManager.maxTransactionCount = 1;
|
2002-07-24 07:35:40 +04:00
|
|
|
} catch (e) {}
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.beginTransaction();
|
2002-07-13 02:28:30 +04:00
|
|
|
try {
|
2003-08-06 13:57:02 +04:00
|
|
|
// We are coming from edit source mode,
|
2002-07-13 02:28:30 +04:00
|
|
|
// so transfer that back into the document
|
2006-03-28 20:44:55 +04:00
|
|
|
source = gSourceTextEditor.outputToString(kTextMimeType, kOutputLFLineBreak);
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.rebuildDocumentFromSource(source);
|
2002-07-13 02:28:30 +04:00
|
|
|
|
|
|
|
// Get the text for the <title> from the newly-parsed document
|
|
|
|
// (must do this for proper conversion of "escaped" characters)
|
|
|
|
var title = "";
|
2002-11-13 01:52:55 +03:00
|
|
|
var titlenodelist = editor.document.getElementsByTagName("title");
|
2002-07-13 02:28:30 +04:00
|
|
|
if (titlenodelist)
|
|
|
|
{
|
|
|
|
var titleNode = titlenodelist.item(0);
|
|
|
|
if (titleNode && titleNode.firstChild && titleNode.firstChild.data)
|
|
|
|
title = titleNode.firstChild.data;
|
|
|
|
}
|
2002-11-13 01:52:55 +03:00
|
|
|
if (editor.document.title != title)
|
2002-10-03 08:07:10 +04:00
|
|
|
SetDocumentTitle(title);
|
2001-05-17 03:44:56 +04:00
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
} catch (ex) {
|
|
|
|
dump(ex);
|
|
|
|
}
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.endTransaction();
|
2000-08-10 07:43:09 +04:00
|
|
|
|
2002-07-24 07:35:40 +04:00
|
|
|
// Restore unlimited undo count
|
|
|
|
try {
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.transactionManager.maxTransactionCount = -1;
|
2002-07-24 07:35:40 +04:00
|
|
|
} catch (e) {}
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
2002-07-13 02:28:30 +04:00
|
|
|
|
|
|
|
// Clear out the string buffers
|
2003-06-13 16:55:17 +04:00
|
|
|
gSourceContentWindow.commandManager.removeCommandObserver(gSourceTextObserver, "cmd_undo");
|
|
|
|
gSourceTextEditor.removeDocumentStateListener(gSourceTextListener);
|
|
|
|
gSourceTextEditor.enableUndo(false);
|
|
|
|
gSourceTextEditor.selectAll();
|
|
|
|
gSourceTextEditor.deleteSelection(gSourceTextEditor.eNone);
|
|
|
|
gSourceTextEditor.resetModificationCount();
|
2002-07-13 02:28:30 +04:00
|
|
|
|
|
|
|
gContentWindow.focus();
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-12 03:41:22 +04:00
|
|
|
function CancelHTMLSource()
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2000-07-12 03:41:22 +04:00
|
|
|
// Don't convert source text back into the DOM document
|
2003-06-13 16:55:17 +04:00
|
|
|
gSourceTextEditor.resetModificationCount();
|
2002-09-13 23:47:38 +04:00
|
|
|
SetDisplayMode(gPreviousNonSourceDisplayMode);
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2000-07-12 03:41:22 +04:00
|
|
|
function FinishHTMLSource()
|
|
|
|
{
|
2002-07-23 09:30:16 +04:00
|
|
|
//Here we need to check whether the HTML source contains <head> and <body> tags
|
|
|
|
//Or RebuildDocumentFromSource() will fail.
|
|
|
|
if (IsInHTMLSourceMode())
|
|
|
|
{
|
2006-03-28 20:44:55 +04:00
|
|
|
var htmlSource = gSourceTextEditor.outputToString(kTextMimeType, kOutputLFLineBreak);
|
2002-07-23 09:30:16 +04:00
|
|
|
if (htmlSource.length > 0)
|
|
|
|
{
|
|
|
|
var beginHead = htmlSource.indexOf("<head");
|
|
|
|
if (beginHead == -1)
|
|
|
|
{
|
|
|
|
AlertWithTitle(GetString("Alert"), GetString("NoHeadTag"));
|
|
|
|
//cheat to force back to Source Mode
|
2002-09-18 23:42:38 +04:00
|
|
|
gEditorDisplayMode = kDisplayModePreview;
|
|
|
|
SetDisplayMode(kDisplayModeSource);
|
2002-07-23 09:30:16 +04:00
|
|
|
throw Components.results.NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
var beginBody = htmlSource.indexOf("<body");
|
|
|
|
if (beginBody == -1)
|
|
|
|
{
|
|
|
|
AlertWithTitle(GetString("Alert"), GetString("NoBodyTag"));
|
|
|
|
//cheat to force back to Source Mode
|
2002-09-18 23:42:38 +04:00
|
|
|
gEditorDisplayMode = kDisplayModePreview;
|
|
|
|
SetDisplayMode(kDisplayModeSource);
|
2002-07-23 09:30:16 +04:00
|
|
|
throw Components.results.NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-12 03:41:22 +04:00
|
|
|
// Switch edit modes -- converts source back into DOM document
|
2002-09-13 23:47:38 +04:00
|
|
|
SetEditMode(gPreviousNonSourceDisplayMode);
|
2000-07-12 03:41:22 +04:00
|
|
|
}
|
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
function SetDisplayMode(mode)
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
if (!IsHTMLEditor())
|
2002-08-21 03:59:19 +04:00
|
|
|
return false;
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
// Already in requested mode:
|
|
|
|
// return false to indicate we didn't switch
|
|
|
|
if (mode == gEditorDisplayMode)
|
|
|
|
return false;
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-10-03 08:07:10 +04:00
|
|
|
var previousMode = gEditorDisplayMode;
|
2002-07-13 02:28:30 +04:00
|
|
|
gEditorDisplayMode = mode;
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2002-10-16 12:07:35 +04:00
|
|
|
ResetStructToolbar();
|
2002-09-18 23:42:38 +04:00
|
|
|
if (mode == kDisplayModeSource)
|
2002-07-13 02:28:30 +04:00
|
|
|
{
|
|
|
|
// Switch to the sourceWindow (second in the deck)
|
2002-10-03 08:07:10 +04:00
|
|
|
gContentWindowDeck.selectedIndex = 1;
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
//Hide the formatting toolbar if not already hidden
|
2002-10-03 08:07:10 +04:00
|
|
|
gFormatToolbarHidden = gFormatToolbar.hidden;
|
|
|
|
gFormatToolbar.hidden = true;
|
|
|
|
gViewFormatToolbar.hidden = true;
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2003-06-13 16:55:17 +04:00
|
|
|
gSourceContentWindow.contentWindow.focus();
|
2002-07-13 02:28:30 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-10-03 08:07:10 +04:00
|
|
|
// Save the last non-source mode so we can cancel source editing easily
|
|
|
|
gPreviousNonSourceDisplayMode = mode;
|
|
|
|
|
|
|
|
// Load/unload appropriate override style sheet
|
|
|
|
try {
|
|
|
|
var editor = GetCurrentEditor();
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.QueryInterface(nsIEditorStyleSheets);
|
2003-02-24 12:37:18 +03:00
|
|
|
editor instanceof Components.interfaces.nsIHTMLObjectResizer;
|
2002-10-03 08:07:10 +04:00
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case kDisplayModePreview:
|
|
|
|
// Disable all extra "edit mode" style sheets
|
|
|
|
editor.enableStyleSheet(kNormalStyleSheet, false);
|
|
|
|
editor.enableStyleSheet(kAllTagsStyleSheet, false);
|
2003-02-24 12:37:18 +03:00
|
|
|
editor.isImageResizingEnabled = true;
|
2002-10-03 08:07:10 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kDisplayModeNormal:
|
|
|
|
editor.addOverrideStyleSheet(kNormalStyleSheet);
|
|
|
|
// Disable ShowAllTags mode
|
|
|
|
editor.enableStyleSheet(kAllTagsStyleSheet, false);
|
2003-02-24 12:37:18 +03:00
|
|
|
editor.isImageResizingEnabled = true;
|
2002-10-03 08:07:10 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kDisplayModeAllTags:
|
|
|
|
editor.addOverrideStyleSheet(kNormalStyleSheet);
|
|
|
|
editor.addOverrideStyleSheet(kAllTagsStyleSheet);
|
2003-02-24 12:37:18 +03:00
|
|
|
// don't allow resizing in AllTags mode because the visible tags
|
|
|
|
// change the computed size of images and tables...
|
|
|
|
if (editor.resizedObject) {
|
|
|
|
editor.hideResizers();
|
|
|
|
}
|
|
|
|
editor.isImageResizingEnabled = false;
|
2002-10-03 08:07:10 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch(e) {}
|
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
// Switch to the normal editor (first in the deck)
|
2002-10-03 08:07:10 +04:00
|
|
|
gContentWindowDeck.selectedIndex = 0;
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
// Restore menus and toolbars
|
2002-10-03 08:07:10 +04:00
|
|
|
gFormatToolbar.hidden = gFormatToolbarHidden;
|
|
|
|
gViewFormatToolbar.hidden = false;
|
2000-08-30 06:44:18 +04:00
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
gContentWindow.focus();
|
|
|
|
}
|
2001-05-18 23:59:17 +04:00
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
// update commands to disable or re-enable stuff
|
|
|
|
window.updateCommands("mode_switch");
|
2000-08-30 06:44:18 +04:00
|
|
|
|
2002-10-03 08:07:10 +04:00
|
|
|
// Set the selected tab at bottom of window:
|
|
|
|
// (Note: Setting "selectedIndex = mode" won't redraw tabs when menu is used.)
|
|
|
|
document.getElementById("EditModeTabs").selectedItem = document.getElementById(kDisplayModeTabIDS[mode]);
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2002-10-03 08:07:10 +04:00
|
|
|
// Uncheck previous menuitem and set new check since toolbar may have been used
|
|
|
|
if (previousMode >= 0)
|
|
|
|
document.getElementById(kDisplayModeMenuIDs[previousMode]).setAttribute("checked","false");
|
|
|
|
document.getElementById(kDisplayModeMenuIDs[mode]).setAttribute("checked","true");
|
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
|
|
|
|
return true;
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function EditorToggleParagraphMarks()
|
|
|
|
{
|
|
|
|
var menuItem = document.getElementById("viewParagraphMarks");
|
|
|
|
if (menuItem)
|
|
|
|
{
|
2000-06-09 05:04:34 +04:00
|
|
|
// Note that the 'type="checbox"' mechanism automatically
|
|
|
|
// toggles the "checked" state before the oncommand is called,
|
|
|
|
// so if "checked" is true now, it was just switched to that mode
|
2000-05-10 09:30:13 +04:00
|
|
|
var checked = menuItem.getAttribute("checked");
|
|
|
|
try {
|
2002-11-13 01:52:55 +03:00
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
editor.QueryInterface(nsIEditorStyleSheets);
|
|
|
|
|
2002-09-13 23:47:38 +04:00
|
|
|
if (checked == "true")
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.addOverrideStyleSheet(kParagraphMarksStyleSheet);
|
2002-09-13 23:47:38 +04:00
|
|
|
else
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.enableStyleSheet(kParagraphMarksStyleSheet, false);
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
2000-08-24 04:28:20 +04:00
|
|
|
catch(e) { return; }
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-09 09:23:37 +04:00
|
|
|
function InitPasteAsMenu()
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2001-05-09 09:23:37 +04:00
|
|
|
var menuItem = document.getElementById("menu_pasteTable")
|
|
|
|
if(menuItem)
|
|
|
|
{
|
|
|
|
menuItem.IsInTable
|
|
|
|
menuItem.setAttribute("label", GetString(IsInTable() ? "NestedTable" : "Table"));
|
|
|
|
// menuItem.setAttribute("accesskey",GetString("ObjectPropertiesAccessKey"));
|
|
|
|
}
|
|
|
|
// TODO: Do enabling based on what is in the clipboard
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2002-10-03 08:07:10 +04:00
|
|
|
function UpdateWindowTitle()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
var windowTitle = GetDocumentTitle();
|
|
|
|
if (!windowTitle)
|
|
|
|
windowTitle = GetString("untitled");
|
|
|
|
|
|
|
|
// Append just the 'leaf' filename to the Doc. Title for the window caption
|
|
|
|
var docUrl = GetDocumentUrl();
|
2002-11-13 01:52:55 +03:00
|
|
|
if (docUrl && !IsUrlAboutBlank(docUrl))
|
2002-10-03 08:07:10 +04:00
|
|
|
{
|
|
|
|
var scheme = GetScheme(docUrl);
|
|
|
|
var filename = GetFilename(docUrl);
|
|
|
|
if (filename)
|
|
|
|
windowTitle += " [" + scheme + ":/.../" + filename + "]";
|
2002-11-13 01:52:55 +03:00
|
|
|
|
|
|
|
// Save changed title in the recent pages data in prefs
|
|
|
|
SaveRecentFilesPrefs();
|
2002-10-03 08:07:10 +04:00
|
|
|
}
|
|
|
|
// Set window title with " - Composer" appended
|
2003-12-21 07:04:33 +03:00
|
|
|
var xulWin = document.documentElement;
|
2004-10-25 04:39:27 +04:00
|
|
|
document.title = windowTitle + xulWin.getAttribute("titlemenuseparator") +
|
|
|
|
xulWin.getAttribute("titlemodifier");
|
2002-11-13 01:52:55 +03:00
|
|
|
} catch (e) { dump(e); }
|
2002-10-03 08:07:10 +04:00
|
|
|
}
|
|
|
|
|
2002-12-06 00:24:09 +03:00
|
|
|
function BuildRecentPagesMenu()
|
2000-06-28 18:58:36 +04:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
if (!editor || !gPrefs)
|
|
|
|
return;
|
2000-06-28 18:58:36 +04:00
|
|
|
|
2000-09-14 18:45:16 +04:00
|
|
|
var popup = document.getElementById("menupopup_RecentFiles");
|
2002-11-13 01:52:55 +03:00
|
|
|
if (!popup || !editor.document)
|
2000-06-28 18:58:36 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Delete existing menu
|
|
|
|
while (popup.firstChild)
|
|
|
|
popup.removeChild(popup.firstChild);
|
|
|
|
|
2000-09-14 18:45:16 +04:00
|
|
|
// Current page is the "0" item in the list we save in prefs,
|
|
|
|
// but we don't include it in the menu.
|
Composer Publishing fixes: Add support to not upload images (b=134001,r=akkana, sr=kin), Don't save site data if not successfully published (b=132604, r=akkana, sr=kin), improve error handling (b=126258, r=andreww, sr=dveditz), Make 'CheckAndSaveDocument' do publishing for remote url (b=126450, r=brade, sr=kin), Save command should publish if remote file (b=132634, r=brade,sr=kin), Fix FTP publishing (b=133823, r=brade, sr=kin) all are: a=asa, adt1.0.0+
2002-04-04 19:14:32 +04:00
|
|
|
var curUrl = StripPassword(GetDocumentUrl());
|
2001-03-22 03:59:29 +03:00
|
|
|
var historyCount = 10;
|
2002-12-06 00:24:09 +03:00
|
|
|
try {
|
|
|
|
historyCount = gPrefs.getIntPref("editor.history.url_maximum");
|
|
|
|
} catch(e) {}
|
2000-09-14 18:45:16 +04:00
|
|
|
var menuIndex = 1;
|
2000-06-28 18:58:36 +04:00
|
|
|
|
2002-12-06 00:24:09 +03:00
|
|
|
for (var i = 0; i < historyCount; i++)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2002-01-05 23:25:53 +03:00
|
|
|
var url = GetUnicharPref("editor.history_url_"+i);
|
2000-06-28 18:58:36 +04:00
|
|
|
|
2002-12-06 00:24:09 +03:00
|
|
|
// Skip over current url
|
|
|
|
if (url && url != curUrl)
|
2000-09-14 18:45:16 +04:00
|
|
|
{
|
|
|
|
// Build the menu
|
2002-12-06 00:24:09 +03:00
|
|
|
var title = GetUnicharPref("editor.history_title_"+i);
|
2000-09-14 18:45:16 +04:00
|
|
|
AppendRecentMenuitem(popup, title, url, menuIndex);
|
|
|
|
menuIndex++;
|
2002-10-03 08:07:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function SaveRecentFilesPrefs()
|
|
|
|
{
|
|
|
|
// Can't do anything if no prefs
|
|
|
|
if (!gPrefs) return;
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var curUrl = StripPassword(GetDocumentUrl());
|
2002-10-03 08:07:10 +04:00
|
|
|
var historyCount = 10;
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
historyCount = gPrefs.getIntPref("editor.history.url_maximum");
|
|
|
|
} catch(e) {}
|
2002-10-03 08:07:10 +04:00
|
|
|
|
2002-12-06 00:24:09 +03:00
|
|
|
var titleArray = [];
|
|
|
|
var urlArray = [];
|
|
|
|
|
|
|
|
if (historyCount && !IsUrlAboutBlank(curUrl) && GetScheme(curUrl) != "data")
|
|
|
|
{
|
|
|
|
titleArray.push(GetDocumentTitle());
|
|
|
|
urlArray.push(curUrl);
|
|
|
|
}
|
2002-10-03 08:07:10 +04:00
|
|
|
|
2002-12-06 00:24:09 +03:00
|
|
|
for (var i = 0; i < historyCount && urlArray.length < historyCount; i++)
|
2002-10-03 08:07:10 +04:00
|
|
|
{
|
|
|
|
var url = GetUnicharPref("editor.history_url_"+i);
|
|
|
|
|
|
|
|
// Continue if URL pref is missing because
|
|
|
|
// a URL not found during loading may have been removed
|
|
|
|
|
2002-12-06 00:24:09 +03:00
|
|
|
// Skip over current an "data" URLs
|
|
|
|
if (url && url != curUrl && GetScheme(url) != "data")
|
2002-10-03 08:07:10 +04:00
|
|
|
{
|
2002-12-06 00:24:09 +03:00
|
|
|
var title = GetUnicharPref("editor.history_title_"+i);
|
|
|
|
titleArray.push(title);
|
|
|
|
urlArray.push(url);
|
2000-09-14 18:45:16 +04:00
|
|
|
}
|
|
|
|
}
|
2000-07-01 06:16:04 +04:00
|
|
|
|
2002-10-03 08:07:10 +04:00
|
|
|
// Resave the list back to prefs in the new order
|
2002-12-06 00:24:09 +03:00
|
|
|
for (i = 0; i < urlArray.length; i++)
|
2000-09-14 18:45:16 +04:00
|
|
|
{
|
2002-10-03 08:07:10 +04:00
|
|
|
SetUnicharPref("editor.history_title_"+i, titleArray[i]);
|
|
|
|
SetUnicharPref("editor.history_url_"+i, urlArray[i]);
|
2000-06-28 18:58:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-14 18:45:16 +04:00
|
|
|
function AppendRecentMenuitem(menupopup, title, url, menuIndex)
|
2000-06-28 18:58:36 +04:00
|
|
|
{
|
|
|
|
if (menupopup)
|
|
|
|
{
|
2002-02-20 05:17:46 +03:00
|
|
|
var menuItem = document.createElementNS(XUL_NS, "menuitem");
|
2000-06-28 18:58:36 +04:00
|
|
|
if (menuItem)
|
|
|
|
{
|
2000-09-14 18:45:16 +04:00
|
|
|
var accessKey;
|
|
|
|
if (menuIndex <= 9)
|
|
|
|
accessKey = String(menuIndex);
|
|
|
|
else if (menuIndex == 10)
|
|
|
|
accessKey = "0";
|
|
|
|
else
|
|
|
|
accessKey = " ";
|
|
|
|
|
|
|
|
var itemString = accessKey+" ";
|
2001-02-27 01:02:07 +03:00
|
|
|
|
|
|
|
// Show "title [url]" or just the URL
|
2000-09-14 18:45:16 +04:00
|
|
|
if (title)
|
2001-02-27 01:02:07 +03:00
|
|
|
{
|
|
|
|
itemString += title;
|
|
|
|
itemString += " [";
|
|
|
|
}
|
|
|
|
itemString += url;
|
|
|
|
if (title)
|
|
|
|
itemString += "]";
|
2000-06-28 18:58:36 +04:00
|
|
|
|
2001-03-22 03:59:29 +03:00
|
|
|
menuItem.setAttribute("label", itemString);
|
2003-09-14 01:15:55 +04:00
|
|
|
menuItem.setAttribute("crop", "center");
|
2001-03-22 03:59:29 +03:00
|
|
|
menuItem.setAttribute("value", url);
|
2000-09-14 18:45:16 +04:00
|
|
|
if (accessKey != " ")
|
2001-03-22 03:59:29 +03:00
|
|
|
menuItem.setAttribute("accesskey", accessKey);
|
2000-06-28 18:58:36 +04:00
|
|
|
menupopup.appendChild(menuItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-05-10 09:30:13 +04:00
|
|
|
|
Composer Publishing fixes: Add support to not upload images (b=134001,r=akkana, sr=kin), Don't save site data if not successfully published (b=132604, r=akkana, sr=kin), improve error handling (b=126258, r=andreww, sr=dveditz), Make 'CheckAndSaveDocument' do publishing for remote url (b=126450, r=brade, sr=kin), Save command should publish if remote file (b=132634, r=brade,sr=kin), Fix FTP publishing (b=133823, r=brade, sr=kin) all are: a=asa, adt1.0.0+
2002-04-04 19:14:32 +04:00
|
|
|
function EditorInitFileMenu()
|
|
|
|
{
|
|
|
|
// Disable "Save" menuitem when editing remote url. User should use "Save As"
|
2002-12-06 00:24:09 +03:00
|
|
|
var docUrl = GetDocumentUrl();
|
|
|
|
var scheme = GetScheme(docUrl);
|
Composer Publishing fixes: Add support to not upload images (b=134001,r=akkana, sr=kin), Don't save site data if not successfully published (b=132604, r=akkana, sr=kin), improve error handling (b=126258, r=andreww, sr=dveditz), Make 'CheckAndSaveDocument' do publishing for remote url (b=126450, r=brade, sr=kin), Save command should publish if remote file (b=132634, r=brade,sr=kin), Fix FTP publishing (b=133823, r=brade, sr=kin) all are: a=asa, adt1.0.0+
2002-04-04 19:14:32 +04:00
|
|
|
if (scheme && scheme != "file")
|
|
|
|
SetElementEnabledById("saveMenuitem", false);
|
2002-12-06 00:24:09 +03:00
|
|
|
|
|
|
|
// Enable recent pages submenu if there are any history entries in prefs
|
|
|
|
var historyUrl = "";
|
|
|
|
|
|
|
|
var historyCount = 10;
|
|
|
|
try { historyCount = gPrefs.getIntPref("editor.history.url_maximum"); } catch(e) {}
|
|
|
|
if (historyCount)
|
|
|
|
{
|
|
|
|
historyUrl = GetUnicharPref("editor.history_url_0");
|
|
|
|
|
|
|
|
// See if there's more if current file is only entry in history list
|
|
|
|
if (historyUrl && historyUrl == docUrl)
|
|
|
|
historyUrl = GetUnicharPref("editor.history_url_1");
|
|
|
|
}
|
|
|
|
SetElementEnabledById("menu_RecentFiles", historyUrl != "");
|
Composer Publishing fixes: Add support to not upload images (b=134001,r=akkana, sr=kin), Don't save site data if not successfully published (b=132604, r=akkana, sr=kin), improve error handling (b=126258, r=andreww, sr=dveditz), Make 'CheckAndSaveDocument' do publishing for remote url (b=126450, r=brade, sr=kin), Save command should publish if remote file (b=132634, r=brade,sr=kin), Fix FTP publishing (b=133823, r=brade, sr=kin) all are: a=asa, adt1.0.0+
2002-04-04 19:14:32 +04:00
|
|
|
}
|
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
function EditorInitFormatMenu()
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
{
|
2001-05-18 10:42:37 +04:00
|
|
|
try {
|
|
|
|
InitObjectPropertiesMenuitem("objectProperties");
|
2002-04-11 17:33:30 +04:00
|
|
|
InitRemoveStylesMenuitems("removeStylesMenuitem", "removeLinksMenuitem", "removeNamedAnchorsMenuitem");
|
2001-05-18 10:42:37 +04:00
|
|
|
} catch(ex) {}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function InitObjectPropertiesMenuitem(id)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2000-05-25 07:35:33 +04:00
|
|
|
// Set strings and enable for the [Object] Properties item
|
|
|
|
// Note that we directly do the enabling instead of
|
|
|
|
// using goSetCommandEnabled since we already have the menuitem
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
var menuItem = document.getElementById(id);
|
2000-09-06 03:21:22 +04:00
|
|
|
if (!menuItem) return null;
|
|
|
|
|
2001-05-18 10:42:37 +04:00
|
|
|
var element;
|
2001-09-29 08:40:38 +04:00
|
|
|
var menuStr = GetString("AdvancedProperties");
|
2000-09-06 03:21:22 +04:00
|
|
|
var name;
|
|
|
|
|
2001-05-18 10:42:37 +04:00
|
|
|
if (IsEditingRenderedHTML())
|
|
|
|
element = GetObjectForProperties();
|
|
|
|
|
2000-09-06 03:21:22 +04:00
|
|
|
if (element && element.nodeName)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2000-09-06 03:21:22 +04:00
|
|
|
var objStr = "";
|
|
|
|
menuItem.setAttribute("disabled", "");
|
|
|
|
name = element.nodeName.toLowerCase();
|
|
|
|
switch (name)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2000-09-06 03:21:22 +04:00
|
|
|
case "img":
|
2002-03-14 10:34:44 +03:00
|
|
|
// Check if img is enclosed in link
|
|
|
|
// (use "href" to not be fooled by named anchor)
|
2002-07-13 02:28:30 +04:00
|
|
|
try
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
if (GetCurrentEditor().getElementOrParentByTagName("href", element))
|
2002-07-13 02:28:30 +04:00
|
|
|
objStr = GetString("ImageAndLink");
|
|
|
|
} catch(e) {}
|
|
|
|
|
|
|
|
if (objStr == "")
|
2002-03-14 10:31:33 +03:00
|
|
|
objStr = GetString("Image");
|
2000-09-06 03:21:22 +04:00
|
|
|
break;
|
|
|
|
case "hr":
|
|
|
|
objStr = GetString("HLine");
|
|
|
|
break;
|
|
|
|
case "table":
|
|
|
|
objStr = GetString("Table");
|
|
|
|
break;
|
|
|
|
case "th":
|
|
|
|
name = "td";
|
|
|
|
case "td":
|
|
|
|
objStr = GetString("TableCell");
|
|
|
|
break;
|
|
|
|
case "ol":
|
|
|
|
case "ul":
|
|
|
|
case "dl":
|
|
|
|
objStr = GetString("List");
|
|
|
|
break;
|
2001-08-18 04:10:37 +04:00
|
|
|
case "li":
|
|
|
|
objStr = GetString("ListItem");
|
|
|
|
break;
|
2002-01-15 18:49:46 +03:00
|
|
|
case "form":
|
|
|
|
objStr = GetString("Form");
|
|
|
|
break;
|
|
|
|
case "input":
|
|
|
|
var type = element.getAttribute("type");
|
|
|
|
if (type && type.toLowerCase() == "image")
|
|
|
|
objStr = GetString("InputImage");
|
|
|
|
else
|
|
|
|
objStr = GetString("InputTag");
|
|
|
|
break;
|
|
|
|
case "textarea":
|
|
|
|
objStr = GetString("TextArea");
|
|
|
|
break;
|
|
|
|
case "select":
|
|
|
|
objStr = GetString("Select");
|
|
|
|
break;
|
|
|
|
case "button":
|
|
|
|
objStr = GetString("Button");
|
|
|
|
break;
|
|
|
|
case "label":
|
|
|
|
objStr = GetString("Label");
|
|
|
|
break;
|
|
|
|
case "fieldset":
|
|
|
|
objStr = GetString("FieldSet");
|
|
|
|
break;
|
2000-09-06 03:21:22 +04:00
|
|
|
case "a":
|
|
|
|
if (element.name)
|
|
|
|
{
|
|
|
|
objStr = GetString("NamedAnchor");
|
|
|
|
name = "anchor";
|
|
|
|
}
|
|
|
|
else if(element.href)
|
|
|
|
{
|
|
|
|
objStr = GetString("Link");
|
|
|
|
name = "href";
|
|
|
|
}
|
|
|
|
break;
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
2001-09-29 08:40:38 +04:00
|
|
|
if (objStr)
|
|
|
|
menuStr = GetString("ObjectProperties").replace(/%obj%/,objStr);
|
2000-09-06 03:21:22 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We show generic "Properties" string, but disable menu item
|
|
|
|
menuItem.setAttribute("disabled","true");
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
2001-03-22 03:59:29 +03:00
|
|
|
menuItem.setAttribute("label", menuStr);
|
2000-09-06 03:21:22 +04:00
|
|
|
menuItem.setAttribute("accesskey",GetString("ObjectPropertiesAccessKey"));
|
|
|
|
return name;
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2000-06-16 18:22:12 +04:00
|
|
|
function InitParagraphMenu()
|
2000-06-06 00:26:26 +04:00
|
|
|
{
|
2002-08-17 01:37:24 +04:00
|
|
|
var mixedObj = { value: null };
|
2002-07-13 02:28:30 +04:00
|
|
|
var state;
|
|
|
|
try {
|
2002-11-13 01:52:55 +03:00
|
|
|
state = GetCurrentEditor().getParagraphState(mixedObj);
|
2002-07-13 02:28:30 +04:00
|
|
|
}
|
|
|
|
catch(e) {}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
var IDSuffix;
|
2000-06-16 18:22:12 +04:00
|
|
|
|
|
|
|
// PROBLEM: When we get blockquote, it masks other styles contained by it
|
2001-03-22 03:59:29 +03:00
|
|
|
// We need a separate method to get blockquote state
|
2000-06-16 18:22:12 +04:00
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
// We use "x" as uninitialized paragraph state
|
2000-08-31 16:44:56 +04:00
|
|
|
if (!state || state == "x")
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
IDSuffix = "bodyText" // No paragraph container
|
|
|
|
else
|
2000-06-16 18:22:12 +04:00
|
|
|
IDSuffix = state;
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2000-09-06 03:21:22 +04:00
|
|
|
// Set "radio" check on one item, but...
|
|
|
|
var menuItem = document.getElementById("menu_"+IDSuffix);
|
|
|
|
menuItem.setAttribute("checked", "true");
|
|
|
|
|
|
|
|
// ..."bodyText" is returned if mixed selection, so remove checkmark
|
|
|
|
if (mixedObj.value)
|
|
|
|
menuItem.setAttribute("checked", "false");
|
2000-06-16 18:22:12 +04:00
|
|
|
}
|
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
function GetListStateString()
|
2000-06-16 18:22:12 +04:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
var editor = GetCurrentEditor();
|
2000-06-16 18:22:12 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var mixedObj = { value: null };
|
|
|
|
var hasOL = { value: false };
|
|
|
|
var hasUL = { value: false };
|
|
|
|
var hasDL = { value: false };
|
|
|
|
editor.getListState(mixedObj, hasOL, hasUL, hasDL);
|
2002-07-13 02:28:30 +04:00
|
|
|
|
|
|
|
if (mixedObj.value)
|
|
|
|
return "mixed";
|
2002-11-13 01:52:55 +03:00
|
|
|
if (hasOL.value)
|
|
|
|
return "ol";
|
|
|
|
if (hasUL.value)
|
|
|
|
return "ul";
|
|
|
|
|
|
|
|
if (hasDL.value)
|
|
|
|
{
|
|
|
|
var hasLI = { value: false };
|
|
|
|
var hasDT = { value: false };
|
|
|
|
var hasDD = { value: false };
|
|
|
|
editor.getListItemState(mixedObj, hasLI, hasDT, hasDD);
|
|
|
|
if (mixedObj.value)
|
|
|
|
return "mixed";
|
|
|
|
if (hasLI.value)
|
|
|
|
return "li";
|
|
|
|
if (hasDT.value)
|
|
|
|
return "dt";
|
|
|
|
if (hasDD.value)
|
|
|
|
return "dd";
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
2002-07-13 02:28:30 +04:00
|
|
|
|
|
|
|
// return "noList" if we aren't in a list at all
|
|
|
|
return "noList";
|
|
|
|
}
|
|
|
|
|
|
|
|
function InitListMenu()
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
if (!IsHTMLEditor())
|
2002-08-21 03:59:19 +04:00
|
|
|
return;
|
2002-07-13 02:28:30 +04:00
|
|
|
|
|
|
|
var IDSuffix = GetListStateString();
|
|
|
|
|
2001-10-03 03:47:47 +04:00
|
|
|
// Set enable state for the "None" menuitem
|
2002-07-13 02:28:30 +04:00
|
|
|
goSetCommandEnabled("cmd_removeList", IDSuffix != "noList");
|
2001-10-03 03:47:47 +04:00
|
|
|
|
2000-09-06 03:21:22 +04:00
|
|
|
// Set "radio" check on one item, but...
|
2002-07-13 02:28:30 +04:00
|
|
|
// we won't find a match if it's "mixed"
|
2000-09-06 03:21:22 +04:00
|
|
|
var menuItem = document.getElementById("menu_"+IDSuffix);
|
2002-07-13 02:28:30 +04:00
|
|
|
if (menuItem)
|
|
|
|
menuItem.setAttribute("checked", "true");
|
|
|
|
}
|
2001-10-03 03:47:47 +04:00
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
function GetAlignmentString()
|
|
|
|
{
|
2002-08-17 01:37:24 +04:00
|
|
|
var mixedObj = { value: null };
|
|
|
|
var alignObj = { value: null };
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
GetCurrentEditor().getAlignment(mixedObj, alignObj);
|
|
|
|
} catch (e) {}
|
2000-06-16 18:22:12 +04:00
|
|
|
|
2000-09-06 03:21:22 +04:00
|
|
|
if (mixedObj.value)
|
2002-07-13 02:28:30 +04:00
|
|
|
return "mixed";
|
|
|
|
if (alignObj.value == nsIHTMLEditor.eLeft)
|
|
|
|
return "left";
|
|
|
|
if (alignObj.value == nsIHTMLEditor.eCenter)
|
|
|
|
return "center";
|
|
|
|
if (alignObj.value == nsIHTMLEditor.eRight)
|
|
|
|
return "right";
|
|
|
|
if (alignObj.value == nsIHTMLEditor.eJustify)
|
|
|
|
return "justify";
|
2001-09-19 04:44:12 +04:00
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
// return "left" if we got here
|
|
|
|
return "left";
|
2000-06-06 00:26:26 +04:00
|
|
|
}
|
|
|
|
|
2000-09-07 09:39:27 +04:00
|
|
|
function InitAlignMenu()
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
if (!IsHTMLEditor())
|
2002-08-21 03:59:19 +04:00
|
|
|
return;
|
2000-09-07 09:39:27 +04:00
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
var IDSuffix = GetAlignmentString();
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
// we won't find a match if it's "mixed"
|
2000-09-07 09:39:27 +04:00
|
|
|
var menuItem = document.getElementById("menu_"+IDSuffix);
|
2002-07-13 02:28:30 +04:00
|
|
|
if (menuItem)
|
|
|
|
menuItem.setAttribute("checked", "true");
|
2000-09-07 09:39:27 +04:00
|
|
|
}
|
|
|
|
|
2001-03-29 01:16:44 +04:00
|
|
|
function EditorSetDefaultPrefsAndDoctype()
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
var domdoc;
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
domdoc = editor.document;
|
|
|
|
} catch (e) { dump( e + "\n"); }
|
2000-05-10 09:30:13 +04:00
|
|
|
if ( !domdoc )
|
|
|
|
{
|
2001-03-29 01:16:44 +04:00
|
|
|
dump("EditorSetDefaultPrefsAndDoctype: EDITOR DOCUMENT NOT FOUND\n");
|
2000-05-10 09:30:13 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-05 18:19:04 +04:00
|
|
|
// Insert a doctype element
|
2001-03-29 01:16:44 +04:00
|
|
|
// if it is missing from existing doc
|
2001-10-15 18:51:26 +04:00
|
|
|
if (!domdoc.doctype)
|
2000-05-12 06:37:40 +04:00
|
|
|
{
|
2003-03-20 18:37:42 +03:00
|
|
|
var newdoctype = domdoc.implementation.createDocumentType("HTML", "-//W3C//DTD HTML 4.01 Transitional//EN","");
|
2001-10-15 18:51:26 +04:00
|
|
|
if (newdoctype)
|
|
|
|
domdoc.insertBefore(newdoctype, domdoc.firstChild);
|
2000-05-12 06:37:40 +04:00
|
|
|
}
|
2001-03-29 01:16:44 +04:00
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
// search for head; we'll need this for meta tag additions
|
|
|
|
var headelement = 0;
|
|
|
|
var headnodelist = domdoc.getElementsByTagName("head");
|
|
|
|
if (headnodelist)
|
|
|
|
{
|
|
|
|
var sz = headnodelist.length;
|
|
|
|
if ( sz >= 1 )
|
|
|
|
headelement = headnodelist.item(0);
|
2001-10-15 18:51:26 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
headelement = domdoc.createElement("head");
|
|
|
|
if (headelement)
|
|
|
|
domdoc.insertAfter(headelement, domdoc.firstChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only set default prefs for new documents */
|
2002-02-15 09:07:40 +03:00
|
|
|
if (!IsUrlAboutBlank(GetDocumentUrl()))
|
2001-10-15 18:51:26 +04:00
|
|
|
return;
|
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
// search for author meta tag.
|
|
|
|
// if one is found, don't do anything.
|
2001-03-22 03:59:29 +03:00
|
|
|
// if not, create one and make it a child of the head tag
|
2000-05-10 09:30:13 +04:00
|
|
|
// and set its content attribute to the value of the editor.author preference.
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
var nodelist = domdoc.getElementsByTagName("meta");
|
|
|
|
if ( nodelist )
|
|
|
|
{
|
2000-08-09 06:25:25 +04:00
|
|
|
// we should do charset first since we need to have charset before
|
|
|
|
// hitting other 8-bit char in other meta tags
|
|
|
|
// grab charset pref and make it the default charset
|
2001-10-15 18:51:26 +04:00
|
|
|
var element;
|
2000-08-09 06:25:25 +04:00
|
|
|
var prefCharsetString = 0;
|
|
|
|
try
|
|
|
|
{
|
2001-10-27 09:39:25 +04:00
|
|
|
prefCharsetString = gPrefs.getComplexValue("intl.charset.default",
|
2001-10-31 03:13:06 +03:00
|
|
|
Components.interfaces.nsIPrefLocalizedString).data;
|
2000-08-09 06:25:25 +04:00
|
|
|
}
|
|
|
|
catch (ex) {}
|
|
|
|
if ( prefCharsetString && prefCharsetString != 0)
|
|
|
|
{
|
2000-09-06 03:21:22 +04:00
|
|
|
element = domdoc.createElement("meta");
|
2000-08-09 06:25:25 +04:00
|
|
|
if ( element )
|
|
|
|
{
|
2002-07-18 01:32:20 +04:00
|
|
|
element.setAttribute("http-equiv", "content-type");
|
|
|
|
element.setAttribute("content", "text/html; charset=" + prefCharsetString);
|
2002-10-15 00:14:40 +04:00
|
|
|
headelement.insertBefore( element, headelement.firstChild );
|
2000-08-09 06:25:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
var node = 0;
|
|
|
|
var listlength = nodelist.length;
|
|
|
|
|
|
|
|
// let's start by assuming we have an author in case we don't have the pref
|
|
|
|
var authorFound = false;
|
|
|
|
for (var i = 0; i < listlength && !authorFound; i++)
|
|
|
|
{
|
|
|
|
node = nodelist.item(i);
|
|
|
|
if ( node )
|
|
|
|
{
|
2001-10-26 22:43:25 +04:00
|
|
|
var value = node.getAttribute("name");
|
|
|
|
if (value && value.toLowerCase() == "author")
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
|
|
|
authorFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var prefAuthorString = 0;
|
|
|
|
try
|
|
|
|
{
|
2001-10-27 09:39:25 +04:00
|
|
|
prefAuthorString = gPrefs.getComplexValue("editor.author",
|
2002-08-06 04:53:19 +04:00
|
|
|
Components.interfaces.nsISupportsString).data;
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
catch (ex) {}
|
|
|
|
if ( prefAuthorString && prefAuthorString != 0)
|
|
|
|
{
|
|
|
|
if ( !authorFound && headelement)
|
|
|
|
{
|
|
|
|
/* create meta tag with 2 attributes */
|
2000-09-06 03:21:22 +04:00
|
|
|
element = domdoc.createElement("meta");
|
2000-05-10 09:30:13 +04:00
|
|
|
if ( element )
|
|
|
|
{
|
2002-07-18 01:32:20 +04:00
|
|
|
element.setAttribute("name", "author");
|
|
|
|
element.setAttribute("content", prefAuthorString);
|
2000-05-10 09:30:13 +04:00
|
|
|
headelement.appendChild( element );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-15 00:14:40 +04:00
|
|
|
// add title tag if not present
|
2002-11-13 01:52:55 +03:00
|
|
|
var titlenodelist = editor.document.getElementsByTagName("title");
|
2002-10-15 00:14:40 +04:00
|
|
|
if (headelement && titlenodelist && titlenodelist.length == 0)
|
|
|
|
{
|
|
|
|
titleElement = domdoc.createElement("title");
|
|
|
|
if (titleElement)
|
|
|
|
headelement.appendChild(titleElement);
|
|
|
|
}
|
|
|
|
|
2000-09-06 03:21:22 +04:00
|
|
|
// Get editor color prefs
|
2000-05-10 09:30:13 +04:00
|
|
|
var use_custom_colors = false;
|
|
|
|
try {
|
2001-10-27 09:39:25 +04:00
|
|
|
use_custom_colors = gPrefs.getBoolPref("editor.use_custom_colors");
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
2000-08-24 04:28:20 +04:00
|
|
|
catch (ex) {}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
|
2000-09-22 09:13:34 +04:00
|
|
|
// find body node
|
|
|
|
var bodyelement = GetBodyElement();
|
|
|
|
if (bodyelement)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2000-09-22 09:13:34 +04:00
|
|
|
if ( use_custom_colors )
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
{
|
2000-09-22 09:13:34 +04:00
|
|
|
// try to get the default color values. ignore them if we don't have them.
|
|
|
|
var text_color;
|
|
|
|
var link_color;
|
|
|
|
var active_link_color;
|
|
|
|
var followed_link_color;
|
|
|
|
var background_color;
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2001-10-27 09:39:25 +04:00
|
|
|
try { text_color = gPrefs.getCharPref("editor.text_color"); } catch (e) {}
|
|
|
|
try { link_color = gPrefs.getCharPref("editor.link_color"); } catch (e) {}
|
|
|
|
try { active_link_color = gPrefs.getCharPref("editor.active_link_color"); } catch (e) {}
|
|
|
|
try { followed_link_color = gPrefs.getCharPref("editor.followed_link_color"); } catch (e) {}
|
|
|
|
try { background_color = gPrefs.getCharPref("editor.background_color"); } catch(e) {}
|
2000-09-22 09:13:34 +04:00
|
|
|
|
|
|
|
// add the color attributes to the body tag.
|
|
|
|
// and use them for the default text and background colors if not empty
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
if (text_color)
|
|
|
|
{
|
|
|
|
editor.setAttributeOrEquivalent(bodyelement, "text", text_color, true);
|
|
|
|
gDefaultTextColor = text_color;
|
|
|
|
}
|
|
|
|
if (background_color)
|
|
|
|
{
|
|
|
|
editor.setAttributeOrEquivalent(bodyelement, "bgcolor", background_color, true);
|
|
|
|
gDefaultBackgroundColor = background_color
|
|
|
|
}
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
if (link_color)
|
|
|
|
bodyelement.setAttribute("link", link_color);
|
|
|
|
if (active_link_color)
|
|
|
|
bodyelement.setAttribute("alink", active_link_color);
|
|
|
|
if (followed_link_color)
|
|
|
|
bodyelement.setAttribute("vlink", followed_link_color);
|
|
|
|
} catch (e) {}
|
2000-09-22 09:13:34 +04:00
|
|
|
}
|
|
|
|
// Default image is independent of Custom colors???
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
var background_image = gPrefs.getCharPref("editor.default_background_image");
|
2003-05-30 17:36:48 +04:00
|
|
|
if (background_image)
|
|
|
|
editor.setAttributeOrEquivalent(bodyelement, "background", background_image, true);
|
2002-11-13 01:52:55 +03:00
|
|
|
} catch (e) {dump("BACKGROUND EXCEPTION: "+e+"\n"); }
|
2000-08-24 04:28:20 +04:00
|
|
|
|
2000-09-22 09:13:34 +04:00
|
|
|
}
|
2000-05-10 09:30:13 +04:00
|
|
|
// auto-save???
|
|
|
|
}
|
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
function GetBodyElement()
|
|
|
|
{
|
|
|
|
try {
|
2002-11-13 01:52:55 +03:00
|
|
|
return GetCurrentEditor().rootElement;
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
dump("no body tag found?!\n");
|
|
|
|
// better have one, how can we blow things up here?
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
// --------------------------- Logging stuff ---------------------------
|
|
|
|
|
|
|
|
function EditorGetNodeFromOffsets(offsets)
|
|
|
|
{
|
|
|
|
var node = null;
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
node = GetCurrentEditor().document;
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
for (var i = 0; i < offsets.length; i++)
|
|
|
|
node = node.childNodes[offsets[i]];
|
|
|
|
} catch (e) {}
|
2000-05-10 09:30:13 +04:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorSetSelectionFromOffsets(selRanges)
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
var selection = editor.selection;
|
|
|
|
selection.removeAllRanges();
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var rangeArr, start, end, node, offset;
|
|
|
|
for (var i = 0; i < selRanges.length; i++)
|
|
|
|
{
|
|
|
|
rangeArr = selRanges[i];
|
|
|
|
start = rangeArr[0];
|
|
|
|
end = rangeArr[1];
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var range = editor.document.createRange();
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
node = EditorGetNodeFromOffsets(start[0]);
|
|
|
|
offset = start[1];
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
range.setStart(node, offset);
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
node = EditorGetNodeFromOffsets(end[0]);
|
|
|
|
offset = end[1];
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
range.setEnd(node, offset);
|
2000-05-10 09:30:13 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
selection.addRange(range);
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
function initFontStyleMenu(menuPopup)
|
|
|
|
{
|
|
|
|
for (var i = 0; i < menuPopup.childNodes.length; i++)
|
|
|
|
{
|
|
|
|
var menuItem = menuPopup.childNodes[i];
|
|
|
|
var theStyle = menuItem.getAttribute("state");
|
|
|
|
if (theStyle)
|
|
|
|
{
|
|
|
|
menuItem.setAttribute("checked", theStyle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
function onButtonUpdate(button, commmandID)
|
|
|
|
{
|
|
|
|
var commandNode = document.getElementById(commmandID);
|
|
|
|
var state = commandNode.getAttribute("state");
|
2001-10-02 07:06:51 +04:00
|
|
|
button.checked = state == "true";
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2000-08-24 05:20:29 +04:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
function onStateButtonUpdate(button, commmandID, onState)
|
|
|
|
{
|
|
|
|
var commandNode = document.getElementById(commmandID);
|
|
|
|
var state = commandNode.getAttribute("state");
|
|
|
|
|
2001-10-02 07:06:51 +04:00
|
|
|
button.checked = state == onState;
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2001-11-15 18:28:24 +03:00
|
|
|
// --------------------------- Status calls ---------------------------
|
2000-05-10 09:30:13 +04:00
|
|
|
function getColorAndSetColorWell(ColorPickerID, ColorWellID)
|
|
|
|
{
|
|
|
|
var colorWell;
|
|
|
|
if (ColorWellID)
|
|
|
|
colorWell = document.getElementById(ColorWellID);
|
|
|
|
|
|
|
|
var colorPicker = document.getElementById(ColorPickerID);
|
2001-03-22 03:59:29 +03:00
|
|
|
if (colorPicker)
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
|
|
|
// Extract color from colorPicker and assign to colorWell.
|
2000-07-12 03:41:22 +04:00
|
|
|
var color = colorPicker.getAttribute("color");
|
2000-05-10 09:30:13 +04:00
|
|
|
|
|
|
|
if (colorWell && color)
|
|
|
|
{
|
2000-11-30 18:07:53 +03:00
|
|
|
// Use setAttribute so colorwell can be a XUL element, such as button
|
2001-03-22 03:59:29 +03:00
|
|
|
colorWell.setAttribute("style", "background-color: " + color);
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------------
|
|
|
|
function IsSpellCheckerInstalled()
|
|
|
|
{
|
2001-09-19 03:35:19 +04:00
|
|
|
return "@mozilla.org/spellchecker;1" in Components.classes;
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
|
2000-08-10 05:04:50 +04:00
|
|
|
//-----------------------------------------------------------------------------------
|
|
|
|
function IsFindInstalled()
|
|
|
|
{
|
2002-08-06 23:16:03 +04:00
|
|
|
return "@mozilla.org/embedcomp/rangefind;1" in Components.classes
|
|
|
|
&& "@mozilla.org/find/find_service;1" in Components.classes;
|
2000-08-10 05:04:50 +04:00
|
|
|
}
|
|
|
|
|
2000-05-10 09:30:13 +04:00
|
|
|
//-----------------------------------------------------------------------------------
|
2000-07-12 03:41:22 +04:00
|
|
|
function RemoveInapplicableUIElements()
|
2000-05-10 09:30:13 +04:00
|
|
|
{
|
2000-08-10 07:43:09 +04:00
|
|
|
// For items that are in their own menu block, remove associated separator
|
|
|
|
// (we can't use "hidden" since class="hide-in-IM" CSS rule interferes)
|
|
|
|
|
2000-08-10 05:04:50 +04:00
|
|
|
// if no find, remove find ui
|
|
|
|
if (!IsFindInstalled())
|
|
|
|
{
|
2001-03-29 01:16:44 +04:00
|
|
|
HideItem("menu_find");
|
|
|
|
HideItem("menu_findnext");
|
|
|
|
HideItem("menu_replace");
|
|
|
|
HideItem("menu_find");
|
|
|
|
RemoveItem("sep_find");
|
2000-08-10 07:43:09 +04:00
|
|
|
}
|
|
|
|
|
2000-08-10 05:04:50 +04:00
|
|
|
// if no spell checker, remove spell checker ui
|
2000-05-10 09:30:13 +04:00
|
|
|
if (!IsSpellCheckerInstalled())
|
|
|
|
{
|
2001-03-29 01:16:44 +04:00
|
|
|
HideItem("spellingButton");
|
|
|
|
HideItem("menu_checkspelling");
|
|
|
|
RemoveItem("sep_checkspelling");
|
|
|
|
}
|
2002-03-27 05:04:43 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
SetElementEnabled(document.getElementById("menu_checkspelling"), true);
|
|
|
|
SetElementEnabled(document.getElementById("spellingButton"), true);
|
|
|
|
SetElementEnabled(document.getElementById("checkspellingkb"), true);
|
|
|
|
}
|
2000-05-17 02:53:01 +04:00
|
|
|
|
2002-07-10 00:24:37 +04:00
|
|
|
// Remove menu items (from overlay shared with HTML editor) in non-HTML.
|
2002-11-13 01:52:55 +03:00
|
|
|
if (!IsHTMLEditor())
|
2001-03-29 01:16:44 +04:00
|
|
|
{
|
|
|
|
HideItem("insertAnchor");
|
|
|
|
HideItem("insertImage");
|
|
|
|
HideItem("insertHline");
|
|
|
|
HideItem("insertTable");
|
|
|
|
HideItem("insertHTML");
|
2002-01-15 18:49:46 +03:00
|
|
|
HideItem("insertFormMenu");
|
2001-03-29 01:16:44 +04:00
|
|
|
HideItem("fileExportToText");
|
|
|
|
HideItem("viewFormatToolbar");
|
|
|
|
HideItem("viewEditModeToolbar");
|
2000-05-10 09:30:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-29 01:16:44 +04:00
|
|
|
function HideItem(id)
|
|
|
|
{
|
|
|
|
var item = document.getElementById(id);
|
|
|
|
if (item)
|
2002-11-19 18:51:56 +03:00
|
|
|
item.hidden = true;
|
2001-03-29 01:16:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function RemoveItem(id)
|
|
|
|
{
|
|
|
|
var item = document.getElementById(id);
|
|
|
|
if (item)
|
|
|
|
item.parentNode.removeChild(item);
|
|
|
|
}
|
|
|
|
|
2000-05-25 07:35:33 +04:00
|
|
|
// Command Updating Strategy:
|
|
|
|
// Don't update on on selection change, only when menu is displayed,
|
|
|
|
// with this "oncreate" hander:
|
|
|
|
function EditorInitTableMenu()
|
2000-09-06 03:21:22 +04:00
|
|
|
{
|
2001-05-18 10:42:37 +04:00
|
|
|
try {
|
|
|
|
InitJoinCellMenuitem("menu_JoinTableCells");
|
|
|
|
} catch (ex) {}
|
2000-09-06 03:21:22 +04:00
|
|
|
|
|
|
|
// Set enable states for all table commands
|
|
|
|
goUpdateTableMenuItems(document.getElementById("composerTableMenuItems"));
|
|
|
|
}
|
|
|
|
|
|
|
|
function InitJoinCellMenuitem(id)
|
2000-05-25 07:35:33 +04:00
|
|
|
{
|
|
|
|
// Change text on the "Join..." item depending if we
|
|
|
|
// are joining selected cells or just cell to right
|
|
|
|
// TODO: What to do about normal selection that crosses
|
|
|
|
// table border? Try to figure out all cells
|
|
|
|
// included in the selection?
|
|
|
|
var menuText;
|
2000-09-06 03:21:22 +04:00
|
|
|
var menuItem = document.getElementById(id);
|
|
|
|
if (!menuItem) return;
|
2000-05-25 07:35:33 +04:00
|
|
|
|
|
|
|
// Use "Join selected cells if there's more than 1 cell selected
|
2002-07-13 02:28:30 +04:00
|
|
|
var numSelected;
|
2001-05-18 10:42:37 +04:00
|
|
|
var foundElement;
|
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
try {
|
2002-08-17 01:37:24 +04:00
|
|
|
var tagNameObj = {};
|
2002-09-13 08:19:30 +04:00
|
|
|
var countObj = {value:0}
|
2002-11-13 01:52:55 +03:00
|
|
|
foundElement = GetCurrentTableEditor().getSelectedOrParentTableElement(tagNameObj, countObj);
|
2002-09-13 08:19:30 +04:00
|
|
|
numSelected = countObj.value
|
2002-07-13 02:28:30 +04:00
|
|
|
}
|
|
|
|
catch(e) {}
|
|
|
|
if (foundElement && numSelected > 1)
|
2000-05-25 07:35:33 +04:00
|
|
|
menuText = GetString("JoinSelectedCells");
|
|
|
|
else
|
|
|
|
menuText = GetString("JoinCellToRight");
|
|
|
|
|
2001-03-22 03:59:29 +03:00
|
|
|
menuItem.setAttribute("label",menuText);
|
2000-09-06 03:21:22 +04:00
|
|
|
menuItem.setAttribute("accesskey",GetString("JoinCellAccesskey"));
|
|
|
|
}
|
2000-08-10 07:43:09 +04:00
|
|
|
|
2002-04-11 17:33:30 +04:00
|
|
|
function InitRemoveStylesMenuitems(removeStylesId, removeLinksId, removeNamedAnchorsId)
|
2000-09-06 03:21:22 +04:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
if (!editor)
|
|
|
|
return;
|
|
|
|
|
2000-09-06 03:21:22 +04:00
|
|
|
// Change wording of menuitems depending on selection
|
|
|
|
var stylesItem = document.getElementById(removeStylesId);
|
|
|
|
var linkItem = document.getElementById(removeLinksId);
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var isCollapsed = editor.selection.isCollapsed;
|
2000-09-06 03:21:22 +04:00
|
|
|
if (stylesItem)
|
|
|
|
{
|
2001-03-22 03:59:29 +03:00
|
|
|
stylesItem.setAttribute("label", isCollapsed ? GetString("StopTextStyles") : GetString("RemoveTextStyles"));
|
2000-09-06 03:21:22 +04:00
|
|
|
stylesItem.setAttribute("accesskey", GetString("RemoveTextStylesAccesskey"));
|
|
|
|
}
|
|
|
|
if (linkItem)
|
|
|
|
{
|
2001-03-22 03:59:29 +03:00
|
|
|
linkItem.setAttribute("label", isCollapsed ? GetString("StopLinks") : GetString("RemoveLinks"));
|
2000-09-06 03:21:22 +04:00
|
|
|
linkItem.setAttribute("accesskey", GetString("RemoveLinksAccesskey"));
|
|
|
|
// Note: disabling text style is a pain since there are so many - forget it!
|
|
|
|
|
2001-03-22 03:59:29 +03:00
|
|
|
// Disable if not in a link, but always allow "Remove"
|
|
|
|
// if selection isn't collapsed since we only look at anchor node
|
2002-07-13 02:28:30 +04:00
|
|
|
try {
|
|
|
|
SetElementEnabled(linkItem, !isCollapsed ||
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.getElementOrParentByTagName("href", null));
|
2002-07-13 02:28:30 +04:00
|
|
|
} catch(e) {}
|
2002-04-11 17:33:30 +04:00
|
|
|
}
|
2002-05-18 01:50:04 +04:00
|
|
|
// Disable if selection is collapsed
|
|
|
|
SetElementEnabledById(removeNamedAnchorsId, !isCollapsed);
|
2000-05-25 07:35:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function goUpdateTableMenuItems(commandset)
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
var editor = GetCurrentTableEditor();
|
|
|
|
if (!editor)
|
2002-07-10 00:24:37 +04:00
|
|
|
{
|
|
|
|
dump("goUpdateTableMenuItems: too early, not initialized\n");
|
|
|
|
return;
|
|
|
|
}
|
2002-07-13 02:28:30 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var enabled = false;
|
|
|
|
var enabledIfTable = false;
|
|
|
|
|
|
|
|
var flags = editor.flags;
|
2002-07-13 02:28:30 +04:00
|
|
|
if (!(flags & nsIPlaintextEditor.eEditorReadonlyMask) &&
|
2002-07-10 00:24:37 +04:00
|
|
|
IsEditingRenderedHTML())
|
2000-05-25 07:35:33 +04:00
|
|
|
{
|
2002-08-17 01:37:24 +04:00
|
|
|
var tagNameObj = { value: "" };
|
2002-09-13 08:19:30 +04:00
|
|
|
var element;
|
2002-07-13 02:28:30 +04:00
|
|
|
try {
|
2002-11-13 01:52:55 +03:00
|
|
|
element = editor.getSelectedOrParentTableElement(tagNameObj, {value:0});
|
2002-07-13 02:28:30 +04:00
|
|
|
}
|
|
|
|
catch(e) {}
|
|
|
|
|
2002-09-13 08:19:30 +04:00
|
|
|
if (element)
|
2000-05-25 07:35:33 +04:00
|
|
|
{
|
|
|
|
// Value when we need to have a selected table or inside a table
|
2001-03-22 03:59:29 +03:00
|
|
|
enabledIfTable = true;
|
2000-05-25 07:35:33 +04:00
|
|
|
|
|
|
|
// All others require being inside a cell or selected cell
|
|
|
|
enabled = (tagNameObj.value == "td");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop through command nodes
|
|
|
|
for (var i = 0; i < commandset.childNodes.length; i++)
|
|
|
|
{
|
|
|
|
var commandID = commandset.childNodes[i].getAttribute("id");
|
|
|
|
if (commandID)
|
|
|
|
{
|
|
|
|
if (commandID == "cmd_InsertTable" ||
|
2000-08-10 07:43:09 +04:00
|
|
|
commandID == "cmd_JoinTableCells" ||
|
2001-05-09 09:23:37 +04:00
|
|
|
commandID == "cmd_SplitTableCell" ||
|
|
|
|
commandID == "cmd_ConvertToTable")
|
2000-05-25 07:35:33 +04:00
|
|
|
{
|
|
|
|
// Call the update method in the command class
|
|
|
|
goUpdateCommand(commandID);
|
2001-03-22 03:59:29 +03:00
|
|
|
}
|
2000-05-25 07:35:33 +04:00
|
|
|
// Directly set with the values calculated here
|
|
|
|
else if (commandID == "cmd_DeleteTable" ||
|
2000-08-10 07:43:09 +04:00
|
|
|
commandID == "cmd_NormalizeTable" ||
|
2001-02-16 06:32:49 +03:00
|
|
|
commandID == "cmd_editTable" ||
|
2001-03-29 01:16:44 +04:00
|
|
|
commandID == "cmd_TableOrCellColor" ||
|
|
|
|
commandID == "cmd_SelectTable")
|
2000-05-25 07:35:33 +04:00
|
|
|
{
|
|
|
|
goSetCommandEnabled(commandID, enabledIfTable);
|
|
|
|
} else {
|
|
|
|
goSetCommandEnabled(commandID, enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------------
|
|
|
|
// Helpers for inserting and editing tables:
|
|
|
|
|
|
|
|
function IsInTable()
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
try {
|
|
|
|
var flags = editor.flags;
|
|
|
|
return (IsHTMLEditor() &&
|
|
|
|
!(flags & nsIPlaintextEditor.eEditorReadonlyMask) &&
|
|
|
|
IsEditingRenderedHTML() &&
|
|
|
|
null != editor.getElementOrParentByTagName("table", null));
|
|
|
|
} catch (e) {}
|
|
|
|
return false;
|
2000-05-25 07:35:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function IsInTableCell()
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
var flags = editor.flags;
|
|
|
|
return (IsHTMLEditor() &&
|
|
|
|
!(flags & nsIPlaintextEditor.eEditorReadonlyMask) &&
|
|
|
|
IsEditingRenderedHTML() &&
|
|
|
|
null != editor.getElementOrParentByTagName("td", null));
|
|
|
|
} catch (e) {}
|
|
|
|
return false;
|
|
|
|
|
2000-05-25 07:35:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function IsSelectionInOneCell()
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
var selection = editor.selection;
|
2000-05-25 07:35:33 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
if (selection.rangeCount == 1)
|
2000-05-25 07:35:33 +04:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
// We have a "normal" single-range selection
|
|
|
|
if (!selection.isCollapsed &&
|
|
|
|
selection.anchorNode != selection.focusNode)
|
|
|
|
{
|
|
|
|
// Check if both nodes are within the same cell
|
|
|
|
var anchorCell = editor.getElementOrParentByTagName("td", selection.anchorNode);
|
|
|
|
var focusCell = editor.getElementOrParentByTagName("td", selection.focusNode);
|
|
|
|
return (focusCell != null && anchorCell != null && (focusCell == anchorCell));
|
|
|
|
}
|
|
|
|
// Collapsed selection or anchor == focus (thus must be in 1 cell)
|
|
|
|
return true;
|
2000-05-25 07:35:33 +04:00
|
|
|
}
|
2002-11-13 01:52:55 +03:00
|
|
|
} catch (e) {}
|
2000-05-25 07:35:33 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call this with insertAllowed = true to allow inserting if not in existing table,
|
|
|
|
// else use false to do nothing if not in a table
|
|
|
|
function EditorInsertOrEditTable(insertAllowed)
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
if (IsInTable())
|
|
|
|
{
|
2001-02-27 01:02:07 +03:00
|
|
|
// Edit properties of existing table
|
2001-02-16 06:32:49 +03:00
|
|
|
window.openDialog("chrome://editor/content/EdTableProps.xul", "_blank", "chrome,close,titlebar,modal", "","TablePanel");
|
2001-05-09 09:23:37 +04:00
|
|
|
gContentWindow.focus();
|
2002-11-13 01:52:55 +03:00
|
|
|
}
|
|
|
|
else if (insertAllowed)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (GetCurrentEditor().selection.isCollapsed)
|
|
|
|
// If we have a caret, insert a blank table...
|
|
|
|
EditorInsertTable();
|
|
|
|
else
|
|
|
|
// else convert the selection into a table
|
|
|
|
goDoCommand("cmd_ConvertToTable");
|
|
|
|
} catch (e) {}
|
2000-05-25 07:35:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorInsertTable()
|
|
|
|
{
|
|
|
|
// Insert a new table
|
|
|
|
window.openDialog("chrome://editor/content/EdInsertTable.xul", "_blank", "chrome,close,titlebar,modal", "");
|
2001-05-09 09:23:37 +04:00
|
|
|
gContentWindow.focus();
|
2000-05-25 07:35:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function EditorTableCellProperties()
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
if (!IsHTMLEditor())
|
2002-08-21 03:59:19 +04:00
|
|
|
return;
|
2002-07-13 02:28:30 +04:00
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
try {
|
|
|
|
var cell = GetCurrentEditor().getElementOrParentByTagName("td", null);
|
|
|
|
if (cell) {
|
|
|
|
// Start Table Properties dialog on the "Cell" panel
|
|
|
|
window.openDialog("chrome://editor/content/EdTableProps.xul", "_blank", "chrome,close,titlebar,modal", "", "CellPanel");
|
|
|
|
gContentWindow.focus();
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
2000-05-25 07:35:33 +04:00
|
|
|
}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
|
2001-05-17 03:44:56 +04:00
|
|
|
function GetNumberOfContiguousSelectedRows()
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
if (!IsHTMLEditor())
|
2001-05-17 03:44:56 +04:00
|
|
|
return 0;
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var rows = 0;
|
|
|
|
try {
|
|
|
|
var editor = GetCurrentTableEditor();
|
|
|
|
var rowObj = { value: 0 };
|
|
|
|
var colObj = { value: 0 };
|
|
|
|
var cell = editor.getFirstSelectedCellInTable(rowObj, colObj);
|
|
|
|
if (!cell)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// We have at least one row
|
|
|
|
rows++;
|
|
|
|
|
|
|
|
var lastIndex = rowObj.value;
|
|
|
|
do {
|
|
|
|
cell = editor.getNextSelectedCell({value:0});
|
|
|
|
if (cell)
|
2001-05-17 03:44:56 +04:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.getCellIndexes(cell, rowObj, colObj);
|
|
|
|
var index = rowObj.value;
|
|
|
|
if (index == lastIndex + 1)
|
|
|
|
{
|
|
|
|
lastIndex = index;
|
|
|
|
rows++;
|
|
|
|
}
|
2001-05-17 03:44:56 +04:00
|
|
|
}
|
|
|
|
}
|
2002-11-13 01:52:55 +03:00
|
|
|
while (cell);
|
|
|
|
} catch (e) {}
|
2001-05-17 03:44:56 +04:00
|
|
|
|
|
|
|
return rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetNumberOfContiguousSelectedColumns()
|
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
if (!IsHTMLEditor())
|
2001-05-17 03:44:56 +04:00
|
|
|
return 0;
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
var columns = 0;
|
|
|
|
try {
|
|
|
|
var editor = GetCurrentTableEditor();
|
|
|
|
var colObj = { value: 0 };
|
|
|
|
var rowObj = { value: 0 };
|
|
|
|
var cell = editor.getFirstSelectedCellInTable(rowObj, colObj);
|
|
|
|
if (!cell)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// We have at least one column
|
|
|
|
columns++;
|
|
|
|
|
|
|
|
var lastIndex = colObj.value;
|
|
|
|
do {
|
|
|
|
cell = editor.getNextSelectedCell({value:0});
|
|
|
|
if (cell)
|
2001-05-17 03:44:56 +04:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
editor.getCellIndexes(cell, rowObj, colObj);
|
|
|
|
var index = colObj.value;
|
|
|
|
if (index == lastIndex +1)
|
|
|
|
{
|
|
|
|
lastIndex = index;
|
|
|
|
columns++;
|
|
|
|
}
|
2001-05-17 03:44:56 +04:00
|
|
|
}
|
|
|
|
}
|
2002-11-13 01:52:55 +03:00
|
|
|
while (cell);
|
|
|
|
} catch (e) {}
|
2001-05-17 03:44:56 +04:00
|
|
|
|
|
|
|
return columns;
|
|
|
|
}
|
|
|
|
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
function EditorOnFocus()
|
|
|
|
{
|
2001-01-18 03:59:18 +03:00
|
|
|
// Current window already has the InsertCharWindow
|
|
|
|
if ("InsertCharWindow" in window && window.InsertCharWindow) return;
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
|
|
|
|
// Find window with an InsertCharsWindow and switch association to this one
|
|
|
|
var windowWithDialog = FindEditorWithInsertCharDialog();
|
|
|
|
if (windowWithDialog)
|
|
|
|
{
|
|
|
|
// Switch the dialog to current window
|
|
|
|
// this sets focus to dialog, so bring focus back to editor window
|
|
|
|
if (SwitchInsertCharToThisWindow(windowWithDialog))
|
2003-06-13 16:55:17 +04:00
|
|
|
top.document.commandDispatcher.focusedWindow.focus();
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function SwitchInsertCharToThisWindow(windowWithDialog)
|
|
|
|
{
|
2001-03-22 03:59:29 +03:00
|
|
|
if (windowWithDialog && "InsertCharWindow" in windowWithDialog &&
|
2001-01-18 03:59:18 +03:00
|
|
|
windowWithDialog.InsertCharWindow)
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
{
|
2001-03-22 03:59:29 +03:00
|
|
|
// Move dialog association to the current window
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
window.InsertCharWindow = windowWithDialog.InsertCharWindow;
|
|
|
|
windowWithDialog.InsertCharWindow = null;
|
|
|
|
|
2002-11-13 01:52:55 +03:00
|
|
|
// Switch the dialog's opener to current window's
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
window.InsertCharWindow.opener = window;
|
|
|
|
|
|
|
|
// Bring dialog to the forground
|
|
|
|
window.InsertCharWindow.focus();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function FindEditorWithInsertCharDialog()
|
|
|
|
{
|
2002-07-13 02:28:30 +04:00
|
|
|
try {
|
|
|
|
// Find window with an InsertCharsWindow and switch association to this one
|
|
|
|
var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
|
|
|
|
var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
|
|
|
|
var enumerator = windowManagerInterface.getEnumerator( null );
|
2001-01-18 03:59:18 +03:00
|
|
|
|
2002-07-13 02:28:30 +04:00
|
|
|
while ( enumerator.hasMoreElements() )
|
2001-03-22 03:59:29 +03:00
|
|
|
{
|
2002-07-13 02:28:30 +04:00
|
|
|
var tempWindow = enumerator.getNext();
|
|
|
|
|
|
|
|
if (tempWindow != window && "InsertCharWindow" in tempWindow &&
|
|
|
|
tempWindow.InsertCharWindow)
|
|
|
|
{
|
|
|
|
return tempWindow;
|
|
|
|
}
|
2001-03-22 03:59:29 +03:00
|
|
|
}
|
|
|
|
}
|
2002-07-13 02:28:30 +04:00
|
|
|
catch(e) {}
|
2000-09-06 03:21:22 +04:00
|
|
|
return null;
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function EditorFindOrCreateInsertCharWindow()
|
|
|
|
{
|
2001-01-18 03:59:18 +03:00
|
|
|
if ("InsertCharWindow" in window && window.InsertCharWindow)
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
window.InsertCharWindow.focus();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Since we switch the dialog during EditorOnFocus(),
|
|
|
|
// this should really never be found, but it's good to be sure
|
|
|
|
var windowWithDialog = FindEditorWithInsertCharDialog();
|
|
|
|
if (windowWithDialog)
|
|
|
|
{
|
|
|
|
SwitchInsertCharToThisWindow(windowWithDialog);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The dialog will set window.InsertCharWindow to itself
|
|
|
|
window.openDialog("chrome://editor/content/EdInsertChars.xul", "_blank", "chrome,close,titlebar", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find another HTML editor window to associate with the InsertChar dialog
|
|
|
|
// or close it if none found (May be a mail composer)
|
|
|
|
function SwitchInsertCharToAnotherEditorOrClose()
|
|
|
|
{
|
2001-03-22 03:59:29 +03:00
|
|
|
if ("InsertCharWindow" in window && window.InsertCharWindow)
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
{
|
2002-04-30 05:36:59 +04:00
|
|
|
var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
|
2002-07-13 02:28:30 +04:00
|
|
|
var enumerator;
|
|
|
|
try {
|
|
|
|
var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
|
|
|
|
enumerator = windowManagerInterface.getEnumerator( null );
|
|
|
|
}
|
|
|
|
catch(e) {}
|
|
|
|
if (!enumerator) return;
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
|
|
|
|
// TODO: Fix this to search for command controllers and look for "cmd_InsertChars"
|
|
|
|
// For now, detect just Web Composer and HTML Mail Composer
|
2001-03-22 03:59:29 +03:00
|
|
|
while ( enumerator.hasMoreElements() )
|
|
|
|
{
|
|
|
|
var tempWindow = enumerator.getNext();
|
2002-11-13 01:52:55 +03:00
|
|
|
if (tempWindow != window && tempWindow != window.InsertCharWindow &&
|
|
|
|
"GetCurrentEditor" in tempWindow && tmpWindow.GetCurrentEditor())
|
2001-03-22 03:59:29 +03:00
|
|
|
{
|
2002-11-13 01:52:55 +03:00
|
|
|
tempWindow.InsertCharWindow = window.InsertCharWindow;
|
|
|
|
window.InsertCharWindow = null;
|
|
|
|
tempWindow.InsertCharWindow.opener = tempWindow;
|
|
|
|
return;
|
2001-03-22 03:59:29 +03:00
|
|
|
}
|
|
|
|
}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
// Didn't find another editor - close the dialog
|
|
|
|
window.InsertCharWindow.close();
|
|
|
|
}
|
|
|
|
}
|
2002-10-16 12:07:35 +04:00
|
|
|
|
|
|
|
function ResetStructToolbar()
|
|
|
|
{
|
|
|
|
gLastFocusNode = null;
|
|
|
|
UpdateStructToolbar();
|
|
|
|
}
|
|
|
|
|
|
|
|
function newCommandListener(element)
|
|
|
|
{
|
|
|
|
return function() { return SelectFocusNodeAncestor(element); };
|
|
|
|
}
|
|
|
|
|
|
|
|
function newContextmenuListener(button, element)
|
|
|
|
{
|
|
|
|
return function() { return InitStructBarContextMenu(button, element); };
|
|
|
|
}
|
|
|
|
|
|
|
|
function UpdateStructToolbar()
|
|
|
|
{
|
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
if (!editor) return;
|
|
|
|
|
|
|
|
var mixed = GetSelectionContainer();
|
|
|
|
if (!mixed) return;
|
|
|
|
var element = mixed.node;
|
|
|
|
var oneElementSelected = mixed.oneElementSelected;
|
|
|
|
|
|
|
|
if (!element) return;
|
|
|
|
|
|
|
|
if (element == gLastFocusNode &&
|
|
|
|
oneElementSelected == gLastFocusNodeWasSelected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gLastFocusNode = element;
|
|
|
|
gLastFocusNodeWasSelected = mixed.oneElementSelected;
|
|
|
|
|
2002-10-23 16:09:02 +04:00
|
|
|
var toolbar = document.getElementById("structToolbar");
|
2002-10-16 12:07:35 +04:00
|
|
|
if (!toolbar) return;
|
|
|
|
var childNodes = toolbar.childNodes;
|
|
|
|
var childNodesLength = childNodes.length;
|
2002-10-23 16:09:02 +04:00
|
|
|
// We need to leave the <label> to flex the buttons to the left
|
|
|
|
// so, don't remove the last child at position length - 1
|
2004-04-16 02:14:39 +04:00
|
|
|
while (childNodes.length > 1) {
|
|
|
|
// Remove back to front so there's less moving about.
|
|
|
|
toolbar.removeChild(childNodes.item(childNodes.length - 2));
|
2002-10-16 12:07:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
toolbar.removeAttribute("label");
|
|
|
|
|
|
|
|
if ( IsInHTMLSourceMode() ) {
|
|
|
|
// we have destroyed the contents of the status bar and are
|
|
|
|
// about to recreate it ; but we don't want to do that in
|
|
|
|
// Source mode
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var tag, button;
|
|
|
|
var bodyElement = GetBodyElement();
|
|
|
|
var isFocusNode = true;
|
|
|
|
var tmp;
|
|
|
|
do {
|
|
|
|
tag = element.nodeName.toLowerCase();
|
|
|
|
|
|
|
|
button = document.createElementNS(XUL_NS, "toolbarbutton");
|
|
|
|
button.setAttribute("label", "<" + tag + ">");
|
|
|
|
button.setAttribute("value", tag);
|
|
|
|
button.setAttribute("context", "structToolbarContext");
|
2002-10-23 16:09:02 +04:00
|
|
|
button.className = "struct-button";
|
2002-10-16 12:07:35 +04:00
|
|
|
|
|
|
|
toolbar.insertBefore(button, toolbar.firstChild);
|
|
|
|
|
|
|
|
button.addEventListener("command", newCommandListener(element), false);
|
|
|
|
|
|
|
|
button.addEventListener("contextmenu", newContextmenuListener(button, element), false);
|
|
|
|
|
|
|
|
if (isFocusNode && oneElementSelected) {
|
2002-10-23 16:09:02 +04:00
|
|
|
button.setAttribute("checked", "true");
|
2002-10-16 12:07:35 +04:00
|
|
|
isFocusNode = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = element;
|
|
|
|
element = element.parentNode;
|
|
|
|
|
|
|
|
} while (tmp != bodyElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
function SelectFocusNodeAncestor(element)
|
|
|
|
{
|
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
if (editor) {
|
|
|
|
if (element == GetBodyElement())
|
|
|
|
editor.selectAll();
|
|
|
|
else
|
|
|
|
editor.selectElement(element);
|
|
|
|
}
|
|
|
|
ResetStructToolbar();
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetSelectionContainer()
|
|
|
|
{
|
|
|
|
var editor = GetCurrentEditor();
|
|
|
|
if (!editor) return null;
|
|
|
|
|
2002-11-08 12:14:00 +03:00
|
|
|
try {
|
|
|
|
var selection = editor.selection;
|
|
|
|
if (!selection) return null;
|
|
|
|
}
|
|
|
|
catch (e) { return null; }
|
2002-10-16 12:07:35 +04:00
|
|
|
|
|
|
|
var result = { oneElementSelected:false };
|
|
|
|
|
|
|
|
if (selection.isCollapsed) {
|
|
|
|
result.node = selection.focusNode;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var rangeCount = selection.rangeCount;
|
|
|
|
if (rangeCount == 1) {
|
|
|
|
result.node = editor.getSelectedElement("");
|
|
|
|
var range = selection.getRangeAt(0);
|
|
|
|
|
|
|
|
// check for a weird case : when we select a piece of text inside
|
|
|
|
// a text node and apply an inline style to it, the selection starts
|
|
|
|
// at the end of the text node preceding the style and ends after the
|
|
|
|
// last char of the style. Assume the style element is selected for
|
|
|
|
// user's pleasure
|
|
|
|
if (!result.node &&
|
|
|
|
range.startContainer.nodeType == Node.TEXT_NODE &&
|
|
|
|
range.startOffset == range.startContainer.length &&
|
|
|
|
range.endContainer.nodeType == Node.TEXT_NODE &&
|
|
|
|
range.endOffset == range.endContainer.length &&
|
|
|
|
range.endContainer.nextSibling == null &&
|
|
|
|
range.startContainer.nextSibling == range.endContainer.parentNode)
|
|
|
|
result.node = range.endContainer.parentNode;
|
|
|
|
|
|
|
|
if (!result.node) {
|
|
|
|
// let's rely on the common ancestor of the selection
|
|
|
|
result.node = range.commonAncestorContainer;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result.oneElementSelected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// assume table cells !
|
|
|
|
var i, container = null;
|
|
|
|
for (i = 0; i < rangeCount; i++) {
|
|
|
|
range = selection.getRangeAt(i);
|
|
|
|
if (!container) {
|
|
|
|
container = range.startContainer;
|
|
|
|
}
|
|
|
|
else if (container != range.startContainer) {
|
|
|
|
// all table cells don't belong to same row so let's
|
|
|
|
// select the parent of all rows
|
|
|
|
result.node = container.parentNode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
result.node = container;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure we have an element here
|
|
|
|
while (result.node.nodeType != Node.ELEMENT_NODE)
|
|
|
|
result.node = result.node.parentNode;
|
|
|
|
|
|
|
|
// and make sure the element is not a special editor node like
|
|
|
|
// the <br> we insert in blank lines
|
2003-06-19 18:06:05 +04:00
|
|
|
// and don't select anonymous content !!! (fix for bug 190279)
|
|
|
|
while (result.node.hasAttribute("_moz_editor_bogus_node") ||
|
|
|
|
editor.isAnonymousElement(result.node))
|
2002-10-16 12:07:35 +04:00
|
|
|
result.node = result.node.parentNode;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2002-11-08 12:14:00 +03:00
|
|
|
|
|
|
|
function FillInHTMLTooltip(tooltip)
|
|
|
|
{
|
2003-06-20 13:11:40 +04:00
|
|
|
const XLinkNS = "http://www.w3.org/1999/xlink";
|
2002-11-08 12:14:00 +03:00
|
|
|
var tooltipText = null;
|
2003-12-21 07:04:33 +03:00
|
|
|
var node;
|
2003-06-20 13:11:40 +04:00
|
|
|
if (gEditorDisplayMode == kDisplayModePreview) {
|
2003-12-21 07:04:33 +03:00
|
|
|
for (node = document.tooltipNode; node; node = node.parentNode) {
|
2003-06-20 13:11:40 +04:00
|
|
|
if (node.nodeType == Node.ELEMENT_NODE) {
|
|
|
|
tooltipText = node.getAttributeNS(XLinkNS, "title");
|
|
|
|
if (tooltipText && /\S/.test(tooltipText)) {
|
|
|
|
tooltip.setAttribute("label", tooltipText);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
tooltipText = node.getAttribute("title");
|
|
|
|
if (tooltipText && /\S/.test(tooltipText)) {
|
|
|
|
tooltip.setAttribute("label", tooltipText);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2003-12-21 07:04:33 +03:00
|
|
|
for (node = document.tooltipNode; node; node = node.parentNode) {
|
2003-06-20 13:11:40 +04:00
|
|
|
if (node instanceof Components.interfaces.nsIDOMHTMLImageElement ||
|
|
|
|
node instanceof Components.interfaces.nsIDOMHTMLInputElement)
|
|
|
|
tooltipText = node.getAttribute("src");
|
|
|
|
else if (node instanceof Components.interfaces.nsIDOMHTMLAnchorElement)
|
|
|
|
tooltipText = node.getAttribute("href") || node.name;
|
|
|
|
if (tooltipText) {
|
|
|
|
tooltip.setAttribute("label", tooltipText);
|
|
|
|
return true;
|
|
|
|
}
|
2002-11-08 12:14:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2002-12-02 16:54:41 +03:00
|
|
|
|
|
|
|
function UpdateTOC()
|
|
|
|
{
|
|
|
|
window.openDialog("chrome://editor/content/EdInsertTOC.xul",
|
|
|
|
"_blank", "chrome,close,modal,titlebar");
|
2004-06-25 03:44:05 +04:00
|
|
|
window.content.focus();
|
2002-12-02 16:54:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function InitTOCMenu()
|
|
|
|
{
|
|
|
|
var elt = GetCurrentEditor().document.getElementById("mozToc");
|
|
|
|
var createMenuitem = document.getElementById("insertTOCMenuitem");
|
|
|
|
var updateMenuitem = document.getElementById("updateTOCMenuitem");
|
|
|
|
var removeMenuitem = document.getElementById("removeTOCMenuitem");
|
|
|
|
if (removeMenuitem && createMenuitem && updateMenuitem) {
|
|
|
|
if (elt) {
|
|
|
|
createMenuitem.setAttribute("disabled", "true");
|
|
|
|
updateMenuitem.removeAttribute("disabled");
|
|
|
|
removeMenuitem.removeAttribute("disabled");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
createMenuitem.removeAttribute("disabled");
|
|
|
|
removeMenuitem.setAttribute("disabled", "true");
|
|
|
|
updateMenuitem.setAttribute("disabled", "true");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function RemoveTOC()
|
|
|
|
{
|
|
|
|
var theDocument = GetCurrentEditor().document;
|
|
|
|
var elt = theDocument.getElementById("mozToc");
|
|
|
|
if (elt) {
|
|
|
|
elt.parentNode.removeChild(elt);
|
|
|
|
}
|
|
|
|
|
|
|
|
function acceptNode(node)
|
|
|
|
{
|
|
|
|
if (node.nodeName.toLowerCase() == "a" &&
|
|
|
|
node.hasAttribute("name") &&
|
|
|
|
node.getAttribute("name").substr(0, 8) == "mozTocId") {
|
|
|
|
return NodeFilter.FILTER_ACCEPT;
|
|
|
|
}
|
|
|
|
return NodeFilter.FILTER_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
var treeWalker = theDocument.createTreeWalker(theDocument.documentElement,
|
|
|
|
NodeFilter.SHOW_ELEMENT,
|
|
|
|
acceptNode,
|
|
|
|
true);
|
|
|
|
if (treeWalker) {
|
|
|
|
var anchorNode = treeWalker.nextNode();
|
|
|
|
while (anchorNode) {
|
|
|
|
var tmp = treeWalker.nextNode();
|
|
|
|
anchorNode.parentNode.removeChild(anchorNode);
|
|
|
|
anchorNode = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|