diff rhodecode/templates/base/base.html @ 1608:0069657aaf42 beta

lazy load of branches and tags menu - to reduce load on repositories with large amount of branches and tags. - reduce load times of pages significantly on large repos
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 29 Oct 2011 00:57:09 +0200
parents 6ebb165c3942
children b1e1dffd595c
line wrap: on
line diff
--- a/rhodecode/templates/base/base.html	Fri Oct 28 02:40:22 2011 +0200
+++ b/rhodecode/templates/base/base.html	Sat Oct 29 00:57:09 2011 +0200
@@ -149,60 +149,6 @@
                             <a href="#">${_('loading...')}</a>
                         </li>
 					</ul>
-					<script type="text/javascript">
-					   YUE.on('repo_switcher','mouseover',function(){
-						      function qfilter(){
-						         var S = YAHOO.util.Selector;
-						         
-						         var q_filter = YUD.get('q_filter_rs');
-						         var F = YAHOO.namespace('q_filter_rs'); 
-						         
-						         YUE.on(q_filter,'click',function(){
-						            q_filter.value = '';
-						         });
-						    
-						         F.filterTimeout = null;
-						         
-						         F.updateFilter  = function() { 
-						            // Reset timeout 
-						            F.filterTimeout = null;
-						            
-						            var obsolete = [];
-						            var nodes = S.query('ul#repo_switcher_list li a.repo_name');
-						            var req = YUD.get('q_filter_rs').value;
-						            for (n in nodes){
-						                YUD.setStyle(nodes[n].parentNode,'display','')
-						            }
-						            if (req){
-						                for (n in nodes){
-						                    if (nodes[n].innerHTML.toLowerCase().indexOf(req) == -1) {
-						                        obsolete.push(nodes[n]); 
-						                    }
-						                }
-						                if(obsolete){
-						                    for (n in obsolete){
-						                        YUD.setStyle(obsolete[n].parentNode,'display','none');
-						                    }
-						                }
-						            }
-						         }
-						         
-						         YUE.on(q_filter,'keyup',function(e){
-						             clearTimeout(F.filterTimeout); 
-						             F.filterTimeout = setTimeout(F.updateFilter,600); 
-						         });
-						}
-						   var loaded = YUD.hasClass('repo_switcher','loaded');
-						   if(!loaded){
-							   YUD.addClass('repo_switcher','loaded');
-							   ypjax("${h.url('repo_switcher')}",'repo_switcher_list',
-								   function(o){qfilter();},
-								   function(o){YUD.removeClass('repo_switcher','loaded');}
-								   ,null);
-						   }
-						   return false;
-					   });
-					</script>	
 				</li>
 				
 	            <li ${is_current('summary')}>
@@ -231,38 +177,15 @@
                 </li>   	
                 
                 <li ${is_current('switch_to')}>
-                   <a title="${_('Switch to')}" href="#">
+                   <a id="branch_tag_switcher" title="${_('Switch to')}" href="#">
                    <span class="icon">
                        <img src="${h.url('/images/icons/arrow_switch.png')}" alt="${_('Switch to')}" />
                    </span>
                    <span>${_('Switch to')}</span>                 
                    </a>    
