Reference Source
import PostStream from 'flarum/components/PostStream.js'
public class | source

PostStream

Extends:

flarum/Component~Component → PostStream

The PostStream component displays an infinitely-scrollable wall of posts in a discussion. Posts that have not loaded will be displayed as placeholders.

Props

  • discussion
  • includedPosts

Member Summary

Public Members
public
public

discussion: Discussion

The discussion to display the post stream for.

public
public
public

Whether or not the infinite-scrolling auto-load functionality is disabled.

public
public
public
public

Method Summary

Public Methods
public

Work out which posts (by number) are currently visible in the viewport, and fire an event with the information.

public

config(isInitialized: *, context: *)

public

count(): Integer

Get the total number of posts in the discussion.

public

flashItem($item: jQuery)

'Flash' the given post, drawing the user's attention to it.

public

getMarginTop(): Integer

Get the distance from the top of the viewport to the point at which we would consider a post to be the first one visible.

public

Load and scroll up to the first post in the discussion.

public

goToIndex(index: Integer, backwards: Boolean, noAnimation: Boolean): Promise

Load and scroll to a certain index within the discussion.

public

Load and scroll down to the last post in the discussion.

public

goToNumber(number: Integer | String, noAnimation: Boolean): Promise

Load and scroll to a post with a certain number.

public

init()

public

loadNearIndex(index: Integer): Promise

Clear the stream and load posts near a certain index.

public

loadNearNumber(number: Integer): Promise

Clear the stream and load posts near a certain number.

public

Load the next page of posts.

public

loadPage(start: Integer, end: Integer, backwards: Boolean)

Load a page of posts into the stream and redraw.

public

Load the previous page of posts.

public

loadRange(start: Integer, end: Integer): Promise

Load and inject the specified range of posts into the stream, without clearing it.

public

onscroll(top: Integer)

When the window is scrolled, check if either extreme of the post stream is in the viewport, and if so, trigger loading the next/previous page.

public

posts(): Post[]

Get the visible page of posts.

public

reset(start: Integer, end: Integer)

Reset the stream so that a specific range of posts is displayed.

public

scrollToIndex(index: Integer, noAnimation: Boolean, bottom: Boolean): jQuery.Deferred

Scroll down to a certain post by index.

public

scrollToItem($item: jQuery, noAnimation: Boolean, force: Boolean, bottom: Boolean): jQuery.Deferred

Scroll down to the given post.

public

scrollToNumber(number: Integer, noAnimation: Boolean): jQuery.Deferred

Scroll down to a certain post by number and 'flash' it.

public

show(posts: Post[])

Set up the stream with the given array of posts.

public

Resume the stream's ability to auto-load posts on scroll.

public

update()

Update the stream so that it loads and includes the latest posts in the discussion, if the end is being viewed.

public

view(): *

Protected Methods
protected

sanitizeIndex(index: Integer): *

Make sure that the given index is not outside of the possible range of indexes in the discussion.

Public Members

public calculatePositionTimeout: * source

public discussion: Discussion source

The discussion to display the post stream for.

public loadPageTimeouts: {} source

public pagesLoading: number source

public paused: Boolean source

Whether or not the infinite-scrolling auto-load functionality is disabled.

public scrollListener: * source

public viewingEnd: * source

public visibleEnd: * source

public visibleStart: * source

Public Methods

public calculatePosition() source

Work out which posts (by number) are currently visible in the viewport, and fire an event with the information.

public config(isInitialized: *, context: *) source

Params:

NameTypeAttributeDescription
isInitialized *
context *

public count(): Integer source

Get the total number of posts in the discussion.

Return:

Integer

public flashItem($item: jQuery) source

'Flash' the given post, drawing the user's attention to it.

Params:

NameTypeAttributeDescription
$item jQuery

public getMarginTop(): Integer source

Get the distance from the top of the viewport to the point at which we would consider a post to be the first one visible.

Return:

Integer

public goToFirst(): Promise source

