~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/static/javascript/custom.js

  • Committer: Michael Hudson
  • Date: 2009-02-19 01:24:20 UTC
  • mto: This revision was merged to the branch mainline in revision 271.
  • Revision ID: michael.hudson@canonical.com-20090219012420-c6s1j3etl2t4r7wa
defer loading of plugins until after we've set up the logging

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
var global_timeout_id = null;
 
2
var global_search_request = null;
 
3
 
 
4
window.addEvent('domready', function() 
 
5
{
 
6
    var search_box = $('q');
 
7
    if ($defined(search_box))
 
8
    {
 
9
        search_box.removeEvents();
 
10
        search_box.addEvents(
 
11
        {
 
12
            keyup: function()
 
13
            {
 
14
                if($('q').value == '')
 
15
                {
 
16
                    $('search_terms').setStyle('display','none');
 
17
                }
 
18
                else
 
19
                {
 
20
                    if (null != global_timeout_id)
 
21
                    {
 
22
                        clearTimeout(global_timeout_id);
 
23
                    }
 
24
                        global_timeout_id = setTimeout('$("q").fireEvent("search",$("q").value)',200);
 
25
                }
 
26
            },
 
27
 
 
28
            search: function(query)
 
29
            {
 
30
                url = global_path + 'search?query=' + query;
 
31
 
 
32
                if ($defined(global_search_request))
 
33
                {
 
34
                    global_search_request.cancel();
 
35
                }
 
36
                global_search_request = new Request({'url':url,'method':'get','onComplete':function(response)
 
37
                  {
 
38
                     cool_search(response,query);
 
39
                 }});
 
40
 
 
41
                global_search_request.send('');
 
42
                var posicion = search_box.getPosition();
 
43
                var size     = search_box.getSize();
 
44
 
 
45
                $('search_terms').setStyle('position','absolute');
 
46
                $('search_terms').setStyle('left',posicion.x);
 
47
                $('search_terms').setStyle('top',posicion.y + size.y);
 
48
                $('search_terms').setStyle('display','block');
 
49
                $('search_terms').set('html','Loading...');
 
50
 
 
51
                new Request({'url':url,'method':'get','onComplete':cool_search}).send('');
 
52
 
 
53
 
 
54
            }
 
55
        });
 
56
    }
 
57
});
 
58
 
 
59
function cool_search(response, query)
 
60
{
 
61
        var posicion = $('q').getPosition();
 
62
        var size     = $('q').getSize();
 
63
    var current_query = $('q').get('value');
 
64
    if (current_query == query)
 
65
    {
 
66
            $('search_terms').set('html',response);
 
67
            $('search_terms').setStyle('display','block');
 
68
            $('search_terms').setStyle('position','absolute');
 
69
            $('search_terms').setStyle('left',posicion.x);
 
70
            $('search_terms').setStyle('top',posicion.y + size.y);
 
71
    }
 
72
}
 
73
 
 
74
function hide_search()
 
75
{
 
76
    hide_div = setTimeout("$('search_terms').setStyle('display','none')", 300);
 
77
}
 
