mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Added Android back button support to action sheet, modal
This commit is contained in:
34
dist/js/ionic-angular.js
vendored
34
dist/js/ionic-angular.js
vendored
@@ -153,10 +153,11 @@ angular.module('ionic.ui.service.slideBoxDelegate', [])
|
||||
|
||||
})(ionic);
|
||||
;
|
||||
angular.module('ionic.service.actionSheet', ['ionic.service.templateLoad', 'ionic.ui.actionSheet', 'ngAnimate'])
|
||||
angular.module('ionic.service.actionSheet', ['ionic.service.templateLoad', 'ionic.service.platform', 'ionic.ui.actionSheet', 'ngAnimate'])
|
||||
|
||||
.factory('$ionicActionSheet', ['$rootScope', '$document', '$compile', '$animate', '$timeout', '$ionicTemplateLoader',
|
||||
function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoader) {
|
||||
.factory('$ionicActionSheet', ['$rootScope', '$document', '$compile', '$animate', '$timeout',
|
||||
'$ionicTemplateLoader', '$ionicPlatform',
|
||||
function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoader, $ionicPlatform) {
|
||||
|
||||
return {
|
||||
/**
|
||||
@@ -191,6 +192,17 @@ angular.module('ionic.service.actionSheet', ['ionic.service.templateLoad', 'ioni
|
||||
});
|
||||
};
|
||||
|
||||
var onHardwareBackButton = function() {
|
||||
hideSheet();
|
||||
};
|
||||
|
||||
scope.$on('$destroy', function() {
|
||||
$ionicPlatform.offHardwareBackButton(onHardwareBackButton);
|
||||
});
|
||||
|
||||
// Support Android back button to close
|
||||
$ionicPlatform.onHardwareBackButton(onHardwareBackButton);
|
||||
|
||||
scope.cancel = function() {
|
||||
hideSheet(true);
|
||||
};
|
||||
@@ -295,10 +307,10 @@ angular.module('ionic.service.loading', ['ionic.ui.loading'])
|
||||
};
|
||||
}]);
|
||||
;
|
||||
angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ngAnimate'])
|
||||
angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ionic.service.platform', 'ngAnimate'])
|
||||
|
||||
|
||||
.factory('$ionicModal', ['$rootScope', '$document', '$compile', '$animate', '$q', '$ionicTemplateLoader', function($rootScope, $document, $compile, $animate, $q, $ionicTemplateLoader) {
|
||||
.factory('$ionicModal', ['$rootScope', '$document', '$compile', '$animate', '$q', '$ionicPlatform', '$ionicTemplateLoader', function($rootScope, $document, $compile, $animate, $q, $ionicPlatform, $ionicTemplateLoader) {
|
||||
var ModalView = ionic.views.Modal.inherit({
|
||||
initialize: function(opts) {
|
||||
ionic.views.Modal.prototype.initialize.call(this, opts);
|
||||
@@ -317,6 +329,18 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ngAnimate'
|
||||
$animate.addClass(element, this.animation, function() {
|
||||
});
|
||||
}
|
||||
|
||||
var onHardwareBackButton = function() {
|
||||
_this.hide();
|
||||
};
|
||||
|
||||
_this.scope.$on('$destroy', function() {
|
||||
$ionicPlatform.offHardwareBackButton(onHardwareBackButton);
|
||||
});
|
||||
|
||||
// Support Android back button to close
|
||||
$ionicPlatform.onHardwareBackButton(onHardwareBackButton);
|
||||
|
||||
},
|
||||
// Hide the modal
|
||||
hide: function() {
|
||||
|
||||
4
dist/js/ionic-angular.min.js
vendored
4
dist/js/ionic-angular.min.js
vendored
File diff suppressed because one or more lines are too long
18
js/ext/angular/src/service/ionicActionSheet.js
vendored
18
js/ext/angular/src/service/ionicActionSheet.js
vendored
@@ -1,7 +1,8 @@
|
||||
angular.module('ionic.service.actionSheet', ['ionic.service.templateLoad', 'ionic.ui.actionSheet', 'ngAnimate'])
|
||||
angular.module('ionic.service.actionSheet', ['ionic.service.templateLoad', 'ionic.service.platform', 'ionic.ui.actionSheet', 'ngAnimate'])
|
||||
|
||||
.factory('$ionicActionSheet', ['$rootScope', '$document', '$compile', '$animate', '$timeout', '$ionicTemplateLoader',
|
||||
function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoader) {
|
||||
.factory('$ionicActionSheet', ['$rootScope', '$document', '$compile', '$animate', '$timeout',
|
||||
'$ionicTemplateLoader', '$ionicPlatform',
|
||||
function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoader, $ionicPlatform) {
|
||||
|
||||
return {
|
||||
/**
|
||||
@@ -36,6 +37,17 @@ angular.module('ionic.service.actionSheet', ['ionic.service.templateLoad', 'ioni
|
||||
});
|
||||
};
|
||||
|
||||
var onHardwareBackButton = function() {
|
||||
hideSheet();
|
||||
};
|
||||
|
||||
scope.$on('$destroy', function() {
|
||||
$ionicPlatform.offHardwareBackButton(onHardwareBackButton);
|
||||
});
|
||||
|
||||
// Support Android back button to close
|
||||
$ionicPlatform.onHardwareBackButton(onHardwareBackButton);
|
||||
|
||||
scope.cancel = function() {
|
||||
hideSheet(true);
|
||||
};
|
||||
|
||||
16
js/ext/angular/src/service/ionicModal.js
vendored
16
js/ext/angular/src/service/ionicModal.js
vendored
@@ -1,7 +1,7 @@
|
||||
angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ngAnimate'])
|
||||
angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ionic.service.platform', 'ngAnimate'])
|
||||
|
||||
|
||||
.factory('$ionicModal', ['$rootScope', '$document', '$compile', '$animate', '$q', '$ionicTemplateLoader', function($rootScope, $document, $compile, $animate, $q, $ionicTemplateLoader) {
|
||||
.factory('$ionicModal', ['$rootScope', '$document', '$compile', '$animate', '$q', '$ionicPlatform', '$ionicTemplateLoader', function($rootScope, $document, $compile, $animate, $q, $ionicPlatform, $ionicTemplateLoader) {
|
||||
var ModalView = ionic.views.Modal.inherit({
|
||||
initialize: function(opts) {
|
||||
ionic.views.Modal.prototype.initialize.call(this, opts);
|
||||
@@ -20,6 +20,18 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ngAnimate'
|
||||
$animate.addClass(element, this.animation, function() {
|
||||
});
|
||||
}
|
||||
|
||||
var onHardwareBackButton = function() {
|
||||
_this.hide();
|
||||
};
|
||||
|
||||
_this.scope.$on('$destroy', function() {
|
||||
$ionicPlatform.offHardwareBackButton(onHardwareBackButton);
|
||||
});
|
||||
|
||||
// Support Android back button to close
|
||||
$ionicPlatform.onHardwareBackButton(onHardwareBackButton);
|
||||
|
||||
},
|
||||
// Hide the modal
|
||||
hide: function() {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
describe('Ionic ActionSheet Service', function() {
|
||||
var sheet, timeout;
|
||||
|
||||
beforeEach(module('ionic.service.actionSheet'));
|
||||
|
||||
beforeEach(inject(function($ionicActionSheet, $timeout) {
|
||||
sheet = $ionicActionSheet;
|
||||
timeout = $timeout;
|
||||
}));
|
||||
|
||||
it('Should show', function() {
|
||||
var s = sheet.show();
|
||||
expect(s.el.classList.contains('active')).toBe(true);
|
||||
});
|
||||
|
||||
it('Should handle hardware back button', function() {
|
||||
// Fake cordova
|
||||
window.device = {};
|
||||
var s = sheet.show();
|
||||
|
||||
timeout.flush();
|
||||
|
||||
ionic.trigger('backbutton', {
|
||||
target: document
|
||||
});
|
||||
|
||||
expect(s.el.classList.contains('active')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
describe('Ionic Modal', function() {
|
||||
var modal, q;
|
||||
var modal, q, timeout;
|
||||
|
||||
beforeEach(module('ionic.service.modal'));
|
||||
|
||||
beforeEach(inject(function($ionicModal, $q, $templateCache) {
|
||||
beforeEach(inject(function($ionicModal, $q, $templateCache, $timeout) {
|
||||
q = $q;
|
||||
modal = $ionicModal;
|
||||
timeout = $timeout;
|
||||
|
||||
$templateCache.put('modal.html', '<div class="modal"></div>');
|
||||
}));
|
||||
@@ -18,7 +19,7 @@ describe('Ionic Modal', function() {
|
||||
expect(modalInstance.el.classList.contains('slide-in-up')).toBe(true);
|
||||
});
|
||||
|
||||
xit('Should show for dynamic template', function() {
|
||||
it('Should show for dynamic template', function() {
|
||||
var template = '<div class="modal"></div>';
|
||||
|
||||
var done = false;
|
||||
@@ -27,11 +28,30 @@ describe('Ionic Modal', function() {
|
||||
done = true;
|
||||
modalInstance.show();
|
||||
expect(modalInstance.el.classList.contains('modal')).toBe(true);
|
||||
expect(modalInstance.el.classList.contains('active')).toBe(true);
|
||||
});
|
||||
|
||||
timeout.flush();
|
||||
|
||||
waitsFor(function() {
|
||||
return done;
|
||||
}, "Modal should be loaded", 100);
|
||||
|
||||
});
|
||||
|
||||
it('Should close on hardware back button', function() {
|
||||
var template = '<div class="modal"></div>';
|
||||
var modalInstance = modal.fromTemplate(template);
|
||||
modalInstance.show();
|
||||
|
||||
timeout.flush();
|
||||
|
||||
expect(modalInstance.el.classList.contains('active')).toBe(true);
|
||||
|
||||
ionic.trigger('backbutton', {
|
||||
target: document
|
||||
});
|
||||
|
||||
expect(modalInstance.el.classList.contains('active')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user