mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AJAXPoll
synced 2024-12-04 03:18:38 +00:00
9c28c663fa
* stylelint-config-wikimedia: 0.6.0 → 0.8.0 * eslint-config-wikimedia: 0.8.1 → 0.15.0 * grunt-stylelint: 0.11.1 → 0.13.0 * grunt-eslint: 21.0.0 → 22.0.0 Additional changes: * Removing manual reportUnusedDisableDirectives for eslint. Change-Id: I42ad5adf1c4c95e2bff90ed46c608c13a37bb33a
57 lines
1.8 KiB
JavaScript
57 lines
1.8 KiB
JavaScript
/* eslint-disable no-implicit-globals, one-var */
|
|
|
|
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( 'csrf', {
|
|
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();
|