!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Daniel Glazman (glazman@netscape.com), original author
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * 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
39 var gContextMenuNode;
40 var gContextMenuFiringDocumentElement;
41
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
42 function InitStructBarContextMenu(button, docElement)
43 {
44 gContextMenuFiringDocumentElement = docElement;
45 gContextMenuNode = button;
46
47 var tag = docElement.nodeName.toLowerCase();
48
49 var structRemoveTag = document.getElementById("structRemoveTag");
50 var enableRemove;
51
52 switch (tag) {
53 case "body":
54 case "tbody":
55 case "thead":
56 case "tfoot":
57 case "col":
58 case "colgroup":
59 case "tr":
60 case "th":
61 case "td":
62 case "caption":
63 enableRemove = false;
64 break;
65 default:
66 enableRemove = true;
67 break;
68 }
69 SetElementEnabled(structRemoveTag, enableRemove);
70
71 var structChangeTag = document.getElementById("structChangeTag");
72 SetElementEnabled(structChangeTag, (tag != "body"));
73 }
74
TableCellFilter
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
75 function TableCellFilter(node)
76 {
77 switch (node.nodeName.toLowerCase())
78 {
79 case "td":
80 case "th":
81 case "caption":
82 return NodeFilter.FILTER_ACCEPT;
83 break;
84 default:
85 return NodeFilter.FILTER_SKIP;
86 break;
87 }
88 return NodeFilter.FILTER_SKIP;
89 }
90
StructRemoveTag
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
91 function StructRemoveTag()
92 {
93 var editor = GetCurrentEditor();
94 if (!editor) return;
95
96 var element = gContextMenuFiringDocumentElement;
97 var offset = 0;
98 var childNodes = element.parentNode.childNodes;
99
100 while (childNodes[offset] != element) {
101 ++offset;
102 }
103
104 editor.beginTransaction();
105
106 try {
107
108 var tag = element.nodeName.toLowerCase();
109 if (tag != "table") {
110 MoveChildNodesAfterElement(editor, element, element, offset);
111 }
112 else {
113
114 var nodeIterator = document.createTreeWalker(element,
115 NodeFilter.SHOW_ELEMENT,
116 TableCellFilter,
117 true);
118 var node = nodeIterator.lastChild();
119 while (node) {
120 MoveChildNodesAfterElement(editor, node, element, offset);
121 node = nodeIterator.previousSibling();
122 }
123
124 }
125 editor.deleteNode(element);
126 }
127 catch (e) {};
128
129 editor.endTransaction();
130 }
131
MoveChildNodesAfterElement
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
132 function MoveChildNodesAfterElement(editor, element, targetElement, targetOffset)
133 {
134 var childNodes = element.childNodes;
135 var childNodesLength = childNodes.length;
136 var i;
137 for (i = childNodesLength - 1; i >= 0; i--) {
138 var clone = childNodes.item(i).cloneNode(true);
139 editor.insertNode(clone, targetElement.parentNode, targetOffset + 1);
140 }
141 }
142
StructChangeTag
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
143 function StructChangeTag()
144 {
145 var textbox = document.createElementNS(XUL_NS, "textbox");
146 textbox.setAttribute("value", gContextMenuNode.getAttribute("value"));
147 textbox.setAttribute("width", gContextMenuNode.boxObject.width);
148 textbox.className = "struct-textbox";
149
150 gContextMenuNode.parentNode.replaceChild(textbox, gContextMenuNode);
151
152 textbox.addEventListener("keypress", OnKeyPress, false);
153 textbox.addEventListener("blur", ResetStructToolbar, true);
154
155 textbox.select();
156 }
157
StructSelectTag
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
158 function StructSelectTag()
159 {
160 SelectFocusNodeAncestor(gContextMenuFiringDocumentElement);
161 }
162
OpenAdvancedProperties
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
163 function OpenAdvancedProperties()
164 {
165 doAdvancedProperties(gContextMenuFiringDocumentElement);
166 }
167
OnKeyPress
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
168 function OnKeyPress(event)
169 {
170 var editor = GetCurrentEditor();
171
172 var keyCode = event.keyCode;
173 if (keyCode == 13) {
174 var newTag = event.target.value;
175
176 var element = gContextMenuFiringDocumentElement;
177
178 var offset = 0;
179 var childNodes = element.parentNode.childNodes;
180 while (childNodes.item(offset) != element) {
181 offset++;
182 }
183
184 editor.beginTransaction();
185
186 try {
187 var newElt = editor.document.createElement(newTag);
188 if (newElt) {
189 childNodes = element.childNodes;
190 var childNodesLength = childNodes.length;
191 var i;
192 for (i = 0; i < childNodesLength; i++) {
193 var clone = childNodes.item(i).cloneNode(true);
194 newElt.appendChild(clone);
195 }
196 editor.insertNode(newElt, element.parentNode, offset+1);
197 editor.deleteNode(element);
198 editor.selectElement(newElt);
199
200 window.content.focus();
201 }
202 }
203 catch (e) {}
204
205 editor.endTransaction();
206
207 }
208 else if (keyCode == 27) {
209 // if the user hits Escape, we discard the changes
210 window.content.focus();
211 }
212 }