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

« back to all changes in this revision

Viewing changes to mozilla/extensions/cview/resources/content/cview-static.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
 
4
 * License Version 1.1 (the "License"); you may not use this file
 
5
 * except in compliance with the License. You may obtain a copy of
 
6
 * the License at http://www.mozilla.org/MPL/
 
7
 *
 
8
 * Software distributed under the License is distributed on an "AS
 
9
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
 * implied. See the License for the specific language governing
 
11
 * rights and limitations under the License.
 
12
 *
 
13
 * The Original Code is mozilla.org code
 
14
 * 
 
15
 * The Initial Developer of the Original Code is Netscape
 
16
 * Communications Corporation.  Portions created by Netscape are
 
17
 * Copyright (C) 1998 Netscape Communications Corporation. All
 
18
 * Rights Reserved.
 
19
 *
 
20
 * Contributor(s):
 
21
 *   Robert Ginda, rginda@netscape.com, original author
 
22
 */
 
23
 
 
24
/*
 
25
 * This file contains "static" functions for cview.  In this case static just
 
26
 * means not-an-event-handler.  If you can come up with a better name, let
 
27
 * me know.  The main code of cview is divided between this file and
 
28
 * cview-handlers.js
 
29
 */
 
30
 
 
31
var cview = new Object();
 
32
/*
 
33
 * instead of creating a slew of global variables, all app-wide values are
 
34
 * stored on this cview object.
 
35
 */
 
36
 
 
37
/* number of items to process per refresh step */
 
38
cview.REFRESH_ITEMS_PER_CYCLE = 30;
 
39
/* number of milliseconds to wait between refresh steps */
 
40
cview.REFRESH_CYCLE_DELAY = 200;
 
41
 
 
42
cview.componentMode = "all";
 
43
cview.interfaceMode = "all";
 
44
 
 
45
/*
 
46
 * hide/show entries in the components list based on the componentMode and
 
47
 * componentFilter properties of the cview object.
 
48
 */
 
49
function filterComponents()
 
50
{
 
51
    function filterAll (rec)
 
52
    {
 
53
        if (rec.isHidden)
 
54
            rec.unHide();
 
55
        cview.visibleComponents++;
 
56
    }
 
57
        
 
58
    function filterContains (rec)
 
59
    {
 
60
        if (rec.name.search(cview.componentFilter) != -1)
 
61
        {
 
62
            if (rec.isHidden)
 
63
                rec.unHide();
 
64
            cview.visibleComponents++;
 
65
        }
 
66
        else
 
67
        {
 
68
            if (!rec.isHidden)
 
69
                rec.hide();
 
70
        }
 
71
    }
 
72
        
 
73
    function filterStarts (rec)
 
74
    {
 
75
        if (rec.name.search(cview.componentFilter) == 0)
 
76
        {
 
77
            if (rec.isHidden)
 
78
                rec.unHide();
 
79
            cview.visibleComponents++;
 
80
        }
 
81
        else
 
82
        {
 
83
            if (!rec.isHidden)
 
84
                rec.hide();
 
85
        }
 
86
    }        
 
87
            
 
88
    var cmps  = cview.componentView.childData.childData;
 
89
    var count = cmps.length;
 
90
 
 
91
    cview.visibleComponents = 0;
 
92
 
 
93
    switch (cview.componentMode)
 
94
    {
 
95
        case "all":
 
96
            filterFunction = filterAll;
 
97
            break;
 
98
 
 
99
        case "contains":
 
100
            filterFunction = filterContains;
 
101
            break;
 
102
 
 
103
        case "starts-with":
 
104
            filterFunction = filterStarts;
 
105
            break;
 
106
    }
 
107
        
 
108
 
 
109
    for (var i = 0; i < count; ++i)
 
110
        filterFunction (cmps[i]);
 
111
    
 
112
    refreshLabels();
 
113
    
 
114
}
 
115
 
 
116
/*
 
117
 * Same as filterComponents() except it works on the interface list
 
118
 */
 
