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

Add a character-specific class to letters #41

Closed
wants to merge 6 commits into from
41 changes: 30 additions & 11 deletions jquery.lettering.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
/*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.
*
* Date: Mon Sep 20 17:14:00 2010 -0600
*/
(function($){
function injector(t, splitter, klass, after) {
var a = t.text().split(splitter), inject = '';
var format = {
line: function(i, line) {
return '<span class="line'+(i+1)+'">'+line+'</span>';
},

word: function(i, word) {
return '<span class="word'+(i+1)+'">'+word+'</span>';
},

char: function(i, char) {
if (char === '&') {
char = '&amp;';
}
quot = char === '"' ? "'" : '"';
return '<span class="char'+(i+1)+'" data-char='+quot+char+quot+'>'+char+'</span>';
}
};

function injector(t, splitter, type, after) {
var a = t.text().split(splitter),
inject = '';
if (a.length) {
$(a).each(function(i, item) {
inject += '<span class="'+klass+(i+1)+'">'+item+'</span>'+after;
});
$.each(a, function(i, item) {
inject += format[type](i, item)+after;
});
t.empty().append(inject);
}
}

var methods = {
init : function() {

Expand All @@ -37,14 +56,14 @@
});

},

lines : function() {

return this.each(function() {
var r = "eefec303079ad17405c889e092e105b0";
// Because it's hard to split a <br/> tag consistently across browsers,
// (*ahem* IE *ahem*), we replace all <br/> 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 <br/> 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', '');
});
Expand Down