mirror of
https://github.com/flarum/core.git
synced 2025-07-20 08:11:27 +02:00
Working on responsive dropdown menu components.
This commit is contained in:
@@ -10,7 +10,7 @@ export default Ember.View.extend(PostStreamMixin, {
|
|||||||
@property templateName
|
@property templateName
|
||||||
@type String
|
@type String
|
||||||
*/
|
*/
|
||||||
templateName: 'discussion-scrollbar',
|
templateName: 'components/discussion-scrollbar',
|
||||||
classNames: ['scrubber', 'discussion-scrubber'],
|
classNames: ['scrubber', 'discussion-scrubber'],
|
||||||
|
|
||||||
// An object which represents/ecapsulates the scrollbar.
|
// An object which represents/ecapsulates the scrollbar.
|
||||||
@@ -28,7 +28,7 @@ export default Ember.View.extend(PostStreamMixin, {
|
|||||||
|
|
||||||
windowWasResized: function(event) {
|
windowWasResized: function(event) {
|
||||||
var view = event.data.view;
|
var view = event.data.view;
|
||||||
view.scrollbar.$.height($('#sidebar-content').height() + $('#sidebar-content').offset().top - view.scrollbar.$.offset().top - 80);
|
// view.scrollbar.$.height($('#sidebar-content').height() + $('#sidebar-content').offset().top - view.scrollbar.$.offset().top - 80);
|
||||||
view.scrollbar.update();
|
view.scrollbar.update();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
21
framework/core/ember/app/components/dropdown-button.js
Normal file
21
framework/core/ember/app/components/dropdown-button.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
export default Ember.Component.extend({
|
||||||
|
items: null, // NamedContainerView/Menu
|
||||||
|
layoutName: 'components/dropdown-button',
|
||||||
|
classNames: ['dropdown', 'btn-group'],
|
||||||
|
classNameBindings: ['itemCountClass'],
|
||||||
|
|
||||||
|
title: 'Controls',
|
||||||
|
icon: 'ellipsis-v',
|
||||||
|
buttonClass: 'btn-default',
|
||||||
|
menuClass: 'pull-right',
|
||||||
|
|
||||||
|
dropdownMenuClass: function() {
|
||||||
|
return 'dropdown-menu '+this.get('menuClass');
|
||||||
|
}.property('menuClass'),
|
||||||
|
|
||||||
|
itemCountClass: function() {
|
||||||
|
return 'item-count-'+this.get('items.length');
|
||||||
|
}.property('items')
|
||||||
|
});
|
24
framework/core/ember/app/components/dropdown-split.js
Normal file
24
framework/core/ember/app/components/dropdown-split.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
export default Ember.Component.extend({
|
||||||
|
items: null, // NamedContainerView/Menu
|
||||||
|
layoutName: 'components/dropdown-split',
|
||||||
|
classNames: ['dropdown', 'dropdown-split', 'btn-group'],
|
||||||
|
classNameBindings: ['itemCountClass'],
|
||||||
|
|
||||||
|
buttonClass: 'btn-default',
|
||||||
|
menuClass: 'pull-right',
|
||||||
|
icon: 'ellipsis-v',
|
||||||
|
|
||||||
|
mainButtonClass: function() {
|
||||||
|
return 'btn '+this.get('buttonClass');
|
||||||
|
}.property('buttonClass'),
|
||||||
|
|
||||||
|
dropdownMenuClass: function() {
|
||||||
|
return 'dropdown-menu '+this.get('menuClass');
|
||||||
|
}.property('menuClass'),
|
||||||
|
|
||||||
|
itemCountClass: function() {
|
||||||
|
return 'item-count-'+this.get('items.length');
|
||||||
|
}.property('items')
|
||||||
|
});
|
@@ -1,15 +0,0 @@
|
|||||||
import Ember from 'ember';
|
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
|
||||||
items: null, // NamedContainerView/Menu
|
|
||||||
layoutName: 'components/menu-split',
|
|
||||||
show: 1,
|
|
||||||
|
|
||||||
visibleItems: function() {
|
|
||||||
return this.get('items').slice(0, this.get('show'));
|
|
||||||
}.property('items'),
|
|
||||||
|
|
||||||
hiddenItems: function() {
|
|
||||||
return this.get('items').slice(this.get('show'));
|
|
||||||
}.property('items'),
|
|
||||||
});
|
|
@@ -0,0 +1,8 @@
|
|||||||
|
{{#if items}}
|
||||||
|
<button {{bind-attr class=":dropdown-toggle :btn buttonClass"}}>
|
||||||
|
{{fa-icon icon class="icon-glyph"}}
|
||||||
|
<span class="label">{{title}}</span>
|
||||||
|
{{fa-icon "caret-down" class="icon-caret"}}
|
||||||
|
</button>
|
||||||
|
{{menu-list items=items class=dropdownMenuClass}}
|
||||||
|
{{/if}}
|
@@ -0,0 +1,8 @@
|
|||||||
|
{{#if items}}
|
||||||
|
{{view items.firstItem class=mainButtonClass}}
|
||||||
|
<button {{bind-attr class=":dropdown-toggle :btn buttonClass"}}>
|
||||||
|
{{fa-icon "caret-down" class="icon-caret"}}
|
||||||
|
{{fa-icon icon class="icon-glyph"}}
|
||||||
|
</button>
|
||||||
|
{{menu-list items=items class=dropdownMenuClass}}
|
||||||
|
{{/if}}
|
@@ -1,13 +0,0 @@
|
|||||||
{{#if items}}
|
|
||||||
<div class="dropdown">
|
|
||||||
<div class="btn-group btn-group-suffix">
|
|
||||||
{{#each item in visibleItems}}
|
|
||||||
{{view item class="btn btn-default"}}
|
|
||||||
{{/each}}
|
|
||||||
{{#if hiddenItems}}
|
|
||||||
<button data-toggle="dropdown" class="dropdown-toggle btn btn-default">{{fa-icon "caret-down"}}</button>
|
|
||||||
{{menu-list items=hiddenItems class="dropdown-menu pull-right"}}
|
|
||||||
{{/if}}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
|
@@ -2,6 +2,10 @@
|
|||||||
{{partial "partials/discussion-header"}}
|
{{partial "partials/discussion-header"}}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
<nav class="discussion-nav">
|
||||||
|
{{view view.sidebar viewName="sidebar"}}
|
||||||
|
</nav>
|
||||||
|
|
||||||
<section class="items posts">
|
<section class="items posts">
|
||||||
{{#each item in postStream}}
|
{{#each item in postStream}}
|
||||||
|
|
||||||
@@ -11,9 +15,3 @@
|
|||||||
|
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
{{#if postStream.lastLoaded}}
|
|
||||||
<footer class="page-footer discussion-footer">
|
|
||||||
{{menu-list items=view.footerControls class="list-inline"}}
|
|
||||||
</footer>
|
|
||||||
{{/if}}
|
|
||||||
|
@@ -48,15 +48,7 @@ export default Ember.ArrayProxy.extend({
|
|||||||
|
|
||||||
firstItem: function() {
|
firstItem: function() {
|
||||||
return this.objectAt(0);
|
return this.objectAt(0);
|
||||||
}.property(),
|
}.property('content.@each'),
|
||||||
|
|
||||||
secondItem: function() {
|
|
||||||
return this.objectAt(1);
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
remainingItems: function() {
|
|
||||||
return this.slice(2);
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
getItem: function(name) {
|
getItem: function(name) {
|
||||||
return this.get('namedViews').get(name);
|
return this.get('namedViews').get(name);
|
||||||
|
@@ -1,11 +1,17 @@
|
|||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
import NamedContainerView from '../utils/named-container-view';
|
||||||
import Menu from '../utils/menu';
|
import Menu from '../utils/menu';
|
||||||
import MenuItem from '../components/menu-item';
|
import MenuItem from '../components/menu-item';
|
||||||
|
import DropdownSplit from '../components/dropdown-split';
|
||||||
|
import DropdownButton from '../components/dropdown-button';
|
||||||
|
import DiscussionScrollbar from '../components/discussion-scrollbar';
|
||||||
import PostStreamMixin from '../mixins/post-stream';
|
import PostStreamMixin from '../mixins/post-stream';
|
||||||
|
|
||||||
export default Ember.View.extend(Ember.Evented, PostStreamMixin, {
|
export default Ember.View.extend(Ember.Evented, PostStreamMixin, {
|
||||||
|
|
||||||
|
sidebar: Ember.ContainerView,
|
||||||
|
|
||||||
// Set up a new menu view that will contain controls to be shown in the
|
// Set up a new menu view that will contain controls to be shown in the
|
||||||
// footer. The template will only render these controls if the last post is
|
// footer. The template will only render these controls if the last post is
|
||||||
// showing.
|
// showing.
|
||||||
@@ -23,11 +29,8 @@ export default Ember.View.extend(Ember.Evented, PostStreamMixin, {
|
|||||||
|
|
||||||
didInsertElement: function() {
|
didInsertElement: function() {
|
||||||
|
|
||||||
this.set('footerControls', Menu.create());
|
// We've just inserted the discussion view.
|
||||||
|
this.trigger('populateSidebar', this.get('sidebar'));
|
||||||
// We've just inserted the discussion view. Let's start off by
|
|
||||||
// populating the footer controls menu object.
|
|
||||||
this.trigger('populateControls', this.get('footerControls'));
|
|
||||||
|
|
||||||
// Whenever the window's scroll position changes, we want to check to
|
// Whenever the window's scroll position changes, we want to check to
|
||||||
// see if any terminal 'gaps' are in the viewport and trigger their
|
// see if any terminal 'gaps' are in the viewport and trigger their
|
||||||
@@ -56,13 +59,26 @@ export default Ember.View.extend(Ember.Evented, PostStreamMixin, {
|
|||||||
controller.off('loadedIndex', this, this.loadedIndex);
|
controller.off('loadedIndex', this, this.loadedIndex);
|
||||||
},
|
},
|
||||||
|
|
||||||
// By default, we just populate the footer controls with a 'reply' button.
|
setupSidebar: function(sidebar) {
|
||||||
addDefaultControls: function(controls) {
|
this.set('controls', Menu.create());
|
||||||
|
this.trigger('populateControls', this.get('controls'));
|
||||||
|
sidebar.pushObject(DropdownSplit.create({
|
||||||
|
items: this.get('controls'),
|
||||||
|
icon: 'reply',
|
||||||
|
buttonClass: 'btn-primary',
|
||||||
|
menuClass: 'pull-right'
|
||||||
|
}));
|
||||||
|
|
||||||
|
sidebar.pushObject(DropdownButton.create({items: this.get('controls')}));
|
||||||
|
|
||||||
|
sidebar.pushObject(DiscussionScrollbar.create());
|
||||||
|
}.on('populateSidebar'),
|
||||||
|
|
||||||
|
setupControls: function(controls) {
|
||||||
var view = this;
|
var view = this;
|
||||||
var ReplyItem = MenuItem.extend({
|
var ReplyItem = MenuItem.extend({
|
||||||
title: 'Reply',
|
title: 'Reply',
|
||||||
icon: 'reply',
|
icon: 'reply',
|
||||||
className: 'btn btn-primary',
|
|
||||||
classNameBindings: ['className', 'replying:disabled'],
|
classNameBindings: ['className', 'replying:disabled'],
|
||||||
replying: function() {
|
replying: function() {
|
||||||
return this.get('parentController.controllers.composer.showing');
|
return this.get('parentController.controllers.composer.showing');
|
||||||
|
Reference in New Issue
Block a user