Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Updating sidebars to use details/summary #789

Merged
merged 24 commits into from
Oct 4, 2018

Conversation

tkadlec
Copy link
Contributor

@tkadlec tkadlec commented Aug 29, 2018

Changes all necessary macro's to start using the <details> and <summary> elements instead of jQuery for the sidebar navigation.

Will close https://app.zenhub.com/workspace/o/mdn/sprints/issues/258

@tkadlec
Copy link
Contributor Author

tkadlec commented Aug 29, 2018

@schalkneethling @jwhitlock Would appreciate you folks having a look. This touched more than I had thought it would and I want to make sure I didn't overlook anything.

Copy link

@schalkneethling schalkneethling left a comment

Choose a reason for hiding this comment

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

Whoah, that is a lot of changes. Thanks @tkadlec. Some nits, questions, general comments, and required changes.

Note: Not all nits was introduced here but, seeing we are doing all this work, we might as well clean up a bit as well ;)

macros/APIRef.ejs Show resolved Hide resolved
<li><a href="/<%=env.locale%>/docs/MDN/Doc_status/JavaScript"><%=titleValues['JavaScript']%></a>
<li><a href="/<%=env.locale%>/docs/MDN/Doc_status/Marketplace"><%=titleValues['Marketplace']%></a>
<li><a href="/<%=env.locale%>/docs/MDN/Doc_status/MathML"><%=titleValues['MathML']%></a>
<li><a href="/<%=env.locale%>/docs/MDN/Doc_status/SVG"><%=titleValues['SVG']%></a>

Choose a reason for hiding this comment

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

Missing closing tags for li tags

macros/DocStatusQuickLinks.ejs Show resolved Hide resolved
macros/FirefoxOSSidebar.ejs Outdated Show resolved Hide resolved
macros/HTMLMainQuickLinks.ejs Outdated Show resolved Hide resolved
macros/nsprapiref.ejs Outdated Show resolved Hide resolved
macros/nsprapiref.ejs Outdated Show resolved Hide resolved
macros/nsprapiref.ejs Outdated Show resolved Hide resolved
tests/macros/test-WebAssemblySidebar.js Show resolved Hide resolved
tests/macros/test-WebAssemblySidebar.js Show resolved Hide resolved
@schalkneethling
Copy link

@tkadlec I notice that the details element has a bottom margin of 20px that is negatively affecting the layout of the sidebar. I am thinking we should remove that, but not for all details elements so, maybe something like

.toggle {
    ...
    details {
      margin-bottom: 0;
    }
}

@schalkneethling
Copy link

@tkadlec and that CSS change will be on the Kuma side ;)

@a2sheppy
Copy link
Contributor

a2sheppy commented Sep 5, 2018

@jwhitlock tells me this gets rid of the links to the overview pages that are linked to from the expandable sections' headings. That's not ideal. I know they never worked right before, but it would be better if we could have that link functional instead:

> HTML
   <a>
   <abbr>
   ...

In that example above, "HTML" is an expandable heading; clicking it makes the elements below appear. What should happen is that there should be a widget you click to expand to show the element names, while allowing clicking the title "HTML" itself to take you to the main HTML reference page.

@schalkneethling
Copy link

Agreed @a2sheppy, very good point. @tkadlec ^^

Copy link
Contributor

@jwhitlock jwhitlock left a comment

Choose a reason for hiding this comment

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

Thanks @tkadlec, this is a big one. I'd prefer if it was broken into multiple pull requests, but I understand a side requirement is to all go at once, to simplify the JS / CSS changes and be able to measure impact.

I think @schalkneethling identified most of the required changes, around missing EJS end tags %>. I think my required changes are:

  • HTMLSidebar.ejs: <%=text['HTML_Elements']%>
  • HTMLSidebar.ejs: Missing Global Attributes section
  • SVGRef.ejs: add missing closing tag </details>.

I just read the code this round, now to integrated testing. I'll see if a change is needed around data-default-state during that testing.

