@@ -1825,23 +1825,35 @@ MdPanelRef.prototype._configureEscapeToClose = function() {
18251825 */
18261826MdPanelRef . prototype . _configureClickOutsideToClose = function ( ) {
18271827 if ( this . config [ 'clickOutsideToClose' ] ) {
1828- var target = this . panelContainer ;
1829- var sourceElem ;
1828+ var target = this . config [ 'propagateContainerEvents' ] ?
1829+ angular . element ( document . body ) :
1830+ this . panelContainer ;
1831+ var sourceEl ;
18301832
18311833 // Keep track of the element on which the mouse originally went down
18321834 // so that we can only close the backdrop when the 'click' started on it.
1833- // A simple 'click' handler does not work,
1834- // it sets the target object as the element the mouse went down on.
1835+ // A simple 'click' handler does not work, it sets the target object as the
1836+ // element the mouse went down on.
18351837 var mousedownHandler = function ( ev ) {
1836- sourceElem = ev . target ;
1838+ sourceEl = ev . target ;
18371839 } ;
18381840
18391841 // We check if our original element and the target is the backdrop
18401842 // because if the original was the backdrop and the target was inside the
18411843 // panel we don't want to panel to close.
18421844 var self = this ;
18431845 var mouseupHandler = function ( ev ) {
1844- if ( sourceElem === target [ 0 ] && ev . target === target [ 0 ] ) {
1846+ if ( self . config [ 'propagateContainerEvents' ] ) {
1847+
1848+ // We check if the sourceEl of the event is the panel element or one
1849+ // of it's children. If it is not, then close the panel.
1850+ var found = sourceEl === self . panelEl [ 0 ] ||
1851+ self . panelEl [ 0 ] . contains ( sourceEl ) ;
1852+ if ( ! found ) {
1853+ self . close ( ) ;
1854+ }
1855+
1856+ } else if ( sourceEl === target [ 0 ] && ev . target === target [ 0 ] ) {
18451857 ev . stopPropagation ( ) ;
18461858 ev . preventDefault ( ) ;
18471859
@@ -2713,6 +2725,7 @@ MdPanelPosition.prototype._constrainToViewport = function(panelEl) {
27132725 }
27142726} ;
27152727
2728+
27162729/**
27172730 * Switches between 'start' and 'end'.
27182731 * @param {string } position Horizontal position of the panel
@@ -2902,6 +2915,7 @@ MdPanelAnimation.prototype.closeTo = function(closeTo) {
29022915 return this ;
29032916} ;
29042917
2918+
29052919/**
29062920 * Specifies the duration of the animation in milliseconds.
29072921 * @param {number|{open: number, close: number} } duration
@@ -2927,6 +2941,7 @@ MdPanelAnimation.prototype.duration = function(duration) {
29272941 }
29282942} ;
29292943
2944+
29302945/**
29312946 * Returns the element and bounds for the animation target.
29322947 * @param {string|!Element|{top: number, left: number} } location
0 commit comments