Revision 1374
Added by Dietmar over 13 years ago
dom.js | ||
---|---|---|
70 | 70 |
|
71 | 71 |
/** |
72 | 72 |
* Provides helper methods for DOM elements. |
73 |
* @namespace YAHOO.util
|
|
74 |
* @class Dom
|
|
75 |
* @requires yahoo, event
|
|
73 |
* @namespace YAHOO.util |
|
74 |
* @class Dom |
|
75 |
* @requires yahoo, event |
|
76 | 76 |
*/ |
77 | 77 |
Y.Dom = { |
78 | 78 |
CUSTOM_ATTRIBUTES: (!documentElement.hasAttribute) ? { // IE < 8 |
... | ... | |
87 | 87 |
|
88 | 88 |
/** |
89 | 89 |
* Returns an HTMLElement reference. |
90 |
* @method get
|
|
91 |
* @param {String | HTMLElement |Array} el Accepts a string to use as an ID for getting a DOM reference, an actual DOM reference, or an Array of IDs and/or HTMLElements.
|
|
92 |
* @return {HTMLElement | Array} A DOM reference to an HTML element or an array of HTMLElements.
|
|
90 |
* @method get |
|
91 |
* @param {String | HTMLElement |Array} el Accepts a string to use as an ID for getting a DOM reference, an actual DOM reference, or an Array of IDs and/or HTMLElements. |
|
92 |
* @return {HTMLElement | Array} A DOM reference to an HTML element or an array of HTMLElements. |
|
93 | 93 |
*/ |
94 | 94 |
get: function(el) { |
95 | 95 |
var id, nodes, c, i, len, attr; |
... | ... | |
146 | 146 |
|
147 | 147 |
/** |
148 | 148 |
* Normalizes currentStyle and ComputedStyle. |
149 |
* @method getStyle
|
|
150 |
* @param {String | HTMLElement |Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements.
|
|
151 |
* @param {String} property The style property whose value is returned.
|
|
152 |
* @return {String | Array} The current value of the style property for the element(s).
|
|
149 |
* @method getStyle |
|
150 |
* @param {String | HTMLElement |Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements. |
|
151 |
* @param {String} property The style property whose value is returned. |
|
152 |
* @return {String | Array} The current value of the style property for the element(s). |
|
153 | 153 |
*/ |
154 | 154 |
getStyle: function(el, property) { |
155 | 155 |
return Y.Dom.batch(el, Y.Dom._getStyle, property); |
... | ... | |
204 | 204 |
|
205 | 205 |
/** |
206 | 206 |
* Wrapper for setting style properties of HTMLElements. Normalizes "opacity" across modern browsers. |
207 |
* @method setStyle
|
|
208 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements.
|
|
209 |
* @param {String} property The style property to be set.
|
|
210 |
* @param {String} val The value to apply to the given property.
|
|
207 |
* @method setStyle |
|
208 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements. |
|
209 |
* @param {String} property The style property to be set. |
|
210 |
* @param {String} val The value to apply to the given property. |
|
211 | 211 |
*/ |
212 | 212 |
setStyle: function(el, property, val) { |
213 | 213 |
Y.Dom.batch(el, Y.Dom._setStyle, { prop: property, val: val }); |
... | ... | |
257 | 257 |
/** |
258 | 258 |
* Gets the current position of an element based on page coordinates. |
259 | 259 |
* Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). |
260 |
* @method getXY
|
|
261 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM
|
|
260 |
* @method getXY |
|
261 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM |
|
262 | 262 |
* reference, or an Array of IDs and/or HTMLElements |
263 |
* @return {Array} The XY position of the element(s)
|
|
263 |
* @return {Array} The XY position of the element(s) |
|
264 | 264 |
*/ |
265 | 265 |
getXY: function(el) { |
266 | 266 |
return Y.Dom.batch(el, Y.Dom._getXY); |
... | ... | |
394 | 394 |
|
395 | 395 |
/** |
396 | 396 |
* Gets the current X position of an element based on page coordinates. The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). |
397 |
* @method getX
|
|
398 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements
|
|
399 |
* @return {Number | Array} The X position of the element(s)
|
|
397 |
* @method getX |
|
398 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements |
|
399 |
* @return {Number | Array} The X position of the element(s) |
|
400 | 400 |
*/ |
401 | 401 |
getX: function(el) { |
402 | 402 |
var f = function(el) { |
... | ... | |
408 | 408 |
|
409 | 409 |
/** |
410 | 410 |
* Gets the current Y position of an element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). |
411 |
* @method getY
|
|
412 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements
|
|
413 |
* @return {Number | Array} The Y position of the element(s)
|
|
411 |
* @method getY |
|
412 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements |
|
413 |
* @return {Number | Array} The Y position of the element(s) |
|
414 | 414 |
*/ |
415 | 415 |
getY: function(el) { |
416 | 416 |
var f = function(el) { |
... | ... | |
423 | 423 |
/** |
424 | 424 |
* Set the position of an html element in page coordinates, regardless of how the element is positioned. |
425 | 425 |
* The element(s) must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). |
426 |
* @method setXY
|
|
427 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements
|
|
428 |
* @param {Array} pos Contains X & Y values for new position (coordinates are page-based)
|
|
429 |
* @param {Boolean} noRetry By default we try and set the position a second time if the first fails
|
|
426 |
* @method setXY |
|
427 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements |
|
428 |
* @param {Array} pos Contains X & Y values for new position (coordinates are page-based) |
|
429 |
* @param {Boolean} noRetry By default we try and set the position a second time if the first fails |
|
430 | 430 |
*/ |
431 | 431 |
setXY: function(el, pos, noRetry) { |
432 | 432 |
Y.Dom.batch(el, Y.Dom._setXY, { pos: pos, noRetry: noRetry }); |
... | ... | |
487 | 487 |
/** |
488 | 488 |
* Set the X position of an html element in page coordinates, regardless of how the element is positioned. |
489 | 489 |
* The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). |
490 |
* @method setX
|
|
491 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements.
|
|
492 |
* @param {Int} x The value to use as the X coordinate for the element(s).
|
|
490 |
* @method setX |
|
491 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements. |
|
492 |
* @param {Int} x The value to use as the X coordinate for the element(s). |
|
493 | 493 |
*/ |
494 | 494 |
setX: function(el, x) { |
495 | 495 |
Y.Dom.setXY(el, [x, null]); |
... | ... | |
498 | 498 |
/** |
499 | 499 |
* Set the Y position of an html element in page coordinates, regardless of how the element is positioned. |
500 | 500 |
* The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). |
501 |
* @method setY
|
|
502 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements.
|
|
503 |
* @param {Int} x To use as the Y coordinate for the element(s).
|
|
501 |
* @method setY |
|
502 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements. |
|
503 |
* @param {Int} x To use as the Y coordinate for the element(s). |
|
504 | 504 |
*/ |
505 | 505 |
setY: function(el, y) { |
506 | 506 |
Y.Dom.setXY(el, [null, y]); |
... | ... | |
509 | 509 |
/** |
510 | 510 |
* Returns the region position of the given element. |
511 | 511 |
* The element must be part of the DOM tree to have a region (display:none or elements not appended return false). |
512 |
* @method getRegion
|
|
513 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements.
|
|
514 |
* @return {Region | Array} A Region or array of Region instances containing "top, left, bottom, right" member data.
|
|
512 |
* @method getRegion |
|
513 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements. |
|
514 |
* @return {Region | Array} A Region or array of Region instances containing "top, left, bottom, right" member data. |
|
515 | 515 |
*/ |
516 | 516 |
getRegion: function(el) { |
517 | 517 |
var f = function(el) { |
... | ... | |
529 | 529 |
|
530 | 530 |
/** |
531 | 531 |
* Returns the width of the client (viewport). |
532 |
* @method getClientWidth
|
|
533 |
* @deprecated Now using getViewportWidth. This interface left intact for back compat.
|
|
534 |
* @return {Int} The width of the viewable area of the page.
|
|
532 |
* @method getClientWidth |
|
533 |
* @deprecated Now using getViewportWidth. This interface left intact for back compat. |
|
534 |
* @return {Int} The width of the viewable area of the page. |
|
535 | 535 |
*/ |
536 | 536 |
getClientWidth: function() { |
537 | 537 |
return Y.Dom.getViewportWidth(); |
... | ... | |
539 | 539 |
|
540 | 540 |
/** |
541 | 541 |
* Returns the height of the client (viewport). |
542 |
* @method getClientHeight
|
|
543 |
* @deprecated Now using getViewportHeight. This interface left intact for back compat.
|
|
544 |
* @return {Int} The height of the viewable area of the page.
|
|
542 |
* @method getClientHeight |
|
543 |
* @deprecated Now using getViewportHeight. This interface left intact for back compat. |
|
544 |
* @return {Int} The height of the viewable area of the page. |
|
545 | 545 |
*/ |
546 | 546 |
getClientHeight: function() { |
547 | 547 |
return Y.Dom.getViewportHeight(); |
... | ... | |
554 | 554 |
* collection in the callback (removing/appending nodes, etc.) will have |
555 | 555 |
* side effects. Instead you should iterate the returned nodes array, |
556 | 556 |
* as you would with the native "getElementsByTagName" method. |
557 |
* @method getElementsByClassName
|
|
558 |
* @param {String} className The class name to match against
|
|
559 |
* @param {String} tag (optional) The tag name of the elements being collected
|
|
560 |
* @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point.
|
|
557 |
* @method getElementsByClassName |
|
558 |
* @param {String} className The class name to match against |
|
559 |
* @param {String} tag (optional) The tag name of the elements being collected |
|
560 |
* @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point. |
|
561 | 561 |
* This element is not included in the className scan. |
562 |
* @param {Function} apply (optional) A function to apply to each element when found
|
|
563 |
* @param {Any} o (optional) An optional arg that is passed to the supplied method
|
|
564 |
* @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o"
|
|
565 |
* @return {Array} An array of elements that have the given class name
|
|
562 |
* @param {Function} apply (optional) A function to apply to each element when found |
|
563 |
* @param {Any} o (optional) An optional arg that is passed to the supplied method |
|
564 |
* @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o" |
|
565 |
* @return {Array} An array of elements that have the given class name |
|
566 | 566 |
*/ |
567 | 567 |
getElementsByClassName: function(className, tag, root, apply, o, overrides) { |
568 | 568 |
tag = tag || '*'; |
... | ... | |
590 | 590 |
|
591 | 591 |
/** |
592 | 592 |
* Determines whether an HTMLElement has the given className. |
593 |
* @method hasClass
|
|
594 |
* @param {String | HTMLElement | Array} el The element or collection to test
|
|
595 |
* @param {String} className the class name to search for
|
|
596 |
* @return {Boolean | Array} A boolean value or array of boolean values
|
|
593 |
* @method hasClass |
|
594 |
* @param {String | HTMLElement | Array} el The element or collection to test |
|
595 |
* @param {String} className the class name to search for |
|
596 |
* @return {Boolean | Array} A boolean value or array of boolean values |
|
597 | 597 |
*/ |
598 | 598 |
hasClass: function(el, className) { |
599 | 599 |
return Y.Dom.batch(el, Y.Dom._hasClass, className); |
... | ... | |
619 | 619 |
|
620 | 620 |
/** |
621 | 621 |
* Adds a class name to a given element or collection of elements. |
622 |
* @method addClass
|
|
623 |
* @param {String | HTMLElement | Array} el The element or collection to add the class to
|
|
624 |
* @param {String} className the class name to add to the class attribute
|
|
625 |
* @return {Boolean | Array} A pass/fail boolean or array of booleans
|
|
622 |
* @method addClass |
|
623 |
* @param {String | HTMLElement | Array} el The element or collection to add the class to |
|
624 |
* @param {String} className the class name to add to the class attribute |
|
625 |
* @return {Boolean | Array} A pass/fail boolean or array of booleans |
|
626 | 626 |
*/ |
627 | 627 |
addClass: function(el, className) { |
628 | 628 |
return Y.Dom.batch(el, Y.Dom._addClass, className); |
... | ... | |
646 | 646 |
|
647 | 647 |
/** |
648 | 648 |
* Removes a class name from a given element or collection of elements. |
649 |
* @method removeClass
|
|
650 |
* @param {String | HTMLElement | Array} el The element or collection to remove the class from
|
|
651 |
* @param {String} className the class name to remove from the class attribute
|
|
652 |
* @return {Boolean | Array} A pass/fail boolean or array of booleans
|
|
649 |
* @method removeClass |
|
650 |
* @param {String | HTMLElement | Array} el The element or collection to remove the class from |
|
651 |
* @param {String} className the class name to remove from the class attribute |
|
652 |
* @return {Boolean | Array} A pass/fail boolean or array of booleans |
|
653 | 653 |
*/ |
654 | 654 |
removeClass: function(el, className) { |
655 | 655 |
return Y.Dom.batch(el, Y.Dom._removeClass, className); |
... | ... | |
685 | 685 |
/** |
686 | 686 |
* Replace a class with another class for a given element or collection of elements. |
687 | 687 |
* If no oldClassName is present, the newClassName is simply added. |
688 |
* @method replaceClass
|
|
689 |
* @param {String | HTMLElement | Array} el The element or collection to remove the class from
|
|
690 |
* @param {String} oldClassName the class name to be replaced
|
|
691 |
* @param {String} newClassName the class name that will be replacing the old class name
|
|
692 |
* @return {Boolean | Array} A pass/fail boolean or array of booleans
|
|
688 |
* @method replaceClass |
|
689 |
* @param {String | HTMLElement | Array} el The element or collection to remove the class from |
|
690 |
* @param {String} oldClassName the class name to be replaced |
|
691 |
* @param {String} newClassName the class name that will be replacing the old class name |
|
692 |
* @return {Boolean | Array} A pass/fail boolean or array of booleans |
|
693 | 693 |
*/ |
694 | 694 |
replaceClass: function(el, oldClassName, newClassName) { |
695 | 695 |
return Y.Dom.batch(el, Y.Dom._replaceClass, { from: oldClassName, to: newClassName }); |
... | ... | |
729 | 729 |
|
730 | 730 |
/** |
731 | 731 |
* Returns an ID and applies it to the element "el", if provided. |
732 |
* @method generateId
|
|
733 |
* @param {String | HTMLElement | Array} el (optional) An optional element array of elements to add an ID to (no ID is added if one is already present).
|
|
734 |
* @param {String} prefix (optional) an optional prefix to use (defaults to "yui-gen").
|
|
735 |
* @return {String | Array} The generated ID, or array of generated IDs (or original ID if already present on an element)
|
|
732 |
* @method generateId |
|
733 |
* @param {String | HTMLElement | Array} el (optional) An optional element array of elements to add an ID to (no ID is added if one is already present). |
|
734 |
* @param {String} prefix (optional) an optional prefix to use (defaults to "yui-gen"). |
|
735 |
* @return {String | Array} The generated ID, or array of generated IDs (or original ID if already present on an element) |
|
736 | 736 |
*/ |
737 | 737 |
generateId: function(el, prefix) { |
738 | 738 |
prefix = prefix || 'yui-gen'; |
... | ... | |
761 | 761 |
|
762 | 762 |
/** |
763 | 763 |
* Determines whether an HTMLElement is an ancestor of another HTML element in the DOM hierarchy. |
764 |
* @method isAncestor
|
|
765 |
* @param {String | HTMLElement} haystack The possible ancestor
|
|
766 |
* @param {String | HTMLElement} needle The possible descendent
|
|
767 |
* @return {Boolean} Whether or not the haystack is an ancestor of needle
|
|
764 |
* @method isAncestor |
|
765 |
* @param {String | HTMLElement} haystack The possible ancestor |
|
766 |
* @param {String | HTMLElement} needle The possible descendent |
|
767 |
* @return {Boolean} Whether or not the haystack is an ancestor of needle |
|
768 | 768 |
*/ |
769 | 769 |
isAncestor: function(haystack, needle) { |
770 | 770 |
haystack = Y.Dom.get(haystack); |
... | ... | |
786 | 786 |
|
787 | 787 |
/** |
788 | 788 |
* Determines whether an HTMLElement is present in the current document. |
789 |
* @method inDocument
|
|
790 |
* @param {String | HTMLElement} el The element to search for
|
|
791 |
* @param {Object} doc An optional document to search, defaults to element's owner document
|
|
792 |
* @return {Boolean} Whether or not the element is present in the current document
|
|
789 |
* @method inDocument |
|
790 |
* @param {String | HTMLElement} el The element to search for |
|
791 |
* @param {Object} doc An optional document to search, defaults to element's owner document |
|
792 |
* @return {Boolean} Whether or not the element is present in the current document |
|
793 | 793 |
*/ |
794 | 794 |
inDocument: function(el, doc) { |
795 | 795 |
return Y.Dom._inDoc(Y.Dom.get(el), doc); |
... | ... | |
812 | 812 |
* collection in the callback (removing/appending nodes, etc.) will have |
813 | 813 |
* side effects. Instead you should iterate the returned nodes array, |
814 | 814 |
* as you would with the native "getElementsByTagName" method. |
815 |
* @method getElementsBy
|
|
816 |
* @param {Function} method - A boolean method for testing elements which receives the element as its only argument.
|
|
817 |
* @param {String} tag (optional) The tag name of the elements being collected
|
|
818 |
* @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point
|
|
819 |
* @param {Function} apply (optional) A function to apply to each element when found
|
|
820 |
* @param {Any} o (optional) An optional arg that is passed to the supplied method
|
|
821 |
* @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o"
|
|
822 |
* @return {Array} Array of HTMLElements
|
|
815 |
* @method getElementsBy |
|
816 |
* @param {Function} method - A boolean method for testing elements which receives the element as its only argument. |
|
817 |
* @param {String} tag (optional) The tag name of the elements being collected |
|
818 |
* @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point |
|
819 |
* @param {Function} apply (optional) A function to apply to each element when found |
|
820 |
* @param {Any} o (optional) An optional arg that is passed to the supplied method |
|
821 |
* @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o" |
|
822 |
* @return {Array} Array of HTMLElements |
|
823 | 823 |
*/ |
824 | 824 |
getElementsBy: function(method, tag, root, apply, o, overrides, firstOnly) { |
825 | 825 |
tag = tag || '*'; |
... | ... | |
853 | 853 |
|
854 | 854 |
/** |
855 | 855 |
* Returns the first HTMLElement that passes the test applied by the supplied boolean method. |
856 |
* @method getElementBy
|
|
857 |
* @param {Function} method - A boolean method for testing elements which receives the element as its only argument.
|
|
858 |
* @param {String} tag (optional) The tag name of the elements being collected
|
|
859 |
* @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point
|
|
860 |
* @return {HTMLElement}
|
|
856 |
* @method getElementBy |
|
857 |
* @param {Function} method - A boolean method for testing elements which receives the element as its only argument. |
|
858 |
* @param {String} tag (optional) The tag name of the elements being collected |
|
859 |
* @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point |
|
860 |
* @return {HTMLElement} |
|
861 | 861 |
*/ |
862 | 862 |
getElementBy: function(method, tag, root) { |
863 | 863 |
return Y.Dom.getElementsBy(method, tag, root, null, null, null, true); |
... | ... | |
866 | 866 |
/** |
867 | 867 |
* Runs the supplied method against each item in the Collection/Array. |
868 | 868 |
* The method is called with the element(s) as the first arg, and the optional param as the second ( method(el, o) ). |
869 |
* @method batch
|
|
870 |
* @param {String | HTMLElement | Array} el (optional) An element or array of elements to apply the method to
|
|
871 |
* @param {Function} method The method to apply to the element(s)
|
|
872 |
* @param {Any} o (optional) An optional arg that is passed to the supplied method
|
|
873 |
* @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o"
|
|
874 |
* @return {Any | Array} The return value(s) from the supplied method
|
|
869 |
* @method batch |
|
870 |
* @param {String | HTMLElement | Array} el (optional) An element or array of elements to apply the method to |
|
871 |
* @param {Function} method The method to apply to the element(s) |
|
872 |
* @param {Any} o (optional) An optional arg that is passed to the supplied method |
|
873 |
* @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o" |
|
874 |
* @return {Any | Array} The return value(s) from the supplied method |
|
875 | 875 |
*/ |
876 | 876 |
batch: function(el, method, o, overrides) { |
877 | 877 |
var collection = [], |
... | ... | |
894 | 894 |
|
895 | 895 |
/** |
896 | 896 |
* Returns the height of the document. |
897 |
* @method getDocumentHeight
|
|
898 |
* @return {Int} The height of the actual document (which includes the body and its margin).
|
|
897 |
* @method getDocumentHeight |
|
898 |
* @return {Int} The height of the actual document (which includes the body and its margin). |
|
899 | 899 |
*/ |
900 | 900 |
getDocumentHeight: function() { |
901 | 901 |
var scrollHeight = (document[COMPAT_MODE] != CSS1_COMPAT || isSafari) ? document.body.scrollHeight : documentElement.scrollHeight, |
... | ... | |
906 | 906 |
|
907 | 907 |
/** |
908 | 908 |
* Returns the width of the document. |
909 |
* @method getDocumentWidth
|
|
910 |
* @return {Int} The width of the actual document (which includes the body and its margin).
|
|
909 |
* @method getDocumentWidth |
|
910 |
* @return {Int} The width of the actual document (which includes the body and its margin). |
|
911 | 911 |
*/ |
912 | 912 |
getDocumentWidth: function() { |
913 | 913 |
var scrollWidth = (document[COMPAT_MODE] != CSS1_COMPAT || isSafari) ? document.body.scrollWidth : documentElement.scrollWidth, |
... | ... | |
917 | 917 |
|
918 | 918 |
/** |
919 | 919 |
* Returns the current height of the viewport. |
920 |
* @method getViewportHeight
|
|
921 |
* @return {Int} The height of the viewable area of the page (excludes scrollbars).
|
|
920 |
* @method getViewportHeight |
|
921 |
* @return {Int} The height of the viewable area of the page (excludes scrollbars). |
|
922 | 922 |
*/ |
923 | 923 |
getViewportHeight: function() { |
924 | 924 |
var height = self.innerHeight, // Safari, Opera |
... | ... | |
935 | 935 |
|
936 | 936 |
/** |
937 | 937 |
* Returns the current width of the viewport. |
938 |
* @method getViewportWidth
|
|
939 |
* @return {Int} The width of the viewable area of the page (excludes scrollbars).
|
|
938 |
* @method getViewportWidth |
|
939 |
* @return {Int} The width of the viewable area of the page (excludes scrollbars). |
|
940 | 940 |
*/ |
941 | 941 |
|
942 | 942 |
getViewportWidth: function() { |
... | ... | |
954 | 954 |
/** |
955 | 955 |
* Returns the nearest ancestor that passes the test applied by supplied boolean method. |
956 | 956 |
* For performance reasons, IDs are not accepted and argument validation omitted. |
957 |
* @method getAncestorBy
|
|
958 |
* @param {HTMLElement} node The HTMLElement to use as the starting point
|
|
959 |
* @param {Function} method - A boolean method for testing elements which receives the element as its only argument.
|
|
960 |
* @return {Object} HTMLElement or null if not found
|
|
957 |
* @method getAncestorBy |
|
958 |
* @param {HTMLElement} node The HTMLElement to use as the starting point |
|
959 |
* @param {Function} method - A boolean method for testing elements which receives the element as its only argument. |
|
960 |
* @return {Object} HTMLElement or null if not found |
|
961 | 961 |
*/ |
962 | 962 |
getAncestorBy: function(node, method) { |
963 | 963 |
while ( (node = node[PARENT_NODE]) ) { // NOTE: assignment |
... | ... | |
971 | 971 |
|
972 | 972 |
/** |
973 | 973 |
* Returns the nearest ancestor with the given className. |
974 |
* @method getAncestorByClassName
|
|
975 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point
|
|
976 |
* @param {String} className
|
|
977 |
* @return {Object} HTMLElement
|
|
974 |
* @method getAncestorByClassName |
|
975 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point |
|
976 |
* @param {String} className |
|
977 |
* @return {Object} HTMLElement |
|
978 | 978 |
*/ |
979 | 979 |
getAncestorByClassName: function(node, className) { |
980 | 980 |
node = Y.Dom.get(node); |
... | ... | |
987 | 987 |
|
988 | 988 |
/** |
989 | 989 |
* Returns the nearest ancestor with the given tagName. |
990 |
* @method getAncestorByTagName
|
|
991 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point
|
|
992 |
* @param {String} tagName
|
|
993 |
* @return {Object} HTMLElement
|
|
990 |
* @method getAncestorByTagName |
|
991 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point |
|
992 |
* @param {String} tagName |
|
993 |
* @return {Object} HTMLElement |
|
994 | 994 |
*/ |
995 | 995 |
getAncestorByTagName: function(node, tagName) { |
996 | 996 |
node = Y.Dom.get(node); |
... | ... | |
1008 | 1008 |
* Returns the previous sibling that is an HTMLElement. |
1009 | 1009 |
* For performance reasons, IDs are not accepted and argument validation omitted. |
1010 | 1010 |
* Returns the nearest HTMLElement sibling if no method provided. |
1011 |
* @method getPreviousSiblingBy
|
|
1012 |
* @param {HTMLElement} node The HTMLElement to use as the starting point
|
|
1013 |
* @param {Function} method A boolean function used to test siblings
|
|
1011 |
* @method getPreviousSiblingBy |
|
1012 |
* @param {HTMLElement} node The HTMLElement to use as the starting point |
|
1013 |
* @param {Function} method A boolean function used to test siblings |
|
1014 | 1014 |
* that receives the sibling node being tested as its only argument |
1015 |
* @return {Object} HTMLElement or null if not found
|
|
1015 |
* @return {Object} HTMLElement or null if not found |
|
1016 | 1016 |
*/ |
1017 | 1017 |
getPreviousSiblingBy: function(node, method) { |
1018 | 1018 |
while (node) { |
... | ... | |
1026 | 1026 |
|
1027 | 1027 |
/** |
1028 | 1028 |
* Returns the previous sibling that is an HTMLElement |
1029 |
* @method getPreviousSibling
|
|
1030 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point
|
|
1031 |
* @return {Object} HTMLElement or null if not found
|
|
1029 |
* @method getPreviousSibling |
|
1030 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point |
|
1031 |
* @return {Object} HTMLElement or null if not found |
|
1032 | 1032 |
*/ |
1033 | 1033 |
getPreviousSibling: function(node) { |
1034 | 1034 |
node = Y.Dom.get(node); |
... | ... | |
1043 | 1043 |
* Returns the next HTMLElement sibling that passes the boolean method. |
1044 | 1044 |
* For performance reasons, IDs are not accepted and argument validation omitted. |
1045 | 1045 |
* Returns the nearest HTMLElement sibling if no method provided. |
1046 |
* @method getNextSiblingBy
|
|
1047 |
* @param {HTMLElement} node The HTMLElement to use as the starting point
|
|
1048 |
* @param {Function} method A boolean function used to test siblings
|
|
1046 |
* @method getNextSiblingBy |
|
1047 |
* @param {HTMLElement} node The HTMLElement to use as the starting point |
|
1048 |
* @param {Function} method A boolean function used to test siblings |
|
1049 | 1049 |
* that receives the sibling node being tested as its only argument |
1050 |
* @return {Object} HTMLElement or null if not found
|
|
1050 |
* @return {Object} HTMLElement or null if not found |
|
1051 | 1051 |
*/ |
1052 | 1052 |
getNextSiblingBy: function(node, method) { |
1053 | 1053 |
while (node) { |
... | ... | |
1061 | 1061 |
|
1062 | 1062 |
/** |
1063 | 1063 |
* Returns the next sibling that is an HTMLElement |
1064 |
* @method getNextSibling
|
|
1065 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point
|
|
1066 |
* @return {Object} HTMLElement or null if not found
|
|
1064 |
* @method getNextSibling |
|
1065 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point |
|
1066 |
* @return {Object} HTMLElement or null if not found |
|
1067 | 1067 |
*/ |
1068 | 1068 |
getNextSibling: function(node) { |
1069 | 1069 |
node = Y.Dom.get(node); |
... | ... | |
1076 | 1076 |
|
1077 | 1077 |
/** |
1078 | 1078 |
* Returns the first HTMLElement child that passes the test method. |
1079 |
* @method getFirstChildBy
|
|
1080 |
* @param {HTMLElement} node The HTMLElement to use as the starting point
|
|
1081 |
* @param {Function} method A boolean function used to test children
|
|
1079 |
* @method getFirstChildBy |
|
1080 |
* @param {HTMLElement} node The HTMLElement to use as the starting point |
|
1081 |
* @param {Function} method A boolean function used to test children |
|
1082 | 1082 |
* that receives the node being tested as its only argument |
1083 |
* @return {Object} HTMLElement or null if not found
|
|
1083 |
* @return {Object} HTMLElement or null if not found |
|
1084 | 1084 |
*/ |
1085 | 1085 |
getFirstChildBy: function(node, method) { |
1086 | 1086 |
var child = ( Y.Dom._testElement(node.firstChild, method) ) ? node.firstChild : null; |
... | ... | |
1089 | 1089 |
|
1090 | 1090 |
/** |
1091 | 1091 |
* Returns the first HTMLElement child. |
1092 |
* @method getFirstChild
|
|
1093 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point
|
|
1094 |
* @return {Object} HTMLElement or null if not found
|
|
1092 |
* @method getFirstChild |
|
1093 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point |
|
1094 |
* @return {Object} HTMLElement or null if not found |
|
1095 | 1095 |
*/ |
1096 | 1096 |
getFirstChild: function(node, method) { |
1097 | 1097 |
node = Y.Dom.get(node); |
... | ... | |
1103 | 1103 |
|
1104 | 1104 |
/** |
1105 | 1105 |
* Returns the last HTMLElement child that passes the test method. |
1106 |
* @method getLastChildBy
|
|
1107 |
* @param {HTMLElement} node The HTMLElement to use as the starting point
|
|
1108 |
* @param {Function} method A boolean function used to test children
|
|
1106 |
* @method getLastChildBy |
|
1107 |
* @param {HTMLElement} node The HTMLElement to use as the starting point |
|
1108 |
* @param {Function} method A boolean function used to test children |
|
1109 | 1109 |
* that receives the node being tested as its only argument |
1110 |
* @return {Object} HTMLElement or null if not found
|
|
1110 |
* @return {Object} HTMLElement or null if not found |
|
1111 | 1111 |
*/ |
1112 | 1112 |
getLastChildBy: function(node, method) { |
1113 | 1113 |
if (!node) { |
... | ... | |
1119 | 1119 |
|
1120 | 1120 |
/** |
1121 | 1121 |
* Returns the last HTMLElement child. |
1122 |
* @method getLastChild
|
|
1123 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point
|
|
1124 |
* @return {Object} HTMLElement or null if not found
|
|
1122 |
* @method getLastChild |
|
1123 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point |
|
1124 |
* @return {Object} HTMLElement or null if not found |
|
1125 | 1125 |
*/ |
1126 | 1126 |
getLastChild: function(node) { |
1127 | 1127 |
node = Y.Dom.get(node); |
... | ... | |
1130 | 1130 |
|
1131 | 1131 |
/** |
1132 | 1132 |
* Returns an array of HTMLElement childNodes that pass the test method. |
1133 |
* @method getChildrenBy
|
|
1134 |
* @param {HTMLElement} node The HTMLElement to start from
|
|
1135 |
* @param {Function} method A boolean function used to test children
|
|
1133 |
* @method getChildrenBy |
|
1134 |
* @param {HTMLElement} node The HTMLElement to start from |
|
1135 |
* @param {Function} method A boolean function used to test children |
|
1136 | 1136 |
* that receives the node being tested as its only argument |
1137 |
* @return {Array} A static array of HTMLElements
|
|
1137 |
* @return {Array} A static array of HTMLElements |
|
1138 | 1138 |
*/ |
1139 | 1139 |
getChildrenBy: function(node, method) { |
1140 | 1140 |
var child = Y.Dom.getFirstChildBy(node, method), |
... | ... | |
1152 | 1152 |
|
1153 | 1153 |
/** |
1154 | 1154 |
* Returns an array of HTMLElement childNodes. |
1155 |
* @method getChildren
|
|
1156 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point
|
|
1157 |
* @return {Array} A static array of HTMLElements
|
|
1155 |
* @method getChildren |
|
1156 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point |
|
1157 |
* @return {Array} A static array of HTMLElements |
|
1158 | 1158 |
*/ |
1159 | 1159 |
getChildren: function(node) { |
1160 | 1160 |
node = Y.Dom.get(node); |
... | ... | |
1166 | 1166 |
|
1167 | 1167 |
/** |
1168 | 1168 |
* Returns the left scroll value of the document |
1169 |
* @method getDocumentScrollLeft
|
|
1170 |
* @param {HTMLDocument} document (optional) The document to get the scroll value of
|
|
1171 |
* @return {Int} The amount that the document is scrolled to the left
|
|
1169 |
* @method getDocumentScrollLeft |
|
1170 |
* @param {HTMLDocument} document (optional) The document to get the scroll value of |
|
1171 |
* @return {Int} The amount that the document is scrolled to the left |
|
1172 | 1172 |
*/ |
1173 | 1173 |
getDocumentScrollLeft: function(doc) { |
1174 | 1174 |
doc = doc || document; |
... | ... | |
1177 | 1177 |
|
1178 | 1178 |
/** |
1179 | 1179 |
* Returns the top scroll value of the document |
1180 |
* @method getDocumentScrollTop
|
|
1181 |
* @param {HTMLDocument} document (optional) The document to get the scroll value of
|
|
1182 |
* @return {Int} The amount that the document is scrolled to the top
|
|
1180 |
* @method getDocumentScrollTop |
|
1181 |
* @param {HTMLDocument} document (optional) The document to get the scroll value of |
|
1182 |
* @return {Int} The amount that the document is scrolled to the top |
|
1183 | 1183 |
*/ |
1184 | 1184 |
getDocumentScrollTop: function(doc) { |
1185 | 1185 |
doc = doc || document; |
... | ... | |
1188 | 1188 |
|
1189 | 1189 |
/** |
1190 | 1190 |
* Inserts the new node as the previous sibling of the reference node |
1191 |
* @method insertBefore
|
|
1192 |
* @param {String | HTMLElement} newNode The node to be inserted
|
|
1193 |
* @param {String | HTMLElement} referenceNode The node to insert the new node before
|
|
1194 |
* @return {HTMLElement} The node that was inserted (or null if insert fails)
|
|
1191 |
* @method insertBefore |
|
1192 |
* @param {String | HTMLElement} newNode The node to be inserted |
|
1193 |
* @param {String | HTMLElement} referenceNode The node to insert the new node before |
|
1194 |
* @return {HTMLElement} The node that was inserted (or null if insert fails) |
|
1195 | 1195 |
*/ |
1196 | 1196 |
insertBefore: function(newNode, referenceNode) { |
1197 | 1197 |
newNode = Y.Dom.get(newNode); |
... | ... | |
1206 | 1206 |
|
1207 | 1207 |
/** |
1208 | 1208 |
* Inserts the new node as the next sibling of the reference node |
1209 |
* @method insertAfter
|
|
1210 |
* @param {String | HTMLElement} newNode The node to be inserted
|
|
1211 |
* @param {String | HTMLElement} referenceNode The node to insert the new node after
|
|
1212 |
* @return {HTMLElement} The node that was inserted (or null if insert fails)
|
|
1209 |
* @method insertAfter |
|
1210 |
* @param {String | HTMLElement} newNode The node to be inserted |
|
1211 |
* @param {String | HTMLElement} referenceNode The node to insert the new node after |
|
1212 |
* @return {HTMLElement} The node that was inserted (or null if insert fails) |
|
1213 | 1213 |
*/ |
1214 | 1214 |
insertAfter: function(newNode, referenceNode) { |
1215 | 1215 |
newNode = Y.Dom.get(newNode); |
... | ... | |
1228 | 1228 |
|
1229 | 1229 |
/** |
1230 | 1230 |
* Creates a Region based on the viewport relative to the document. |
1231 |
* @method getClientRegion
|
|
1232 |
* @return {Region} A Region object representing the viewport which accounts for document scroll
|
|
1231 |
* @method getClientRegion |
|
1232 |
* @return {Region} A Region object representing the viewport which accounts for document scroll |
|
1233 | 1233 |
*/ |
1234 | 1234 |
getClientRegion: function() { |
1235 | 1235 |
var t = Y.Dom.getDocumentScrollTop(), |
... | ... | |
1242 | 1242 |
|
1243 | 1243 |
/** |
1244 | 1244 |
* Provides a normalized attribute interface. |
1245 |
* @method setAttribute
|
|
1246 |
* @param {String | HTMLElement} el The target element for the attribute.
|
|
1247 |
* @param {String} attr The attribute to set.
|
|
1248 |
* @param {String} val The value of the attribute.
|
|
1245 |
* @method setAttribute |
|
1246 |
* @param {String | HTMLElement} el The target element for the attribute. |
|
1247 |
* @param {String} attr The attribute to set. |
|
1248 |
* @param {String} val The value of the attribute. |
|
1249 | 1249 |
*/ |
1250 | 1250 |
setAttribute: function(el, attr, val) { |
1251 | 1251 |
Y.Dom.batch(el, Y.Dom._setAttribute, { attr: attr, val: val }); |
... | ... | |
1268 | 1268 |
|
1269 | 1269 |
/** |
1270 | 1270 |
* Provides a normalized attribute interface. |
1271 |
* @method getAttribute
|
|
1272 |
* @param {String | HTMLElement} el The target element for the attribute.
|
|
1273 |
* @param {String} attr The attribute to get.
|
|
1274 |
* @return {String} The current value of the attribute.
|
|
1271 |
* @method getAttribute |
|
1272 |
* @param {String | HTMLElement} el The target element for the attribute. |
|
1273 |
* @param {String} attr The attribute to get. |
|
1274 |
* @return {String} The current value of the attribute. |
|
1275 | 1275 |
*/ |
1276 | 1276 |
getAttribute: function(el, attr) { |
1277 | 1277 |
return Y.Dom.batch(el, Y.Dom._getAttribute, attr); |
... | ... | |
1392 | 1392 |
|
1393 | 1393 |
/** |
1394 | 1394 |
* The region's top extent |
1395 |
* @property top
|
|
1396 |
* @type Int
|
|
1395 |
* @property top |
|
1396 |
* @type Int |
|
1397 | 1397 |
*/ |
1398 | 1398 |
this.top = t; |
1399 | 1399 |
|
1400 | 1400 |
/** |
1401 | 1401 |
* The region's top extent |
1402 |
* @property y
|
|
1403 |
* @type Int
|
|
1402 |
* @property y |
|
1403 |
* @type Int |
|
1404 | 1404 |
*/ |
1405 | 1405 |
this.y = t; |
1406 | 1406 |
|
1407 | 1407 |
/** |
1408 | 1408 |
* The region's top extent as index, for symmetry with set/getXY |
1409 |
* @property 1
|
|
1410 |
* @type Int
|
|
1409 |
* @property 1 |
|
1410 |
* @type Int |
|
1411 | 1411 |
*/ |
1412 | 1412 |
this[1] = t; |
1413 | 1413 |
|
1414 | 1414 |
/** |
1415 | 1415 |
* The region's right extent |
1416 |
* @property right
|
|
1417 |
* @type int
|
|
1416 |
* @property right |
|
1417 |
* @type int |
|
1418 | 1418 |
*/ |
1419 | 1419 |
this.right = r; |
1420 | 1420 |
|
1421 | 1421 |
/** |
1422 | 1422 |
* The region's bottom extent |
1423 |
* @property bottom
|
|
1424 |
* @type Int
|
|
1423 |
* @property bottom |
|
1424 |
* @type Int |
|
1425 | 1425 |
*/ |
1426 | 1426 |
this.bottom = b; |
1427 | 1427 |
|
1428 | 1428 |
/** |
1429 | 1429 |
* The region's left extent |
1430 |
* @property left
|
|
1431 |
* @type Int
|
|
1430 |
* @property left |
|
1431 |
* @type Int |
|
1432 | 1432 |
*/ |
1433 | 1433 |
this.left = l; |
1434 | 1434 |
|
1435 | 1435 |
/** |
1436 | 1436 |
* The region's left extent |
1437 |
* @property x
|
|
1438 |
* @type Int
|
|
1437 |
* @property x |
|
1438 |
* @type Int |
|
1439 | 1439 |
*/ |
1440 | 1440 |
this.x = l; |
1441 | 1441 |
|
1442 | 1442 |
/** |
1443 | 1443 |
* The region's left extent as index, for symmetry with set/getXY |
1444 |
* @property 0
|
|
1445 |
* @type Int
|
|
1444 |
* @property 0 |
|
1445 |
* @type Int |
|
1446 | 1446 |
*/ |
1447 | 1447 |
this[0] = l; |
1448 | 1448 |
|
1449 | 1449 |
/** |
1450 | 1450 |
* The region's total width |
1451 |
* @property width
|
|
1452 |
* @type Int
|
|
1451 |
* @property width |
|
1452 |
* @type Int |
|
1453 | 1453 |
*/ |
1454 | 1454 |
this.width = this.right - this.left; |
1455 | 1455 |
|
1456 | 1456 |
/** |
1457 | 1457 |
* The region's total height |
1458 |
* @property height
|
|
1459 |
* @type Int
|
|
1458 |
* @property height |
|
1459 |
* @type Int |
|
1460 | 1460 |
*/ |
1461 | 1461 |
this.height = this.bottom - this.top; |
1462 | 1462 |
}; |
Also available in: Unified diff
fixed headerinfos