diff options
author | Alexander Schmitz <arschmitz@gmail.com> | 2015-07-15 20:23:44 -0400 |
---|---|---|
committer | Alexander Schmitz <arschmitz@gmail.com> | 2015-08-08 00:29:37 -0400 |
commit | 72bfafbedea4973b803abeefc97637f246b11c89 (patch) | |
tree | 501addde9d778f56695ce48b405e97f86dd72cdc /ui/scroll-parent.js | |
parent | 6064a5e0487428d53bd694dcebce952730992c46 (diff) | |
download | jquery-ui-72bfafbedea4973b803abeefc97637f246b11c89.tar.gz jquery-ui-72bfafbedea4973b803abeefc97637f246b11c89.zip |
Core: Move scrollParent into its own module
Ref #9647
Diffstat (limited to 'ui/scroll-parent.js')
-rw-r--r-- | ui/scroll-parent.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/ui/scroll-parent.js b/ui/scroll-parent.js new file mode 100644 index 000000000..478b86ae3 --- /dev/null +++ b/ui/scroll-parent.js @@ -0,0 +1,42 @@ +/*! + * jQuery UI Scroll Parent @VERSION + * http://jqueryui.com + * + * Copyright jQuery Foundation and other contributors + * Released under the MIT license. + * http://jquery.org/license + */ + +//>>label: scrollParent +//>>group: Core +//>>description: Get the closest ancestor element that is scrollable. +//>>docs: http://api.jqueryui.com/scrollParent/ + +( function( factory ) { + if ( typeof define === "function" && define.amd ) { + + // AMD. Register as an anonymous module. + define( [ "jquery", "./version" ], factory ); + } else { + + // Browser globals + factory( jQuery ); + } +} ( function( $ ) { + +return $.fn.scrollParent = function( includeHidden ) { + var position = this.css( "position" ), + excludeStaticParent = position === "absolute", + overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/, + scrollParent = this.parents().filter( function() { + var parent = $( this ); + if ( excludeStaticParent && parent.css( "position" ) === "static" ) { + return false; + } + return overflowRegex.test( parent.css( "overflow" ) + parent.css( "overflow-y" ) + parent.css( "overflow-x" ) ); + } ).eq( 0 ); + + return position === "fixed" || !scrollParent.length ? $( this[ 0 ].ownerDocument || document ) : scrollParent; +}; + +} ) ); |