78
var Colapsable = new Class({
 
79
    initialize: function(item,expand_icon,open_content,close_content,is_open)
 
80
    {
 
81
        this.is_open = false;
 
82
        if ($defined(is_open))
 
83
        {
 
84
            this.is_open = is_open;
 
85
        }
 
86
        this.item = item;
 
87
        item.set('colapsable',this);
 
88
        this.open_content  = open_content;
 
89
        this.close_content = close_content;
 
90
        this.expand_icon   = expand_icon;
 
91
 
 
92
        var expander = new Fx.Slide(this.item, { duration: 200 } );
 
93
        if (!this.is_open)
 
94
        {
 
95
            expander.hide();
 
96
            if ($defined(this.expand_icon))
 
97
            {
 
98
                this.expand_icon.set('src',this.expand_icon.title);
 
99
            }
 
100
        }
 
101
        else
 
102
        {
 
103
            if ($defined(this.expand_icon))
 
104
            {
 
105
                this.expand_icon.set('src',this.expand_icon.alt);
 
106
            }
 
107
        }
 
108
    },
 
109
 
 
110
    open: function()
 
111
    {
 
112
        this.item.setStyle('display', 'block');
 
113
        var expander = this.item.get('slide');
 
114
        expander.slideIn();
 
115
        if ($defined(this.open_content))
 
116
        {
 
117
            for (var i=0;i<this.open_content.length;++i)
 
118
            {
 
119
                this.open_content[i].setStyle('display','block');
 
120
            }
 
121
                }
 
122
                
 
123
        if ($defined(this.close_content))
 
124
        {
 
125
            for (var i=0;i<this.close_content.length;++i)
 
126
            {
 
127
                this.close_content[i].setStyle('display','none');
 
128
            }
 
129
        }
 
130
 
 
131
        if ($defined(this.expand_icon))
 
132
        {
 
133
            this.expand_icon.set('src',this.expand_icon.alt);
 
134
        }
 
135
        this.is_open = true;
 
136
    },
 
137
 
 
138
    close: function()
 
139
    {
 
140
        var expander = this.item.get('slide');
 
141
        expander.slideOut();
 
142
        if ($defined(this.open_content))
 
143
        {
 
144
            for (var i=0;i<this.open_content.length;++i)
 
145
            {
 
146
                this.open_content[i].setStyle('display','none');
 
147
            }
 
148
        }
 
149
 
 
150
        if ($defined(this.close_content))
 
151
        {
 
152
            for (var i=0;i<this.close_content.length;++i)
 
153
            {
 
154
                this.close_content[i].setStyle('display','block');
 
155
            }
 
156
        }
 
157
        if ($defined(this.expand_icon))
 
158
        {
 
159
            this.expand_icon.set('src',this.expand_icon.title);
 
160
        }
 
161
        this.is_open = false;
 
162
    },
 
163
 
 
164
    isOpen : function()
 
165
    {
 
166
        return this.is_open;
 
167
    },
 
168
 
 
169
    toggle: function()
 
170
    {
 
171
        if (this.isOpen())
 
172
        {
 
173
            this.close();
 
174
        }
 
175
        else
 
176
        {
 
177
            this.open();
 
178
        }
 
179
    }
 
180
    });
 
181
 
 
182
 
 
183
window.addEvent('domready', function()
 
184
{
 
185
    $$('.revision_log').each(function(item, i)
 
186
    {
 
187
        var item_slide = item.getElement('.revisioninfo');
 
188
        var open_content  = new Array();
 
189
        var close_content = new Array();
 
190
        open_content.push(item.getElement('.long_description'));
 
191
        close_content.push(item.getElement('.short_description'));
 
192
        var expand_icon = item.getElement('.expand_icon');
 
193
        var colapsable = new Colapsable(item_slide,expand_icon,open_content,close_content);
 
194
        
 
195
        item.getElement('.expand_revisioninfo').addEvent('click',function(){colapsable.toggle();});
 
196
        item.colapsable = colapsable;
 
197
    });
 
198
 
 
199
    $$('.diffBox').each(function(item, i)
 
200
    {
 
201
        var item_slide = item.getNext('.diffinfo');
 
202
        var expand_icon = item.getElement( '.expand_diff' );
 
203
        var colapsable = new Colapsable(item_slide,expand_icon,null,null,true);
 
204
        item.getElement( '.expand_diff' ).addEvent( 'click', function(){colapsable.toggle();});
 
205
        item.colapsable=colapsable;
 
206
    });
 
207
});
 
208
 
 
209
function toggle_expand_all(action)
 
210
{
 
211
    $$('.revision_log').each(function(item, i)
 
212
    {
 
213
        var colapsable = item.colapsable;
 
214
        if(action == 'close')
 
215
        {
 
216
            $('expand_all').setStyle('display','block');
 
217
            $('collapse_all').setStyle('display','none');
 
218
            colapsable.close();
 
219
        }
 
220
        else if(action == 'open')
 
221
        {
 
222
            $('expand_all').setStyle('display','none');
 
223
            $('collapse_all').setStyle('display','block');
 
224
            colapsable.open();
 
225
        }
 
226
    });
 
227
}
 
228
 
 
229
function toggle_expand_all_revisionview(action)
 
230
{
 
231
    $$('.diffBox').each(function(item, i)
 
232
    {
 
233
        var colapsable = item.colapsable;
 
234
        if(action == 'close')
 
235
        {
 
236
            $('expand_all').setStyle('display','block');
 
237
            $('collapse_all').setStyle('display','none');
 
238
            colapsable.close();
 
239
        }
 
240
        else if(action == 'open')
 
241
        {
 
242
            $('expand_all').setStyle('display','none');
 
243
            $('collapse_all').setStyle('display','block');
 
244
            colapsable.open();
 
245
        }
 
246
    });
 
247
}
 
248