User:SSethi (WMF)/common.js

/** * feedback.js * * Displays a feedback form and collect user votes */

var yesButton = new OO.ui.ButtonWidget( { label: 'Yes' } ), noButton = new OO.ui.ButtonWidget( { label: 'No' } ),

hasUserVoted = false, feedbackData = [];

yesButton.on( 'click', function {	collectVote( "Yes" ); } );

noButton.on( 'click', function {	collectVote( "No" ); } );

function collectVote( response ) { var pageID = mw.config.get( 'wgArticleId' );

if( !hasUserVoted && response == "Yes" ) { hasUserVoted = true; feedbackData.push( { pageId: pageID, vote: "Yes" } ); }

if( hasUserVoted && response == "No" ) { hasUserVoted = false; feedbackData.push( { pageId: pageID, vote: "No" } ); }

console.log( feedbackData ); }

//TODO: Replace `body` with `#mw-content-text` $( '#mw-content-text' ).append( 'Was this documentation helpful? ' ); $( '#mw-content-text' ).append( yesButton.$element ); $( '#mw-content-text' ).append( noButton.$element );