!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 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
BuildJSEAttributeNameList
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
39 function BuildJSEAttributeNameList()
40 {
41 gDialog.AddJSEAttributeNameList.removeAllItems();
42
43 // Get events specific to current element
44 var elementName = gElement.localName.toLowerCase();
45 if (elementName in gJSAttr)
46 {
47 var attNames = gJSAttr[elementName];
48 var i;
49 var popup;
50 var sep;
51
52 if (attNames && attNames.length)
53 {
54 // Since we don't allow user-editable JS events yet (but we will soon)
55 // simply remove the JS tab to not allow adding JS events
56 if (attNames[0] == "noJSEvents")
57 {
58 var tab = document.getElementById("tabJSE");
59 if (tab)
60 tab.parentNode.removeChild(tab);
61
62 return;
63 }
64
65 for (i = 0; i < attNames.length; i++)
66 gDialog.AddJSEAttributeNameList.appendItem(attNames[i], attNames[i]);
67
68 popup = gDialog.AddJSEAttributeNameList.firstChild;
69 if (popup)
70 {
71 sep = document.createElementNS(XUL_NS, "menuseparator");
72 if (sep)
73 popup.appendChild(sep);
74 }
75 }
76 }
77
78 // Always add core JS events unless we aborted above
79 for (i = 0; i < gCoreJSEvents.length; i++)
80 {
81 if (gCoreJSEvents[i] == "-")
82 {
83 if (!popup)
84 popup = gDialog.AddJSEAttributeNameList.firstChild;
85
86 sep = document.createElementNS(XUL_NS, "menuseparator");
87
88 if (popup && sep)
89 popup.appendChild(sep);
90 }
91 else
92 gDialog.AddJSEAttributeNameList.appendItem(gCoreJSEvents[i], gCoreJSEvents[i]);
93 }
94
95 gDialog.AddJSEAttributeNameList.selectedIndex = 0;
96
97 // Use current name and value of first tree item if it exists
98 onSelectJSETreeItem();
99 }
100
101 // build attribute list in tree form from element attributes
BuildJSEAttributeTable
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
102 function BuildJSEAttributeTable()
103 {
104 var nodeMap = gElement.attributes;
105 if (nodeMap.length > 0)
106 {
107 var added = false;
108 for (var i = 0; i < nodeMap.length; i++)
109 {
110 if( CheckAttributeNameSimilarity( nodeMap[i].nodeName, JSEAttrs ) )
111 continue; // repeated or non-JS handler, ignore this one and go to next
112 if( !IsEventHandler( nodeMap[i].nodeName ) )
113 continue; // attribute isn't an event handler.
114 var name = nodeMap[i].nodeName.toLowerCase();
115 var value = gElement.getAttribute(nodeMap[i].nodeName);
116 if (AddTreeItem( name, value, "JSEAList", JSEAttrs )) // add item to tree
117 added = true;
118 }
119
120 // Select first item
121 if (added)
122 gDialog.AddJSEAttributeTree.selectedIndex = 0;
123 }
124 }
125
126 // check to see if given string is an event handler.
IsEventHandler
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
127 function IsEventHandler( which )
128 {
129 var handlerName = which.toLowerCase();
130 var firstTwo = handlerName.substring(0,2);
131 if (firstTwo == "on")
132 return true;
133 else
134 return false;
135 }
136
onSelectJSEAttribute
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
137 function onSelectJSEAttribute()
138 {
139 if(!gDoOnSelectTree)
140 return;
141
142 gDialog.AddJSEAttributeValueInput.value =
143 GetAndSelectExistingAttributeValue(gDialog.AddJSEAttributeNameList.label, "JSEAList");
144 }
145
onSelectJSETreeItem
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
146 function onSelectJSETreeItem()
147 {
148 var tree = gDialog.AddJSEAttributeTree;
149 if (tree && tree.view.selection.count)
150 {
151 // Select attribute name in list
152 gDialog.AddJSEAttributeNameList.value = GetTreeItemAttributeStr(getSelectedItem(tree));
153
154 // Set value input to that in tree (no need to update this in the tree)
155 gUpdateTreeValue = false;
156 gDialog.AddJSEAttributeValueInput.value = GetTreeItemValueStr(getSelectedItem(tree));
157 gUpdateTreeValue = true;
158 }
159 }
160
onInputJSEAttributeValue
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
161 function onInputJSEAttributeValue()
162 {
163 if (gUpdateTreeValue)
164 {
165
166 var name = TrimString(gDialog.AddJSEAttributeNameList.label);
167 var value = TrimString(gDialog.AddJSEAttributeValueInput.value);
168
169 // Update value in the tree list
170 // Since we have a non-editable menulist,
171 // we MUST automatically add the event attribute if it doesn't exist
172 if (!UpdateExistingAttribute( name, value, "JSEAList" ) && value)
173 AddTreeItem( name, value, "JSEAList", JSEAttrs );
174 }
175 }
176
editJSEAttributeValue
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
177 function editJSEAttributeValue(targetCell)
178 {
179 if (IsNotTreeHeader(targetCell))
180 gDialog.AddJSEAttributeValueInput.inputField.select();
181 }
182
UpdateJSEAttributes
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
183 function UpdateJSEAttributes()
184 {
185 var JSEAList = document.getElementById("JSEAList");
186 var i;
187
188 // remove removed attributes
189 for (i = 0; i < JSERAttrs.length; i++)
190 {
191 var name = JSERAttrs[i];
192
193 if (gElement.hasAttribute(name))
194 doRemoveAttribute(name);
195 }
196
197 // Add events
198 for (i = 0; i < JSEAList.childNodes.length; i++)
199 {
200 var item = JSEAList.childNodes[i];
201
202 // set the event handler
203 doSetAttribute( GetTreeItemAttributeStr(item), GetTreeItemValueStr(item) );
204 }
205 }
206
RemoveJSEAttribute
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
207 function RemoveJSEAttribute()
208 {
209 var treechildren = gDialog.AddJSEAttributeTree.lastChild;
210
211 // This differs from HTML and CSS panels:
212 // We reselect after removing, because there is not
213 // editable attribute name input, so we can't clear that
214 // like we do in other panels
215 var newIndex = gDialog.AddJSEAttributeTree.selectedIndex;
216
217 // We only allow 1 selected item
218 if (gDialog.AddJSEAttributeTree.view.selection.count)
219 {
220 var item = getSelectedItem(gDialog.AddJSEAttributeTree);
221
222 // Name is the text of the treecell
223 var attr = GetTreeItemAttributeStr(item);
224
225 // remove the item from the attribute array
226 if (newIndex >= (JSEAttrs.length-1))
227 newIndex--;
228
229 // remove the item from the attribute array
230 JSERAttrs[JSERAttrs.length] = attr;
231 RemoveNameFromAttArray(attr, JSEAttrs);
232
233 // Remove the item from the tree
234 treechildren.removeChild (item);
235
236 // Reselect an item
237 gDialog.AddJSEAttributeTree.selectedIndex = newIndex;
238 }
239 }