~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

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

  • Committer: Martin Albisetti
  • Date: 2009-01-23 21:40:04 UTC
  • mto: This revision was merged to the branch mainline in revision 263.
  • Revision ID: argentina@gmail.com-20090123214004-yfhi7k3xyhlk1tc8
Tweak NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Y = YUI().use("node", "io-base", "io-queue", "anim");
2
 
 
3
 
Y.io.queue.size(2);
4
 
 
5
1
var global_timeout_id = null;
6
2
var global_search_request = null;
7
3
 
8
 
Y.on(
9
 
  'domready',
10
 
  function()
11
 
  {
12
 
    var search_box = Y.get('#q');
13
 
    if (!Y.Lang.isNull(search_box))
 
4
window.addEvent('domready', function() 
 
5
{
 
6
    var search_box = $('q');
 
7
    if ($defined(search_box))
14
8
    {
15
 
      function get_suggestions() {
16
 
        var query = search_box.get('value');
17
 
        var url = global_path + 'search?query=' + query;
18
 
 
19
 
        if (!Y.Lang.isNull(global_search_request))
20
 
        {
21
 
          global_search_request.abort();
22
 
        }
23
 
        global_search_request = Y.io(
24
 
          url,
25
 
          {
26
 
            on: {complete: cool_search},
27
 
            arguments: [query]
28
 
          }
29
 
        );
30
 
 
31
 
        var region = search_box.get('region');
32
 
        var current_query = search_box.get('value');
33
 
 
34
 
        Y.get('#search_terms').setStyle('display', 'block');
35
 
        Y.get('#search_terms').setStyle('position', 'absolute');
36
 
        Y.get('#search_terms').setStyle('left', region.left);
37
 
        Y.get('#search_terms').setStyle('top', region.bottom);
38
 
        Y.get('#search_terms').set('innerHTML','Loading...');
39
 
      }
40
 
      search_box.on(
41
 
        "keyup",
42
 
        function(event)
43
 
        {
44
 
          if(search_box.get('value') == '')
45
 
          {
46
 
            Y.get('#search_terms').setStyle('display', 'none');
47
 
          }
48
 
          else
49
 
          {
50
 
            if (null != global_timeout_id)
51
 
            {
52
 
              clearTimeout(global_timeout_id);
 
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
 
53
54
            }
54
 
            global_timeout_id = setTimeout(get_suggestions, 200);
55
 
          }
56
55
        });
57
56
    }
58
 
  });
 
57
});
59
58
 
60
 
function cool_search(tid, response, query)
 
59
function cool_search(response, query)
61
60
{
62
 
  var q = Y.get('#q');
63
 
  var region = q.get('region');
64
 
  var current_query = q.get('value');
65
 
  if (current_query == query)
66
 
  {
67
 
    Y.get('#search_terms').set('innerHTML', response.responseText);
68
 
    Y.get('#search_terms').setStyle('display', 'block');
69
 
    Y.get('#search_terms').setStyle('position', 'absolute');
70
 
    Y.get('#search_terms').setStyle('left', region.left);
71
 
    Y.get('#search_terms').setStyle('top', region.bottom);
72
 
  }
 
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
    }
73
72
}
74
73
 
75
74
function hide_search()
76
75
{
77
 
  setTimeout("Y.get('#search_terms').setStyle('display','none')", 300);
78
 
}
79
 
 
80
 
function Collapsable(config)
81
 
{
82
 
  this.is_open = config.is_open;
83
 
  this.source_target = config.source_target;
84
 
  this.open_node = config.open_node;
85
 
  this.close_node = config.close_node;
86
 
  this.expand_icon = config.expand_icon;
87
 
  this.source = config.source;
88
 
  this.loading = config.loading;
89
 
  this.node_process = config.node_process;
90
 
}
91
 
 
92
 
function get_height(node) {
93
 
  node.setStyle('position', 'absolute');
94
 
  node.setStyle('top', -1000000000);
95
 
  node.setStyle('display', 'block');
96
 
  var height = node.get('region').height;
97
 
  node.setStyle('display', 'none');
98
 
  node.setStyle('position', 'static');
99
 
  node.setStyle('top', 'auto');
100
 
  return height;
101
 
}
102
 
 
103
 
