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 dataObject 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 urlstring base URL (e.g. "http://www.example.com/example.html") valid_argsArray.<Object> arguments that could be added to this URL argsObject.<string, string> arguments to add to the URL hashstring 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 configObject 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 replyHTMLDocumentObject | 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 urlstring 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 urlstring URL to get dataObject parameters Returns:
Type Description jQuery.Promise -
abstractget_pages(doc){Array.<number>}
Get the current and maximum page number
-
Name Type Description docstring | 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 docstring | 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 namestring object name textstring post text Returns:
Type Description Object parsed object -
parse_post(name, post){Object}
Retrieve a string previously encoded with .stringify()
-
Name Type Description namestring object name postObject 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_argsObject 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 urlstring URL to send to dataObject parameters to send use_formboolean 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 postsjQuery 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 textstring 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 namestring object name objectObject object to stringify cmpfunction 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_idnumber ID of thread to get posts for docstring | jQuery | HTMLDocument document to get posts for skip_imagesboolean 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_idNumber 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 promisesArray.<jQuery.Promise> array of promises to wait for Returns:
Type Description jQuery.Promise return values from each promise