Update: Added SVGRef to required changes

macros/HTMLMainQuickLinks.ejs Show resolved Hide resolved
macros/DocStatusQuickLinks.ejs Show resolved Hide resolved
</ol>
<li class="toggle">
<details <%=state('Introduction_to_HTML')%>>
<summary><%=text['Introduction_to_HTML']%></summary>
Copy link
Contributor

Choose a reason for hiding this comment

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

This drops the link, but it's also the first element in the details list, so 👍

There's a number of times that a section element has an <a> element in the existing sidebar, that is removed by this change. The translate attribute page has one of these sidebars, and if you hover over "HTML basics" -> "Introduction to HTML", you can see that the browser thinks clicking will go to Learn/HTML/Introduction_to_HTML. However, if you click the item, JavaScript takes over, and the section expands or collapses instead.

I'm not sure of a good way to combine "click here to expand / collapse" and "click here to go to this page". The arrow could be "collapse / expand" and the text could be "go to page", but that seems like a bad UI, making the common action the one with the tiny target.

This list has the pattern "move the summary link to the first item and add 'Overview'", and a few others do as well. This seems like a decent compromise going forward, and other sections should adopt it.

I'm trying to decide if this should be future work, since we're losing some information with this change. And I attached my essay to a line that doesn't need the change.

macros/HTMLSidebar.ejs Show resolved Hide resolved
macros/HTMLSidebar.ejs Outdated Show resolved Hide resolved
<li data-default-state="<%=currentPageIsUnder('WebExtensions/API')%>"><a href="<%=baseURL%>WebExtensions/API"><%=text['WebExtensions/API']%></a>
<%-template("WebExtAPISidebar", [])%>
<li class="toggle">
<details <%=currentPageIsUnder('WebExtensions/API')%>>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: GitHub hates %>>. I guess EJS isn't popular enough for a robust syntax highlighter? 😉

The "Whitespace Slurping" ending tag may help appease GitHub and get the desired output:

<details <%=currentPageIsUnder('WebExtensions/API')_%> >

Nope, that seems worse. Maybe it doesn't like HTML escaping into an unquoted context?

<details <%- currentPageIsUnder('WebExtensions/API')_%> >

Nope, syntax highlighting just seems to hate us. No change needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

All EJS (and Liquid/Jinja2/<insert templating language of choice here>) syntax highlighters I tried can’t properly highlight conditional attributes,

<li><a href="/<%=locale%>/docs/Mozilla/Projects/NSPR/Reference/Introduction_to_NSPR#NSPR_Naming_Conventions"><%=text['NSPR Naming Conventions']%></a></li>
<li><a href="/<%=locale%>/docs/Mozilla/Projects/NSPR/Reference/Introduction_to_NSPR#NSPR_Threads"><%=text['NSPR Threads']%></a>
<ol>
<li><a href="/<%=locale%>/docs/Mozilla/Projects/NSPR/Reference/Introduction_to_NSPR#Thread_Schedoling"><%=text['Thread Scheduling']%></a>
Copy link
Contributor

Choose a reason for hiding this comment

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

Existing nit: #Thread_Scheduling, not #Thread_Schedoling. Although "Schedoling" should be a word...

tests/macros/test-WebAssemblySidebar.js Show resolved Hide resolved
tests/macros/test-WebAssemblySidebar.js Show resolved Hide resolved
let links = dom.querySelectorAll('a');
assert.equal(links[1].textContent, locales[locale].Page_Inspector);
let summaries = dom.querySelectorAll('summary');
assert.equal(summaries[0].textContent, locales[locale].Core_Tools);
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird test, but works after change. The HTML was:

<ol>
    <li><a href="#">Core Tools</a>
      <ol>
        <li><a href="/en-US/docs/Tools/Page_Inspector">Page Inspector</a></li>

and now is:

<ol>
    <li class="toggle">
      <details>
        <summary>Core Tools</summary>
        <ol>
           <li><a href="/en-US/docs/Tools/Page_Inspector">Page Inspector</a></li>

