-
Notifications
You must be signed in to change notification settings - Fork 228
Event delegation #353
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
Event delegation #353
Changes from all commits
234b419
e06394e
5dc484e
ff39c36
475c3e7
5e45108
84c78f0
b23c55e
9517ef9
7e24604
f1cf397
031c98a
c213810
4848363
4c69af1
41c7660
789814d
2ec1979
1f09fd1
37fc3f3
69391c0
0d26d8e
e92bf90
82ef753
204f06a
91d4874
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
The solution has two parts. | ||
La solución tiene dos partes. | ||
|
||
1. Wrap every tree node title into `<span>`. Then we can CSS-style them on `:hover` and handle clicks exactly on text, because `<span>` width is exactly the text width (unlike without it). | ||
2. Set a handler to the `tree` root node and handle clicks on that `<span>` titles. | ||
1. Envuelve cada nodo de título del árbol dentro de `<span>`. Luego podemos aplicarles CSS-style en `:hover` y manejar los clics exactamente sobre el texto, porque el ancho de `<span>` es exactamente el ancho del texto (no lo será si no lo tiene). | ||
2. Establece el manejador al nodo raíz del `tree` y maneja los clics en aquellos títulos `<span>`. | ||
vplentinax marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,13 +2,13 @@ importance: 5 | |||||
|
||||||
--- | ||||||
|
||||||
# Tree menu | ||||||
# Menú de árbol | ||||||
|
||||||
Create a tree that shows/hides node children on click: | ||||||
Crea un árbol que muestre y oculte nodos hijos con clics: | ||||||
vplentinax marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
[iframe border=1 src="solution"] | ||||||
|
||||||
Requirements: | ||||||
Requerimientos: | ||||||
|
||||||
- Only one event handler (use delegation) | ||||||
- A click outside the node title (on an empty space) should not do anything. | ||||||
- Solamente un manejador de eventos (usa delegación) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lo mismo que mi comentario anterior. Parece que a elección de @joaquinelio prefiere "manejador" |
||||||
- Un clic fuera de los nodos de títulos (en un espacio vacío) no debe hacer nada. | ||||||
vplentinax marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,37 +2,37 @@ importance: 5 | |||||
|
||||||
--- | ||||||
|
||||||
# Tooltip behavior | ||||||
# Comportamiento: Tooltip | ||||||
|
||||||
Create JS-code for the tooltip behavior. | ||||||
Crea código JS para el comportamiento "tooltip". | ||||||
joaquinelio marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
When a mouse comes over an element with `data-tooltip`, the tooltip should appear over it, and when it's gone then hide. | ||||||
Cuando un mouse pasa sobre un elemento con `data-tooltip`, el tooltip debe aparecer sobre él, y ocultarse cuando se va. | ||||||
|
||||||
An example of annotated HTML: | ||||||
Un ejemplo en HTML comentado: | ||||||
```html | ||||||
<button data-tooltip="the tooltip is longer than the element">Short button</button> | ||||||
<button data-tooltip="HTML<br>tooltip">One more button</button> | ||||||
``` | ||||||
|
||||||
Should work like this: | ||||||
Debe funcionar así: | ||||||
|
||||||
[iframe src="solution" height=200 border=1] | ||||||
|
||||||
In this task we assume that all elements with `data-tooltip` have only text inside. No nested tags (yet). | ||||||
En esta tarea suponemos que todos los elementos con `data-tooltip` solo tienen texto dentro. Sin tags anidados (todavía). | ||||||
|
||||||
Details: | ||||||
Detalles: | ||||||
|
||||||
- The distance between the element and the tooltip should be `5px`. | ||||||
- The tooltip should be centered relative to the element, if possible. | ||||||
- The tooltip should not cross window edges. Normally it should be above the element, but if the element is at the page top and there's no space for the tooltip, then below it. | ||||||
- The tooltip content is given in the `data-tooltip` attribute. It can be arbitrary HTML. | ||||||
- La distancia entre el elemento y el tooltip debe ser `5px`. | ||||||
- El tooltip debe ser centrado relativo al elemento si es posible. | ||||||
- El tooltip no debe cruzar los bordes de la ventana. Normalmente debería estar sobre el elemento, pero si el elemento está en la parte superior de la página y no hay espacio para el tooltip, entonces debajo de él. | ||||||
- El contenido del tooltip está dado en el atributo `data-tooltip`. Este puede ser HTML arbitrario. | ||||||
|
||||||
You'll need two events here: | ||||||
- `mouseover` triggers when a pointer comes over an element. | ||||||
- `mouseout` triggers when a pointer leaves an element. | ||||||
Necesitarás dos eventos aquí: | ||||||
- `mouseover` se dispara cuando el puntero pasa sobre el elemento. | ||||||
- `mouseout` se dispara cuando el puntero deja el elemento. | ||||||
|
||||||
Please use event delegation: set up two handlers on `document` to track all "overs" and "outs" from elements with `data-tooltip` and manage tooltips from there. | ||||||
Usa delegación de eventos: prepare dos manejadores en el `document` para rastrear todos los "overs" y "outs" de los elementos con `data-tooltip` y administra los tooltips desde allí. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
After the behavior is implemented, even people unfamiliar with JavaScript can add annotated elements. | ||||||
Después de implementar el comportamiento, incluso gente no familiarizada con JavaScript puede agregar elementos anotados. | ||||||
|
||||||
P.S. Only one tooltip may show up at a time. | ||||||
P.D. Solamente un tooltip puede mostrarse a la vez. |
Uh oh!
There was an error while loading. Please reload this page.