[ Index ]

PHP Cross Reference of MyBB

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(rating_element) {
   6              var elements = Element.getElementsBySelector(rating_element, 'li a');
   7              if(Element.hasClassName(rating_element, 'star_rating_notrated'))
   8              {
   9                  elements.each(function(element) {
  10                      element.onclick = function() {
  11                          var parameterString = this.href.replace(/.*\?(.*)/, "$1");
  12                          return Rating.add_rating(parameterString);
  13                      };
  14                  });
  15              }
  16              else
  17              {
  18                  elements.each(function(element) {
  19                      element.onclick = function() { return false; };
  20                      element.style.cursor = 'default';
  21                      var element_id = element.href.replace(/.*\?(.*)/, "$1").match(/tid=(.*)&(.*)&/)[1];
  22                      element.title = $('current_rating_'+element_id).innerHTML;
  23                  });
  24              }
  25          });
  26      },
  27      
  28      build_forumdisplay: function(tid, options)
  29      {
  30          if(!$('rating_thread_'+tid))
  31          {
  32              return;
  33          }
  34          var list = document.getElementById('rating_thread_'+tid);
  35          list.className = 'star_rating' + options.extra_class;
  36          
  37          list_classes = new Array();
  38          list_classes[1] = 'one_star';
  39          list_classes[2] = 'two_stars';
  40          list_classes[3] = 'three_stars';
  41          list_classes[4] = 'four_stars';
  42          list_classes[5] = 'five_stars';
  43  
  44          for(var i = 1; i <= 5; i++)
  45          {
  46              var list_element = document.createElement('li');
  47              var list_element_a = document.createElement('a');
  48              list_element_a.className = list_classes[i];
  49              list_element_a.title = lang.stars[i];
  50              list_element_a.href = './ratethread.php?tid='+tid+'&rating='+i+'&my_post_key='+my_post_key;
  51              list_element_a.innerHTML = i;
  52              list_element.appendChild(list_element_a);
  53              list.appendChild(list_element);
  54          }
  55      },
  56  
  57      add_rating: function(parameterString)
  58      {
  59          this.spinner = new ActivityIndicator('body', {image: imagepath + "/spinner_big.gif"});
  60          var element_id = parameterString.match(/tid=(.*)&(.*)&/)[1];
  61          new Ajax.Request('ratethread.php?ajax=1&my_post_key='+my_post_key, {
  62              method: 'post',
  63              postBody: parameterString,
  64              onComplete: function(request) { Rating.rating_added(request, element_id); }
  65          });
  66          document.body.style.cursor = 'wait';
  67          return false;
  68      },
  69  
  70      rating_added: function(request, element_id)
  71      {
  72          if(request.responseText.match(/<error>(.*)<\/error>/))
  73          {
  74              message = request.responseText.match(/<error>(.*)<\/error>/);
  75              if(!message[1])
  76              {
  77                  message[1] = 'An unknown error occurred.';
  78              }
  79              if(this.spinner)
  80              {
  81                  this.spinner.destroy();
  82                  this.spinner = '';
  83              }
  84              document.body.style.cursor = 'default';
  85              alert('There was an error performing the update.\n\n'+message[1]);
  86          }
  87          else if(request.responseText.match(/<success>(.*)<\/success>/))
  88          {
  89              if(!$('success_rating_' + element_id))
  90              {
  91                  var success = document.createElement('span');
  92                  var element = $('rating_thread_' + element_id);
  93                  element.parentNode.insertBefore(success, element.nextSibling);
  94                  element.removeClassName('star_rating_notrated');
  95              }
  96              else
  97              {
  98                  var success = $('success_rating_' + element_id);
  99              }
 100              success.className = 'star_rating_success';
 101              success.id = 'success_rating_' + element_id;
 102              success.innerHTML = request.responseText.match(/<success>(.*)<\/success>/)[1];
 103  
 104              if(request.responseText.match(/<average>(.*)<\/average>/))
 105              {
 106                  $('current_rating_' + element_id).innerHTML = request.responseText.match(/<average>(.*)<\/average>/)[1];
 107              }
 108  
 109              var rating_elements = $$('.star_rating');
 110              rating_elements.each(function(rating_element) {
 111                  var elements = Element.getElementsBySelector(rating_element, 'li a');
 112                  elements.each(function(element) {
 113                      if(element.id == "rating_thread_" + element_id) {
 114                          element.onclick = function() { return false; };
 115                          element.style.cursor = 'default';
 116                          element.title = $('current_rating_'+element_id).innerHTML;
 117                      }
 118                  });
 119              });
 120              window.setTimeout("Element.remove('success_rating_" + element_id + "')", 5000);
 121              document.body.style.cursor = 'default';
 122              $('current_rating_' + element_id).style.width = request.responseText.match(/<width>(.*)<\/width>/)[1]+"%";
 123          }
 124  
 125          if(this.spinner)
 126          {
 127              this.spinner.destroy();
 128              this.spinner = '';
 129          }
 130      }
 131  };
 132  
 133  if(use_xmlhttprequest == 1)
 134  {
 135      Event.observe(document, 'dom:loaded', Rating.init);
 136  }


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1