<commit_before>/**
 * Toggle comment box in Evaluation tool
 * @author <EMAIL>
 */

(function($) {
    $.fn.evalComment = function() {
        init($(this));
    };
    //Private variable and  functions
    var truncateLength = 70;   //Customise this if need be
    function init(that) {
        that.each(function() {
            //populate init Fn-scope DOM variables
            var commentHolder = $(this), isSelectionMade = false,
                    dom = {
                        commentHolder: commentHolder,
                        showLink: commentHolder.find("a.JSshow"),
                        editLink: commentHolder.find("a.JSedit"),
                        hideLink: commentHolder.find("a.JShide"),
                        textarea: commentHolder.find("textarea"),
                        commentTruncated: commentHolder.find("span.JScommentTruncated"),
                        commentLabel: commentHolder.find("span.JSlabel"),
                        //if li:eq(0) doesn't return an object, we are in an item preview
                        questionHolder: commentHolder.parents("li:eq(0)").length === 0 ? commentHolder.parents("div.highlightPanel:eq(0)") : commentHolder.parents("li:eq(0)"),
                        warn: commentHolder.find("span.JSwarn")
                    };
            //Set listeners for any question item response activity and toggle comment controls - EVALSYS-628

            dom.questionHolder.find("input").each(function() {
                if (this.checked) {
                    isSelectionMade = true;
                }
                $(this).bind("click", function() {
                    //Only items with checkboxes or radio buttions are supported.
                    if (dom.questionHolder.find("input:checked").length == 1) {
                        //Activate comment controls
                        enable(dom);
                    } else if (dom.questionHolder.find("input:checked").length == 0) {
                        //De-activate comment controls
                        disable(dom);
                    }
                });
            });

            //Question has an answer (possibly a comment too), so activate comment controls
            if (isSelectionMade && dom.textarea.val().length > 0) {
                enable(dom);
                dom.hideLink.trigger('click');
            } else if (isSelectionMade) {
                enable(dom);
            } else {
                disable(dom);
            }
        });
    }

    //Deal with existing comments
    function hideComment(dom) {
        var truncatedComment = truncate(dom.textarea.val());//Truncate the comment and update Dom
        dom.showLink.hide();
        dom.commentLabel.fadeIn("fast");
        dom.editLink.fadeIn("fast");
        dom.commentTruncated.text(truncatedComment).fadeIn("fast"); //add truncated comment to DOM
    }

    function truncate(str) {
        if (str.length > truncateLength) {
            return ( ( str.substring(0, truncateLength).replace(/\w+$/, '') ) + " ..."  );
        }
        return str;
    }

    function resizeFrame(updown) {
        try {
            var clientH, frame = parent.document.getElementById(window.name);
            if (frame) {
                if (updown === 'shrink') {
                    clientH = document.body.clientHeight - 70;
                } else {
                    clientH = document.body.clientHeight + 70;
                }
                $(frame).height(clientH);
            }
        } catch(e) {
        }
    }

    function disable(dom) {
        if (dom.hideLink.css("display") !== "none") {
            dom.hideLink.trigger('click');
        }
        dom.commentHolder.find("a, span:not(.JSwarn)")
                .css({color:"#000", opacity:0.5})
                .unbind("click")
                .bind("click", function() {
            return false;
        });
        if (dom.textarea.val().length > 0) {
            //Warn user
            dom.warn.fadeIn("fast");
        }
    }

    function enable(dom) {
        dom.commentHolder.find("a, span:not(.JSwarn)")
                .css({color:null, opacity:1})
                .unbind("click");
        //Hide warning
        dom.warn.fadeOut("fast");
        //Bind the click event for ADD comment control
        dom.showLink.bind('click', function() {
            dom.textarea.slideDown("fast");
            dom.showLink.slideUp("fast");
            dom.hideLink.slideDown("fast");
            dom.warn.fadeOut("fast");
            resizeFrame('grow');
            dom.textarea.focus();
            return false;
        });
        //Bind the click event for EDIT comment control
        dom.editLink.bind('click', function() {
            dom.textarea.slideDown("fast");
            dom.commentLabel.slideUp("fast");
            dom.commentTruncated.slideUp("fast");
            dom.editLink.slideUp("fast");
            dom.hideLink.slideDown("fast");
            dom.warn.fadeOut("fast");
            resizeFrame('grow');
            dom.textarea.focus();
            return false;
        });
        //Bind the click event for HIDE comment control
        dom.hideLink.bind('click', function() {
            if (dom.textarea.val().length > 0) {
                hideComment(dom);
            } else {
                dom.showLink.slideDown("fast");
            }
            dom.textarea.slideUp("fast");
            dom.hideLink.slideUp("fast");
            resizeFrame('shrink');
            return false;
        });

    }
})($);<commit_msg>EVALSYS-628 For some reason JSLint like this order of declaring functions, so these changes honour that requirement. Functionally nothing has changed.<commit_after>/**
 * Toggle comment box in Evaluation tool
 * @author <EMAIL>
 */

