!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is Mozilla Communicator client code, released
15 * March 31, 1998.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-1999
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38 var tagName = "hr";
39 var gHLineElement;
40 var width;
41 var height;
42 var align;
43 var shading;
44 const gMaxHRSize = 1000; // This is hard-coded in nsHTMLHRElement::StringToAttribute()
45
46 // dialog initialization code
Startup
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
47 function Startup()
48 {
49 var editor = GetCurrentEditor();
50 if (!editor)
51 {
52 window.close();
53 return;
54 }
55 try {
56 // Get the selected horizontal line
57 gHLineElement = editor.getSelectedElement(tagName);
58 } catch (e) {}
59
60 if (!gHLineElement) {
61 // We should never be here if not editing an existing HLine
62 window.close();
63 return;
64 }
65 gDialog.heightInput = document.getElementById("height");
66 gDialog.widthInput = document.getElementById("width");
67 gDialog.leftAlign = document.getElementById("leftAlign");
68 gDialog.centerAlign = document.getElementById("centerAlign");
69 gDialog.rightAlign = document.getElementById("rightAlign");
70 gDialog.alignGroup = gDialog.rightAlign.radioGroup;
71 gDialog.shading = document.getElementById("3dShading");
72 gDialog.pixelOrPercentMenulist = document.getElementById("pixelOrPercentMenulist");
73
74 // Make a copy to use for AdvancedEdit and onSaveDefault
75 globalElement = gHLineElement.cloneNode(false);
76
77 // Initialize control values based on existing attributes
78 InitDialog()
79
80 // SET FOCUS TO FIRST CONTROL
81 SetTextboxFocus(gDialog.widthInput);
82
83 // Resize window
84 window.sizeToContent();
85
86 SetWindowLocation();
87 }
88
89 // Set dialog widgets with attribute data
90 // We get them from globalElement copy so this can be used
91 // by AdvancedEdit(), which is shared by all property dialogs
InitDialog
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
92 function InitDialog()
93 {
94 // Just to be confusing, "size" is used instead of height because it does
95 // not accept % values, only pixels
96 var height = GetHTMLOrCSSStyleValue(globalElement, "size", "height")
97 if (/px/.test(height)) {
98 height = RegExp.leftContext;
99 }
100 if(!height) {
101 height = 2; //Default value
102 }
103
104 // We will use "height" here and in UI
105 gDialog.heightInput.value = height;
106
107 // Get the width attribute of the element, stripping out "%"
108 // This sets contents of menulist (adds pixel and percent menuitems elements)
109 gDialog.widthInput.value = InitPixelOrPercentMenulist(globalElement, gHLineElement, "width","pixelOrPercentMenulist");
110
111 var marginLeft = GetHTMLOrCSSStyleValue(globalElement, "align", "margin-left").toLowerCase();
112 var marginRight = GetHTMLOrCSSStyleValue(globalElement, "align", "margin-right").toLowerCase();
113 align = marginLeft + " " + marginRight;
114 gDialog.leftAlign.checked = (align == "left left" || align == "0px auto");
115 gDialog.centerAlign.checked = (align == "center center" || align == "auto auto" || align == " ");
116 gDialog.rightAlign.checked = (align == "right right" || align == "auto 0px");
117
118 if (gDialog.centerAlign.checked) {
119 gDialog.alignGroup.selectedItem = gDialog.centerAlign;
120 }
121 else if (gDialog.rightAlign.checked) {
122 gDialog.alignGroup.selectedItem = gDialog.rightAlign;
123 }
124 else {
125 gDialog.alignGroup.selectedItem = gDialog.leftAlign;
126 }
127
128 gDialog.shading.checked = !globalElement.hasAttribute("noshade");
129 }
130
onSaveDefault
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
131 function onSaveDefault()
132 {
133 // "false" means set attributes on the globalElement,
134 // not the real element being edited
135 if (ValidateData()) {
136 var prefs = GetPrefs();
137 if (prefs) {
138
139 var alignInt;
140 if (align == "left") {
141 alignInt = 0;
142 } else if (align == "right") {
143 alignInt = 2;
144 } else {
145 alignInt = 1;
146 }
147 prefs.setIntPref("editor.hrule.align", alignInt);
148
149 var percent;
150 var widthInt;
151 var heightInt;
152
153 if (width)
154 {
155 if (/%/.test(width)) {
156 percent = true;
157 widthInt = Number(RegExp.leftContext);
158 } else {
159 percent = false;
160 widthInt = Number(width);
161 }
162 }
163 else
164 {
165 percent = true;
166 widthInt = Number(100);
167 }
168
169 heightInt = height ? Number(height) : 2;
170
171 prefs.setIntPref("editor.hrule.width", widthInt);
172 prefs.setBoolPref("editor.hrule.width_percent", percent);
173 prefs.setIntPref("editor.hrule.height", heightInt);
174 prefs.setBoolPref("editor.hrule.shading", shading);
175
176 // Write the prefs out NOW!
177 var prefService = Components.classes["@mozilla.org/preferences-service;1"]
178 .getService(Components.interfaces.nsIPrefService);
179 prefService.savePrefFile(null);
180 }
181 }
182 }
183
184 // Get and validate data from widgets.
185 // Set attributes on globalElement so they can be accessed by AdvancedEdit()
ValidateData
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
186 function ValidateData()
187 {
188 // Height is always pixels
189 height = ValidateNumber(gDialog.heightInput, null, 1, gMaxHRSize,
190 globalElement, "size", false);
191 if (gValidationError)
192 return false;
193
194 width = ValidateNumber(gDialog.widthInput, gDialog.pixelOrPercentMenulist, 1, gMaxPixels,
195 globalElement, "width", false);
196 if (gValidationError)
197 return false;
198
199 align = "left";
200 if (gDialog.centerAlign.selected) {
201 // Don't write out default attribute
202 align = "";
203 } else if (gDialog.rightAlign.selected) {
204 align = "right";
205 }
206 if (align)
207 globalElement.setAttribute("align", align);
208 else
209 try {
210 GetCurrentEditor().removeAttributeOrEquivalent(globalElement, "align", true);
211 } catch (e) {}
212
213 if (gDialog.shading.checked) {
214 shading = true;
215 globalElement.removeAttribute("noshade");
216 } else {
217 shading = false;
218 globalElement.setAttribute("noshade", "noshade");
219 }
220 return true;
221 }
222
onAccept
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
223 function onAccept()
224 {
225 if (ValidateData())
226 {
227 // Copy attributes from the globalElement to the document element
228 try {
229 GetCurrentEditor().cloneAttributes(gHLineElement, globalElement);
230 } catch (e) {}
231 return true;
232 }
233 return false;
234 }