Fix double confirm when you click the 'Leave Gather' button

This commit is contained in:
jamal 2014-10-11 09:13:07 -04:00
parent ffb7793e88
commit 3589e226d3
2 changed files with 8 additions and 4 deletions

View file

@ -3,7 +3,7 @@
<% if @gatherer and @gatherer.can_destroy? cuser %>
<p>Gather running, <%= Gather::FULL - @gather.gatherers.length %> more needed.</p>
<%= link_to 'Leave Gather', @gatherer, confirm: 'Are you sure?', method: :delete, class: 'button tiny' %>
<%= link_to 'Leave Gather', @gatherer, confirm: 'Are you sure?', method: :delete, class: 'button tiny leave-gather' %>
<% elsif (g = Gatherer.new(gather: @gather, user: cuser)).can_create?(cuser) %>
<%= form_for g do |f| %>

View file

@ -1,7 +1,7 @@
<div id="jplayer"></div>
<script type="text/javascript">
var played = false;
var leaving = true;
var leaving = false;
<% if @gatherer and @gatherer.can_destroy? cuser %>
var gatherer_id = <%= @gatherer.id %>;
<% else %>
@ -59,17 +59,21 @@
});
$(window).bind('beforeunload', function(e) {
if (gatherer_id > 0) {
if (gatherer_id > 0 && !leaving) {
return "You will be removed from the Gather if you leave this page.";
}
});
$(window).bind('unload', function() {
if (gatherer_id > 0) {
if (gatherer_id > 0 && !leaving) {
updateGathererStatus('leaving');
}
});
$('.leave-gather').click(function() {
leaving = true;
});
var afk = false;
var afk_timeout;
var afk_time = 1000 * 60 * 15; // 15 minutes