~snaggen/loggerhead/project_view_and_user_branches

« back to all changes in this revision

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

  • Committer: Martin Albisetti
  • Date: 2008-07-22 00:40:03 UTC
  • mfrom: (182 loggerhead.search_integration)
  • mto: This revision was merged to the branch mainline in revision 187.
  • Revision ID: argentina@gmail.com-20080722004003-lx1fp0tthpp6kl92
Merged from trunk, resolved billions of conflicts

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