Index: lib/src/iron-overlay-behavior/iron-overlay-behavior.html |
diff --git a/lib/src/iron-overlay-behavior/iron-overlay-behavior.html b/lib/src/iron-overlay-behavior/iron-overlay-behavior.html |
index 180b19cefac6d15794626ea3789483c5a97fe5db..837759f7e7f73007be88e53f3a36613a34751247 100644 |
--- a/lib/src/iron-overlay-behavior/iron-overlay-behavior.html |
+++ b/lib/src/iron-overlay-behavior/iron-overlay-behavior.html |
@@ -28,7 +28,8 @@ intent. Closing generally implies that the user acknowledged the content on the |
it will cancel whenever the user taps outside it or presses the escape key. This behavior is |
configurable with the `no-cancel-on-esc-key` and the `no-cancel-on-outside-click` properties. |
`close()` should be called explicitly by the implementer when the user interacts with a control |
-in the overlay element. |
+in the overlay element. When the dialog is canceled, the overlay fires an 'iron-overlay-canceled' |
+event. Call `preventDefault` on this event to prevent the overlay from closing. |
### Positioning |
@@ -139,7 +140,7 @@ context. You should place this element as a child of `<body>` whenever possible. |
}, |
listeners: { |
- 'click': '_onClick', |
+ 'tap': '_onClick', |
'iron-resize': '_onIronResize' |
}, |
@@ -199,7 +200,12 @@ context. You should place this element as a child of `<body>` whenever possible. |
* Cancels the overlay. |
*/ |
cancel: function() { |
- this.opened = false, |
+ var cancelEvent = this.fire('iron-overlay-canceled', undefined, {cancelable: true}); |
+ if (cancelEvent.defaultPrevented) { |
+ return; |
+ } |
+ |
+ this.opened = false; |
this._setCanceled(true); |
}, |
@@ -257,8 +263,16 @@ context. You should place this element as a child of `<body>` whenever possible. |
_toggleListener: function(enable, node, event, boundListener, capture) { |
if (enable) { |
+ // enable document-wide tap recognizer |
+ if (event === 'tap') { |
+ Polymer.Gestures.add(document, 'tap', null); |
+ } |
node.addEventListener(event, boundListener, capture); |
} else { |
+ // disable document-wide tap recognizer |
+ if (event === 'tap') { |
+ Polymer.Gestures.remove(document, 'tap', null); |
+ } |
node.removeEventListener(event, boundListener, capture); |
} |
}, |
@@ -269,10 +283,10 @@ context. You should place this element as a child of `<body>` whenever possible. |
} |
// async so we don't auto-close immediately via a click. |
this._toggleListenersAsync = this.async(function() { |
- this._toggleListener(this.opened, document, 'click', this._boundOnCaptureClick, true); |
+ this._toggleListener(this.opened, document, 'tap', this._boundOnCaptureClick, true); |
this._toggleListener(this.opened, document, 'keydown', this._boundOnCaptureKeydown, true); |
this._toggleListenersAsync = null; |
- }); |
+ }, 1); |
}, |
// tasks which must occur before opening; e.g. making the element visible |