I think the weirdness around testing sidebars is a symptom of a need for re-implementing them. Future work.

@jwhitlock
Copy link
Contributor

@jwhitlock tells me this gets rid of the links to the overview pages that are linked to from the expandable sections' headings. That's not ideal. I know they never worked right before, but it would be better if we could have that link functional instead

@a2sheppy, if there is a way to make this work, then that would be great. It's not obvious to me that there is. I think most users want to expand / collapse the list, and a smaller number want to go to the other page. Making the title a link to the page makes the largest UI element the minority action, which I think is a bad user experience.

My mental model is application menus in macOS, where a menu item is either an item or expands a submenu, never mixed. If you have a UI example where actions are combined with submenus, that would help me wrap my head around your solution.

Otherwise, my inclination is to not expand the scope of this PR to "fix this UX problem". If we need to retain the links, my preference is to commit to the model where the first submenu item is the link to the overview menu. The side menu on the <img> page would then be:

<img>
> HTML Elements
  HTML Elements Overview
  A
     <a>
     <abbr>
     ...

I'm 50/50 on shipping @tkadlec's changes and adding overview items later, or making them part of this change.

@schalkneethling
Copy link

@jwhitlock I think the biggest thing is to not lose the links. I reckon your suggestion of adding another menu entry that links to the overview makes a lot of sense. It would also fix a bug that was opened a while back, complaining about the fact that you have to:

  1. Right click the item
  2. Copy the url
  3. Paste it in the url bar

in order to get to the overview pages. +1

@ExE-Boss
Copy link
Contributor

ExE-Boss commented Sep 7, 2018

