diff --git a/resources/assets/src/js/user/closet.js b/resources/assets/src/js/user/closet.js
deleted file mode 100644
index e82bc7b5..00000000
--- a/resources/assets/src/js/user/closet.js
+++ /dev/null
@@ -1,371 +0,0 @@
-/* global initSkinViewer, applySkinViewerConfig, defaultSteveSkin */
-
-'use strict';
-
-$(document).ready(initCloset);
-
-$('body').on('click', '.item-body', async function () {
- $('.item-selected').parent().removeClass('item-selected');
- const $item = $(this).parent();
- const $indicator = $('#textures-indicator');
-
- $item.addClass('item-selected');
-
- const tid = parseInt($item.attr('tid'));
-
- try {
- const { type, hash } = await fetch({
- type: 'POST',
- url: url(`skinlib/info/${tid}`),
- dataType: 'json'
- });
-
- if (type === 'cape') {
- $.msp.config.capeUrl = url(`textures/${hash}`);
- $indicator.data('cape', tid);
- } else {
- $.msp.config.skinUrl = url(`textures/${hash}`);
- $indicator.data('skin', tid);
- }
-
- if (type === 'alex' && !$.msp.config.slim || type === 'steve' && $.msp.config.slim) {
- // Reset skinview3d to change model
- $.msp.config.slim = (type === 'alex');
- initSkinViewer();
- } else {
- applySkinViewerConfig();
- }
-
- const skin = $indicator.data('skin');
- const cape = $indicator.data('cape');
-
- if (skin !== undefined && cape !== undefined) {
- $indicator.text(`${trans('general.skin')} & ${trans('general.cape')}`);
- } else if (skin) {
- $indicator.text(trans('general.skin'));
- } else if (cape) {
- $indicator.text(trans('general.cape'));
- }
- } catch (error) {
- showAjaxError(error);
- }
-});
-
-$('body').on('click', '.category-switch', () => {
- const category = $('a[href="#skin-category"]').parent().hasClass('active') ? 'cape' : 'skin';
- const search = $('input[name=q]').val();
- const page = parseInt($('#closet-paginator').attr(`last-${category}-page`));
-
- reloadCloset(category, page, search);
-});
-
-$('#closet-reset').click(() => {
- const $indicator = $('#textures-indicator');
- $indicator.text('');
- $indicator.removeData('skin');
- $indicator.removeData('cape');
-
- $.msp.config.skinUrl = defaultSteveSkin;
- $.msp.config.capeUrl = '';
- $.msp.config.slim = false;
- initSkinViewer();
-});
-
-async function initCloset() {
- if ($('#closet-container').length !== 1)
- return;
-
- $('input[name=q]').on('input', debounce(() => {
- const category = $('#skin-category').hasClass('active') ? 'skin' : 'cape';
- reloadCloset(category, 1, $('input[name=q]').val());
- }, 350));
-
- try {
- const { items, category, total_pages } = await fetch({
- type: 'GET',
- url: url('/user/closet-data'),
- dataType: 'json'
- });
-
- renderCloset(items, category);
-
- $('#closet-paginator').jqPaginator($.extend({}, $.defaultPaginatorConfig, {
- totalPages: total_pages,
- onPageChange: page => reloadCloset(
- $('#skin-category').hasClass('active') ? 'skin' : 'cape',
- page, $('input[name=q]').val()
- )
- }));
- } catch (error) {
- showAjaxError(error);
- }
-}
-
-/**
- *
- * @param {{ name: string, tid: number, type: 'steve' | 'alex' | 'cape' }} item
- */
-function renderClosetItemComponent(item) {
- return `
-
-
-
}preview/${item.tid}.png)
-
-
-
`;
-}
-
-/**
- * Render closet with giving items & category.
- *
- * @param {Array<{ name: string, tid: number, type: 'steve' | 'alex' | 'cape' }>} items
- * @param {'skin' | 'cape'} category
- */
-function renderCloset(items, category) {
- const search = $('input[name=q]').val();
- const container = $(`#${category}-category`).html('');
-
- if (items.length === 0) {
- $('#closet-paginator').hide();
-
- if (search === '') {
- container.html('' +
- trans('user.emptyClosetMsg', { url: url(`skinlib?filter=${category}`) }) +
- '
');
- } else {
- container.html(`${trans('general.noResult')}
`);
- }
-
- } else {
- $('#closet-paginator').show();
-
- container.html(items.reduce((carry, item) => carry + renderClosetItemComponent(item), ''));
- }
-}
-
-/**
- * Reload and render closet.
- *
- * @param {string} category
- * @param {number} page
- * @param {string} search
- */
-async function reloadCloset(textureCategory, page, search) {
- try {
- const { items, category, total_pages } = await fetch({
- type: 'GET',
- url: url('user/closet-data'),
- dataType: 'json',
- data: {
- category: textureCategory,
- page: page,
- perPage: getCapacityOfCloset(),
- q: search
- }
- });
-
- renderCloset(items, category);
-
- const paginator = $('#closet-paginator');
-
- paginator.attr(`last-${category}-page`, page);
- paginator.jqPaginator('option', {
- currentPage: page,
- totalPages: total_pages
- });
- } catch (error) {
- showAjaxError(error);
- }
-}
-
-/**
- * Get the capacity of closet.
- *
- * @returns {number}
- */
-function getCapacityOfCloset() {
- return ~~(
- $('#skin-category').width() /
- ($('.item').width() + parseFloat($('.item').css('margin-right')))
- ) * 2;
-}
-
-async function renameClosetItem(tid, oldName) {
- let newTextureName = '';
-
- try {
- newTextureName = await swal({
- title: trans('user.renameClosetItem'),
- input: 'text',
- inputValue: oldName,
- showCancelButton: true,
- inputValidator: value => (new Promise((resolve, reject) => {
- value ? resolve() : reject(trans('skinlib.emptyNewTextureName'));
- }))
- });
- } catch (error) {
- return;
- }
-
- try {
- const { errno, msg } = await fetch({
- type: 'POST',
- url: url('user/closet/rename'),
- dataType: 'json',
- data: { tid: tid, new_name: newTextureName }
- });
-
- if (errno === 0) {
- const type = $(`[tid=${tid}]`).data('texture-type');
- $(`[tid=${tid}]>.item-footer>.texture-name>span`).html(
- newTextureName +
- ` (${type})`
- );
- toastr.success(msg);
- } else {
- toastr.warning(msg);
- }
- } catch (error) {
- showAjaxError(error);
- }
-}
-
-async function removeFromCloset(tid) {
- try {
- await swal({
- text: trans('user.removeFromClosetNotice'),
- type: 'warning',
- showCancelButton: true
- });
- } catch (error) {
- return;
- }
-
- try {
- const { errno, msg } = await fetch({
- type: 'POST',
- url: url('user/closet/remove'),
- dataType: 'json',
- data: { tid: tid }
- });
-
- if (errno === 0) {
- swal({ type: 'success', html: msg });
-
- $(`div[tid=${tid}]`).remove();
-
- ['skin', 'cape'].forEach(type => {
- const container = $(`#${type}-category`);
-
- if ($.trim(container.html()) === '') {
- const msg = trans('user.emptyClosetMsg', { url: url(`skinlib?filter=${type}`) });
- container.html(`${msg}
`);
- }
- });
- } else {
- toastr.warning(msg);
- }
- } catch (error) {
- showAjaxError(error);
- }
-}
-
-async function setAsAvatar(tid) {
- try {
- await swal({
- title: trans('user.setAvatar'),
- text: trans('user.setAvatarNotice'),
- type: 'question',
- showCancelButton: true
- });
- } catch (error) {
- return;
- }
-
- try {
- const { errno, msg } = await fetch({
- type: 'POST',
- url: url('user/profile/avatar'),
- dataType: 'json',
- data: { tid: tid }
- });
-
- if (errno === 0) {
- toastr.success(msg);
-
- // Refersh avatars
- $('[alt="User Image"]').each(function () {
- $(this).prop('src', $(this).attr('src') + '?' + new Date().getTime());
- });
- } else {
- toastr.warning(msg);
- }
- } catch (error) {
- showAjaxError(error);
- }
-}
-
-async function setTexture() {
- const $indicator = $('#textures-indicator');
- let pid = 0;
- const skin = $indicator.data('skin'),
- cape = $indicator.data('cape');
-
- $('input[name="player"]').each(function(){
- if (this.checked) pid = this.id;
- });
-
- if (! pid) {
- toastr.info(trans('user.emptySelectedPlayer'));
- } else if (!skin && !cape) {
- toastr.info(trans('user.emptySelectedTexture'));
- } else {
- try {
- const { errno, msg } = await fetch({
- type: 'POST',
- url: url('user/player/set'),
- dataType: 'json',
- data: {
- 'pid': pid,
- 'tid[skin]': skin,
- 'tid[cape]': cape
- }
- });
-
- if (errno === 0) {
- swal({ type: 'success', html: msg });
- $('#modal-use-as').modal('hide');
- } else {
- toastr.warning(msg);
- }
- } catch (error) {
- showAjaxError(error);
- }
- }
-}
-
-if (process.env.NODE_ENV === 'test') {
- module.exports = {
- setAsAvatar,
- renderCloset,
- reloadCloset,
- getCapacityOfCloset,
- renameClosetItem,
- removeFromCloset,
- initCloset,
- setTexture,
- };
-}
diff --git a/resources/assets/src/js/user/player.js b/resources/assets/src/js/user/player.js
deleted file mode 100644
index 11f9c7a0..00000000
--- a/resources/assets/src/js/user/player.js
+++ /dev/null
@@ -1,248 +0,0 @@
-/* global initSkinViewer, defaultSteveSkin, defaultAlexSkin */
-
-'use strict';
-
-$('body').on('click', '.player', function () {
- $('.player-selected').removeClass('player-selected');
- $(this).addClass('player-selected');
-
- showPlayerTexturePreview(this.id);
-}).on('change', '#preference', async function () {
- try {
- const { errno, msg } = await fetch({
- type: 'POST',
- url: url('user/player/preference'),
- dataType: 'json',
- data: { pid: $(this).attr('pid'), preference: $(this).val() }
- });
- errno === 0 ? toastr.success(msg) : toastr.warning(msg);
- } catch (error) {
- showAjaxError(error);
- }
-}).on('click', '#preview-switch', () => {
- // Switch preview type between 2D and 3D
- $('#preview-3d-container').toggle();
- $('#preview-2d-container').toggle();
- $('.operations').toggle();
-
- if ($('#preview-3d-container').is(':visible')) {
- $('#preview-switch').html(trans('user.switch2dPreview'));
- } else {
- $('#preview-switch').html(trans('user.switch3dPreview'));
- }
-});
-
-async function showPlayerTexturePreview(pid) {
- try {
- const result = await fetch({
- type: 'GET',
- url: url('user/player/show'),
- dataType: 'json',
- data: { pid: pid }
- });
-
- let shouldBeUpdated = false;
-
- for (const type of ['steve', 'alex', 'cape']) {
- // Render skin preview of selected player
- const tid = result[`tid_${type}`];
-
- if (tid) {
- $(`#${type}`)
- .attr('src', url(`preview/200/${tid}.png`)).show().parent()
- .attr('href', url(`skinlib/show/${tid}`)).next().hide();
-
- const { hash } = await fetch({
- type: 'GET',
- url: url(`skinlib/info/${tid}`),
- dataType: 'json'
- });
-
- if (type === 'cape') {
- $.msp.config.capeUrl = url(`textures/${hash}`);
- } else if (type === (result.preference === 'slim' ? 'alex' : 'steve')) {
- $.msp.config.skinUrl = url(`textures/${hash}`);
- }
- } else {
- $(`#${type}`).hide().parent().next().show();
-
- if (type === 'cape') {
- $.msp.config.capeUrl = '';
- } else if (type === (result.preference === 'slim' ? 'alex' : 'steve')) {
- $.msp.config.skinUrl = type === 'steve' ? defaultSteveSkin : defaultAlexSkin;
- }
- }
- }
-
- if ($.msp.config.slim !== (result.preference === 'slim')) {
- $.msp.config.slim = !$.msp.config.slim;
- shouldBeUpdated = true;
- }
-
- if ($.msp.config.skinUrl !== $.msp.viewer.skinUrl || $.msp.config.capeUrl !== $.msp.viewer.capeUrl) {
- shouldBeUpdated = true;
- }
-
- if (shouldBeUpdated) {
- initSkinViewer();
- console.log(`[skinview3d] texture previews of player ${result.player_name} rendered`);
- }
- } catch (error) {
- showAjaxError(error);
- }
-}
-
-async function changePlayerName(pid) {
- let newPlayerName = '';
- const $playerName = $(`tr#${pid} td.player-name`);
-
- try {
- newPlayerName = await swal({
- title: trans('user.changePlayerName'),
- text: $('#player_name').attr('placeholder'),
- inputValue: $playerName.html(),
- input: 'text',
- showCancelButton: true,
- inputValidator: value => (new Promise((resolve, reject) => {
- value ? resolve() : reject(trans('user.emptyPlayerName'));
- }))
- });
- } catch (error) {
- return;
- }
-
- try {
- const { errno, msg } = await fetch({
- type: 'POST',
- url: url('user/player/rename'),
- dataType: 'json',
- data: { pid: pid, new_player_name: newPlayerName }
- });
-
- if (errno === 0) {
- swal({ type: 'success', html: msg });
-
- $playerName.html(newPlayerName);
- } else {
- swal({ type: 'warning', html: msg });
- }
- } catch (error) {
- showAjaxError(error);
- }
-}
-
-function clearTexture(pid) {
- const dom = `
- Default (Steve)
-
-
- Slim (Alex)
-
-
- ${trans('general.cape')}
-
- `;
-
- return showModal(dom, trans('user.chooseClearTexture'), 'default', {
- callback: `ajaxClearTexture(${pid})`
- });
-}
-
-async function ajaxClearTexture(pid) {
- $('.modal').each(function () {
- if ($(this).css('display') === 'none') $(this).remove();
- });
-
- const data = { pid: pid };
-
- ['steve', 'alex', 'cape'].forEach(type => {
- data[type] = $(`#clear-${type}`).prop('checked') ? 1 : 0;
- });
-
- if (data['steve'] === 0 && data['alex'] === 0 && data['cape'] === 0) {
- return toastr.warning(trans('user.noClearChoice'));
- }
-
- try {
- const { errno, msg } = await fetch({
- type: 'POST',
- url: url('user/player/texture/clear'),
- dataType: 'json',
- data: data
- });
- swal({ type: errno === 0 ? 'success' : 'error', html: msg });
- $('.modal').modal('hide');
- } catch (error) {
- showAjaxError(error);
- }
-}
-
-async function deletePlayer(pid) {
- try {
- await swal({
- title: trans('user.deletePlayer'),
- text: trans('user.deletePlayerNotice'),
- type: 'warning',
- showCancelButton: true,
- cancelButtonColor: '#3085d6',
- confirmButtonColor: '#d33'
- });
- } catch (error) {
- return;
- }
-
- try {
- const { errno, msg } = await fetch({
- type: 'POST',
- url: url('user/player/delete'),
- dataType: 'json',
- data: { pid: pid }
- });
-
- if (errno === 0) {
- await swal({
- type: 'success',
- html: msg
- });
- $(`tr#${pid}`).remove();
- } else {
- swal({ type: 'warning', html: msg });
- }
- } catch (error) {
- showAjaxError(error);
- }
-}
-
-async function addNewPlayer() {
- try {
- const { errno, msg } = await fetch({
- type: 'POST',
- url: url('user/player/add'),
- dataType: 'json',
- data: { player_name: $('#player_name').val() }
- });
-
- if (errno === 0) {
- await swal({ type: 'success', html: msg });
-
- $('#modal-add-player').modal('hide');
- location.reload();
- } else {
- swal({ type: 'warning', html: msg });
- }
- } catch (error) {
- showAjaxError(error);
- }
-}
-
-if (process.env.NODE_ENV === 'test') {
- module.exports = {
- addNewPlayer,
- clearTexture,
- deletePlayer,
- changePlayerName,
- ajaxClearTexture,
- };
-}
diff --git a/resources/assets/src/js/user/profile.js b/resources/assets/src/js/user/profile.js
deleted file mode 100644
index 99563c17..00000000
--- a/resources/assets/src/js/user/profile.js
+++ /dev/null
@@ -1,180 +0,0 @@
-'use strict';
-
-async function changeNickName() {
- const name = $('#new-nickname').val();
-
- if (! name) {
- return swal({ type: 'error', html: trans('user.emptyNewNickName') });
- }
-
- try {
- await swal({
- text: trans('user.changeNickName', { new_nickname: name }),
- type: 'question',
- showCancelButton: true
- });
- } catch (error) {
- return;
- }
-
- try {
- const { errno, msg } = await fetch({
- type: 'POST',
- url: url('user/profile?action=nickname'),
- dataType: 'json',
- data: { new_nickname: name }
- });
-
- if (errno === 0) {
-
- $('.nickname').each(function () {
- $(this).html(name);
- });
-
- return swal({ type: 'success', html: msg });
- } else {
- return swal({ type: 'warning', html: msg });
- }
- } catch (error) {
- showAjaxError(error);
- }
-}
-
-async function changePassword() {
- const $oldPasswd = $('#password'),
- $newPasswd = $('#new-passwd'),
- $confirmPwd = $('#confirm-pwd');
-
- const password = $oldPasswd.val(),
- newPasswd = $newPasswd.val();
-
- if (password === '') {
- toastr.info(trans('user.emptyPassword'));
- $oldPasswd.focus();
- } else if (newPasswd === '') {
- toastr.info(trans('user.emptyNewPassword'));
- $newPasswd.focus();
- } else if ($confirmPwd.val() === '') {
- toastr.info(trans('auth.emptyConfirmPwd'));
- $confirmPwd.focus();
- } else if (newPasswd !== $confirmPwd.val()) {
- toastr.warning(trans('auth.invalidConfirmPwd'));
- $confirmPwd.focus();
- } else {
- try {
- const { errno, msg } = await fetch({
- type: 'POST',
- url: url('user/profile?action=password'),
- dataType: 'json',
- data: { 'current_password': password, 'new_password': newPasswd }
- });
-
- if (errno === 0) {
- await swal({
- type: 'success',
- text: msg
- });
-
- // Cookies were already deleted by remote server
- return window.location = url('auth/login');
- } else {
- return swal({ type: 'warning', text: msg });
- }
- } catch (error) {
- showAjaxError(error);
- }
- }
-}
-
-$('#new-email').focusin(() => {
- $('#current-password').parent().show();
-}).focusout(debounce(() => {
- const dom = $('#current-password');
-
- if (! dom.is(':focus')) {
- dom.parent().hide();
- }
-}, 10));
-
-async function changeEmail() {
- const newEmail = $('#new-email').val();
-
- if (! newEmail) {
- return swal({ type: 'error', html: trans('user.emptyNewEmail') });
- }
-
- // check valid email address
- if (!/\S+@\S+\.\S+/.test(newEmail)) {
- return swal({ type: 'warning', html: trans('auth.invalidEmail') });
- }
-
- try {
- await swal({
- text: trans('user.changeEmail', { new_email: newEmail }),
- type: 'question',
- showCancelButton: true
- });
- } catch (error) {
- return;
- }
-
- try {
- const { errno, msg } = await fetch({
- type: 'POST',
- url: url('user/profile?action=email'),
- dataType: 'json',
- data: { new_email: newEmail, password: $('#current-password').val() }
- });
-
- if (errno === 0) {
- await swal({
- type: 'success',
- text: msg
- });
-
- return window.location = url('auth/login');
- } else {
- return swal({ type: 'warning', text: msg });
- }
- } catch (error) {
- showAjaxError(error);
- }
-}
-
-async function deleteAccount() {
- const password = $('.modal-body>#password').val();
-
- if (! password) {
- return swal({ type: 'warning', html: trans('user.emptyDeletePassword') });
- }
-
- try {
- const { errno, msg } = await fetch({
- type: 'POST',
- url: url('user/profile?action=delete'),
- dataType: 'json',
- data: { password: password }
- });
-
- if (errno === 0) {
- await swal({
- type: 'success',
- html: msg
- });
- window.location = url('auth/login');
- } else {
- return swal({ type: 'warning', html: msg });
- }
- } catch (error) {
- showAjaxError(error);
- }
-}
-
-if (process.env.NODE_ENV === 'test') {
- module.exports = {
- changeEmail,
- deleteAccount,
- changeNickName,
- changePassword,
- };
-}
diff --git a/resources/assets/src/js/user/sign.js b/resources/assets/src/js/user/sign.js
deleted file mode 100644
index c8ef61ac..00000000
--- a/resources/assets/src/js/user/sign.js
+++ /dev/null
@@ -1,41 +0,0 @@
-async function sign() {
- try {
- const result = await fetch({
- type: 'POST',
- url: url('user/sign'),
- dataType: 'json'
- });
-
- if (result.errno === 0) {
- $('#score').html(result.score);
- const dom = ' ' + trans(
- 'user.signRemainingTime',
- result.remaining_time >= 1
- ? { time: result.remaining_time.toString(), unit: trans('user.timeUnitHour') }
- : { time: (result.remaining_time * 60).toFixed(), unit: trans('user.timeUnitMin') }
- );
-
- $('#sign-button').attr('disabled', 'disabled').html(dom);
-
- if (result.storage.used > 1024) {
- $('#user-storage').html(
- `${Math.round(result.storage.used / 1024)}/ ${Math.round(result.storage.total / 1024)} MB`
- );
- } else {
- $('#user-storage').html(`${Math.round(result.storage.used)}/ ${Math.round(result.storage.total)} KB`);
- }
-
- $('#user-storage-bar').css('width', `${result.storage.percentage}%`);
-
- return swal({ type: 'success', html: result.msg });
- } else {
- toastr.warning(result.msg);
- }
- } catch (error) {
- showAjaxError(error);
- }
-}
-
-if (process.env.NODE_ENV === 'test') {
- module.exports = sign;
-}