From bde2b12632f68df6b22329666d139e673e264a19 Mon Sep 17 00:00:00 2001 From: Antoine Date: Mon, 11 Apr 2016 23:45:10 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liore=20le=20mod=C3=A8le=20et=20la=20co?= =?UTF-8?q?llection=20Sound?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/app/collections/sounds.js | 15 +++++++++++++-- js/app/models/sound.js | 7 ++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/js/app/collections/sounds.js b/js/app/collections/sounds.js index 5514103..79593a7 100644 --- a/js/app/collections/sounds.js +++ b/js/app/collections/sounds.js @@ -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; diff --git a/js/app/models/sound.js b/js/app/models/sound.js index ec193ab..86cd118 100644 --- a/js/app/models/sound.js +++ b/js/app/models/sound.js @@ -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); } });