mirror of
https://github.com/flarum/framework.git
synced 2024-12-04 00:03:37 +08:00
c28307903b
HTMLBars goodness! Since there was some breakage and a lot of fiddling around to get some things working, I took this opportunity to do a big cleanup of the whole Ember app. I accidentally worked on some new features too :3 Note that the app is still broken right now, pending on https://github.com/emberjs/ember.js/issues/10401 Cleanup: - Restructuring of components - Consolidation of some stuff into mixins, cleanup of some APIs that will be public - Change all instances of .property() / .observes() / .on() to Ember.computed() / Ember.observer() / Ember.on() respectively (I think it is more readable) - More comments - Start conforming to a code style (2 spaces for indentation) New features: - Post hiding/restoring - Mark individual discussions as read by clicking - Clicking on a read discussion jumps to the end - Mark all discussions as read - Progressively mark the discussion as read as the page is scrolled - Unordered list post formatting - Post permalink popup Demo once that Ember regression is fixed!
100 lines
2.8 KiB
JavaScript
100 lines
2.8 KiB
JavaScript
import Ember from 'ember';
|
|
|
|
export var PositionEnum = {
|
|
HIDDEN: 'hidden',
|
|
NORMAL: 'normal',
|
|
MINIMIZED: 'minimized',
|
|
FULLSCREEN: 'fullscreen'
|
|
};
|
|
|
|
export default Ember.Controller.extend(Ember.Evented, {
|
|
content: null,
|
|
position: PositionEnum.HIDDEN,
|
|
|
|
visible: Ember.computed.or('normal', 'minimized', 'fullscreen'),
|
|
normal: Ember.computed.equal('position', PositionEnum.NORMAL),
|
|
minimized: Ember.computed.equal('position', PositionEnum.MINIMIZED),
|
|
fullscreen: Ember.computed.equal('position', PositionEnum.FULLSCREEN),
|
|
|
|
// Switch out the composer's content for a new component. The old
|
|
// component will be given the opportunity to abort the switch. Note:
|
|
// there appears to be a bug in Ember where the content binding won't
|
|
// update in the view if we switch the value out immediately. As a
|
|
// workaround, we set it to null, and then set it to its new value in the
|
|
// next run loop iteration.
|
|
switchContent: function(newContent) {
|
|
var composer = this;
|
|
this.confirmExit().then(function() {
|
|
composer.set('content', null);
|
|
Ember.run.next(function() {
|
|
newContent.composer = composer;
|
|
composer.set('content', newContent);
|
|
});
|
|
});
|
|
},
|
|
|
|
// Ask the content component if it's OK to close it, and give it the
|
|
// opportunity to abort. The content component must respond to the
|
|
// `willExit(abort)` action, and call `abort()` if we should not proceed.
|
|
confirmExit: function() {
|
|
var composer = this;
|
|
var promise = new Ember.RSVP.Promise(function(resolve, reject) {
|
|
var content = composer.get('content');
|
|
if (content) {
|
|
content.send('willExit', reject);
|
|
}
|
|
resolve();
|
|
});
|
|
return promise;
|
|
},
|
|
|
|
actions: {
|
|
show: function() {
|
|
var composer = this;
|
|
|
|
// We do this in the next run loop because we need to wait for new
|
|
// content to be switched in. See `switchContent` above.
|
|
Ember.run.next(function() {
|
|
composer.set('position', PositionEnum.NORMAL);
|
|
composer.trigger('focus');
|
|
});
|
|
},
|
|
|
|
hide: function() {
|
|
this.set('position', PositionEnum.HIDDEN);
|
|
},
|
|
|
|
clearContent: function() {
|
|
this.set('content', null);
|
|
},
|
|
|
|
close: function() {
|
|
var composer = this;
|
|
this.confirmExit().then(function() {
|
|
composer.send('hide');
|
|
});
|
|
},
|
|
|
|
minimize: function() {
|
|
if (this.get('position') !== PositionEnum.HIDDEN) {
|
|
this.set('position', PositionEnum.MINIMIZED);
|
|
}
|
|
},
|
|
|
|
fullscreen: function() {
|
|
if (this.get('position') !== PositionEnum.HIDDEN) {
|
|
this.set('position', PositionEnum.FULLSCREEN);
|
|
this.trigger('focus');
|
|
}
|
|
},
|
|
|
|
exitFullscreen: function() {
|
|
if (this.get('position') === PositionEnum.FULLSCREEN) {
|
|
this.set('position', PositionEnum.NORMAL);
|
|
this.trigger('focus');
|
|
}
|
|
}
|
|
}
|
|
|
|
});
|