Skip to content

Commit 030482c

Browse files
authored
Merge pull request #210 from ufal/add-select-mode
Add select mode
2 parents fdce11e + 991a6a6 commit 030482c

File tree

5 files changed

+49
-14
lines changed

5 files changed

+49
-14
lines changed

factgenie/static/css/custom.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,13 @@ a:hover {
10361036
user-select: none;
10371037
}
10381038

1039+
.annotatable-paragraph.select-mode-enabled {
1040+
-webkit-user-select: text;
1041+
-moz-user-select: text;
1042+
-ms-user-select: text;
1043+
user-select: text;
1044+
}
1045+
10391046
.whitespace {
10401047
display: inline;
10411048
}

factgenie/static/js/annotate.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,12 @@ $(".btn-eraser").change(function () {
325325
}
326326
});
327327

328+
$(".btn-select").change(function () {
329+
if (this.checked) {
330+
spanAnnotator.setCurrentAnnotationType(-2);
331+
}
332+
});
333+
328334
$('.btn-check').on('change', function () {
329335
$('.btn-check').each(function () {
330336
const label = $(`label[for=${this.id}]`);

factgenie/static/js/span-annotator.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,25 @@ class SpanAnnotator {
2727
// make sure that type is integer
2828
this.currentType = parseInt(type);
2929

30-
// Get all annotatable paragraphs
31-
const paragraphs = $('.annotate-box');
32-
33-
if (type === -1) {
30+
// Get all annotatable paragraph boxes
31+
const paragraphBoxes = $('.annotate-box');
32+
const paragraphs = $('.annotatable-paragraph');
33+
34+
if (type === -2) {
35+
// Select mode - use text cursor
36+
paragraphs.addClass('select-mode-enabled');
37+
paragraphBoxes.css('cursor', 'text');
38+
} else if (type === -1) {
39+
paragraphs.removeClass('select-mode-enabled');
3440
// Eraser mode - use eraser cursor
35-
paragraphs.css('cursor', 'pointer');
41+
paragraphBoxes.css('cursor', 'pointer');
3642
} else if (type != null) {
43+
paragraphs.removeClass('select-mode-enabled');
3744
// Annotation mode - use colored brush cursor based on category
3845
const color = this.annotationTypes[type]?.color;
3946
if (color) {
4047
// Create colored cursor style
41-
paragraphs.css({
48+
paragraphBoxes.css({
4249
'cursor': `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='25' height='25' viewBox='0 0 328.862 328.862'%3E%3Cg%3E%3Cpath fill='${encodeURIComponent(color)}' d='M251.217,195.25L56.286,69.063c-4.609-2.984-10.48-3.21-15.308-0.591c-4.826,2.62-7.835,7.667-7.844,13.158l-0.375,232.206c-0.01,6.371,4.006,12.054,10.016,14.172c1.633,0.576,3.315,0.854,4.981,0.854c4.464,0,8.802-1.997,11.704-5.617l71.455-89.101l113.645-11.378c6.34-0.635,11.587-5.206,13.085-11.398C259.143,205.176,256.566,198.712,251.217,195.25z'/%3E%3C/g%3E%3C/svg%3E") 7 7, pointer`
4350
});
4451
}
@@ -164,14 +171,22 @@ class SpanAnnotator {
164171
const $element = $elementPar.parent();
165172

166173
$element.on('selectstart', (e) => {
167-
e.preventDefault();
174+
// Only prevent selection when not in select mode
175+
if (this.currentType !== -2) {
176+
e.preventDefault();
177+
}
168178
});
169179

170180
$element.on('contextmenu', (e) => {
171181
e.preventDefault();
172182
});
173183

174184
$element.on('mousedown', (e) => {
185+
// Skip annotation logic in select mode
186+
if (this.currentType === -2) {
187+
return;
188+
}
189+
175190
if (e.button === 2) { // Right click
176191
const span = this._findClosestSpan(objectId, e.clientX, e.clientY);
177192
if (span) {

factgenie/templates/crowdsourcing/annotate_body.html

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,18 @@ <h2 class="accordion-header">
6767
{{ category.name }}
6868
</label>
6969
{% endfor %}
70-
<input type="radio" class="btn-check btn-outline-secondary btn-eraser" name="btnradio"
71-
id="btnradioeraser" autocomplete="off" data-cat-idx="-1">
72-
<label class="btn btn-err-cat-label ms-auto" for="btnradioeraser" style="background-color: #FFF; color: #000 !important;">
73-
Erase mode
74-
</label>
70+
<div class="ms-auto">
71+
<input type="radio" class="btn-check btn-outline-secondary btn-select" name="btnradio"
72+
id="btnradioselect" autocomplete="off" data-cat-idx="-2">
73+
<label class="btn btn-err-cat-label" for="btnradioselect" style="background-color: #FFF; color: #000 !important;">
74+
<i class="fa fa-mouse-pointer" aria-hidden="true"></i> Select mode
75+
</label>
76+
<input type="radio" class="btn-check btn-outline-secondary btn-eraser" name="btnradio"
77+
id="btnradioeraser" autocomplete="off" data-cat-idx="-1">
78+
<label class="btn btn-err-cat-label" for="btnradioeraser" style="background-color: #FFF; color: #000 !important;">
79+
<i class="fa fa-eraser" aria-hidden="true"></i> Erase mode
80+
</label>
81+
</div>
7582
</div>
7683
</div>
7784
<div id='text-type-info' class='mt-3'>Drag your mouse over the text to highlight the span:

factgenie/templates/pages/app_config.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ <h5>Password protection</h5>
3939
<div class="form-group mt-3">
4040
<label for="lock_view_pages">Include view pages in password protection</label>
4141
<div class="mb-2">
42-
<small class="form-text text-muted">If disable, the Browse and Analyze pages will not require login even
42+
<small class="form-text text-muted">If disabled, the Browse and Analyze pages will not require login even
4343
when login is active. Useful for publishing results collected with factgenie.</small>
4444
</div>
4545
<div class="form-check form-switch">
@@ -117,7 +117,7 @@ <h5>API Keys</h5>
117117
<div class="form-group mt-3">
118118
<label>OpenAI</label>
119119
<div class="mb-2">
120-
<small class="form-text text-muted">API key for OpenAI models (GPT-3, GPT-4, etc.)</small>
120+
<small class="form-text text-muted">API key for OpenAI models</small>
121121
</div>
122122
<input type="password" class="form-control" id="openai_api_key" name="openai_api_key"
123123
value="{{ app_config.api_keys.OPENAI_API_KEY }}">

0 commit comments

Comments
 (0)