Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Search] Inject id and class attr into individual result #3142

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions src/definitions/modules/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@
var
$result = $(this),
$title = $result.find(selector.title).eq(0),
$link = $result.is('a[href]')
? $result
: $result.find('a[href]').eq(0),
$link = $result.is('a[href]') ? $result : $(),
href = $link.attr('href') || false,
target = $link.attr('target') || false,
// title is used for result lookup
Expand Down Expand Up @@ -1459,6 +1457,8 @@
results: 'results', // array of results (standard)
title: 'title', // result title
url: 'url', // result url
id: 'id', // HTML 'id' attribute
classes: 'classes', // Classes specific to each result to add to the HTML 'class' attribute.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should name the property class instead of classes

action: 'action', // "view more" object name
actionText: 'text', // "view more" text
actionURL: 'url', // "view more" url
Expand Down Expand Up @@ -1538,8 +1538,17 @@
html += '<div class="results">';
$.each(category.results, function (index, result) {
html += result[fields.url]
? '<a class="result" href="' + result[fields.url].replace(/"/g, '') + '">'
: '<a class="result">';
? '<a href="' + result[fields.url].replace(/"/g, '') + '" '
: html += '<div ';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed and a breaking change, keep using the anchor tag


html += result[fields.id] !== undefined
? ' id="' + result[fields.id] + '" '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be sanitzed (doubple quotes removed

Suggested change
? ' id="' + result[fields.id] + '" '
? ' id="' + result[fields.id].replace(/"/g, '') + '" '

: '';

html += result[fields.classes] !== undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should rename the fields property to class ins tead of classes

? ' class="result ' + result[fields.classes] + '">'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be sanitized (double quotes removed)

Suggested change
? ' class="result ' + result[fields.classes] + '">'
? ' class="result ' + result[fields.classes].replace(/"/g, '') + '">'

: ' class="result">';

if (result[fields.image] !== undefined) {
html += ''
+ '<div class="image">'
Expand All @@ -1558,7 +1567,10 @@
}
html += ''
+ '</div>';
html += '</a>';

html += result[fields.url]
? '</a>'
: '</div>';
Comment on lines +1570 to +1573
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above and revert. Keep using the anchor tag

});
html += '</div>';
html += ''
Expand Down Expand Up @@ -1591,8 +1603,17 @@
// each result
$.each(response[fields.results], function (index, result) {
html += result[fields.url]
? '<a class="result" href="' + result[fields.url].replace(/"/g, '') + '">'
: '<a class="result">';
? '<a href="' + result[fields.url].replace(/"/g, '') + '" '
: '<div ';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change as existing projects could rely on always assuming an a tag. And an anchor tag without href attribute is still valid HTML


html += result[fields.id] !== undefined
? ' id="' + result[fields.id] + '" '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be sanitized (double quotes removed)

Suggested change
? ' id="' + result[fields.id] + '" '
? ' id="' + result[fields.id].replace(/"/g, '') + '" '

: '';

html += result[fields.classes] !== undefined
Copy link
Member

@lubber-de lubber-de Dec 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should rename the fields property to class instead of classes

? ' class="result ' + result[fields.classes] + '">'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be sanitized (double quotes removed)

: ' class="result">';

if (result[fields.image] !== undefined) {
html += ''
+ '<div class="image">'
Expand All @@ -1611,7 +1632,10 @@
}
html += ''
+ '</div>';
html += '</a>';

html += result[fields.url]
? '</a>'
: '</div>';
Comment on lines +1635 to +1638
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, this should be reverted to always create an achor a tag

});
if (response[fields.action]) {
html += fields.actionURL === false
Expand Down
Loading