Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MMM-XKCD.js #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions MMM-XKCD.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,26 @@ Module.register("MMM-XKCD", {
// Limit width or height of comic on load
comic.onload = function() {
const width = this.width;
if (this.config.limitComicHeight > 0) {

// This updated section allows you to set a maximum for both the width and height and
// scales the final size so the comic is no larger than either. Making either 0 will
// still scale the entire comic to the max size of the other parameter.
const height = this.height;
let comicRatio = width / height;

if (this.config.limitComicWidth != 0 &&
this.config.limitComicHeight != 0) {
if (width / this.config.limitComicWidth > height / this.config.limitComicHeight) {
comic.style.width = this.config.limitComicWidth + "px";
comic.style.height = this.config.limitComicWidth / comicRatio + "px";
} else {
comic.style.height = this.config.limitComicHeight + "px";
comic.style.width = this.config.limitComicHeight * comicRatio + "px";
}
} else if (this.config.limitComicHeight > 0) {
comic.style.height = this.config.limitComicHeight + "px";
comic.style.width = "auto";
} else if (this.config.limitComicWidth > 0 && width > this.config.limitComicWidth) {
} else {
comic.style.width = this.config.limitComicWidth + "px";
comic.style.height = "auto";
}
Expand All @@ -105,4 +121,4 @@ Module.register("MMM-XKCD", {
this.updateDom(this.animationSpeed);
}
}
});
});