Question

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!

Was it helpful?

Solution

$("#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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top