Working drop downs for category changing

This commit is contained in:
Robin Ward 2013-10-24 15:19:15 -04:00
parent 9adcd1579d
commit ee2dd9d24c
5 changed files with 136 additions and 25 deletions

View File

@ -1,5 +1,19 @@
Discourse.DiscourseBreadcrumbsComponent = Ember.Component.extend({ Discourse.DiscourseBreadcrumbsComponent = Ember.Component.extend({
classNames: ['category-breadcrumb'], classNames: ['category-breadcrumb'],
tagName: 'ol', tagName: 'ol',
parentCategory: Em.computed.alias('category.parentCategory') parentCategory: Em.computed.alias('category.parentCategory'),
parentCategories: Em.computed.filter('categories', function(c) {
return !c.get('parentCategory');
}),
targetCategory: function() {
// Note we can't use Em.computed.or here because it returns a boolean not the object
return this.get('parentCategory') || this.get('category');
}.property('parentCategory', 'category'),
childCategories: Em.computed.filter('categories', function(c) {
return c.get('parentCategory') === this.get('targetCategory');
})
}); });

View File

@ -0,0 +1,44 @@
Discourse.DiscourseCategorydropComponent = Ember.Component.extend({
classNameBindings: ['category::no-category', 'categories:has-drop'],
tagName: 'li',
iconClass: function() {
if (this.get('expanded')) { return "icon icon-caret-down"; }
return "icon icon-caret-right";
}.property('expanded'),
actions: {
expand: function() {
if (this.get('expanded')) {
this.close();
return;
}
if (this.get('categories')) {
this.set('expanded', true);
}
var self = this,
$dropdown = this.$()[0];
$('html').on('click.category-drop', function(e) {
var closest = $(e.target).closest($dropdown);
return (closest.length && closest[0] === $dropdown) ? true : self.close();
});
}
},
close: function() {
$('html').off('click.category-drop');
this.set('expanded', false);
},
didInsertElement: function() {
},
willDestroyElement: function() {
$('html').off('click.category-drop');
}
});

View File

@ -1,18 +1,9 @@
<li> {{discourse-categorydrop title=title categories=parentCategories}}
<a href="/">{{title}}</a>
<i class='icon icon-caret-right first-caret'></i> {{discourse-categorydrop category=targetCategory categories=childCategories}}
</li>
{{#if parentCategory}} {{#if parentCategory}}
<li>
{{discourse-categorydrop category=parentCategory categories=categories}}
</li>
{{/if}}
{{#if category}}
<li>
{{discourse-categorydrop category=category}} {{discourse-categorydrop category=category}}
</li>
{{/if}} {{/if}}
<div class='clear'></div> <div class='clear'></div>

View File

@ -1,4 +1,15 @@
{{#if category}}
{{categoryLink category}} {{categoryLink category}}
{{#if categories}} {{else}}
<button {{action expand}}><i class='icon icon-caret-right'></i></button> <a href="/">{{title}}</a>
{{/if}}
{{#if categories}}
<button {{action expand}}><i {{bindAttr class='iconClass'}}></i></button>
<section {{bindAttr class="expanded::hidden :category-menu"}} class='chooser'>
{{#each categories}}
<div class='cat'>{{categoryLink this}}</div>
{{/each}}
</section>
{{/if}} {{/if}}

View File

@ -203,25 +203,62 @@ ol.category-breadcrumb {
margin: 0 0 10px 0; margin: 0 0 10px 0;
padding: 0; padding: 0;
.first-caret {
margin: 0 3px 0 3px;
color: #666;
font-size: 13px;
}
li { li {
float: left; float: left;
margin-right: 5px; margin-right: 5px;
border: 1px solid transparent; border: 1px solid transparent;
height: 21px;
padding-top: 2px; &.no-category {
font-size: 13px;
a {
margin-right: 3px;
margin-left: 4px;
&:hover {
color: black;
}
}
button {
padding-left: 6px;
&:hover {
background-color: #eee;
}
}
&.has-drop:hover {
background-color: #f9f9f9;
button {
border-left: 1px solid #bbb;
}
}
.category-menu {
margin-left: -1px;
padding: 8px 5px 0 3px;
}
}
.badge-category {
margin: 0;
display: inline-block;
padding: 1px 6px 2px 6px;
}
button { button {
background: none; background: none;
border: 1px solid transparent; border: 1px solid transparent;
padding: 0px 4px; padding: 0 4px 0 2px;
margin: 0; margin: 0;
height: 22px;
color: #666; color: #666;
line-height: 13px;
text-align: center;
i.icon-caret-down {
margin-left: -2px;
}
} }
&.has-drop:hover { &.has-drop:hover {
@ -238,5 +275,19 @@ ol.category-breadcrumb {
clear: both; clear: both;
} }
.category-menu {
overflow-x: hidden;
overflow-y: scroll;
position: absolute;
border: 1px solid #ccc;
background-color: white;
width: 200px;
height: 200px;
padding: 8px 5px 0 7px;
z-index: 100;
div {
margin-bottom: 10px;
}
}
} }