mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor(ionHeaderBar): make sure tapScrollToTop works even on rootScope
This commit is contained in:
19
js/ext/angular/src/directive/ionicBar.js
vendored
19
js/ext/angular/src/directive/ionicBar.js
vendored
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user