Fix adding event listener using jQuery

This commit is contained in:
printempw 2017-08-01 12:19:23 +08:00
parent 21011ef277
commit 07110d2580
2 changed files with 22 additions and 26 deletions

View File

@ -2,18 +2,18 @@
'use strict';
$('#private').on('ifToggled', function () {
$(this).prop('checked') ? $('#msg').show() : $('#msg').hide();
});
$('#type-skin').on('ifToggled', function () {
$(this).prop('checked') ? $('#skin-type').show() : $('#skin-type').hide();
});
$('body').on('change', '#file', () => handleFiles()).on('ifToggled', '#type-cape', () => {
MSP.clear();
handleFiles();
});
$('body')
.on('change', '#file', () => handleFiles())
.on('ifToggled', '#type-cape', () => {
MSP.clear();
handleFiles();
})
.on('ifToggled', '#type-skin', function () {
$(this).prop('checked') ? $('#skin-type').show() : $('#skin-type').hide();
})
.on('ifToggled', '#private', function () {
$(this).prop('checked') ? $('#msg').show() : $('#msg').hide();
});
// Real-time preview
function handleFiles(files, type) {

View File

@ -7,10 +7,17 @@ $('body').on('click', '.player', function () {
$(this).addClass('player-selected');
showPlayerTexturePreview(this.id);
});
$('body').on('click', '#preview-switch', () => {
}).on('click', '#preview-switch', () => {
TexturePreview.previewType == '3D' ? TexturePreview.show2dPreview() : TexturePreview.show3dPreview();
}).on('change', '#preference', function () {
fetch({
type: 'POST',
url: url('user/player/preference'),
dataType: 'json',
data: { pid: $(this).attr('pid'), preference: $(this).val() }
}).then(({ errno, msg }) => {
(errno == 0) ? toastr.success(msg) : toastr.warning(msg);
}).catch(err => showAjaxError(err));
});
function showPlayerTexturePreview(pid) {
@ -44,17 +51,6 @@ function showPlayerTexturePreview(pid) {
}).catch(err => showAjaxError(err));
}
$('body').on('change', '#preference', function () {
fetch({
type: 'POST',
url: url('user/player/preference'),
dataType: 'json',
data: { pid: $(this).attr('pid'), preference: $(this).val() }
}).then(({ errno, msg }) => {
(errno == 0) ? toastr.success(msg) : toastr.warning(msg);
}).catch(err => showAjaxError(err));
});
function changePlayerName(pid) {
let newPlayerName = '';
const $playerName = $(`td:contains("${pid}")`).next();