mediawiki-extensions-AJAXPoll/resources/js/ajaxpoll.js
Jack Phoenix 0469665d77 Version 2.0: somewhat more properly convert the AJAX function into an API module to ensure continued post-1.30 compatibility
MW 1.30.0+ is now explicitly required; as such, dropped pre-1.17 support
from AJAXPoll#onLoadExtensionSchemaUpdates.

Also "fixed" T163625 by changing an INSERT INTO query into INSERT IGNORE
INTO, swapped some "double quotes" to 'single quotes', refactored some
stuff, etc.

Bug: T163625
Change-Id: Ifbabf3bf5da25c602fe5873539520c517573890c
2018-05-12 15:50:02 +03:00

57 lines
1.8 KiB
JavaScript

/*global $, mw*/
var ajaxpollTmp;
var setupEventHandlers = function () {
'use strict';
$( '.ajaxpoll-answer-vote' ).on( 'mouseover', function () {
var sp = $( this ).find( 'span' );
ajaxpollTmp = sp.html();
sp.text( sp.attr( 'title' ) );
sp.attr( 'title', '' );
} );
$( '.ajaxpoll-answer-vote' ).on( 'mouseout', function () {
var sp = $( this ).find( 'span' );
sp.attr( 'title', sp.text() );
sp.text( ajaxpollTmp );
} );
/* attach click handler */
$( '.ajaxpoll-answer-name label' ).on( 'click', function ( event ) {
var choice = $( this ).parent().parent(), poll, answer;
event.preventDefault();
event.stopPropagation();
poll = choice.attr( 'poll' );
answer = choice.attr( 'answer' );
choice.find( '.ajaxpoll-hover-vote' ).addClass( 'ajaxpoll-checkevent' );
choice.find( 'input' ).prop( 'checked', 'checked' );
$( '#ajaxpoll-ajax-' + poll ).text( mw.message( 'ajaxpoll-submitting' ).text() ).css( 'display', 'inline-block' );
( new mw.Api() ).postWithToken( 'edit', {
action: 'pollsubmitvote',
format: 'json',
poll: poll,
answer: answer
} ).done( function ( data ) {
$( '#ajaxpoll-container-' + poll ).html( data.pollsubmitvote.result );
setupEventHandlers();
} );
} );
$( '.ajaxpoll-answer-name:not(.ajaxpoll-answer-name-revoke) label' ).on( 'mouseover', function () {
$( this ).addClass( 'ajaxpoll-hover-vote' );
} );
$( '.ajaxpoll-answer-name:not(.ajaxpoll-answer-name-revoke) label' ).on( 'mouseout', function () {
$( this ).removeClass( 'ajaxpoll-hover-vote' );
} );
$( '.ajaxpoll-answer-name-revoke label' ).on( 'mouseover', function () {
$( this ).addClass( 'ajaxpoll-hover-revoke' );
} );
$( '.ajaxpoll-answer-name-revoke label' ).on( 'mouseout', function () {
$( this ).removeClass( 'ajaxpoll-hover-revoke' );
} );
};
setupEventHandlers();