Go to top of page after clicking "Vote"
-
After voting with a poll that re-directs to another page for the results, an interim window comes up which is configured it to say “Thank you for Your Vote. You’re being redirected to the results”.
Unfortunately, that message is at the top of the page and the user can’t see it after clicking the “Vote” button because they’re at the middle/bottom. During the slight delay they start clicking on other things. Is there a way to have the action of clicking on the “Vote” button first go to the top of the page so they can see the message?
-
Hello
Assuming you’re using version 5.6, edit js/yop-poll-public.js and replace
function yop_poll_do_vote(...){...}
with the code below
function yop_poll_do_vote(yop_poll_various_config) { wLog=1; poll_id = typeof yop_poll_various_config.poll_id !== 'undefined' ? yop_poll_various_config.poll_id : 0; is_modal = typeof yop_poll_various_config.is_modal !== 'undefined' ? yop_poll_various_config.is_modal : false; vote_type = typeof yop_poll_various_config.vote_type !== 'undefined' ? yop_poll_various_config.vote_type : 'default'; poll_location = typeof yop_poll_various_config.poll_location !== 'undefined' ? yop_poll_various_config.poll_location : 'page'; unique_id = typeof yop_poll_various_config.unique_id !== 'undefined' ? yop_poll_various_config.unique_id : ''; if( vote_type == "anonymous" ) { supercookie = yop_poll_get_cookie( "set_vote_cookie_anonymous_" + poll_id ); } else if( vote_type == "google" ) { supercookie = yop_poll_get_cookie( "set_vote_cookie_google_" + poll_id + "user_" + yop_poll_various_config.google_user_id ); } else if( vote_type = "wordpress" ) { supercookie = yop_poll_get_cookie( "set_vote_cookie_wordpress_" + poll_id + "user_" + yop_poll_various_config.worspress_user_id ); } var popupClose = true; var pollData = { 'action': yop_poll_public_config_general.ajax.vote_action, 'poll_id': poll_id, 'vote_type': vote_type, 'facebook_user_details': yop_poll_various_config.facebook_user_details, 'google_user_details': yop_poll_various_config.google_user_details, 'facebook_error': yop_poll_various_config.facebook_error, 'unique_id': unique_id, 'location': poll_location, 'supercookie': supercookie }; pollData = jQuery.param( pollData ) + "&" + jQuery( '#yop-poll-form-' + poll_id + unique_id ).serialize(); jQuery.ajax( { type: 'POST', url: yop_poll_public_config_general.ajax.url, data: pollData, cache: false, async: true, success: function(data) { //console.log(data); data = yop_poll_extractResponse( data ); response = JSON.parse( data ); if( '' != response.error ) { yop_poll_show_message( response.error, poll_id, unique_id, "error" ); // jQuery( '#yop_poll_wordpress-vote-button-' + poll_id + unique_id ).show(); // jQuery( '#yop_poll_anonimous-vote-button-' + poll_id + unique_id).show(); jQuery('#yop_poll_vote_options_div-'+ poll_id + unique_id).remove(); jQuery( '#yop_poll_vote-button-' + poll_id + unique_id ).show(); jQuery( '#yop_poll_wordpress_loading_img-' + poll_id + unique_id ).remove(); popupClose = true; } else { if( '' != response.message ) { jQuery( '#yop-poll-container-' + poll_id + unique_id ).replaceWith( response.message ); yop_poll_show_message( response.success, poll_id, unique_id, "success" ); if( vote_type == "anonymous" ) { supercookie = yop_poll_set_super_cookie( "set_vote_cookie_anonymous_" + poll_id ); } else if( vote_type == "google" ) { supercookie = yop_poll_set_super_cookie( "set_vote_cookie_google_" + poll_id + "user_" + yop_poll_various_config.google_user_id ); } else if( vote_type = "wordpress" ) { supercookie = yop_poll_set_super_cookie( "set_vote_cookie_wordpress_" + poll_id + "user_" + yop_poll_various_config.worspress_user_id ); } yop_poll_runEval( poll_id, unique_id ); if( 'yes' == yop_poll_various_config.public_config.poll_options.redirect_after_vote ) { window.location = yop_poll_various_config.public_config.poll_options.redirect_after_vote_url; } if( 'yes' == yop_poll_various_config.public_config.poll_options.facebook_share_after_vote ) { FB.ui( { method: 'feed', redirect_uri: "https://localhost/", name: 'Yop Poll', link: 'https://yop-poll.com/wordpress/', caption: 'Yop Poll', description: yop_poll_various_config.public_config.poll_options.share_description }, function(response) { if( response && response.post_id ) { yop_poll_show_message( "Poll shared", poll_id, unique_id, "success" ); } else { yop_poll_show_message( "Poll not shared", poll_id, unique_id, "error" ); } } ); } } else { jQuery('#yop_poll_vote_options_div-'+ poll_id + unique_id).remove(); // jQuery( '#yop_poll_wordpress-vote-button-' + poll_id + unique_id ).show(); //jQuery( '#yop_poll_anonimous-vote-button-' + poll_id + unique_id).show(); jQuery( '#yop_poll_wordpress_loading_img-' + poll_id + unique_id ).remove(); yop_poll_show_message( "An error has occured", poll_id, unique_id, "error" ); popupClose = true; } } jQuery('html, body').animate({ scrollTop: 0 }, 'fast'); }, error: function() { jQuery('#yop_poll_vote_options_div-'+ poll_id + unique_id).remove(); //jQuery( '#yop_poll_wordpress-vote-button-' + poll_id + unique_id ).show(); //jQuery( '#yop_poll_anonimous-vote-button-' + poll_id + unique_id).show(); jQuery( '#yop_poll_wordpress_loading_img-' + poll_id + unique_id ).remove(); yop_poll_show_message( "An error has occured", poll_id, unique_id, "error" ); popupClose = true; } } ); //superCookie(); return popupClose; }
Let us know how it goes.
Best
YOP TeamThank you for the reply! I’ve modified the file several times to be sure I wasn’t making a mistake but all I get is a spinning circle after clicking the vote button.
I’m using the “Message after vote” field in your options panel and adding the message “Thank you for your vote! You’re being redirected to the results.” If the message could be displayed where the vote button is, then it would be visible. The only reason I’m asking how to scroll to the top is because that’s where the message after vote displays, which is off the screen after scrolling to answer the questions.
Thanks again for your help!
- The topic ‘Go to top of page after clicking "Vote"’ is closed to new replies.