From a36cae4e714af52dc976cd81bb755480dbfdf977 Mon Sep 17 00:00:00 2001 From: Jason Tremblay Date: Thu, 5 Sep 2013 16:32:30 -0400 Subject: [PATCH 1/6] Add a character-specific class to enable kerning combinations It can be useful to kern every instance of certain letter combinations. With these extra classes, you can now apply more broad css rules. For example, to consistently tighten the space between the characters "A" and "W", you could use the css rule `.char-a + .char-w { margin-left:-2px; }` --- jquery.lettering.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jquery.lettering.js b/jquery.lettering.js index 8a693c8..b3304bd 100644 --- a/jquery.lettering.js +++ b/jquery.lettering.js @@ -15,7 +15,12 @@ var a = t.text().split(splitter), inject = ''; if (a.length) { $(a).each(function(i, item) { - inject += ''+item+''+after; + var klasses = []; + klasses.push(klass+(i+1)); + if (item.match(/^[a-z]{1}$/i)) { + klasses.push(klass+'-'+item); + } + inject += ''+item+''+after; }); t.empty().append(inject); } From 7e482f0737315933a0a0acc1372145a7c4a879a5 Mon Sep 17 00:00:00 2001 From: Jason Tremblay Date: Mon, 9 Sep 2013 22:06:04 -0400 Subject: [PATCH 2/6] add char- class for any character, but encode non-latin characters --- jquery.lettering.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/jquery.lettering.js b/jquery.lettering.js index b3304bd..2324a3b 100644 --- a/jquery.lettering.js +++ b/jquery.lettering.js @@ -1,9 +1,9 @@ /*global jQuery */ -/*! +/*! * Lettering.JS 0.6.1 * * Copyright 2010, Dave Rupert http://daverupert.com -* Released under the WTFPL license +* Released under the WTFPL license * http://sam.zoy.org/wtfpl/ * * Thanks to Paul Irish - http://paulirish.com - for the feedback. @@ -11,21 +11,28 @@ * Date: Mon Sep 20 17:14:00 2010 -0600 */ (function($){ + + function char_klass(item) { + var ok_chars = /^[A-Za-z0-9]{1}$/, + suffix = item.match(ok_chars) ? item : encodeURIComponent(item).replace(/%/g,''); + return 'char-'+suffix; + } + function injector(t, splitter, klass, after) { var a = t.text().split(splitter), inject = ''; if (a.length) { $(a).each(function(i, item) { var klasses = []; klasses.push(klass+(i+1)); - if (item.match(/^[a-z]{1}$/i)) { - klasses.push(klass+'-'+item); + if (klass === 'char') { + klasses.push(char_klass(item)); } inject += ''+item+''+after; - }); + }); t.empty().append(inject); } } - + var methods = { init : function() { @@ -42,14 +49,14 @@ }); }, - + lines : function() { return this.each(function() { var r = "eefec303079ad17405c889e092e105b0"; // Because it's hard to split a
tag consistently across browsers, - // (*ahem* IE *ahem*), we replace all
instances with an md5 hash - // (of the word "split"). If you're trying to use this plugin on that + // (*ahem* IE *ahem*), we replace all
instances with an md5 hash + // (of the word "split"). If you're trying to use this plugin on that // md5 hash string, it will fail because you're being ridiculous. injector($(this).children("br").replaceWith(r).end(), r, 'line', ''); }); From 90787ea78236f1b7528e51a1eb10c85fa1bc2d54 Mon Sep 17 00:00:00 2001 From: Jason Tremblay Date: Mon, 9 Sep 2013 22:22:15 -0400 Subject: [PATCH 3/6] handle single-quote character, juggle the conditionals --- jquery.lettering.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/jquery.lettering.js b/jquery.lettering.js index 2324a3b..7b6a560 100644 --- a/jquery.lettering.js +++ b/jquery.lettering.js @@ -13,9 +13,13 @@ (function($){ function char_klass(item) { - var ok_chars = /^[A-Za-z0-9]{1}$/, - suffix = item.match(ok_chars) ? item : encodeURIComponent(item).replace(/%/g,''); - return 'char-'+suffix; + var ok_chars = /^[A-Za-z0-9]{1}$/; + if (item === "'") { + item = '27'; + } else if (!item.match(ok_chars)) { + item = encodeURIComponent(item).replace(/%/g,''); + } + return 'char-'+item; } function injector(t, splitter, klass, after) { From 4c482a22bcd5a2593e4790821d9ce496da4523cd Mon Sep 17 00:00:00 2001 From: Jason Tremblay Date: Thu, 19 Sep 2013 22:07:44 -0400 Subject: [PATCH 4/6] added data-char attribute to character spans / split formatting into separate methods for legibility --- jquery.lettering.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/jquery.lettering.js b/jquery.lettering.js index 7b6a560..c78c059 100644 --- a/jquery.lettering.js +++ b/jquery.lettering.js @@ -11,27 +11,26 @@ * Date: Mon Sep 20 17:14:00 2010 -0600 */ (function($){ + var format = { + line: function(i, line) { + return ''+line+''; + }, + + word: function(i, word) { + return ''+word+''; + }, - function char_klass(item) { - var ok_chars = /^[A-Za-z0-9]{1}$/; - if (item === "'") { - item = '27'; - } else if (!item.match(ok_chars)) { - item = encodeURIComponent(item).replace(/%/g,''); + char: function(i, char) { + return ''+char+''; } - return 'char-'+item; - } + }; - function injector(t, splitter, klass, after) { - var a = t.text().split(splitter), inject = ''; + function injector(t, splitter, type, after) { + var a = t.text().split(splitter), + inject = ''; if (a.length) { - $(a).each(function(i, item) { - var klasses = []; - klasses.push(klass+(i+1)); - if (klass === 'char') { - klasses.push(char_klass(item)); - } - inject += ''+item+''+after; + $.each(a, function(i, item) { + inject += format[type](i, item)+after; }); t.empty().append(inject); } From 8497fe42af3f2b7aa38375ac960a3e0eb46139a6 Mon Sep 17 00:00:00 2001 From: Jason Tremblay Date: Thu, 19 Sep 2013 22:30:24 -0400 Subject: [PATCH 5/6] no data- attribute for word / change how data- attribute is quoted if character is ampersand or double-quote --- jquery.lettering.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jquery.lettering.js b/jquery.lettering.js index c78c059..676c504 100644 --- a/jquery.lettering.js +++ b/jquery.lettering.js @@ -17,11 +17,12 @@ }, word: function(i, word) { - return ''+word+''; + return ''+word+''; }, char: function(i, char) { - return ''+char+''; + quot = char.match(/[&"]/) ? "'" : '"'; + return ''+char+''; } }; From a119a14ad1eedffc8ecc1b7c222b372396ab9984 Mon Sep 17 00:00:00 2001 From: Jason Tremblay Date: Fri, 20 Sep 2013 00:10:18 -0400 Subject: [PATCH 6/6] encode ampersand / double-quote is only other special-case --- jquery.lettering.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jquery.lettering.js b/jquery.lettering.js index 676c504..1177420 100644 --- a/jquery.lettering.js +++ b/jquery.lettering.js @@ -21,7 +21,10 @@ }, char: function(i, char) { - quot = char.match(/[&"]/) ? "'" : '"'; + if (char === '&') { + char = '&'; + } + quot = char === '"' ? "'" : '"'; return ''+char+''; } };