|
224 | 224 | **/
|
225 | 225 | Element.Layout = Class.create(Hash, {
|
226 | 226 | /**
|
227 |
| - * new Element.Layout(element[, preCompute]) |
| 227 | + * new Element.Layout(element[, preCompute = false]) |
228 | 228 | * - element (Element): The element to be measured.
|
229 |
| - * - preCompute (Boolean): Whether to compute all values at once. |
| 229 | + * - preCompute (Boolean): Whether to compute all values at once. Default |
| 230 | + * is `false`. |
230 | 231 | *
|
231 | 232 | * Declare a new layout hash.
|
232 | 233 | *
|
|
273 | 274 | *
|
274 | 275 | * Retrieve the measurement specified by `property`. Will throw an error
|
275 | 276 | * if the property is invalid.
|
| 277 | + * |
| 278 | + * ##### Caveats |
| 279 | + * |
| 280 | + * * `Element.Layout` can measure the dimensions of an element hidden with |
| 281 | + * CSS (`display: none`), but _only_ if its parent element is visible. |
276 | 282 | **/
|
277 | 283 | get: function($super, property) {
|
278 | 284 | // Try to fetch from the cache.
|
|
386 | 392 | *
|
387 | 393 | * Keys can be passed into this method as individual arguments _or_
|
388 | 394 | * separated by spaces within a string.
|
| 395 | + * |
| 396 | + * // Equivalent statements: |
| 397 | + * someLayout.toObject('top', 'bottom', 'left', 'right'); |
| 398 | + * someLayout.toObject('top bottom left right'); |
389 | 399 | **/
|
390 | 400 | toObject: function() {
|
391 | 401 | var args = $A(arguments);
|
|
410 | 420 | *
|
411 | 421 | * Keys can be passed into this method as individual arguments _or_
|
412 | 422 | * separated by spaces within a string.
|
| 423 | + * |
| 424 | + * // Equivalent statements: |
| 425 | + * someLayout.toHash('top', 'bottom', 'left', 'right'); |
| 426 | + * someLayout.toHash('top bottom left right'); |
413 | 427 | **/
|
414 | 428 | toHash: function() {
|
415 | 429 | var obj = this.toObject.apply(this, arguments);
|
|
712 | 726 |
|
713 | 727 | /**
|
714 | 728 | * Element.Offset#inspect() -> String
|
| 729 | + * |
| 730 | + * Returns a debug-friendly representation of the offset. |
715 | 731 | **/
|
716 | 732 | inspect: function() {
|
717 | 733 | return "#<Element.Offset left: #{left} top: #{top}>".interpolate(this);
|
|
726 | 742 |
|
727 | 743 | /**
|
728 | 744 | * Element.Offset#toArray() -> Array
|
| 745 | + * |
| 746 | + * Returns an array representation fo the offset in [x, y] format. |
729 | 747 | **/
|
730 | 748 | toArray: function() {
|
731 | 749 | return [this.left, this.top];
|
732 | 750 | }
|
733 | 751 | });
|
734 | 752 |
|
735 | 753 | /**
|
736 |
| - * Element.getLayout(@element, preCompute) -> Element.Layout |
| 754 | + * Element.getLayout(@element[, preCompute = false]) -> Element.Layout |
| 755 | + * - element (Element): The element to be measured. |
| 756 | + * - preCompute (Boolean): Whether to compute all values at once. Default |
| 757 | + * is `false`. |
737 | 758 | *
|
738 | 759 | * Returns an instance of [[Element.Layout]] for measuring an element's
|
739 | 760 | * dimensions.
|
|
744 | 765 | * `Element.getLayout` whenever you need a measurement. You should call
|
745 | 766 | * `Element.getLayout` again only when the values in an existing
|
746 | 767 | * `Element.Layout` object have become outdated.
|
| 768 | + * |
| 769 | + * Remember that instances of `Element.Layout` compute values the first |
| 770 | + * time they're asked for and remember those values for later retrieval. |
| 771 | + * If you want to compute all an element's measurements at once, pass |
| 772 | + * |
| 773 | + * ##### Examples |
| 774 | + * |
| 775 | + * var layout = $('troz').getLayout(); |
| 776 | + * |
| 777 | + * layout.get('width'); //-> 150 |
| 778 | + * layout.get('height'); //-> 500 |
| 779 | + * layout.get('padding-left'); //-> 10 |
| 780 | + * layout.get('margin-left'); //-> 25 |
| 781 | + * layout.get('border-top'); //-> 5 |
| 782 | + * layout.get('border-bottom'); //-> 5 |
| 783 | + * |
| 784 | + * // Won't re-compute width; remembers value from first time. |
| 785 | + * layout.get('width'); //-> 150 |
| 786 | + * |
| 787 | + * // Composite values obtained by adding together other properties; |
| 788 | + * // will re-use any values we've already looked up above. |
| 789 | + * layout.get('padding-box-width'); //-> 170 |
| 790 | + * layout.get('border-box-height'); //-> 510 |
| 791 | + * |
| 792 | + * ##### Caveats |
| 793 | + * |
| 794 | + * * Instances of `Element.Layout` can measure the dimensions of an |
| 795 | + * element hidden with CSS (`display: none`), but _only_ if its parent |
| 796 | + * element is visible. |
747 | 797 | **/
|
748 | 798 | function getLayout(element, preCompute) {
|
749 | 799 | return new Element.Layout(element, preCompute);
|
|
759 | 809 | * calling this method frequently over short spans of code, you might want
|
760 | 810 | * to call [[Element.getLayout]] and operate on the [[Element.Layout]]
|
761 | 811 | * object itself (thereby taking advantage of measurement caching).
|
| 812 | + * |
| 813 | + * ##### Examples |
| 814 | + * |
| 815 | + * $('troz').measure('width'); //-> 150 |
| 816 | + * $('troz').measure('border-top'); //-> 5 |
| 817 | + * $('troz').measure('top'); //-> 226 |
| 818 | + * |
| 819 | + * ##### Caveats |
| 820 | + * |
| 821 | + * * `Element.measure` can measure the dimensions of an element hidden with |
| 822 | + * CSS (`display: none`), but _only_ if its parent element is visible. |
762 | 823 | **/
|
763 | 824 | function measure(element, property) {
|
764 | 825 | return $(element).getLayout().get(property);
|
|
0 commit comments