// source --> https://zulustig.de/wp-content/plugins/comment-ace/assets/js/core.js?ver=1.0.2 
'use strict';

/* global commentace */
/* global console */

(function () {

    'use strict';

    /**
     * Check whether the user is logged in
     */

    commentace.isUserLoggedIn = function () {
        return commentace.user_logged_in;
    };

    /**
     * Extract ID from comment HTML tag
     */
    commentace.extractCommentId = function (comment) {
        return parseInt(comment.getAttribute('id').replace(/^[^\d]+/, ''), 10);
    };

    /**
     * Extract ID from comment HTML tag
     */
    commentace.extractCommentDepth = function (comment) {
        if (!comment) {
            return 0;
        }

        return comment.getAttribute('class').match(/depth-\d+/)[0].replace(/[^\d]+/, '');
    };

    commentace.decodeHTMLEntities = function (text) {
        var elem = document.createElement('textarea');
        elem.innerHTML = text;

        return elem.value;
    };

    /**
     * Format number according to WordPress locale
     */
    commentace.numberFormatI18N = function (number) {
        var decimals = commentace.number_format.decimals;
        var decPoint = commentace.number_format.dec_point;
        var thousandsSep = commentace.number_format.thousands_sep;

        number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
        var n = !isFinite(+number) ? 0 : +number;
        var prec = !isFinite(+decimals) ? 0 : Math.abs(decimals);
        var sep = typeof thousandsSep === 'undefined' ? ',' : thousandsSep;
        var dec = typeof decPoint === 'undefined' ? '.' : decPoint;
        var s = '';

        var toFixedFix = function toFixedFix(n, prec) {
            if (('' + n).indexOf('e') === -1) {
                return +(Math.round(n + 'e+' + prec) + 'e-' + prec);
            } else {
                var arr = ('' + n).split('e');
                var sig = '';
                if (+arr[1] + prec > 0) {
                    sig = '+';
                }

                return (+(Math.round(+arr[0] + 'e' + sig + (+arr[1] + prec)) + 'e-' + prec)).toFixed(prec);
            }
        };

        s = (prec ? toFixedFix(n, prec).toString() : '' + Math.round(n)).split('.');
        if (s[0].length > 3) {
            s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
        }
        if ((s[1] || '').length < prec) {
            s[1] = s[1] || '';
            s[1] += new Array(prec - s[1].length + 1).join('0');
        }

        return s.join(dec);
    };

    /**
     * Log
     */
    commentace.log = function () {
        if (!commentace.in_debug_mode) {
            return;
        }

        if (typeof console !== 'undefined') {
            console.group('CommentAce');

            for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
                args[_key] = arguments[_key];
            }

            args.forEach(function (msg) {
                return console.log(msg);
            });
            console.groupEnd('CommentAce');
        }
    };

    /**
     * Error log
     */
    commentace.error = function () {
        if (!commentace.in_debug_mode) {
            return;
        }

        if (typeof console !== 'undefined') {
            console.group('CommentAce');

            for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
                args[_key2] = arguments[_key2];
            }

            args.forEach(function (msg) {
                return console.error(msg);
            });
            console.groupEnd('CommentAce');
        }
    };

    /**
     * Extend Element class with parent() method
     */
    if (!('parent' in Element.prototype)) {
        Element.prototype.parent = function (selector) {
            var elem = this;
            var haveSelector = selector !== undefined;

            while ((elem = elem.parentElement) !== null) {
                if (elem.nodeType !== Node.ELEMENT_NODE) {
                    continue;
                }

                if (!haveSelector || elem.matches(selector)) {
                    return elem;
                }
            }

            return null;
        };
    }

    /**
     * Extend Element class with next() method
     */
    if (!('next' in Element.prototype)) {
        Element.prototype.next = function (selector) {
            var elem = this;
            var haveSelector = selector !== undefined;

            while ((elem = elem.nextSibling) !== null) {
                if (elem.nodeType !== Node.ELEMENT_NODE) {
                    continue;
                }

                if (!haveSelector || elem.matches(selector)) {
                    return elem;
                }
            }

            return null;
        };
    }

    /**
     * Extend Element class with isInViewport() method
     */
    if (!('isInViewport' in Element.prototype)) {
        Element.prototype.isInViewport = function () {
            var bottomOffset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;

            var elem = this;
            var distance = elem.getBoundingClientRect();
            return distance.top >= 0 && distance.left >= 0 && distance.bottom - bottomOffset <= (window.innerHeight || document.documentElement.clientHeight) && distance.right <= (window.innerWidth || document.documentElement.clientWidth);
        };
    }

    /**
     * Extend document with createElementFromString() method
     */
    if (!('createElementFromString' in document)) {
        document.createElementFromString = function (string) {
            var parser = new DOMParser();
            var doc = parser.parseFromString(string, 'text/html');

            return doc.body.childNodes[0];
        };
    }

    commentace.debounce = function (func) {
        var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 20;
        var immediate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;

        var timeout;
        return function () {
            var context = this,
                args = arguments;
            var later = function later() {
                timeout = null;
                if (!immediate) func.apply(context, args);
            };
            var callNow = immediate && !timeout;
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
            if (callNow) func.apply(context, args);
        };
    };

    // Shortcut.
    window.ca = commentace;
})();
// source --> https://zulustig.de/wp-content/plugins/comment-ace/assets/js/comments.js?ver=1.0.2 
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

