Skip to content

Commit 38cafcc

Browse files
Documentation fixes.
1 parent afdb2c0 commit 38cafcc

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

src/dom/dom.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,16 @@
290290
}
291291

292292
/**
293-
* Element.toggle(@element) -> Element
293+
* Element.toggle(@element[, bool]) -> Element
294294
*
295-
* Toggles the visibility of `element`. Returns `element`.
295+
* Toggles the CSS `display` of `element`. Returns `element`.
296+
*
297+
* Switches an element's CSS `display` between `none` and its inherited
298+
* value (usually `block` or `inline`).
299+
*
300+
* By default, `toggle` will switch the display to the opposite of its
301+
* current state, but will use the `bool` argument instead if it's
302+
* provided (`true` to show the element, `false` to hide it).
296303
*
297304
* ##### Examples
298305
*
@@ -305,6 +312,10 @@
305312
* $('error-message').toggle();
306313
* // -> Element (and displays div#error-message)
307314
*
315+
* $('error-message).toggle(true);
316+
* // -> Element (and displays div#error-message, no matter what its
317+
* // previous state)
318+
*
308319
* Toggle multiple elements using [[Enumerable#each]]:
309320
*
310321
* ['error-message', 'welcome-message'].each(Element.toggle);
@@ -314,6 +325,11 @@
314325
*
315326
* $('error-message', 'welcome-message').invoke('toggle');
316327
* // -> [Element, Element]
328+
*
329+
* $('error-message', 'welcome-message').invoke('toggle', false);
330+
* // -> [Element, Element] (and hides both elements, no matter what
331+
* their previous state)
332+
*
317333
*
318334
* ##### Notes
319335
*
@@ -331,7 +347,7 @@
331347
*
332348
* <div id="hidden-by-css"></div>
333349
*
334-
* $('hidden-by-css').toggle(); // WONT' WORK!
350+
* $('hidden-by-css').toggle(); // WON'T WORK!
335351
* // -> Element (div#hidden-by-css is still hidden!)
336352
**/
337353
function toggle(element, bool) {
@@ -2485,9 +2501,13 @@
24852501
}
24862502

24872503
/**
2488-
* Element.toggleClassName(@element, className) -> Element
2504+
* Element.toggleClassName(@element, className[, bool]) -> Element
24892505
*
24902506
* Toggles the presence of CSS class `className` on `element`.
2507+
*
2508+
* By default, `toggleClassName` will flip to the opposite state, but
2509+
* will use `bool` instead if it's given; `true` will add the class name
2510+
* and `false` will remove it.
24912511
*
24922512
* ##### Examples
24932513
*
@@ -2500,10 +2520,13 @@
25002520
* // -> false
25012521
*
25022522
* $('mutsu').toggleClassName('fruit');
2503-
* // -> element
2523+
* // -> Element
25042524
*
25052525
* $('mutsu').hasClassName('fruit');
25062526
* // -> true
2527+
*
2528+
* $('mutsu').toggleClassName('fruit', true);
2529+
* // -> Element (keeps the "fruit" class name that was already there)
25072530
**/
25082531
function toggleClassName(element, className, bool) {
25092532
if (!(element = $(element))) return;

src/dom/event.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
// (Though Opera supports both systems, the event object appears to be
100100
// the same no matter which system is used. That means that this function
101101
// will always return `true` in Opera, but that's OK; it keeps us from
102-
// having to do a browser sniff.
102+
// having to do a browser sniff.)
103103
isIELegacyEvent = function(event) {
104104
return !(event instanceof window.Event);
105105
};
@@ -151,6 +151,7 @@
151151

152152
/**
153153
* Event.isLeftClick(@event) -> Boolean
154+
* - event (Event): An Event object
154155
*
155156
* Determines whether a button-related mouse event involved the left
156157
* mouse button.
@@ -163,6 +164,7 @@
163164

164165
/**
165166
* Event.isMiddleClick(@event) -> Boolean
167+
* - event (Event): An Event object
166168
*
167169
* Determines whether a button-related mouse event involved the middle
168170
* mouse button.
@@ -171,11 +173,12 @@
171173

172174
/**
173175
* Event.isRightClick(@event) -> Boolean
176+
* - event (Event): An Event object
174177
*
175178
* Determines whether a button-related mouse event involved the right
176179
* mouse button.
177180
*
178-
* Keep in mind that the "left" mouse button is actually the "secondary"
181+
* Keep in mind that the "right" mouse button is actually the "secondary"
179182
* mouse button. When a mouse is in left-handed mode, the browser will
180183
* report clicks of the _left_ button as "left-clicks."
181184
**/
@@ -255,11 +258,11 @@
255258
*
256259
* ##### Example
257260
*
258-
* Here's a simple code that lets you click everywhere on the page and hides
259-
* the closest-fitting paragraph around your click (if any).
261+
* Here's a simple example that lets you click everywhere on the page and
262+
* hides the closest-fitting paragraph around your click (if any).
260263
*
261264
* document.observe('click', function(event) {
262-
* var element = Event.findElement(event, 'p');
265+
* var element = event.findElement('p');
263266
* if (element != document)
264267
* $(element).hide();
265268
* });
@@ -433,6 +436,7 @@
433436

434437
/**
435438
* Event.extend(@event) -> Event
439+
* - event (Event): An Event object
436440
*
437441
* Extends `event` with all of the methods contained in `Event.Methods`.
438442
*

0 commit comments

Comments
 (0)