User stream now uses eyeline for loading more content.

This commit is contained in:
Robin Ward 2013-07-23 16:06:26 -04:00
parent 44bebf255d
commit c9c6a8fd9d
6 changed files with 63 additions and 74 deletions

View File

@ -169,11 +169,10 @@ Discourse.Eyeline.prototype.update = function() {
@method flushRest
**/
Discourse.Eyeline.prototype.flushRest = function() {
var _this = this;
var eyeline = this;
return $(this.selector).each(function(i, elem) {
var $elem;
$elem = $(elem);
return _this.trigger('saw', { detail: $elem });
var $elem = $(elem);
return eyeline.trigger('saw', { detail: $elem });
});
};

View File

@ -35,7 +35,7 @@ Discourse.Scrolling = Em.Mixin.create({
},
/**
Begin watching for scroll events. They will be called at max every 100ms.
Stop watching for scroll events.
@method unbindScrolling
*/

View File

@ -1,4 +1,3 @@
<div id='user-stream'>
{{#each view.stream.content}}
<div {{bindAttr class=":item hidden deleted moderator_action"}}>
<div class='clearfix info'>
@ -23,5 +22,3 @@
</div>
{{/each}}
</div>
<div id="user-stream-bottom"></div>

View File

@ -76,9 +76,9 @@ Discourse.ListTopicsView = Discourse.View.extend(Discourse.Scrolling, {
// When the topic list is scrolled
scrolled: function(e) {
var _ref;
this.saveScrollPos();
return (_ref = this.get('eyeline')) ? _ref.update() : void 0;
var eyeline = this.get('eyeline');
if (eyeline) { eyeline.update(); }
}

View File

@ -9,34 +9,23 @@
**/
Discourse.UserStreamView = Discourse.View.extend(Discourse.Scrolling, {
templateName: 'user/stream',
loading: false,
elementId: 'user-stream',
scrolled: function(e) {
var eyeline = this.get('eyeline');
if (eyeline) { eyeline.update(); }
},
var $userStreamBottom = $('#user-stream-bottom');
if ($userStreamBottom.data('loading')) return;
var position = $userStreamBottom.position();
if (!($userStreamBottom && position)) return;
var docViewTop = $(window).scrollTop();
var windowHeight = $(window).height();
var docViewBottom = docViewTop + windowHeight;
if (position.top < docViewBottom) {
$userStreamBottom.data('loading', true);
this.set('loading', true);
loadMore: function() {
var userStreamView = this;
var user = this.get('stream.user');
var stream = this.get('stream');
if (userStreamView.get('loading')) { return; }
var stream = this.get('stream');
stream.findItems().then(function() {
userStreamView.set('loading', false);
Em.run.schedule('afterRender', function() {
$userStreamBottom.data('loading', null);
userStreamView.get('eyeline').flushRest();
});
});
}
},
willDestroyElement: function() {
@ -45,8 +34,15 @@ Discourse.UserStreamView = Discourse.View.extend(Discourse.Scrolling, {
didInsertElement: function() {
this.bindScrolling();
}
var eyeline = new Discourse.Eyeline('#user-stream .item');
this.set('eyeline', eyeline);
var userStreamView = this;
eyeline.on('sawBottom', function() {
userStreamView.loadMore();
});
}
});

View File

@ -237,14 +237,11 @@
}
}
#user-stream-bottom {
margin-bottom: 50px;
clear: both;
}
#user-stream {
width: 840px;
float: left;
margin-bottom: 50px;
.excerpt {
margin: 5px 0px;
font-size: 13px;