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

Conversation

dreaming-augustin
Copy link
Contributor

Give much more flexibility on the type of content and theming possibilities for each individual search result.

We could already manipulate the response received by the Search API:

onResponse: function(original_response) {
    var response = {
       results : {}
    };
    $.each(original_response.results, function(index, item) {
          // Manipulate each item.
          // Possibly add item.id
         // Possibly add item.classes
    }
    return response;
}

The problem is that we couldn't inject the id and class attributes to each individual item rendered by the Search module.

Now, depending on the status of each response, the status potentially reflecting a given website's logic and needs, we can inject an id and additional classes that can then be used for theming and manipulating.

Also, before each item was wrapped within a <a> tag. Because HTML prohibits having nested <a> tags (which makes sense), we couldn't inject any link into the body of individual items (e.g. inject relevant links to open in a different browser tab, while keeping the result popup menu open).

Now, if the result item has result[fields.url], then keep the <a> tag, because it makes sense: the whole result is assigned an URL.
If result[fields.url] is absent, the result is wrapped within a <div> tag, making it possible to inject one or even several links into the result's description, as may be required.

This feature is backward-compatible, as the default behavior is unchanged.

@dreaming-augustin
Copy link
Contributor Author

If requested, I can submit a PR for documentation later.

@dreaming-augustin
Copy link
Contributor Author

Here are two examples of theming achieved with this new feature:

Fomantic-search-classes-PR3142-2024-12-23-1
Fomantic-search-classes-PR3142-2024-12-23-2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant