~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

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

  • Committer: Aaron Bentley
  • Date: 2007-12-18 06:31:45 UTC
  • mto: (143.1.1 faster-history-creation)
  • mto: This revision was merged to the branch mainline in revision 144.
  • Revision ID: aaron.bentley@utoronto.ca-20071218063145-g66jtdp0xgd8czsl
Optimize History.from_subfolder

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