/*global jquery */
/*!
* lettering.js 0.6.1
*
* copyright 2010, dave rupert http://daverupert.com
* 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 = '';
if (a.length) {
$(a).each(function(i, item) {
inject += ''+item+''+after;
});
t.empty().append(inject);
}
}
var methods = {
init : function() {
return this.each(function() {
injector($(this), '', 'char', '');
});
},
words : function() {
return this.each(function() {
injector($(this), ' ', 'word', ' ');
});
},
lines : function() {
return this.each(function() {
var r = "eefec303079ad17405c889e092e105b0";
// because it's hard to split a
tag consistently across browsers,
// (*ahem* ie *ahem*), we replaces 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', '');
});
}
};
$.fn.lettering = function( method ) {
// method calling logic
if ( method && methods[method] ) {
return methods[ method ].apply( this, [].slice.call( arguments, 1 ));
} else if ( method === 'letters' || ! method ) {
return methods.init.apply( this, [].slice.call( arguments, 0 ) ); // always pass an array
}
$.error( 'method ' + method + ' does not exist on jquery.lettering' );
return this;
};
})(jquery);