(In reply to @schalkneethling from #789 (comment))

@jwhitlock I think the biggest thing is to not lose the links. I reckon your suggestion of adding another menu entry that links to the overview makes a lot of sense. It would also fix a bug that was opened a while back, complaining about the fact that you have to:

  1. Right click the item
  2. Copy the url
  3. Paste it in the url bar

in order to get to the overview pages. +1

You can also middle‑click to open the overview page in a new tab.

@schalkneethling
Copy link

@ExE-Boss True, you could also right click and open in a new tab or, command+click. Not an ideal user experience though, that is why I like @jwhitlock's idea.

@tkadlec
Copy link
Contributor Author

tkadlec commented Sep 9, 2018

@jwhitlock @schalkneethling @ExE-Boss I'd vote for John's solution, at least for a starting point.

Do I wrap that into this PR or do we break it out?

@tkadlec
Copy link
Contributor Author

tkadlec commented Sep 9, 2018

@tkadlec I notice that the details element has a bottom margin of 20px that is negatively affecting the layout of the sidebar

@schalkneethling Where are you seeing that? It should be taken care of here: mdn/kuma@11b4d07#diff-691645fb32733fcf070299b5bddeb224R56

<li><a href="<%=baseURL%>Responsive_Design_Mode"><%=text["Responsive_Design_Mode"]%></a></li>
<li><a href="<%=baseURL%>Tips"><%=text["Tips"]%></a></li>
</ol>
<li class="toggle">
Copy link
Contributor

Choose a reason for hiding this comment

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

The {{ToolsSidebar}} was converted correctly 👍 as seen on https://developer.mozilla.org/en-US/docs/Tools/Web_Console . There's some local weirdness because the macro has https://developer.mozilla.org hard-coded into some links, which make them looks like external links in local dev. This should be removed, but it was in the old version, so out-of-scope for this PR.

pr 789 toolssiderbar

<li><a href="<%=baseURL%>/Caching_modules"><%=text['Caching_modules']%></a></li>
<li><a href="<%=baseURL%>/Exported_functions"><%=text['Exported_functions']%></a></li>
</ol>
<li class="toggle">
Copy link
Contributor

Choose a reason for hiding this comment

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

The {{WebAssemblySidebar}} macro was correctly updated, as seen on https://developer.mozilla.org/en-US/docs/WebAssembly/C_to_wasm

pr 789 webassemblysidebar

<li><a href="/<%=locale%>/docs/Web/API/WebGL_API/Tutorial/Lighting_in_WebGL"><%=text['Lightning']%></a></li>
<li><a href="/<%=locale%>/docs/Web/API/WebGL_API/Tutorial/Animating_textures_in_WebGL"><%=text['Animating_textures']%></a></li>
</ol>
<li class="toggle">
Copy link
Contributor

Choose a reason for hiding this comment

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

The {{WebGLSidebar}} is converted correctly 👍, as seen on https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Tutorial/Getting_started_with_WebGL

pr 789 webglsidebar

<li><a href="/<%=locale%>/docs/Web/API/WebRTC_API/Session_lifetime"><%=text['Session_lifetime']%></a></li>
<li><a href="/<%=locale%>/docs/Web/API/WebRTC_API/Using_data_channels"><%=text['Using_data_channels']%></a></li>
</ol>
<li class="toggle">
Copy link
Contributor

Choose a reason for hiding this comment

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

The {{WebRTCSidebar}} macro is correctly converted 👍, as seen on https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Signaling_and_video_calling ("WebRTC Basics" in the sidebar):

pr 789 webrtcsidebar

@@ -21,11 +21,12 @@ output += '<li><strong><a href="' + EventHref + '">Events</a></strong></li>';

function buildEventList(name, events, open) {
var openstr = open ? ' data-default-state="open"' : '';
var result = '<li'+ openstr +'><a href="#"><strong>' + name + '</strong></a><ol>';
<li class="toggle"><details open><summary>' + title + '</summary><ol></ol>
var result = '<li class="toggle"><details ' + openstr + '><summary>' + name + '</summary><ol>';
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't valid EJS, starting at <li class="toggle"> inside an EJS <% block. I think it should be something like:

var openstr = open ? ' open' : '';
var result = '<li class="toggle"><details ' + openstr + '><summary>' + name + '</summary><ol>';

Copy link
Contributor

Choose a reason for hiding this comment

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

It's valid now, but it should use the open attribute, not data-default-state="open". On https://developer.mozilla.org/en-US/docs/Web/Events/datachannel, the new sidebar (right side) is collapsed:

pr 789 - eventref-collapsed

Copy link
Contributor

@jwhitlock jwhitlock left a comment

Choose a reason for hiding this comment

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

There are still some missing closing EJS tags in the summary blocks.

'Doc_Status' : 'NSPR Documentation status',
'The_MDN_project' : 'The MDN Project'

'NSPR' : 'NSPR',
Copy link
Contributor

Choose a reason for hiding this comment

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

{{nsprapiref}} is a big one, and it converted correctly 👍, as seen on https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSPR/Reference/NSPR_Types:

pr 789 nsprapiref

@jwhitlock
Copy link
Contributor

I've done a live test of each of the changed macros, and these need some fixes:

  • {{AddonSidebar}} - r216474286 - i18n text key fixes, "manifest.json" section to convert, indentation
  • {{HTMLRef}} - r216689743 - "HTML Elements" section to convert
  • {{HTMLSidebar}} - r216708844 - too much escaping for input
  • {{HTTPSidebar}} - Invalid EJS leads to rendering errors
  • {{SpiderMonkeySidebar}} - r216864956 - i18n key fix
  • {{eventref}} - Invalid EJS leads to rendering errors
  • {{jsctypesSidebar}} - Invalid EJS leads to rendering errors

@schalkneethling
Copy link

Thanks so much for all the detailed reviews @jwhitlock ☕️

@tkadlec
Copy link
Contributor Author

tkadlec commented Sep 27, 2018

@jwhitlock @schalkneethling I've gone through the sidebar's John flagged and tested each of them. Can you take another look when you have time?

Copy link

@schalkneethling schalkneethling left a comment

Choose a reason for hiding this comment

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

Couple of items to clean up still here, but we are soooo close. Thx @tkadlec

macros/APIRef.ejs Show resolved Hide resolved
<li><a href="<%=baseURL%>WebExtensions/Examples"><%=text['WebExtensions/Examples']%></a></li>
<li><a href="<%=baseURL%>WebExtensions/What_next_"><%=text['WebExtensions/What_next_']%></a></li>
</ol>
<li class="toggle">

Choose a reason for hiding this comment

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

I am still seeing the above problems as mentioned above. I would also suggest that we add some padding inside the grey container.

macros/HTMLRef.ejs Show resolved Hide resolved
@tkadlec
Copy link
Contributor Author

tkadlec commented Sep 28, 2018

@schalkneethling Thanks for the review! All of the issues are taken care of in the Kuma PR. The only thing that I need you to double-check is APIRef.ejs where I don't see the issues you're still seeing.

@schalkneethling
Copy link

The only thing that I need you to double-check is APIRef.ejs where I don't see the > issues you're still seeing.

All good, after pulling the latest and restarting all the things those issues were gone. I see there are two files with conflicts now though :/

@tkadlec
Copy link
Contributor Author

tkadlec commented Sep 28, 2018

Pushed just as your comment appeared for me. :)

Copy link

@schalkneethling schalkneethling left a comment

Choose a reason for hiding this comment

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

That's an r+ from me. Thanks @tkadlec 🌮

Copy link
Contributor

@jwhitlock jwhitlock left a comment

Choose a reason for hiding this comment

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

These now work without errors, so I think we're ready to go. However, these changes will require re-rendering every page with the sidebars. Once the kuma style changes ship, the existing sidebars will get ugly until re-rendering. To apply the new sidebars, we'll need to re-render each page that uses them, which takes about 1 second per page (3-5 hours). I think we're going to aim for Thursday, October 4th for merging, deploying, and re-rendering.

Two small fixes we could still get in before Thursday:

  • open attribute in eventref.ejs, to auto-expand the details
  • Spacing in jsctypesSidebar

@@ -21,11 +21,12 @@ output += '<li><strong><a href="' + EventHref + '">Events</a></strong></li>';

function buildEventList(name, events, open) {
var openstr = open ? ' data-default-state="open"' : '';
var result = '<li'+ openstr +'><a href="#"><strong>' + name + '</strong></a><ol>';
<li class="toggle"><details open><summary>' + title + '</summary><ol></ol>
var result = '<li class="toggle"><details ' + openstr + '><summary>' + name + '</summary><ol>';
Copy link
Contributor

Choose a reason for hiding this comment

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

It's valid now, but it should use the open attribute, not data-default-state="open". On https://developer.mozilla.org/en-US/docs/Web/Events/datachannel, the new sidebar (right side) is collapsed:

pr 789 - eventref-collapsed


<li data-default-state="<%=state('Introduction')%>"><a href="/<%=locale%>/docs/Mozilla/js-ctypes/Using_js-ctypes"><%=text['Introduction']%></a>
<%-template("ListSubpagesForSidebar", ['/' + locale + '/docs/Mozilla/js-ctypes/Using_js-ctypes', 1])%>
<li class="toggle">
Copy link
Contributor

@jwhitlock jwhitlock Sep 28, 2018

Choose a reason for hiding this comment

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

This compiles now. On https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/js-ctypes_reference/CType, the new sidebar (right side) has more vertical spacing than before. I'm OK with the change, but @schalkneethling may have something to say about it.

pr 789 - jsctypessidebar.

Choose a reason for hiding this comment

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

Nope, all good. I like the new spacing.

@jwhitlock
Copy link
Contributor

I'll address eventref.ejs in a new PR. The commits seems like a sequence of fixes, so squashing for merging, and adding bug 1488884.

@jwhitlock jwhitlock merged commit 50a70d8 into mdn:master Oct 4, 2018
@ExE-Boss ExE-Boss mentioned this pull request Oct 11, 2018
2 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants