Skip to content

Commit

Permalink
refactor($ionicPopup): add close() to returned promise, change closing
Browse files Browse the repository at this point in the history
BREAKING CHANGE: $ionicPopup.show()'s button onTap function has changed.

When using `$ionicPopup.show()`, previously a button's onTap function
would only result in closing the popup and resolving the promise if the
 `onTap(event)` function returned a truthy value.

Now, a button's onTap event will *always* close the popup and resolve
the popup's promise, no matter the return value, by default. The only
way to prevent the popup from closing is to call
`event.preventDefault()`.

Change your code from this:

```js
$ionicPopup.show({
  buttons: [{
    onTap: function(event) {
      if (!shouldClosePopup) {
        return false;
      }
    }
  }]
});
```

To this:

```js
$ionicPopup.show({
  buttons: [{
    onTap: function(event) {
      if (!shouldClosePopup) {
        event.preventDefault();
      }
    }
  }]
});
```
  • Loading branch information
ajoslin committed Apr 8, 2014
1 parent 98e7e3d commit cb1a5f6
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 223 deletions.
27 changes: 17 additions & 10 deletions js/ext/angular/src/service/ionicLoading.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ var TPL_LOADING =
'<div class="loading ng-hide" ng-bind-html="html">' +
'</div>';

var HIDE_DEPRECATED = '$ionicLoading instance.hide() has been deprecated. Use $ionicLoading.hide().';
var SHOW_DEPRECATED = '$ionicLoading instance.show() has been deprecated. Use $ionicLoading.show().';
var SET_DEPRECATED = '$ionicLoading instance.setContent() has been deprecated. Use $ionicLoading.show({ content: \'my content\' }).';
var SHOW_DELAY_DEPRECATED = '$ionicLoading options.showDelay has been deprecated. Use options.delay instead.';
var SHOW_BACKDROP_DEPRECATED = '$ionicLoading options.showBackdrop has been deprecated. Use options.noBackdrop instead.';
var HIDE_LOADING_DEPRECATED = '$ionicLoading instance.hide() has been deprecated. Use $ionicLoading.hide().';
var SHOW_LOADING_DEPRECATED = '$ionicLoading instance.show() has been deprecated. Use $ionicLoading.show().';
var SET_LOADING_DEPRECATED = '$ionicLoading instance.setContent() has been deprecated. Use $ionicLoading.show({ content: \'my content\' }).';
var SHOW_DELAY_LOADING_DEPRECATED = '$ionicLoading options.showDelay has been deprecated. Use options.delay instead.';
var SHOW_BACKDROP_LOADING_DEPRECATED = '$ionicLoading options.showBackdrop has been deprecated. Use options.noBackdrop instead.';

angular.module('ionic.service.loading', [])

Expand Down Expand Up @@ -97,9 +97,16 @@ function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q
}

var el = this.element;
var scope = this.scope;
ionic.requestAnimationFrame(function() {
$animate.removeClass(el, 'ng-hide');
//Fix for ios: if we center the element twice, it always gets
//position right. Otherwise, it doesn't
ionic.DomUtil.centerElementByMargin(el[0]);
//One frame after it's visible, position it
ionic.requestAnimationFrame(function() {
ionic.DomUtil.centerElementByMargin(el[0]);
});
});

this.isShown = true;
Expand All @@ -123,20 +130,20 @@ function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q
function showLoader(options) {
options || (options = {});

deprecated.field(SHOW_DELAY_DEPRECATED, $log.warn, options, 'showDelay', options.showDelay);
deprecated.field(SHOW_BACKDROP_DEPRECATED, $log.warn, options, 'showBackdrop', options.showBackdrop);
deprecated.field(SHOW_DELAY_LOADING_DEPRECATED, $log.warn, options, 'showDelay', options.showDelay);
deprecated.field(SHOW_BACKDROP_LOADING_DEPRECATED, $log.warn, options, 'showBackdrop', options.showBackdrop);

$timeout(getLoader, options.delay || options.showDelay || 0)
.then(function(loader) {
return loader.show(options);
});

return {
hide: deprecated.method(HIDE_DEPRECATED, $log.warn, hideLoader),
show: deprecated.method(SHOW_DEPRECATED, $log.warn, function() {
hide: deprecated.method(HIDE_LOADING_DEPRECATED, $log.warn, hideLoader),
show: deprecated.method(SHOW_LOADING_DEPRECATED, $log.warn, function() {
showLoader(options);
}),
setContent: deprecated.method(SET_DEPRECATED, $log.warn, function(content) {
setContent: deprecated.method(SET_LOADING_DEPRECATED, $log.warn, function(content) {
getLoader().then(function(loader) {
loader.scope.html = content;
});
Expand Down
Loading

0 comments on commit cb1a5f6

Please sign in to comment.