Mute button for gather.

This commit is contained in:
simplefl 2015-05-13 23:17:58 +02:00
parent 5a7c9f60d0
commit 6560fe18f9
2 changed files with 33 additions and 5 deletions

View file

@ -12,7 +12,7 @@
<p>Gather running, <%= Gather::FULL - @gather.gatherers.length %> more needed.</p> <p>Gather running, <%= Gather::FULL - @gather.gatherers.length %> more needed.</p>
<p> <p>
You can download custom maps via the You can download custom maps via the
<%= link_to "Steam Workshop", "http://steamcommunity.com/workshop/browse?searchtext=&childpublishedfileid=0&section=items&appid=4920&browsesort=trend&requiredtags%5B%5D=level" %>. <%= link_to "Steam Workshop", "http://steamcommunity.com/workshop/browse?searchtext=&childpublishedfileid=0&section=items&appid=4920&browsesort=trend&requiredtags%5B%5D=level" %>.
</p> </p>
@ -49,13 +49,13 @@
<% elsif @gather.status == Gather::STATE_FINISHED and @gather.server %> <% elsif @gather.status == Gather::STATE_FINISHED and @gather.server %>
<p>Gather finished, join the Server and TeamSpeak 3.</p> <p>Gather finished, join the Server and TeamSpeak 3.</p>
<p> <p>
<strong>Maps</strong>: <%= namelink @gather.map1.map if @gather.map1 %>, <%= (namelink @gather.map2.map) if @gather.map2 %> <br> <strong>Maps</strong>: <%= namelink @gather.map1.map if @gather.map1 %>, <%= (namelink @gather.map2.map) if @gather.map2 %> <br>
<strong>Server</strong>: <strong>Server</strong>:
<% if @gather.server %> <% if @gather.server %>
<%= @gather.server %> <%= @gather.server %>
(<%= @gather.server.ip %>:<%= @gather.server.port %> ; (<%= @gather.server.ip %>:<%= @gather.server.port %> ;
password = <%= if @gather.server.password then @gather.server.password else "<Password not specified>" end %>) password = <%= if @gather.server.password then @gather.server.password else "<Password not specified>" end %>)
<% end %> <% end %>
</p> </p>
@ -67,6 +67,8 @@
<% end %> <% end %>
<% end %> <% end %>
<%= link_to "Mute", '#', id: "mute", class: 'button tiny' %>
<% if cuser and cuser.admin? %> <% if cuser and cuser.admin? %>
<%= link_to "Admin Page", edit_gather_url, class: 'admin button' %> <%= link_to "Admin Page", edit_gather_url, class: 'admin button' %>
<% end %> <% end %>

View file

@ -1,11 +1,14 @@
<div id="jplayer"></div> <div id="jplayer"></div>
<script type="text/javascript"> <script type="text/javascript">
var played = false; var played = false;
var muted = false;
var leave_confirm = true; var leave_confirm = true;
<% if @gatherer and @gatherer.can_destroy? cuser %> <% if @gatherer and @gatherer.can_destroy? cuser %>
var gatherer_id = <%= @gatherer.id %>; var gatherer_id = <%= @gatherer.id %>;
var muted = false;
<% else %> <% else %>
var gatherer_id = 0; var gatherer_id = 0;
var muted = true;
<% end %> <% end %>
function updateGathererStatus(status) { function updateGathererStatus(status) {
@ -22,6 +25,7 @@
} }
$(document).ready(function() { $(document).ready(function() {
init_mute();
$.PeriodicalUpdater("/gathers/" + <%= @gather.id %> + ".js", { $.PeriodicalUpdater("/gathers/" + <%= @gather.id %> + ".js", {
method: "GET", method: "GET",
type: "script", type: "script",
@ -35,7 +39,7 @@
$(this).jPlayer("setMedia", { $(this).jPlayer("setMedia", {
mp3: "http://www.ensl.org/sounds/gather-1.mp3" mp3: "http://www.ensl.org/sounds/gather-1.mp3"
}).jPlayer("play"); }).jPlayer("play");
var click = document.ontouchstart === undefined ? 'click' : 'touchstart'; var click = document.ontouchstart === undefined ? 'click' : 'touchstart';
var kickoff = function () { var kickoff = function () {
$("#jplayer").jPlayer("play"); $("#jplayer").jPlayer("play");
@ -55,9 +59,31 @@
else if (response.length > 10) { else if (response.length > 10) {
$("#jplayer").jPlayer("stop"); $("#jplayer").jPlayer("stop");
} }
init_mute();
} }
}); });
function init_mute() {
if(!muted){
$("#mute").text("Mute");
$("#jplayer").jPlayer("unmute");
} else {
$("#mute").text("Unmute");
$("#jplayer").jPlayer("mute");
}
$("#mute").off("click");
$("#mute").on("click", function() {
if(muted){
$(this).text("Mute");
$("#jplayer").jPlayer("unmute");
} else {
$(this).text("Unmute");
$("#jplayer").jPlayer("mute");
}
muted = !muted;
return false;
});
}
$(window).bind('unload', function() { $(window).bind('unload', function() {
if (gatherer_id > 0 && leave_confirm) { if (gatherer_id > 0 && leave_confirm) {
updateGathererStatus('leaving'); updateGathererStatus('leaving');