/** @param {jQuery} $ jQuery Object */ !function($, window, document, _undefined) { XenForo.BriviumCommentLoader = function($element) { this.__construct($element); }; XenForo.BriviumCommentLoader.prototype = { __construct: function($link) { this.$link = $link; $link.click($.context(this, 'click')); }, click: function(e) { var params = this.$link.data('loadparams'); if (typeof params != 'object') { params = {}; } e.preventDefault(); XenForo.ajax( this.$link.attr('href'), params, $.context(this, 'loadSuccess'), { type: 'GET' } ); }, loadSuccess: function(ajaxData) { var $replace, replaceSelector = this.$link.data('replace'), els = [], $els, i; if (XenForo.hasResponseError(ajaxData)) { return false; } if (replaceSelector) { $replace = $(replaceSelector); } else { $replace = this.$link.parent(); } $commentList = this.$link.closest('ol.BriviumCommentList'); if (ajaxData.comments && ajaxData.comments.length) { for (i = 0; i < ajaxData.comments.length; i++) { $id = $(ajaxData.comments[i]).attr('id'); if(!$commentList.find('#'+$id).length) { $.merge(els, $(ajaxData.comments[i])); } } // xfInsert didn't like this $els = $(els).hide(); $replace.xfFadeUp().replaceWith($els); $els.xfActivate().xfFadeDown(); for (i = 0; i < ajaxData.comments.length; i++) { $(ajaxData.comments[i]).xfInsert('insertBefore', $replace); } $replace.xfHide(); } else { $replace.xfRemove(); } } }; XenForo.BriviumCommentPoster = function($element) { this.__construct($element); }; XenForo.BriviumCommentPoster.prototype = { __construct: function($link) { this.$link = $link; this.$commentArea = $($link.data('commentarea')); if (this.$commentArea.data('submiturl')) { this.submitUrl = this.$commentArea.data('submiturl'); } else { this.submitUrl = $link.attr('href'); } $link.click($.context(this, 'click')); this.$commentArea.find('input:submit, button').click($.context(this, 'submit')); }, click: function(e) { console.log(this) e.preventDefault(); this.$commentArea.xfFadeDown(XenForo.speed.fast, function() { $tmpEditor = $(this).find('iframe').contents().find('body'); if($tmpEditor.length) { $tmpEditor.focus(); }else { $(this).find('textarea').focus(); } }); }, submit: function(e) { e.preventDefault(); var $message_html = ''; var $blockComment = this.$commentArea; if($blockComment.find('iframe').length) { if($blockComment.find('.redactor_box:visible').length) { $message_html = $blockComment.find('iframe').contents().find('body').html(); }else { $message_html = $blockComment.find('.bbCodeEditorContainer textarea[name="message"]').val(); } }else { $message_html = $blockComment.find('textarea').val(); } XenForo.ajax( this.submitUrl, { message_html: $message_html, attachment_hash: $blockComment.find('input[name="attachment_hash"]').val() }, $.context(this, 'submitSuccess') ); }, submitSuccess: function(ajaxData) { if (XenForo.hasResponseError(ajaxData)) { return false; } if (ajaxData.comment) { $(ajaxData.comment).xfInsert('insertBefore', this.$commentArea); } var $blockComment = this.$commentArea; $blockComment.find('.BriviumAttachmentList li:not(#BriviumAttachedFileTemplate)').xfRemove(null); $blockComment.find('.BriviumAttachmentInsertAllBlock').hide(); if($blockComment.find('iframe').length) { if($blockComment.find('.redactor_box:visible').length) { $blockComment.find('iframe').contents().find('body').text(''); }else { $blockComment.find('.bbCodeEditorContainer textarea[name="message"]').val(''); } }else { $blockComment.find('textarea').val(''); } } }; XenForo.register('a.BriviumCommentLoader', 'XenForo.BriviumCommentLoader'); XenForo.register('a.BriviumCommentPoster', 'XenForo.BriviumCommentPoster'); } (jQuery, this, document);