Reputation: 142
trying to have a simple box popup if a user has been on site for certain duration (3 seconds for testing) and they're not logged in.
It works fine, but it's still popping up even when a user is logged in, and that shouldn't be case.
the HAML:
.signuppopup{:id => if current_user then "user_id#{current_user.id}" else "user_id#{0}" end}
%h1 You've been browsing the site for a while, why not sign up?
the coffescript:
signupPopUp = ->
$(".signuppopup").css "display", "block" unless $("#user_id").val() is 0
return
setTimeout signupPopUp, 3000
When I console.log the $("#user_id").val() it always says it's undefined even when I'm logged in
the css (not the issue):
.signuppopup{
opacity:0.92;
position: absolute;
text-align: center;
top: 35%;
left: 35%;
height: 30%;
width: 30%;
background: #69EAB8;
padding-top: 20px;
display: none;
overflow-y: auto;
}
Upvotes: 1
Views: 283
Reputation: 13067
The haml
code for setting the :id
is not correct; so it is not being set, and hence $("#user_id").val()
is evaluating to undefined in all cases.
Try:
haml:
.signuppopup{:id => (if current_user then "signed_in" else "not_signed_in")}
%h1 You've been browsing the site for a while, why not sign up?
coffeescript:
signupPopUp = ->
$(".signuppopup").css "display", "block" if $("#signed_in").length > 0
return
setTimeout signupPopUp, 3000
Upvotes: 1