[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/jscripts/ -> rating.js (source)

   1  var Rating = {
   2      init: function()
   3      {
   4          var rating_elements = $(".star_rating");
   5          rating_elements.each(function()
   6          {
   7              var rating_element = $(this);
   8              var elements = rating_element.find("li a");
   9              if(rating_element.hasClass("star_rating_notrated"))
  10              {
  11                  elements.each(function()
  12                  {
  13                      var element = $(this);
  14                      element.on('click', function()
  15                      {
  16                          var parameterString = element.attr("href").replace(/.*\?(.*)/, "$1");
  17                          return Rating.add_rating(parameterString);
  18                      });
  19                  });
  20              }
  21              else
  22              {
  23                  elements.each(function()
  24                  {
  25                      var element = $(this);
  26                      element.attr("onclick", "return false;");
  27                      element.css("cursor", "default");
  28                      var element_id = element.attr("href").replace(/.*\?(.*)/, "$1").match(/tid=(.*)&(.*)&/)[1];
  29                      element.attr("title", $("#current_rating_"+element_id).text());
  30                  });
  31              }
  32          });
  33      },
  34  
  35      build_forumdisplay: function(tid, options)
  36      {
  37          var list = $("#rating_thread_"+tid);
  38          if(!list.length)
  39          {
  40              return;
  41          }
  42          
  43          list.addClass("star_rating")
  44              .addClass(options.extra_class);
  45  
  46          list_classes = new Array();
  47          list_classes[1] = 'one_star';
  48          list_classes[2] = 'two_stars';
  49          list_classes[3] = 'three_stars';
  50          list_classes[4] = 'four_stars';
  51          list_classes[5] = 'five_stars';
  52  
  53          for(var i = 1; i <= 5; i++)
  54          {
  55              var list_element = $("<li></li>");
  56              var list_element_a = $("<a></a>");
  57              list_element_a.addClass(list_classes[i])
  58                            .attr("title", lang.stars[i])
  59                            .attr("href", "./ratethread.php?tid="+tid+"&rating="+i+"&my_post_key="+my_post_key)
  60                            .html(i);
  61              list_element.append(list_element_a);
  62              list.append(list_element);
  63          }
  64      },
  65  
  66      add_rating: function(parameterString)
  67      {
  68          var tid = parameterString.match(/tid=(.*)&(.*)&/)[1];
  69          var rating = parameterString.match(/rating=(.*)&(.*)/)[1];
  70          $.ajax(
  71          {
  72              url: 'ratethread.php?ajax=1&my_post_key='+my_post_key+'&tid='+tid+'&rating='+rating,
  73              async: true,
  74              method: 'post',
  75              dataType: 'json',
  76              complete: function (request)
  77              {
  78                  Rating.rating_added(request, tid);
  79              }
  80          });
  81          return false;
  82      },
  83  
  84      rating_added: function(request, element_id)
  85      {
  86          var json = JSON.parse(request.responseText);
  87          if(json.hasOwnProperty("errors"))
  88          {
  89              $.each(json.errors, function(i, error)
  90              {
  91                  $.jGrowl(lang.ratings_update_error + ' ' + error, {theme:'jgrowl_error'});
  92              });
  93          }
  94          else if(json.hasOwnProperty("success"))
  95          {
  96              var element = $("#rating_thread_"+element_id);
  97              element.parent().before(element.next());
  98              element.removeClass("star_rating_notrated");
  99  
 100              $.jGrowl(json.success, {theme:'jgrowl_success'});
 101              if(json.hasOwnProperty("average"))
 102              {
 103                  $("#current_rating_"+element_id).html(json.average);
 104              }
 105  
 106              var rating_elements = $(".star_rating");
 107              rating_elements.each(function()
 108              {
 109                  var rating_element = $(this);
 110                  var elements = rating_element.find("li a");
 111                  if(rating_element.hasClass('star_rating_notrated'))
 112                  {
 113                      elements.each(function()
 114                      {
 115                          var element = $(this);
 116                          if(element.attr("id") == "rating_thread_" + element_id)
 117                          {
 118                              element.attr("onclick", "return false;")
 119                                     .css("cursor", "default")
 120                                     .attr("title", $("#current_rating_"+element_id).text());
 121                          }
 122                      });
 123                  }
 124              });
 125              $("#current_rating_"+element_id).css("width", json.width+"%");
 126          }
 127      }
 128  };
 129  
 130  if(use_xmlhttprequest == 1)
 131  {
 132      $(function()
 133      {
 134          Rating.init();
 135      });
 136  }


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref