1
0
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:
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',
[
'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;

View File

@@ -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);
}
});