From 03fcf0cbd61b823f107208300c3316c5c7ab2583 Mon Sep 17 00:00:00 2001 From: kevcenteno Date: Fri, 23 Aug 2013 15:30:06 -0400 Subject: [PATCH 1/8] added option to use em units for min and max font --- flowtype.js | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/flowtype.js b/flowtype.js index 4a918b0..96ab546 100644 --- a/flowtype.js +++ b/flowtype.js @@ -23,22 +23,38 @@ maxFont : 9999, minFont : 1, fontRatio : 35, - lineRatio : 1.45 + lineRatio : 1.45, + useEm: false }, options), // Do the magic math // ================= changes = function(el) { var $el = $(el), - elw = $el.width(), - width = elw > settings.maximum ? settings.maximum : elw < settings.minimum ? settings.minimum : elw, - fontBase = width / settings.fontRatio, - fontSize = fontBase > settings.maxFont ? settings.maxFont : fontBase < settings.minFont ? settings.minFont : fontBase; + elw = $el.width(); - $el.css({ - 'font-size' : fontSize + 'px', - 'line-height' : fontSize * settings.lineRatio + 'px' - }); + if (!settings.useEm) { + var width = elw > settings.maximum ? settings.maximum : elw < settings.minimum ? settings.minimum : elw, + fontBase = width / settings.fontRatio, + fontSize = fontBase > settings.maxFont ? settings.maxFont : fontBase < settings.minFont ? settings.minFont : fontBase; + + $el.css({ + 'font-size' : fontSize + 'px', + 'line-height' : fontSize * settings.lineRatio + 'px' + }); + } + else + { + elw = elw / parseFloat($("body").css("font-size")); + var width = elw > settings.maximum ? settings.maximum : elw < settings.minimum ? settings.minimum : elw, + fontBase = width / settings.fontRatio, + fontSize = fontBase > settings.maxFont ? settings.maxFont : fontBase < settings.minFont ? settings.minFont : fontBase; + + $el.css({ + 'font-size' : fontSize + 'em', + 'line-height' : settings.lineRatio + 'em' + }); + } }; // Make the magic visible From 8ba065e8ba36655befa209df9802da6300cefefe Mon Sep 17 00:00:00 2001 From: kevcenteno Date: Fri, 23 Aug 2013 17:44:37 -0400 Subject: [PATCH 2/8] refactored to use less if statements and avoid duplication of code --- flowtype.js | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/flowtype.js b/flowtype.js index 96ab546..7829874 100644 --- a/flowtype.js +++ b/flowtype.js @@ -31,30 +31,22 @@ // ================= changes = function(el) { var $el = $(el), - elw = $el.width(); + unit = 'px', + elw = $el.width(); - if (!settings.useEm) { - var width = elw > settings.maximum ? settings.maximum : elw < settings.minimum ? settings.minimum : elw, - fontBase = width / settings.fontRatio, - fontSize = fontBase > settings.maxFont ? settings.maxFont : fontBase < settings.minFont ? settings.minFont : fontBase; - - $el.css({ - 'font-size' : fontSize + 'px', - 'line-height' : fontSize * settings.lineRatio + 'px' - }); + if (settings.useEm) { + unit = 'em'; + elw = elw / parseFloat($('body').css('font-size')); } - else - { - elw = elw / parseFloat($("body").css("font-size")); - var width = elw > settings.maximum ? settings.maximum : elw < settings.minimum ? settings.minimum : elw, + + var width = elw > settings.maximum ? settings.maximum : elw < settings.minimum ? settings.minimum : elw, fontBase = width / settings.fontRatio, fontSize = fontBase > settings.maxFont ? settings.maxFont : fontBase < settings.minFont ? settings.minFont : fontBase; - $el.css({ - 'font-size' : fontSize + 'em', - 'line-height' : settings.lineRatio + 'em' - }); - } + $el.css({ + 'font-size' : fontSize + unit, + 'line-height' : settings.useEm ? settings.lineRatio + unit : fontSize * settings.lineRatio + unit + }); }; // Make the magic visible From 0aa7dd75bd322ea760a86d6734632709abaa77a6 Mon Sep 17 00:00:00 2001 From: kevcenteno Date: Tue, 10 Feb 2015 12:14:12 -0500 Subject: [PATCH 3/8] test revert --- flowtype.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/flowtype.js b/flowtype.js index 7829874..aa03de5 100644 --- a/flowtype.js +++ b/flowtype.js @@ -47,6 +47,10 @@ 'font-size' : fontSize + unit, 'line-height' : settings.useEm ? settings.lineRatio + unit : fontSize * settings.lineRatio + unit }); + + console.log('holler'); + console.log('at'); + console.log('your'); }; // Make the magic visible @@ -57,9 +61,10 @@ var that = this; // Make changes upon resize $(window).resize(function(){changes(that);}); + console.log('boy'); // Set changes on load changes(this); }); }; -}(jQuery)); \ No newline at end of file +}(jQuery)); From 08c127a3a301eeea8189f75f24a03a0cb8b8fcae Mon Sep 17 00:00:00 2001 From: Kevin Centeno Date: Tue, 10 Feb 2015 12:15:06 -0500 Subject: [PATCH 4/8] Revert "test revert" --- flowtype.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/flowtype.js b/flowtype.js index aa03de5..7829874 100644 --- a/flowtype.js +++ b/flowtype.js @@ -47,10 +47,6 @@ 'font-size' : fontSize + unit, 'line-height' : settings.useEm ? settings.lineRatio + unit : fontSize * settings.lineRatio + unit }); - - console.log('holler'); - console.log('at'); - console.log('your'); }; // Make the magic visible @@ -61,10 +57,9 @@ var that = this; // Make changes upon resize $(window).resize(function(){changes(that);}); - console.log('boy'); // Set changes on load changes(this); }); }; -}(jQuery)); +}(jQuery)); \ No newline at end of file From 9771c4565e3115afa18bcfe80d2b37cd4a5000d3 Mon Sep 17 00:00:00 2001 From: kevcenteno Date: Tue, 10 Feb 2015 12:33:30 -0500 Subject: [PATCH 5/8] holler --- flowtype.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flowtype.js b/flowtype.js index 7829874..4ca4c95 100644 --- a/flowtype.js +++ b/flowtype.js @@ -42,6 +42,7 @@ var width = elw > settings.maximum ? settings.maximum : elw < settings.minimum ? settings.minimum : elw, fontBase = width / settings.fontRatio, fontSize = fontBase > settings.maxFont ? settings.maxFont : fontBase < settings.minFont ? settings.minFont : fontBase; + console.log('holler'); $el.css({ 'font-size' : fontSize + unit, @@ -62,4 +63,4 @@ changes(this); }); }; -}(jQuery)); \ No newline at end of file +}(jQuery)); From 2f9d8d53258f666bdf77953c265e7ff287fcaa31 Mon Sep 17 00:00:00 2001 From: kevcenteno Date: Tue, 10 Feb 2015 12:33:43 -0500 Subject: [PATCH 6/8] at --- flowtype.js | 1 + 1 file changed, 1 insertion(+) diff --git a/flowtype.js b/flowtype.js index 4ca4c95..0fea539 100644 --- a/flowtype.js +++ b/flowtype.js @@ -43,6 +43,7 @@ fontBase = width / settings.fontRatio, fontSize = fontBase > settings.maxFont ? settings.maxFont : fontBase < settings.minFont ? settings.minFont : fontBase; console.log('holler'); + console.log('at'); $el.css({ 'font-size' : fontSize + unit, From 393653ee1359ffa1952ae77c83a04750ddca2309 Mon Sep 17 00:00:00 2001 From: kevcenteno Date: Tue, 10 Feb 2015 12:33:54 -0500 Subject: [PATCH 7/8] your --- flowtype.js | 1 + 1 file changed, 1 insertion(+) diff --git a/flowtype.js b/flowtype.js index 0fea539..13ffa11 100644 --- a/flowtype.js +++ b/flowtype.js @@ -44,6 +44,7 @@ fontSize = fontBase > settings.maxFont ? settings.maxFont : fontBase < settings.minFont ? settings.minFont : fontBase; console.log('holler'); console.log('at'); + console.log('your'); $el.css({ 'font-size' : fontSize + unit, From 383704d7115283e5b65db78c1b301cbcd667c0e4 Mon Sep 17 00:00:00 2001 From: Kevin Centeno Date: Tue, 10 Feb 2015 12:34:24 -0500 Subject: [PATCH 8/8] Revert "Test" --- flowtype.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/flowtype.js b/flowtype.js index 13ffa11..7829874 100644 --- a/flowtype.js +++ b/flowtype.js @@ -42,9 +42,6 @@ var width = elw > settings.maximum ? settings.maximum : elw < settings.minimum ? settings.minimum : elw, fontBase = width / settings.fontRatio, fontSize = fontBase > settings.maxFont ? settings.maxFont : fontBase < settings.minFont ? settings.minFont : fontBase; - console.log('holler'); - console.log('at'); - console.log('your'); $el.css({ 'font-size' : fontSize + unit, @@ -65,4 +62,4 @@ changes(this); }); }; -}(jQuery)); +}(jQuery)); \ No newline at end of file