Created
November 12, 2015 06:16
-
-
Save gregtap/17b0da37b9e95aec6d3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Set N latest non visible messages to visible. | |
| */ | |
| revealLastNmessages: function() { | |
| let hiddenMessages = this.get('store').peekAll('chat-message').filterBy('isVisible', false); | |
| let l = hiddenMessages.get('length'); | |
| // Show latest N messages. | |
| hiddenMessages.slice(l - MAX_MESSAGES_COUNT, l) | |
| .setEach('isVisible', true); | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * User scrolled up to the top of the messages list. | |
| * Lets reveal more messages from history. | |
| */ | |
| scrolledToTop() { | |
| let messagesElmt = Ember.$('.messages-container')[0]; | |
| let originalScrollHeight = messagesElmt.scrollHeight; | |
| this.get('core').revealLastNmessages(); | |
| // Once our elements are added lets scroll | |
| // back to the previous position. | |
| run.scheduleOnce('afterRender', this, function() { | |
| Ember.$('.messages-container').scrollTop(messagesElmt.scrollHeight - originalScrollHeight); | |
| }); | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment