2021-07-30 22:21:45 +00:00
|
|
|
/* eslint-disable no-implicit-globals */
|
2015-02-16 00:59:04 +00:00
|
|
|
|
2012-03-17 21:13:10 +00:00
|
|
|
var ajaxpollTmp;
|
2012-03-13 22:31:46 +00:00
|
|
|
|
2015-02-16 00:59:04 +00:00
|
|
|
var setupEventHandlers = function () {
|
2015-02-19 22:11:52 +00:00
|
|
|
'use strict';
|
|
|
|
$( '.ajaxpoll-answer-vote' ).on( 'mouseover', function () {
|
|
|
|
var sp = $( this ).find( 'span' );
|
|
|
|
ajaxpollTmp = sp.html();
|
|
|
|
sp.text( sp.attr( 'title' ) );
|
|
|
|
sp.attr( 'title', '' );
|
|
|
|
} );
|
2012-03-13 22:31:46 +00:00
|
|
|
|
2015-02-19 22:11:52 +00:00
|
|
|
$( '.ajaxpoll-answer-vote' ).on( 'mouseout', function () {
|
|
|
|
var sp = $( this ).find( 'span' );
|
|
|
|
sp.attr( 'title', sp.text() );
|
|
|
|
sp.text( ajaxpollTmp );
|
|
|
|
} );
|
2012-03-13 22:31:46 +00:00
|
|
|
|
2015-02-19 22:11:52 +00:00
|
|
|
/* attach click handler */
|
|
|
|
$( '.ajaxpoll-answer-name label' ).on( 'click', function ( event ) {
|
2018-05-12 12:27:22 +00:00
|
|
|
var choice = $( this ).parent().parent(), poll, answer;
|
2015-02-19 22:11:52 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
poll = choice.attr( 'poll' );
|
2020-01-28 22:28:04 +00:00
|
|
|
|
|
|
|
if ( $( this ).attr( 'id' ) === 'ajaxpoll-label-disabled' ) {
|
|
|
|
$( '#ajaxpoll-ajax-' + poll ).text( $( this ).attr( 'title' ) ).css( 'display', 'inline-block' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-19 22:11:52 +00:00
|
|
|
answer = choice.attr( 'answer' );
|
|
|
|
choice.find( '.ajaxpoll-hover-vote' ).addClass( 'ajaxpoll-checkevent' );
|
|
|
|
choice.find( 'input' ).prop( 'checked', 'checked' );
|
2015-09-29 20:40:24 +00:00
|
|
|
$( '#ajaxpoll-ajax-' + poll ).text( mw.message( 'ajaxpoll-submitting' ).text() ).css( 'display', 'inline-block' );
|
2018-05-12 12:27:22 +00:00
|
|
|
|
2020-01-02 04:42:57 +00:00
|
|
|
( new mw.Api() ).postWithToken( 'csrf', {
|
2018-05-12 12:27:22 +00:00
|
|
|
action: 'pollsubmitvote',
|
|
|
|
format: 'json',
|
|
|
|
poll: poll,
|
|
|
|
answer: answer
|
|
|
|
} ).done( function ( data ) {
|
|
|
|
$( '#ajaxpoll-container-' + poll ).html( data.pollsubmitvote.result );
|
|
|
|
setupEventHandlers();
|
|
|
|
} );
|
2015-02-19 22:11:52 +00:00
|
|
|
} );
|
2012-03-13 22:31:46 +00:00
|
|
|
|
2015-09-29 20:40:24 +00:00
|
|
|
$( '.ajaxpoll-answer-name:not(.ajaxpoll-answer-name-revoke) label' ).on( 'mouseover', function () {
|
2015-02-19 22:11:52 +00:00
|
|
|
$( this ).addClass( 'ajaxpoll-hover-vote' );
|
|
|
|
} );
|
2015-09-29 20:40:24 +00:00
|
|
|
$( '.ajaxpoll-answer-name:not(.ajaxpoll-answer-name-revoke) label' ).on( 'mouseout', function () {
|
2015-02-19 22:11:52 +00:00
|
|
|
$( this ).removeClass( 'ajaxpoll-hover-vote' );
|
|
|
|
} );
|
2012-03-13 22:31:46 +00:00
|
|
|
|
2015-02-19 22:11:52 +00:00
|
|
|
$( '.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' );
|
|
|
|
} );
|
2015-02-16 00:59:04 +00:00
|
|
|
};
|
2015-09-29 20:40:24 +00:00
|
|
|
setupEventHandlers();
|