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

Commit b1e3ae7

Browse files
committed
refactor(interimElement): no longer pass controller to options.onShow()
- it does not appear to be used by any components that depend on interimElement - panel, bottom sheet, tooltip, dialog, toast - improve docs, comments and JSDoc types - for `$mdDialog`, `$mdCompiler`, `$mdToast`, and `$$interimElement`
1 parent 89c76e8 commit b1e3ae7

File tree

4 files changed

+48
-33
lines changed

4 files changed

+48
-33
lines changed

src/components/dialog/dialog.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,12 @@ function MdDialogDirective($$rAF, $mdTheming, $mdDialog) {
458458
* @param {Object} optionsOrPreset Either provide a dialog preset returned from `alert()`,
459459
* `prompt()`, or `confirm()`; or an options object with the following properties:
460460
* - `templateUrl` - `{string=}`: The url of a template that will be used as the content
461-
* of the dialog.
461+
* of the dialog.
462462
* - `template` - `{string=}`: HTML template to show in the dialog. This **must** be trusted HTML
463463
* with respect to Angular's [$sce service](https://docs.angularjs.org/api/ng/service/$sce).
464464
* This template should **never** be constructed with any kind of user input or user data.
465465
* - `contentElement` - `{string|Element}`: Instead of using a template, which will be compiled
466-
* each time a dialog opens, you can also use a DOM element.<br/>
466+
* each time a dialog opens, you can also use a DOM element.<br/>
467467
* * When specifying an element, which is present on the DOM, `$mdDialog` will temporary fetch
468468
* the element into the dialog and restores it at the old DOM position upon close.
469469
* * When specifying a string, the string be used as a CSS selector, to lookup for the element
@@ -485,7 +485,7 @@ function MdDialogDirective($$rAF, $mdTheming, $mdDialog) {
485485
* This scope will be destroyed when the dialog is removed unless `preserveScope` is set to
486486
* true.
487487
* - `preserveScope` - `{boolean=}`: whether to preserve the scope when the element is removed.
488-
* Default is false
488+
* Default is false
489489
* - `disableParentScroll` - `{boolean=}`: Whether to disable scrolling while the dialog is open.
490490
* Default true.
491491
* - `hasBackdrop` - `{boolean=}`: Whether there should be an opaque backdrop behind the dialog.
@@ -497,31 +497,30 @@ function MdDialogDirective($$rAF, $mdTheming, $mdDialog) {
497497
* - `focusOnOpen` - `{boolean=}`: An option to override focus behavior on open. Only disable if
498498
* focusing some other way, as focus management is required for dialogs to be accessible.
499499
* Defaults to true.
500-
* - `controller` - `{function|string=}`: The controller to associate with the dialog. The
501-
* controller will be injected with the local `$mdDialog`, which passes along a scope for the
502-
* dialog.
500+
* - `controller` - `{Function|string=}`: The controller to associate with the dialog. The
501+
* controller will be injected with the local `$mdDialog`, which passes along a scope for the
502+
* dialog.
503503
* - `locals` - `{Object=}`: An object containing key/value pairs. The keys will be used as names
504504
* of values to inject into the controller. For example, `locals: {three: 3}` would inject
505505
* `three` into the controller, with the value 3. If `bindToController` is true, they will be
506506
* copied to the controller instead.
507507
* - `bindToController` - `bool`: bind the locals to the controller, instead of passing them in.
508-
* - `resolve` - `{function=}`: Similar to locals, except it takes as values functions that return
509-
* promises, and the
510-
* dialog will not open until all of the promises resolve.
508+
* - `resolve` - `{Function=}`: Similar to locals, except it takes as values functions that return
509+
* promises, and the dialog will not open until all of the promises resolve.
511510
* - `controllerAs` - `{string=}`: An alias to assign the controller to on the scope.
512511
* - `parent` - `{element=}`: The element to append the dialog to. Defaults to appending
513512
* to the root element of the application.
514-
* - `onShowing` - `function(scope, element)`: Callback function used to announce the show()
515-
* action is starting.
516-
* - `onComplete` - `function(scope, element)`: Callback function used to announce when the show()
517-
* action is finished.
518-
* - `onRemoving` - `function(element, removePromise)`: Callback function used to announce the
513+
* - `onShowing` - `Function(scope, element, options: Object=, controller: Object)=`: Callback
514+
* function used to notify the show() animation is starting.
515+
* - `onComplete` - `Function(scope, element, options: Object=)=`: Callback function used to
516+
* notify when the show() animation is finished.
517+
* - `onRemoving` - `Function(element, removePromise)`: Callback function used to announce the
519518
* close/hide() action is starting. This allows developers to run custom animations
520519
* in parallel with the close animations.
521520
* - `fullscreen` `{boolean=}`: An option to toggle whether the dialog should show in fullscreen
522521
* or not. Defaults to `false`.
523522
* - `multiple` `{boolean=}`: An option to allow this dialog to display over one that's currently
524-
* open.
523+
* open.
525524
* @returns {Promise} A promise that can be resolved with `$mdDialog.hide()` or
526525
* rejected with `$mdDialog.cancel()`.
527526
*/

src/components/toast/toast.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ function MdToastProvider($$interimElementProvider) {
426426
}
427427
}
428428

429-
// We have to return the innerHTMl, because we do not want to have the `md-template`
429+
// We have to return the innerHTML, because we do not want to have the `md-template`
430430
// element to be the root element of our interimElement.
431431
return templateRoot.innerHTML;
432432
}

src/core/services/compiler/compiler.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,29 +154,29 @@ function MdCompilerProvider() {
154154
* dependency. If the result is a promise, it is resolved before its value is
155155
* injected into the controller.
156156
*
157-
* @returns {Object} promise A promise, which will be resolved with a `compileData` object.
158-
* `compileData` has the following properties:
157+
* @returns {Q.Promise<{element: JQLite, link: Function, locals: Object, cleanup: any,
158+
* controller: Object=}>} promise A promise, which will be resolved with a `compileData` object.
159+
* `compileData` has the following properties:
159160
*
160-
* - `element` - `{Element}`: an uncompiled element matching the provided template.
161+
* - `element` - `{JQLite}`: an uncompiled element matching the provided template.
161162
* - `link` - `{function(scope)}`: A link function, which, when called, will compile
162163
* the element and instantiate the provided controller (if given).
163164
* - `locals` - `{Object}`: The locals which will be passed into the controller once `link` is
164165
* called. If `bindToController` is true, they will be copied to the ctrl instead
165166
*/
166167
MdCompilerService.prototype.compile = function(options) {
167-
168168
if (options.contentElement) {
169169
return this._prepareContentElement(options);
170170
} else {
171171
return this._compileTemplate(options);
172172
}
173-
174173
};
175174

176175
/**
177176
* Instead of compiling any template, the compiler just fetches an existing HTML element from the
178177
* DOM and provides a restore function to put the element back it old DOM position.
179178
* @param {!Object} options Options to be used for the compiler.
179+
* @returns {Q.Promise<{element: JQLite, link: Function, locals: Object, cleanup: any}>}
180180
*/
181181
MdCompilerService.prototype._prepareContentElement = function(options) {
182182

@@ -196,7 +196,8 @@ function MdCompilerProvider() {
196196
/**
197197
* Compiles a template by considering all options and waiting for all resolves to be ready.
198198
* @param {!Object} options Compile options
199-
* @returns {!Object} Compile data with link function.
199+
* @returns {!Q.Promise<{element: JQLite, link: Function, locals: Object, cleanup: any}>} Compile
200+
* data with link function.
200201
*/
201202
MdCompilerService.prototype._compileTemplate = function(options) {
202203

@@ -245,7 +246,7 @@ function MdCompilerProvider() {
245246
* @param {!Object} locals Locals to be injected to the controller if present
246247
* @param {!JQLite} element Element to be compiled and linked
247248
* @param {!Object} options Options to be used for linking.
248-
* @returns {!Object} Compile data with link function.
249+
* @returns {!{element: JQLite, link: Function, locals: Object, cleanup: any, controller: Object}} Compile data with link function.
249250
*/
250251
MdCompilerService.prototype._compileElement = function(locals, element, options) {
251252
var self = this;

src/core/services/interimElement/interimElement.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ function InterimElementProvider() {
278278
* Adds the `$interimElement` to the DOM and returns a special promise that will be resolved
279279
* or rejected with hide or cancel, respectively.
280280
*
281-
* @param {object} options map of options and values
281+
* @param {Object} options map of options and values
282282
* @returns {Promise} a Promise that will be resolved when hide() is called or rejected when
283283
* cancel() is called.
284284
*/
@@ -491,8 +491,9 @@ function InterimElementProvider() {
491491
};
492492

493493
/**
494-
* Compile, link, and show this interim element
495-
* Use optional autoHided and transition-in effects
494+
* Compile, link, and show this interim element. Use optional autoHide and transition-in
495+
* effects.
496+
* @return {Q.Promise}
496497
*/
497498
function createAndTransitionIn() {
498499
return $q(function(resolve, reject) {
@@ -606,6 +607,9 @@ function InterimElementProvider() {
606607

607608
/**
608609
* Compile an element with a templateUrl, controller, and locals
610+
* @param {Object} options
611+
* @return {Q.Promise<{element: JQLite=, link: Function, locals: Object, cleanup: any=,
612+
* controller: Object=}>}
609613
*/
610614
function compileElement(options) {
611615

@@ -622,9 +626,12 @@ function InterimElementProvider() {
622626
}
623627

624628
/**
625-
* Link an element with compiled configuration
629+
* Link an element with compiled configuration
630+
* @param {{element: JQLite=, link: Function, locals: Object, controller: Object=}} compileData
631+
* @param {Object} options
632+
* @return {JQLite}
626633
*/
627-
function linkElement(compileData, options){
634+
function linkElement(compileData, options) {
628635
angular.extend(compileData.locals, options);
629636

630637
var element = compileData.link(options.scope);
@@ -638,7 +645,10 @@ function InterimElementProvider() {
638645
}
639646

640647
/**
641-
* Search for parent at insertion time, if not specified
648+
* Search for parent at insertion time, if not specified.
649+
* @param {JQLite} element
650+
* @param {Object} options
651+
* @return {JQLite}
642652
*/
643653
function findParent(element, options) {
644654
var parent = options.parent;
@@ -660,7 +670,7 @@ function InterimElementProvider() {
660670
el = $rootElement[0].querySelector(':not(svg) > body');
661671
}
662672
if (!el) el = $rootElement[0];
663-
if (el.nodeName == '#comment') {
673+
if (el.nodeName === '#comment') {
664674
el = $document[0].body;
665675
}
666676
return angular.element(el);
@@ -690,8 +700,12 @@ function InterimElementProvider() {
690700
}
691701

692702
/**
693-
* Show the element ( with transitions), notify complete and start
694-
* optional auto-Hide
703+
* Show the element (with transitions), notify complete and start optional auto hiding
704+
* timer.
705+
* @param {JQLite} element
706+
* @param {Object} options
707+
* @param {Object} controller
708+
* @return {Q.Promise<JQLite>}
695709
*/
696710
function showElement(element, options, controller) {
697711
// Trigger onShowing callback before the `show()` starts
@@ -701,6 +715,7 @@ function InterimElementProvider() {
701715

702716
// Necessary for consistency between AngularJS 1.5 and 1.6.
703717
try {
718+
// This fourth controller parameter is used by $mdDialog in beforeShow().
704719
notifyShowing(options.scope, element, options, controller);
705720
} catch (e) {
706721
return $q.reject(e);
@@ -709,7 +724,7 @@ function InterimElementProvider() {
709724
return $q(function (resolve, reject) {
710725
try {
711726
// Start transitionIn
712-
$q.when(options.onShow(options.scope, element, options, controller))
727+
$q.when(options.onShow(options.scope, element, options))
713728
.then(function () {
714729
notifyComplete(options.scope, element, options);
715730
startAutoHide();

0 commit comments

Comments
 (0)