Load and scroll up to the first post in the discussion.

Return:

Promise

public goToIndex(index: Integer, backwards: Boolean, noAnimation: Boolean): Promise source

Load and scroll to a certain index within the discussion.

Params:

NameTypeAttributeDescription
index Integer
backwards Boolean

Whether or not to load backwards from the given index.

noAnimation Boolean

Return:

Promise

public goToLast(): Promise source

Load and scroll down to the last post in the discussion.

Return:

Promise

public goToNumber(number: Integer | String, noAnimation: Boolean): Promise source

Load and scroll to a post with a certain number.

Params:

NameTypeAttributeDescription
number Integer | String

The post number to go to. If 'reply', go to the last post and scroll the reply preview into view.

noAnimation Boolean

Return:

Promise

public init() source

public loadNearIndex(index: Integer): Promise source

Clear the stream and load posts near a certain index. A page of posts surrounding the given index will be loaded. Returns a promise. If the given index is already loaded, the promise will be resolved immediately.

Params:

NameTypeAttributeDescription
index Integer

Return:

Promise

public loadNearNumber(number: Integer): Promise source

Clear the stream and load posts near a certain number. Returns a promise. If the post with the given number is already loaded, the promise will be resolved immediately.

Params:

NameTypeAttributeDescription
number Integer

Return:

Promise

public loadNext() source

Load the next page of posts.

public loadPage(start: Integer, end: Integer, backwards: Boolean) source

Load a page of posts into the stream and redraw.

Params:

NameTypeAttributeDescription
start Integer
end Integer
backwards Boolean

public loadPrevious() source

Load the previous page of posts.

public loadRange(start: Integer, end: Integer): Promise source

Load and inject the specified range of posts into the stream, without clearing it.

Params:

NameTypeAttributeDescription
start Integer
end Integer

Return:

Promise

public onscroll(top: Integer) source

When the window is scrolled, check if either extreme of the post stream is in the viewport, and if so, trigger loading the next/previous page.

Params:

NameTypeAttributeDescription
top Integer

public posts(): Post[] source

Get the visible page of posts.

Return:

Post[]

public reset(start: Integer, end: Integer) source

Reset the stream so that a specific range of posts is displayed. If a range is not specified, the first page of posts will be displayed.

Params:

NameTypeAttributeDescription
start Integer
  • optional
end Integer
  • optional

public scrollToIndex(index: Integer, noAnimation: Boolean, bottom: Boolean): jQuery.Deferred source

Scroll down to a certain post by index.

Params:

NameTypeAttributeDescription
index Integer
noAnimation Boolean
bottom Boolean

Whether or not to scroll to the bottom of the post at the given index, instead of the top of it.

Return:

jQuery.Deferred

public scrollToItem($item: jQuery, noAnimation: Boolean, force: Boolean, bottom: Boolean): jQuery.Deferred source

Scroll down to the given post.

Params:

NameTypeAttributeDescription
$item jQuery
noAnimation Boolean
force Boolean

Whether or not to force scrolling to the item, even if it is already in the viewport.

bottom Boolean

Whether or not to scroll to the bottom of the post at the given index, instead of the top of it.

Return:

jQuery.Deferred

public scrollToNumber(number: Integer, noAnimation: Boolean): jQuery.Deferred source

Scroll down to a certain post by number and 'flash' it.

Params:

NameTypeAttributeDescription
number Integer
noAnimation Boolean

Return:

jQuery.Deferred

public show(posts: Post[]) source

Set up the stream with the given array of posts.

Params:

NameTypeAttributeDescription
posts Post[]

public unpause() source

Resume the stream's ability to auto-load posts on scroll.

public update() source

Update the stream so that it loads and includes the latest posts in the discussion, if the end is being viewed.

public view(): * source

Return:

*

Protected Methods

protected sanitizeIndex(index: Integer): * source

Make sure that the given index is not outside of the possible range of indexes in the discussion.

Params:

NameTypeAttributeDescription
index Integer

Return:

*