defer rendering of the site map

add new and unread links in the site map categories section
This commit is contained in:
Sam 2013-11-19 10:41:57 +11:00
parent a45334d2b9
commit 3ce6a7be4a
3 changed files with 31 additions and 3 deletions

View File

@ -0,0 +1,13 @@
{{categoryLink category allowUncategorized=true}}
{{#if currentUser}}
{{#with view.category}}
{{#if unreadTopics}}
<a href={{unbound unreadUrl}} class='badge new-posts badge-notification' title='{{i18n topic.unread_topics count="unreadTopics"}}'>{{unbound unreadTopics}}</a>
{{/if}}
{{#if newTopics}}
<a href={{unbound newUrl}} class='badge new-posts badge-notification' title='{{i18n topic.new_topics count="newTopics"}}'>{{unbound newTopics}} <i class='icon icon-asterisk'></i></a>
{{/if}}
{{/with}}
{{else}}
<b>{{unbound category.topic_count}}</b></a>
{{/if}}

View File

@ -74,6 +74,7 @@
{{else}} {{else}}
<a class='icon' <a class='icon'
data-dropdown="site-map-dropdown" data-dropdown="site-map-dropdown"
data-render="renderSiteMap"
href="#" href="#"
title='{{i18n site_map}}'> title='{{i18n site_map}}'>
<i class='icon-reorder'></i> <i class='icon-reorder'></i>
@ -96,6 +97,7 @@
{{render notifications notifications}} {{render notifications notifications}}
{{#if view.renderSiteMap}}
<section class='d-dropdown' id='site-map-dropdown'> <section class='d-dropdown' id='site-map-dropdown'>
<ul class="location-links"> <ul class="location-links">
{{#if currentUser.staff}} {{#if currentUser.staff}}
@ -131,14 +133,14 @@
{{#each categories}} {{#each categories}}
<li class='category'> <li class='category'>
{{categoryLink this allowUncategorized=true}} {{discourse-header-category-info category=this currentUser=controller.currentUser}}
<b>{{unbound topic_count}}</b></a>
</li> </li>
{{/each}} {{/each}}
</ul> </ul>
{{/if}} {{/if}}
</section> </section>
{{/if}}
</div> </div>
</div> </div>

View File

@ -20,6 +20,19 @@ Discourse.HeaderView = Discourse.View.extend({
$ul = $target.closest('ul'), $ul = $target.closest('ul'),
$html = $('html'); $html = $('html');
// we need to ensure we are rendered,
// this optimises the speed of the initial render
var render = $target.data('render');
if(render){
if(!this.get(render)){
this.set(render, true);
Em.run.next(this, function(){
this.showDropdown($target);
});
return;
}
}
var hideDropdown = function() { var hideDropdown = function() {
$dropdown.fadeOut('fast'); $dropdown.fadeOut('fast');
$li.removeClass('active'); $li.removeClass('active');
@ -27,7 +40,7 @@ Discourse.HeaderView = Discourse.View.extend({
return $html.off('click.d-dropdown'); return $html.off('click.d-dropdown');
}; };
// if a dropdown is active and the user clics on it, close it // if a dropdown is active and the user clicks on it, close it
if($li.hasClass('active')) { return hideDropdown(); } if($li.hasClass('active')) { return hideDropdown(); }
// otherwhise, mark it as active // otherwhise, mark it as active
$li.addClass('active'); $li.addClass('active');