entry.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup Polls Polls
  6. * @ingroup UnaModules
  7. *
  8. * @{
  9. */
  10. function BxPollsEntry(oOptions) {
  11. this._sActionsUrl = oOptions.sActionUrl;
  12. this._sObjName = oOptions.sObjName == undefined ? 'oBxPollsEntry' : oOptions.sObjName;
  13. this._bEmbed = oOptions.bEmbed == undefined ? false : oOptions.bEmbed;
  14. this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
  15. this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
  16. this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
  17. this._oRequestParams = oOptions.oRequestParams == undefined ? {} : oOptions.oRequestParams;
  18. var $this = this;
  19. if(this._bEmbed)
  20. $(document).ready(function() {
  21. $this.resizeEmbed();
  22. });
  23. }
  24. BxPollsEntry.prototype.resizeEmbed = function() {
  25. var oEntry = $('.bx-polls-content:last');
  26. if(!oEntry || oEntry.length == 0)
  27. return;
  28. var iEntryId = parseInt(oEntry.attr('id').replace(this._aHtmlIds['content'], ''));
  29. var iEntryHeight = oEntry.height();
  30. if(!iEntryId || !iEntryHeight)
  31. return;
  32. window.parent.$('iframe#' + this._aHtmlIds['embed'] + iEntryId).height(iEntryHeight);
  33. };
  34. BxPollsEntry.prototype.changeBlockSnippet = function(oLink, sBlock, mixedContent) {
  35. var $this = this;
  36. this.changeBlock(oLink, sBlock, mixedContent, function(iContentId, oData) {
  37. $(oLink).hide().siblings('.bx-base-text-unit-switcher:hidden').show();
  38. $(oLink).parents('.bx-base-text-unit:first').find('#' + $this._aHtmlIds['content'] + iContentId).bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
  39. $(this).replaceWith(oData.content);
  40. });
  41. });
  42. };
  43. BxPollsEntry.prototype.changeBlock = function(oLink, sBlock, mixedContent, onComplete) {
  44. var $this = this;
  45. this.loadingInBlock(oLink, true);
  46. if(typeof onComplete !== 'function')
  47. onComplete = function(iContentId, oData) {
  48. var sContentId = $this._aHtmlIds['content'] + iContentId;
  49. var oContent = $(oLink).parents('.bx-db-container:first').find('#' + sContentId);
  50. if(!oContent.length)
  51. oContent = $('#' + sContentId);
  52. if(!oContent.length)
  53. return;
  54. oContent.bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
  55. $(this).replaceWith(oData.content);
  56. if(this._bEmbed || sBlock === 'results')
  57. $this.resizeEmbed();
  58. });
  59. };
  60. var iContentId = 0;
  61. var oParams = {
  62. block: sBlock,
  63. };
  64. switch(typeof mixedContent) {
  65. case 'number':
  66. iContentId = parseInt(mixedContent);
  67. oParams['content_id'] = iContentId;
  68. break;
  69. case 'object':
  70. iContentId = parseInt(mixedContent.content_id);
  71. oParams = $.extend({}, oParams, mixedContent);
  72. break;
  73. }
  74. jQuery.get (
  75. this._sActionsUrl + 'get_block',
  76. oParams,
  77. function(oData) {
  78. if(oLink)
  79. $this.loadingInBlock(oLink, false);
  80. if(!oData.content)
  81. return;
  82. if(typeof onComplete === 'function')
  83. onComplete(iContentId, oData);
  84. },
  85. 'json'
  86. );
  87. };
  88. BxPollsEntry.prototype.onVote = function(oLink, oData, iContentId, sSalt) {
  89. //--- Check for block submenu (tabs)
  90. var oMenuLink = $('#' + this._aHtmlIds['block_link_results'] + sSalt);
  91. if(oMenuLink.length > 0) {
  92. oMenuLink.click();
  93. return;
  94. }
  95. //--- Check for snippet meta submenu
  96. var oMenuLink = $('#' + this._aHtmlIds['snippet_link_results'] + sSalt);
  97. if(oMenuLink.length > 0) {
  98. oMenuLink.click();
  99. return;
  100. }
  101. this.changeBlock(oLink, 'results', {content_id: iContentId, salt: sSalt});
  102. };
  103. BxPollsEntry.prototype.loadingInBlock = function(e, bShow) {
  104. var oParent = $(e).length ? $(e).parents('.bx-db-container:first') : $('body');
  105. bx_loading(oParent, bShow);
  106. };