From d30b2cb4c6c633157f1a37ad9b1317be8088651f Mon Sep 17 00:00:00 2001 From: printempw Date: Tue, 31 Jul 2018 11:50:36 +0800 Subject: [PATCH] Add quick-apply button to skinlib.show page --- resources/assets/src/js/skinlib/operations.js | 11 ++++++----- resources/assets/src/js/user/closet.js | 11 ++++++++++- resources/lang/en/skinlib.yml | 1 + resources/lang/zh_CN/skinlib.yml | 1 + resources/views/skinlib/show.tpl | 6 ++++++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/resources/assets/src/js/skinlib/operations.js b/resources/assets/src/js/skinlib/operations.js index 0f491fa4..daca0429 100644 --- a/resources/assets/src/js/skinlib/operations.js +++ b/resources/assets/src/js/skinlib/operations.js @@ -181,16 +181,17 @@ async function changeTextureModel(tid, oldModel) { */ function updateTextureStatus(tid, action) { const likes = parseInt($('#likes').html()) + (action === 'add' ? 1 : -1); - action = (action === 'add') ? 'removeFromCloset' : 'addToCloset'; + const buttonAction = (action === 'add') ? 'removeFromCloset' : 'addToCloset'; $(`a[tid=${tid}]`) - .attr('onclick', `${action}(${tid});`) - .attr('title', trans(`skinlib.${action}`)) + .attr('onclick', `${buttonAction}(${tid});`) + .attr('title', trans(`skinlib.${buttonAction}`)) .toggleClass('liked'); $(`#${tid}`) - .attr('onclick', `${action}(${tid});`) - .html(trans(`skinlib.${action}`)); + .attr('onclick', `${buttonAction}(${tid});`) + .html(trans(`skinlib.${buttonAction}`)); $('#likes').html(likes); + $('#quick-apply').toggle(action === 'add'); } $(document).on('click', '.private-label', async function () { diff --git a/resources/assets/src/js/user/closet.js b/resources/assets/src/js/user/closet.js index e82bc7b5..798b29ae 100644 --- a/resources/assets/src/js/user/closet.js +++ b/resources/assets/src/js/user/closet.js @@ -2,7 +2,16 @@ 'use strict'; -$(document).ready(initCloset); +$(document).ready(async () => { + await initCloset(); + + const tid = getQueryString('tid'); + + // Select closet item if texture id is specified by query string + if (tid !== undefined) { + $(`[tid=${tid}]`).children('.item-body').click(); + } +}); $('body').on('click', '.item-body', async function () { $('.item-selected').parent().removeClass('item-selected'); diff --git a/resources/lang/en/skinlib.yml b/resources/lang/en/skinlib.yml index da975fee..e1b4cd64 100644 --- a/resources/lang/en/skinlib.yml +++ b/resources/lang/en/skinlib.yml @@ -24,6 +24,7 @@ item: steve: (Steve) alex: (Alex) cape: (Cape) + apply: Quick Apply remove-from-closet: Remove from closet add-to-closet: Add to closet anonymous: Please login first diff --git a/resources/lang/zh_CN/skinlib.yml b/resources/lang/zh_CN/skinlib.yml index 7097b92b..2d637344 100644 --- a/resources/lang/zh_CN/skinlib.yml +++ b/resources/lang/zh_CN/skinlib.yml @@ -24,6 +24,7 @@ item: steve: (Steve) alex: (Alex) cape: (披风) + apply: 立即使用 remove-from-closet: 从衣柜中移除 add-to-closet: 添加至衣柜 anonymous: 请先登录 diff --git a/resources/views/skinlib/show.tpl b/resources/views/skinlib/show.tpl index e7b0c5f7..04c9f640 100644 --- a/resources/views/skinlib/show.tpl +++ b/resources/views/skinlib/show.tpl @@ -25,6 +25,12 @@ @else + {{ trans('skinlib.item.apply') }} + @if ($user->getCloset()->has($texture->tid)) {{ trans('skinlib.item.remove-from-closet') }} @else