Skip to content

Commit

Permalink
Released v0.5.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
oblador committed Apr 12, 2014
1 parent bdcdc59 commit cf540f2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
18 changes: 13 additions & 5 deletions angular-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ run(function($window, requestAnimation, duScrollEasing) {
return proto;
};

var isDocument = function(el) {
return (typeof HTMLDocument !== 'undefined' && el instanceof HTMLDocument) || (el.nodeType && el.nodeType === el.DOCUMENT_NODE);
};

var isElement = function(el) {
return (typeof HTMLElement !== 'undefined' && el instanceof HTMLElement) || (el.nodeType && el.nodeType === el.ELEMENT_NODE);
};

var unwrap = function(el) {
return el instanceof HTMLElement || el instanceof HTMLDocument ? el : el[0];
return isElement(el) || isDocument(el) ? el : el[0];
};

proto.scrollTo = function(left, top, duration, easing) {
Expand All @@ -30,7 +38,7 @@ run(function($window, requestAnimation, duScrollEasing) {
return this.scrollToAnimated.apply(this, arguments);
}
var el = unwrap(this);
if(el instanceof HTMLDocument) {
if(isDocument(el)) {
return $window.scrollTo(left, top);
}
el.scrollLeft = left;
Expand Down Expand Up @@ -65,7 +73,7 @@ run(function($window, requestAnimation, duScrollEasing) {
proto.scrollToElement = function(target, offset, duration, easing) {
var el = unwrap(this);
var top = this.scrollTop() + unwrap(target).getBoundingClientRect().top - offset;
if(el instanceof HTMLElement) {
if(isElement(el)) {
top -= el.getBoundingClientRect().top;
}
this.scrollTo(0, top, duration, easing);
Expand All @@ -76,7 +84,7 @@ run(function($window, requestAnimation, duScrollEasing) {
return this.scrollTo(value, this.scrollTop(), duration, easing);
}
var el = unwrap(this);
if(el instanceof HTMLDocument) {
if(isDocument(el)) {
return $window.scrollX || document.documentElement.scrollLeft || document.body.scrollLeft;
}
return el.scrollLeft;
Expand All @@ -87,7 +95,7 @@ run(function($window, requestAnimation, duScrollEasing) {
return this.scrollTo(this.scrollTop(), value, duration, easing);
}
var el = unwrap(this);
if(el instanceof HTMLDocument) {
if(isDocument(el)) {
return $window.scrollY || document.documentElement.scrollTop || document.body.scrollTop;
}
return el.scrollTop;
Expand Down
2 changes: 1 addition & 1 deletion angular-scroll.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cf540f2

Please sign in to comment.