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-06-12 21:22:12 +00:00
|
|
|
var tagName = "hr";
|
|
|
|
var hLineElement;
|
1999-08-27 04:12:47 +00:00
|
|
|
var width;
|
|
|
|
var height;
|
|
|
|
var align;
|
|
|
|
var shading;
|
1999-06-09 01:27:08 +00:00
|
|
|
|
|
|
|
// dialog initialization code
|
|
|
|
function Startup()
|
|
|
|
{
|
1999-10-14 00:13:27 +00:00
|
|
|
dump("HLine Properties startup...\n");
|
1999-07-14 15:24:33 +00:00
|
|
|
if (!InitEditorShell())
|
1999-06-09 01:27:08 +00:00
|
|
|
return;
|
1999-06-12 22:11:59 +00:00
|
|
|
|
1999-08-25 14:36:13 +00:00
|
|
|
doSetOKCancel(onOK, null);
|
|
|
|
|
1999-06-12 21:22:12 +00:00
|
|
|
// Get the selected horizontal line
|
1999-07-14 15:24:33 +00:00
|
|
|
hLineElement = 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-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");
|
1999-10-14 00:13:27 +00:00
|
|
|
dialog.pixelOrPercentSelect = document.getElementById("pixelOrPercentSelect");
|
1999-06-12 21:22:12 +00:00
|
|
|
|
1999-09-02 01:47:18 +00:00
|
|
|
// Make a copy to use for AdvancedEdit and onSaveDefault
|
|
|
|
globalElement = hLineElement.cloneNode(false);
|
|
|
|
|
1999-06-12 21:22:12 +00:00
|
|
|
// Initialize control values based on existing attributes
|
1999-09-02 01:47:18 +00:00
|
|
|
InitDialog()
|
1999-06-12 21:22:12 +00:00
|
|
|
|
1999-09-02 01:47:18 +00:00
|
|
|
// SET FOCUS TO FIRST CONTROL
|
|
|
|
dialog.heightInput.focus();
|
1999-10-20 14:15:25 +00:00
|
|
|
|
|
|
|
// Resize window
|
|
|
|
window.sizeToContent();
|
1999-09-02 01:47:18 +00:00
|
|
|
}
|
|
|
|
|
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-02 01:47:18 +00:00
|
|
|
function InitDialog()
|
|
|
|
{
|
|
|
|
// Just to be confusing, "size" is used instead of height
|
2000-01-11 21:03:23 +00:00
|
|
|
var height = globalElement.getAttribute("size");
|
|
|
|
if(!height) {
|
|
|
|
dump("NO SIZE FOUND FOR HLINE");
|
|
|
|
height = 2; //Default value
|
|
|
|
}
|
|
|
|
|
1999-09-02 01:47:18 +00:00
|
|
|
// We will use "height" here and in UI
|
2000-01-11 21:03:23 +00:00
|
|
|
dialog.heightInput.value = height;
|
1999-06-15 04:03:22 +00:00
|
|
|
|
1999-07-14 15:24:33 +00:00
|
|
|
// Get the width attribute of the element, stripping out "%"
|
1999-10-14 00:13:27 +00:00
|
|
|
// This sets contents of combobox (adds pixel and percent option elements)
|
|
|
|
dialog.widthInput.value = InitPixelOrPercentCombobox(globalElement,"width","pixelOrPercentSelect");
|
1999-06-12 22:11:59 +00:00
|
|
|
|
1999-09-02 01:47:18 +00:00
|
|
|
align = globalElement.getAttribute("align");
|
1999-06-12 21:22:12 +00:00
|
|
|
if (align == "center") {
|
|
|
|
dialog.centerAlign.checked = true;
|
|
|
|
} else if (align == "right") {
|
|
|
|
dialog.rightAlign.checked = true;
|
|
|
|
} else {
|
|
|
|
dialog.leftAlign.checked = true;
|
|
|
|
}
|
1999-09-02 01:47:18 +00:00
|
|
|
noshade = globalElement.getAttribute("noshade");
|
1999-06-12 21:22:12 +00:00
|
|
|
dialog.shading.checked = (noshade == "");
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSaveDefault()
|
|
|
|
{
|
1999-09-02 01:47:18 +00:00
|
|
|
// "false" means set attributes on the globalElement,
|
1999-06-22 19:12:16 +00:00
|
|
|
// not the real element being edited
|
1999-09-02 01:47:18 +00:00
|
|
|
if (ValidateData()) {
|
2000-02-15 15:54:05 +00:00
|
|
|
var prefs = GetPrefs();
|
1999-08-27 04:12:47 +00:00
|
|
|
if (prefs) {
|
|
|
|
dump("Setting HLine prefs\n");
|
|
|
|
|
|
|
|
var alignInt;
|
|
|
|
if (align == "left") {
|
|
|
|
alignInt = 0;
|
|
|
|
} else if (align == "right") {
|
|
|
|
alignInt = 2;
|
|
|
|
} else {
|
|
|
|
alignInt = 1;
|
|
|
|
}
|
|
|
|
prefs.SetIntPref("editor.hrule.align", alignInt);
|
|
|
|
|
|
|
|
var percentIndex = width.search(/%/);
|
|
|
|
var percent;
|
|
|
|
var widthInt;
|
|
|
|
if (percentIndex > 0) {
|
|
|
|
percent = true;
|
|
|
|
widthInt = Number(width.substr(0, percentIndex));
|
|
|
|
} else {
|
|
|
|
percent = false;
|
|
|
|
widthInt = Number(width);
|
|
|
|
}
|
|
|
|
prefs.SetIntPref("editor.hrule.width", widthInt);
|
|
|
|
prefs.SetBoolPref("editor.hrule.width_percent", percent);
|
|
|
|
|
|
|
|
// Convert string to number
|
|
|
|
prefs.SetIntPref("editor.hrule.height", Number(height));
|
|
|
|
|
|
|
|
prefs.SetBoolPref("editor.hrule.shading", shading);
|
|
|
|
|
|
|
|
// Write the prefs out NOW!
|
|
|
|
prefs.SavePrefFile();
|
2000-02-15 15:54:05 +00:00
|
|
|
}
|
|
|
|
}
|
1999-06-12 21:22:12 +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()
|
1999-09-02 01:47:18 +00:00
|
|
|
function ValidateData()
|
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
|
1999-07-14 15:24:33 +00:00
|
|
|
dump("Height is empty\n");
|
1999-06-12 21:22:12 +00:00
|
|
|
dialog.heightInput.focus();
|
|
|
|
return false;
|
|
|
|
}
|
1999-06-15 04:03:22 +00:00
|
|
|
dump("Setting height="+height+"\n");
|
1999-09-02 01:47:18 +00:00
|
|
|
globalElement.setAttribute("size", height);
|
1999-06-12 21:22:12 +00:00
|
|
|
|
1999-11-03 00:48:26 +00:00
|
|
|
var isPercent = (dialog.pixelOrPercentSelect.selectedIndex == 1);
|
1999-06-12 21:22:12 +00:00
|
|
|
var maxLimit;
|
1999-10-14 00:13:27 +00:00
|
|
|
if (isPercent) {
|
1999-06-12 21:22:12 +00:00
|
|
|
maxLimit = 100;
|
|
|
|
} else {
|
|
|
|
// Upper limit when using pixels
|
|
|
|
maxLimit = maxPixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
width = ValidateNumberString(dialog.widthInput.value, 1, maxLimit);
|
|
|
|
if (width == "") {
|
1999-07-14 15:24:33 +00:00
|
|
|
dump("Width is empty\n");
|
1999-06-12 21:22:12 +00:00
|
|
|
dialog.widthInput.focus();
|
|
|
|
return false;
|
|
|
|
}
|
1999-10-14 00:13:27 +00:00
|
|
|
if (isPercent)
|
|
|
|
width = width + "%";
|
|
|
|
|
1999-06-12 21:22:12 +00:00
|
|
|
dump("Height="+height+" Width="+width+"\n");
|
1999-09-02 01:47:18 +00:00
|
|
|
globalElement.setAttribute("width", width);
|
1999-06-22 19:12:16 +00:00
|
|
|
|
1999-06-12 21:22:12 +00:00
|
|
|
align = "left";
|
|
|
|
if (dialog.centerAlign.checked) {
|
|
|
|
align = "center";
|
|
|
|
} else if (dialog.rightAlign.checked) {
|
|
|
|
align = "right";
|
|
|
|
}
|
1999-09-02 01:47:18 +00:00
|
|
|
globalElement.setAttribute("align", align);
|
1999-06-12 21:22:12 +00:00
|
|
|
|
|
|
|
if (dialog.shading.checked) {
|
1999-08-27 04:12:47 +00:00
|
|
|
shading = true;
|
1999-09-02 01:47:18 +00:00
|
|
|
globalElement.removeAttribute("noshade");
|
1999-06-12 21:22:12 +00:00
|
|
|
} else {
|
1999-08-27 04:12:47 +00:00
|
|
|
shading = false;
|
1999-09-02 01:47:18 +00:00
|
|
|
globalElement.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-09-21 01:36:30 +00:00
|
|
|
if (ValidateData())
|
|
|
|
{
|
|
|
|
// Copy attributes from the globalElement to the document element
|
1999-09-02 01:47:18 +00:00
|
|
|
editorShell.CloneAttributes(hLineElement, globalElement);
|
1999-09-21 01:36:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
1999-06-09 01:27:08 +00:00
|
|
|
}
|