Collapsable.prototype._load_finished = function(tid, res, args)
104
 
{
105
 
  var newNode = Y.Node.create(res.responseText.split('\n').splice(1).join(''));
106
 
  if (this.node_process)
107
 
    this.node_process(newNode);
108
 
  this.source_target.ancestor().replaceChild(newNode, this.source_target);
109
 
  this.source_target = null;
110
 
  this.source = null;
111
 
  this.loading.setStyle('display', 'none');
112
 
  this.open(args[0]);
113
 
};
114
 
 
115
 
Collapsable.prototype.open = function(callback)
116
 
{
117
 
  if (this.source) {
118
 
    this.loading.setStyle('display', 'block');
119
 
    Y.io.queue(
120
 
      this.source,
121
 
      {
122
 
        on: {complete: this._load_finished},
123
 
        arguments: [callback],
124
 
        context: this
125
 
      });
126
 
    return;
127
 
  }
128
 
 
129
 
  var open_height = get_height(this.open_node);
130
 
 
131
 
  var close_height;
132
 
  if (this.close_node) {
133
 
    close_height = this.close_node.get('region').height;
134
 
  }
135
 
  else {
136
 
    close_height = 0;
137
 
  }
138
 
 
139
 
  var container = this.open_node.ancestor('.container');
140
 
 
141
 
  var anim = new Y.Anim(
142
 
    {
143
 
      node: container,
144
 
      from: {
145
 
        marginBottom: close_height - open_height
146
 
      },
147
 
      to: {
148
 
        marginBottom: 0
149
 
      },
150
 
      duration: 0.2
151
 
    });
152
 
 
153
 
  anim.on('end', this.openComplete, this, callback);
154
 
  container.setStyle('marginBottom', close_height - open_height);
155
 
  if (this.close_node) {
156
 
    this.close_node.setStyle('display', 'none');
157
 
  }
158
 
  this.open_node.setStyle('display', 'block');
159
 
  this.expand_icon.set('src', this.expand_icon.get('alt'));
160
 
  anim.run();
161
 
};
162
 
 
163
 
Collapsable.prototype.openComplete = function(evt, callback)
164
 
{
165
 
  if (callback) callback();
166
 
  this.is_open = true;
167
 
};
168
 
 
169
 
Collapsable.prototype.close = function()
170
 
{
171
 
  var container = this.open_node.ancestor('.container');
172
 
 
173
 
  var open_height = this.open_node.get('region').height;
174
 
 
175
 
  var close_height;
176
 
  if (this.close_node) {
177
 
    close_height = get_height(this.close_node);
178
 
  }
179
 
  else {
180
 
    close_height = 0;
181
 
  }
182
 
 
183
 
  var anim = new Y.Anim(
184
 
    {
185
 
      node: container,
186
 
      from: {
187
 
        marginBottom: 0
188
 
      },
189
 
      to: {
190
 
        marginBottom: close_height - open_height
191
 
      },
192
 
      duration: 0.2
193
 
    });
194
 
  anim.on("end", this.closeComplete, this);
195
 
  anim.run();
196
 
};
197
 
 
198
 
Collapsable.prototype.closeComplete = function () {
199
 
  this.open_node.setStyle('display', 'none');
200
 
  if (this.close_node) {
201
 
    this.close_node.setStyle('display', 'block');
202
 
  }
203
 
  this.open_node.ancestor('.container').setStyle('marginBottom', 0);
204
 
  this.expand_icon.set('src', this.expand_icon.get('title'));
205
 
  this.is_open = false;
206
 
};
207
 
 
208
 
Collapsable.prototype.toggle = function()
209
 
{
210
 
  if (this.is_open)
211
 
  {
212
 
    this.close();
213
 
  }
214
 
  else
215
 
  {
216
 
    this.open();
217
 
  }
218
 
};
 
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
}
219
248