refactor(ionHeaderBar): make sure tapScrollToTop works even on rootScope

This commit is contained in:
Andy Joslin
2014-03-21 09:08:43 -05:00
parent 423f9e4f77
commit 6d403efb48
2 changed files with 15 additions and 15 deletions

View File

@@ -3,10 +3,10 @@
angular.module('ionic.ui.header', ['ngAnimate', 'ngSanitize'])
.directive('barHeader', ['$document', function($document) {
.directive('ionHeaderBar', ['$document', function($document) {
return {
restrict: 'C',
link: function($scope, $element, $attr) {
restrict: 'E',
link: function($scope, $element, $attr, scrollCtrl) {
ionic.requestAnimationFrame(function() {
var scrollCtrl = $element.controller('$ionicScroll');
if (!scrollCtrl) {
@@ -129,24 +129,25 @@ function barDirective(isHeader) {
).assign($scope, hb);
var el = $element[0];
var parentScope = $scope.$parent || $scope; //just incase header is on rootscope
if (isHeader) {
$scope.$watch(function() { return el.className; }, function(value) {
var isSubheader = value.indexOf('bar-subheader') !== -1;
$scope.$parent.$hasHeader = !isSubheader;
$scope.$parent.$hasSubheader = isSubheader;
parentScope.$hasHeader = !isSubheader;
parentScope.$hasSubheader = isSubheader;
});
$scope.$on('$destroy', function() {
$scope.$parent.$hasHeader = $scope.$parent.$hasSubheader = null;
parentScope.$hasHeader = parentScope.$hasSubheader = null;
});
} else {
$scope.$watch(function() { return el.className; }, function(value) {
var isSubfooter = value.indexOf('bar-subfooter') !== -1;
$scope.$parent.$hasFooter = !isSubfooter;
$scope.$parent.$hasSubfooter = isSubfooter;
parentScope.$hasFooter = !isSubfooter;
parentScope.$hasSubfooter = isSubfooter;
});
$scope.$on('$destroy', function() {
$scope.$parent.$hasFooter = $scope.$parent.$hasSubfooter = null;
parentScope.$hasFooter = parentScope.$hasSubfooter = null;
});
$scope.$watch('$hasTabs', function(val) {
$element.toggleClass('has-tabs', !!val);

View File

@@ -1,16 +1,15 @@
describe('bar directives', function() {
beforeEach(module('ionic'));
describe('barHeader tapScrollToTop', function() {
describe('tapScrollToTop', function() {
function setup() {
var el;
inject(function($compile, $rootScope) {
el = angular.element('<div class="bar-header">')
el.data('$$ionicScrollController', {
scrollTop: jasmine.createSpy('scrollTop')
});
el = angular.element('<ion-header-bar>')
var container = angular.element('<ion-content>').append(el);
ionic.requestAnimationFrame = function(cb) { cb(); };
$compile(el)($rootScope.$new());
$compile(container)($rootScope.$new());
container.controller('$ionicScroll').scrollTop = jasmine.createSpy('scrollTop')
$rootScope.$apply();
});
return el;