Clean up Javascript code. Obey the 80 character limit.
svn path=/plone.app.discussion/trunk/; revision=36991
This commit is contained in:
		
							parent
							
								
									7b2aa33a45
								
							
						
					
					
						commit
						28d88dcfb4
					
				@ -4,6 +4,9 @@ Changelog
 | 
			
		||||
1.0b5 (unreleased)
 | 
			
		||||
------------------
 | 
			
		||||
 | 
			
		||||
* Clean up Javascript code.
 | 
			
		||||
  [timo]
 | 
			
		||||
 | 
			
		||||
* Fix encoding error in migration procedure, otherwise migration procedure 
 | 
			
		||||
  breaks on joining output list in case we have there any non-ascii characters.
 | 
			
		||||
  [piv]
 | 
			
		||||
 | 
			
		||||
@ -1,20 +1,31 @@
 | 
			
		||||
jq(document).ready(function() {
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Hide the reply and the cancel button for the regular add
 | 
			
		||||
 | 
			
		||||
    /**************************************************************************
 | 
			
		||||
     * By default, hide the reply and the cancel button for the regular add
 | 
			
		||||
     * comment form.
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    jq(".reply").find("input[name='form.buttons.reply']").css("display", "none");
 | 
			
		||||
    jq(".reply").find("input[name='form.buttons.cancel']").css("display", "none");
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    jq(".reply").find("input[name='form.buttons.reply']")
 | 
			
		||||
		        .css("display", "none");
 | 
			
		||||
    jq(".reply").find("input[name='form.buttons.cancel']")
 | 
			
		||||
	            .css("display", "none");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * If a reply-to-comment form was submitted (in_reply_to field was
 | 
			
		||||
     * set in the request), create a reply-to-comment form right under
 | 
			
		||||
     * the comment.
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    /**************************************************************************
 | 
			
		||||
     * By default, show the reply button only when Javascript is enabled.
 | 
			
		||||
     * Otherwise hide it, since the reply functions only work with JS enabled.
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    jq(".reply-to-comment-button").css("display" , "inline");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**************************************************************************
 | 
			
		||||
     * If the user has hit the reply button of a reply-to-comment form (form was 
 | 
			
		||||
     * submitted with a value for the "in_reply_to" field in the request), 
 | 
			
		||||
     * create a reply-to-comment form right under this comment.
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    var post_comment_div = jq("#commenting");
 | 
			
		||||
    var in_reply_to_field = post_comment_div.find("input[name='form.widgets.in_reply_to']");
 | 
			
		||||
    var in_reply_to_field = 
 | 
			
		||||
	    post_comment_div.find("input[name='form.widgets.in_reply_to']");
 | 
			
		||||
    if (in_reply_to_field.val() != "") {
 | 
			
		||||
        var current_reply_id = "#" + in_reply_to_field.val();
 | 
			
		||||
        var current_reply_to_div = jq(".discussion").find(current_reply_id);
 | 
			
		||||
@ -22,20 +33,12 @@ jq(document).ready(function() {
 | 
			
		||||
        clearForm(post_comment_div);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Remove the z3c.form error messages and all input values from a
 | 
			
		||||
     * form.
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    function clearForm(form_div) {
 | 
			
		||||
        form_div.find(".error").removeClass("error");
 | 
			
		||||
        form_div.find(".fieldErrorBox").remove();
 | 
			
		||||
        form_div.find("input[type='text']").attr("value", "")
 | 
			
		||||
        form_div.find("textarea").attr("value", "")
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Create a reply-to-comment form right under the comment_div.
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    /**************************************************************************
 | 
			
		||||
     * Create a reply-to-comment form right beneath the form that is passed to
 | 
			
		||||
     * the function. We do this by copying the regular comment form and 
 | 
			
		||||
     * adding a hidden in_reply_to field to the form.
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    function createReplyForm(comment_div){
 | 
			
		||||
 | 
			
		||||
        var comment_id = comment_div.attr("id");
 | 
			
		||||
@ -50,7 +53,9 @@ jq(document).ready(function() {
 | 
			
		||||
        /* Remove the ReCaptcha JS code before appending the form. If not
 | 
			
		||||
         * removed, this causes problems
 | 
			
		||||
         */
 | 
			
		||||
        reply_div.find("#formfield-form-widgets-captcha").find("script").remove();
 | 
			
		||||
        reply_div.find("#formfield-form-widgets-captcha")
 | 
			
		||||
		         .find("script")
 | 
			
		||||
				 .remove();
 | 
			
		||||
 | 
			
		||||
        /* Insert the cloned comment form right after the reply button of the
 | 
			
		||||
         * current comment.
 | 
			
		||||
@ -70,14 +75,16 @@ jq(document).ready(function() {
 | 
			
		||||
        var reply_form = reply_div.find("form");
 | 
			
		||||
 | 
			
		||||
        /* Populate the hidden 'in_reply_to' field with the correct comment id */
 | 
			
		||||
        reply_form.find("input[name='form.widgets.in_reply_to']").val(comment_id);
 | 
			
		||||
        reply_form.find("input[name='form.widgets.in_reply_to']")
 | 
			
		||||
		          .val(comment_id);
 | 
			
		||||
 | 
			
		||||
        /* Add a remove-reply-to-comment Javascript function to remove the form */
 | 
			
		||||
        var cancel_reply_button = reply_div.find(".cancelreplytocomment");
 | 
			
		||||
        cancel_reply_button.attr("id", comment_id);
 | 
			
		||||
 | 
			
		||||
        /* Show the cancel buttons. */
 | 
			
		||||
        reply_form.find("input[name='form.buttons.cancel']").css("display", "inline");
 | 
			
		||||
        reply_form.find("input[name='form.buttons.cancel']")
 | 
			
		||||
		          .css("display", "inline");
 | 
			
		||||
 | 
			
		||||
        /* Show the reply layer with a slide down effect */
 | 
			
		||||
        reply_div.slideDown("slow");
 | 
			
		||||
@ -86,28 +93,41 @@ jq(document).ready(function() {
 | 
			
		||||
        cancel_reply_button.css("display", "inline");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Show the reply button only when Javascript is enabled.
 | 
			
		||||
     * Otherwise hide it, since the reply functions rely on jQuery.
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    jq(".reply-to-comment-button").css("display" , "inline");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Create reply to comment form.
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    
 | 
			
		||||
	/**************************************************************************
 | 
			
		||||
     * Remove all error messages and field values from the form that is passed
 | 
			
		||||
     * to the function.
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    function clearForm(form_div) {
 | 
			
		||||
        form_div.find(".error").removeClass("error");
 | 
			
		||||
        form_div.find(".fieldErrorBox").remove();
 | 
			
		||||
        form_div.find("input[type='text']").attr("value", "");
 | 
			
		||||
        form_div.find("textarea").attr("value", "");
 | 
			
		||||
        /* XXX: Clean all additional form extender fields. */
 | 
			
		||||
    }
 | 
			
		||||
	
 | 
			
		||||
    
 | 
			
		||||
	/**************************************************************************
 | 
			
		||||
     * If the user hits the "reply" button of an existing comment, create a 
 | 
			
		||||
     * reply form right beneath this comment.
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    jq(".reply-to-comment-button").bind("click", function(e){
 | 
			
		||||
        var comment_div = jq(this).parents().filter(".comment");
 | 
			
		||||
        createReplyForm(comment_div);
 | 
			
		||||
        clearForm(comment_div);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Remove reply to comment form.
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
 | 
			
		||||
    /**************************************************************************
 | 
			
		||||
     * If the user hits the "clear" button of an open reply-to-comment form,
 | 
			
		||||
     * remove the form and show the "reply" button again.
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    jq("#form-buttons-cancel").bind("click", function(e){
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        reply_to_comment_button = jq(this).parents().filter(".comment").find(".reply-to-comment-button");
 | 
			
		||||
        reply_to_comment_button = jq(this).
 | 
			
		||||
		                              parents().
 | 
			
		||||
								      filter(".comment").
 | 
			
		||||
									  find(".reply-to-comment-button");
 | 
			
		||||
 | 
			
		||||
        /* Find the reply-to-comment form and hide and remove it again. */
 | 
			
		||||
        reply_to_comment_form = jq(this).parents().filter(".reply")
 | 
			
		||||
@ -118,56 +138,5 @@ jq(document).ready(function() {
 | 
			
		||||
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Remove comment.
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    /*
 | 
			
		||||
    jq("input[name='form.button.DeleteComment']").click(function(e){
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        var form = jq(this).parent();
 | 
			
		||||
        var target = jq(form).attr("action");
 | 
			
		||||
        var comment = jq(form).parent();
 | 
			
		||||
        var reply_comments = jq(comment).find("~ .comment:not(.replyTreeLevel0 ~ div)");
 | 
			
		||||
        reply_comments.css("background", "red");
 | 
			
		||||
        jq.ajax({
 | 
			
		||||
            type: "GET",
 | 
			
		||||
            url: target,
 | 
			
		||||
            success: function(msg){
 | 
			
		||||
                // fade out row
 | 
			
		||||
                jq(comment).fadeOut("normal", function(){
 | 
			
		||||
                    jq(this).remove();
 | 
			
		||||
                });
 | 
			
		||||
            },
 | 
			
		||||
            error: function(msg){
 | 
			
		||||
                alert("Error sending AJAX request:" + target);
 | 
			
		||||
            },
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
    */
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Publish comment.
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    /*
 | 
			
		||||
    jq("input[name='form.button.PublishComment']").click(function(e){
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        var button = jq(this);
 | 
			
		||||
        var form = jq(this).parent();
 | 
			
		||||
        var target = jq(form).attr("action");
 | 
			
		||||
        var comment = jq(form).parent()
 | 
			
		||||
        jq.ajax({
 | 
			
		||||
            type: "GET",
 | 
			
		||||
            url: target,
 | 
			
		||||
            success: function(msg){
 | 
			
		||||
                // fade out row
 | 
			
		||||
                jq(button).fadeOut("normal", function(){
 | 
			
		||||
                    jq(form).remove();
 | 
			
		||||
                });
 | 
			
		||||
            },
 | 
			
		||||
            error: function(msg){
 | 
			
		||||
                alert("Error sending AJAX request:" + target);
 | 
			
		||||
            },
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
    */
 | 
			
		||||
 });
 | 
			
		||||
 });
 | 
			
		||||
 
 | 
			
		||||
@ -1,27 +1,9 @@
 | 
			
		||||
jq(document).ready(function() {
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Check or uncheck all checkboxes
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    jq("input[name='check_all']").click(function(){
 | 
			
		||||
          if(jq(this).val()==0){
 | 
			
		||||
            jq(this).parents("table")
 | 
			
		||||
                   .find("input:checkbox")
 | 
			
		||||
                   .attr("checked","checked");
 | 
			
		||||
            jq(this).val("1");
 | 
			
		||||
          }
 | 
			
		||||
          else{
 | 
			
		||||
            jq(this).parents("table")
 | 
			
		||||
                   .find("input:checkbox")
 | 
			
		||||
                   .attr("checked","");
 | 
			
		||||
            jq(this).val("0");
 | 
			
		||||
          }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Delete comment
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    /**************************************************************************
 | 
			
		||||
     * Delete a single comment.
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    jq("input[name='form.button.Delete']").click(function(e) {
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        var button = jq(this);
 | 
			
		||||
@ -45,9 +27,10 @@ jq(document).ready(function() {
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Publish comment
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
 | 
			
		||||
    /**************************************************************************
 | 
			
		||||
     * Publish a single comment.
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    jq("input[name='form.button.Publish']").click(function(e) {
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        var button = jq(this);
 | 
			
		||||
@ -72,9 +55,9 @@ jq(document).ready(function() {
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Bulk actions (delete, publish)
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    /**************************************************************************
 | 
			
		||||
     * Bulk actions for comments (delete, publish)
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    jq("input[name='form.button.BulkAction']").click(function(e) {
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        var form = jq(this).parents("form")
 | 
			
		||||
@ -102,10 +85,30 @@ jq(document).ready(function() {
 | 
			
		||||
            selectField.find("option[value='-1']").attr( 'selected', 'selected' );
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Show full text of a comment.
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    /**************************************************************************
 | 
			
		||||
     * Check or uncheck all checkboxes from the batch moderation page.
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    jq("input[name='check_all']").click(function(){
 | 
			
		||||
          if(jq(this).val()==0){
 | 
			
		||||
            jq(this).parents("table")
 | 
			
		||||
                   .find("input:checkbox")
 | 
			
		||||
                   .attr("checked","checked");
 | 
			
		||||
            jq(this).val("1");
 | 
			
		||||
          }
 | 
			
		||||
          else{
 | 
			
		||||
            jq(this).parents("table")
 | 
			
		||||
                   .find("input:checkbox")
 | 
			
		||||
                   .attr("checked","");
 | 
			
		||||
            jq(this).val("0");
 | 
			
		||||
          }
 | 
			
		||||
    });
 | 
			
		||||
		
 | 
			
		||||
 | 
			
		||||
    /**************************************************************************
 | 
			
		||||
     * Show full text of a comment in the batch moderation page.
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    jq(".show-full-comment-text").click(function(e) {    
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        var target = jq(this).attr("href");
 | 
			
		||||
@ -124,4 +127,4 @@ jq(document).ready(function() {
 | 
			
		||||
        });        
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
});
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user