~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/extensions/inspector/resources/content/utils.js

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
3
 *
 
4
 * The contents of this file are subject to the Netscape Public License
 
5
 * Version 1.1 (the "License"); you may not use this file except in
 
6
 * compliance with the License. You may obtain a copy of the License at
 
7
 * http://www.mozilla.org/NPL/
 
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.org code.
 
15
 *
 
16
 * The Initial Developer of the Original Code is 
 
17
 * Netscape Communications Corporation.
 
18
 * Portions created by the Initial Developer are Copyright (C) 2001
 
19
 * the Initial Developer. All Rights Reserved.
 
20
 *
 
21
 * Contributor(s):
 
22
 *   Joe Hewitt <hewitt@netscape.com> (original author)
 
23
 *
 
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 NPL, 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 NPL, the GPL or the LGPL.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
/***************************************************************
 
40
* Inspector Utils ----------------------------------------------
 
41
*  Common functions and constants used across the app.
 
42
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
43
* REQUIRED IMPORTS:
 
44
* chrome://inspector/content/jsutil/xpcom/XPCU.js
 
45
* chrome://inspector/content/jsutil/rdf/RDFU.js
 
46
****************************************************************/
 
47
 
 
48
//////////// global constants ////////////////////
 
49
 
 
50
const kInspectorNSURI = "http://www.mozilla.org/inspector#";
 
51
const kXULNSURI = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
52
const kHTMLNSURI = "http://www.w3.org/1999/xhtml";
 
53
 
 
54
var InsUtil = {
 
55
  /******************************************************************************
 
56
  * Convenience function for calling nsIChromeRegistry::convertChromeURL 
 
57
  *******************************************************************************/
 
58
  convertChromeURL: function(aURL)
 
59
  {
 
60
    var uri = XPCU.getService("@mozilla.org/network/simple-uri;1", "nsIURI");
 
61
    uri.spec = aURL;
 
62
    var reg = XPCU.getService("@mozilla.org/chrome/chrome-registry;1", "nsIChromeRegistry");
 
63
    return reg.convertChromeURL(uri);
 
64
  },
 
65
 
 
66
  /******************************************************************************
 
67
  * Convenience function for getting a literal value from nsIRDFDataSource::GetTarget
 
68
  *******************************************************************************/
 
69
  getDSProperty: function(/*nsISupports*/ aDS, /*String*/ aId, /*String*/ aPropName) 
 
70
  {
 
71
    var ruleRes = gRDF.GetResource(aId);
 
72
    var ds = XPCU.QI(aDS, "nsIRDFDataSource"); // just to be sure
 
73
    var propRes = ds.GetTarget(ruleRes, gRDF.GetResource(kInspectorNSURI+aPropName), true);
 
74
    propRes = XPCU.QI(propRes, "nsIRDFLiteral");
 
75
    return propRes.Value;
 
76
  },
 
77
  
 
78
  /******************************************************************************
 
79
  * Convenience function for persisting an element's persisted attributes.
 
80
  *******************************************************************************/
 
81
  persistAll: function(aId)
 
82
  {
 
83
    var el = document.getElementById(aId);
 
84
    if (el) {
 
85
      var attrs = el.getAttribute("persist").split(" ");
 
86
      for (var i = 0; i < attrs.length; ++i) {
 
87
        document.persist(aId, attrs[i]);
 
88
      }
 
89
    }
 
90
  }
 
91
};
 
92
 
 
93
// ::::::: debugging utilities :::::: 
 
94
 
 
95
function debug(aText)
 
96
{
 
97
  // XX comment out to reduce noise 
 
98
  consoleDump(aText);
 
99
  //dump(aText);
 
100
}
 
101
 
 
102
// dump text to the Javascript Console
 
103
function consoleDump(aText)
 
104
{
 
105
  var csClass = Components.classes['@mozilla.org/consoleservice;1'];
 
106
  var cs = csClass.getService(Components.interfaces.nsIConsoleService);
 
107
  cs.logStringMessage(aText);
 
108
}
 
109
 
 
110
function dumpDOM(aNode, aIndent)
 
111
{
 
112
  if (!aIndent) aIndent = "";
 
113
  debug(aIndent + "<" + aNode.localName + "\n");
 
114
  var attrs = aNode.attributes;
 
115
  var attr;
 
116
  for (var a = 0; a < attrs.length; ++a) { 
 
117
    attr = attrs[a];
 
118
    debug(aIndent + "  " + attr.nodeName + "=\"" + attr.nodeValue + "\"\n");
 
119
  }
 
120
  debug(aIndent + ">\n");
 
121
 
 
122
  aIndent += "  ";
 
123
  
 
124
  for (var i = 0; i < aNode.childNodes.length; ++i)
 
125
    dumpDOM(aNode.childNodes[i], aIndent);
 
126
}
 
127
 
 
128
var gStringBundle;
 
129
 
 
130
// convert nodeType constant into human readable form
 
131
function nodeTypeToText (nodeType)
 
132
{
 
133
  if (!gStringBundle) {
 
134
    var strBundleService =
 
135
       Components.classes["@mozilla.org/intl/stringbundle;1"].
 
136
                  getService(Components.interfaces.nsIStringBundleService);
 
137
    gStringBundle = strBundleService.createBundle("chrome://inspector/locale/inspector.properties"); 
 
138
  }
 
139
 
 
140
  if (gStringBundle) {
 
141
    const nsIDOMNode = Components.interfaces.nsIDOMNode;
 
142
    if (nodeType >= nsIDOMNode.ELEMENT_NODE && nodeType <= nsIDOMNode.NOTATION_NODE) {
 
143
      return gStringBundle.GetStringFromName(nodeType);
 
144
    }
 
145
  }
 
146
 
 
147
  return nodeType;
 
148
}