rate_article.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Reads a cookie
  3. *
  4. * @param a the cookie name.
  5. * @return b the cookie value of the 'a' cookie.
  6. */
  7. function readCookie(a) {
  8. var b = "";
  9. a = a + "=";
  10. if(document.cookie.length > 0) {
  11. offset = document.cookie.indexOf(a);
  12. if(offset != -1) {
  13. offset += a.length;
  14. end = document.cookie.indexOf(";", offset);
  15. if(end == -1)end = document.cookie.length;
  16. b = unescape(document.cookie.substring(offset, end))
  17. }
  18. }return b
  19. }
  20. /**
  21. * Write in a cookie the rate star value
  22. *
  23. * @param a the cookie name.
  24. * @param b the cookie value of the 'a' cookie.
  25. * @param d the cookie expiration time.
  26. */
  27. function writeStar(a, b, d, f) {document.cookie = a + "=" + b + "; path = " + f; }
  28. /**
  29. * Set the rate (how many stars and the title description) and shows the feedback textarea
  30. *
  31. * @param star - how many stars the user selected.
  32. * @param title - the selected stars description: e.g. 'Somewhat helpful'.
  33. */
  34. function setRate(star, title){
  35. var x = document.getElementsByTagName('a');
  36. // set cookie
  37. writeStar('rateUGO2', star + ' -> ' + title,1440 ,'');
  38. for (i = 0; i < x.length; i++) {
  39. if (x[i].className.match('show_star')) {
  40. x[i].className = "";
  41. }
  42. }
  43. document.getElementById('rate_comment').className = 'show';
  44. document.getElementById(star).className = 'show_star';
  45. }
  46. $(function() {
  47. $('textarea#feedback').focus(function(){
  48. $(this).css({backgroundColor:"#fff"});
  49. });
  50. $('textarea#feedback').blur(function(){
  51. $(this).css({backgroundColor:"#fff"});
  52. });
  53. $(".button").click(function() {
  54. // process form
  55. var feedback = $("textarea#feedback").val();
  56. var dataString = '&feedback=' + feedback + '&page=' + window.location.href+ '&star=' + readCookie('rateUGO2');
  57. var pageRateFile = ratingFile;
  58. $.ajax({
  59. type: "POST",
  60. url: pageRateFile,
  61. data: dataString,
  62. success: function() {
  63. $('div#rate_stars').css({display:"none"});
  64. $('#rate_comment').html("<div class='rate_response'>Thank you for your feedback!</div>");
  65. $('#rate_response').html("")
  66. .hide()
  67. .fadeIn(1000, function() {
  68. $('#message').append("<img id='checkmark' src='../img/check.png' />");
  69. });
  70. }
  71. });
  72. return false;
  73. });
  74. });