From d082c0c148380fb44d4a820ee36a0f1e78b668c7 Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Fri, 8 Nov 2013 16:58:14 -0600 Subject: [PATCH] Fixed #56 - pull to drag --- dist/js/ionic-angular.js | 18 +++++++----- dist/js/ionic.js | 29 +++++++++++--------- js/ext/angular/src/directive/ionicContent.js | 18 +++++++----- js/ext/angular/test/content.html | 10 +++---- js/ext/angular/test/tabs.html | 8 +++--- js/views/scrollView.js | 29 +++++++++++--------- 6 files changed, 63 insertions(+), 49 deletions(-) diff --git a/dist/js/ionic-angular.js b/dist/js/ionic-angular.js index 2388f85179..c8d49b2a33 100644 --- a/dist/js/ionic-angular.js +++ b/dist/js/ionic-angular.js @@ -481,13 +481,16 @@ angular.module('ionic.ui.content', []) // The content directive is a core scrollable content area // that is part of many View hierarchies -.directive('content', function() { +.directive('content', ['$parse', function($parse) { return { restrict: 'E', replace: true, template: '
', transclude: true, - scope: true, + scope: { + onRefresh: '&', + onRefreshOpening: '&' + }, compile: function(element, attr, transclude) { return function($scope, $element, $attr) { var c = $element.eq(0); @@ -506,7 +509,6 @@ angular.module('ionic.ui.content', []) c.addClass('has-tabs'); } - // If they want plain overflows scrolling, add that as a class if(attr.overflowScroll === "true") { c.addClass('overflow-scroll'); @@ -514,23 +516,25 @@ angular.module('ionic.ui.content', []) // Otherwise, supercharge this baby! var sv = new ionic.views.Scroll({ el: $element[0].firstElementChild, + hasPullToRefresh: (typeof $scope.onRefresh !== 'undefined'), onRefresh: function() { - $scope.onRefresh && $scope.onRefresh(); + $scope.onRefresh(); }, onRefreshOpening: function(amt) { - $scope.onRefreshOpening && $scope.onRefreshOpening({amount: amt}); + $scope.onRefreshOpening({amount: amt}); } }); // Let child scopes access this $scope.scrollView = sv; } - var clone = transclude($scope); + // Pass the parent scope down to the child + var clone = transclude($scope.$parent); angular.element($element[0].firstElementChild).append(clone); }; } }; -}) +}]) .directive('refresher', function() { return { diff --git a/dist/js/ionic.js b/dist/js/ionic.js index 35fe939966..b808c294c4 100644 --- a/dist/js/ionic.js +++ b/dist/js/ionic.js @@ -2414,21 +2414,24 @@ window.ionic = { // Grab the refresher element if using Pull to Refresh if(this.hasPullToRefresh) { this._refresher = document.querySelector('.scroll-refresher'); - this._refresherHeight = parseFloat(this._refresher.firstElementChild.offsetHeight) || 100; - // We always start the refresher hidden - if(this.y < 0) { - this._isRefresherHidden = true; - this._refresher.style.display = 'none'; - } else { - this._isRefresherHidden = false; - this._didTriggerRefresh = false; - this._refresher.style.display = 'block'; - } - - this._isHoldingRefresh = false; if(this._refresher) { - this._refresher.classList.remove('scroll-refreshing'); + this._refresherHeight = parseFloat(this._refresher.firstElementChild.offsetHeight) || 100; + // We always start the refresher hidden + if(this.y < 0) { + this._isRefresherHidden = true; + this._refresher.style.display = 'none'; + } else { + this._isRefresherHidden = false; + this._didTriggerRefresh = false; + this._refresher.style.display = 'block'; + } + + this._isHoldingRefresh = false; + + if(this._refresher) { + this._refresher.classList.remove('scroll-refreshing'); + } } } diff --git a/js/ext/angular/src/directive/ionicContent.js b/js/ext/angular/src/directive/ionicContent.js index aba621dd40..2a5b6681bf 100644 --- a/js/ext/angular/src/directive/ionicContent.js +++ b/js/ext/angular/src/directive/ionicContent.js @@ -14,13 +14,16 @@ angular.module('ionic.ui.content', []) // The content directive is a core scrollable content area // that is part of many View hierarchies -.directive('content', function() { +.directive('content', ['$parse', function($parse) { return { restrict: 'E', replace: true, template: '
', transclude: true, - scope: true, + scope: { + onRefresh: '&', + onRefreshOpening: '&' + }, compile: function(element, attr, transclude) { return function($scope, $element, $attr) { var c = $element.eq(0); @@ -39,7 +42,6 @@ angular.module('ionic.ui.content', []) c.addClass('has-tabs'); } - // If they want plain overflows scrolling, add that as a class if(attr.overflowScroll === "true") { c.addClass('overflow-scroll'); @@ -47,23 +49,25 @@ angular.module('ionic.ui.content', []) // Otherwise, supercharge this baby! var sv = new ionic.views.Scroll({ el: $element[0].firstElementChild, + hasPullToRefresh: (typeof $scope.onRefresh !== 'undefined'), onRefresh: function() { - $scope.onRefresh && $scope.onRefresh(); + $scope.onRefresh(); }, onRefreshOpening: function(amt) { - $scope.onRefreshOpening && $scope.onRefreshOpening({amount: amt}); + $scope.onRefreshOpening({amount: amt}); } }); // Let child scopes access this $scope.scrollView = sv; } - var clone = transclude($scope); + // Pass the parent scope down to the child + var clone = transclude($scope.$parent); angular.element($element[0].firstElementChild).append(clone); }; } }; -}) +}]) .directive('refresher', function() { return { diff --git a/js/ext/angular/test/content.html b/js/ext/angular/test/content.html index 9c3cdb1709..e8c43e3128 100644 --- a/js/ext/angular/test/content.html +++ b/js/ext/angular/test/content.html @@ -7,9 +7,9 @@ - - - + + + - +
- +
diff --git a/js/ext/angular/test/tabs.html b/js/ext/angular/test/tabs.html index 3ae942ebe9..3a1165b918 100644 --- a/js/ext/angular/test/tabs.html +++ b/js/ext/angular/test/tabs.html @@ -5,9 +5,9 @@ - - - + + +