mirror of
https://github.com/2ec0b4/kaamelott-soundboard.git
synced 2025-12-08 15:43:24 +00:00
Améliore le modèle et la collection Sound
This commit is contained in:
@@ -2,14 +2,25 @@ define(
|
||||
'collections/sounds',
|
||||
[
|
||||
'backbone',
|
||||
'underscore',
|
||||
'models/sound'
|
||||
],
|
||||
function (Backbone, Sound) {
|
||||
function (Backbone, _, Sound) {
|
||||
"use strict";
|
||||
|
||||
var Sounds = Backbone.Collection.extend({
|
||||
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;
|
||||
|
||||
@@ -16,11 +16,12 @@ define(
|
||||
},
|
||||
play: function() {
|
||||
if( !this.audio ) {
|
||||
this.audio = new Audio('sounds/'+this.attributes.file);
|
||||
this.audio = new Audio('sounds/'+this.get('file'));
|
||||
}
|
||||
|
||||
this.audio.play();
|
||||
this.attributes.playing = true;
|
||||
|
||||
this.set('playing', true);
|
||||
},
|
||||
stop: function() {
|
||||
if( this.audio && !this.audio.paused ) {
|
||||
@@ -28,7 +29,7 @@ define(
|
||||
this.audio.load();
|
||||
}
|
||||
|
||||
this.attributes.playing = false;
|
||||
this.set('playing', false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user