Skip to content

Commit

Permalink
fix issue where fitty would override css text now only updates releva…
Browse files Browse the repository at this point in the history
…nt styles
  • Loading branch information
rikschennink committed Jul 27, 2020
1 parent 9ffd0e2 commit 4322fd2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions dist/fitty.min.js

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

24 changes: 15 additions & 9 deletions dist/fitty.module.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* fitty v2.3.0 - Snugly resizes text to fit its parent container
* fitty v2.3.1 - Snugly resizes text to fit its parent container
* Copyright (c) 2020 Rik Schennink <rik@pqina.nl> (https://pqina.nl/)
*/
'use strict';
Expand Down Expand Up @@ -152,12 +152,9 @@ exports.default = function (w) {

// apply styles to single fitty
var applyStyle = function applyStyle(f) {

// remember original style, we need this to restore the fitty style when unsubscribing
if (!f.originalStyle) f.originalStyle = f.element.getAttribute('style') || '';

// set the new style to the original style plus the fitty styles
f.element.style.cssText = f.originalStyle + ';white-space:' + f.whiteSpace + ';display:' + f.display + ';font-size:' + f.currentFontSize + 'px';
f.element.style.whiteSpace = f.whiteSpace;
f.element.style.display = f.display;
f.element.style.fontSize = f.currentFontSize + 'px';
};

// dispatch a fit event on a fitty
Expand All @@ -182,6 +179,13 @@ exports.default = function (w) {

var init = function init(f) {

// save some of the original CSS properties before we change them
f.originalStyle = {
whiteSpace: f.element.style.whiteSpace,
display: f.element.style.display,
fontSize: f.element.style.fontSize
};

// should we observe DOM mutations
observeMutations(f);

Expand All @@ -206,8 +210,10 @@ exports.default = function (w) {
// stop observing DOM
if (f.observeMutations) f.observer.disconnect();

// reset font size to inherited size
f.element.style.cssText = f.originalStyle;
// reset the CSS properties we changes
f.element.style.whiteSpace = f.originalStyle.whiteSpace;
f.element.style.display = f.originalStyle.display;
f.element.style.fontSize = f.originalStyle.fontSize;
};
};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fitty",
"version": "2.3.0",
"version": "2.3.1",
"description": "Snugly resizes text to fit its parent container",
"keywords": [
"fit",
Expand Down Expand Up @@ -39,4 +39,4 @@
"url": "https://github.com/rikschennink/fitty/issues"
},
"homepage": "https://github.com/rikschennink/fitty"
}
}

0 comments on commit 4322fd2

Please sign in to comment.