From 220573f13702a7b79605c3c54ea386c7ca501d99 Mon Sep 17 00:00:00 2001 From: euvl Date: Mon, 9 Oct 2017 14:04:12 +0100 Subject: [PATCH] Tiny refactoring of the new pull request (passing linting) --- .github/ISSUE_TEMPLATE.md | 3 +- src/Modal.vue | 59 ++++++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 1fa2061..9eab08a 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,2 +1 @@ - \ No newline at end of file + diff --git a/src/Modal.vue b/src/Modal.vue index 22e7e81..bc0c64a 100644 --- a/src/Modal.vue +++ b/src/Modal.vue @@ -217,35 +217,44 @@ window.addEventListener('resize', this.onWindowResize) this.onWindowResize() - + /** + * Making sure that autoHeight is enabled when using "scrollable" + */ if (this.scrollable && !this.isAutoHeight) { console.warn(`Modal "${this.name}" has scrollable flag set to true ` + `but height is not "auto" (${this.height})`) } - - // init MutationObserver /** - * MutationObserver feature detection: - * Detects if MutationObserver is available, return false if not. - * No polyfill is provided here, so height 'auto' recalculation will simply stay at its initial height (won't crash). - * (Provide polyfill to support IE < 11) + * Only observe when using height: 'auto' + * The callback will be called when modal DOM changes, + * this is for updating the `top` attribute for height 'auto' modals. */ - const MutationObserver = (function () { - const prefixes = ['', 'WebKit', 'Moz', 'O', 'Ms'] - for (let i = 0; i < prefixes.length; i++) { - if (prefixes[i] + 'MutationObserver' in window) { - return window[prefixes[i] + 'MutationObserver'] + if (this.isAutoHeight) { + /** + * MutationObserver feature detection: + * Detects if MutationObserver is available, return false if not. + * No polyfill is provided here, so height 'auto' recalculation will + * simply stay at its initial height (won't crash). + * (Provide polyfill to support IE < 11) + */ + const MutationObserver = (function () { + const prefixes = ['', 'WebKit', 'Moz', 'O', 'Ms'] + + for (let i = 0; i < prefixes.length; i++) { + let name = prefixes[i] + 'MutationObserver' + + if (name in window) { + return window[name] + } } + return false + }()) + + if (MutationObserver) { + this.mutationObserver = new MutationObserver(mutations => { + this.updateRenderedHeight() + }) } - return false - }()) - // Only observe when using height: 'auto' - // The callback will be called when modal DOM changes, - // this is for updating the `top` attribute for height 'auto' modals. - if (this.isAutoHeight && MutationObserver) { - this.mutationObserver = new MutationObserver(mutations => { - this.updateRenderedHeight() - }) } }, /** @@ -563,7 +572,8 @@ * 2. MutationObserver's observe callback */ updateRenderedHeight () { - this.modal.renderedHeight = this.$refs.modal.getBoundingClientRect().height + this.modal.renderedHeight = this.$refs.modal + .getBoundingClientRect().height }, /** @@ -572,7 +582,10 @@ */ observe () { if (this.mutationObserver) { - this.mutationObserver.observe(this.$refs.modal, { childList: true, subtree: true }) + this.mutationObserver.observe(this.$refs.modal, { + childList: true, + subtree: true + }) } },