-                    <ul>
-                        <li>
-                            ${h.link_to('%s (%s)' % (_('branches'),len(c.rhodecode_repo.branches.values()),),h.url('branches_home',repo_name=c.repo_name),class_='branches childs')}
-                            <ul>
-                            %if c.rhodecode_repo.branches.values():
-						        %for cnt,branch in enumerate(c.rhodecode_repo.branches.items()):
-						            <li>${h.link_to('%s - %s' % (branch[0],h.short_id(branch[1])),h.url('files_home',repo_name=c.repo_name,revision=branch[1]))}</li>
-						        %endfor
-						    %else:
-						    	<li>${h.link_to(_('There are no branches yet'),'#')}</li>
-						    %endif
-                            </ul>                        
-                        </li>
-                        <li>
-                            ${h.link_to('%s (%s)' % (_('tags'),len(c.rhodecode_repo.tags.values()),),h.url('tags_home',repo_name=c.repo_name),class_='tags childs')}
-                            <ul>
-                            %if c.rhodecode_repo.tags.values():
-                                %for cnt,tag in enumerate(c.rhodecode_repo.tags.items()):
-                                 <li>${h.link_to('%s - %s' % (tag[0],h.short_id(tag[1])),h.url('files_home',repo_name=c.repo_name,revision=tag[1]))}</li>
-                                %endfor
-                            %else:
-                            	<li>${h.link_to(_('There are no tags yet'),'#')}</li>
-                            %endif
-                            </ul>                        
-                        </li>                        
-                    </ul>
+                    <ul id="switch_to_list" class="switch_to">
+                        <li><a href="#">${_('loading...')}</a></li>
+                    </ul>                     
                 </li>
                 <li ${is_current('files')}>
                    <a title="${_('Files')}" href="${h.url('files_home',repo_name=c.repo_name)}">
@@ -329,8 +252,73 @@
                     <span class="short">${c.repository_forks}</span>
                     </a>
                 </li>                
-                
 	        </ul>
+            <script type="text/javascript">
+               YUE.on('repo_switcher','mouseover',function(){
+                      function qfilter(){
+                         var S = YAHOO.util.Selector;
+                         
+                         var q_filter = YUD.get('q_filter_rs');
+                         var F = YAHOO.namespace('q_filter_rs'); 
+                         
+                         YUE.on(q_filter,'click',function(){
+                            q_filter.value = '';
+                         });
+                    
+                         F.filterTimeout = null;
+                         
+                         F.updateFilter  = function() { 
+                            // Reset timeout 
+                            F.filterTimeout = null;
+                            
+                            var obsolete = [];
+                            var nodes = S.query('ul#repo_switcher_list li a.repo_name');
+                            var req = YUD.get('q_filter_rs').value.toLowerCase();
+                            for (n in nodes){
+                                YUD.setStyle(nodes[n].parentNode,'display','')
+                            }
+                            if (req){
+                                for (n in nodes){
+                                    if (nodes[n].innerHTML.toLowerCase().indexOf(req) == -1) {
+                                        obsolete.push(nodes[n]); 
+                                    }
+                                }
+                                if(obsolete){
+                                    for (n in obsolete){
+                                        YUD.setStyle(obsolete[n].parentNode,'display','none');
+                                    }
+                                }
+                            }
+                         }
+                         
+                         YUE.on(q_filter,'keyup',function(e){
+                             clearTimeout(F.filterTimeout); 
+                             F.filterTimeout = setTimeout(F.updateFilter,600); 
+                         });
+                }
+                   var loaded = YUD.hasClass('repo_switcher','loaded');
+                   if(!loaded){
+                       YUD.addClass('repo_switcher','loaded');
+                       ypjax("${h.url('repo_switcher')}",'repo_switcher_list',
+                           function(o){qfilter();},
+                           function(o){YUD.removeClass('repo_switcher','loaded');}
+                           ,null);
+                   }
+                   return false;
+               });
+
+            YUE.on('branch_tag_switcher','mouseover',function(){
+               var loaded = YUD.hasClass('branch_tag_switcher','loaded');
+               if(!loaded){
+                   YUD.addClass('branch_tag_switcher','loaded');
+                   ypjax("${h.url('branch_tag_switcher',repo_name=c.repo_name)}",'switch_to_list',
+                       function(o){},
+                       function(o){YUD.removeClass('branch_tag_switcher','loaded');}
+                       ,null);
+               }
+               return false;
+            });
+            </script>             
 		%else:
 		    ##ROOT MENU
             <ul id="quick">
@@ -373,5 +361,5 @@
                 </li>
 				%endif
 			</ul>
-		%endif    
+		%endif
 </%def>