119
function filterInterfaces()
 
120
{
 
121
    function filterAll (rec)
 
122
    {
 
123
        if (rec.isHidden)
 
124
            rec.unHide();
 
125
        cview.visibleInterfaces++;
 
126
    }
 
127
        
 
128
    function filterContains (rec)
 
129
    {
 
130
        if (rec.name.search(cview.interfaceFilter) != -1)
 
131
        {
 
132
            if (rec.isHidden)
 
133
                rec.unHide();
 
134
            cview.visibleInterfaces++;
 
135
        }
 
136
        else
 
137
        {
 
138
            if (!rec.isHidden)
 
139
                rec.hide();
 
140
        }
 
141
    }
 
142
        
 
143
    function filterStarts (rec)
 
144
    {
 
145
        if (rec.name.search(cview.interfaceFilter) == 0)
 
146
        {
 
147
            if (rec.isHidden)
 
148
                rec.unHide();
 
149
            cview.visibleInterfaces++;
 
150
        }
 
151
        else
 
152
        {
 
153
            if (!rec.isHidden)
 
154
                rec.hide();
 
155
        }
 
156
    }
 
157
 
 
158
    var ifcs  = cview.interfaceView.childData.childData;
 
159
    var count = ifcs.length;
 
160
 
 
161
    cview.visibleInterfaces = 0;
 
162
 
 
163
    switch (cview.interfaceMode)
 
164
    {
 
165
        case "all":
 
166
            filterFunction = filterAll;
 
167
            break;
 
168
 
 
169
        case "contains":
 
170
            filterFunction = filterContains;
 
171
            break;
 
172
 
 
173
        case "starts-with":
 
174
            filterFunction = filterStarts;
 
175
            break;
 
176
    }
 
177
        
 
178
 
 
179
    for (var i = 0; i < count; ++i)
 
180
        filterFunction (ifcs[i]);
 
181
    
 
182
    refreshLabels();    
 
183
 
 
184
}
 
185
 
 
186
 
 
187
/*
 
188
 * Update the list headings based on the componentMode and
 
189
 * componentFilter properties of the cview object.
 
190
 */
 
191
function refreshLabels()
 
192
{
 
193
    var value = "";
 
194
    
 
195
    switch (cview.componentMode)
 
196
    {
 
197
        case "all":
 
198
            value = "All components";
 
199
            break;
 
200
            
 
201
        case "contains":
 
202
            value = "Components containing '" + cview.componentFilter + "'";
 
203
            break;
 
204
 
 
205
        case "starts-with":
 
206
            value = "Components starting with '" + cview.componentFilter + "'";
 
207
            break;
 
208
 
 
209
        default:
 
210
            value = "Components?";
 
211
            break;
 
212
    }
 
213
 
 
214
    value += " (" + cview.visibleComponents + "/" + cview.totalComponents + ")";
 
215
    document.getElementById("component-label").setAttribute ("value", value);
 
216
    
 
217
    switch (cview.interfaceMode)
 
218
    {
 
219
        case "all":
 
220
            value = "All interfaces";
 
221
            break;
 
222
            
 
223
        case "contains":
 
224
            value = "Interfaces containing '" + cview.interfaceFilter + "'";
 
225
            break;
 
226
 
 
227
        case "starts-with":
 
228
            value = "Interfaces starting with '" + cview.interfaceFilter + "'";
 
229
            break;
 
230
 
 
231
        case "implemented-by":
 
232
            if (!cview.interfaceFilter)
 
233
                value = "Please select a component";
 
234
            else
 
235
                value = "Interfaces implemented by '" +
 
236
                    Components.classes[cview.interfaceFilter] + "'";
 
237
            break;
 
238
 
 
239
        default:
 
240
            value = "Interfaces?";
 
241
            break;
 
242
    }
 
243
 
 
244
    value += " (" + cview.visibleInterfaces + "/" + cview.totalInterfaces + ")";
 
245
    document.getElementById("interface-label").setAttribute ("value", value);
 
246
}