mirror of
https://github.com/2ec0b4/kaamelott-soundboard.git
synced 2025-12-08 23:53:24 +00:00
Révise l'utilisation de require
This commit is contained in:
@@ -1,32 +1,30 @@
|
||||
define(
|
||||
'views/filter',
|
||||
[
|
||||
'marionette',
|
||||
'backbone.radio',
|
||||
'hbs!templates/filter'
|
||||
],
|
||||
function (Marionette, Radio, SoundsFilterTemplate) {
|
||||
"use strict";
|
||||
define('views/filter', function(require) {
|
||||
"use strict";
|
||||
|
||||
var SoundsFilterView = Marionette.LayoutView.extend({
|
||||
template: SoundsFilterTemplate,
|
||||
ui: {
|
||||
searchForm: 'form',
|
||||
searchField: 'form input[name="s"]'
|
||||
},
|
||||
events: {
|
||||
'submit @ui.searchForm': 'filterSounds',
|
||||
'keyup @ui.searchField': 'filterSounds'
|
||||
},
|
||||
initialize: function() {
|
||||
this.channel = Radio.channel('Sounds');
|
||||
},
|
||||
filterSounds: function(e) {
|
||||
e.preventDefault();
|
||||
var Marionette = require('marionette'),
|
||||
Radio = require('backbone.radio'),
|
||||
SoundsFilterTemplate = require('hbs!templates/filter.hbs'),
|
||||
SoundsFilterView;
|
||||
|
||||
this.channel.trigger('sounds:filter', $(this.ui.searchField).val());
|
||||
}
|
||||
});
|
||||
SoundsFilterView = Marionette.LayoutView.extend({
|
||||
template: SoundsFilterTemplate,
|
||||
ui: {
|
||||
searchForm: 'form',
|
||||
searchField: 'form input[name="s"]'
|
||||
},
|
||||
events: {
|
||||
'submit @ui.searchForm': 'filterSounds',
|
||||
'keyup @ui.searchField': 'filterSounds'
|
||||
},
|
||||
initialize: function() {
|
||||
this.channel = Radio.channel('Sounds');
|
||||
},
|
||||
filterSounds: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
return SoundsFilterView;
|
||||
this.channel.trigger('sounds:filter', $(this.ui.searchField).val());
|
||||
}
|
||||
});
|
||||
|
||||
return SoundsFilterView;
|
||||
});
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
define(
|
||||
'views/main',
|
||||
[
|
||||
'marionette',
|
||||
'hbs!templates/main'
|
||||
],
|
||||
function (Marionette, MainTemplate) {
|
||||
"use strict";
|
||||
|
||||
var MainView = Marionette.LayoutView.extend({
|
||||
template: MainTemplate,
|
||||
regions: {
|
||||
'main': 'main'
|
||||
}
|
||||
});
|
||||
|
||||
return MainView;
|
||||
});
|
||||
@@ -1,69 +1,67 @@
|
||||
define(
|
||||
'views/sound',
|
||||
[
|
||||
'marionette',
|
||||
'models/sound',
|
||||
'hbs!templates/sound'
|
||||
],
|
||||
function (Marionette, SoundModel, SoundBlockTemplate) {
|
||||
"use strict";
|
||||
define('views/sound', function(require) {
|
||||
"use strict";
|
||||
|
||||
var SoundBlockView = Marionette.ItemView.extend({
|
||||
template: SoundBlockTemplate,
|
||||
model: SoundModel,
|
||||
tagName: 'li',
|
||||
ui: {
|
||||
soundItem: 'a'
|
||||
},
|
||||
events: {
|
||||
'click @ui.soundItem': 'toggleSound',
|
||||
'mouseenter @ui.soundItem': 'toggleSoundDetail',
|
||||
'mouseleave @ui.soundItem': 'toggleSoundDetail'
|
||||
},
|
||||
initialize: function() {
|
||||
this.listenTo(this.model, "change:playing", this.playingAttributeChanged);
|
||||
},
|
||||
toggleSound: function(e) {
|
||||
e.preventDefault();
|
||||
var Marionette = require('marionette'),
|
||||
SoundModel = require('models/sound'),
|
||||
SoundTemplate = require('hbs!templates/sound.hbs'),
|
||||
SoundView;
|
||||
|
||||
if( this.model.get('playing') ) {
|
||||
this.trigger('sound:stop');
|
||||
SoundView = Marionette.ItemView.extend({
|
||||
template: SoundTemplate,
|
||||
model: SoundModel,
|
||||
tagName: 'li',
|
||||
ui: {
|
||||
soundItem: 'a'
|
||||
},
|
||||
events: {
|
||||
'click @ui.soundItem': 'toggleSound',
|
||||
'mouseenter @ui.soundItem': 'toggleSoundDetail',
|
||||
'mouseleave @ui.soundItem': 'toggleSoundDetail'
|
||||
},
|
||||
initialize: function() {
|
||||
this.listenTo(this.model, "change:playing", this.playingAttributeChanged);
|
||||
},
|
||||
toggleSound: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
this.model.stop();
|
||||
} else {
|
||||
this.trigger('sound:play');
|
||||
if( this.model.get('playing') ) {
|
||||
this.trigger('sound:stop');
|
||||
|
||||
this.model.play();
|
||||
}
|
||||
},
|
||||
playingAttributeChanged: function() {
|
||||
if( this.model.get('playing') ) {
|
||||
$(this.ui.soundItem).addClass('playing');
|
||||
} else {
|
||||
$(this.ui.soundItem).removeClass('playing');
|
||||
}
|
||||
},
|
||||
toggleSoundDetail: function(e) {
|
||||
var offset;
|
||||
this.model.stop();
|
||||
} else {
|
||||
this.trigger('sound:play');
|
||||
|
||||
if (e.type === 'mouseleave') {
|
||||
$('.tooltip').remove();
|
||||
return;
|
||||
}
|
||||
|
||||
offset = $(this.el).offset();
|
||||
|
||||
$('<div/>')
|
||||
.addClass('tooltip')
|
||||
.append(
|
||||
$('<p/>').text(this.model.getSoundDetail())
|
||||
)
|
||||
.css({left: (offset.left+25)+'px', top: (offset.top+30)+'px'})
|
||||
.appendTo('body')
|
||||
.delay(1000)
|
||||
.show(0);
|
||||
this.model.play();
|
||||
}
|
||||
});
|
||||
},
|
||||
playingAttributeChanged: function() {
|
||||
if( this.model.get('playing') ) {
|
||||
$(this.ui.soundItem).addClass('playing');
|
||||
} else {
|
||||
$(this.ui.soundItem).removeClass('playing');
|
||||
}
|
||||
},
|
||||
toggleSoundDetail: function(e) {
|
||||
var offset;
|
||||
|
||||
return SoundBlockView;
|
||||
if (e.type === 'mouseleave') {
|
||||
$('.tooltip').remove();
|
||||
return;
|
||||
}
|
||||
|
||||
offset = $(this.el).offset();
|
||||
|
||||
$('<div/>')
|
||||
.addClass('tooltip')
|
||||
.append(
|
||||
$('<p/>').text(this.model.getSoundDetail())
|
||||
)
|
||||
.css({left: (offset.left+25)+'px', top: (offset.top+30)+'px'})
|
||||
.appendTo('body')
|
||||
.delay(1000)
|
||||
.show(0);
|
||||
}
|
||||
});
|
||||
|
||||
return SoundView;
|
||||
});
|
||||
|
||||
@@ -1,27 +1,23 @@
|
||||
define(
|
||||
'views/soundboard',
|
||||
[
|
||||
'marionette',
|
||||
'views/filter',
|
||||
'views/sounds',
|
||||
'hbs!templates/soundboard'
|
||||
],
|
||||
function (Marionette, SoundsFilterView, SoundsView, SoundboardTemplate) {
|
||||
"use strict";
|
||||
define('views/soundboard', function(require) {
|
||||
"use strict";
|
||||
|
||||
var SoundboardView = Marionette.LayoutView.extend({
|
||||
template: SoundboardTemplate,
|
||||
regions: {
|
||||
'filter': '#filter',
|
||||
'list': '#list'
|
||||
},
|
||||
onShow: function() {
|
||||
var Marionette = require('marionette'),
|
||||
SoundsFilterView = require('views/filter'),
|
||||
SoundsView = require('views/sounds'),
|
||||
SoundboardTemplate = require('hbs!templates/soundboard.hbs'),
|
||||
SoundboardView;
|
||||
|
||||
this.showChildView('filter', new SoundsFilterView());
|
||||
this.showChildView('list', new SoundsView());
|
||||
SoundboardView = Marionette.LayoutView.extend({
|
||||
template: SoundboardTemplate,
|
||||
regions: {
|
||||
'filter': '#filter',
|
||||
'list': '#list'
|
||||
},
|
||||
onShow: function() {
|
||||
this.showChildView('filter', new SoundsFilterView());
|
||||
this.showChildView('list', new SoundsView());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return SoundboardView;
|
||||
return SoundboardView;
|
||||
});
|
||||
|
||||
@@ -1,52 +1,49 @@
|
||||
define(
|
||||
'views/sounds',
|
||||
[
|
||||
'marionette',
|
||||
'backbone.radio',
|
||||
'underscore',
|
||||
'collections/sounds',
|
||||
'views/sound'
|
||||
],
|
||||
function (Marionette, Radio, _, SoundsCollection, SoundView) {
|
||||
"use strict";
|
||||
define('views/sounds', function(require) {
|
||||
"use strict";
|
||||
|
||||
var SoundsCollectionView = Marionette.CollectionView.extend({
|
||||
childView: SoundView,
|
||||
collection: new SoundsCollection(),
|
||||
tagName: 'ul',
|
||||
childEvents: {
|
||||
'sound:play': 'stopPlayingSound'
|
||||
},
|
||||
initialize: function() {
|
||||
var that = this;
|
||||
var Marionette = require('marionette'),
|
||||
Radio = require('backbone.radio'),
|
||||
SoundsCollection = require('collections/sounds'),
|
||||
SoundView = require('views/sound'),
|
||||
SoundsCollectionView;
|
||||
|
||||
this.data = {
|
||||
collection: this.collection
|
||||
};
|
||||
SoundsCollectionView = Marionette.CollectionView.extend({
|
||||
childView: SoundView,
|
||||
collection: new SoundsCollection(),
|
||||
tagName: 'ul',
|
||||
childEvents: {
|
||||
'sound:play': 'stopPlayingSound'
|
||||
},
|
||||
initialize: function() {
|
||||
var that = this;
|
||||
|
||||
this.channel = Radio.channel('Sounds');
|
||||
this.channel.request('getSounds').then(this.initCollection.bind(this));
|
||||
this.channel.on('sounds:filter', this.filterCollection.bind(this));
|
||||
},
|
||||
initCollection: function(sounds) {
|
||||
this.data.collection = new SoundsCollection(sounds);
|
||||
this.collection = this.data.collection;
|
||||
this.data = {
|
||||
collection: this.collection
|
||||
};
|
||||
|
||||
this.render();
|
||||
},
|
||||
filterCollection: function(search) {
|
||||
this.collection = this.data.collection.filterByTitle(search);
|
||||
this.channel = Radio.channel('Sounds');
|
||||
this.channel.request('getSounds').then(this.initCollection.bind(this));
|
||||
this.channel.on('sounds:filter', this.filterCollection.bind(this));
|
||||
},
|
||||
initCollection: function(sounds) {
|
||||
this.data.collection = new SoundsCollection(sounds);
|
||||
this.collection = this.data.collection;
|
||||
|
||||
this.render();
|
||||
},
|
||||
stopPlayingSound: function() {
|
||||
var playingSound = this.collection.findWhere({playing: true});
|
||||
this.render();
|
||||
},
|
||||
filterCollection: function(search) {
|
||||
this.collection = this.data.collection.filterByTitle(search);
|
||||
|
||||
if( playingSound ) {
|
||||
playingSound.stop();
|
||||
}
|
||||
this.render();
|
||||
},
|
||||
stopPlayingSound: function() {
|
||||
var playingSound = this.collection.findWhere({playing: true});
|
||||
|
||||
if( playingSound ) {
|
||||
playingSound.stop();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return SoundsCollectionView;
|
||||
return SoundsCollectionView;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user