Revision 1374
Added by Dietmar over 13 years ago
dom-debug.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); |
... | ... | |
206 | 206 |
|
207 | 207 |
/** |
208 | 208 |
* Wrapper for setting style properties of HTMLElements. Normalizes "opacity" across modern browsers. |
209 |
* @method setStyle
|
|
210 |
* @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.
|
|
211 |
* @param {String} property The style property to be set.
|
|
212 |
* @param {String} val The value to apply to the given property.
|
|
209 |
* @method setStyle |
|
210 |
* @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. |
|
211 |
* @param {String} property The style property to be set. |
|
212 |
* @param {String} val The value to apply to the given property. |
|
213 | 213 |
*/ |
214 | 214 |
setStyle: function(el, property, val) { |
215 | 215 |
Y.Dom.batch(el, Y.Dom._setStyle, { prop: property, val: val }); |
... | ... | |
261 | 261 |
/** |
262 | 262 |
* Gets the current position of an element based on page coordinates. |
263 | 263 |
* Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). |
264 |
* @method getXY
|
|
265 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM
|
|
264 |
* @method getXY |
|
265 |
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM |
|
266 | 266 |
* reference, or an Array of IDs and/or HTMLElements |
267 |
* @return {Array} The XY position of the element(s)
|
|
267 |
* @return {Array} The XY position of the element(s) |
|
268 | 268 |
*/ |
269 | 269 |
getXY: function(el) { |
270 | 270 |
return Y.Dom.batch(el, Y.Dom._getXY); |
... | ... | |
400 | 400 |
|
401 | 401 |
/** |
402 | 402 |
* 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). |
403 |
* @method getX
|
|
404 |
* @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
|
|
405 |
* @return {Number | Array} The X position of the element(s)
|
|
403 |
* @method getX |
|
404 |
* @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 |
|
405 |
* @return {Number | Array} The X position of the element(s) |
|
406 | 406 |
*/ |
407 | 407 |
getX: function(el) { |
408 | 408 |
var f = function(el) { |
... | ... | |
414 | 414 |
|
415 | 415 |
/** |
416 | 416 |
* 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). |
417 |
* @method getY
|
|
418 |
* @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
|
|
419 |
* @return {Number | Array} The Y position of the element(s)
|
|
417 |
* @method getY |
|
418 |
* @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 |
|
419 |
* @return {Number | Array} The Y position of the element(s) |
|
420 | 420 |
*/ |
421 | 421 |
getY: function(el) { |
422 | 422 |
var f = function(el) { |
... | ... | |
429 | 429 |
/** |
430 | 430 |
* Set the position of an html element in page coordinates, regardless of how the element is positioned. |
431 | 431 |
* The element(s) must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). |
432 |
* @method setXY
|
|
433 |
* @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
|
|
434 |
* @param {Array} pos Contains X & Y values for new position (coordinates are page-based)
|
|
435 |
* @param {Boolean} noRetry By default we try and set the position a second time if the first fails
|
|
432 |
* @method setXY |
|
433 |
* @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 |
|
434 |
* @param {Array} pos Contains X & Y values for new position (coordinates are page-based) |
|
435 |
* @param {Boolean} noRetry By default we try and set the position a second time if the first fails |
|
436 | 436 |
*/ |
437 | 437 |
setXY: function(el, pos, noRetry) { |
438 | 438 |
Y.Dom.batch(el, Y.Dom._setXY, { pos: pos, noRetry: noRetry }); |
... | ... | |
495 | 495 |
/** |
496 | 496 |
* Set the X position of an html element in page coordinates, regardless of how the element is positioned. |
497 | 497 |
* The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). |
498 |
* @method setX
|
|
499 |
* @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.
|
|
500 |
* @param {Int} x The value to use as the X coordinate for the element(s).
|
|
498 |
* @method setX |
|
499 |
* @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. |
|
500 |
* @param {Int} x The value to use as the X coordinate for the element(s). |
|
501 | 501 |
*/ |
502 | 502 |
setX: function(el, x) { |
503 | 503 |
Y.Dom.setXY(el, [x, null]); |
... | ... | |
506 | 506 |
/** |
507 | 507 |
* Set the Y position of an html element in page coordinates, regardless of how the element is positioned. |
508 | 508 |
* The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). |
509 |
* @method setY
|
|
510 |
* @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.
|
|
511 |
* @param {Int} x To use as the Y coordinate for the element(s).
|
|
509 |
* @method setY |
|
510 |
* @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. |
|
511 |
* @param {Int} x To use as the Y coordinate for the element(s). |
|
512 | 512 |
*/ |
513 | 513 |
setY: function(el, y) { |
514 | 514 |
Y.Dom.setXY(el, [null, y]); |
... | ... | |
517 | 517 |
/** |
518 | 518 |
* Returns the region position of the given element. |
519 | 519 |
* The element must be part of the DOM tree to have a region (display:none or elements not appended return false). |
520 |
* @method getRegion
|
|
521 |
* @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.
|
|
522 |
* @return {Region | Array} A Region or array of Region instances containing "top, left, bottom, right" member data.
|
|
520 |
* @method getRegion |
|
521 |
* @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. |
|
522 |
* @return {Region | Array} A Region or array of Region instances containing "top, left, bottom, right" member data. |
|
523 | 523 |
*/ |
524 | 524 |
getRegion: function(el) { |
525 | 525 |
var f = function(el) { |
... | ... | |
539 | 539 |
|
540 | 540 |
/** |
541 | 541 |
* Returns the width of the client (viewport). |
542 |
* @method getClientWidth
|
|
543 |
* @deprecated Now using getViewportWidth. This interface left intact for back compat.
|
|
544 |
* @return {Int} The width of the viewable area of the page.
|
|
542 |
* @method getClientWidth |
|
543 |
* @deprecated Now using getViewportWidth. This interface left intact for back compat. |
|
544 |
* @return {Int} The width of the viewable area of the page. |
|
545 | 545 |
*/ |
546 | 546 |
getClientWidth: function() { |
547 | 547 |
return Y.Dom.getViewportWidth(); |
... | ... | |
549 | 549 |
|
550 | 550 |
/** |
551 | 551 |
* Returns the height of the client (viewport). |
552 |
* @method getClientHeight
|
|
553 |
* @deprecated Now using getViewportHeight. This interface left intact for back compat.
|
|
554 |
* @return {Int} The height of the viewable area of the page.
|
|
552 |
* @method getClientHeight |
|
553 |
* @deprecated Now using getViewportHeight. This interface left intact for back compat. |
|
554 |
* @return {Int} The height of the viewable area of the page. |
|
555 | 555 |
*/ |
556 | 556 |
getClientHeight: function() { |
557 | 557 |
return Y.Dom.getViewportHeight(); |
... | ... | |
564 | 564 |
* collection in the callback (removing/appending nodes, etc.) will have |
565 | 565 |
* side effects. Instead you should iterate the returned nodes array, |
566 | 566 |
* as you would with the native "getElementsByTagName" method. |
567 |
* @method getElementsByClassName
|
|
568 |
* @param {String} className The class name to match against
|
|
569 |
* @param {String} tag (optional) The tag name of the elements being collected
|
|
570 |
* @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point.
|
|
567 |
* @method getElementsByClassName |
|
568 |
* @param {String} className The class name to match against |
|
569 |
* @param {String} tag (optional) The tag name of the elements being collected |
|
570 |
* @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point. |
|
571 | 571 |
* This element is not included in the className scan. |
572 |
* @param {Function} apply (optional) A function to apply to each element when found
|
|
573 |
* @param {Any} o (optional) An optional arg that is passed to the supplied method
|
|
574 |
* @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o"
|
|
575 |
* @return {Array} An array of elements that have the given class name
|
|
572 |
* @param {Function} apply (optional) A function to apply to each element when found |
|
573 |
* @param {Any} o (optional) An optional arg that is passed to the supplied method |
|
574 |
* @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o" |
|
575 |
* @return {Array} An array of elements that have the given class name |
|
576 | 576 |
*/ |
577 | 577 |
getElementsByClassName: function(className, tag, root, apply, o, overrides) { |
578 | 578 |
tag = tag || '*'; |
... | ... | |
600 | 600 |
|
601 | 601 |
/** |
602 | 602 |
* Determines whether an HTMLElement has the given className. |
603 |
* @method hasClass
|
|
604 |
* @param {String | HTMLElement | Array} el The element or collection to test
|
|
605 |
* @param {String} className the class name to search for
|
|
606 |
* @return {Boolean | Array} A boolean value or array of boolean values
|
|
603 |
* @method hasClass |
|
604 |
* @param {String | HTMLElement | Array} el The element or collection to test |
|
605 |
* @param {String} className the class name to search for |
|
606 |
* @return {Boolean | Array} A boolean value or array of boolean values |
|
607 | 607 |
*/ |
608 | 608 |
hasClass: function(el, className) { |
609 | 609 |
return Y.Dom.batch(el, Y.Dom._hasClass, className); |
... | ... | |
630 | 630 |
|
631 | 631 |
/** |
632 | 632 |
* Adds a class name to a given element or collection of elements. |
633 |
* @method addClass
|
|
634 |
* @param {String | HTMLElement | Array} el The element or collection to add the class to
|
|
635 |
* @param {String} className the class name to add to the class attribute
|
|
636 |
* @return {Boolean | Array} A pass/fail boolean or array of booleans
|
|
633 |
* @method addClass |
|
634 |
* @param {String | HTMLElement | Array} el The element or collection to add the class to |
|
635 |
* @param {String} className the class name to add to the class attribute |
|
636 |
* @return {Boolean | Array} A pass/fail boolean or array of booleans |
|
637 | 637 |
*/ |
638 | 638 |
addClass: function(el, className) { |
639 | 639 |
return Y.Dom.batch(el, Y.Dom._addClass, className); |
... | ... | |
658 | 658 |
|
659 | 659 |
/** |
660 | 660 |
* Removes a class name from a given element or collection of elements. |
661 |
* @method removeClass
|
|
662 |
* @param {String | HTMLElement | Array} el The element or collection to remove the class from
|
|
663 |
* @param {String} className the class name to remove from the class attribute
|
|
664 |
* @return {Boolean | Array} A pass/fail boolean or array of booleans
|
|
661 |
* @method removeClass |
|
662 |
* @param {String | HTMLElement | Array} el The element or collection to remove the class from |
|
663 |
* @param {String} className the class name to remove from the class attribute |
|
664 |
* @return {Boolean | Array} A pass/fail boolean or array of booleans |
|
665 | 665 |
*/ |
666 | 666 |
removeClass: function(el, className) { |
667 | 667 |
return Y.Dom.batch(el, Y.Dom._removeClass, className); |
... | ... | |
699 | 699 |
/** |
700 | 700 |
* Replace a class with another class for a given element or collection of elements. |
701 | 701 |
* If no oldClassName is present, the newClassName is simply added. |
702 |
* @method replaceClass
|
|
703 |
* @param {String | HTMLElement | Array} el The element or collection to remove the class from
|
|
704 |
* @param {String} oldClassName the class name to be replaced
|
|
705 |
* @param {String} newClassName the class name that will be replacing the old class name
|
|
706 |
* @return {Boolean | Array} A pass/fail boolean or array of booleans
|
|
702 |
* @method replaceClass |
|
703 |
* @param {String | HTMLElement | Array} el The element or collection to remove the class from |
|
704 |
* @param {String} oldClassName the class name to be replaced |
|
705 |
* @param {String} newClassName the class name that will be replacing the old class name |
|
706 |
* @return {Boolean | Array} A pass/fail boolean or array of booleans |
|
707 | 707 |
*/ |
708 | 708 |
replaceClass: function(el, oldClassName, newClassName) { |
709 | 709 |
return Y.Dom.batch(el, Y.Dom._replaceClass, { from: oldClassName, to: newClassName }); |
... | ... | |
744 | 744 |
|
745 | 745 |
/** |
746 | 746 |
* Returns an ID and applies it to the element "el", if provided. |
747 |
* @method generateId
|
|
748 |
* @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).
|
|
749 |
* @param {String} prefix (optional) an optional prefix to use (defaults to "yui-gen").
|
|
750 |
* @return {String | Array} The generated ID, or array of generated IDs (or original ID if already present on an element)
|
|
747 |
* @method generateId |
|
748 |
* @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). |
|
749 |
* @param {String} prefix (optional) an optional prefix to use (defaults to "yui-gen"). |
|
750 |
* @return {String | Array} The generated ID, or array of generated IDs (or original ID if already present on an element) |
|
751 | 751 |
*/ |
752 | 752 |
generateId: function(el, prefix) { |
753 | 753 |
prefix = prefix || 'yui-gen'; |
... | ... | |
778 | 778 |
|
779 | 779 |
/** |
780 | 780 |
* Determines whether an HTMLElement is an ancestor of another HTML element in the DOM hierarchy. |
781 |
* @method isAncestor
|
|
782 |
* @param {String | HTMLElement} haystack The possible ancestor
|
|
783 |
* @param {String | HTMLElement} needle The possible descendent
|
|
784 |
* @return {Boolean} Whether or not the haystack is an ancestor of needle
|
|
781 |
* @method isAncestor |
|
782 |
* @param {String | HTMLElement} haystack The possible ancestor |
|
783 |
* @param {String | HTMLElement} needle The possible descendent |
|
784 |
* @return {Boolean} Whether or not the haystack is an ancestor of needle |
|
785 | 785 |
*/ |
786 | 786 |
isAncestor: function(haystack, needle) { |
787 | 787 |
haystack = Y.Dom.get(haystack); |
... | ... | |
805 | 805 |
|
806 | 806 |
/** |
807 | 807 |
* Determines whether an HTMLElement is present in the current document. |
808 |
* @method inDocument
|
|
809 |
* @param {String | HTMLElement} el The element to search for
|
|
810 |
* @param {Object} doc An optional document to search, defaults to element's owner document
|
|
811 |
* @return {Boolean} Whether or not the element is present in the current document
|
|
808 |
* @method inDocument |
|
809 |
* @param {String | HTMLElement} el The element to search for |
|
810 |
* @param {Object} doc An optional document to search, defaults to element's owner document |
|
811 |
* @return {Boolean} Whether or not the element is present in the current document |
|
812 | 812 |
*/ |
813 | 813 |
inDocument: function(el, doc) { |
814 | 814 |
return Y.Dom._inDoc(Y.Dom.get(el), doc); |
... | ... | |
832 | 832 |
* collection in the callback (removing/appending nodes, etc.) will have |
833 | 833 |
* side effects. Instead you should iterate the returned nodes array, |
834 | 834 |
* as you would with the native "getElementsByTagName" method. |
835 |
* @method getElementsBy
|
|
836 |
* @param {Function} method - A boolean method for testing elements which receives the element as its only argument.
|
|
837 |
* @param {String} tag (optional) The tag name of the elements being collected
|
|
838 |
* @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point
|
|
839 |
* @param {Function} apply (optional) A function to apply to each element when found
|
|
840 |
* @param {Any} o (optional) An optional arg that is passed to the supplied method
|
|
841 |
* @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o"
|
|
842 |
* @return {Array} Array of HTMLElements
|
|
835 |
* @method getElementsBy |
|
836 |
* @param {Function} method - A boolean method for testing elements which receives the element as its only argument. |
|
837 |
* @param {String} tag (optional) The tag name of the elements being collected |
|
838 |
* @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point |
|
839 |
* @param {Function} apply (optional) A function to apply to each element when found |
|
840 |
* @param {Any} o (optional) An optional arg that is passed to the supplied method |
|
841 |
* @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o" |
|
842 |
* @return {Array} Array of HTMLElements |
|
843 | 843 |
*/ |
844 | 844 |
getElementsBy: function(method, tag, root, apply, o, overrides, firstOnly) { |
845 | 845 |
tag = tag || '*'; |
... | ... | |
874 | 874 |
|
875 | 875 |
/** |
876 | 876 |
* Returns the first HTMLElement that passes the test applied by the supplied boolean method. |
877 |
* @method getElementBy
|
|
878 |
* @param {Function} method - A boolean method for testing elements which receives the element as its only argument.
|
|
879 |
* @param {String} tag (optional) The tag name of the elements being collected
|
|
880 |
* @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point
|
|
881 |
* @return {HTMLElement}
|
|
877 |
* @method getElementBy |
|
878 |
* @param {Function} method - A boolean method for testing elements which receives the element as its only argument. |
|
879 |
* @param {String} tag (optional) The tag name of the elements being collected |
|
880 |
* @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point |
|
881 |
* @return {HTMLElement} |
|
882 | 882 |
*/ |
883 | 883 |
getElementBy: function(method, tag, root) { |
884 | 884 |
return Y.Dom.getElementsBy(method, tag, root, null, null, null, true); |
... | ... | |
887 | 887 |
/** |
888 | 888 |
* Runs the supplied method against each item in the Collection/Array. |
889 | 889 |
* The method is called with the element(s) as the first arg, and the optional param as the second ( method(el, o) ). |
890 |
* @method batch
|
|
891 |
* @param {String | HTMLElement | Array} el (optional) An element or array of elements to apply the method to
|
|
892 |
* @param {Function} method The method to apply to the element(s)
|
|
893 |
* @param {Any} o (optional) An optional arg that is passed to the supplied method
|
|
894 |
* @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o"
|
|
895 |
* @return {Any | Array} The return value(s) from the supplied method
|
|
890 |
* @method batch |
|
891 |
* @param {String | HTMLElement | Array} el (optional) An element or array of elements to apply the method to |
|
892 |
* @param {Function} method The method to apply to the element(s) |
|
893 |
* @param {Any} o (optional) An optional arg that is passed to the supplied method |
|
894 |
* @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o" |
|
895 |
* @return {Any | Array} The return value(s) from the supplied method |
|
896 | 896 |
*/ |
897 | 897 |
batch: function(el, method, o, overrides) { |
898 | 898 |
var collection = [], |
... | ... | |
916 | 916 |
|
917 | 917 |
/** |
918 | 918 |
* Returns the height of the document. |
919 |
* @method getDocumentHeight
|
|
920 |
* @return {Int} The height of the actual document (which includes the body and its margin).
|
|
919 |
* @method getDocumentHeight |
|
920 |
* @return {Int} The height of the actual document (which includes the body and its margin). |
|
921 | 921 |
*/ |
922 | 922 |
getDocumentHeight: function() { |
923 | 923 |
var scrollHeight = (document[COMPAT_MODE] != CSS1_COMPAT || isSafari) ? document.body.scrollHeight : documentElement.scrollHeight, |
... | ... | |
929 | 929 |
|
930 | 930 |
/** |
931 | 931 |
* Returns the width of the document. |
932 |
* @method getDocumentWidth
|
|
933 |
* @return {Int} The width of the actual document (which includes the body and its margin).
|
|
932 |
* @method getDocumentWidth |
|
933 |
* @return {Int} The width of the actual document (which includes the body and its margin). |
|
934 | 934 |
*/ |
935 | 935 |
getDocumentWidth: function() { |
936 | 936 |
var scrollWidth = (document[COMPAT_MODE] != CSS1_COMPAT || isSafari) ? document.body.scrollWidth : documentElement.scrollWidth, |
... | ... | |
941 | 941 |
|
942 | 942 |
/** |
943 | 943 |
* Returns the current height of the viewport. |
944 |
* @method getViewportHeight
|
|
945 |
* @return {Int} The height of the viewable area of the page (excludes scrollbars).
|
|
944 |
* @method getViewportHeight |
|
945 |
* @return {Int} The height of the viewable area of the page (excludes scrollbars). |
|
946 | 946 |
*/ |
947 | 947 |
getViewportHeight: function() { |
948 | 948 |
var height = self.innerHeight, // Safari, Opera |
... | ... | |
960 | 960 |
|
961 | 961 |
/** |
962 | 962 |
* Returns the current width of the viewport. |
963 |
* @method getViewportWidth
|
|
964 |
* @return {Int} The width of the viewable area of the page (excludes scrollbars).
|
|
963 |
* @method getViewportWidth |
|
964 |
* @return {Int} The width of the viewable area of the page (excludes scrollbars). |
|
965 | 965 |
*/ |
966 | 966 |
|
967 | 967 |
getViewportWidth: function() { |
... | ... | |
980 | 980 |
/** |
981 | 981 |
* Returns the nearest ancestor that passes the test applied by supplied boolean method. |
982 | 982 |
* For performance reasons, IDs are not accepted and argument validation omitted. |
983 |
* @method getAncestorBy
|
|
984 |
* @param {HTMLElement} node The HTMLElement to use as the starting point
|
|
985 |
* @param {Function} method - A boolean method for testing elements which receives the element as its only argument.
|
|
986 |
* @return {Object} HTMLElement or null if not found
|
|
983 |
* @method getAncestorBy |
|
984 |
* @param {HTMLElement} node The HTMLElement to use as the starting point |
|
985 |
* @param {Function} method - A boolean method for testing elements which receives the element as its only argument. |
|
986 |
* @return {Object} HTMLElement or null if not found |
|
987 | 987 |
*/ |
988 | 988 |
getAncestorBy: function(node, method) { |
989 | 989 |
while ( (node = node[PARENT_NODE]) ) { // NOTE: assignment |
... | ... | |
999 | 999 |
|
1000 | 1000 |
/** |
1001 | 1001 |
* Returns the nearest ancestor with the given className. |
1002 |
* @method getAncestorByClassName
|
|
1003 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point
|
|
1004 |
* @param {String} className
|
|
1005 |
* @return {Object} HTMLElement
|
|
1002 |
* @method getAncestorByClassName |
|
1003 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point |
|
1004 |
* @param {String} className |
|
1005 |
* @return {Object} HTMLElement |
|
1006 | 1006 |
*/ |
1007 | 1007 |
getAncestorByClassName: function(node, className) { |
1008 | 1008 |
node = Y.Dom.get(node); |
... | ... | |
1016 | 1016 |
|
1017 | 1017 |
/** |
1018 | 1018 |
* Returns the nearest ancestor with the given tagName. |
1019 |
* @method getAncestorByTagName
|
|
1020 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point
|
|
1021 |
* @param {String} tagName
|
|
1022 |
* @return {Object} HTMLElement
|
|
1019 |
* @method getAncestorByTagName |
|
1020 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point |
|
1021 |
* @param {String} tagName |
|
1022 |
* @return {Object} HTMLElement |
|
1023 | 1023 |
*/ |
1024 | 1024 |
getAncestorByTagName: function(node, tagName) { |
1025 | 1025 |
node = Y.Dom.get(node); |
... | ... | |
1038 | 1038 |
* Returns the previous sibling that is an HTMLElement. |
1039 | 1039 |
* For performance reasons, IDs are not accepted and argument validation omitted. |
1040 | 1040 |
* Returns the nearest HTMLElement sibling if no method provided. |
1041 |
* @method getPreviousSiblingBy
|
|
1042 |
* @param {HTMLElement} node The HTMLElement to use as the starting point
|
|
1043 |
* @param {Function} method A boolean function used to test siblings
|
|
1041 |
* @method getPreviousSiblingBy |
|
1042 |
* @param {HTMLElement} node The HTMLElement to use as the starting point |
|
1043 |
* @param {Function} method A boolean function used to test siblings |
|
1044 | 1044 |
* that receives the sibling node being tested as its only argument |
1045 |
* @return {Object} HTMLElement or null if not found
|
|
1045 |
* @return {Object} HTMLElement or null if not found |
|
1046 | 1046 |
*/ |
1047 | 1047 |
getPreviousSiblingBy: function(node, method) { |
1048 | 1048 |
while (node) { |
... | ... | |
1056 | 1056 |
|
1057 | 1057 |
/** |
1058 | 1058 |
* Returns the previous sibling that is an HTMLElement |
1059 |
* @method getPreviousSibling
|
|
1060 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point
|
|
1061 |
* @return {Object} HTMLElement or null if not found
|
|
1059 |
* @method getPreviousSibling |
|
1060 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point |
|
1061 |
* @return {Object} HTMLElement or null if not found |
|
1062 | 1062 |
*/ |
1063 | 1063 |
getPreviousSibling: function(node) { |
1064 | 1064 |
node = Y.Dom.get(node); |
... | ... | |
1074 | 1074 |
* Returns the next HTMLElement sibling that passes the boolean method. |
1075 | 1075 |
* For performance reasons, IDs are not accepted and argument validation omitted. |
1076 | 1076 |
* Returns the nearest HTMLElement sibling if no method provided. |
1077 |
* @method getNextSiblingBy
|
|
1078 |
* @param {HTMLElement} node The HTMLElement to use as the starting point
|
|
1079 |
* @param {Function} method A boolean function used to test siblings
|
|
1077 |
* @method getNextSiblingBy |
|
1078 |
* @param {HTMLElement} node The HTMLElement to use as the starting point |
|
1079 |
* @param {Function} method A boolean function used to test siblings |
|
1080 | 1080 |
* that receives the sibling node being tested as its only argument |
1081 |
* @return {Object} HTMLElement or null if not found
|
|
1081 |
* @return {Object} HTMLElement or null if not found |
|
1082 | 1082 |
*/ |
1083 | 1083 |
getNextSiblingBy: function(node, method) { |
1084 | 1084 |
while (node) { |
... | ... | |
1092 | 1092 |
|
1093 | 1093 |
/** |
1094 | 1094 |
* Returns the next sibling that is an HTMLElement |
1095 |
* @method getNextSibling
|
|
1096 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point
|
|
1097 |
* @return {Object} HTMLElement or null if not found
|
|
1095 |
* @method getNextSibling |
|
1096 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point |
|
1097 |
* @return {Object} HTMLElement or null if not found |
|
1098 | 1098 |
*/ |
1099 | 1099 |
getNextSibling: function(node) { |
1100 | 1100 |
node = Y.Dom.get(node); |
... | ... | |
1108 | 1108 |
|
1109 | 1109 |
/** |
1110 | 1110 |
* Returns the first HTMLElement child that passes the test method. |
1111 |
* @method getFirstChildBy
|
|
1112 |
* @param {HTMLElement} node The HTMLElement to use as the starting point
|
|
1113 |
* @param {Function} method A boolean function used to test children
|
|
1111 |
* @method getFirstChildBy |
|
1112 |
* @param {HTMLElement} node The HTMLElement to use as the starting point |
|
1113 |
* @param {Function} method A boolean function used to test children |
|
1114 | 1114 |
* that receives the node being tested as its only argument |
1115 |
* @return {Object} HTMLElement or null if not found
|
|
1115 |
* @return {Object} HTMLElement or null if not found |
|
1116 | 1116 |
*/ |
1117 | 1117 |
getFirstChildBy: function(node, method) { |
1118 | 1118 |
var child = ( Y.Dom._testElement(node.firstChild, method) ) ? node.firstChild : null; |
... | ... | |
1121 | 1121 |
|
1122 | 1122 |
/** |
1123 | 1123 |
* Returns the first HTMLElement child. |
1124 |
* @method getFirstChild
|
|
1125 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point
|
|
1126 |
* @return {Object} HTMLElement or null if not found
|
|
1124 |
* @method getFirstChild |
|
1125 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point |
|
1126 |
* @return {Object} HTMLElement or null if not found |
|
1127 | 1127 |
*/ |
1128 | 1128 |
getFirstChild: function(node, method) { |
1129 | 1129 |
node = Y.Dom.get(node); |
... | ... | |
1136 | 1136 |
|
1137 | 1137 |
/** |
1138 | 1138 |
* Returns the last HTMLElement child that passes the test method. |
1139 |
* @method getLastChildBy
|
|
1140 |
* @param {HTMLElement} node The HTMLElement to use as the starting point
|
|
1141 |
* @param {Function} method A boolean function used to test children
|
|
1139 |
* @method getLastChildBy |
|
1140 |
* @param {HTMLElement} node The HTMLElement to use as the starting point |
|
1141 |
* @param {Function} method A boolean function used to test children |
|
1142 | 1142 |
* that receives the node being tested as its only argument |
1143 |
* @return {Object} HTMLElement or null if not found
|
|
1143 |
* @return {Object} HTMLElement or null if not found |
|
1144 | 1144 |
*/ |
1145 | 1145 |
getLastChildBy: function(node, method) { |
1146 | 1146 |
if (!node) { |
... | ... | |
1153 | 1153 |
|
1154 | 1154 |
/** |
1155 | 1155 |
* Returns the last HTMLElement child. |
1156 |
* @method getLastChild
|
|
1157 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point
|
|
1158 |
* @return {Object} HTMLElement or null if not found
|
|
1156 |
* @method getLastChild |
|
1157 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point |
|
1158 |
* @return {Object} HTMLElement or null if not found |
|
1159 | 1159 |
*/ |
1160 | 1160 |
getLastChild: function(node) { |
1161 | 1161 |
node = Y.Dom.get(node); |
... | ... | |
1164 | 1164 |
|
1165 | 1165 |
/** |
1166 | 1166 |
* Returns an array of HTMLElement childNodes that pass the test method. |
1167 |
* @method getChildrenBy
|
|
1168 |
* @param {HTMLElement} node The HTMLElement to start from
|
|
1169 |
* @param {Function} method A boolean function used to test children
|
|
1167 |
* @method getChildrenBy |
|
1168 |
* @param {HTMLElement} node The HTMLElement to start from |
|
1169 |
* @param {Function} method A boolean function used to test children |
|
1170 | 1170 |
* that receives the node being tested as its only argument |
1171 |
* @return {Array} A static array of HTMLElements
|
|
1171 |
* @return {Array} A static array of HTMLElements |
|
1172 | 1172 |
*/ |
1173 | 1173 |
getChildrenBy: function(node, method) { |
1174 | 1174 |
var child = Y.Dom.getFirstChildBy(node, method), |
... | ... | |
1186 | 1186 |
|
1187 | 1187 |
/** |
1188 | 1188 |
* Returns an array of HTMLElement childNodes. |
1189 |
* @method getChildren
|
|
1190 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point
|
|
1191 |
* @return {Array} A static array of HTMLElements
|
|
1189 |
* @method getChildren |
|
1190 |
* @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point |
|
1191 |
* @return {Array} A static array of HTMLElements |
|
1192 | 1192 |
*/ |
1193 | 1193 |
getChildren: function(node) { |
1194 | 1194 |
node = Y.Dom.get(node); |
... | ... | |
1201 | 1201 |
|
1202 | 1202 |
/** |
1203 | 1203 |
* Returns the left scroll value of the document |
1204 |
* @method getDocumentScrollLeft
|
|
1205 |
* @param {HTMLDocument} document (optional) The document to get the scroll value of
|
|
1206 |
* @return {Int} The amount that the document is scrolled to the left
|
|
1204 |
* @method getDocumentScrollLeft |
|
1205 |
* @param {HTMLDocument} document (optional) The document to get the scroll value of |
|
1206 |
* @return {Int} The amount that the document is scrolled to the left |
|
1207 | 1207 |
*/ |
1208 | 1208 |
getDocumentScrollLeft: function(doc) { |
1209 | 1209 |
doc = doc || document; |
... | ... | |
1212 | 1212 |
|
1213 | 1213 |
/** |
1214 | 1214 |
* Returns the top scroll value of the document |
1215 |
* @method getDocumentScrollTop
|
|
1216 |
* @param {HTMLDocument} document (optional) The document to get the scroll value of
|
|
1217 |
* @return {Int} The amount that the document is scrolled to the top
|
|
1215 |
* @method getDocumentScrollTop |
|
1216 |
* @param {HTMLDocument} document (optional) The document to get the scroll value of |
|
1217 |
* @return {Int} The amount that the document is scrolled to the top |
|
1218 | 1218 |
*/ |
1219 | 1219 |
getDocumentScrollTop: function(doc) { |
1220 | 1220 |
doc = doc || document; |
... | ... | |
1223 | 1223 |
|
1224 | 1224 |
/** |
1225 | 1225 |
* Inserts the new node as the previous sibling of the reference node |
1226 |
* @method insertBefore
|
|
1227 |
* @param {String | HTMLElement} newNode The node to be inserted
|
|
1228 |
* @param {String | HTMLElement} referenceNode The node to insert the new node before
|
|
1229 |
* @return {HTMLElement} The node that was inserted (or null if insert fails)
|
|
1226 |
* @method insertBefore |
|
1227 |
* @param {String | HTMLElement} newNode The node to be inserted |
|
1228 |
* @param {String | HTMLElement} referenceNode The node to insert the new node before |
|
1229 |
* @return {HTMLElement} The node that was inserted (or null if insert fails) |
|
1230 | 1230 |
*/ |
1231 | 1231 |
insertBefore: function(newNode, referenceNode) { |
1232 | 1232 |
newNode = Y.Dom.get(newNode); |
... | ... | |
1242 | 1242 |
|
1243 | 1243 |
/** |
1244 | 1244 |
* Inserts the new node as the next sibling of the reference node |
1245 |
* @method insertAfter
|
|
1246 |
* @param {String | HTMLElement} newNode The node to be inserted
|
|
1247 |
* @param {String | HTMLElement} referenceNode The node to insert the new node after
|
|
1248 |
* @return {HTMLElement} The node that was inserted (or null if insert fails)
|
|
1245 |
* @method insertAfter |
|
1246 |
* @param {String | HTMLElement} newNode The node to be inserted |
|
1247 |
* @param {String | HTMLElement} referenceNode The node to insert the new node after |
|
1248 |
* @return {HTMLElement} The node that was inserted (or null if insert fails) |
|
1249 | 1249 |
*/ |
1250 | 1250 |
insertAfter: function(newNode, referenceNode) { |
1251 | 1251 |
newNode = Y.Dom.get(newNode); |
... | ... | |
1265 | 1265 |
|
1266 | 1266 |
/** |
1267 | 1267 |
* Creates a Region based on the viewport relative to the document. |
1268 |
* @method getClientRegion
|
|
1269 |
* @return {Region} A Region object representing the viewport which accounts for document scroll
|
|
1268 |
* @method getClientRegion |
|
1269 |
* @return {Region} A Region object representing the viewport which accounts for document scroll |
|
1270 | 1270 |
*/ |
1271 | 1271 |
getClientRegion: function() { |
1272 | 1272 |
var t = Y.Dom.getDocumentScrollTop(), |
... | ... | |
1279 | 1279 |
|
1280 | 1280 |
/** |
1281 | 1281 |
* Provides a normalized attribute interface. |
1282 |
* @method setAttribute
|
|
1283 |
* @param {String | HTMLElement} el The target element for the attribute.
|
|
1284 |
* @param {String} attr The attribute to set.
|
|
1285 |
* @param {String} val The value of the attribute.
|
|
1282 |
* @method setAttribute |
|
1283 |
* @param {String | HTMLElement} el The target element for the attribute. |
|
1284 |
* @param {String} attr The attribute to set. |
|
1285 |
* @param {String} val The value of the attribute. |
|
1286 | 1286 |
*/ |
1287 | 1287 |
setAttribute: function(el, attr, val) { |
1288 | 1288 |
Y.Dom.batch(el, Y.Dom._setAttribute, { attr: attr, val: val }); |
... | ... | |
1306 | 1306 |
|
1307 | 1307 |
/** |
1308 | 1308 |
* Provides a normalized attribute interface. |
1309 |
* @method getAttribute
|
|
1310 |
* @param {String | HTMLElement} el The target element for the attribute.
|
|
1311 |
* @param {String} attr The attribute to get.
|
|
1312 |
* @return {String} The current value of the attribute.
|
|
1309 |
* @method getAttribute |
|
1310 |
* @param {String | HTMLElement} el The target element for the attribute. |
|
1311 |
* @param {String} attr The attribute to get. |
|
1312 |
* @return {String} The current value of the attribute. |
|
1313 | 1313 |
*/ |
1314 | 1314 |
getAttribute: function(el, attr) { |
1315 | 1315 |
return Y.Dom.batch(el, Y.Dom._getAttribute, attr); |
... | ... | |
1431 | 1431 |
|
1432 | 1432 |
/** |
1433 | 1433 |
* The region's top extent |
1434 |
* @property top
|
|
1435 |
* @type Int
|
|
1434 |
* @property top |
|
1435 |
* @type Int |
|
1436 | 1436 |
*/ |
1437 | 1437 |
this.top = t; |
1438 | 1438 |
|
1439 | 1439 |
/** |
1440 | 1440 |
* The region's top extent |
1441 |
* @property y
|
|
1442 |
* @type Int
|
|
1441 |
* @property y |
|
1442 |
* @type Int |
|
1443 | 1443 |
*/ |
1444 | 1444 |
this.y = t; |
1445 | 1445 |
|
1446 | 1446 |
/** |
1447 | 1447 |
* The region's top extent as index, for symmetry with set/getXY |
1448 |
* @property 1
|
|
1449 |
* @type Int
|
|
1448 |
* @property 1 |
|
1449 |
* @type Int |
|
1450 | 1450 |
*/ |
1451 | 1451 |
this[1] = t; |
1452 | 1452 |
|
1453 | 1453 |
/** |
1454 | 1454 |
* The region's right extent |
1455 |
* @property right
|
|
1456 |
* @type int
|
|
1455 |
* @property right |
|
1456 |
* @type int |
|
1457 | 1457 |
*/ |
1458 | 1458 |
this.right = r; |
1459 | 1459 |
|
1460 | 1460 |
/** |
1461 | 1461 |
* The region's bottom extent |
1462 |
* @property bottom
|
|
1463 |
* @type Int
|
|
1462 |
* @property bottom |
|
1463 |
* @type Int |
|
1464 | 1464 |
*/ |
1465 | 1465 |
this.bottom = b; |
1466 | 1466 |
|
1467 | 1467 |
/** |
1468 | 1468 |
* The region's left extent |
1469 |
* @property left
|
|
1470 |
* @type Int
|
|
1469 |
* @property left |
|
1470 |
* @type Int |
|
1471 | 1471 |
*/ |
1472 | 1472 |
this.left = l; |
1473 | 1473 |
|
1474 | 1474 |
/** |
1475 | 1475 |
* The region's left extent |
1476 |
* @property x
|
|
1477 |
* @type Int
|
|
1476 |
* @property x |
|
1477 |
* @type Int |
|
1478 | 1478 |
*/ |
1479 | 1479 |
this.x = l; |
1480 | 1480 |
|
1481 | 1481 |
/** |
1482 | 1482 |
* The region's left extent as index, for symmetry with set/getXY |
1483 |
* @property 0
|
|
1484 |
* @type Int
|
|
1483 |
* @property 0 |
|
1484 |
* @type Int |
|
1485 | 1485 |
*/ |
1486 | 1486 |
this[0] = l; |
1487 | 1487 |
|
1488 | 1488 |
/** |
1489 | 1489 |
* The region's total width |
1490 |
* @property width
|
|
1491 |
* @type Int
|
|
1490 |
* @property width |
|
1491 |
* @type Int |
|
1492 | 1492 |
*/ |
1493 | 1493 |
this.width = this.right - this.left; |
1494 | 1494 |
|
1495 | 1495 |
/** |
1496 | 1496 |
* The region's total height |
1497 |
* @property height
|
|
1498 |
* @type Int
|
|
1497 |
* @property height |
|
1498 |
* @type Int |
|
1499 | 1499 |
*/ |
1500 | 1500 |
this.height = this.bottom - this.top; |
1501 | 1501 |
}; |
Also available in: Unified diff
fixed headerinfos