Skip to content

Commit

Permalink
MDL-59936 javascript: hide modal footer without content
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwyllie authored and andrewnicols committed Oct 30, 2017
1 parent 40f1801 commit 368832d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/amd/build/modal.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 39 additions & 1 deletion lib/amd/src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes',
};

/**
* Set the modal footer element.
* Set the modal footer element. The footer element is made visible, if it
* isn't already.
*
* This method is overloaded to take either a string
* value for the body or a jQuery promise that is resolved with HTML and Javascript
Expand All @@ -368,6 +369,9 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes',
* @param {(string|object)} value The footer string or jQuery promise
*/
Modal.prototype.setFooter = function(value) {
// Make sure the footer is visible.
this.showFooter();

var footer = this.getFooter();

if (typeof value === 'string') {
Expand Down Expand Up @@ -396,6 +400,34 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes',
}
};

/**
* Check if the footer has any content in it.
*
* @method hasFooterContent
* @return {bool}
*/
Modal.prototype.hasFooterContent = function() {
return this.getFooter().children().length ? true : false;
};

/**
* Hide the footer element.
*
* @method hideFooter
*/
Modal.prototype.hideFooter = function() {
this.getFooter().addClass('hidden');
};

/**
* Show the footer element.
*
* @method showFooter
*/
Modal.prototype.showFooter = function() {
this.getFooter().removeClass('hidden');
};

/**
* Mark the modal as a large modal.
*
Expand Down Expand Up @@ -508,6 +540,12 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes',
return;
}

if (this.hasFooterContent()) {
this.showFooter();
} else {
this.hideFooter();
}

if (!this.isAttached) {
this.attachToDOM();
}
Expand Down

0 comments on commit 368832d

Please sign in to comment.