Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 0ed110b

Browse files
Splaktarmmalerba
authored andcommitted
fix(sidenav): refactor syntax to work around issue in babel-minify (#11351)
avoid creating variables in a block when they are used outside instead create them directly in the function block they are hoisted to fix typos fix lint issues and whitespace improve JSDoc Relates to babel/minify#878
1 parent f7b7f10 commit 0ed110b

File tree

3 files changed

+98
-89
lines changed

3 files changed

+98
-89
lines changed

src/components/chips/js/chipsController.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,9 +849,9 @@ MdChipsCtrl.prototype.configureUserInput = function(inputElement) {
849849
// Bind to keydown and focus events of input
850850
inputElement
851851
.attr({ tabindex: 0 })
852-
.on('keydown', function(event) { scopeApplyFn(event, ctrl.inputKeydown) })
853-
.on('focus', function(event) { scopeApplyFn(event, ctrl.onInputFocus) })
854-
.on('blur', function(event) { scopeApplyFn(event, ctrl.onInputBlur) });
852+
.on('keydown', function(event) { scopeApplyFn(event, ctrl.inputKeydown); })
853+
.on('focus', function(event) { scopeApplyFn(event, ctrl.onInputFocus); })
854+
.on('blur', function(event) { scopeApplyFn(event, ctrl.onInputBlur); });
855855
};
856856

857857
/**

src/components/navBar/navBar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ function MdNavItem($mdAria, $$rAF, $mdUtil, $window) {
503503

504504
scope.$on('destroy', function() {
505505
disconnect();
506-
})
506+
});
507507
}
508508
};
509509
}

src/components/sidenav/sidenav.js

Lines changed: 94 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @name material.components.sidenav
44
*
55
* @description
6-
* A Sidenav QP component.
6+
* A Sidenav component.
77
*/
88
angular
99
.module('material.components.sidenav', [
@@ -22,10 +22,9 @@ angular
2222
* @module material.components.sidenav
2323
*
2424
* @description
25-
* `$mdSidenav` makes it easy to interact with multiple sidenavs
26-
* in an app. When looking up a sidenav instance, you can either look
27-
* it up synchronously or wait for it to be initializied asynchronously.
28-
* This is done by passing the second argument to `$mdSidenav`.
25+
* `$mdSidenav` makes it easy to interact with multiple sidenavs in an app. When looking up a
26+
* sidenav instance, you can either look it up synchronously or wait for it to be initialized
27+
* asynchronously. This is done by passing the second argument to `$mdSidenav`.
2928
*
3029
* @usage
3130
* <hljs lang="js">
@@ -74,77 +73,84 @@ angular
7473
function SidenavService($mdComponentRegistry, $mdUtil, $q, $log) {
7574
var errorMsg = "SideNav '{0}' is not available! Did you use md-component-id='{0}'?";
7675
var service = {
77-
find : findInstance, // sync - returns proxy API
78-
waitFor : waitForInstance // async - returns promise
79-
};
76+
find: findInstance, // sync - returns proxy API
77+
waitFor: waitForInstance // async - returns promise
78+
};
8079

8180
/**
8281
* Service API that supports three (3) usages:
83-
* $mdSidenav().find("left") // sync (must already exist) or returns undefined
84-
* $mdSidenav("left").toggle(); // sync (must already exist) or returns reject promise;
85-
* $mdSidenav("left",true).then( function(left){ // async returns instance when available
86-
* left.toggle();
87-
* });
82+
* $mdSidenav().find("left") // sync (must already exist) or returns undefined
83+
* $mdSidenav("left").toggle(); // sync (must already exist) or returns reject promise;
84+
* $mdSidenav("left",true).then(function(left) { // async returns instance when available
85+
* left.toggle();
86+
* });
8887
*/
8988
return function(handle, enableWait) {
90-
if ( angular.isUndefined(handle) ) return service;
89+
if (angular.isUndefined(handle)) {
90+
return service;
91+
}
9192

9293
var shouldWait = enableWait === true;
9394
var instance = service.find(handle, shouldWait);
94-
return !instance && shouldWait ? service.waitFor(handle) :
95-
!instance && angular.isUndefined(enableWait) ? addLegacyAPI(service, handle) : instance;
95+
return !instance && shouldWait ? service.waitFor(handle) :
96+
!instance && angular.isUndefined(enableWait) ? addLegacyAPI(service, handle) : instance;
9697
};
9798

9899
/**
99100
* For failed instance/handle lookups, older-clients expect an response object with noops
100101
* that include `rejected promise APIs`
102+
* @param service
103+
* @param handle
104+
* @returns {Object}
101105
*/
102106
function addLegacyAPI(service, handle) {
103-
var falseFn = function() { return false; };
104-
var rejectFn = function() {
105-
return $q.when($mdUtil.supplant(errorMsg, [handle || ""]));
106-
};
107-
108-
return angular.extend({
109-
isLockedOpen : falseFn,
110-
isOpen : falseFn,
111-
toggle : rejectFn,
112-
open : rejectFn,
113-
close : rejectFn,
114-
onClose : angular.noop,
115-
then : function(callback) {
116-
return waitForInstance(handle)
117-
.then(callback || angular.noop);
118-
}
119-
}, service);
120-
}
121-
/**
122-
* Synchronously lookup the controller instance for the specified sidNav instance which has been
123-
* registered with the markup `md-component-id`
124-
*/
125-
function findInstance(handle, shouldWait) {
126-
var instance = $mdComponentRegistry.get(handle);
107+
var falseFn = function() {
108+
return false;
109+
};
110+
var rejectFn = function() {
111+
return $q.when($mdUtil.supplant(errorMsg, [handle || ""]));
112+
};
127113

128-
if (!instance && !shouldWait) {
114+
return angular.extend({
115+
isLockedOpen: falseFn,
116+
isOpen: falseFn,
117+
toggle: rejectFn,
118+
open: rejectFn,
119+
close: rejectFn,
120+
onClose: angular.noop,
121+
then: function(callback) {
122+
return waitForInstance(handle).then(callback || angular.noop);
123+
}
124+
}, service);
125+
}
129126

130-
// Report missing instance
131-
$log.error( $mdUtil.supplant(errorMsg, [handle || ""]) );
127+
/**
128+
* Synchronously lookup the controller instance for the specified sidNav instance which has been
129+
* registered with the markup `md-component-id`
130+
*/
131+
function findInstance(handle, shouldWait) {
132+
var instance = $mdComponentRegistry.get(handle);
132133

133-
// The component has not registered itself... most like NOT yet created
134-
// return null to indicate that the Sidenav is not in the DOM
135-
return undefined;
136-
}
137-
return instance;
138-
}
134+
if (!instance && !shouldWait) {
135+
// Report missing instance
136+
$log.error($mdUtil.supplant(errorMsg, [handle || ""]));
139137

140-
/**
141-
* Asynchronously wait for the component instantiation,
142-
* Deferred lookup of component instance using $component registry
143-
*/
144-
function waitForInstance(handle) {
145-
return $mdComponentRegistry.when(handle).catch($log.error);
138+
// The component has not registered itself... most like NOT yet created
139+
// return null to indicate that the Sidenav is not in the DOM
140+
return undefined;
146141
}
142+
return instance;
143+
}
144+
145+
/**
146+
* Asynchronously wait for the component instantiation,
147+
* Deferred lookup of component instance using $component registry
148+
*/
149+
function waitForInstance(handle) {
150+
return $mdComponentRegistry.when(handle).catch($log.error);
151+
}
147152
}
153+
148154
/**
149155
* @ngdoc directive
150156
* @name mdSidenavFocus
@@ -177,15 +183,15 @@ function SidenavFocusDirective() {
177183
}
178184
};
179185
}
186+
180187
/**
181188
* @ngdoc directive
182189
* @name mdSidenav
183190
* @module material.components.sidenav
184191
* @restrict E
185192
*
186193
* @description
187-
*
188-
* A Sidenav component that can be opened and closed programatically.
194+
* A Sidenav component that can be opened and closed programmatically.
189195
*
190196
* By default, upon opening it will slide out on top of the main content area.
191197
*
@@ -230,8 +236,10 @@ function SidenavFocusDirective() {
230236
* </hljs>
231237
*
232238
* @param {expression=} md-is-open A model bound to whether the sidenav is opened.
233-
* @param {boolean=} md-disable-backdrop When present in the markup, the sidenav will not show a backdrop.
234-
* @param {boolean=} md-disable-close-events When present in the markup, clicking the backdrop or pressing the 'Escape' key will not close the sidenav.
239+
* @param {boolean=} md-disable-backdrop When present in the markup, the sidenav will not show a
240+
* backdrop.
241+
* @param {boolean=} md-disable-close-events When present in the markup, clicking the backdrop or
242+
* pressing the 'Escape' key will not close the sidenav.
235243
* @param {string=} md-component-id componentId to use with $mdSidenav service.
236244
* @param {expression=} md-is-locked-open When this expression evaluates to true,
237245
* the sidenav 'locks open': it falls into the content's flow instead
@@ -268,6 +276,7 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInterac
268276
var lastParentOverFlow;
269277
var backdrop;
270278
var disableScrollTarget = null;
279+
var disableCloseEvents;
271280
var triggeringInteractionType;
272281
var triggeringElement = null;
273282
var previousContainerStyles;
@@ -291,7 +300,8 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInterac
291300
disableScrollTarget = angular.element(disableScrollTarget);
292301
} else {
293302
$log.warn($mdUtil.supplant('mdSidenav: couldn\'t find element matching ' +
294-
'selector "{selector}". Falling back to parent.', { selector: attr.mdDisableScrollTarget }));
303+
'selector "{selector}". Falling back to parent.',
304+
{ selector: attr.mdDisableScrollTarget }));
295305
}
296306
}
297307

@@ -307,7 +317,7 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInterac
307317
// If md-disable-close-events is set on the sidenav we will disable
308318
// backdrop click and Escape key events
309319
if (attr.hasOwnProperty('mdDisableCloseEvents')) {
310-
var disableCloseEvents = true;
320+
disableCloseEvents = true;
311321
}
312322

313323
element.addClass('_md'); // private md component indicator for styling
@@ -336,6 +346,7 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInterac
336346
/**
337347
* Toggle the DOM classes to indicate `locked`
338348
* @param isLocked
349+
* @param oldValue
339350
*/
340351
function updateIsLocked(isLocked, oldValue) {
341352
scope.isLockedOpen = isLocked;
@@ -355,19 +366,21 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInterac
355366
*/
356367
function updateIsOpen(isOpen) {
357368
// Support deprecated md-sidenav-focus attribute as fallback
358-
var focusEl = $mdUtil.findFocusTarget(element) || $mdUtil.findFocusTarget(element,'[md-sidenav-focus]') || element;
369+
var focusEl = $mdUtil.findFocusTarget(element) ||
370+
$mdUtil.findFocusTarget(element,'[md-sidenav-focus]') || element;
359371
var parent = element.parent();
372+
var restorePositioning;
360373

361374
// If the user hasn't set the disable close events property we are adding
362375
// click and escape events to close the sidenav
363-
if ( !disableCloseEvents ) {
376+
if (!disableCloseEvents) {
364377
parent[isOpen ? 'on' : 'off']('keydown', onKeyDown);
365378
if (backdrop) backdrop[isOpen ? 'on' : 'off']('click', close);
366379
}
367380

368-
var restorePositioning = updateContainerPositions(parent, isOpen);
381+
restorePositioning = updateContainerPositions(parent, isOpen);
369382

370-
if ( isOpen ) {
383+
if (isOpen) {
371384
// Capture upon opening..
372385
triggeringElement = $document[0].activeElement;
373386
triggeringInteractionType = $mdInteraction.getLastInteractionType();
@@ -407,9 +420,10 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInterac
407420
height: drawerEl.style.height
408421
};
409422

410-
// When the parent is scrolled down, then we want to be able to show the sidenav at the current scroll
411-
// position. We're moving the sidenav down to the correct scroll position and apply the height of the
412-
// parent, to increase the performance. Using 100% as height, will impact the performance heavily.
423+
// When the parent is scrolled down, then we want to be able to show the sidenav at the
424+
// current scroll position. We're moving the sidenav down to the correct scroll position
425+
// and apply the height of the parent, to increase the performance. Using 100% as height,
426+
// will impact the performance heavily.
413427
var positionStyle = {
414428
top: scrollTop + 'px',
415429
bottom: 'auto',
@@ -454,19 +468,16 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInterac
454468
/**
455469
* Toggle the sideNav view and publish a promise to be resolved when
456470
* the view animation finishes.
457-
*
458-
* @param isOpen
459-
* @returns {*}
471+
* @param {boolean} isOpen true to open the sidenav, false to close it
472+
* @returns {*} promise to be resolved when the view animation finishes
460473
*/
461-
function toggleOpen( isOpen ) {
462-
if (scope.isOpen == isOpen ) {
463-
474+
function toggleOpen(isOpen) {
475+
if (scope.isOpen === isOpen) {
464476
return $q.when(true);
465-
466477
} else {
467478
if (scope.isOpen && sidenavCtrl.onCloseCb) sidenavCtrl.onCloseCb();
468479

469-
return $q(function(resolve){
480+
return $q(function(resolve) {
470481
// Toggle value to force an async `updateIsOpen()` to run
471482
scope.isOpen = isOpen;
472483

@@ -483,32 +494,30 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInterac
483494
resolve(result);
484495
});
485496
});
486-
487497
});
488-
489498
}
490499
}
491500

492501
/**
493502
* Auto-close sideNav when the `escape` key is pressed.
494-
* @param evt
503+
* @param {KeyboardEvent} ev keydown event
495504
*/
496505
function onKeyDown(ev) {
497506
var isEscape = (ev.keyCode === $mdConstant.KEY_CODE.ESCAPE);
498507
return isEscape ? close(ev) : $q.when(true);
499508
}
500509

501510
/**
502-
* With backdrop `clicks` or `escape` key-press, immediately
503-
* apply the CSS close transition... Then notify the controller
504-
* to close() and perform its own actions.
511+
* With backdrop `clicks` or `escape` key-press, immediately apply the CSS close transition...
512+
* Then notify the controller to close() and perform its own actions.
513+
* @param {Event} ev
514+
* @returns {*}
505515
*/
506516
function close(ev) {
507517
ev.preventDefault();
508518

509519
return sidenavCtrl.close();
510520
}
511-
512521
}
513522
}
514523

@@ -519,7 +528,6 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInterac
519528
* @module material.components.sidenav
520529
*/
521530
function SidenavController($scope, $attrs, $mdComponentRegistry, $q, $interpolate) {
522-
523531
var self = this;
524532

525533
// Use Default internal method until overridden by directive postLink
@@ -552,7 +560,8 @@ function SidenavController($scope, $attrs, $mdComponentRegistry, $q, $interpolat
552560
if (hasDataBinding) {
553561
$attrs.$observe('mdComponentId', function(id) {
554562
if (id && id !== self.$$mdHandle) {
555-
self.destroy(); // `destroy` only deregisters the old component id so we can add the new one.
563+
// `destroy` only deregisters the old component id so we can add the new one.
564+
self.destroy();
556565
self.destroy = $mdComponentRegistry.register(self, id);
557566
}
558567
});

0 commit comments

Comments
 (0)