(function($) {
    //Private variable and  functions

    function truncate(dom, str) {
        if (str.length > dom.truncateLength) {
            return ( ( str.substring(0, dom.truncateLength).replace(/\w+$/, '') ) + " ..."  );
        }
        return str;
    }

    //Deal with existing comments
    function hideComment(dom) {
        var truncatedComment = truncate(dom, dom.textarea.val());//Truncate the comment and update Dom
        dom.showLink.hide();
        dom.commentLabel.fadeIn("fast");
        dom.editLink.fadeIn("fast");
        dom.commentTruncated.text(truncatedComment).fadeIn("fast"); //add truncated comment to DOM
    }


    function resizeFrame(updown) {
        try {
            var clientH, frame = parent.document.getElementById(window.name);
            if (frame) {
                if (updown === 'shrink') {
                    clientH = document.body.clientHeight - 70;
                } else {
                    clientH = document.body.clientHeight + 70;
                }
                $(frame).height(clientH);
            }
        } catch(e) {
        }
    }

    function disable(dom) {
        if (dom.hideLink.css("display") !== "none") {
            dom.hideLink.trigger('click');
        }
        dom.commentHolder.find("a, span:not(.JSwarn)")
                .css({color:"#000", opacity:0.5})
                .unbind("click")
                .bind("click", function() {
            return false;
        });
        if (dom.textarea.val().length > 0) {
            //Warn user
            dom.warn.fadeIn("fast");
        }
    }

    function enable(dom) {
        dom.commentHolder.find("a, span:not(.JSwarn)")
                .css({color:null, opacity:1})
                .unbind("click");
        //Hide warning
        dom.warn.fadeOut("fast");
        //Bind the click event for ADD comment control
        dom.showLink.bind('click', function() {
            dom.textarea.slideDown("fast");
            dom.showLink.slideUp("fast");
            dom.hideLink.slideDown("fast");
            dom.warn.fadeOut("fast");
            resizeFrame('grow');
            dom.textarea.focus();
            return false;
        });
        //Bind the click event for EDIT comment control
        dom.editLink.bind('click', function() {
            dom.textarea.slideDown("fast");
            dom.commentLabel.slideUp("fast");
            dom.commentTruncated.slideUp("fast");
            dom.editLink.slideUp("fast");
            dom.hideLink.slideDown("fast");
            dom.warn.fadeOut("fast");
            resizeFrame('grow');
            dom.textarea.focus();
            return false;
        });
        //Bind the click event for HIDE comment control
        dom.hideLink.bind('click', function() {
            if (dom.textarea.val().length > 0) {
                hideComment(dom);
            } else {
                dom.showLink.slideDown("fast");
            }
            dom.textarea.slideUp("fast");
            dom.hideLink.slideUp("fast");
            resizeFrame('shrink');
            return false;
        });

    }

    function init(that) {
        that.each(function() {
            //populate init Fn-scope DOM variables
            var commentHolder = $(this), isSelectionMade = false,
                    dom = {
                        truncateLength: 70,   //Customise this if need be
                        commentHolder: commentHolder,
                        showLink: commentHolder.find("a.JSshow"),
                        editLink: commentHolder.find("a.JSedit"),
                        hideLink: commentHolder.find("a.JShide"),
                        textarea: commentHolder.find("textarea"),
                        commentTruncated: commentHolder.find("span.JScommentTruncated"),
                        commentLabel: commentHolder.find("span.JSlabel"),
                        //if li:eq(0) doesn't return an object, we are in an item preview
                        questionHolder: commentHolder.parents("li:eq(0)").length === 0 ? commentHolder.parents("div.highlightPanel:eq(0)") : commentHolder.parents("li:eq(0)"),
                        warn: commentHolder.find("span.JSwarn")
                    };
            //Set listeners for any question item response activity and toggle comment controls - EVALSYS-628

            dom.questionHolder.find("input").each(function() {
                if (this.checked) {
                    isSelectionMade = true;
                }
                $(this).bind("click", function() {
                    //Only items with checkboxes or radio buttions are supported.
                    if (dom.questionHolder.find("input:checked").length === 1) {
                        //Activate comment controls
                        enable(dom);
                    } else if (dom.questionHolder.find("input:checked").length === 0) {
                        //De-activate comment controls
                        disable(dom);
                    }
                });
            });

            //Question has an answer (possibly a comment too), so activate comment controls
            if ( isSelectionMade && dom.textarea.val().length > 0 ) {
                enable(dom);
                dom.hideLink.trigger('click');
            } else if (isSelectionMade) {
                enable(dom);
            } else {
                disable(dom);
            }
        });
    }
    $.fn.evalComment = function() {
            init($(this));
        };

})(jQuery);
{'fraction_non_alphanumeric': 0.12868561278863233, 'fraction_numerical': 0.004884547069271759, 'mean_word_length': 1.5209312737855385, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3217836', 'n_tokens_mistral': 3019, 'n_tokens_neox': 2801, 'n_words': 590}