From da3984988543de38eb92dd3497ad441ee7704d34 Mon Sep 17 00:00:00 2001 From: robby1066 Date: Tue, 26 Dec 2023 13:46:55 -0800 Subject: [PATCH 1/7] progress on #47 changing attr tid to data-text-id (although I can't see a place where the attribute is actually used) --- lute/templates/read/textitem.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lute/templates/read/textitem.html b/lute/templates/read/textitem.html index 35efe457..5eec6e73 100644 --- a/lute/templates/read/textitem.html +++ b/lute/templates/read/textitem.html @@ -1,7 +1,7 @@ {# Render a read.render.renderable_calculator.TextItem #} Date: Tue, 26 Dec 2023 13:50:04 -0800 Subject: [PATCH 2/7] progress on #47 changing attr lid to data-lang-id --- lute/static/js/lute.js | 4 ++-- lute/templates/read/textitem.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lute/static/js/lute.js b/lute/static/js/lute.js index f8dd8261..b8298f0a 100644 --- a/lute/static/js/lute.js +++ b/lute/static/js/lute.js @@ -105,7 +105,7 @@ let tooltip_textitem_hover_content = function (el, setContent) { function showEditFrame(el, extra_args = {}) { - const lid = parseInt(el.attr('lid')); + const lid = parseInt(el.data('lang-id')); let text = extra_args.textparts ?? [ el.attr('data_text') ]; const sendtext = text.join(''); @@ -596,7 +596,7 @@ function update_status_for_elements(new_status, elements) { if (elements.length == 0) return; const firstel = $(elements[0]); - const langid = firstel.attr('lid'); + const langid = firstel.data('lang-id'); const texts = elements.map(el => $(el).text()); data = JSON.stringify({ diff --git a/lute/templates/read/textitem.html b/lute/templates/read/textitem.html index 5eec6e73..ece3dcbc 100644 --- a/lute/templates/read/textitem.html +++ b/lute/templates/read/textitem.html @@ -2,7 +2,7 @@ Date: Tue, 26 Dec 2023 13:56:26 -0800 Subject: [PATCH 3/7] progress on #47 changing attrs paraid and seid to data-paragraph-id and data-sentence-id --- lute/static/js/lute.js | 11 +++-------- lute/templates/read/textitem.html | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lute/static/js/lute.js b/lute/static/js/lute.js index b8298f0a..3ca17492 100644 --- a/lute/static/js/lute.js +++ b/lute/static/js/lute.js @@ -329,15 +329,10 @@ let get_textitems_spans = function(e) { if (w == null) return null; - let attr_name = 'seid'; - let attr_value = w.attr('seid'); + const attr_name = !e.shiftKey ? 'sentence-id' : 'paragraph-id'; + const attr_value = w.data(attr_name); - if (e.shiftKey) { - attr_name = 'paraid'; - attr_value = w.attr('paraid'); - } - - return $('span.textitem').toArray().filter(x => x.getAttribute(attr_name) === attr_value); + return $(`span.textitem[data-${attr_name}="${attr_value}"]`).toArray(); }; /** Copy the text of the textitemspans to the clipboard, and add a diff --git a/lute/templates/read/textitem.html b/lute/templates/read/textitem.html index ece3dcbc..dc0a8bce 100644 --- a/lute/templates/read/textitem.html +++ b/lute/templates/read/textitem.html @@ -3,8 +3,8 @@ class="{{ item.html_class_string }}" data-text-id="{{ item.text_id }}" data-lang-id="{{ item.lang_id }}" - paraid="{{ item.para_id }}" - seid="{{ item.se_id }}" + data-paragraph-id="{{ item.para_id }}" + data-sentence-id="{{ item.se_id }}" data_text="{{ item.text }}" data_status_class="{{ item.status_class }}" data_order="{{ item.order }}" From 56b0482093c87c2ac47d31c081d104a7d308de2d Mon Sep 17 00:00:00 2001 From: robby1066 Date: Tue, 26 Dec 2023 13:59:06 -0800 Subject: [PATCH 4/7] progress on #47 changing attr data_text to data-text --- lute/static/js/lute.js | 2 +- lute/templates/read/textitem.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lute/static/js/lute.js b/lute/static/js/lute.js index 3ca17492..4c6ade2c 100644 --- a/lute/static/js/lute.js +++ b/lute/static/js/lute.js @@ -107,7 +107,7 @@ let tooltip_textitem_hover_content = function (el, setContent) { function showEditFrame(el, extra_args = {}) { const lid = parseInt(el.data('lang-id')); - let text = extra_args.textparts ?? [ el.attr('data_text') ]; + let text = extra_args.textparts ?? [ el.data('text') ]; const sendtext = text.join(''); let extras = Object.entries(extra_args). diff --git a/lute/templates/read/textitem.html b/lute/templates/read/textitem.html index dc0a8bce..3e4f69bd 100644 --- a/lute/templates/read/textitem.html +++ b/lute/templates/read/textitem.html @@ -5,7 +5,7 @@ data-lang-id="{{ item.lang_id }}" data-paragraph-id="{{ item.para_id }}" data-sentence-id="{{ item.se_id }}" - data_text="{{ item.text }}" + data-text="{{ item.text }}" data_status_class="{{ item.status_class }}" data_order="{{ item.order }}" {% if item.wo_id is not none %} From 62fc6a932eaa367d9230b2bd8eb769381b3726e4 Mon Sep 17 00:00:00 2001 From: robby1066 Date: Tue, 26 Dec 2023 14:06:45 -0800 Subject: [PATCH 5/7] progress on #47 changing attr data_order to data-order --- lute/static/js/lute.js | 12 ++++++------ lute/templates/read/textitem.html | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lute/static/js/lute.js b/lute/static/js/lute.js index 4c6ade2c..295a98ea 100644 --- a/lute/static/js/lute.js +++ b/lute/static/js/lute.js @@ -122,7 +122,7 @@ function showEditFrame(el, extra_args = {}) { let save_curr_data_order = function(el) { - LUTE_CURR_TERM_DATA_ORDER = parseInt(el.attr('data_order')); + LUTE_CURR_TERM_DATA_ORDER = parseInt(el.data('order')); } @@ -214,8 +214,8 @@ function select_started(e) { } let get_selected_in_range = function(start_el, end_el, selector) { - const first = parseInt(start_el.attr('data_order')) - const last = parseInt(end_el.attr('data_order')); + const first = parseInt(start_el.data('order')) + const last = parseInt(end_el.data('order')); let startord = first; let endord = last; @@ -226,7 +226,7 @@ let get_selected_in_range = function(start_el, end_el, selector) { } const selected = $(selector).filter(function() { - const ord = $(this).attr("data_order"); + const ord = $(this).data("order"); return ord >= startord && ord <= endord; }); return selected; @@ -301,7 +301,7 @@ var maxindex = null; function load_reading_pane_globals() { words = $('span.word').sort(function(a, b) { - return $(a).attr('data_order') - $(b).attr('data_order'); + return $(a).data('order') - $(b).data('order'); }); // console.log('have ' + words.size() + ' words'); maxindex = words.size() - 1; @@ -310,7 +310,7 @@ function load_reading_pane_globals() { $(document).ready(load_reading_pane_globals); let current_word_index = function() { - const i = words.toArray().findIndex(x => parseInt(x.getAttribute('data_order')) === LUTE_CURR_TERM_DATA_ORDER); + const i = words.toArray().findIndex(x => parseInt(x.dataset.order) === LUTE_CURR_TERM_DATA_ORDER); // console.log(`found index = ${i}`); return i; }; diff --git a/lute/templates/read/textitem.html b/lute/templates/read/textitem.html index 3e4f69bd..7b06a1a8 100644 --- a/lute/templates/read/textitem.html +++ b/lute/templates/read/textitem.html @@ -7,7 +7,7 @@ data-sentence-id="{{ item.se_id }}" data-text="{{ item.text }}" data_status_class="{{ item.status_class }}" - data_order="{{ item.order }}" + data-order="{{ item.order }}" {% if item.wo_id is not none %} data_wid="{{ item.wo_id }}" {% endif %}>{{ item.html_display_text | safe }} From dc4b4b4a936fb61896b4cd3851aa7a87ce29331a Mon Sep 17 00:00:00 2001 From: robby1066 Date: Tue, 26 Dec 2023 14:14:29 -0800 Subject: [PATCH 6/7] progress on #47 changing attr data_status_class to data-status-class --- lute/static/js/lute.js | 14 +++++++------- lute/templates/read/textitem.html | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lute/static/js/lute.js b/lute/static/js/lute.js index 295a98ea..6ec2f01a 100644 --- a/lute/static/js/lute.js +++ b/lute/static/js/lute.js @@ -141,7 +141,7 @@ let _show_highlights = function() { } /** - * Terms have data_status_class attribute. If highlights should be shown, + * Terms have data-status-class attribute. If highlights should be shown, * then add that value to the actual span. */ function add_status_classes() { if (!_show_highlights()) @@ -151,9 +151,9 @@ function add_status_classes() { }); } -/** Add the data_status_class to the term's classes. */ +/** Add the data-status-class to the term's classes. */ let apply_status_class = function(el) { - el.addClass(el.attr("data_status_class")); + el.addClass(el.data("status-class")); } /** Remove the status from elements, if not showing highlights. */ @@ -164,7 +164,7 @@ let remove_status_highlights = function() { } $('span.word').toArray().forEach(function (m) { el = $(m); - el.removeClass(el.attr("data_status_class")); + el.removeClass(el.data("status-class")); }); } @@ -394,7 +394,7 @@ let find_non_Ign_or_Wkn = function(currindex, shiftby) { let newindex = currindex + shiftby; while (newindex >= 0 && newindex <= maxindex) { const nextword = words.eq(newindex); - const st = nextword.attr('data_status_class'); + const st = nextword.data('status-class'); if (st != 'status99' && st != 'status98') { break; } @@ -558,7 +558,7 @@ function update_selected_statuses(newStatus, elements) { matches.forEach(function (m) { $(m).removeClass('status98 status99 status0 status1 status2 status3 status4 status5 shiftClicked') .addClass(newClass) - .attr('data_status_class',`${newClass}`); + .attr('data-status-class',`${newClass}`); }); }; $(elements).each(update_data_status_class) @@ -650,7 +650,7 @@ function increment_status_for_selected_elements(e, shiftBy) { let payloads = {}; elements.forEach((element) => { - let statusClass = element.getAttribute('data_status_class'); + let statusClass = element.dataset.statusClass; if (!statusClass || !validStatuses.includes(statusClass)) return; diff --git a/lute/templates/read/textitem.html b/lute/templates/read/textitem.html index 7b06a1a8..2697acca 100644 --- a/lute/templates/read/textitem.html +++ b/lute/templates/read/textitem.html @@ -6,7 +6,7 @@ data-paragraph-id="{{ item.para_id }}" data-sentence-id="{{ item.se_id }}" data-text="{{ item.text }}" - data_status_class="{{ item.status_class }}" + data-status-class="{{ item.status_class }}" data-order="{{ item.order }}" {% if item.wo_id is not none %} data_wid="{{ item.wo_id }}" From ed866f013c63ab8f598ae832e17015ffaf7f8057 Mon Sep 17 00:00:00 2001 From: robby1066 Date: Tue, 26 Dec 2023 14:20:08 -0800 Subject: [PATCH 7/7] finishes #47 changing attrs on textitems to html5 data-* attributes --- lute/static/js/lute.js | 3 +-- lute/templates/read/textitem.html | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lute/static/js/lute.js b/lute/static/js/lute.js index 6ec2f01a..19a9cd14 100644 --- a/lute/static/js/lute.js +++ b/lute/static/js/lute.js @@ -93,7 +93,7 @@ function prepareTextInteractions(textid) { * Build the html content for jquery-ui tooltip. */ let tooltip_textitem_hover_content = function (el, setContent) { - elid = parseInt(el.attr('data_wid')); + elid = parseInt(el.data('wid')); $.ajax({ url: `/read/termpopup/${elid}`, type: 'get', @@ -419,7 +419,6 @@ let show_translation = function(e) { if (tis == null) return; const sentence = tis.map(s => $(s).text()).join(''); - // console.log(sentence); const userdict = $('#translateURL').text(); if (userdict == null || userdict == '') diff --git a/lute/templates/read/textitem.html b/lute/templates/read/textitem.html index 2697acca..735e1f51 100644 --- a/lute/templates/read/textitem.html +++ b/lute/templates/read/textitem.html @@ -9,5 +9,5 @@ data-status-class="{{ item.status_class }}" data-order="{{ item.order }}" {% if item.wo_id is not none %} - data_wid="{{ item.wo_id }}" + data-wid="{{ item.wo_id }}" {% endif %}>{{ item.html_display_text | safe }}