repost.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup Timeline Timeline
  6. * @ingroup UnaModules
  7. *
  8. * @{
  9. */
  10. function BxTimelineRepost(oOptions) {
  11. this._sActionsUri = oOptions.sActionUri;
  12. this._sActionsUrl = oOptions.sActionUrl;
  13. this._sObjName = oOptions.sObjName == undefined ? 'oTimelineRepost' : oOptions.sObjName;
  14. this._iOwnerId = oOptions.iOwnerId == undefined ? 0 : oOptions.iOwnerId;
  15. this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'slide' : oOptions.sAnimationEffect;
  16. this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
  17. this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
  18. this._oRequestParams = oOptions.oRequestParams == undefined ? {} : oOptions.oRequestParams;
  19. }
  20. BxTimelineRepost.prototype = new BxTimelineMain();
  21. BxTimelineRepost.prototype.repostItem = function(oLink, iOwnerId, sType, sAction, iId) {
  22. var $this = this;
  23. var oDate = new Date();
  24. var oParams = {
  25. owner_id: iOwnerId,
  26. type: sType,
  27. action: sAction,
  28. object_id: iId,
  29. _t: oDate.getTime()
  30. };
  31. this.loadingIn(oLink, true);
  32. jQuery.post(
  33. this._sActionsUrl + 'repost/',
  34. oParams,
  35. function(oData) {
  36. $this.loadingIn(oLink, false);
  37. var oPopup = $(oLink).parents('.bx-popup-applied:visible:first');
  38. if(oPopup.length >0)
  39. oPopup.dolPopupHide();
  40. var oCounter = $this._getCounter(oLink);
  41. var bCounter = oCounter && oCounter.length > 0;
  42. var fContinue = function() {
  43. if(oData && oData.count != undefined && bCounter) {
  44. oCounter.html(oData.countf);
  45. oCounter.parents('.' + $this.sSP + '-repost-counter-holder:first').bx_anim(oData.count > 0 ? 'show' : 'hide');
  46. }
  47. if(oData && oData.disabled)
  48. $(oLink).removeAttr('onclick').addClass($(oLink).hasClass('bx-btn') ? 'bx-btn-disabled' : $this.sSP + '-repost-disabled');
  49. };
  50. if(oData && oData.message != undefined && oData.message.length > 0 && !bCounter)
  51. bx_alert(oData.message, fContinue);
  52. else
  53. fContinue();
  54. },
  55. 'json'
  56. );
  57. };
  58. BxTimelineRepost.prototype.repostItemWith = function(oLink, iOwnerId, sType, sAction, iId) {
  59. var $this = this;
  60. var oData = this._getDefaultData();
  61. oData = jQuery.extend({}, oData, {
  62. owner_id: iOwnerId,
  63. type: sType,
  64. action: sAction,
  65. object_id: iId
  66. });
  67. $(window).dolPopupAjax({
  68. id: {value: this._aHtmlIds['with_popup'], force: true},
  69. url: bx_append_url_params(this._sActionsUri + 'repost_with/', oData),
  70. closeOnOuterClick: false,
  71. removeOnClose: true,
  72. onBeforeShow: function() {
  73. $this.loadingIn(oLink, false);
  74. $(oLink).parents(".bx-popup-applied:visible:first").dolPopupHide();
  75. }
  76. });
  77. return false;
  78. };
  79. BxTimelineRepost.prototype.repostItemTo = function(oLink, iReposterId, sType, sAction, iId) {
  80. var $this = this;
  81. var oData = this._getDefaultData();
  82. oData = jQuery.extend({}, oData, {
  83. reposter_id: iReposterId,
  84. type: sType,
  85. action: sAction,
  86. object_id: iId
  87. });
  88. $(window).dolPopupAjax({
  89. id: {value: this._aHtmlIds['to_popup'], force: true},
  90. url: bx_append_url_params(this._sActionsUri + 'repost_to/', oData),
  91. closeOnOuterClick: false,
  92. removeOnClose: true,
  93. onBeforeShow: function() {
  94. $this.loadingIn(oLink, false);
  95. $(oLink).parents(".bx-popup-applied:visible:first").dolPopupHide();
  96. }
  97. });
  98. return false;
  99. };
  100. BxTimelineRepost.prototype.toggleByPopup = function(oLink, iId) {
  101. var oData = this._getDefaultData();
  102. oData['id'] = iId;
  103. $(oLink).dolPopupAjax({
  104. id: this._aHtmlIds['by_popup'] + iId,
  105. url: bx_append_url_params(this._sActionsUri + 'get_reposted_by/', oData)
  106. });
  107. return false;
  108. };
  109. BxTimelineRepost.prototype._getCounter = function(oElement) {
  110. var sSPRepost = this.sSP + '-repost';
  111. if($(oElement).hasClass(sSPRepost))
  112. return $(oElement).find('.' + sSPRepost + '-counter');
  113. else
  114. return $(oElement).parents('.' + sSPRepost + ':first').find('.' + sSPRepost + '-counter');
  115. };