Guest User

NGG Voting UI popup hack

a guest
Jun 5th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function show_props(obj, obj_name) { /* debug method to alert objs */
  2.     var result = "";
  3.     for (var i in obj)
  4.         result += obj_name + "." + i + " = " + obj[i] + "\n" ;
  5.     return result;
  6. }
  7.  
  8. jQuery(document).ready(function() {
  9.         var $voteConfirm = jQuery('<div id="ngg-vote-confirm">Are you sure you want to vote for this image?</div>');
  10.        
  11.         jQuery('a.nggv-link-like, a.nggv-link-dislike').click(function(e) {
  12.                 var container = jQuery(this).parents('.nggv_container');
  13.                 var $thisLink = jQuery(this);
  14.                
  15.                 $voteConfirm.dialog({
  16.                         modal: true,
  17.                         buttons: {
  18.                             "Yes": function() {
  19.                                 jQuery(this).dialog("close");
  20.                                 jQuery(this).dialog("destroy");
  21.                                
  22.                                 container.find('img.nggv-star-loader').show();
  23.                                
  24.                                 var url = $thisLink.attr('href');
  25.                                 url += '&ajaxify=1';
  26.                                
  27.                                 jQuery.ajax({
  28.                                         url: url,
  29.                                         data: '',
  30.                                         success: function(data, textStatus, XMLHttpRequest) {
  31.                                             var start = data.indexOf("<!-- NGGV START AJAX RESPONSE -->") + 33; //find the start of the outputting by the ajax url (stupid wordpress and poor buffering options blah blah)
  32.                                             var end = data.indexOf("<!-- NGGV END AJAX RESPONSE -->");
  33.                                            
  34.                                             eval(data.substr(start, (end-start))); //the array of voters gets echoed out at the ajax url
  35.                                            
  36.                                             if(typeof(nggv_js) == 'object') {
  37.                                                 var msg = '';
  38.                                                 if(nggv_js.saved) {
  39.                                                     jQuery(document).focus();
  40.                                                     container.html(nggv_js.nggv_container);
  41.                                                 }else{
  42.                                                     if(nggv_js.msg) {
  43.                                                         msg = nggv_js.msg
  44.                                                     }else{ //there should always be a msg, but just in case lets default one
  45.                                                         msg = 'There was a problem saving your vote, please try again in a few moments.';
  46.                                                     }
  47.                                                 }
  48.                                             }else{
  49.                                                 msg = 'There was a problem saving your vote, please try again in a few moments.';
  50.                                             }
  51.                                            
  52.                                             if(msg) {
  53.                                                 //the 'continer' div and 'nggv-error' div are on the same dom level, making them siblings
  54.                                                 container.siblings('div.nggv-error').show();
  55.                                                 container.siblings('div.nggv-error').html(msg);
  56.                                             }
  57.                                         },
  58.                                         error: function(XMLHttpRequest, textStatus, errorThrown) {
  59.                                             jQuery('div.nggv-error').show();
  60.                                             jQuery('div.nggv-error').html('There was a problem saving your vote, please try again in a few moments.');
  61.                                         },
  62.                                         complete: function() {
  63.                                             container.find('img.nggv-star-loader').hide();
  64.                                         }
  65.                                 });
  66.                             },
  67.                             "No": function() {
  68.                                 jQuery(this).dialog("close");
  69.                                 jQuery(this).dialog("destroy");
  70.                             }
  71.                         }
  72.                 });
  73.                
  74.                 e.preventDefault();
  75.                 return false;
  76.                
  77.                 e.preventDefault();
  78.                 return false;
  79.         });
  80. });
Add Comment
Please, Sign In to add comment