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

Améliore le modèle et la collection Sound

This commit is contained in:
Antoine
2016-04-11 23:45:10 +02:00
parent 878f37351f
commit bde2b12632
2 changed files with 17 additions and 5 deletions

View File

@@ -2,14 +2,25 @@ define(
'collections/sounds', 'collections/sounds',
[ [
'backbone', 'backbone',
'underscore',
'models/sound' 'models/sound'
], ],
function (Backbone, Sound) { function (Backbone, _, Sound) {
"use strict"; "use strict";
var Sounds = Backbone.Collection.extend({ var Sounds = Backbone.Collection.extend({
model: Sound, model: Sound,
url: 'sounds/sounds.json' url: 'sounds/sounds.json',
search : function(search){
if( search == "" ) {
return this;
}
var pattern = new RegExp('^'+search, 'gi');
return _(this.filter(function(data) {
return pattern.test(data.get('title'));
}));
}
}); });
return Sounds; return Sounds;

View File

@@ -16,11 +16,12 @@ define(
}, },
play: function() { play: function() {
if( !this.audio ) { if( !this.audio ) {
this.audio = new Audio('sounds/'+this.attributes.file); this.audio = new Audio('sounds/'+this.get('file'));
} }
this.audio.play(); this.audio.play();
this.attributes.playing = true;
this.set('playing', true);
}, },
stop: function() { stop: function() {
if( this.audio && !this.audio.paused ) { if( this.audio && !this.audio.paused ) {
@@ -28,7 +29,7 @@ define(
this.audio.load(); this.audio.load();
} }
this.attributes.playing = false; this.set('playing', false);
} }
}); });