1 (edited by 2009-07-15 12:27:10)

Topic: [HACK] Quoting Comments

Name: Quoting comments.
Author: Ifa, (lkj), FUNimations, Spritanium
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: This was made in a group effort. This hack adds a "quote" button to each comment. When clicked upon, the text from the comment is added to the new comment textarea in quote tags with the HTML stripped. The HTML is stripped because otherwise, the HTML would show up as text and clutter up the comment. This won't work for comments in a popup.
Instructions:
Add this to the HEAD section of whatever page you show Cutenews on:

<script type="text/javascript">
function quote(element_id, textarea_id)
    {
        var textarea = null;
        var comment = null;
        
        if (document.getElementById)
            {
                textarea = document.getElementById(textarea_id);
                comment = document.getElementById(element_id).innerHTML;
            }
        else if (document.all)
            {
                textarea = document.all[textarea_id];
                comment = document.all[element_id].innerHTML;
            }
        else if (document.layers)
            {
                textarea = document.layers[textarea_id];
                comment = document.layers[element_id].innerHTML;
            }
        
        if (textarea)
            {
                textarea.focus();
                var text = textarea.value + " " + "[quote]" + comment + "[/quote]";
                textarea.value = text.stripHTML();
                textarea.focus();
            }
    }
String.prototype.stripHTML = function()
{
        // What a tag looks like
        var matchTag = /<(?:.|\s)*?>/g;
        // Replace the tag
        return this.replace(matchTag, " ");
};
</script>

Now, go to your comments template and put div tags around {comment} with an id of "a{comment-id}", like so:

<div id="a{comment-id}">
{comment}
</div>

(The "a" before {comment-id} is there because in (X)HTML, a number can't begin an id attribute.)

Next, add this to your comments template:

<input type="button" value="Quote" onclick="java script:quote('a{comment-id}', 'commentsbox')" />


(Make sure your comment box's id is "commentsbox". It is by default, but some people might change it for whatever reason. Also make sure that you change "java script" to "javascript" (one word). This forum censors it.)

You're done!  https://cutephp.com/forum/style_emoticons/default/laugh.gif