2001-09-20 04:02:59 +04:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
2001-06-13 05:04:39 +04:00
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
2001-09-20 04:02:59 +04:00
|
|
|
* the License at http://www.mozilla.org/NPL/
|
2001-06-13 05:04:39 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2001-09-20 04:02:59 +04:00
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
2001-06-13 05:04:39 +04:00
|
|
|
*
|
2001-09-20 04:02:59 +04:00
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
2001-06-13 05:04:39 +04:00
|
|
|
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2001-09-20 04:02:59 +04:00
|
|
|
* Ben "Count XULula" Goodger
|
|
|
|
*/
|
2001-06-13 05:04:39 +04:00
|
|
|
|
|
|
|
function BuildJSEAttributeNameList()
|
|
|
|
{
|
2001-10-11 00:07:06 +04:00
|
|
|
ClearMenulist(gDialog.AddJSEAttributeNameList);
|
2001-06-13 05:04:39 +04:00
|
|
|
|
|
|
|
// Get events specific to current element
|
Fixed Advanced Editor dialog bugs (fixed warnings, user input filter rules, dynamic value menulist for particular attributes): bugs 86710, 86712, 86713, 86934, 88878, 88888, 88917, 88923, 88930, 88935, 89445, 92554 (includes help from stephend), r=brade (86713=rcassin, 92554=glazman), sr=kin; fix to 95085 by neil@parkwayscc.co.uk, r=cmanske, sr=kin
2001-08-18 02:41:52 +04:00
|
|
|
var elementName = gElement.localName.toLowerCase();
|
|
|
|
if (elementName in gJSAttr)
|
2001-06-13 05:04:39 +04:00
|
|
|
{
|
Fixed Advanced Editor dialog bugs (fixed warnings, user input filter rules, dynamic value menulist for particular attributes): bugs 86710, 86712, 86713, 86934, 88878, 88888, 88917, 88923, 88930, 88935, 89445, 92554 (includes help from stephend), r=brade (86713=rcassin, 92554=glazman), sr=kin; fix to 95085 by neil@parkwayscc.co.uk, r=cmanske, sr=kin
2001-08-18 02:41:52 +04:00
|
|
|
var attNames = gJSAttr[elementName];
|
|
|
|
var i;
|
|
|
|
var popup;
|
|
|
|
var sep;
|
2001-06-13 05:04:39 +04:00
|
|
|
|
Fixed Advanced Editor dialog bugs (fixed warnings, user input filter rules, dynamic value menulist for particular attributes): bugs 86710, 86712, 86713, 86934, 88878, 88888, 88917, 88923, 88930, 88935, 89445, 92554 (includes help from stephend), r=brade (86713=rcassin, 92554=glazman), sr=kin; fix to 95085 by neil@parkwayscc.co.uk, r=cmanske, sr=kin
2001-08-18 02:41:52 +04:00
|
|
|
if (attNames && attNames.length)
|
2001-06-13 05:04:39 +04:00
|
|
|
{
|
Fixed Advanced Editor dialog bugs (fixed warnings, user input filter rules, dynamic value menulist for particular attributes): bugs 86710, 86712, 86713, 86934, 88878, 88888, 88917, 88923, 88930, 88935, 89445, 92554 (includes help from stephend), r=brade (86713=rcassin, 92554=glazman), sr=kin; fix to 95085 by neil@parkwayscc.co.uk, r=cmanske, sr=kin
2001-08-18 02:41:52 +04:00
|
|
|
// Since we don't allow user-editable JS events yet (but we will soon)
|
|
|
|
// simply remove the JS tab to not allow adding JS events
|
|
|
|
if (attNames[0] == "noJSEvents")
|
|
|
|
{
|
|
|
|
var tab = document.getElementById("tabJSE");
|
|
|
|
if (tab)
|
|
|
|
tab.parentNode.removeChild(tab);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < attNames.length; i++)
|
2001-10-11 00:07:06 +04:00
|
|
|
AppendStringToMenulist(gDialog.AddJSEAttributeNameList, attNames[i]);
|
Fixed Advanced Editor dialog bugs (fixed warnings, user input filter rules, dynamic value menulist for particular attributes): bugs 86710, 86712, 86713, 86934, 88878, 88888, 88917, 88923, 88930, 88935, 89445, 92554 (includes help from stephend), r=brade (86713=rcassin, 92554=glazman), sr=kin; fix to 95085 by neil@parkwayscc.co.uk, r=cmanske, sr=kin
2001-08-18 02:41:52 +04:00
|
|
|
|
2001-10-11 00:07:06 +04:00
|
|
|
popup = gDialog.AddJSEAttributeNameList.firstChild;
|
Fixed Advanced Editor dialog bugs (fixed warnings, user input filter rules, dynamic value menulist for particular attributes): bugs 86710, 86712, 86713, 86934, 88878, 88888, 88917, 88923, 88930, 88935, 89445, 92554 (includes help from stephend), r=brade (86713=rcassin, 92554=glazman), sr=kin; fix to 95085 by neil@parkwayscc.co.uk, r=cmanske, sr=kin
2001-08-18 02:41:52 +04:00
|
|
|
if (popup)
|
|
|
|
{
|
2001-11-07 08:42:41 +03:00
|
|
|
sep = document.createElementNS(XUL_NS, "menuseparator");
|
Fixed Advanced Editor dialog bugs (fixed warnings, user input filter rules, dynamic value menulist for particular attributes): bugs 86710, 86712, 86713, 86934, 88878, 88888, 88917, 88923, 88930, 88935, 89445, 92554 (includes help from stephend), r=brade (86713=rcassin, 92554=glazman), sr=kin; fix to 95085 by neil@parkwayscc.co.uk, r=cmanske, sr=kin
2001-08-18 02:41:52 +04:00
|
|
|
if (sep)
|
|
|
|
popup.appendChild(sep);
|
|
|
|
}
|
|
|
|
}
|
2001-06-13 05:04:39 +04:00
|
|
|
}
|
|
|
|
|
Fixed Advanced Editor dialog bugs (fixed warnings, user input filter rules, dynamic value menulist for particular attributes): bugs 86710, 86712, 86713, 86934, 88878, 88888, 88917, 88923, 88930, 88935, 89445, 92554 (includes help from stephend), r=brade (86713=rcassin, 92554=glazman), sr=kin; fix to 95085 by neil@parkwayscc.co.uk, r=cmanske, sr=kin
2001-08-18 02:41:52 +04:00
|
|
|
// Always add core JS events unless we aborted above
|
2001-06-13 05:04:39 +04:00
|
|
|
for (i = 0; i < gCoreJSEvents.length; i++)
|
|
|
|
{
|
|
|
|
if (gCoreJSEvents[i] == "-")
|
|
|
|
{
|
|
|
|
if (!popup)
|
2001-10-11 00:07:06 +04:00
|
|
|
popup = gDialog.AddJSEAttributeNameList.firstChild;
|
2001-06-13 05:04:39 +04:00
|
|
|
|
2001-11-07 08:42:41 +03:00
|
|
|
sep = document.createElementNS(XUL_NS, "menuseparator");
|
2001-06-13 05:04:39 +04:00
|
|
|
|
|
|
|
if (popup && sep)
|
|
|
|
popup.appendChild(sep);
|
|
|
|
}
|
|
|
|
else
|
2001-10-11 00:07:06 +04:00
|
|
|
AppendStringToMenulist(gDialog.AddJSEAttributeNameList, gCoreJSEvents[i]);
|
2001-06-13 05:04:39 +04:00
|
|
|
}
|
|
|
|
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.AddJSEAttributeNameList.selectedIndex = 0;
|
2001-06-13 05:04:39 +04:00
|
|
|
|
|
|
|
// Use current name and value of first tree item if it exists
|
|
|
|
onSelectJSETreeItem();
|
|
|
|
}
|
1999-12-02 13:22:31 +03:00
|
|
|
|
1999-09-30 01:45:50 +04:00
|
|
|
// build attribute list in tree form from element attributes
|
|
|
|
function BuildJSEAttributeTable()
|
|
|
|
{
|
2001-06-13 05:04:39 +04:00
|
|
|
var nodeMap = gElement.attributes;
|
|
|
|
if (nodeMap.length > 0)
|
|
|
|
{
|
|
|
|
var added = false;
|
|
|
|
for (var i = 0; i < nodeMap.length; i++)
|
1999-12-02 13:22:31 +03:00
|
|
|
{
|
2001-06-13 05:04:39 +04:00
|
|
|
if( CheckAttributeNameSimilarity( nodeMap[i].nodeName, JSEAttrs ) )
|
1999-12-02 13:22:31 +03:00
|
|
|
continue; // repeated or non-JS handler, ignore this one and go to next
|
|
|
|
if( !IsEventHandler( nodeMap[i].nodeName ) )
|
|
|
|
continue; // attribute isn't an event handler.
|
|
|
|
var name = nodeMap[i].nodeName.toLowerCase();
|
2001-06-13 05:04:39 +04:00
|
|
|
var value = gElement.getAttribute(nodeMap[i].nodeName);
|
|
|
|
if (AddTreeItem( name, value, "JSEAList", JSEAttrs )) // add item to tree
|
|
|
|
added = true;
|
1999-12-02 13:22:31 +03:00
|
|
|
}
|
2001-06-13 05:04:39 +04:00
|
|
|
|
|
|
|
// Select first item
|
|
|
|
if (added)
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.AddJSEAttributeTree.selectedIndex = 0;
|
1999-09-30 01:45:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-02 13:22:31 +03:00
|
|
|
// check to see if given string is an event handler.
|
|
|
|
function IsEventHandler( which )
|
1999-09-30 01:45:50 +04:00
|
|
|
{
|
|
|
|
var handlerName = which.toLowerCase();
|
|
|
|
var firstTwo = handlerName.substring(0,2);
|
2001-06-13 05:04:39 +04:00
|
|
|
if (firstTwo == "on")
|
1999-09-30 01:45:50 +04:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-06-13 05:04:39 +04:00
|
|
|
function onSelectJSEAttribute()
|
1999-09-30 01:45:50 +04:00
|
|
|
{
|
2001-06-13 05:04:39 +04:00
|
|
|
if(!gDoOnSelectTree)
|
1999-12-02 13:22:31 +03:00
|
|
|
return;
|
|
|
|
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.AddJSEAttributeValueInput.value =
|
|
|
|
GetAndSelectExistingAttributeValue(gDialog.AddJSEAttributeNameList.label, "JSEAList");
|
2001-06-13 05:04:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSelectJSETreeItem()
|
|
|
|
{
|
2001-10-11 00:07:06 +04:00
|
|
|
var tree = gDialog.AddJSEAttributeTree;
|
2002-03-29 05:46:01 +03:00
|
|
|
if (tree && tree.treeBoxObject.selection.count)
|
2001-06-13 05:04:39 +04:00
|
|
|
{
|
2002-03-29 05:46:01 +03:00
|
|
|
var name = GetTreeItemAttributeStr(getSelectedItem(tree));
|
2001-01-04 03:52:49 +03:00
|
|
|
|
2001-06-13 05:04:39 +04:00
|
|
|
// Select attribute name in list
|
2001-10-11 00:07:06 +04:00
|
|
|
if (gDialog.AddJSEAttributeNameList.firstChild)
|
2001-06-13 05:04:39 +04:00
|
|
|
{
|
2001-10-11 00:07:06 +04:00
|
|
|
var arr = gDialog.AddJSEAttributeNameList.firstChild.getElementsByAttribute('label', name);
|
2001-06-13 05:04:39 +04:00
|
|
|
if (arr && arr.length)
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.AddJSEAttributeNameList.selectedItem = arr[0];
|
1999-12-02 13:22:31 +03:00
|
|
|
|
2001-06-13 05:04:39 +04:00
|
|
|
// Set value input to that in tree (no need to update this in the tree)
|
|
|
|
gUpdateTreeValue = false;
|
2002-03-29 05:46:01 +03:00
|
|
|
gDialog.AddJSEAttributeValueInput.value = GetTreeItemValueStr(getSelectedItem(tree));
|
2001-06-13 05:04:39 +04:00
|
|
|
gUpdateTreeValue = true;
|
|
|
|
}
|
1999-09-30 01:45:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-13 05:04:39 +04:00
|
|
|
function onInputJSEAttributeValue()
|
1999-09-30 01:45:50 +04:00
|
|
|
{
|
2001-06-13 05:04:39 +04:00
|
|
|
if (gUpdateTreeValue)
|
|
|
|
{
|
1999-12-02 13:22:31 +03:00
|
|
|
|
2001-10-11 00:07:06 +04:00
|
|
|
var name = TrimString(gDialog.AddJSEAttributeNameList.label);
|
|
|
|
var value = TrimString(gDialog.AddJSEAttributeValueInput.value);
|
2001-03-08 18:07:14 +03:00
|
|
|
|
2001-06-13 05:04:39 +04:00
|
|
|
// Update value in the tree list
|
|
|
|
// Since we have a non-editable menulist,
|
|
|
|
// we MUST automatically add the event attribute if it doesn't exist
|
2001-10-17 01:51:12 +04:00
|
|
|
if (!UpdateExistingAttribute( name, value, "JSEAList" ) && value)
|
2001-06-13 05:04:39 +04:00
|
|
|
AddTreeItem( name, value, "JSEAList", JSEAttrs );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function editJSEAttributeValue(targetCell)
|
|
|
|
{
|
|
|
|
if (IsNotTreeHeader(targetCell))
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.AddJSEAttributeValueInput.inputField.select();
|
1999-09-30 01:45:50 +04:00
|
|
|
}
|
1999-12-02 13:22:31 +03:00
|
|
|
|
|
|
|
function UpdateJSEAttributes()
|
|
|
|
{
|
|
|
|
var JSEAList = document.getElementById("JSEAList");
|
2000-09-12 04:35:42 +04:00
|
|
|
var i;
|
2001-06-13 05:04:39 +04:00
|
|
|
|
1999-12-02 13:22:31 +03:00
|
|
|
// remove removed attributes
|
2001-06-13 05:04:39 +04:00
|
|
|
for (i = 0; i < JSERAttrs.length; i++)
|
1999-12-02 13:22:31 +03:00
|
|
|
{
|
2001-06-13 05:04:39 +04:00
|
|
|
name = JSERAttrs[i];
|
|
|
|
if (gElement.getAttribute(name))
|
2001-10-03 03:36:02 +04:00
|
|
|
doRemoveAttribute(gElement, name);
|
1999-12-02 13:22:31 +03:00
|
|
|
}
|
2001-03-22 03:59:29 +03:00
|
|
|
|
2001-01-04 03:52:49 +03:00
|
|
|
// Add events
|
2001-06-13 05:04:39 +04:00
|
|
|
for (i = 0; i < JSEAList.childNodes.length; i++)
|
2001-01-04 03:52:49 +03:00
|
|
|
{
|
|
|
|
var item = JSEAList.childNodes[i];
|
2001-03-08 18:07:14 +03:00
|
|
|
|
2001-01-04 03:52:49 +03:00
|
|
|
// set the event handler
|
2001-10-03 03:36:02 +04:00
|
|
|
doSetAttribute( GetTreeItemAttributeStr(item), GetTreeItemValueStr(item) );
|
2001-06-13 05:04:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function RemoveJSEAttribute()
|
|
|
|
{
|
2001-10-11 00:07:06 +04:00
|
|
|
var treechildren = gDialog.AddJSEAttributeTree.lastChild;
|
2001-06-13 05:04:39 +04:00
|
|
|
|
|
|
|
// This differs from HTML and CSS panels:
|
|
|
|
// We reselect after removing, because there is not
|
|
|
|
// editable attribute name input, so we can't clear that
|
|
|
|
// like we do in other panels
|
2001-10-11 00:07:06 +04:00
|
|
|
var newIndex = gDialog.AddJSEAttributeTree.selectedIndex;
|
2001-06-13 05:04:39 +04:00
|
|
|
|
|
|
|
// We only allow 1 selected item
|
2002-03-29 05:46:01 +03:00
|
|
|
if (gDialog.AddJSEAttributeTree.treeBoxObject.selection.count)
|
2001-06-13 05:04:39 +04:00
|
|
|
{
|
2002-03-29 05:46:01 +03:00
|
|
|
var item = getSelectedItem(gDialog.AddJSEAttributeTree);
|
2001-06-13 05:04:39 +04:00
|
|
|
|
|
|
|
// Name is the text of the treecell
|
|
|
|
var attr = GetTreeItemAttributeStr(item);
|
|
|
|
|
|
|
|
// remove the item from the attribute array
|
|
|
|
if (newIndex >= (JSEAttrs.length-1))
|
|
|
|
newIndex--;
|
|
|
|
|
|
|
|
// remove the item from the attribute array
|
|
|
|
JSERAttrs[JSERAttrs.length] = attr;
|
|
|
|
RemoveNameFromAttArray(attr, JSEAttrs);
|
|
|
|
|
|
|
|
// Remove the item from the tree
|
|
|
|
treechildren.removeChild (item);
|
|
|
|
|
|
|
|
// Reselect an item
|
2001-10-11 00:07:06 +04:00
|
|
|
gDialog.AddJSEAttributeTree.selectedIndex = newIndex;
|
2001-01-04 03:52:49 +03:00
|
|
|
}
|
2001-03-08 18:07:14 +03:00
|
|
|
}
|