1
0
mirror of https://github.com/2ec0b4/kaamelott-soundboard.git synced 2025-12-08 15:43:24 +00:00

(master) Merge branch 'petosorus-random_button'

* petosorus-random_button:
  (petosorus-random_button) Corrige un "faux-vrai" de référence de fichier versionné par Gulp
  (petosorus-random_button) Améliore les espacements des boutons
  (petosorus-random_button) Réinitialise également le filtre
  (petosorus-random_button) Active / désactive le bouton
  Random button styling
  styling
  Filtrage lors de l'aléatoire
  Proto bouton aléatoire
This commit is contained in:
Antoine
2020-02-15 20:01:13 +01:00
10 changed files with 141 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ define("app", function(require) {
Radio.channel("App").reply("region:show", this.showRegion.bind(this));
Radio.channel("App").reply("modal:show", this.showModal.bind(this));
Radio.channel("Sounds").on("sound:play", this.changeUrl.bind(this));
Radio.channel("Sounds").on("sound:stop", this.resetUrl.bind(this));
this.router = new Marionette.AppRouter();
@@ -46,6 +47,10 @@ define("app", function(require) {
this.router.navigate("son/"+slug);
},
resetUrl: function() {
this.router.navigate("/");
},
showRegion: function showRegion(params) {
this.mainRegion.show(params.view);
},

View File

@@ -14,6 +14,15 @@ define("collections/sounds", function(require) {
return str1.localeCompare(str2);
},
filterByCid: function(cid) {
if(cid == "") {
return this;
}
return new Sounds(this.filter(function(data) {
return data.cid == cid;
}));
},
filterByTitle: function(search){
var that = this,
pattern;
@@ -25,7 +34,7 @@ define("collections/sounds", function(require) {
pattern = new RegExp(this.removeDiacritics(search), "gi");
return new Sounds(this.filter(function(data) {
pattern.lastIndex = 0;
return pattern.test(that.removeDiacritics(data.get("title")))
|| pattern.test(that.removeDiacritics(data.get("character")))
|| pattern.test(that.removeDiacritics(data.get("episode")));

View File

@@ -0,0 +1,2 @@
<button id="random" class="btn">Aléatoire</button>
<button id="reset" class="btn" disabled>Réinitialiser</button>

View File

@@ -2,6 +2,10 @@
</div>
<div id="random">
</div>
<div id="list">
</div>

View File

@@ -20,6 +20,7 @@ define("views/filter", function(require) {
},
initialize: function() {
this.channel = Radio.channel("Sounds");
this.channel.on("sounds:reset", this.resetFilter.bind(this));
},
filterSounds: function(e) {
var value = this.$el.find(this.ui.searchField).val();
@@ -35,7 +36,9 @@ define("views/filter", function(require) {
this.channel.trigger("sounds:filter", value);
},
resetFilter: function(e) {
e.preventDefault();
if (e) {
e.preventDefault();
}
this.$el.find(this.ui.searchField).val('');
this.$el.find(this.ui.searchForm).submit();

43
js/app/views/random.js Normal file
View File

@@ -0,0 +1,43 @@
define("views/random", function(require) {
"use strict";
var Marionette = require("marionette"),
Radio = require("backbone.radio"),
RandomTemplate = require("hbs!templates/random"),
RandomView;
RandomView = Marionette.LayoutView.extend({
template: RandomTemplate,
ui: {
randomButton: "#random",
resetButton: "#reset"
},
events: {
"click @ui.randomButton": "random",
"click @ui.resetButton": "reset"
},
initialize: function() {
var that = this;
this.channel = Radio.channel("Sounds");
this.channel.on("sounds:filter", function (value) {
if (value == "") {
return;
}
that.enableButton();
});
},
random: function() {
this.enableButton();
this.channel.trigger("sounds:random");
},
reset: function() {
this.$el.find(this.ui.resetButton).attr('disabled', 'disabled');
this.channel.trigger("sounds:reset");
},
enableButton: function() {
this.$el.find(this.ui.resetButton).removeAttr('disabled');
}
});
return RandomView;
});

View File

@@ -3,6 +3,7 @@ define("views/soundboard", function(require) {
var Marionette = require("marionette"),
SoundsFilterView = require("views/filter"),
RandomView = require("views/random"),
SoundsView = require("views/sounds"),
SoundboardTemplate = require("hbs!templates/soundboard"),
SoundboardView;
@@ -11,6 +12,7 @@ define("views/soundboard", function(require) {
template: SoundboardTemplate,
regions: {
regFilter: "#filter",
regRandom: "#random",
regList: "#list"
},
initialize: function(options) {
@@ -18,6 +20,7 @@ define("views/soundboard", function(require) {
},
onShow: function() {
this.showChildView("regFilter", new SoundsFilterView());
this.showChildView("regRandom", new RandomView());
this.showChildView("regList", new SoundsView({
slug: this.slug
}));

View File

@@ -28,6 +28,8 @@ define("views/sounds", function(require) {
this.channel = Radio.channel("Sounds");
this.channel.request("getSounds").then(this.initCollection.bind(this));
this.channel.on("sounds:filter", this.filterCollection.bind(this));
this.channel.on("sounds:random", this.randomSound.bind(this));
this.channel.on("sounds:reset", this.resetCollection.bind(this));
},
onBeforeRender: function() {
var sound;
@@ -52,11 +54,32 @@ define("views/sounds", function(require) {
this.render();
},
filterCollectionByCid: function(cid) {
this.collection = this.data.collection.filterByCid(cid);
this.render();
},
manageSounds: function(args) {
this.stopPlayingSound();
Radio.channel("Sounds").trigger("sound:play", args.model.getSlug());
},
randomSound: function() {
this.stopPlayingSound();
this.filterCollection("");
var index = Math.floor(Math.random() * Math.floor(this.collection.length));
var sound = this.collection.models[index];
this.filterCollectionByCid(sound.cid);
Radio.channel("Sounds").trigger("sound:play", sound.getSlug());
sound.play();
},
resetCollection: function() {
this.filterCollection("");
Radio.channel("Sounds").trigger("sound:stop");
},
stopPlayingSound: function() {
var playingSound = this.collection.findWhere({playing: true});