Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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