BxDolCmtsReviews.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup UnaCore UNA Core
  6. * @{
  7. */
  8. function BxDolCmtsReviews (oOptions) {
  9. BxDolCmts.call(this, oOptions);
  10. this._sClassRating = this._sSP + '-rating';
  11. this._sClassRatingLegend = this._sSP + '-rating-legend';
  12. this._sClassRatingElement = this._sSP + '-rating-element';
  13. this._sAttributeRating = this._sSP + '-rating-data';
  14. }
  15. BxDolCmtsReviews.prototype = Object.create(BxDolCmts.prototype);
  16. BxDolCmtsReviews.prototype.constructor = BxDolCmtsReviews;
  17. BxDolCmtsReviews.prototype.cmtInit = function ()
  18. {
  19. var $this = this;
  20. $('.' + this._sClassRating).each(function() {
  21. $this.cmtInitRating($(this));
  22. });
  23. BxDolCmts.prototype.cmtInit.call(this);
  24. };
  25. BxDolCmtsReviews.prototype.cmtAfterEditSubmit = function (oCmtForm, oData, onComplete)
  26. {
  27. var $this = this;
  28. BxDolCmts.prototype.cmtAfterEditSubmit.call(this, oCmtForm, oData, function() {
  29. if(oData && oData.mood != undefined && oData.mood_legend_id != undefined)
  30. $this.cmtInitRating($('#' + oData.mood_legend_id).attr('cmt-rating-data', oData.mood));
  31. if(typeof onComplete == 'function')
  32. onComplete(oCmtForm, oData);
  33. });
  34. };
  35. BxDolCmtsReviews.prototype.cmtInitRating = function(oElement)
  36. {
  37. var fValue = oElement.attr(this._sAttributeRating);
  38. var iStarWidth = this._getStarWidth(oElement);
  39. this._getSlider(oElement).width(Math.round(fValue * iStarWidth));
  40. };
  41. BxDolCmtsReviews.prototype.vote = function(oLink, iValue)
  42. {
  43. this._iSaveWidth = Math.round(iValue * this._getStarWidth(oLink));
  44. $(oLink).parents('.' + this._sClassRatingElement + ':first').attr(this._sAttributeRating, iValue).find(':input:hidden').val(iValue);
  45. };
  46. BxDolCmtsReviews.prototype.over = function (oLink)
  47. {
  48. var oSlider = this._getSlider(oLink);
  49. var iIndex = this._getButtons(oLink).index(oLink);
  50. this._iSaveWidth = parseInt(oSlider.width());
  51. oSlider.width((iIndex + 1) * this._getStarWidth(oLink));
  52. };
  53. BxDolCmtsReviews.prototype.out = function (oLink)
  54. {
  55. this._getSlider(oLink).width(this._iSaveWidth);
  56. };
  57. BxDolCmtsReviews.prototype._getButtons = function(oElement)
  58. {
  59. if($(oElement).hasClass(this._sClassRatingElement))
  60. return $(oElement).find('.' + this._sSP + '-mood-button');
  61. else
  62. return $(oElement).parents('.' + this._sClassRatingElement + ':first').find('.' + this._sSP + '-mood-button');
  63. };
  64. BxDolCmtsReviews.prototype._getSlider = function(oElement, sParent) {
  65. var sSlider = (sParent != undefined && sParent.length > 0 ? sParent + ' ' : '') + '.' + this._sSP + '-mood-slider';
  66. if($(oElement).hasClass(this._sClassRating))
  67. return $(oElement).find(sSlider);
  68. else
  69. return $(oElement).parents('.' + this._sClassRating + ':first').find(sSlider);
  70. };
  71. BxDolCmtsReviews.prototype._getStarWidth = function(oElement)
  72. {
  73. return this._getSlider(oElement).find('.sys-icon').width();
  74. };
  75. /** @} */