1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
14
* The Original Code is mozilla.org code for the DOM Inspector.
16
* The Initial Developer of the Original Code is
17
* Shawn Wilsher <me@shawnwilsher.com>
19
* Portions created by the Initial Developer are Copyright (C) 2006
20
* the Initial Developer. All Rights Reserved.
23
* Dave Townsend <dave.townsend@blueprintit.co.uk>
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.
37
* ***** END LICENSE BLOCK ***** */
39
///////////////////////////////////////////////////////////////////////////////
44
///////////////////////////////////////////////////////////////////////////////
45
//// Initialization/Destruction
47
window.addEventListener("load", InsertDialog_initialize, false);
49
function InsertDialog_initialize()
51
dialog = new InsertDialog();
55
///////////////////////////////////////////////////////////////////////////////
56
//// class InsertDialog
58
function InsertDialog()
60
this.mDoc = window.arguments[0];
61
this.mData = window.arguments[1];
63
this.nodeType = document.getElementById("ml_nodeType");
64
this.tagName = document.getElementById("tx_tagName");
65
this.nodeValue = document.getElementById("tx_nodeValue");
66
this.namespace = document.getElementById("tx_namespace");
67
this.menulist = document.getElementById("ml_namespace");
70
InsertDialog.prototype =
73
* This function initializes the content of the dialog.
75
initialize: function initialize()
77
var menuitems = this.menulist.firstChild.childNodes;
78
var defaultNS = document.getElementById("mi_namespace");
79
var customNS = document.getElementById("mi_custom");
80
var accept = document.documentElement.getButton("accept");
82
this.menulist.disabled = !this.enableNamespaces();
83
defaultNS.value = this.mDoc.documentElement.namespaceURI;
85
this.toggleNamespace();
90
* The function that is called on accept. Sets data.
92
accept: function accept()
94
switch (this.nodeType.value)
97
this.mData.type = Components.interfaces.nsIDOMNode.ELEMENT_NODE;
98
this.mData.value = this.tagName.value;
101
this.mData.type = Components.interfaces.nsIDOMNode.TEXT_NODE;
102
this.mData.value = this.nodeValue.value;
105
this.mData.namespaceURI = this.namespace.value;
106
this.mData.accepted = true;
111
* updateType changes the visibility of rows based on the node type.
113
updateType: function updateType()
115
switch (dialog.nodeType.value)
118
document.getElementById("row_text").hidden = false;
119
document.getElementById("row_element").hidden = true;
122
document.getElementById("row_text").hidden = true;
123
document.getElementById("row_element").hidden = false;
126
dialog.toggleAccept();
130
* toggleNamespace toggles the namespace textbox based on the namespace menu.
132
toggleNamespace: function toggleNamespace()
134
dialog.namespace.disabled = dialog.menulist.selectedItem.id != "mi_custom";
135
dialog.namespace.value = dialog.menulist.value;
139
* enableNamespaces determines if the document accepts namespaces or not
141
* @return True if the document can have namespaced attributes, false
144
enableNamespaces: function enableNamespaces()
146
return this.mDoc.contentType != "text/html";
150
* toggleAccept enables/disables the Accept button when there is/isn't an
153
toggleAccept: function toggleAccept()
155
document.documentElement.getButton("accept").disabled =
156
(dialog.tagName.value == "") && (dialog.nodeType.selectedItem.value == "element");