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

#2779 Dev edition: add back jump-to search #2822

Merged
merged 1 commit into from Jul 13, 2017

Conversation

juanbzpy
Copy link

@juanbzpy juanbzpy commented Jul 8, 2017

Final steps for #2779

@juanbzpy
Copy link
Author

juanbzpy commented Jul 8, 2017

This is still a WIP, need to add CSS for responsiveness and some missing JavaScript features.

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

I forgot this was WIP before I started my review, so apologies if some of this was stuff you were already aware of. Very excited!!

search.js Outdated
@@ -0,0 +1,41 @@
;(function() {
Copy link
Member

Choose a reason for hiding this comment

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

Can you put this in dev/? Then we don't need an additional build step to copy it.

No preceding semicolon please. "use strict"; at the top of the file please.

search.js Outdated
*/

// Get elements
var d = document;
Copy link
Member

Choose a reason for hiding this comment

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

Let's use const consistenly

search.js Outdated
function findSections(word, arr) {
return arr
.filter((item) => {
const regex = new RegExp(`${word.toLowerCase()}`, 'gi');
Copy link
Member

Choose a reason for hiding this comment

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

Why toLowerCase if you're going to add the i flag anyway? Also, no need for the template string.

search.js Outdated
.then(data => jsonResponses = data)
.catch(err => console.error('Error loading search-index.json'));

function resultTpl(result) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's spell out "Template"

source Outdated
<div id="search" w-nohtml>
<div id="query-container">
<input name="query" type="search" placeholder="Search. Press '/'" autocomplete="off" id="query"
class="field-input-text">
Copy link
Member

Choose a reason for hiding this comment

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

No need for this class, or the class below, I think

search.js Outdated
const regex = new RegExp(`${word.toLowerCase()}`, 'gi');
return item.text.match(regex);
})
.slice(0, 10)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe factor out this constant (10) into the top of the file

search.js Outdated

function findSections(word, arr) {
return arr
.filter((item) => {
Copy link
Member

Choose a reason for hiding this comment

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

Although the functional style is nice, it does mean we'll iterate over the entire array when we only want 10 elements. It might be better to go with a for loop? Or maybe it doesn't matter. I'm just a little concerned about mobile jank.

Copy link
Author

Choose a reason for hiding this comment

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

I think that for the amount of data we are iterating over (~480 results) we can use .filter just fine. Also, in my opinion, this way we can select better results looking into all results.

But I'm probably not thinking through all the constrains, so if a for loop is a better option, lets do it.

Copy link
Member

Choose a reason for hiding this comment

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

Happy to stick with the functional style for now and then I can do some measurements to see if it's a real issue.

search.js Outdated
.map(value => resultTpl(value));
}

query.addEventListener('keyup', (event) => {
Copy link
Member

Choose a reason for hiding this comment

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

A lot of code in https://github.com/benschwarz/developers.whatwg.org/blob/97ff943a8f5b8fe38f78e224b4b44b472ccefb57/javascript/master.js for clearing results and navigating the list seems to be missing. Should we add it, or do you think it's not necessary?

Copy link
Author

Choose a reason for hiding this comment

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

Is not necessary, but it's an absolutely nice to have. I'm adding those missing features.

dev/styles.css Outdated
}

div#search input,
div#Search ol {
Copy link
Member

Choose a reason for hiding this comment

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

Accidental uppercase S

dev/styles.css Outdated
position: absolute;
top: 0;
right: 0;
}
Copy link
Member

Choose a reason for hiding this comment

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

@juanbzpy
Copy link
Author

I think it's done. @domenic please review as I'm sure I missed something.

Small demo:

domenic pushed a commit to whatwg/html-build that referenced this pull request Jul 12, 2017
Part of fixing whatwg/html#2779. See also whatwg/html#2822 which uses this.

In the future we plan to have Wattsi generate this, but for now it is a Python-based postprocessing step.

This can be bypassed by using the new --no-post flag.
Closes whatwg#2779. This depends on whatwg/html-build#114. The styles and scripts are based on https://github.com/benschwarz/developers.whatwg.org/tree/97ff943a8f5b8fe38f78e224b4b44b472ccefb57, but adapted and modernized, with some bugs fixed and behaviors tweaked.
@domenic
Copy link
Member

domenic commented Jul 12, 2017

So currently it looks like our build server does not have a recent enough Python/pip/virtualenv to work with this, hmm. I've asked for an upgrade and will report back when it's done, and then we can merge this.

@domenic domenic merged commit cfb8b9e into whatwg:master Jul 13, 2017
@juanbzpy juanbzpy deleted the add-search-bar branch July 13, 2017 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants