0

I'm using Ryan Bates gem to create notification of my app for comments, the comments are polymorphic to the Posts that are created,

BEFORE going into the details, here is the Javascript that picks the first argument no matter what the values are, I have no idea why!

$('#notify').bind('DOMNodeInserted DOMNodeRemoved', function(event) {
    if (event.type == 'DOMNodeInserted') {

        if ( $('#PostOwnerID').val() == $('#CuID').val() ) {
            $("#Notification").removeClass("btn btn-primary");
            $("#Notification").addClass("btn btn-success");
            alert('Eq')             
        }                               

        else {
            alert('Not Equal')  
        }
    } 
    else {  
    }
    });

And Here is the rest of what I'm doing, starting from Add Comment View create.js.erb >

<% publish_to "/layouts/comments" do %>
$("#<%= @commentable.id %>").empty();
$("#<%= @commentable.id  %>").append("<%= escape_javascript(render(:partial => 'comments')) %>");
$("textarea#user_comment_content").val(null);
<% end %>

And for controller to keep the post short I publish back these fields >

PrivatePub.publish_to("/layouts/comments", "$('#notify').append('#{@comment.content}'); $('#CuID').append('#{current_user.id}'); $('#PostOwnerID').append('#{@commentable.user_id}');")

and where in the notification view I have these lines:

 <div id="demo" class="collapse in"> 
<div id="PostOwnerID"></div>
<div id="CuID"></div>
<div id="notify"></div> 
 <%= subscribe_to "/layouts/comments" %>
 </div>

the if else suppose to check if the Post Owner Is the current user or not, if it was the current user, then he/she gets the notification. BUT it's driving me crazy, because it keeps choosing first Argument!

0bserver07
  • 3,390
  • 1
  • 28
  • 56
  • 1
    I dont understand your question – beck03076 Jan 09 '14 at 07:19
  • @beck03076 I'm trying to use the JS script to update a div content, depending on what the div content is. However, the if statement is not picking the content, it gets executed before the actual thing being inserted. – 0bserver07 Jan 09 '14 at 18:53
  • @beck03076 I figured it out! (I think) I need to use track_activity on the backend rather than using a front end wise JS stuff. – 0bserver07 Jan 09 '14 at 18:54

1 Answers1

0
$("#someDiv").bind("DOMSubtreeModified", function() {
    alert("tree changed");
});

Is there a JavaScript/jQuery DOM change listener?

This worked, but I realized I was doing it the wrong way, it's too late to manipulate the data in the front end.

Community
  • 1
  • 1
0bserver07
  • 3,390
  • 1
  • 28
  • 56