-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindscrollable.js
More file actions
58 lines (47 loc) · 1.77 KB
/
findscrollable.js
File metadata and controls
58 lines (47 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(function( $ )
{
if ($.fn)
{
$.fn.findScrollable = function() {
var hasHorizontalScrollbar;
var hasVerticalScrollbar;
var scrollableElements = [];
var defer = $.Deferred();
var elements;
var callback = typeof arguments === 'object' && typeof arguments[0] === 'function' ? arguments[0] : arguments[1];
var elementsArray = typeof arguments === 'object' && typeof arguments[0] === 'object' ? arguments[0] : undefined;
try
{
if (this[0] === window)
{
scrollableElements.push(this);
}
elements = typeof elementsArray === 'object' && elementsArray.join ? ( this[0] === window ? $(elementsArray.join(',')) : this.find(elementsArray.join(','))) : ( this[0] === window ? $('*') : this.find('*'));
elements.each(function(index)
{
hasHorizontalScrollbar = $(this).get(0).scrollWidth>$(this).get(0).clientWidth;
hasVerticalScrollbar = $(this).get(0).scrollHeight>$(this).get(0).clientHeight;
if (hasHorizontalScrollbar || hasVerticalScrollbar)
{
scrollableElements.push($(this));
}
if (index === elements.length - 1)
{
defer.resolve();
}
});
}
catch(e)
{
defer.resolve();
}
defer.promise().done(function()
{
if (typeof callback === 'function')
{
callback(scrollableElements);
}
});
};
}
})( jQuery );