Fandom Developers Wiki
Advertisement

AjaxPoll brings Discussions Polls onto your wiki pages. It is named after a popular MW extension which was no longer supported on the UCP.

Features

  • Embed Discussions Polls on the wiki page.
  • Allow voting directly on the poll, even changing your vote, which is not supported by the Discussions Poll itself.
  • Allow easy customization of the poll's styling.

Installation

Usage

  • Create a poll thread in Discussions.
  • Copy the thread ID, which is present in the address bar, e.g https://dev.fandom.com/f/p/ID
  • Setup a div with class d-poll and supply the thread ID to the data-id attribute.
Example
<div class="d-poll" data-id="4400000000000005134"></div>
Result

You can also copy and use Template:AjaxPoll which only requires you to supply the ID, and it also automatically adds a fallback link (See about fallback content below).

Fallback content

As custom JavaScript is disabled on mobile, the poll will not be loaded, therefore it is recommended to put some fallback content. The fallback content could be some text to display to the readers when the poll is not loaded, or a spinner/loader to indicate the poll is being loaded, or a link to the original poll.

Example
<div class="d-poll" data-id="4400000000000005134">
[[File:Ajax-loader.gif]]
</div>
Result

Ajax-loader

Styling

Quickly import the available skins below, or easily design your own.

Modern

AjaxPoll Modern

AjaxPoll Modern

Whale

AjaxPoll Whale

AjaxPoll Whale

Bootstrap

AjaxPoll Bootstrap

AjaxPoll Bootstrap

Discussions

AjaxPoll Discussions

AjaxPoll Discussions

HTML Structure (for custom styling)

div.d-poll
    └─ form
        ├─ div.d-poll__question
        ├─ div.d-poll__answer
        |   ├─ label.d-poll__answerName
        |   |   └─ input[type="radio"]
        |   ├─ div.d-poll__answerVotes
        |   └─ div.d-poll__answerBar
        |       └─ div
        ├─ div.d-poll__info
        └─ input[type="submit"]

Using with personal JS for changing a vote

Typically, this script only makes sense when imported by admins in sitewide JS, as the point is to show the polls to everyone. However, it can be used in personal JS for the purpose of changing a vote, which isn't possible via the built-in poll interface.

In order to do so, first import the script personally

importArticles({
    type: 'script',
    articles: [
        'u:dev:MediaWiki:AjaxPoll.js'
    ]
});

then follow the same usage steps, but you don't need to save the page where you insert the embed code. You can simply use preview mode and change your vote from there.


Known issues

  • Voting does not work on wikis with a content language other than English. Solution: Adjust the form action URL (line 54) to support other wiki languages. - Fixed

Changelog

Date Description Author
Dec 1, 2020 First commit. KhangND
Text above can be found here (edit)
Advertisement