balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

jquery.lettering.js (1842B)


      1 "use strict";
      2 
      3 /*global jQuery */
      4 
      5 /*!	
      6 * Lettering.JS 0.6.1
      7 *
      8 * Copyright 2010, Dave Rupert http://daverupert.com
      9 * Released under the WTFPL license 
     10 * http://sam.zoy.org/wtfpl/
     11 *
     12 * Thanks to Paul Irish - http://paulirish.com - for the feedback.
     13 *
     14 * Date: Mon Sep 20 17:14:00 2010 -0600
     15 */
     16 (function ($) {
     17   function injector(t, splitter, klass, after) {
     18     var a = t.text().split(splitter),
     19         inject = '';
     20 
     21     if (a.length) {
     22       $(a).each(function (i, item) {
     23         inject += '<span class="' + klass + (i + 1) + '">' + item + '</span>' + after;
     24       });
     25       t.empty().append(inject);
     26     }
     27   }
     28 
     29   var methods = {
     30     init: function init() {
     31       return this.each(function () {
     32         injector($(this), '', 'char', '');
     33       });
     34     },
     35     words: function words() {
     36       return this.each(function () {
     37         injector($(this), ' ', 'word', ' ');
     38       });
     39     },
     40     lines: function lines() {
     41       return this.each(function () {
     42         var r = "eefec303079ad17405c889e092e105b0"; // Because it's hard to split a <br/> tag consistently across browsers,
     43         // (*ahem* IE *ahem*), we replaces all <br/> instances with an md5 hash 
     44         // (of the word "split").  If you're trying to use this plugin on that 
     45         // md5 hash string, it will fail because you're being ridiculous.
     46 
     47         injector($(this).children("br").replaceWith(r).end(), r, 'line', '');
     48       });
     49     }
     50   };
     51 
     52   $.fn.lettering = function (method) {
     53     // Method calling logic
     54     if (method && methods[method]) {
     55       return methods[method].apply(this, [].slice.call(arguments, 1));
     56     } else if (method === 'letters' || !method) {
     57       return methods.init.apply(this, [].slice.call(arguments, 0)); // always pass an array
     58     }
     59 
     60     $.error('Method ' + method + ' does not exist on jQuery.lettering');
     61     return this;
     62   };
     63 })(jQuery);