vendor: 8,189 bytes, lines 1-287
1/* 2 * textillate.js 3 * http://jschr.github.com/textillate 4 * MIT licensed 5 * 6 * Copyright (C) 2012-2013 Jordan Schroter 7 */ 8 9(function ($) { 10 "use strict"; 11 12 function isInEffect (effect) { 13 return /In/.test(effect) || $.inArray(effect, $.fn.textillate.defaults.inEffects) >= 0; 14 }; 15 16 function isOutEffect (effect) { 17 return /Out/.test(effect) || $.inArray(effect, $.fn.textillate.defaults.outEffects) >= 0; 18 }; 19 20 21 function stringToBoolean(str) { 22 if (str !== "true" && str !== "false") return str; 23 return (str === "true"); 24 }; 25 26 // custom get data api method 27 function getData (node) { 28 var attrs = node.attributes || [] 29 , data = {}; 30 31 if (!attrs.length) return data; 32 33 $.each(attrs, function (i, attr) { 34 var nodeName = attr.nodeName.replace(/delayscale/, 'delayScale'); 35 if (/^data-in-*/.test(nodeName)) { 36 data.in = data.in || {}; 37 data.in[nodeName.replace(/data-in-/, '')] = stringToBoolean(attr.nodeValue); 38 } else if (/^data-out-*/.test(nodeName)) { 39 data.out = data.out || {}; 40 data.out[nodeName.replace(/data-out-/, '')] =stringToBoolean(attr.nodeValue); 41 } else if (/^data-*/.test(nodeName)) { 42 data[nodeName.replace(/data-/, '')] = stringToBoolean(attr.nodeValue); 43 } 44 }) 45 46 return data; 47 } 48 49 function shuffle (o) { 50 for (var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); 51 return o; 52 } 53 54 function animate ($t, effect, cb) { 55 $t.addClass('animated ' + effect) 56 .css('visibility', 'visible') 57 .show(); 58 59 $t.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () { 60 $t.removeClass('animated ' + effect); 61 cb && cb(); 62 }); 63 } 64 65 function animateTokens ($tokens, options, cb) { 66 var that = this 67 , count = $tokens.length; 68 69 if (!count) { 70 cb && cb(); 71 return; 72 } 73 74 if (options.shuffle) $tokens = shuffle($tokens); 75 if (options.reverse) $tokens = $tokens.toArray().reverse(); 76 77 $.each($tokens, function (i, t) { 78 var $token = $(t); 79 80 function complete () { 81 if (isInEffect(options.effect)) { 82 $token.css('visibility', 'visible'); 83 } else if (isOutEffect(options.effect)) { 84 $token.css('visibility', 'hidden'); 85 } 86 count -= 1; 87 if (!count && cb) cb(); 88 } 89 90 var delay = options.sync ? options.delay : options.delay * i * options.delayScale; 91 92 $token.text() ? 93 setTimeout(function () { animate($token, options.effect, complete) }, delay) : 94 complete(); 95 }); 96 }; 97 98 var Textillate = function (element, options) { 99 var base = this 100 , $element = $(element); 101 102 base.init = function () { 103 base.$texts = $element.find(options.selector); 104 105 if (!base.$texts.length) { 106 base.$texts = $('<ul class="texts"><li>' + $element.html() + '</li></ul>'); 107 $element.html(base.$texts); 108 } 109 110 base.$texts.hide(); 111 112 base.$current = $('<span>') 113 .html(base.$texts.find(':first-child').html()) 114 .prependTo($element); 115 116 if (isInEffect(options.in.effect)) { 117 base.$current.css('visibility', 'hidden'); 118 } else if (isOutEffect(options.out.effect)) { 119 base.$current.css('visibility', 'visible'); 120 } 121 122 base.setOptions(options); 123 124 base.timeoutRun = null; 125 126 setTimeout(function () { 127 base.options.autoStart && base.start(); 128 }, base.options.initialDelay) 129 }; 130 131 base.setOptions = function (options) { 132 base.options = options; 133 }; 134 135 base.triggerEvent = function (name) { 136 var e = $.Event(name + '.tlt'); 137 $element.trigger(e, base); 138 return e; 139 }; 140 141 base.in = function (index, cb) { 142 index = index || 0; 143 144 var $elem = base.$texts.find(':nth-child(' + ((index||0) + 1) + ')') 145 , options = $.extend(true, {}, base.options, $elem.length ? getData($elem[0]) : {}) 146 , $tokens; 147 148 $elem.addClass('current'); 149 150 base.triggerEvent('inAnimationBegin'); 151 152 base.$current 153 .html($elem.html()) 154 .lettering('words'); 155 156 // split words to individual characters if token type is set to 'char' 157 if (base.options.type == "char") { 158 base.$current.find('[class^="word"]') 159 .css({ 160 'display': 'inline-block', 161 // fix for poor ios performance 162 '-webkit-transform': 'translate3d(0,0,0)', 163 '-moz-transform': 'translate3d(0,0,0)', 164 '-o-transform': 'translate3d(0,0,0)', 165 'transform': 'translate3d(0,0,0)' 166 }) 167 .each(function () { $(this).lettering() }); 168 } 169 170 $tokens = base.$current 171 .find('[class^="' + base.options.type + '"]') 172 .css('display', 'inline-block'); 173 174 if (isInEffect(options.in.effect)) { 175 $tokens.css('visibility', 'hidden'); 176 } else if (isOutEffect(options.in.effect)) { 177 $tokens.css('visibility', 'visible'); 178 } 179 180 base.currentIndex = index; 181 182 animateTokens($tokens, options.in, function () { 183 base.triggerEvent('inAnimationEnd'); 184 if (options.in.callback) options.in.callback(); 185 if (cb) cb(base); 186 }); 187 }; 188 189 base.out = function (cb) { 190 var $elem = base.$texts.find(':nth-child(' + ((base.currentIndex||0) + 1) + ')') 191 , $tokens = base.$current.find('[class^="' + base.options.type + '"]') 192 , options = $.extend(true, {}, base.options, $elem.length ? getData($elem[0]) : {}) 193 194 base.triggerEvent('outAnimationBegin'); 195 196 animateTokens($tokens, options.out, function () { 197 $elem.removeClass('current'); 198 base.triggerEvent('outAnimationEnd'); 199 if (options.out.callback) options.out.callback(); 200 if (cb) cb(base); 201 }); 202 }; 203 204 base.start = function (index) { 205 setTimeout(function () { 206 base.triggerEvent('start'); 207 208 (function run (index) { 209 base.in(index, function () { 210 var length = base.$texts.children().length; 211 212 index += 1; 213 214 if (!base.options.loop && index >= length) { 215 if (base.options.callback) base.options.callback(); 216 base.triggerEvent('end'); 217 } else { 218 index = index % length; 219 220 base.timeoutRun = setTimeout(function () { 221 base.out(function () { 222 run(index) 223 }); 224 }, base.options.minDisplayTime); 225 } 226 }); 227 }(index || 0)); 228 }, base.options.initialDelay); 229 }; 230 231 base.stop = function () { 232 if (base.timeoutRun) { 233 clearInterval(base.timeoutRun); 234 base.timeoutRun = null; 235 } 236 }; 237 238 base.init(); 239 } 240 241 $.fn.textillate = function (settings, args) { 242 return this.each(function () { 243 var $this = $(this) 244 , data = $this.data('textillate') 245 , options = $.extend(true, {}, $.fn.textillate.defaults, getData(this), typeof settings == 'object' && settings); 246 247 if (!data) { 248 $this.data('textillate', (data = new Textillate(this, options))); 249 } else if (typeof settings == 'string') { 250 data[settings].apply(data, [].concat(args)); 251 } else { 252 data.setOptions.call(data, options); 253 } 254 }) 255 }; 256 257 $.fn.textillate.defaults = { 258 selector: '.texts', 259 loop: false, 260 minDisplayTime: 2000, 261 initialDelay: 0, 262 in: { 263 effect: 'fadeInLeftBig', 264 delayScale: 1.5, 265 delay: 50, 266 sync: false, 267 reverse: false, 268 shuffle: false, 269 callback: function () {} 270 }, 271 out: { 272 effect: 'hinge', 273 delayScale: 1.5, 274 delay: 50, 275 sync: false, 276 reverse: false, 277 shuffle: false, 278 callback: function () {} 279 }, 280 autoStart: true, 281 inEffects: [], 282 outEffects: [ 'hinge' ], 283 callback: function () {}, 284 type: 'char' 285 }; 286 287}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.