1999-08-19 14:28:44 +00:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*/
|
|
|
|
|
1999-07-04 23:01:10 +00:00
|
|
|
//Cancel() is in EdDialogCommon.js
|
|
|
|
var tagName = "table"
|
|
|
|
var tableElement = null;
|
|
|
|
var rowElement = null;
|
|
|
|
var cellElement = null;
|
|
|
|
var maxRows = 10000;
|
|
|
|
var maxColumns = 10000;
|
1999-07-14 15:24:33 +00:00
|
|
|
var maxPixels = 10000;
|
1999-09-03 22:05:47 +00:00
|
|
|
var rows;
|
|
|
|
var columns;
|
1999-07-04 23:01:10 +00:00
|
|
|
|
|
|
|
// dialog initialization code
|
|
|
|
function Startup()
|
|
|
|
{
|
1999-07-14 15:24:33 +00:00
|
|
|
if (!InitEditorShell())
|
1999-07-04 23:01:10 +00:00
|
|
|
return;
|
1999-08-25 14:36:13 +00:00
|
|
|
|
|
|
|
doSetOKCancel(onOK, null);
|
1999-07-04 23:01:10 +00:00
|
|
|
|
1999-07-27 23:59:22 +00:00
|
|
|
dump(tagName+" = InsertTable tagName\n");
|
1999-07-14 15:24:33 +00:00
|
|
|
tableElement = editorShell.CreateElementWithDefaults(tagName);
|
|
|
|
if(!tableElement)
|
|
|
|
{
|
|
|
|
dump("Failed to create a new table!\n");
|
|
|
|
window.close();
|
|
|
|
}
|
1999-10-14 00:13:27 +00:00
|
|
|
dump("Rows editbox:"+document.getElementById("rows")+"\n");
|
|
|
|
dump("Columns editbox:"+document.getElementById("columns")+"\n");
|
|
|
|
dump("width editbox:"+document.getElementById("width")+"\n");
|
|
|
|
dump("pixelOrPercentSelect:"+document.getElementById("pixelOrPercentSelect")+"\n");
|
|
|
|
dump("borderInput editbox:"+document.getElementById("borderInput")+"\n");
|
1999-07-14 15:24:33 +00:00
|
|
|
|
1999-07-04 23:01:10 +00:00
|
|
|
// Create dialog object to store controls for easy access
|
|
|
|
dialog = new Object;
|
|
|
|
dialog.rowsInput = document.getElementById("rows");
|
|
|
|
dialog.columnsInput = document.getElementById("columns");
|
1999-07-14 15:24:33 +00:00
|
|
|
dialog.widthInput = document.getElementById("width");
|
1999-10-14 00:13:27 +00:00
|
|
|
dialog.borderInput = document.getElementById("borderInput");
|
|
|
|
dialog.pixelOrPercentSelect = document.getElementById("pixelOrPercentSelect");
|
1999-07-14 15:24:33 +00:00
|
|
|
|
1999-09-03 22:05:47 +00:00
|
|
|
// Make a copy to use for AdvancedEdit
|
|
|
|
globalElement = tableElement.cloneNode(false);
|
|
|
|
|
|
|
|
// Initialize all widgets with image attributes
|
|
|
|
InitDialog();
|
|
|
|
|
1999-09-29 21:45:50 +00:00
|
|
|
// Set initial number to 1 row, 2 columns:
|
|
|
|
// 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
|
|
|
|
dialog.rowsInput.value = 1;
|
|
|
|
dialog.columnsInput.value = 2;
|
|
|
|
|
1999-09-03 22:05:47 +00:00
|
|
|
dialog.rowsInput.focus();
|
1999-10-20 14:15:25 +00:00
|
|
|
|
|
|
|
// Resize window
|
|
|
|
window.sizeToContent();
|
1999-09-03 22:05:47 +00: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-29 21:45:50 +00:00
|
|
|
function InitDialog()
|
1999-09-03 22:05:47 +00:00
|
|
|
{
|
1999-07-14 15:24:33 +00:00
|
|
|
// Get default attributes set on the created table:
|
|
|
|
// Get the width attribute of the element, stripping out "%"
|
1999-10-14 00:13:27 +00:00
|
|
|
// This sets contents of select combobox list
|
|
|
|
dialog.widthInput.value = InitPixelOrPercentCombobox(globalElement,"width","pixelOrPercentSelect");
|
1999-09-03 22:05:47 +00:00
|
|
|
dialog.borderInput.value = globalElement.getAttribute("border");
|
1999-07-04 23:01:10 +00:00
|
|
|
}
|
|
|
|
|
1999-09-03 22:05:47 +00:00
|
|
|
// Get and validate data from widgets.
|
|
|
|
// Set attributes on globalElement so they can be accessed by AdvancedEdit()
|
|
|
|
function ValidateData()
|
1999-07-04 23:01:10 +00:00
|
|
|
{
|
|
|
|
rows = ValidateNumberString(dialog.rowsInput.value, 1, maxRows);
|
|
|
|
if (rows == "") {
|
|
|
|
// Set focus to the offending control
|
|
|
|
dialog.rowsInput.focus();
|
1999-08-25 14:36:13 +00:00
|
|
|
return false;
|
1999-07-04 23:01:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
columns = ValidateNumberString(dialog.columnsInput.value, 1, maxColumns);
|
|
|
|
if (columns == "") {
|
|
|
|
// Set focus to the offending control
|
|
|
|
dialog.columnsInput.focus();
|
1999-08-25 14:36:13 +00:00
|
|
|
return false;
|
1999-07-04 23:01:10 +00:00
|
|
|
}
|
1999-09-03 22:05:47 +00:00
|
|
|
|
1999-10-14 00:13:27 +00:00
|
|
|
// Set attributes: NOTE: These may be empty strings
|
1999-07-27 23:59:22 +00:00
|
|
|
borderText = TrimString(dialog.borderInput.value);
|
1999-09-16 04:36:16 +00:00
|
|
|
if (borderText) {
|
1999-07-27 23:59:22 +00:00
|
|
|
// Set the other attributes on the table
|
|
|
|
if (ValidateNumberString(borderText, 0, maxPixels))
|
1999-09-03 22:05:47 +00:00
|
|
|
globalElement.setAttribute("border", borderText);
|
1999-07-27 23:59:22 +00:00
|
|
|
}
|
|
|
|
|
1999-10-14 00:13:27 +00:00
|
|
|
var isPercent = (dialog.pixelOrPercentSelect.selectedIndex == 1);
|
1999-07-27 23:59:22 +00:00
|
|
|
widthText = TrimString(dialog.widthInput.value);
|
1999-09-16 04:36:16 +00:00
|
|
|
if (widthText) {
|
1999-07-27 23:59:22 +00:00
|
|
|
var maxLimit;
|
1999-10-14 00:13:27 +00:00
|
|
|
if (isPercent) {
|
1999-07-27 23:59:22 +00:00
|
|
|
maxLimit = 100;
|
|
|
|
} else {
|
|
|
|
// Upper limit when using pixels
|
|
|
|
maxLimit = maxPixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
widthText = ValidateNumberString(dialog.widthInput.value, 1, maxLimit);
|
1999-10-14 00:13:27 +00:00
|
|
|
if (widthText) {
|
|
|
|
if (isPercent)
|
|
|
|
widthText += "%";
|
1999-09-03 22:05:47 +00:00
|
|
|
globalElement.setAttribute("width", widthText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onOK()
|
|
|
|
{
|
|
|
|
if (ValidateData())
|
|
|
|
{
|
|
|
|
editorShell.CloneAttributes(tableElement, globalElement);
|
|
|
|
|
1999-10-14 00:13:27 +00:00
|
|
|
var tableBody = editorShell.CreateElementWithDefaults("tbody");
|
|
|
|
if (tableBody)
|
1999-09-03 22:05:47 +00:00
|
|
|
{
|
1999-10-14 00:13:27 +00:00
|
|
|
tableElement.appendChild(tableBody);
|
|
|
|
|
|
|
|
// Create necessary rows and cells for the table
|
|
|
|
dump("Rows = "+rows+" Columns = "+columns+"\n");
|
2000-02-15 15:54:05 +00:00
|
|
|
for (var i = 0; i < rows; i++)
|
1999-09-03 22:05:47 +00:00
|
|
|
{
|
1999-10-14 00:13:27 +00:00
|
|
|
var newRow = editorShell.CreateElementWithDefaults("tr");
|
|
|
|
if (newRow)
|
1999-09-03 22:05:47 +00:00
|
|
|
{
|
1999-10-14 00:13:27 +00:00
|
|
|
tableBody.appendChild(newRow);
|
2000-02-15 15:54:05 +00:00
|
|
|
for (var j = 0; j < columns; j++)
|
1999-09-03 22:05:47 +00:00
|
|
|
{
|
1999-10-14 00:13:27 +00:00
|
|
|
newCell = editorShell.CreateElementWithDefaults("td");
|
|
|
|
if (newCell)
|
|
|
|
{
|
|
|
|
newRow.appendChild(newCell);
|
|
|
|
}
|
1999-09-03 22:05:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-07-27 23:59:22 +00:00
|
|
|
}
|
1999-10-14 00:13:27 +00:00
|
|
|
try {
|
|
|
|
// Don't delete selected text when inserting
|
|
|
|
editorShell.InsertElementAtSelection(tableElement, false);
|
|
|
|
} catch (e) {
|
|
|
|
dump("Exception occured in InsertElementAtSelection\n");
|
|
|
|
}
|
1999-09-07 23:55:13 +00:00
|
|
|
return true;
|
1999-07-27 23:59:22 +00:00
|
|
|
}
|
1999-09-07 23:55:13 +00:00
|
|
|
return false;
|
1999-07-04 23:01:10 +00:00
|
|
|
}
|