From 3d6c60f6f72bdb1415a2f1d66b5d1dbce3545802 Mon Sep 17 00:00:00 2001 From: Misode Date: Thu, 24 Oct 2019 10:06:53 +0200 Subject: [PATCH] Add help to other field types --- custom.css | 2 +- locales/en.json | 3 +++ schemas/1.14.json | 3 ++- view.js | 27 ++++++++++++++++++++++++++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/custom.css b/custom.css index ef2eef47..eb686555 100644 --- a/custom.css +++ b/custom.css @@ -1,5 +1,5 @@ -.btn-circle { +.help-tooltip { width: 30px; height: 30px; padding: 6px 0px; diff --git a/locales/en.json b/locales/en.json index 12cbc02c..73a6e2b2 100644 --- a/locales/en.json +++ b/locales/en.json @@ -11,6 +11,9 @@ "group": "Executes all child entries when own conditions pass", "dynamic": "Gets block specific drops" } + }, + "$pool": { + "rolls": "The amount of entries that are randomly chosen" } }, "$condition": { diff --git a/schemas/1.14.json b/schemas/1.14.json index 0a3d6079..6c4b418a 100644 --- a/schemas/1.14.json +++ b/schemas/1.14.json @@ -33,7 +33,8 @@ { "id": "rolls", "type": "random", - "translate": "$pool.rolls" + "translate": "$pool.rolls", + "help": true }, { "id": "bonus_rolls", diff --git a/view.js b/view.js index 3b955ac2..06850e59 100644 --- a/view.js +++ b/view.js @@ -2,6 +2,13 @@ let structure; let components; let collections; +i18next.on('initialized', () => { + $('[data-help]').each(function() { + console.log('ahhh'); + $(this).tooltip({title: i18next.t('$help.' + $(this).attr('data-help'))}); + }); +}); + changeVersion('1.14'); function changeVersion(version) { $.getJSON('schemas/' + version + '.json', json => { @@ -95,6 +102,9 @@ function generateString(data, struct) { $el.attr('data-index', struct.id); $el.find('[data-name]').attr('data-i18n', struct.translate); $el.find('input').val(data); + if (struct.help) { + $el.append(generateTooltip(struct.translate)); + } return {out: data, component: $el}; } @@ -107,6 +117,9 @@ function generateBoolean(data, struct) { } else if (data === false) { $el.find('[value="false"]').addClass('active'); } + if (struct.help) { + $el.append(generateTooltip(struct.translate)); + } return {out: data, component: $el}; } @@ -128,6 +141,9 @@ function generateRandom(data, struct) { $el.find('.exact').removeClass('d-none'); $el.find('.exact').val(data); } + if (struct.help) { + $el.append(generateTooltip(struct.translate)); + } return {out: data, component: $el}; } @@ -143,6 +159,9 @@ function generateRange(data, struct) { $el.find('.exact').removeClass('d-none'); $el.find('.exact').val(data); } + if (struct.help) { + $el.append(generateTooltip(struct.translate)); + } return {out: data, component: $el}; } @@ -154,6 +173,9 @@ function generateBoundary(data, struct) { $el.find('.range.min').val(data.min); $el.find('.range.max').val(data.max); } + if (struct.help) { + $el.append(generateTooltip(struct.translate)); + } return {out: data, component: $el}; } @@ -258,6 +280,9 @@ function generateJson(data, struct) { data = JSON.stringify(data); } $el.find('textarea').val(data).keydown(e => preventNewline(e)); + if (struct.help) { + $el.append(generateTooltip(struct.translate)); + } return {out: data, component: $el}; } @@ -436,7 +461,7 @@ function generateField(data, field, parent) { } function generateTooltip(str) { - let $el = $(''); + let $el = $(''); $el.tooltip({title: i18next.t('$help.' + str)}); return $el; }