From 2332bc0960477b0bea2a3a0a5b4ba8641a1f1808 Mon Sep 17 00:00:00 2001 From: Pablo Vazquez Date: Fri, 31 Aug 2018 14:20:59 +0200 Subject: [PATCH] jQuery: Small utility to set CSS display type Showing elements with jQuery's native .show() sets display as 'inline', but sometimes we need to set 'flex' or 'inline-block'. --- src/scripts/tutti/00_utils.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/scripts/tutti/00_utils.js b/src/scripts/tutti/00_utils.js index 99f853c4..47796812 100644 --- a/src/scripts/tutti/00_utils.js +++ b/src/scripts/tutti/00_utils.js @@ -64,4 +64,13 @@ return this; }; + // jQuery's show() sets display as 'inline', this utility sets it to whatever we want. + // Useful for buttons or links that need 'inline-block' or flex for correct padding and alignment. + $.fn.displayAs = function(display_type) { + if (typeof(display_type) === 'undefined') { + display_type = 'block'; + } + + this.css('display', display_type); + } }(jQuery));