Advertisement
Guest User

gallery_options.js (fixed removed dislike)

a guest
Jun 13th, 2012
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(function() {
  2.         jQuery("#gallerydiv table.form-table").each(function(item) { //the table with gallery fields (hack to add to it with js, sorry)
  3.                 var row = this.insertRow(this.rows.length);
  4.                 var cell = row.insertCell(0);
  5.                 cell.align = "left";
  6.                 cell.vAlign = "top";
  7.                 cell.innerHTML = "Gallery Voting Options";
  8.                
  9.                 var cell = row.insertCell(1);
  10.                 cell.colSpan = 3;
  11.                 var str = "";
  12.                
  13.                 str += "<input type='checkbox' name='nggv[enable]' value=1 "+(nggv_enable ? "checked" : "")+" /> Enable voting for this gallery<br />";
  14.                 str += "<input type='checkbox' name='nggv[force_login]' value=1 "+(nggv_login ? "checked" : "")+" /> Only allow logged in users to vote<br />";
  15.                 str += "<input type='checkbox' name='nggv[force_once]' value=1 "+(nggv_once ? "checked" : "")+" /> Only allow 1 vote per person (IP or userid is used to stop multiple)<br />";
  16.                 str += "<input type='checkbox' name='nggv[user_results]' value=1 "+(user_results ? "checked" : "")+" /> Allow users to see results<br />";
  17.                 str += "Rating Type: <select name='nggv[voting_type]'>";
  18.                 str += "<option value='1' "+(voting_type == 1 ? "selected" : "")+">Drop Down</option>";
  19.                 str += "<option value='2' "+(voting_type == 2 ? "selected" : "")+">Star Rating</option>";
  20.                 str += "<option value='3' "+(voting_type == 3 ? "selected" : "")+">Like</option>";
  21.                 str += "</select>";
  22.                
  23.                 cell.innerHTML = str;
  24.  
  25.                 row = this.insertRow(this.rows.length);
  26.                 cell = row.insertCell(0);
  27.                 cell.align = "left";
  28.                 cell.vAlign = "top";
  29.                 cell.innerHTML = "Current Votes";
  30.                
  31.                 cell = row.insertCell(1);
  32.                 cell.colSpan = 3;
  33.                 if(voting_type == 3) { //likes
  34.                     str = nggv_num_likes+' ';
  35.                     str += nggv_num_likes == 1 ? 'Vote ' : 'Votes ';
  36.                     //str += nggv_num_dislikes+' ';
  37.                     //str += nggv_num_dislikes == 1 ? 'Dislike' : 'Dislikes';
  38.                     str += " <a href='#' id='nggv_more_results'>("+nggv_num_votes+" votes cast)</a>";
  39.                 }else{
  40.                     str = nggv_avg+" / 10 <a href='#' id='nggv_more_results'>("+nggv_num_votes+" votes cast)</a>";
  41.                 }
  42.                
  43.                 cell.innerHTML = str;
  44.                
  45.                 jQuery("a#nggv_more_results").click(function() { //button click to open more detail on the voting
  46.                         tb_show("", "#TB_inline?width=640&height=300&inlineId=nggvShowList&modal=true", false); //thick box seems to be included, so lets use it :)
  47.                        
  48.                         jQuery.get(nggv_more_url, 'gid='+nggv_gid, function(data, status) {
  49.                                 if(status == 'success') {
  50.                                     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)
  51.                                     eval(data.substr(start)); //the array of voters gets echoed out at the ajax url
  52.                                     if(nggv_votes_list.length > 0) {
  53.                                         //todo, paginate results (pseudo even, with hidden divs etc)?
  54.                                         var bgcol;
  55.                                         var html = '<table style="width:100%;">';
  56.                                         html += '<thead>';
  57.                                         html += '<tr>';
  58.                                         html += '<td><strong>Date</strong></td>';
  59.                                         html += '<td><strong>Vote</strong><br /><em>(out 10)</em></td>';
  60.                                         html += '<td><strong>User Name</strong><br ><em>(if logged in)</em></td>';
  61.                                         html += '<td><strong>IP</strong></td>';
  62.                                         html += '</tr>';
  63.                                         html += '</thead>';
  64.                                         html += '<tbody>';
  65.                                         for(i=0; i<nggv_votes_list.length; i++) {
  66.                                             bgcol = i % 2 == 0 ? "" : "#DFDFDF";
  67.                                             html += '<tr style="background-color: '+bgcol+'">';
  68.                                             html += '<td>'+nggv_votes_list[i][1]+'</td>';
  69.                                             if(parseInt(nggv_voting_type) == 3) {
  70.                                                 html += '<td>'+(nggv_votes_list[i][0] == 100 ? 'Like' : 'Dislike')+'</td>';
  71.                                             }else{
  72.                                                 html += '<td>'+(Math.round(nggv_votes_list[i][0]) / 10)+'</td>';
  73.                                             }
  74.                                             html += '<td>'+nggv_votes_list[i][3][1]+'</td>';
  75.                                             html += '<td>'+nggv_votes_list[i][2]+'</td>';
  76.                                             html += '</tr>';
  77.                                         }
  78.                                         html += '</tbody>';
  79.                                         html += '</table>';
  80.                                        
  81.                                         jQuery("div#nggvShowList_content").html(html);
  82.                                     }else{
  83.                                         jQuery("div#nggvShowList_content").html("No votes yet for this gallery");
  84.                                     }
  85.                                 }else{
  86.                                     jQuery("div#nggvShowList_content").html("There was a problem retrieving the list of votes, please try again in a momement.");
  87.                                 }
  88.                         });
  89.                         return false; //cancel click
  90.                 });
  91.                
  92.                 jQuery("a#nggv_more_results_close").click(function() {
  93.                         tb_remove();
  94.                         return false;
  95.                 });
  96.                
  97.                 jQuery("a.nggv_mote_results_image").click(function() { //button click to open more detail on the voting
  98.                         var pid = parseInt(this.id.substr(24));
  99.                         tb_show("", "#TB_inline?width=640&height=300&inlineId=nggvShowList&modal=true", false); //thick box seems to be included, so lets use it :)
  100.                        
  101.                         jQuery.get(nggv_more_url, 'pid='+pid, function(data, status) {
  102.                                 if(status == 'success') {
  103.                                     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)
  104.                                     eval(data.substr(start)); //the array of voters gets echoed out at the ajax url
  105.                                     if(nggv_votes_list.length > 0) {
  106.                                         //todo, paginate results (pseudo even, with hidden divs etc)?
  107.                                         var bgcol;
  108.                                         var html = '<table style="width:100%;">';
  109.                                         html += '<thead>';
  110.                                         html += '<tr>';
  111.                                         html += '<td><strong>Date</strong></td>';
  112.                                         html += '<td><strong>Vote</strong><br /><em>(out 10)</em></td>';
  113.                                         html += '<td><strong>User Name</strong><br ><em>(if logged in)</em></td>';
  114.                                         html += '<td><strong>IP</strong></td>';
  115.                                         html += '</tr>';
  116.                                         html += '</thead>';
  117.                                         html += '<tbody>';
  118.                                         for(i=0; i<nggv_votes_list.length; i++) {
  119.                                             bgcol = i % 2 == 0 ? "" : "#DFDFDF";
  120.                                             html += '<tr style="background-color: '+bgcol+'">';
  121.                                             html += '<td>'+nggv_votes_list[i][1]+'</td>';
  122.                                             if(parseInt(nggv_voting_type) == 3) {
  123.                                                 html += '<td>'+(nggv_votes_list[i][0] == 100 ? 'Like' : 'Dislike')+'</td>';
  124.                                             }else{
  125.                                                 html += '<td>'+(Math.round(nggv_votes_list[i][0]) / 10)+'</td>';
  126.                                             }
  127.                                             html += '<td>'+nggv_votes_list[i][3][1]+'</td>';
  128.                                             html += '<td>'+nggv_votes_list[i][2]+'</td>';
  129.                                             html += '</tr>';
  130.                                         }
  131.                                         html += '</tbody>';
  132.                                         html += '</table>';
  133.                                        
  134.                                         jQuery("div#nggvShowList_content").html(html);
  135.                                     }else{
  136.                                         jQuery("div#nggvShowList_content").html("No votes yet for this image");
  137.                                     }
  138.                                 }else{
  139.                                     jQuery("div#nggvShowList_content").html("There was a problem retrieving the list of votes, please try again in a momement.");
  140.                                 }
  141.                         });
  142.                         return false; //cancel click
  143.                 });
  144.                
  145.                 jQuery("a.nggv_clear_image_results").click(function(e) { //button click to clear all votes per image. Just add a quick confirm to it
  146.                         if(!confirm('Are you sure you want to delete all votes for this image? This cannot be undone!')) {
  147.                              e.preventDefault();
  148.                              return false;
  149.                         }
  150.                 });
  151.         });
  152. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement