abstractnew BulletinBoard()
Generic class for any type of bulletin board
Example
var bb = new ChildOfBulletinBoard({
config: { ... },
origin: 'http://www.example.com', // default: current site
doc: my_document // default: document
});
Methods
-
abstract,protected_add_standard_data(data){jQuery.Promise}
Add parameters required for standard POST requests
-
Name Type Description data
Object parameters passed to jQuery Returns:
Type Description jQuery.Promise deferred object that will return when all necessary parameters have been found -
protectedbuild_url(url, valid_args, args, hash)
Convenience function to construct a URL
-
Name Type Description url
string base URL (e.g. "http://www.example.com/example.html") valid_args
Array.<Object> arguments that could be added to this URL args
Object.<string, string> arguments to add to the URL hash
string optional string added after the '#' Example
// returns "/example.html?f=qux&b=default+value" bb.build_url( '/example.html', [ { key: 'foo', param: 'f' }, { key: 'bar', param: 'b', default: 'default value' }, { key: 'baz', param: 'bb' }, ], { foo: 'qux' } );
-
config(config)
add or change configuration values
-
Name Type Description config
Object new configuration values Returns:
(updated) configuration -
abstract,protecteddetect_post_error(reply)
Return the error string contained in a reply to post(), or null on success
-
Name Type Description reply
HTMLDocumentObject | XMLDocumentObject | string string | null -
fix_url(url){string}
convert a relative URL to use the correct origin
-
BulletinBoards can have an origin other than the site we're currently on (so we can e.g. browse as one user and post as another)
Name Type Description url
string URL to translate Returns:
Type Description string absolute URL -
protectedget(url, data){jQuery.Promise}
Send a message to the server as an AJAX request
-
Name Type Description url
string URL to get data
Object parameters Returns:
Type Description jQuery.Promise -
abstractget_pages(doc){Array.<number>}
Get the current and maximum page number
-
Name Type Description doc
string | jQuery | HTMLDocument document to get posts for Returns:
Type Description Array.<number> current and maximum page numbers, number of posts on the page -
abstractget_posts(doc){jQuery}
Get all documents on the specified page
-
Name Type Description doc
string | jQuery | HTMLDocument document to get posts for Returns:
Type Description jQuery list of posts -
parse(name, text){Object}
Retrieve a string previously encoded with .stringify()
-
Name Type Description name
string object name text
string post text Returns:
Type Description Object parsed object -
parse_post(name, post){Object}
Retrieve a string previously encoded with .stringify()
-
Name Type Description name
string object name post
Object post data returned from process_posts() Returns:
Type Description Object parsed object -
protectedping(var_args){jQuery.Promise}
Connect to the server and get some very basic information
-
the return value contains 'results ('success' or 'fail'), 'duration' (milliseconds taken for the round trip), and 'offset' (number of milliseconds the server is ahead of the client, which can be negative)
Name Type Description var_args
Object repeatable passed to $.get() Returns:
Type Description jQuery.Promise -
protectedpost(url, data, use_form){jQuery.Promise}
Send a message to the server as either an AJAX request or a form
-
Name Type Description url
string URL to send to data
Object parameters to send use_form
boolean send a form requset instead of an AJAX request Returns:
Type Description jQuery.Promise -
abstractprocess_posts(posts){Array.<Object>}
Map a list of elements returned by get_posts() to data about the posts they represent
-
Name Type Description posts
jQuery list of post elements Returns:
Type Description Array.<Object> list of hashes describing each post -
quotes_process(text){Array.Object}
Map BBCode to a list of (non-nested) quotes
-
Note: supports vBCode's [quote=author;post_id] syntax
Name Type Description text
string BBCode to parse Returns:
Type Description Array.Object -
stringify(name, object, cmp){string}
Escape an object in a way that's safe to put in a forum post
-
Name Type Description name
string object name object
Object object to stringify cmp
function comparison function Returns:
Type Description string text to include in a post -
thread_posts(thread_id, doc, skip_images){jQuery.Promise}
Get information about posts from many pages in a thread
-
We need to get a single page first, to work out the number of pages in the thread. Passing in that first page will make the function return faster, and will cause only pages after that one to be loaded.
Name Type Description thread_id
number ID of thread to get posts for doc
string | jQuery | HTMLDocument document to get posts for skip_images
boolean convert all images to - significantly improves performance Returns:
Type Description jQuery.Promise Deferred object that will return when all pages have loaded -
user_duplicates(user_id){jQuery.Promise}
get information about the specified account and suspected duplicate accounts
-
Name Type Description user_id
Number user ID Returns:
Type Description jQuery.Promise promise Example
bb.get_duplicates(1234) .progress( completed, total ) .then(function(user) { console.log( user.suspiciousness, user.suspected_duplicates ); // see user_moderation_info() for details on users });
-
when(promises){jQuery.Promise}
Sane wrapper around $.when()
-
$.when() has several problems: - it wants a variadic list of arguments - it has a different return syntax when passed a single item than many - does not notify on completion of individual promises This workalike solves those issues.
Name Type Description promises
Array.<jQuery.Promise> array of promises to wait for Returns:
Type Description jQuery.Promise return values from each promise