mirror of
https://github.com/2ec0b4/kaamelott-soundboard.git
synced 2025-12-10 08:25:34 +00:00
Révise l'utilisation de require
This commit is contained in:
@@ -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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user