1999-06-11 18:58:32 +00:00
|
|
|
var editorShell;
|
1999-06-09 01:27:08 +00:00
|
|
|
var toolkitCore;
|
1999-06-12 21:22:12 +00:00
|
|
|
var tagName = "hr";
|
|
|
|
var hLineElement;
|
1999-06-22 19:12:16 +00:00
|
|
|
var tempLineElement;
|
1999-06-12 21:22:12 +00:00
|
|
|
var percentChar = "";
|
|
|
|
var maxPixels = 10000;
|
|
|
|
var shading = true;
|
1999-06-09 01:27:08 +00:00
|
|
|
|
|
|
|
// dialog initialization code
|
|
|
|
function Startup()
|
|
|
|
{
|
1999-06-11 18:58:32 +00:00
|
|
|
// get the editor shell from the parent window
|
|
|
|
editorShell = window.opener.editorShell;
|
|
|
|
editorShell = editorShell.QueryInterface(Components.interfaces.nsIEditorShell);
|
|
|
|
if(!editorShell) {
|
1999-06-12 21:22:12 +00:00
|
|
|
dump("editorShell not found!!!\n");
|
1999-06-09 01:27:08 +00:00
|
|
|
window.close();
|
|
|
|
return;
|
|
|
|
}
|
1999-06-12 22:11:59 +00:00
|
|
|
|
1999-06-12 21:22:12 +00:00
|
|
|
// Get the selected horizontal line
|
|
|
|
hLineElement = window.editorShell.GetSelectedElement(tagName);
|
1999-06-11 18:58:32 +00:00
|
|
|
|
1999-06-12 21:22:12 +00:00
|
|
|
if (!hLineElement) {
|
|
|
|
// We should never be here if not editing an existing HLine
|
|
|
|
dump("HLine is not selected! Shouldn't be here!\n");
|
|
|
|
window.close();
|
|
|
|
return;
|
|
|
|
}
|
1999-06-22 19:12:16 +00:00
|
|
|
// Create a temporary element to use with Save Settings as default
|
|
|
|
tempLineElement = window.editorShell.editorDocument.createElement("HR");
|
|
|
|
if (!hLineElement) {
|
|
|
|
dump("Temporary HLine element was not created!\n");
|
|
|
|
window.close();
|
|
|
|
return;
|
|
|
|
}
|
1999-06-09 01:27:08 +00:00
|
|
|
|
|
|
|
// Create dialog object to store controls for easy access
|
|
|
|
dialog = new Object;
|
1999-06-12 21:22:12 +00:00
|
|
|
dialog.heightInput = document.getElementById("height");
|
|
|
|
dialog.widthInput = document.getElementById("width");
|
|
|
|
dialog.leftAlign = document.getElementById("leftAlign");
|
|
|
|
dialog.centerAlign = document.getElementById("centerAlign");
|
|
|
|
dialog.rightAlign = document.getElementById("rightAlign");
|
|
|
|
dialog.shading = document.getElementById("3dShading");
|
|
|
|
dialog.pixelOrPercentButton = document.getElementById("pixelOrPercentButton");
|
|
|
|
|
|
|
|
// Initialize control values based on existing attributes
|
|
|
|
|
1999-06-29 21:17:04 +00:00
|
|
|
// Just to be confusing, "size" is used instead of height
|
|
|
|
// We will use "height" here and in UI
|
|
|
|
dialog.heightInput.value = hLineElement.getAttribute("size");
|
1999-06-12 21:22:12 +00:00
|
|
|
width = hLineElement.getAttribute("width");
|
1999-06-12 22:11:59 +00:00
|
|
|
|
1999-06-15 04:03:22 +00:00
|
|
|
// This assumes initial button text is "percent"
|
1999-06-12 22:35:39 +00:00
|
|
|
// Search for a "%" character
|
|
|
|
percentIndex = width.search(/%/);
|
|
|
|
if (percentIndex > 0) {
|
1999-06-12 21:22:12 +00:00
|
|
|
percentChar = "%";
|
1999-06-12 22:35:39 +00:00
|
|
|
// Strip out the %
|
|
|
|
width = width.substr(0, percentIndex);
|
1999-06-15 04:03:22 +00:00
|
|
|
} else {
|
|
|
|
dialog.pixelOrPercentButton.setAttribute("value","pixels");
|
1999-06-12 21:22:12 +00:00
|
|
|
}
|
1999-06-15 04:03:22 +00:00
|
|
|
|
1999-06-12 22:35:39 +00:00
|
|
|
dialog.widthInput.value = width;
|
1999-06-12 22:11:59 +00:00
|
|
|
|
1999-06-12 21:22:12 +00:00
|
|
|
align = hLineElement.getAttribute("align");
|
|
|
|
if (align == "center") {
|
|
|
|
dialog.centerAlign.checked = true;
|
|
|
|
} else if (align == "right") {
|
|
|
|
dialog.rightAlign.checked = true;
|
|
|
|
} else {
|
|
|
|
dialog.leftAlign.checked = true;
|
|
|
|
}
|
|
|
|
noshade = hLineElement.getAttribute("noshade");
|
|
|
|
dialog.shading.checked = (noshade == "");
|
1999-06-09 01:27:08 +00:00
|
|
|
|
|
|
|
// SET FOCUS TO FIRST CONTROL
|
1999-06-12 21:22:12 +00:00
|
|
|
dialog.heightInput.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Input string is "" for pixel, or "%" for percent
|
|
|
|
function SetPixelOrPercent(percentString)
|
|
|
|
{
|
|
|
|
percentChar = percentString;
|
|
|
|
dump("SetPixelOrPercent. PercentChar="+percentChar+"\n");
|
|
|
|
|
|
|
|
if (percentChar == "%") {
|
1999-06-15 04:03:22 +00:00
|
|
|
dialog.pixelOrPercentButton.setAttribute("value","percent");
|
1999-06-12 21:22:12 +00:00
|
|
|
dump("TODO: Set button text to PERCENT\n");
|
|
|
|
} else {
|
1999-06-15 04:03:22 +00:00
|
|
|
dialog.pixelOrPercentButton.setAttribute("value","pixels");
|
1999-06-12 21:22:12 +00:00
|
|
|
dump("TODO: Set button text to PIXELS\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSaveDefault()
|
|
|
|
{
|
1999-06-22 19:12:16 +00:00
|
|
|
// "false" means set attributes on the tempLineElement,
|
|
|
|
// not the real element being edited
|
|
|
|
if (ValidateData(false)) {
|
|
|
|
editorShell.SaveHLineSettings(tempLineElement);
|
1999-06-12 21:22:12 +00:00
|
|
|
dump("Saving HLine settings to preferences\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onAdvanced()
|
|
|
|
{
|
|
|
|
//TODO: Call the generic attribute editor ("extra HTML")
|
|
|
|
}
|
|
|
|
|
1999-06-22 19:12:16 +00:00
|
|
|
function ValidateData(setAttributes)
|
1999-06-12 21:22:12 +00:00
|
|
|
{
|
|
|
|
// Height is always pixels
|
|
|
|
height = ValidateNumberString(dialog.heightInput.value, 1, maxPixels);
|
|
|
|
if (height == "") {
|
|
|
|
// Set focus to the offending control
|
|
|
|
dialog.heightInput.focus();
|
|
|
|
return false;
|
|
|
|
}
|
1999-06-15 04:03:22 +00:00
|
|
|
dump("Setting height="+height+"\n");
|
1999-06-22 19:12:16 +00:00
|
|
|
if (setAttributes) {
|
1999-06-29 21:17:04 +00:00
|
|
|
hLineElement.setAttribute("size", height);
|
1999-06-22 19:12:16 +00:00
|
|
|
} else {
|
1999-06-29 21:17:04 +00:00
|
|
|
hLineElement.setAttribute("size", height);
|
1999-06-22 19:12:16 +00:00
|
|
|
}
|
1999-06-12 21:22:12 +00:00
|
|
|
|
|
|
|
var maxLimit;
|
|
|
|
dump("Validate width. PercentChar="+percentChar+"\n");
|
|
|
|
if (percentChar == "%") {
|
|
|
|
maxLimit = 100;
|
|
|
|
} else {
|
|
|
|
// Upper limit when using pixels
|
|
|
|
maxLimit = maxPixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
width = ValidateNumberString(dialog.widthInput.value, 1, maxLimit);
|
|
|
|
if (width == "") {
|
|
|
|
dialog.widthInput.focus();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
width = width + percentChar;
|
|
|
|
dump("Height="+height+" Width="+width+"\n");
|
1999-06-22 19:12:16 +00:00
|
|
|
if (setAttributes) {
|
|
|
|
hLineElement.setAttribute("width", width);
|
|
|
|
} else {
|
|
|
|
tempLineElement.setAttribute("width", width);
|
|
|
|
}
|
|
|
|
|
1999-06-12 21:22:12 +00:00
|
|
|
|
|
|
|
align = "left";
|
|
|
|
if (dialog.centerAlign.checked) {
|
|
|
|
align = "center";
|
|
|
|
} else if (dialog.rightAlign.checked) {
|
|
|
|
align = "right";
|
|
|
|
}
|
1999-06-22 19:12:16 +00:00
|
|
|
if (setAttributes) {
|
|
|
|
hLineElement.setAttribute("align", align);
|
|
|
|
} else {
|
|
|
|
tempLineElement.setAttribute("align", align);
|
|
|
|
}
|
1999-06-12 21:22:12 +00:00
|
|
|
|
|
|
|
if (dialog.shading.checked) {
|
1999-06-22 19:12:16 +00:00
|
|
|
if (setAttributes) {
|
|
|
|
hLineElement.removeAttribute("noshade");
|
|
|
|
} else {
|
|
|
|
tempLineElement.removeAttribute("noshade");
|
|
|
|
}
|
1999-06-12 21:22:12 +00:00
|
|
|
} else {
|
1999-06-22 19:12:16 +00:00
|
|
|
if (setAttributes) {
|
|
|
|
hLineElement.setAttribute("noshade", "");
|
|
|
|
} else {
|
|
|
|
tempLineElement.setAttribute("noshade", "");
|
|
|
|
}
|
1999-06-12 21:22:12 +00:00
|
|
|
}
|
|
|
|
return true;
|
1999-06-09 01:27:08 +00:00
|
|
|
}
|
|
|
|
|
1999-06-15 04:03:22 +00:00
|
|
|
function onOK()
|
1999-06-09 01:27:08 +00:00
|
|
|
{
|
1999-06-15 04:03:22 +00:00
|
|
|
// Since we only edit existing HLines,
|
|
|
|
// ValidateData will set the new attributes
|
|
|
|
// so there's nothing else to do
|
1999-06-22 19:12:16 +00:00
|
|
|
if (ValidateData(true)) {
|
1999-06-12 21:22:12 +00:00
|
|
|
window.close();
|
1999-06-12 22:11:59 +00:00
|
|
|
dump("CLOSING EdHLineProps\n");
|
1999-06-12 21:22:12 +00:00
|
|
|
}
|
1999-06-09 01:27:08 +00:00
|
|
|
}
|