!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 * Ben "Count XULula" Goodger
24 * Daniel Glazman <glazman@netscape.com>
25 * Charles Manske (cmanske@netscape.com)
26 * Neil Rashbrook <neil@parkwaycc.co.uk>
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * either of the GNU General Public License Version 2 or later (the "GPL"),
30 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
39 *
40 * ***** END LICENSE BLOCK ***** */
41
42 // build attribute list in tree form from element attributes
BuildCSSAttributeTable
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
43 function BuildCSSAttributeTable()
44 {
45 var style = gElement.style;
46 if (style == undefined)
47 {
48 dump("Inline styles undefined\n");
49 return;
50 }
51
52 var declLength = style.length;
53
54 if (declLength == undefined || declLength == 0)
55 {
56 if (declLength == undefined) {
57 dump("Failed to query the number of inline style declarations\n");
58 }
59
60 return;
61 }
62
63 if (declLength > 0)
64 {
65 for (var i = 0; i < declLength; ++i)
66 {
67 var name = style.item(i);
68 var value = style.getPropertyValue(name);
69 AddTreeItem( name, value, "CSSAList", CSSAttrs );
70 }
71 }
72
73 ClearCSSInputWidgets();
74 }
75
onChangeCSSAttribute
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
76 function onChangeCSSAttribute()
77 {
78 var name = TrimString(gDialog.AddCSSAttributeNameInput.value);
79 if ( !name )
80 return;
81
82 var value = TrimString(gDialog.AddCSSAttributeValueInput.value);
83
84 // First try to update existing attribute
85 // If not found, add new attribute
86 if ( !UpdateExistingAttribute( name, value, "CSSAList" ) && value)
87 AddTreeItem( name, value, "CSSAList", CSSAttrs );
88 }
89
ClearCSSInputWidgets
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
90 function ClearCSSInputWidgets()
91 {
92 gDialog.AddCSSAttributeTree.view.selection.clearSelection();
93 gDialog.AddCSSAttributeNameInput.value ="";
94 gDialog.AddCSSAttributeValueInput.value = "";
95 SetTextboxFocus(gDialog.AddCSSAttributeNameInput);
96 }
97
onSelectCSSTreeItem
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
98 function onSelectCSSTreeItem()
99 {
100 if (!gDoOnSelectTree)
101 return;
102
103 var tree = gDialog.AddCSSAttributeTree;
104 if (tree && tree.view.selection.count)
105 {
106 gDialog.AddCSSAttributeNameInput.value = GetTreeItemAttributeStr(getSelectedItem(tree));
107 gDialog.AddCSSAttributeValueInput.value = GetTreeItemValueStr(getSelectedItem(tree));
108 }
109 }
110
onInputCSSAttributeName
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
111 function onInputCSSAttributeName()
112 {
113 var attName = TrimString(gDialog.AddCSSAttributeNameInput.value).toLowerCase();
114 var newValue = "";
115
116 var existingValue = GetAndSelectExistingAttributeValue(attName, "CSSAList");
117 if (existingValue)
118 newValue = existingValue;
119
120 gDialog.AddCSSAttributeValueInput.value = newValue;
121 }
122
editCSSAttributeValue
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
123 function editCSSAttributeValue(targetCell)
124 {
125 if (IsNotTreeHeader(targetCell))
126 gDialog.AddCSSAttributeValueInput.inputField.select();
127 }
128
UpdateCSSAttributes
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
129 function UpdateCSSAttributes()
130 {
131 var CSSAList = document.getElementById("CSSAList");
132 var styleString = "";
133 for(var i = 0; i < CSSAList.childNodes.length; i++)
134 {
135 var item = CSSAList.childNodes[i];
136 var name = GetTreeItemAttributeStr(item);
137 var value = GetTreeItemValueStr(item);
138 // this code allows users to be sloppy in typing in values, and enter
139 // things like "foo: " and "bar;". This will trim off everything after the
140 // respective character.
141 if (name.indexOf(":") != -1)
142 name = name.substring(0,name.lastIndexOf(":"));
143 if (value.indexOf(";") != -1)
144 value = value.substring(0,value.lastIndexOf(";"));
145 if (i == (CSSAList.childNodes.length - 1))
146 styleString += name + ": " + value + ";"; // last property
147 else
148 styleString += name + ": " + value + "; ";
149 }
150 if (styleString)
151 {
152 // Use editor transactions if modifying the element directly in the document
153 doRemoveAttribute("style");
154 doSetAttribute("style", styleString); // NOTE BUG 18894!!!
155 }
156 else if (gElement.getAttribute("style"))
157 doRemoveAttribute("style");
158 }
159
RemoveCSSAttribute
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
160 function RemoveCSSAttribute()
161 {
162 var treechildren = gDialog.AddCSSAttributeTree.lastChild;
163
164 // We only allow 1 selected item
165 if (gDialog.AddCSSAttributeTree.view.selection.count)
166 {
167 var item = getSelectedItem(gDialog.AddCSSAttributeTree);
168
169 // Remove the item from the tree
170 // We always rebuild complete "style" string,
171 // so no list of "removed" items
172 treechildren.removeChild (item);
173
174 ClearCSSInputWidgets();
175 }
176 }
177
SelectCSSTree
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
178 function SelectCSSTree( index )
179 {
180 gDoOnSelectTree = false;
181 try {
182 gDialog.AddCSSAttributeTree.selectedIndex = index;
183 } catch (e) {}
184 gDoOnSelectTree = true;
185 }