Skip to content

Commit 5d1037c

Browse files
committed
minor
1 parent 28cc5c8 commit 5d1037c

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

1-js/04-object-basics/03-symbol/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ alert(id); // TypeError: Cannot convert a Symbol value to a string
5252
5353
That's a "language guard" against messing up, because strings and symbols are fundamentally different and should not occasionally convert one into another.
5454
55-
If we really want to show a symbol, we need to call `.toString()` on it, like here:
55+
If we really want to show a symbol, we need to explicitly call `.toString()` on it, like here:
5656
```js run
5757
let id = Symbol("id");
5858
*!*
5959
alert(id.toString()); // Symbol(id), now it works
6060
*/!*
6161
```
6262
63-
Or get `symbol.description` property to get the description only:
63+
Or get `symbol.description` property to show the description only:
6464
```js run
6565
let id = Symbol("id");
6666
*!*
@@ -133,7 +133,7 @@ let id = Symbol("id");
133133
let user = {
134134
name: "John",
135135
*!*
136-
[id]: 123 // not just "id: 123"
136+
[id]: 123 // not "id: 123"
137137
*/!*
138138
};
139139
```
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
As we can see from HTML/CSS, the slider is a `<div>` with a colored background, that contains a runner -- another `<div>` with `position:relative`.
12

2-
We have a horizontal Drag'n'Drop here.
3+
To position the runner we use `position:relative`, to provide the coordinates relative to its parent, here it's more convenient here than `position:absolute`.
34

4-
To position the element we use `position:relative` and slider-relative coordinates for the thumb. Here it's more convenient here than `position:absolute`.
5+
Then we implement horizontal-only Drag'n'Drop with limitation by width.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
To drag the element we can use `position:fixed`, it makes coordinates easier to manage. At the end we should switch it back to `position:absolute`.
1+
To drag the element we can use `position:fixed`, it makes coordinates easier to manage. At the end we should switch it back to `position:absolute` to lay the element into the document.
22

3-
Then, when coordinates are at window top/bottom, we use `window.scrollTo` to scroll it.
3+
When coordinates are at window top/bottom, we use `window.scrollTo` to scroll it.
44

55
More details in the code, in comments.

2-ui/3-event-details/4-mouse-drag-and-drop/2-drag-heroes/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Requirements:
1212

1313
- Use event delegation to track drag start: a single event handler on `document` for `mousedown`.
1414
- If elements are dragged to top/bottom window edges -- the page scrolls up/down to allow further dragging.
15-
- There is no horizontal scroll.
16-
- Draggable elements should never leave the window, even after swift mouse moves.
15+
- There is no horizontal scroll (this makes the task a bit simpler, adding it is easy).
16+
- Draggable elements or their parts should never leave the window, even after swift mouse moves.
1717

1818
The demo is too big to fit it here, so here's the link.
1919

2-ui/3-event-details/4-mouse-drag-and-drop/article.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ An extended code of `onMouseMove` to find "droppable" elements:
241241
242242
```js
243243
// potential droppable that we're flying over right now
244-
let currentDroppable = null;
244+
let currentDroppable = null;
245245

246246
function onMouseMove(event) {
247247
moveAt(event.pageX, event.pageY);
@@ -251,13 +251,13 @@ function onMouseMove(event) {
251251
ball.hidden = false;
252252

253253
// mousemove events may trigger out of the window (when the ball is dragged off-screen)
254-
// if clientX/clientY are out of the window, then elementfromPoint returns null
254+
// if clientX/clientY are out of the window, then elementFromPoint returns null
255255
if (!elemBelow) return;
256256

257257
// potential droppables are labeled with the class "droppable" (can be other logic)
258258
let droppableBelow = elemBelow.closest('.droppable');
259259

260-
if (currentDroppable != droppableBelow) { // if there are any changes
260+
if (currentDroppable != droppableBelow) {
261261
// we're flying in or out...
262262
// note: both values can be null
263263
// currentDroppable=null if we were not over a droppable before this event (e.g over an empty space)
@@ -288,13 +288,13 @@ We considered a basic Drag'n'Drop algorithm.
288288

289289
The key components:
290290

291-
1. Events flow: `ball.mousedown` -> `document.mousemove` -> `ball.mouseup` (cancel native `ondragstart`).
291+
1. Events flow: `ball.mousedown` -> `document.mousemove` -> `ball.mouseup` (don't forget to cancel native `ondragstart`).
292292
2. At the drag start -- remember the initial shift of the pointer relative to the element: `shiftX/shiftY` and keep it during the dragging.
293293
3. Detect droppable elements under the pointer using `document.elementFromPoint`.
294294

295295
We can lay a lot on this foundation.
296296

297-
- On `mouseup` we can finalize the drop: change data, move elements around.
297+
- On `mouseup` we can intellectually finalize the drop: change data, move elements around.
298298
- We can highlight the elements we're flying over.
299299
- We can limit dragging by a certain area or direction.
300300
- We can use event delegation for `mousedown/up`. A large-area event handler that checks `event.target` can manage Drag'n'Drop for hundreds of elements.

0 commit comments

Comments
 (0)