From 3adec2199d2328494f286fe9dda8d7debfafd661 Mon Sep 17 00:00:00 2001 From: Saint Clair Date: Tue, 3 Sep 2013 08:31:07 -0300 Subject: [PATCH 1/5] Improved performance .css 'jquery' x .style 'js' --- jquery.fittext.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jquery.fittext.js b/jquery.fittext.js index 080b82e..97640c3 100644 --- a/jquery.fittext.js +++ b/jquery.fittext.js @@ -27,7 +27,10 @@ // Resizer() resizes items based on the object width divided by the compressor * 10 var resizer = function () { - $this.css('font-size', Math.max(Math.min($this.width() / (compressor*10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize))); + var valFontSize = Math.max(Math.min($this.width() / (compressor*10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize)); + + var cachedStyle = document.getElementById($this.attr('id')).style; + cachedStyle.fontSize = valFontSize; }; // Call once to set. From f7fe25d92d59cb48caf0f09be25c5c3ed180c7d0 Mon Sep 17 00:00:00 2001 From: Saint Clair Date: Thu, 12 Sep 2013 08:54:06 -0300 Subject: [PATCH 2/5] [Improving performance] Using the style.fontSize and style.width --- jquery.fittext.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/jquery.fittext.js b/jquery.fittext.js index 97640c3..4b03da3 100644 --- a/jquery.fittext.js +++ b/jquery.fittext.js @@ -27,10 +27,13 @@ // Resizer() resizes items based on the object width divided by the compressor * 10 var resizer = function () { - var valFontSize = Math.max(Math.min($this.width() / (compressor*10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize)); - - var cachedStyle = document.getElementById($this.attr('id')).style; - cachedStyle.fontSize = valFontSize; + $this[0].style.fontSize = Math.max( + Math.min( + $this[0].style.width / (compressor*10), + parseFloat(settings.maxFontSize) + ), + parseFloat(settings.minFontSize) + ) +'px'; // Don't forget to add PX value or it breaks }; // Call once to set. From df04e938691c04652d91b0885405981ea8e40e74 Mon Sep 17 00:00:00 2001 From: Saint Clair Date: Thu, 12 Sep 2013 17:04:12 -0300 Subject: [PATCH 3/5] [Improving performance] Using the style.fontSize --- jquery.fittext.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.fittext.js b/jquery.fittext.js index 4b03da3..10e6653 100644 --- a/jquery.fittext.js +++ b/jquery.fittext.js @@ -29,7 +29,7 @@ var resizer = function () { $this[0].style.fontSize = Math.max( Math.min( - $this[0].style.width / (compressor*10), + $this[0].width() / (compressor*10), parseFloat(settings.maxFontSize) ), parseFloat(settings.minFontSize) From 810b7f698a8cc1d9b35eba7967cf73ea70a0cb48 Mon Sep 17 00:00:00 2001 From: Saint Clair Date: Thu, 12 Sep 2013 17:28:16 -0300 Subject: [PATCH 4/5] [Fixed] getting width via clientWidth --- jquery.fittext.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jquery.fittext.js b/jquery.fittext.js index 10e6653..55f0c3d 100644 --- a/jquery.fittext.js +++ b/jquery.fittext.js @@ -26,14 +26,14 @@ var $this = $(this); // Resizer() resizes items based on the object width divided by the compressor * 10 - var resizer = function () { + var resizer = function () { $this[0].style.fontSize = Math.max( Math.min( - $this[0].width() / (compressor*10), + $this[0].clientWidth / (compressor*10), parseFloat(settings.maxFontSize) ), parseFloat(settings.minFontSize) - ) +'px'; // Don't forget to add PX value or it breaks + ).toFixed(2) +'px'; // Don't forget to add PX value or it breaks }; // Call once to set. From c45cf70d64e41f4c5a0445351c6d9c0fc1937872 Mon Sep 17 00:00:00 2001 From: Saint Clair Date: Thu, 12 Sep 2013 17:45:57 -0300 Subject: [PATCH 5/5] Improved performance .css 'jquery' x .style 'js' --- jquery.fittext.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/jquery.fittext.js b/jquery.fittext.js index 55f0c3d..10037f1 100644 --- a/jquery.fittext.js +++ b/jquery.fittext.js @@ -26,14 +26,14 @@ var $this = $(this); // Resizer() resizes items based on the object width divided by the compressor * 10 - var resizer = function () { - $this[0].style.fontSize = Math.max( - Math.min( - $this[0].clientWidth / (compressor*10), - parseFloat(settings.maxFontSize) - ), - parseFloat(settings.minFontSize) - ).toFixed(2) +'px'; // Don't forget to add PX value or it breaks + var resizer = function () { + $this[0].style.fontSize = Math.max( + Math.min( + $this.width() / (compressor*10), + parseFloat(settings.maxFontSize) + ), + parseFloat(settings.minFontSize) + ) +'px'; // Don't forget to add PX value or it breaks }; // Call once to set.