diff --git a/js/angular/controller/scrollController.js b/js/angular/controller/scrollController.js index 5f2c9e5940..e5c997c37e 100644 --- a/js/angular/controller/scrollController.js +++ b/js/angular/controller/scrollController.js @@ -134,12 +134,14 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca }; this.scrollTop = function(shouldAnimate) { + ionic.DomUtil.blurAll(); this.resize().then(function() { scrollView.scrollTo(0, 0, !!shouldAnimate); }); }; this.scrollBottom = function(shouldAnimate) { + ionic.DomUtil.blurAll(); this.resize().then(function() { var max = scrollView.getScrollMax(); scrollView.scrollTo(max.left, max.top, !!shouldAnimate); @@ -147,30 +149,35 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca }; this.scrollTo = function(left, top, shouldAnimate) { + ionic.DomUtil.blurAll(); this.resize().then(function() { scrollView.scrollTo(left, top, !!shouldAnimate); }); }; this.zoomTo = function(zoom, shouldAnimate, originLeft, originTop) { + ionic.DomUtil.blurAll(); this.resize().then(function() { scrollView.zoomTo(zoom, !!shouldAnimate, originLeft, originTop); }); }; this.zoomBy = function(zoom, shouldAnimate, originLeft, originTop) { + ionic.DomUtil.blurAll(); this.resize().then(function() { scrollView.zoomBy(zoom, !!shouldAnimate, originLeft, originTop); }); }; this.scrollBy = function(left, top, shouldAnimate) { + ionic.DomUtil.blurAll(); this.resize().then(function() { scrollView.scrollBy(left, top, !!shouldAnimate); }); }; this.anchorScroll = function(shouldAnimate) { + ionic.DomUtil.blurAll(); this.resize().then(function() { var hash = $location.hash(); var elm = hash && $document[0].getElementById(hash); @@ -201,6 +208,7 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca this._rememberScrollId = null; }; this.scrollToRememberedPosition = function(shouldAnimate) { + ionic.DomUtil.blurAll(); var values = $$scrollValueCache[this._rememberScrollId]; if (values) { this.resize().then(function() { diff --git a/js/utils/dom.js b/js/utils/dom.js index 43fbbbb283..bddcca6df2 100644 --- a/js/utils/dom.js +++ b/js/utils/dom.js @@ -14,7 +14,7 @@ if (!isDomReady){ document.addEventListener('DOMContentLoaded', domReady); } - + // From the man himself, Mr. Paul Irish. // The requestAnimationFrame polyfill @@ -254,6 +254,20 @@ if(x < x1 || x > x2) return false; if(y < y1 || y > y2) return false; return true; + }, + /** + * @ngdoc method + * @name ionic.DomUtil#blurAll + * @description + * Blurs any currently focused input element + * @returns {DOMElement} The element blurred or null + */ + blurAll: function() { + if (document.activeElement && document.activeElement != document.body){ + document.activeElement.blur(); + return document.activeElement; + } + return null; } }; diff --git a/test/html/scroll-set-top.html b/test/html/scroll-set-top.html new file mode 100644 index 0000000000..037a716111 --- /dev/null +++ b/test/html/scroll-set-top.html @@ -0,0 +1,75 @@ + + + + + + + Ionic List Directive + + + + + + + + +

Ionic Scroll Top Test

+ + +
+ + + + +
+ Scroll Down +
+ + +

Item {{ item.id }}

+

{{item.id}}

+ +
+ +
+ +
+ +
+ +
+ + + +