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

Revise docs for dom functions #6534

Merged
merged 3 commits into from
Nov 14, 2023

Conversation

nickmcintyre
Copy link
Member

@nickmcintyre nickmcintyre commented Nov 7, 2023

Addresses #6511

Changes:

I edited the inline docs for the top-level functions in src/dom/dom.js. This includes everything in the DOM group except the following:

I'll make a separate pull request for the last four items.

@dkessner, @MsQCompSci, @davepagurek, @limzykenneth, @Qianqianye, @SarveshLimaye, @SoundaryaKoutharapu, @ramya202000, @BamaCharanChhandogi, @Obi-Engine10, @MarceloGoncalves, @hiddenenigma I'd love to incorporate any feedback you may have! Here's a staging version of the edits in this pull request.

PR Checklist

  • npm run lint passes
  • [Inline documentation] is included / updated

@MsQCompSci
Copy link

Edits look great!

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

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

This is looking good! Biggest questions for me are how we want to handle the media element ones and autoplaying and the browser's limitations of autoplaying with sound.

src/dom/dom.js Outdated
* @param {String|p5.Element|HTMLElement} [container] CSS selector string, <a href="#/p5.Element">p5.Element</a>
* , or HTML element to search within
* @return {p5.Element[]} Array of <a href="#/p5.Element">p5.Element</a>s containing nodes found
* @param {String} selectors CSS selector string of element to search for..
Copy link
Contributor

Choose a reason for hiding this comment

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

Small typo I think:

Suggested change
* @param {String} selectors CSS selector string of element to search for..
* @param {String} selectors CSS selector string of element to search for.

src/dom/dom.js Outdated
@@ -339,18 +486,28 @@ p5.prototype.createDiv = function (html = '') {
};

/**
* Creates a `&lt;p&gt;&lt;/p&gt;` element in the DOM with given inner HTML. Used
* for paragraph length text.
* Creates a `&lt;p&gt;&lt;/p&gt;` element. It's commonly use for
Copy link
Contributor

Choose a reason for hiding this comment

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

Small typo:

Suggested change
* Creates a `&lt;p&gt;&lt;/p&gt;` element. It's commonly use for
* Creates a `&lt;p&gt;&lt;/p&gt;` element. It's commonly used for

src/dom/dom.js Outdated
@@ -359,16 +516,42 @@ p5.prototype.createP = function (html = '') {
};

/**
* Creates a `&lt;span&gt;&lt;/span&gt;` element in the DOM with given inner HTML.
* Creates a `&lt;span&gt;&lt;/span&gt;` element. It's commonly used as a
* container for other elements.
Copy link
Contributor

Choose a reason for hiding this comment

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

We also say this for <div>, maybe we can add something small about it being generally used as a container for inline things? Not sure what the best wording for that is. Things that might wrap along with text?

src/dom/dom.js Outdated
* background(200);
*
* // Create an h3 element within the span.
* let span = createSpan('<h3>p5*js</h3>');
Copy link
Contributor

Choose a reason for hiding this comment

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

This works but I also wonder if there's a way to illustrate the difference with a div here. Maybe if you have a div that already has some text, you could add a span with red text into the middle of its contents?

src/dom/dom.js Outdated
@@ -377,29 +560,54 @@ p5.prototype.createSpan = function (html = '') {
};

/**
* Creates an `&lt;img&gt;` element in the DOM with given src and
* alternate text.
* Creates an `&lt;img&gt;` element.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe worth differentiating this from p5.Image: this exists outside of the canvas while p5.Image is only visible when you draw it on the canvas

src/dom/dom.js Outdated
* the button.
*
* The second parameter, `value`, is optional. It's a string that sets the
* button's value. See <a href="#/p5.Element/value">p5.Element.value()</a> for
Copy link
Contributor

Choose a reason for hiding this comment

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

Think it's worth linking to MDN here https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#value for an explanation of why a button might need a value and how it gets used? It's definitely an edge case, I didn't even realize this was a thing until a few minutes ago, but I just had to go google it to see what it might mean 😅

* function handleVideo() {
* video.size(100, 100);
* video.loop();
* video.volume(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

If I go directly to https://computiful.dev/sod-dom-functions/reference/#/p5/createVideo to simulate coming from a google search (or search for createVideo, go to the docs, then reload) the video doesn't immediately play, I suspect this is because we're muting after looping:
image

Maybe we should try muting first? If that does indeed fix it, it's probably worth mentioning explicitly in the docs that that ordering matters because of how the browser deals with autoplaying media.

src/dom/dom.js Outdated
* // Load the audio.
* beat = createAudio('assets/beat.mp3', () => {
* // Play the audio in a loop once it's loaded.
* beat.loop();
Copy link
Contributor

Choose a reason for hiding this comment

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

This one also doesn't work for me if I go directly to the URL for this doc. Maybe we can start it on click, or only load the audio on click? Probably worth mentioning for both audio and video that this might happen if there hasn't been a user interaction

@nickmcintyre
Copy link
Member Author

Thanks @davepagurek! I fixed the typos, reworked the <span> example, and used showControls() to get around autoplay issues.

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

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

Nice, looks good!

@davepagurek davepagurek merged commit 1092835 into processing:main Nov 14, 2023
2 checks passed
@nickmcintyre nickmcintyre deleted the sod-dom-functions branch May 6, 2024 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

3 participants