Skip to content

Commit

Permalink
Merge branch 'feature/triage-count-bytes-selection'
Browse files Browse the repository at this point in the history
  • Loading branch information
albertoleoncio committed Dec 19, 2023
1 parent a40750e commit 71d3b5e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
37 changes: 35 additions & 2 deletions bin/triage.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,42 @@ function movePosition(){
}
}

function getSelectedText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type !== "Control") {
text = document.selection.createRange().text;
}
return text;
}

function countBytes(text) {
// Count the number of bytes using the TextEncoder API
var encoder = new TextEncoder();
var bytes = encoder.encode(text);
return bytes.length;
}

function updateTooltip() {
var selectedText = getSelectedText();
var byteCount = countBytes(selectedText);
var tooltip = document.getElementById("tooltip");

if (byteCount > 0) {
tooltip.parentElement.style.visibility = "visible";
tooltip.innerHTML = "<?=§('triage-counter')?>: " + byteCount;
} else {
tooltip.parentElement.style.visibility = "hidden";
}
}

var domReady = function(callback) {
document.readyState === "interactive" || document.readyState === "complete" ? callback() : document.addEventListener("DOMContentLoaded", callback);
};
domReady(function() {
movePosition()
movePosition();
document.getElementById("text-container").addEventListener("mouseup", updateTooltip);
});

window.onresize = function(event) {
Expand Down Expand Up @@ -712,7 +742,10 @@ class="w3-button w3-red w3-leftbar w3-rightbar w3-border-light-grey w3-block"
<?=htmlspecialchars($output['compare']['tocomment']??'')?>
</div>
</div>
<div class="w3-container">
<div class="tooltip w3-button w3-orange" style="visibility: hidden;">
<span class="tooltiptext" id="tooltip"><?=§('triage-counter')?>: 0</span>
</div>
<div class="w3-container" id="text-container">
<h3><?=§('triage-differential')?></h3>
<table
role="presentation"
Expand Down
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
"triage-onlycat": "Mere categorization",
"triage-onlytag": "Mere insertion of maintenance marks",
"triage-outreach": "Outreach Dashboard",
"triage-counter": "Bytes in selected text",
"manage-invalidcode": "Error: Invalid internal code!",
"manage-alreadyexist": "Error: Tables already exist!",
"manage-creationerror": "Error: Unable to create tables!",
Expand Down
1 change: 1 addition & 0 deletions translations/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
"triage-images": "Maximum number of points accepted by each participant in each article.\n\nParameters:\n* $1: number of points",
"triage-indef": "{{Identical|Undefined}}",
"triage-noimages": "{{Identical|Disabled}}",
"triage-counter": "Label for the byte counter referring to the text of an edition selected by the user",
"triage-list": "Name of the tool page that redirects the evaluator to the official list of articles on the wiki.",
"triage-cat": "Name of the page of the tool that redirects the contest page categorization system. Corresponds a category on the wiki or a [[:m:PetScan|PetScan search]].",
"triage-differential": "Title of the section where the changes between two revisions of a page are displayed.",
Expand Down

0 comments on commit 71d3b5e

Please sign in to comment.