/* global ca */

(function () {
    /**
     * Comments controller class
     */
    var Comments = function () {
        function Comments(comments) {
            _classCallCheck(this, Comments);

            this.comments = comments;

            this.init();
            this.bindEvents();
        }

        _createClass(Comments, [{
            key: 'init',
            value: function init() {
                ca.log('[Init comments]', this.comments);

                this.tabs = this.comments.querySelectorAll('.cace-tab-item');
                this.types = this.comments.querySelectorAll('.cace-comment-type');
                this.activeTypes = {};

                var currentType = this.comments.querySelector('.cace-comment-type-current').dataset.commentType;

                this.activateType(currentType);
            }
        }, {
            key: 'bindEvents',
            value: function bindEvents() {
                var _this = this;

                // Handle tabs.
                this.tabs.forEach(function (tab) {
                    return tab.addEventListener('click', function (e) {
                        e.preventDefault();
                        _this.selectTab(e.currentTarget);
                    });
                });
            }
        }, {
            key: 'getActiveType',
            value: function getActiveType(type) {
                if (type in this.activeTypes) {
                    return this.activeTypes[type];
                }

                return null;
            }
        }, {
            key: 'activateType',
            value: function activateType(type) {
                if (type in this.activeTypes) {
                    return;
                }

                var typeComments = this.comments.querySelector('.cace-comment-type-' + type);

                if (typeComments) {
                    var typeClass = type.charAt(0).toUpperCase() + type.slice(1) + 'Comments';
                    var configVar = 'commentace_' + type;

                    if (ca[typeClass] && window[configVar]) {
                        this.activeTypes[type] = new ca[typeClass](typeComments, window[configVar]);
                    }
                }
            }
        }, {
            key: 'selectTab',
            value: function selectTab(tab) {
                var type = tab.dataset.commentType;

                // Remove current selection.
                this.comments.querySelector('.cace-tab-item-current').classList.remove('cace-tab-item-current', 'g1-tab-item-current');
                this.comments.querySelector('.cace-comment-type-current').classList.remove('cace-comment-type-current');

                // Select target tab and its content.
                tab.classList.add('cace-tab-item-current', 'g1-tab-item-current');
                this.comments.querySelector('.cace-comment-type-' + type).classList.add('cace-comment-type-current');

                // Activate.
                this.activateType(type);
            }
        }]);

        return Comments;
    }();

    ca.Comments = Comments;
})();

// Init.
document.addEventListener('DOMContentLoaded', function () {
    document.querySelectorAll('.cace-comments').forEach(function (comments) {
        new ca.Comments(comments);
    });
});