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

« back to all changes in this revision

Viewing changes to mozilla/extensions/venkman/resources/content/venkman-munger.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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 * The contents of this file are subject to the Mozilla Public License
 
4
 * Version 1.1 (the "License"); you may not use this file except in
 
5
 * compliance with the License. You may obtain a copy of the License at
 
6
 * http://www.mozilla.org/MPL/ 
 
7
 * 
 
8
 * Software distributed under the License is distributed on an "AS IS" basis,
 
9
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
10
 * for the specific language governing rights and limitations under the
 
11
 * License. 
 
12
 *
 
13
 * The Original Code is The JavaScript Debugger
 
14
 * 
 
15
 * The Initial Developer of the Original Code is
 
16
 * Netscape Communications Corporation
 
17
 * Portions created by Netscape are
 
18
 * Copyright (C) 1998 Netscape Communications Corporation.
 
19
 *
 
20
 * Alternatively, the contents of this file may be used under the
 
21
 * terms of the GNU Public License (the "GPL"), in which case the
 
22
 * provisions of the GPL are applicable instead of those above.
 
23
 * If you wish to allow use of your version of this file only
 
24
 * under the terms of the GPL and not to allow others to use your
 
25
 * version of this file under the MPL, indicate your decision by
 
26
 * deleting the provisions above and replace them with the notice
 
27
 * and other provisions required by the GPL.  If you do not delete
 
28
 * the provisions above, a recipient may use your version of this
 
29
 * file under either the MPL or the GPL.
 
30
 *
 
31
 * Contributor(s):
 
32
 *  Robert Ginda, <rginda@netscape.com>, original author
 
33
 *
 
34
 */
 
35
 
 
36
function CMungerEntry (name, regex, className, tagName)
 
37
{
 
38
    
 
39
    this.name = name;
 
40
    this.tagName = (tagName) ? tagName : "html:span";
 
41
 
 
42
    if (regex instanceof RegExp)
 
43
        this.regex = regex;
 
44
    else
 
45
        this.lambdaMatch = regex;
 
46
    
 
47
    if (typeof className == "function")
 
48
        this.lambdaReplace = className;
 
49
    else 
 
50
        this.className = className;
 
51
    
 
52
}
 
53
 
 
54
function CMunger () 
 
55
{
 
56
    
 
57
    this.entries = new Object();
 
58
    
 
59
}
 
60
 
 
61
CMunger.prototype.enabled = true;
 
62
 
 
63
CMunger.prototype.addRule =
 
64
function mng_addrule (name, regex, className)
 
65
{
 
66
    
 
67
    this.entries[name] = new CMungerEntry (name, regex, className);
 
68
    
 
69
}
 
70
 
 
71
CMunger.prototype.delRule =
 
72
function mng_delrule (name)
 
73
{
 
74
 
 
75
    delete this.entries[name];
 
76
    
 
77
}
 
78
 
 
79
CMunger.prototype.munge =
 
80
function mng_munge (text, containerTag, data)
 
81
{
 
82
    var entry;
 
83
    var ary;    
 
84
 
 
85
    if (!text) //(ASSERT(text, "no text to munge"))
 
86
        return "";
 
87
     
 
88
    if (typeof text != "string")
 
89
        text = String(text);
 
90
 
 
91
    if (!containerTag)
 
92
    {
 
93
        containerTag =
 
94
            document.createElementNS (NS_XHTML, this.tagName);
 
95
    }
 
96
 
 
97
    if (this.enabled)
 
98
    {
 
99
        for (entry in this.entries)
 
100
        {
 
101
            if (typeof this.entries[entry].lambdaMatch == "function")
 
102
            {
 
103
                var rval;
 
104
                
 
105
                rval = this.entries[entry].lambdaMatch(text, containerTag,
 
106
                                                       data,
 
107
                                                       this.entries[entry]);
 
108
                if (rval)
 
109
                    ary = [(void 0), rval];
 
110
                else
 
111
                    ary = null;
 
112
            }
 
113
            else
 
114
                ary = text.match(this.entries[entry].regex);
 
115
            
 
116
            if ((ary != null) && (ary[1]))
 
117
            {
 
118
                var startPos = text.indexOf(ary[1]);
 
119
                
 
120
                if (typeof this.entries[entry].lambdaReplace == "function")
 
121
                {
 
122
                    this.munge (text.substr(0,startPos), containerTag,
 
123
                                data);
 
124
                    this.entries[entry].lambdaReplace (ary[1], containerTag,
 
125
                                                       data,
 
126
                                                       this.entries[entry]);
 
127
                    this.munge (text.substr (startPos + ary[1].length,
 
128
                                             text.length), containerTag,
 
129
                                data);
 
130
                
 
131
                    return containerTag;
 
132
                }
 
133
                else
 
134
                {
 
135
                    this.munge (text.substr(0,startPos), containerTag,
 
136
                                data);
 
137
                    
 
138
                    var subTag = 
 
139
                        document.createElementNS (NS_XHTML,
 
140
                                                  this.entries[entry].tagName);
 
141
 
 
142
                    subTag.setAttribute ("class",
 
143
                                         this.entries[entry].className);
 
144
                    var wordParts = splitLongWord (ary[1],
 
145
                                                   client.MAX_WORD_DISPLAY);
 
146
                    for (var i in wordParts)
 
147
                    {
 
148
                        subTag.appendChild (document.createTextNode (wordParts[i]));
 
149
                        subTag.appendChild (htmlWBR());
 
150
                    }
 
151
                    
 
152
                    containerTag.appendChild (subTag);
 
153
                    this.munge (text.substr (startPos + ary[1].length,
 
154
                                             text.length), containerTag, data);
 
155
 
 
156
                    return containerTag;
 
157
                }
 
158
            }
 
159
        }
 
160
    }
 
161
 
 
162
    containerTag.appendChild (document.createTextNode (text));
 
163
    return containerTag;
 
164
    
 
165
}