[英]rails jquery popup if user not logged in
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. 如果用户已经在网站上停留了一定时间(测试3秒)并且未登录,则尝试弹出一个简单的对话框。
It works fine, but it's still popping up even when a user is logged in, and that shouldn't be case. 它可以正常工作,但是即使用户登录,它仍然会弹出,但事实并非如此。
the HAML: 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 当我console.log $(“#user_id”)。val()时,即使我登录也总是说它是未定义的
the css (not the issue): CSS(不是问题):
.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;
}
The haml
code for setting the :id
is not correct; 设置:id
的haml
代码不正确; so it is not being set, and hence $("#user_id").val()
is evaluating to undefined in all cases. 因此未设置它,因此$("#user_id").val()
在所有情况下的评估结果均为undefined。
Try: 尝试:
haml: 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: CoffeeScript的:
signupPopUp = ->
$(".signuppopup").css "display", "block" if $("#signed_in").length > 0
return
setTimeout signupPopUp, 3000
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.