2
* The contents of this file are subject to the Netscape Public
3
* License Version 1.1 (the "License"); you may not use this file
4
* except in compliance with the License. You may obtain a copy of
5
* the License at http://www.mozilla.org/NPL/
7
* Software distributed under the License is distributed on an "AS
8
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9
* implied. See the License for the specific language governing
10
* rights and limitations under the License.
12
* The Original Code is Mozilla Communicator client code, released
15
* The Initial Developer of the Original Code is Netscape
16
* Communications Corporation. Portions created by Netscape are
17
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
21
* Ben "Count XULula" Goodger
22
* Charles Manske (cmanske@netscape.com)
23
* Neil Rashbrook (neil@parkwaycc.co.uk)
26
/************** GLOBALS **************/
27
var gElement = null; // handle to actual element edited
29
var HTMLAttrs = []; // html attributes
30
var CSSAttrs = []; // css attributes
31
var JSEAttrs = []; // js events
33
var HTMLRAttrs = []; // removed html attributes
34
var JSERAttrs = []; // removed js events
36
/* Set false to allow changing selection in tree
37
without doing "onselect" handler actions
39
var gDoOnSelectTree = true;
40
var gUpdateTreeValue = true;
42
/************** INITIALISATION && SETUP **************/
45
* function : void Startup();
48
* desc. : startup and initialisation, prepares dialog.
52
var editor = GetCurrentEditor();
54
// Element to edit is passed in
55
if (!editor || !window.arguments[1])
57
dump("Advanced Edit: No editor or element to edit not supplied\n");
61
// This is the return value for the parent,
62
// who only needs to know if OK was clicked
63
window.opener.AdvancedEditOK = false;
65
// The actual element edited (not a copy!)
66
gElement = window.arguments[1];
68
// place the tag name in the header
69
var tagLabel = document.getElementById("tagLabel");
70
tagLabel.setAttribute("value", ("<" + gElement.localName + ">"));
72
// Create dialog object to store controls for easy access
73
gDialog.AddHTMLAttributeNameInput = document.getElementById("AddHTMLAttributeNameInput");
75
// We use a <deck> to switch between editable menulist and textbox
76
gDialog.AddHTMLAttributeValueDeck = document.getElementById("AddHTMLAttributeValueDeck");
77
gDialog.AddHTMLAttributeValueMenulist = document.getElementById("AddHTMLAttributeValueMenulist");
78
gDialog.AddHTMLAttributeValueTextbox = document.getElementById("AddHTMLAttributeValueTextbox");
79
gDialog.AddHTMLAttributeValueInput = gDialog.AddHTMLAttributeValueTextbox;
81
gDialog.AddHTMLAttributeTree = document.getElementById("HTMLATree");
82
gDialog.AddCSSAttributeNameInput = document.getElementById("AddCSSAttributeNameInput");
83
gDialog.AddCSSAttributeValueInput = document.getElementById("AddCSSAttributeValueInput");
84
gDialog.AddCSSAttributeTree = document.getElementById("CSSATree");
85
gDialog.AddJSEAttributeNameList = document.getElementById("AddJSEAttributeNameList");
86
gDialog.AddJSEAttributeValueInput = document.getElementById("AddJSEAttributeValueInput");
87
gDialog.AddJSEAttributeTree = document.getElementById("JSEATree");
88
gDialog.okButton = document.documentElement.getButton("accept");
90
// build the attribute trees
91
BuildHTMLAttributeTable();
92
BuildCSSAttributeTable();
93
BuildJSEAttributeTable();
95
// Build attribute name arrays for menulists
96
BuildJSEAttributeNameList();
97
BuildHTMLAttributeNameList();
98
// No menulists for CSS panel (yet)
100
// Set focus to Name editable menulist in HTML panel
101
SetTextboxFocus(gDialog.AddHTMLAttributeNameInput);
103
// size the dialog properly
104
window.sizeToContent();
110
* function : bool onAccept ( void );
112
* returns : boolean true to close the window
113
* desc. : event handler for ok button
117
var editor = GetCurrentEditor();
118
editor.beginTransaction();
120
// Update our gElement attributes
121
UpdateHTMLAttributes();
122
UpdateCSSAttributes();
123
UpdateJSEAttributes();
127
editor.endTransaction();
129
window.opener.AdvancedEditOK = true;
130
SaveWindowLocation();
132
return true; // do close the window
135
// Helpers for removing and setting attributes
136
// Use editor transactions if modifying the element already in the document
137
// (Temporary element from a property dialog won't have a parent node)
138
function doRemoveAttribute(attrib)
141
var editor = GetCurrentEditor();
142
if (gElement.parentNode)
143
editor.removeAttribute(gElement, attrib);
145
gElement.removeAttribute(attrib);
149
function doSetAttribute(attrib, value)
152
var editor = GetCurrentEditor();
153
if (gElement.parentNode)
154
editor.setAttribute(gElement, attrib, value);
156
gElement.setAttribute(attrib, value);
161
* function : bool CheckAttributeNameSimilarity ( string attName, array attArray );
162
* parameters : attribute to look for, array of current attributes
163
* returns : true if attribute already exists, false if it does not
164
* desc. : checks to see if any other attributes by the same name as the arg supplied
167
function CheckAttributeNameSimilarity(attName, attArray)
169
for (var i = 0; i < attArray.length; i++)
171
if (attName.toLowerCase() == attArray[i].toLowerCase())
178
* function : bool UpdateExistingAttribute ( string attName, string attValue, string treeChildrenId );
179
* parameters : attribute to look for, new value, ID of <treeChildren> node in XUL tree
180
* returns : true if attribute already exists in tree, false if it does not
181
* desc. : checks to see if any other attributes by the same name as the arg supplied
182
* already exist while setting the associated value if different from current value
184
function UpdateExistingAttribute( attName, attValue, treeChildrenId )
186
var treeChildren = document.getElementById(treeChildrenId);
192
attName = TrimString(attName).toLowerCase();
193
attValue = TrimString(attValue);
195
for (i = 0; i < treeChildren.childNodes.length; i++)
197
var item = treeChildren.childNodes[i];
198
name = GetTreeItemAttributeStr(item);
199
if (name.toLowerCase() == attName)
201
// Set the text in the "value' column treecell
202
SetTreeItemValueStr(item, attValue);
204
// Select item just changed,
205
// but don't trigger the tree's onSelect handler
206
gDoOnSelectTree = false;
208
selectTreeItem(treeChildren, item);
210
gDoOnSelectTree = true;
219
* function : string GetAndSelectExistingAttributeValue ( string attName, string treeChildrenId );
220
* parameters : attribute to look for, ID of <treeChildren> node in XUL tree
221
* returns : value in from the tree or empty string if name not found
223
function GetAndSelectExistingAttributeValue( attName, treeChildrenId )
228
var treeChildren = document.getElementById(treeChildrenId);
232
for (i = 0; i < treeChildren.childNodes.length; i++)
234
var item = treeChildren.childNodes[i];
235
name = GetTreeItemAttributeStr(item);
236
if (name.toLowerCase() == attName.toLowerCase())
238
// Select item in the tree
239
// but don't trigger the tree's onSelect handler
240
gDoOnSelectTree = false;
242
selectTreeItem(treeChildren, item);
244
gDoOnSelectTree = true;
246
// Get the text in the "value' column treecell
247
return GetTreeItemValueStr(item);
251
// Attribute doesn't exist in tree, so remove selection
252
gDoOnSelectTree = false;
254
treeChildren.parentNode.treeBoxObject.selection.clearSelection();
256
gDoOnSelectTree = true;
264
<treeCell> // Name Cell
265
<treeCell // Value Cell
267
function GetTreeItemAttributeStr(treeItem)
270
return TrimString(treeItem.firstChild.firstChild.getAttribute("label"));
275
function GetTreeItemValueStr(treeItem)
278
return TrimString(treeItem.firstChild.lastChild.getAttribute("label"));
283
function SetTreeItemValueStr(treeItem, value)
285
if (treeItem && GetTreeItemValueStr(treeItem) != value)
286
treeItem.firstChild.lastChild.setAttribute("label", value);
289
function IsNotTreeHeader(treeCell)
292
return (treeCell.parentNode.parentNode.nodeName != "treehead");
297
function RemoveNameFromAttArray(attName, attArray)
299
for (var i=0; i < attArray.length; i++)
301
if (attName.toLowerCase() == attArray[i].toLowerCase())
303
// Remove 1 array item
304
attArray.splice(i,1);
310
// adds a generalised treeitem.
311
function AddTreeItem ( name, value, treeChildrenId, attArray )
313
attArray[attArray.length] = name;
314
var treeChildren = document.getElementById ( treeChildrenId );
315
var treeitem = document.createElementNS ( XUL_NS, "treeitem" );
316
var treerow = document.createElementNS ( XUL_NS, "treerow" );
318
var attrCell = document.createElementNS ( XUL_NS, "treecell" );
319
attrCell.setAttribute( "class", "propertylist" );
320
attrCell.setAttribute( "label", name );
322
var valueCell = document.createElementNS ( XUL_NS, "treecell" );
323
valueCell.setAttribute( "class", "propertylist" );
324
valueCell.setAttribute( "label", value );
326
treerow.appendChild ( attrCell );
327
treerow.appendChild ( valueCell );
328
treeitem.appendChild ( treerow );
329
treeChildren.appendChild ( treeitem );
331
// Select item just added,
332
// but suppress calling the onSelect handler
333
gDoOnSelectTree = false;
335
selectTreeItem(treeChildren, treeitem);
337
gDoOnSelectTree = true;
342
function doHelpButton()
344
openHelp("advanced_property_editor");
348
function selectTreeItem(treeChildren, item)
350
var index = treeChildren.parentNode.contentView.getIndexOfItem(item);
351
treeChildren.parentNode.treeBoxObject.selection.select(index);
354
function getSelectedItem(tree)
356
if (tree.treeBoxObject.selection.count == 1)
357
return tree.contentView.getItemAtIndex(tree.currentIndex);