Skip to content

Commit f5cb878

Browse files
committed
Fixes HugoFara#170, after creation multi-word was displayed two times.
1 parent 09983bc commit f5cb878

5 files changed

Lines changed: 40 additions & 31 deletions

File tree

‎docs/CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ Solves [#129](https://github.com/HugoFara/lwt/issues/129), thanks to the help of
5151
* Fixes on multi-words:
5252
* Tooltip was not properly saved ([#170](https://github.com/HugoFara/lwt/pull/170)).
5353
* Translation may be escaped two times ([#170](https://github.com/HugoFara/lwt/pull/170)).
54+
* Fixes [#170](https://github.com/HugoFara/lwt/pull/170): on creation,
55+
multi-word was always displayed before the text it encompasses,
56+
without removing this text.
5457
* Tootltip title was not properly saved, normally without incidence on user display.
5558
* Parsing Japanese texts with MeCab was creating warnings when the text was not finishing by a punctation mark.
5659
* Multi-words were not saved with MeCab parsing on Japanese.

‎docs/info.html‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,9 @@ <h4>Fixed</h4>
22392239
<ul>
22402240
<li>Tooltip was not properly saved (<a href="https://github.com/HugoFara/lwt/pull/170">#170</a>).</li>
22412241
<li>Translation may be escaped two times (<a href="https://github.com/HugoFara/lwt/pull/170">#170</a>).</li>
2242+
<li>Fixes <a href="https://github.com/HugoFara/lwt/pull/170">#170</a>: on creation,
2243+
multi-word was always displayed before the text it encompasses,
2244+
without removing this text.</li>
22422245
<li>Tootltip title was not properly saved, normally without incidence on user display.</li>
22432246
</ul>
22442247
</li>

‎inc/session_utility.php‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4371,20 +4371,21 @@ function insert_standard_expression($textlc, $lid, $wid, $len, $mode): array
43714371
*/
43724372
function new_expression_interactable($hex, $appendtext, $sid, $len): void
43734373
{
4374-
$showAll = getSettingZeroOrOne('showallwords', 1) ? "m" : "";
4374+
$showAll = (bool) getSettingZeroOrOne('showallwords', 1);
4375+
$showType = $showAll ? "m" : '';
43754376

43764377
?>
43774378
<script type="text/javascript">
43784379
newExpressionInteractable(
43794380
<?php echo json_encode($appendtext); ?>,
4380-
' class="click mword <?php echo $showAll; ?>wsty TERM<?php echo $hex; ?> word' +
4381+
' class="click mword <?php echo $showType; ?>wsty TERM<?php echo $hex; ?> word' +
43814382
woid + ' status' + status + '" data_trans="' + trans + '" data_rom="' +
43824383
roman + '" data_code="<?php echo $len; ?>" data_status="' +
43834384
status + '" data_wid="' + woid +
43844385
'" title="' + title + '"' ,
43854386
<?php echo json_encode($len); ?>,
43864387
<?php echo json_encode($hex); ?>,
4387-
<?php echo json_encode(!$showAll); ?>
4388+
<?php echo json_encode($showAll); ?>
43884389
);
43894390
</script>
43904391
<?php
@@ -4409,15 +4410,16 @@ function new_expression_interactable($hex, $appendtext, $sid, $len): void
44094410
function new_expression_interactable2($hex, $appendtext, $wid, $len): void
44104411
{
44114412
global $tbpref;
4412-
$showAll = (bool)getSettingZeroOrOne('showallwords', 1) ? "m" : "";
4413+
$showAll = (bool)getSettingZeroOrOne('showallwords', 1);
4414+
$showType = $showAll ? "m" : "";
44134415

44144416
$sql = "SELECT * FROM {$tbpref}words WHERE WoID=$wid";
44154417
$res = do_mysqli_query($sql);
44164418

44174419
$record = mysqli_fetch_assoc($res);
44184420

44194421
$attrs = array(
4420-
"class" => "click mword {$showAll}wsty TERM$hex word$wid status" .
4422+
"class" => "click mword {$showType}wsty TERM$hex word$wid status" .
44214423
$record["WoStatus"],
44224424
"data_trans" => $record["WoTranslation"],
44234425
"data_rom" => $record["WoRomanization"],
@@ -4451,7 +4453,7 @@ function new_expression_interactable2($hex, $appendtext, $wid, $len): void
44514453
attrs,
44524454
<?php echo json_encode($len); ?>,
44534455
<?php echo json_encode($hex); ?>,
4454-
<?php echo json_encode(!$showAll); ?>
4456+
<?php echo json_encode($showAll); ?>
44554457
);
44564458
</script>
44574459
<?php

‎js/pgm.js‎

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/js/user_interactions.js‎

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ function quickMenuRedirection(value) {
3232
* @param {string} attrs A group of attributes to add
3333
* @param {int} length Number of words, should correspond to WoWordCount
3434
* @param {string} hex Lowercase formatted version of the text.
35-
* @param {bool} showallwords Set to false if a group if multi-words should be
36-
* displayed as index
35+
* @param {bool} showallwords true: multi-word is a superscript, show mw index + words
36+
* false: only show the multiword, hide the words
3737
* @returns {undefined}
3838
*
3939
* @since 2.5.2-fork Don't hide multi-word index when inserting new multi-word.
@@ -43,30 +43,27 @@ function newExpressionInteractable(text, attrs, length, hex, showallwords) {
4343
const context = window.parent.document;
4444
// From each multi-word group
4545
for (key in text) {
46-
// Select words that are not hidden
47-
const words = $('span[id^="ID-'+ key +'-"]', context).not(".hide");
48-
// Mark necessary page if these words are displayed
49-
const text_refresh = (
50-
words.attr('data_code') !== undefined
51-
&& words.attr('data_code') <= length
52-
);
46+
// Remove any previous multi-word of same length + same position
5347
$('#ID-' + key + '-' + length, context).remove();
54-
// From text, select first word of multi-word group
55-
let word_selector = '';
48+
49+
// From text, select the first mword smaller than this one, or the first
50+
// word in this mword
51+
let next_term_key = '';
5652
for (let j = length - 1; j > 0; j--) {
57-
if (j==1)
58-
word_selector = '#ID-' + key + '-1';
53+
if (j == 1)
54+
next_term_key = '#ID-' + key + '-1';
5955
if ($('#ID-' + key + '-' + j, context).length) {
60-
word_selector = '#ID-' + key + '-' + j;
56+
next_term_key = '#ID-' + key + '-' + j;
6157
break;
6258
}
6359
}
6460
// Add the multi-word marker before
65-
$(word_selector, context)
61+
$(next_term_key, context)
6662
.before(
6763
'<span id="ID-' + key + '-' + length + '"' + attrs + '>' + text[key] +
6864
'</span>'
6965
);
66+
7067
// Change multi-word properties
7168
const multi_word = $('#ID-' + key + '-' + length, context);
7269
multi_word.addClass('order' + key).attr('data_order', key);
@@ -82,14 +79,16 @@ function newExpressionInteractable(text, attrs, length, hex, showallwords) {
8279
const pos = $('#ID-' + key + '-1', context).attr('data_pos');
8380
multi_word.attr('data_text', txt).attr('data_pos', pos);
8481

85-
// Show/hide multi-word on need
86-
if (!showallwords) {
87-
if (text_refresh) {
88-
// refresh_text(multi_word); // replace by JS style
89-
} else {
90-
multi_word.addClass('hide');
91-
}
82+
// Hide the next words if necessary
83+
if (showallwords) {
84+
return;
85+
}
86+
const next_words = [];
87+
// TODO: overlapsing multi-words
88+
for (let i = 0; i < length * 2 - 1; i++) {
89+
next_words.push('span[id="ID-' + (parseInt(key) + i) + '-1"]');
9290
}
91+
$(next_words.join(','), context).hide();
9392
}
9493
}
9594

0 commit comments

Comments
 (0)