2004-04-18 18:21:17 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* 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/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2001-09-20 04:02:59 +04:00
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
2004-04-18 18:21:17 +04:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998-1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* 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"),
|
|
|
|
* 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
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* 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
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-08-19 18:28:44 +04:00
|
|
|
|
1999-07-05 03:01:10 +04:00
|
|
|
//Cancel() is in EdDialogCommon.js
|
2002-09-19 07:32:23 +04:00
|
|
|
var gTableElement = null;
|
|
|
|
var gRows;
|
|
|
|
var gColumns;
|
|
|
|
var gActiveEditor;
|
1999-07-05 03:01:10 +04:00
|
|
|
|
|
|
|
// dialog initialization code
|
|
|
|
function Startup()
|
|
|
|
{
|
2002-11-13 01:44:04 +03:00
|
|
|
gActiveEditor = GetCurrentTableEditor();
|
2002-09-19 07:32:23 +04:00
|
|
|
if (!gActiveEditor)
|
|
|
|
{
|
|
|
|
dump("Failed to get active editor!\n");
|
|
|
|
window.close();
|
1999-07-05 03:01:10 +04:00
|
|
|
return;
|
2002-09-19 07:32:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
gTableElement = gActiveEditor.createElementWithDefaults("table");
|
|
|
|
} catch (e) {}
|
1999-08-25 18:36:13 +04:00
|
|
|
|
2002-09-19 07:32:23 +04:00
|
|
|
if(!gTableElement)
|
1999-07-14 19:24:33 +04:00
|
|
|
{
|
|
|
|
dump("Failed to create a new table!\n");
|
|
|
|
window.close();
|
2001-05-09 09:23:37 +04:00
|
|
|
return;
|
1999-07-14 19:24:33 +04:00
|
|
|
}
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.rowsInput = document.getElementById("rowsInput");
|
|
|
|
gDialog.columnsInput = document.getElementById("columnsInput");
|
|
|
|
gDialog.widthInput = document.getElementById("widthInput");
|
|
|
|
gDialog.borderInput = document.getElementById("borderInput");
|
|
|
|
gDialog.widthPixelOrPercentMenulist = document.getElementById("widthPixelOrPercentMenulist");
|
2001-12-18 08:59:30 +03:00
|
|
|
gDialog.OkButton = document.documentElement.getButton("accept");
|
1999-07-14 19:24:33 +04:00
|
|
|
|
1999-09-04 02:05:47 +04:00
|
|
|
// Make a copy to use for AdvancedEdit
|
2002-09-19 07:32:23 +04:00
|
|
|
globalElement = gTableElement.cloneNode(false);
|
|
|
|
try {
|
2002-11-13 01:44:04 +03:00
|
|
|
if (GetPrefs().getBoolPref("editor.use_css") && IsHTMLEditor()
|
2002-09-19 07:32:23 +04:00
|
|
|
&& !(gActiveEditor.flags & Components.interfaces.nsIPlaintextEditor.eEditorMailMask))
|
|
|
|
{
|
|
|
|
// only for Composer and not for htmlmail
|
|
|
|
globalElement.setAttribute("style", "text-align: left;");
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
|
1999-09-04 02:05:47 +04:00
|
|
|
// Initialize all widgets with image attributes
|
|
|
|
InitDialog();
|
|
|
|
|
Big UI fix! bugs=47898, 26843, 26871, 37152, 38944, 41545, 42246, 42343, 43089, 45463, 45904, 46001, 47644, 47314, 47510, 47515, 47622, 47650, 47653, 47699, 47700, 46179, 47696, 47693. r=sfraser
2000-08-10 06:10:17 +04:00
|
|
|
// Set initial number to 2 rows, 2 columns:
|
1999-09-30 01:45:50 +04:00
|
|
|
// Note, these are not attributes on the table,
|
|
|
|
// so don't put them in InitDialog(),
|
|
|
|
// else the user's values will be trashed when they use
|
|
|
|
// the Advanced Edit dialog
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.rowsInput.value = 2;
|
|
|
|
gDialog.columnsInput.value = 2;
|
1999-09-30 01:45:50 +04:00
|
|
|
|
Big UI fix! bugs=47898, 26843, 26871, 37152, 38944, 41545, 42246, 42343, 43089, 45463, 45904, 46001, 47644, 47314, 47510, 47515, 47622, 47650, 47653, 47699, 47700, 46179, 47696, 47693. r=sfraser
2000-08-10 06:10:17 +04:00
|
|
|
// If no default value on the width, set to 100%
|
2001-10-11 00:07:06 +04:00
|
|
|
if (gDialog.widthInput.value.length == 0)
|
Big UI fix! bugs=47898, 26843, 26871, 37152, 38944, 41545, 42246, 42343, 43089, 45463, 45904, 46001, 47644, 47314, 47510, 47515, 47622, 47650, 47653, 47699, 47700, 46179, 47696, 47693. r=sfraser
2000-08-10 06:10:17 +04:00
|
|
|
{
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.widthInput.value = "100";
|
|
|
|
gDialog.widthPixelOrPercentMenulist.selectedIndex = 1;
|
Big UI fix! bugs=47898, 26843, 26871, 37152, 38944, 41545, 42246, 42343, 43089, 45463, 45904, 46001, 47644, 47314, 47510, 47515, 47622, 47650, 47653, 47699, 47700, 46179, 47696, 47693. r=sfraser
2000-08-10 06:10:17 +04:00
|
|
|
}
|
|
|
|
|
2001-05-09 09:23:37 +04:00
|
|
|
SetTextboxFocusById("rowsInput");
|
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
|
|
|
|
|
|
|
SetWindowLocation();
|
1999-09-04 02:05:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set dialog widgets with attribute data
|
|
|
|
// We get them from globalElement copy so this can be used
|
|
|
|
// by AdvancedEdit(), which is shared by all property dialogs
|
1999-09-30 01:45:50 +04:00
|
|
|
function InitDialog()
|
1999-09-04 02:05:47 +04:00
|
|
|
{
|
1999-07-14 19:24:33 +04:00
|
|
|
// Get default attributes set on the created table:
|
|
|
|
// Get the width attribute of the element, stripping out "%"
|
Big UI fix! bugs=47898, 26843, 26871, 37152, 38944, 41545, 42246, 42343, 43089, 45463, 45904, 46001, 47644, 47314, 47510, 47515, 47622, 47650, 47653, 47699, 47700, 46179, 47696, 47693. r=sfraser
2000-08-10 06:10:17 +04:00
|
|
|
// This sets contents of menu combobox list
|
2001-10-31 02:40:02 +03:00
|
|
|
// 2nd param = null: Use current selection to find if parent is table cell or window
|
|
|
|
gDialog.widthInput.value = InitPixelOrPercentMenulist(globalElement, null, "width", "widthPixelOrPercentMenulist", gPercent);
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.borderInput.value = globalElement.getAttribute("border");
|
1999-07-05 03:01:10 +04:00
|
|
|
}
|
|
|
|
|
2000-08-11 07:20:47 +04:00
|
|
|
function ChangeRowOrColumn(id)
|
|
|
|
{
|
|
|
|
// Allow only integers
|
|
|
|
forceInteger(id);
|
|
|
|
|
|
|
|
// Enable OK only if both rows and columns have a value > 0
|
2001-10-31 02:40:02 +03:00
|
|
|
var enable = gDialog.rowsInput.value.length > 0 &&
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.rowsInput.value > 0 &&
|
|
|
|
gDialog.columnsInput.value.length > 0 &&
|
2001-10-31 02:40:02 +03:00
|
|
|
gDialog.columnsInput.value > 0;
|
|
|
|
|
2001-12-18 08:59:30 +03:00
|
|
|
SetElementEnabled(gDialog.OkButton, enable);
|
2001-10-31 02:40:02 +03:00
|
|
|
SetElementEnabledById("AdvancedEditButton1", enable);
|
2000-08-11 07:20:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-04 02:05:47 +04:00
|
|
|
// Get and validate data from widgets.
|
|
|
|
// Set attributes on globalElement so they can be accessed by AdvancedEdit()
|
|
|
|
function ValidateData()
|
1999-07-05 03:01:10 +04:00
|
|
|
{
|
2002-09-19 07:32:23 +04:00
|
|
|
gRows = ValidateNumber(gDialog.rowsInput, null, 1, gMaxRows, null, null, true)
|
2001-04-05 02:05:06 +04:00
|
|
|
if (gValidationError)
|
1999-08-25 18:36:13 +04:00
|
|
|
return false;
|
1999-07-05 03:01:10 +04:00
|
|
|
|
2002-09-19 07:32:23 +04:00
|
|
|
gColumns = ValidateNumber(gDialog.columnsInput, null, 1, gMaxColumns, null, null, true)
|
2001-04-05 02:05:06 +04:00
|
|
|
if (gValidationError)
|
1999-08-25 18:36:13 +04:00
|
|
|
return false;
|
1999-09-04 02:05:47 +04:00
|
|
|
|
2001-04-05 02:05:06 +04:00
|
|
|
// Set attributes: NOTE: These may be empty strings (last param = false)
|
2002-08-16 01:49:40 +04:00
|
|
|
ValidateNumber(gDialog.borderInput, null, 0, gMaxPixels, globalElement, "border", false);
|
2001-04-05 02:05:06 +04:00
|
|
|
// TODO: Deal with "BORDER" without value issue
|
|
|
|
if (gValidationError) return false;
|
1999-07-28 03:59:22 +04:00
|
|
|
|
2001-10-11 00:07:06 +04:00
|
|
|
ValidateNumber(gDialog.widthInput, gDialog.widthPixelOrPercentMenulist,
|
2002-08-16 01:49:40 +04:00
|
|
|
1, gMaxTableSize, globalElement, "width", false);
|
2001-04-05 02:05:06 +04:00
|
|
|
if (gValidationError)
|
|
|
|
return false;
|
2000-04-21 19:00:23 +04:00
|
|
|
|
1999-09-04 02:05:47 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-07 07:38:52 +03:00
|
|
|
function onAccept()
|
1999-09-04 02:05:47 +04:00
|
|
|
{
|
|
|
|
if (ValidateData())
|
|
|
|
{
|
2002-09-19 07:32:23 +04:00
|
|
|
gActiveEditor.beginTransaction();
|
|
|
|
try {
|
|
|
|
gActiveEditor.cloneAttributes(gTableElement, globalElement);
|
1999-10-14 04:13:27 +04:00
|
|
|
|
|
|
|
// Create necessary rows and cells for the table
|
2002-09-19 07:32:23 +04:00
|
|
|
var tableBody = gActiveEditor.createElementWithDefaults("tbody");
|
|
|
|
if (tableBody)
|
1999-09-04 02:05:47 +04:00
|
|
|
{
|
2002-09-19 07:32:23 +04:00
|
|
|
gTableElement.appendChild(tableBody);
|
|
|
|
|
|
|
|
// Create necessary rows and cells for the table
|
|
|
|
for (var i = 0; i < gRows; i++)
|
1999-09-04 02:05:47 +04:00
|
|
|
{
|
2002-09-19 07:32:23 +04:00
|
|
|
var newRow = gActiveEditor.createElementWithDefaults("tr");
|
|
|
|
if (newRow)
|
1999-09-04 02:05:47 +04:00
|
|
|
{
|
2002-09-19 07:32:23 +04:00
|
|
|
tableBody.appendChild(newRow);
|
|
|
|
for (var j = 0; j < gColumns; j++)
|
1999-10-14 04:13:27 +04:00
|
|
|
{
|
2002-09-19 07:32:23 +04:00
|
|
|
var newCell = gActiveEditor.createElementWithDefaults("td");
|
|
|
|
if (newCell)
|
|
|
|
{
|
|
|
|
newRow.appendChild(newCell);
|
|
|
|
}
|
1999-10-14 04:13:27 +04:00
|
|
|
}
|
1999-09-04 02:05:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-09-19 07:32:23 +04:00
|
|
|
// Detect when entire cells are selected:
|
|
|
|
// Get number of cells selected
|
|
|
|
var tagNameObj = { value: "" };
|
|
|
|
var countObj = { value: 0 };
|
|
|
|
var element = gActiveEditor.getSelectedOrParentTableElement(tagNameObj, countObj);
|
|
|
|
var deletePlaceholder = false;
|
|
|
|
|
|
|
|
if (tagNameObj.value == "table")
|
2000-09-28 02:24:17 +04:00
|
|
|
{
|
2002-09-19 07:32:23 +04:00
|
|
|
//Replace entire selected table with new table, so delete the table
|
|
|
|
gActiveEditor.deleteTable();
|
|
|
|
}
|
|
|
|
else if (tagNameObj.value == "td")
|
|
|
|
{
|
|
|
|
if (countObj.value >= 1)
|
2000-09-28 02:24:17 +04:00
|
|
|
{
|
2002-09-19 07:32:23 +04:00
|
|
|
if (countObj.value > 1)
|
|
|
|
{
|
|
|
|
// Assume user wants to replace a block of
|
|
|
|
// contiguous cells with a table, so
|
|
|
|
// join the selected cells
|
|
|
|
gActiveEditor.joinTableCells(false);
|
2000-09-28 02:24:17 +04:00
|
|
|
|
2002-09-19 07:32:23 +04:00
|
|
|
// Get the cell everything was merged into
|
|
|
|
element = gActiveEditor.getFirstSelectedCell();
|
2000-09-28 02:24:17 +04:00
|
|
|
|
2002-09-19 07:32:23 +04:00
|
|
|
// Collapse selection into just that cell
|
|
|
|
gActiveEditor.selection.collapse(element,0);
|
|
|
|
}
|
2000-09-28 02:24:17 +04:00
|
|
|
|
2002-09-19 07:32:23 +04:00
|
|
|
if (element)
|
|
|
|
{
|
|
|
|
// Empty just the contents of the cell
|
|
|
|
gActiveEditor.deleteTableCellContents();
|
2000-09-28 02:24:17 +04:00
|
|
|
|
2002-09-19 07:32:23 +04:00
|
|
|
// Collapse selection to start of empty cell...
|
|
|
|
gActiveEditor.selection.collapse(element,0);
|
|
|
|
// ...but it will contain a <br> placeholder
|
|
|
|
deletePlaceholder = true;
|
|
|
|
}
|
2000-09-28 02:24:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-11 07:54:20 +03:00
|
|
|
// true means delete selection when inserting
|
2002-09-19 07:32:23 +04:00
|
|
|
gActiveEditor.insertElementAtSelection(gTableElement, true);
|
|
|
|
|
|
|
|
if (deletePlaceholder && gTableElement && gTableElement.nextSibling)
|
|
|
|
{
|
|
|
|
// Delete the placeholder <br>
|
|
|
|
gActiveEditor.deleteNode(gTableElement.nextSibling);
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
2000-09-28 02:24:17 +04:00
|
|
|
|
2002-09-19 07:32:23 +04:00
|
|
|
gActiveEditor.endTransaction();
|
2000-09-28 02:24:17 +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
|
|
|
SaveWindowLocation();
|
1999-09-08 03:55:13 +04:00
|
|
|
return true;
|
1999-07-28 03:59:22 +04:00
|
|
|
}
|
1999-09-08 03:55:13 +04:00
|
|
|
return false;
|
1999-07-05 03:01:10 +04:00
|
|
|
}
|