@@ -198,44 +198,56 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
198
198
* use the passed parent element.
199
199
*/
200
200
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 ) {
210
216
restoreBody ( ) ;
211
217
restoreElement ( ) ;
212
- delete $mdUtil . disableScrollAround . _enableScrolling ;
218
+ delete $mdUtil . disableScrollAround . _restoreScroll ;
213
219
}
214
220
} ;
215
221
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
+ */
217
226
function disableElementScroll ( element ) {
218
227
element = angular . element ( element || body ) ;
228
+
219
229
var scrollMask ;
220
- if ( options && options . disableScrollMask ) {
230
+
231
+ if ( options . disableScrollMask ) {
221
232
scrollMask = element ;
222
233
} else {
223
- element = element [ 0 ] ;
224
234
scrollMask = angular . element (
225
235
'<div class="md-scroll-mask">' +
226
236
' <div class="md-scroll-mask-bar"></div>' +
227
237
'</div>' ) ;
228
- element . appendChild ( scrollMask [ 0 ] ) ;
238
+ element . append ( scrollMask ) ;
229
239
}
230
240
231
241
scrollMask . on ( 'wheel' , preventDefault ) ;
232
242
scrollMask . on ( 'touchmove' , preventDefault ) ;
233
243
234
- return function restoreScroll ( ) {
244
+ return function restoreElementScroll ( ) {
235
245
scrollMask . off ( 'wheel' ) ;
236
246
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
+ }
239
251
} ;
240
252
241
253
function preventDefault ( e ) {
@@ -279,10 +291,12 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
279
291
}
280
292
281
293
} ,
294
+
282
295
enableScrolling : function ( ) {
283
- var method = this . disableScrollAround . _enableScrolling ;
284
- method && method ( ) ;
296
+ var restoreFn = this . disableScrollAround . _restoreScroll ;
297
+ restoreFn && restoreFn ( ) ;
285
298
} ,
299
+
286
300
floatingScrollbars : function ( ) {
287
301
if ( this . floatingScrollbars . cached === undefined ) {
288
302
var tempNode = angular . element ( '<div><div></div></div>' ) . css ( {
0 commit comments