@@ -198,44 +198,56 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
198198 * use the passed parent element.
199199 */
200200 disableScrollAround : function ( element , parent , options ) {
201- $mdUtil . disableScrollAround . _count = $mdUtil . disableScrollAround . _count || 0 ;
202- ++ $mdUtil . disableScrollAround . _count ;
203- if ( $mdUtil . disableScrollAround . _enableScrolling ) return $mdUtil . disableScrollAround . _enableScrolling ;
204- var body = $document [ 0 ] . body ,
205- restoreBody = disableBodyScroll ( ) ,
206- restoreElement = disableElementScroll ( parent ) ;
207-
208- return $mdUtil . disableScrollAround . _enableScrolling = function ( ) {
209- if ( ! -- $mdUtil . disableScrollAround . _count ) {
201+ options = options || { } ;
202+
203+ $mdUtil . disableScrollAround . _count = Math . max ( 0 , $mdUtil . disableScrollAround . _count || 0 ) ;
204+ $mdUtil . disableScrollAround . _count ++ ;
205+
206+ if ( $mdUtil . disableScrollAround . _restoreScroll ) {
207+ return $mdUtil . disableScrollAround . _restoreScroll ;
208+ }
209+
210+ var body = $document [ 0 ] . body ;
211+ var restoreBody = disableBodyScroll ( ) ;
212+ var restoreElement = disableElementScroll ( parent ) ;
213+
214+ return $mdUtil . disableScrollAround . _restoreScroll = function ( ) {
215+ if ( -- $mdUtil . disableScrollAround . _count <= 0 ) {
210216 restoreBody ( ) ;
211217 restoreElement ( ) ;
212- delete $mdUtil . disableScrollAround . _enableScrolling ;
218+ delete $mdUtil . disableScrollAround . _restoreScroll ;
213219 }
214220 } ;
215221
216- // Creates a virtual scrolling mask to absorb touchmove, keyboard, scrollbar clicking, and wheel events
222+ /**
223+ * Creates a virtual scrolling mask to prevent touchmove, keyboard, scrollbar clicking,
224+ * and wheel events
225+ */
217226 function disableElementScroll ( element ) {
218227 element = angular . element ( element || body ) ;
228+
219229 var scrollMask ;
220- if ( options && options . disableScrollMask ) {
230+
231+ if ( options . disableScrollMask ) {
221232 scrollMask = element ;
222233 } else {
223- element = element [ 0 ] ;
224234 scrollMask = angular . element (
225235 '<div class="md-scroll-mask">' +
226236 ' <div class="md-scroll-mask-bar"></div>' +
227237 '</div>' ) ;
228- element . appendChild ( scrollMask [ 0 ] ) ;
238+ element . append ( scrollMask ) ;
229239 }
230240
231241 scrollMask . on ( 'wheel' , preventDefault ) ;
232242 scrollMask . on ( 'touchmove' , preventDefault ) ;
233243
234- return function restoreScroll ( ) {
244+ return function restoreElementScroll ( ) {
235245 scrollMask . off ( 'wheel' ) ;
236246 scrollMask . off ( 'touchmove' ) ;
237- scrollMask [ 0 ] . parentNode . removeChild ( scrollMask [ 0 ] ) ;
238- delete $mdUtil . disableScrollAround . _enableScrolling ;
247+
248+ if ( ! options . disableScrollMask ) {
249+ scrollMask [ 0 ] . parentNode . removeChild ( scrollMask [ 0 ] ) ;
250+ }
239251 } ;
240252
241253 function preventDefault ( e ) {
@@ -279,10 +291,12 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
279291 }
280292
281293 } ,
294+
282295 enableScrolling : function ( ) {
283- var method = this . disableScrollAround . _enableScrolling ;
284- method && method ( ) ;
296+ var restoreFn = this . disableScrollAround . _restoreScroll ;
297+ restoreFn && restoreFn ( ) ;
285298 } ,
299+
286300 floatingScrollbars : function ( ) {
287301 if ( this . floatingScrollbars . cached === undefined ) {
288302 var tempNode = angular . element ( '<div><div></div></div>' ) . css ( {
0 commit comments