BxDolCmts.js 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  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 BxDolCmts (options) {
  9. this._sObjName = undefined == options.sObjName ? 'oCmts' : options.sObjName; // javascript object name, to run current object instance from onTimer
  10. this._sActionsUrl = options.sRootUrl + 'cmts.php'; // actions url address
  11. this._sSystem = options.sSystem; // current comment system
  12. this._iAuthorId = options.iAuthorId; // this comment's author ID.
  13. this._iObjId = options.iObjId; // this object id comments
  14. this._sBaseUrl = options.sBaseUrl; // base url to view comment's listing.
  15. this._sSocket = options.sSocket === undefined ? this._sSystem : options.sSocket;
  16. this._iMinPostForm = undefined == options.iMinPostForm ? 0 : options.iMinPostForm;
  17. this._sPostFormPosition = undefined == options.sPostFormPosition ? 'top' : options.sPostFormPosition;
  18. this._sDisplayType = undefined == options.sDisplayType ? 'threaded' : options.sDisplayType;
  19. this._iDisplayStructure = undefined == options.iDisplayStructure ? 0 : options.iDisplayStructure;
  20. this._sBrowseType = undefined == options.sBrowseType ? 'tail' : options.sBrowseType;
  21. this._sBrowseFilter = undefined == options.sBrowseFilter ? 'all' : options.sBrowseFilter;
  22. this._sSP = options.sStylePrefix === undefined ? 'cmt' : options.sStylePrefix;
  23. this._aParams = options.aParams === undefined ? false : options.aParams;
  24. this._aHtmlIds = options.aHtmlIds;
  25. this._sAnimationEffect = 'fade';
  26. this._iAnimationSpeed = 'slow';
  27. this._oSavedTexts = {};
  28. this._sRootId = '#cmts-box-' + this._sSystem + '-' + this._iObjId;
  29. this._bLiveUpdatePaused = false;
  30. }
  31. /*--- Main layout functionality ---*/
  32. BxDolCmts.prototype.cmtInit = function()
  33. {
  34. var $this = this;
  35. $(document).ready(function() {
  36. // init socket
  37. if(window.oBxDolSockets !== undefined && $this._sSocket)
  38. oBxDolSockets.subscribe($this._sSocket, $this._iObjId, 'comment_added', function(oData) {
  39. $this.cmtUpdateCounterAs(oData);
  40. $this.showLiveUpdateForSocket(oData);
  41. });
  42. // init post comment form
  43. var sFormId = $this._sRootId + ' .cmt-post-reply form';
  44. if ($(sFormId).length) {
  45. $(sFormId).each(function() {
  46. $this.cmtInitFormPost($(this));
  47. });
  48. }
  49. // blink (highlight) necessary comments
  50. $this._cmtsBlink($($this._sRootId));
  51. // check content to show 'See More'
  52. $this._cmtsInitSeeMore($($this._sRootId));
  53. // init gallery
  54. $this._cmtsInitGallery($($this._sRootId));
  55. });
  56. };
  57. BxDolCmts.prototype.cmtInitFormPost = function(oCmtForm)
  58. {
  59. var $this = this;
  60. oCmtForm.ajaxForm({
  61. dataType: "json",
  62. beforeSubmit: function (formData, jqForm, options) {
  63. window[$this._sObjName].cmtBeforePostSubmit(oCmtForm);
  64. },
  65. success: function (oData) {
  66. window[$this._sObjName].cmtAfterPostSubmit(oCmtForm, oData);
  67. }
  68. });
  69. };
  70. BxDolCmts.prototype.cmtShowForm = function(oElement)
  71. {
  72. var oForm = $(oElement).parents('.cmt-reply.cmt-reply-min:first');
  73. oForm.find('.cmt-body-min').bx_anim('hide', this._sAnimationEffect, this._iAnimationSpeed, function() {
  74. oForm.find('.cmt-body').show(function() {
  75. var oTextarea = oForm.find("[name='cmt_text']");
  76. if(oTextarea && oTextarea.hasClass('bx-form-input-html') && typeof bx_editor_get_htmleditable === 'function')
  77. oTextarea = bx_editor_get_htmleditable(oTextarea);
  78. if(!oTextarea || oTextarea.length == 0)
  79. return;
  80. if (oTextarea.attr('object_editor'))
  81. eval('bx_editor_activate(' + oTextarea.attr('object_editor') + ')');
  82. else
  83. oTextarea.focus();
  84. });
  85. });
  86. };
  87. BxDolCmts.prototype.cmtBeforePostSubmit = function(oCmtForm)
  88. {
  89. this._loadingInButton($(oCmtForm).children().find(':submit'), true);
  90. };
  91. BxDolCmts.prototype.cmtAfterPostSubmit = function (oCmtForm, oData)
  92. {
  93. var $this = this;
  94. var fContinue = function() {
  95. var oParent = oCmtForm.parents('.cmt-reply:first');
  96. if(oData && oData.id != undefined) {
  97. $this._getCmt(oCmtForm, oData.id);
  98. //--- Update form
  99. var iCmtParentId = parseInt(oData.parent_id);
  100. if(iCmtParentId == 0)
  101. $this._getForm(undefined, {CmtParent: iCmtParentId}, function(sFormWrp) {
  102. if(sFormWrp && sFormWrp.length > 0)
  103. sFormWrp = $(sFormWrp).html();
  104. oParent.hide().html(sFormWrp).bxProcessHtml().show();
  105. $this.cmtInitFormPost(oParent.find('form'));
  106. });
  107. else
  108. oParent.remove();
  109. //--- Update counter
  110. $this.cmtUpdateCounter(oCmtForm, oData);
  111. return;
  112. }
  113. if(oData && oData.form != undefined && oData.form_id != undefined) {
  114. oParent.find('form').replaceWith(oData.form);
  115. $this.cmtInitFormPost(oParent.find('form'));
  116. return;
  117. }
  118. };
  119. this._loadingInButton($(oCmtForm).children().find(':submit'), false);
  120. // Posted: a subtle success; turned down (the form comes back, or a message instead of the comment): error.
  121. if(oData && typeof(bx_sound) == 'function')
  122. bx_sound(oData.id != undefined ? 'success' : 'error', oData.id != undefined ? {emphasis: 'subtle'} : undefined);
  123. if(oData && oData.msg != undefined)
  124. bx_alert(oData.msg, fContinue);
  125. else
  126. fContinue();
  127. };
  128. BxDolCmts.prototype.cmtInitFormEdit = function(sCmtFormId)
  129. {
  130. var $this = this;
  131. var oCmtForm = $('#' + sCmtFormId);
  132. oCmtForm.ajaxForm({
  133. dataType: "json",
  134. beforeSubmit: function (formData, jqForm, options) {
  135. window[$this._sObjName].cmtBeforeEditSubmit(oCmtForm);
  136. },
  137. success: function (oData) {
  138. window[$this._sObjName].cmtAfterEditSubmit(oCmtForm, oData);
  139. }
  140. });
  141. };
  142. BxDolCmts.prototype.cmtBeforeEditSubmit = function(oCmtForm)
  143. {
  144. this._loadingInButton($(oCmtForm).children().find(':submit'), true);
  145. };
  146. BxDolCmts.prototype.cmtAfterEditSubmit = function (oCmtForm, oData, onComplete)
  147. {
  148. var $this = this;
  149. var fContinue = function() {
  150. if(oData && oData.id != undefined && oData.content != undefined) {
  151. var iCmtId = parseInt(oData.id);
  152. if(iCmtId > 0) {
  153. $('#cmt' + iCmtId + ' .cmt-cont-cnt:first').bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
  154. $(this).html(oData.content).bxProcessHtml().bx_anim('show', $this._sAnimationEffect, $this._iAnimationSpeed);
  155. });
  156. }
  157. }
  158. if(oData && oData.form != undefined && oData.form_id != undefined) {
  159. $('#' + oData.form_id).replaceWith(oData.form);
  160. $this.cmtInitFormEdit(oData.form_id);
  161. }
  162. if(typeof onComplete == 'function')
  163. onComplete(oCmtForm, oData);
  164. };
  165. this._loadingInButton($(oCmtForm).children().find(':submit'), false);
  166. // Saved: a subtle success; the form back with an error: error.
  167. if(oData && typeof(bx_sound) == 'function')
  168. if(oData.form != undefined && oData.form_id != undefined)
  169. bx_sound('error');
  170. else if(oData.id != undefined)
  171. bx_sound('success', {emphasis: 'subtle'});
  172. if(oData && oData.msg != undefined)
  173. bx_alert(oData.msg, fContinue);
  174. else
  175. fContinue();
  176. };
  177. BxDolCmts.prototype.cmtUpdateCounter = function (oElement, oData)
  178. {
  179. if(oData && (oData.count == undefined || parseInt(oData.count) == 0))
  180. return;
  181. if(oData.countf != undefined && oData.countf.length != 0) {
  182. var oCounter = this._getCounter(oElement);
  183. if(oCounter && oCounter.length > 0)
  184. oCounter.replaceWith(oData.countf);
  185. }
  186. var oCounter = this._getCounter(oElement, true);
  187. if(oCounter && oCounter.length > 0)
  188. oCounter.html(oData.count);
  189. var sClassHidden = 'sys-ac-hidden';
  190. if(!oCounter.is('.' + sClassHidden))
  191. oCounter = oCounter.parents('.' + sClassHidden + ':first');
  192. oCounter.toggleClass(sClassHidden);
  193. };
  194. BxDolCmts.prototype.cmtUpdateCounterAs = function (oData)
  195. {
  196. this.cmtUpdateCounter(null, JSON.parse(oData));
  197. };
  198. BxDolCmts.prototype.cmtPin = function(oLink, iCmtId, iWay, bHideMenu) {
  199. var $this = this;
  200. if(bHideMenu == undefined || bHideMenu)
  201. $(oLink).parents('.bx-popup-applied:first:visible').dolPopupHide();
  202. var oParams = this._getDefaultActions();
  203. oParams['action'] = 'Pin';
  204. oParams['Cmt'] = iCmtId;
  205. oParams['way'] = iWay;
  206. var oCmt = $(this._sRootId + ' #cmt' + iCmtId);
  207. this._loadingInBlock(oCmt, true);
  208. jQuery.post (
  209. this._sActionsUrl,
  210. oParams,
  211. function (oData) {
  212. var fContinue = function() {
  213. if(oData && oData.parent_id != undefined) {
  214. $this._getCmts(oLink, {
  215. CmtParent: oData.parent_id,
  216. CmtBrowse: $this._sBrowseType,
  217. CmtFilter: $this._sBrowseFilter,
  218. CmtDisplay: $this._sDisplayType,
  219. CmtPinned: 1
  220. }, function(sListId, sContent) {
  221. $this._loadingInBlock(oCmt, false);
  222. $this._sDisplayType = $this._sDisplayType;
  223. $this._cmtsReplaceContent($(sListId), sContent);
  224. var oDivider = $(sListId).siblings('.cmts-divider');
  225. if(oDivider.length > 0) {
  226. if(oDivider.is(':hidden') && sContent.length != 0)
  227. oDivider.show();
  228. else if(!oDivider.is(':hidden') && sContent.length == 0)
  229. oDivider.hide();
  230. }
  231. });
  232. }
  233. };
  234. if(oData && oData.msg != undefined)
  235. bx_alert(oData.msg, fContinue);
  236. else
  237. fContinue();
  238. },
  239. 'json'
  240. );
  241. };
  242. BxDolCmts.prototype.cmtEdit = function(oLink, iCmtId, bHideMenu) {
  243. var $this = this;
  244. if(bHideMenu == undefined || bHideMenu)
  245. $(oLink).parents('.bx-popup-applied:first:visible').dolPopupHide();
  246. var sContentId = this._sRootId + ' #cmt' + iCmtId + ' .cmt-cont-cnt:first';
  247. if ($(sContentId + ' > form').length) {
  248. $(sContentId).bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
  249. $(this).html($this._oSavedTexts[iCmtId]).bxProcessHtml().bx_anim('show', $this._sAnimationEffect, $this._iAnimationSpeed);
  250. });
  251. return;
  252. }
  253. var oParams = this._getDefaultActions();
  254. oParams['action'] = 'GetFormEdit';
  255. oParams['Cmt'] = iCmtId;
  256. this._oSavedTexts[iCmtId] = $(sContentId).html();
  257. this._loadingInContent(oLink, true);
  258. jQuery.post (
  259. this._sActionsUrl,
  260. oParams,
  261. function (oData) {
  262. var fContinue = function() {
  263. if(oData && oData.form != undefined && oData.form_id != undefined) {
  264. $(sContentId).bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
  265. $(this).html(oData.form).bxProcessHtml().bx_anim('show', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
  266. $this.cmtInitFormEdit(oData.form_id);
  267. });
  268. });
  269. }
  270. };
  271. $this._loadingInContent(oLink, false);
  272. if(oData && oData.msg != undefined)
  273. bx_alert(oData.msg, fContinue);
  274. else
  275. fContinue();
  276. },
  277. 'json'
  278. );
  279. };
  280. BxDolCmts.prototype.cmtRemove = function(e, iCmtId) {
  281. var $this = this;
  282. $(e).parents('.bx-popup-active:first').dolPopupHide();
  283. bx_confirm('', function() {
  284. var oParams = $this._getDefaultActions();
  285. oParams['action'] = 'Remove';
  286. oParams['Cmt'] = iCmtId;
  287. $this._loadingInContent(e, true);
  288. jQuery.post (
  289. $this._sActionsUrl,
  290. oParams,
  291. function(oData) {
  292. var fContinue = function() {
  293. if(oData && oData.id != undefined) {
  294. $(e).parents('.bx-popup-applied:first:visible').dolPopupHide();
  295. var fDelete = function() {
  296. var sCmtSel = '#cmt' + oData.id;
  297. $(sCmtSel).bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
  298. //--- Update counter
  299. if(oData && oData.count != undefined && parseInt(oData.count) >= 0) {
  300. var oSource = $(this);
  301. var oCounter = $this._getCounter(oSource);
  302. if(oCounter && oCounter.length > 0) {
  303. if(oData.countf != undefined && oData.countf.length != 0)
  304. oCounter.html(oData.countf);
  305. if(parseInt(oData.count) == 0)
  306. oCounter.toggleClass('sys-ac-hidden');
  307. }
  308. var oCounter = $this._getCounter(oSource, true);
  309. if(oCounter && oCounter.length > 0)
  310. oCounter.html(oData.count);
  311. }
  312. $(this).remove();
  313. var oCmt = $(sCmtSel);
  314. if(oCmt && oCmt.length > 0)
  315. fDelete();
  316. });
  317. };
  318. fDelete();
  319. }
  320. };
  321. $this._loadingInContent(e, false);
  322. if(oData && oData.msg != undefined)
  323. bx_alert(oData.msg, fContinue);
  324. else
  325. fContinue();
  326. },
  327. 'json'
  328. );
  329. });
  330. };
  331. BxDolCmts.prototype.cmtLoad = function(oLink, iCmtParentId, iStart, iPerView)
  332. {
  333. var $this = this;
  334. var bButton = $(oLink).hasClass('bx-btn');
  335. if(bButton)
  336. this._loadingInButton(oLink, true);
  337. else
  338. this._loading($(oLink).parents('ul.cmts:first'), true);
  339. this._getCmts(oLink, {
  340. CmtParent: iCmtParentId,
  341. CmtStart: iStart,
  342. CmtPerView: iPerView,
  343. CmtBrowse: this._sBrowseType,
  344. CmtFilter: this._sBrowseFilter,
  345. CmtDisplay: this._sDisplayType,
  346. CmtDisplayStructure: this._iDisplayStructure
  347. }, function(sListId, sContent) {
  348. if(bButton)
  349. $this._loadingInButton(oLink, false);
  350. else
  351. $this._loading($(oLink).parents('ul.cmts:first'), false);
  352. $this._cmtsReplace($(oLink).parents('li:first'), sContent);
  353. });
  354. };
  355. BxDolCmts.prototype.cmtChangeDisplay = function(oLink, sType)
  356. {
  357. var $this = this;
  358. this._getCmts(oLink, {
  359. CmtParent: 0,
  360. CmtBrowse: this._sBrowseType,
  361. CmtFilter: this._sBrowseFilter,
  362. CmtDisplay: sType
  363. }, function(sListId, sContent) {
  364. $this._sDisplayType = sType;
  365. $this._cmtsReplaceContent($(sListId), sContent);
  366. });
  367. };
  368. BxDolCmts.prototype.cmtChangeBrowse = function(oLink, sType)
  369. {
  370. var $this = this;
  371. this._getCmts(oLink, {
  372. CmtParent: 0,
  373. CmtBrowse: sType,
  374. CmtFilter: this._sBrowseFilter,
  375. CmtDisplay: this._sDisplayType
  376. }, function(sListId, sContent) {
  377. $this._sBrowseType = sType;
  378. $this._cmtsReplaceContent($(sListId), sContent);
  379. });
  380. };
  381. BxDolCmts.prototype.cmtChangeFilter = function(oLink, sType)
  382. {
  383. var $this = this;
  384. this._getCmts(oLink, {
  385. CmtParent: 0,
  386. CmtBrowse: this._sBrowseType,
  387. CmtFilter: sType,
  388. CmtDisplay: this._sDisplayType
  389. }, function(sListId, sContent) {
  390. $this._sBrowseFilter = sType;
  391. $this._cmtsReplaceContent($(sListId), sContent);
  392. });
  393. };
  394. BxDolCmts.prototype.showReplacement = function(iCmtId)
  395. {
  396. $('#cmt' + iCmtId + '-hidden').bx_anim('hide', this._sAnimationEffect, this._iAnimationSpeed, function(){
  397. $(this).next('#cmt' + iCmtId).bx_anim('show', this._sAnimationEffect, this._iAnimationSpeed);
  398. });
  399. };
  400. BxDolCmts.prototype.toggleReply = function(oElement, iCmtParentId, iQuote)
  401. {
  402. var $this = this;
  403. var aParams = {
  404. CmtParent: iCmtParentId,
  405. CmtQuote: iQuote != undefined ? parseInt(iQuote) : 0
  406. };
  407. var fOnShow = function() {
  408. $(this).find('textarea:first').focus();
  409. };
  410. var oParentId = null;
  411. if(oElement)
  412. oParentId = $(oElement).parents('#cmt' + iCmtParentId);
  413. else
  414. oParentId = $(this._sRootId + ' #cmt' + iCmtParentId);
  415. var sReplyQuoteId = '.cmt-reply-quote';
  416. var sReplyQuoteIdOpst = ':not(' + sReplyQuoteId + ')';
  417. var sReplyId = '';
  418. var sReplyIdOpst = '';
  419. if(aParams['CmtQuote']) {
  420. sReplyId = '.cmt-reply' + sReplyQuoteId;
  421. sReplyIdOpst = '.cmt-reply' + sReplyQuoteIdOpst;
  422. }
  423. else {
  424. sReplyId = '.cmt-reply' + sReplyQuoteIdOpst;
  425. sReplyIdOpst = '.cmt-reply' + sReplyQuoteId;
  426. }
  427. //--- Hide opposite form.
  428. if (oParentId.find('> ' + sReplyIdOpst + ':visible').length)
  429. oParentId.find('> ' + sReplyIdOpst).hide();
  430. if (oParentId.find('> ' + sReplyId).length) {
  431. oParentId.find('> ' + sReplyId).bx_anim('toggle', this._sAnimationEffect, this._iAnimationSpeed, fOnShow);
  432. return;
  433. }
  434. this._getForm(oElement, aParams, function(sForm) {
  435. var oForm = $(sForm).hide().addClass('cmt-reply-' + $this._sPostFormPosition).addClass('cmt-reply-margin');
  436. var oFormSibling = oParentId.find('> ul.cmts:first');
  437. switch($this._sPostFormPosition) {
  438. case 'top':
  439. oFormSibling.before(oForm);
  440. break;
  441. case 'bottom':
  442. oFormSibling.after(oForm);
  443. break;
  444. }
  445. $this.cmtInitFormPost(oForm.find('form'));
  446. oParentId.children(sReplyId).bx_anim('toggle', $this._sAnimationEffect, $this._iAnimationSpeed, fOnShow);
  447. });
  448. };
  449. BxDolCmts.prototype.toggleQuote = function(e, iCmtParentId)
  450. {
  451. this.toggleReply(e, iCmtParentId, 1);
  452. };
  453. BxDolCmts.prototype.goTo = function(oLink, sGoToId, sBlinkIds, onLoad)
  454. {
  455. $(oLink).parents('.bx-popup-applied:first:visible').dolPopupHide();
  456. var $this = this;
  457. this._getCmts(null, {
  458. CmtParent: 0,
  459. CmtBrowse: this._sBrowseType,
  460. CmtFilter: this._sBrowseFilter,
  461. CmtDisplay: this._sDisplayType,
  462. CmtBlink: sBlinkIds
  463. }, function(sListId, sContent) {
  464. $this._cmtsReplaceContent($(sListId), sContent, function() {
  465. location.hash = sGoToId;
  466. if(typeof onLoad == 'function')
  467. onLoad();
  468. });
  469. });
  470. };
  471. BxDolCmts.prototype.goToBtn = function(oLink, sGoToId, sBlinkIds, onLoad)
  472. {
  473. var $this = this;
  474. this._loadingInButton(oLink, true);
  475. this._getCmts(null, {
  476. CmtParent: 0,
  477. CmtBrowse: this._sBrowseType,
  478. CmtFilter: this._sBrowseFilter,
  479. CmtDisplay: this._sDisplayType,
  480. CmtBlink: sBlinkIds
  481. }, function(sListId, sContent) {
  482. $this._cmtsReplaceContent($(sListId), sContent, function() {
  483. location.hash = sGoToId;
  484. if(typeof onLoad == 'function')
  485. onLoad();
  486. $(oLink).parents('.cmt-lu-button:first').remove();
  487. $this.resumeLiveUpdates();
  488. });
  489. });
  490. };
  491. BxDolCmts.prototype.goToAndReply = function(oLink, sGoToId, sBlinkIds)
  492. {
  493. var $this = this;
  494. this.goTo(oLink, sGoToId, sBlinkIds, function() {
  495. var aBlinkIds = sBlinkIds.split(",");
  496. $.each(aBlinkIds, function(iIndex, iValue) {
  497. $this.toggleReply(null, iValue);
  498. });
  499. });
  500. };
  501. /*----------------------------*/
  502. /*--- Live Updates methods ---*/
  503. /*----------------------------*/
  504. BxDolCmts.prototype.showLiveUpdate = function(oData)
  505. {
  506. if(!oData.code)
  507. return;
  508. var oButton = $(oData.code);
  509. var sId = oButton.attr('id');
  510. $('#' + sId).remove();
  511. oButton.prependTo(this._sRootId).bxProcessHtml();
  512. };
  513. BxDolCmts.prototype.showLiveUpdateForSocket = function(sData)
  514. {
  515. var oData = JSON.parse(sData);
  516. if(this._iAuthorId == oData.author_id)
  517. return;
  518. var sSelector = this._sRootId + ' .' + this._sSP + '-lu-button';
  519. if($(sSelector + ':visible').length != 0)
  520. return;
  521. var oElement = $(sSelector + ':hidden').clone();
  522. if(!oElement || oElement.length == 0)
  523. return;
  524. var sOnClick = oElement.find('.bx-btn').attr('onclick');
  525. oElement.find('.bx-btn').attr('onclick', sOnClick.replace('{cmt_id}', oData.id).replace('{cmt_anchor}', oData.anchor));
  526. oElement.prependTo(this._sRootId).show();
  527. };
  528. BxDolCmts.prototype.showLiveUpdates = function(oData)
  529. {
  530. /*
  531. * Note. oData.count_old and oData.count_new are also available and can be checked or used in notification popup.
  532. */
  533. if(!oData.code)
  534. return;
  535. var $this = this;
  536. var oNotifs = $(oData.code);
  537. var sId = oNotifs.attr('id');
  538. $('#' + sId).remove();
  539. oNotifs.prependTo('body').dolPopup({
  540. position: 'fixed',
  541. left: '1rem',
  542. top: 'auto',
  543. bottom: '1rem',
  544. fog: false,
  545. onBeforeShow: function() {
  546. },
  547. onBeforeHide: function() {
  548. },
  549. onShow: function() {
  550. setTimeout(function() {
  551. $('.bx-popup-chain.bx-popup-applied:visible:first').dolPopupHide();
  552. }, 5000);
  553. },
  554. onHide: function() {
  555. $this.resumeLiveUpdates();
  556. }
  557. });
  558. };
  559. BxDolCmts.prototype.previousLiveUpdate = function(oLink)
  560. {
  561. var fPrevious = function() {
  562. var sClass = 'bx-popup-chain-item';
  563. $(oLink).parents('.' + sClass + ':first').hide().prev('.' + sClass).show();
  564. };
  565. if(!this.pauseLiveUpdates(fPrevious));
  566. fPrevious();
  567. };
  568. BxDolCmts.prototype.hideLiveUpdate = function(oLink)
  569. {
  570. $(oLink).parents('.bx-popup-applied:visible:first').dolPopupHide();
  571. };
  572. BxDolCmts.prototype.resumeLiveUpdates = function(onLoad)
  573. {
  574. if(!this._bLiveUpdatePaused)
  575. return false;
  576. var $this = this;
  577. this.changeLiveUpdates('ResumeLiveUpdate', function() {
  578. $this._bLiveUpdatePaused = false;
  579. if(typeof onLoad == 'function')
  580. onLoad();
  581. });
  582. return true;
  583. };
  584. BxDolCmts.prototype.pauseLiveUpdates = function(onLoad)
  585. {
  586. if(this._bLiveUpdatePaused)
  587. return false;
  588. var $this = this;
  589. this.changeLiveUpdates('PauseLiveUpdate', function() {
  590. $this._bLiveUpdatePaused = true;
  591. if(typeof onLoad == 'function')
  592. onLoad();
  593. });
  594. return true;
  595. };
  596. BxDolCmts.prototype.changeLiveUpdates = function(sAction, onLoad)
  597. {
  598. var $this = this;
  599. var oParams = this._getDefaultActions();
  600. oParams['action'] = sAction;
  601. jQuery.get(
  602. this._sActionsUrl,
  603. oParams,
  604. function() {
  605. if(typeof onLoad == 'function')
  606. onLoad();
  607. }
  608. );
  609. };
  610. BxDolCmts.prototype.cmtShowMore = function(oLink)
  611. {
  612. var oShowMore = $(oLink).parents('.' + this._sSP + '-body-show-more:first');
  613. if(!oShowMore.length)
  614. return;
  615. var sClassOverflow = 'bx-overflow';
  616. oShowMore.siblings('.' + sClassOverflow).css('max-height', 'none').removeClass(sClassOverflow);
  617. oShowMore.remove();
  618. };
  619. BxDolCmts.prototype.cmtOnFindOverflow = function(oElement) {
  620. $(oElement).after($(oElement).parents(this._sRootId + ':first').find('.' + this._sSP + '-body-show-more:hidden:first').clone().show());
  621. };
  622. /*----------------------------------*/
  623. /*--- Methods for internal usage ---*/
  624. /*----------------------------------*/
  625. BxDolCmts.prototype._getCmt = function (e, iCmtId)
  626. {
  627. var $this = this;
  628. var oData = this._getDefaultActions();
  629. oData['action'] = 'GetCmt';
  630. oData['Cmt'] = iCmtId;
  631. oData['CmtBrowse'] = this._sBrowseType;
  632. oData['CmtDisplay'] = this._sDisplayType;
  633. this._loadingInBlock (e);
  634. jQuery.post (
  635. this._sActionsUrl,
  636. oData,
  637. function (oData) {
  638. $this._loadingInBlock (e, false);
  639. var sListId = $this._sRootId + ' #cmt' + oData.vparent_id + ' > ul.cmts-all';
  640. var sReplyFormId = $this._sRootId + ' #cmt' + oData.parent_id + ' > .cmt-reply';
  641. //--- Hide reply form ---//
  642. if($(sReplyFormId).length)
  643. $(sReplyFormId).bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed);
  644. $(sListId).each(function() {
  645. //--- Some number of comments already loaded ---//
  646. if($(this).children('li.cmt').length) {
  647. var oAdded = null;
  648. if($('#cmt' + iCmtId).length) {
  649. $('#cmt' + iCmtId).replaceWith($(oData.content).hide());
  650. oAdded = $('#cmt' + iCmtId);
  651. }
  652. else {
  653. switch($this._sPostFormPosition) {
  654. case 'top':
  655. oAdded = $(this).children('li.cmt:first').before($(oData.content).hide()).prevAll('li.cmt:hidden');
  656. break;
  657. case 'bottom':
  658. oAdded = $(this).children('li.cmt:last').after($(oData.content).hide()).nextAll('li.cmt:hidden');
  659. break;
  660. }
  661. }
  662. oAdded.each(function() {
  663. $(this).bxProcessHtml().bx_anim('toggle', $this._sAnimationEffect, $this._iAnimationSpeed);
  664. });
  665. }
  666. //-- There is no comments at all ---//
  667. else
  668. $(this).hide().html(oData.content).bxProcessHtml().bx_anim('show', $this._sAnimationEffect, $this._iAnimationSpeed);
  669. $this._cmtsInitSeeMore($(this));
  670. $this._cmtsInitGallery($(this));
  671. });
  672. },
  673. 'json'
  674. );
  675. };
  676. BxDolCmts.prototype._getCmts = function (oElement, oRequestParams, onLoad)
  677. {
  678. var $this = this;
  679. var oData = this._getDefaultActions();
  680. oData['action'] = 'GetCmts';
  681. oData = $.extend({}, oData, oRequestParams);
  682. var sListId = this._sRootId + ' #cmt' + oData['CmtParent'] + ' > ul.cmts-' + (oRequestParams.CmtPinned ? 'pinned' : 'all') + ':first';
  683. if(oElement)
  684. this._loadingInBlock(oElement, true);
  685. jQuery.post (
  686. this._sActionsUrl,
  687. oData,
  688. function(s) {
  689. if(oElement)
  690. $this._loadingInBlock(oElement, false);
  691. if(typeof onLoad == 'function')
  692. onLoad(sListId, s);
  693. else
  694. $this._cmtsAppend(sListId, s);
  695. }
  696. );
  697. };
  698. BxDolCmts.prototype._getForm = function (e, oParams, onLoad)
  699. {
  700. var $this = this;
  701. var oData = $.extend({}, this._getDefaultActions(), {
  702. action: 'GetFormPost',
  703. CmtType: 'reply',
  704. CmtBrowse: this._sBrowseType,
  705. CmtDisplay: this._sDisplayType,
  706. CmtMinPostForm: this._iMinPostForm
  707. }, oParams);
  708. if(e)
  709. this._loadingInContent(e, true);
  710. jQuery.post (
  711. this._sActionsUrl,
  712. oData,
  713. function (s) {
  714. if(e)
  715. $this._loadingInContent(e, false);
  716. if(typeof onLoad == 'function')
  717. onLoad(s);
  718. }
  719. );
  720. };
  721. BxDolCmts.prototype._cmtsAppend = function(sIdTo, sContent)
  722. {
  723. $(sIdTo).append($(sContent).hide()).children(':hidden').bxProcessHtml().bx_anim('show', this._sAnimationEffect, this._iAnimationSpeed);
  724. };
  725. BxDolCmts.prototype._cmtsPrepend = function(sIdTo, sContent)
  726. {
  727. $(sIdTo).prepend($(sContent).hide()).children(':hidden').bxProcessHtml().bx_anim('show', this._sAnimationEffect, this._iAnimationSpeed);
  728. };
  729. BxDolCmts.prototype._cmtsReplace = function(oReplace, sContent, onLoad)
  730. {
  731. var $this = this;
  732. $(oReplace).bx_anim('hide', this._sAnimationEffect, this._iAnimationSpeed, function() {
  733. $(this).after($(sContent).hide()).nextAll(':hidden').bxProcessHtml().bx_anim('show', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
  734. $this._cmtsBlink($(this));
  735. $this._cmtsInitSeeMore($(this));
  736. $this._cmtsInitGallery($(this));
  737. if(typeof onLoad == 'function')
  738. onLoad();
  739. });
  740. $(this).remove();
  741. });
  742. };
  743. BxDolCmts.prototype._cmtsReplaceContent = function(oParent, sContent, onLoad)
  744. {
  745. var $this = this;
  746. $(oParent).bx_anim('hide', this._sAnimationEffect, this._iAnimationSpeed, function() {
  747. $(this).html(sContent).bxProcessHtml().bx_anim('show', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
  748. $this._cmtsBlink($(this));
  749. $this._cmtsInitSeeMore($(this));
  750. $this._cmtsInitGallery($(this));
  751. if(typeof onLoad == 'function')
  752. onLoad();
  753. });
  754. });
  755. };
  756. BxDolCmts.prototype._cmtsBlink = function(oParent)
  757. {
  758. var sBlinkClass = 'cmt-blink';
  759. oParent.find('.' + sBlinkClass + '-plate:visible').animate({
  760. opacity: 0
  761. }, 5000, function() {
  762. oParent.find('.' + sBlinkClass).removeClass(sBlinkClass);
  763. });
  764. };
  765. BxDolCmts.prototype._cmtsInitGallery = function(oParent)
  766. {
  767. // init gallery
  768. const lightbox = new PhotoSwipeLightbox({
  769. gallery: '.pswp-gallery',
  770. children: 'a',
  771. pswpModule: PhotoSwipe,
  772. });
  773. lightbox.init();
  774. }
  775. BxDolCmts.prototype._cmtsInitSeeMore = function(oParent)
  776. {
  777. var $this = this;
  778. oParent.find('.cmt-body.bx-overflow-ready').bxCheckOverflowHeight('', function(oElement) {
  779. $this.cmtOnFindOverflow(oElement);
  780. });
  781. };
  782. BxDolCmts.prototype._getCounter = function(oElement, bText)
  783. {
  784. var oCounter = null;
  785. var sSelector = '.' + this._sSP + '-counter' + (bText ? '-text' : '');
  786. if(oElement) {
  787. if($(oElement).hasClass(this._sSP))
  788. oCounter = $(oElement).find(sSelector);
  789. else
  790. oCounter = $(oElement).parents('.' + this._sSP + ':first').find(sSelector);
  791. }
  792. if((!oCounter || !oCounter.length) && this._aHtmlIds['counter'] != undefined) {
  793. oCounter = $('#' + this._aHtmlIds['counter']);
  794. if(!oCounter.is(sSelector))
  795. oCounter = oCounter.find(sSelector);
  796. }
  797. return oCounter;
  798. };
  799. BxDolCmts.prototype._getDefaultActions = function() {
  800. var oDate = new Date();
  801. var oResult = {
  802. sys: this._sSystem,
  803. id: this._iObjId,
  804. _t: oDate.getTime()
  805. };
  806. if(this._aParams)
  807. oResult['params'] = this._aParams;
  808. return oResult;
  809. };
  810. BxDolCmts.prototype._loading = function(e, bShow) {
  811. var oParent = $(e).length ? $(e) : $('body');
  812. bx_loading(oParent, bShow);
  813. };
  814. BxDolCmts.prototype._loadingInBlock = function(e, bShow) {
  815. var oParent = $(e).length ? $(e).parents('.bx-db-content:first') : $('body');
  816. bx_loading(oParent, bShow);
  817. };
  818. BxDolCmts.prototype._loadingInContent = function(e, bShow) {
  819. var oParent = $(e).length ? $(e).parents('li.cmt:first,.cmt-reply:first') : $('body');
  820. bx_loading(oParent, bShow);
  821. };
  822. BxDolCmts.prototype._loadingInButton = function(e, bShow) {
  823. if($(e).length)
  824. bx_loading_btn($(e), bShow);
  825. else
  826. bx_loading($('body'), bShow);
  827. };
  828. /** @} */