1(function ($) { 2 3 "use strict"; 4 5 var LetterFx = function (element, options) { 6 7 this.options = $.extend({}, $.fn.letterfx.defaults, options); 8 9 this.num_completed_fx = 0; 10 11 this.is_done = false; 12 13 this.monitor_timer = null; 14 15 this.killswitch=null; 16 17 this.$element = $(element); 18 19 if(this.options.restore) 20 this.original_html = this.$element.html(); 21 22 this.init(); 23 24 } 25 26 LetterFx.prototype.init = function(){ 27 28 this.new_html = this.$element.text().replace( this.options.pattern, this.options.replacement ); 29 30 this.$element.addClass(this.options.css.element.base).addClass( this.options.css.element.before ); 31 32 this.$element.html( this.new_html ); 33 34 this.$letters = this.$element.find(this.options.selector); 35 36 this.$letters 37 .css('transition-duration', this.options.fx_duration) 38 .addClass(this.options.css.letters.base) 39 .addClass(this.options.css.letters.before); 40 41 this.bindLetterFxEnd(); 42 43 this.num_letters = this.$letters.length; 44 45 46 this.fx(); 47 48 return this; 49 } 50 51 LetterFx.prototype.bindLetterFxEnd = function(){ 52 var options = this.options; 53 var lfx = this; 54 this.$letters.bind("transitionend", function(){ 55 options.onLetterComplete( $(this), lfx.$element, lfx ); 56 lfx.notifyFXEnd( ); 57 58 switch(options.letter_end){ 59 case "destroy": 60 $(this).remove(); 61 break; 62 63 case "rewind": 64 lfx.applyLetterFx( $(this), options.timing, options.css.letters.after, options.css.letters.before ); 65 break; 66 67 case "stay": 68 break; 69 70 // restore 71 default: 72 $(this).replaceWith( $(this).text() ); 73 } 74 75 }); 76 return lfx; 77 } 78 79 LetterFx.prototype.terminate=function(){ 80 this.is_done = true; 81 this.options.onElementComplete(this.$element, this); 82 83 clearTimeout(this.killswitch); 84 85 switch(this.options.element_end){ 86 case "destroy": 87 this.$element.remove(); 88 break; 89 90 case "stay": 91 break; 92 93 // restore 94 default: 95 this.$element.html( this.original_html ); 96 this.$element.removeClass( this.options.css.element.base ).removeClass(this.options.css.element.after); 97 break; 98 } 99 100 } 101 102 LetterFx.prototype.notifyFXEnd=function(){ 103 clearTimeout(this.monitor_timer); 104 this.num_completed_fx++; 105 106 var lfx = this; 107 this.monitor_timer = setTimeout( 108 function(){ 109 if(lfx.num_completed_fx % lfx.num_letters===0){ 110 lfx.terminate(); 111 } 112 }, 113 Math.max(this.options.timing+10, 50) 114 ); 115 116 return this; 117 } 118 119 LetterFx.prototype.startKillWatch = function(){ 120 var fx_duration = this.options.fx_duration.match(/\d+s/) ? parseInt(this.options.fx_duration) : 1; 121 var time = Math.ceil(1.5 * this.num_letters * this.options.timing * fx_duration ); 122 var lfx = this; 123 this.killswitch = window.setTimeout(function(){ 124 if(!lfx.isDone()){ 125 lfx.terminate() 126 } 127 }, time) 128 } 129 130 LetterFx.prototype.fx = function(){ 131 var lfx = this; 132 this.startKillWatch(); 133 this.$element.removeClass(this.options.css.element.before).addClass(this.options.css.element.after); 134 var $letters = this.options.sort(this.$letters); 135 var options = this.options; 136 137 138 139 $letters.each( 140 function(i, letter){ 141 lfx.applyLetterFx( $(letter), (i+1)*options.timing, options.css.letters.before, options.css.letters.after); 142 } 143 ); 144 return this; 145 } 146 147 LetterFx.prototype.applyLetterFx = function($letter, timing, css_before, css_after){ 148 var options = this.options; 149 150 window.setTimeout( 151 function(){ 152 $letter.removeClass(css_before).addClass(css_after); 153 }, 154 timing 155 ); 156 return this 157 } 158 159 LetterFx.prototype.isDone = function(){ 160 return this.is_done; 161 } 162 163 164 165 166 var LetterFxConfig = function(conf){ 167 this.config = $.extend({}, $.fn.letterfx.defaults, conf); 168 this.buildCss(this.config.backwards); 169 170 // check & change to word pattern 171 if(this.config.words) 172 this.config.pattern=/(\S+)/g; 173 174 175 } 176 177 178 LetterFxConfig.prototype.buildCss = function(flip){ 179 var options = this.config; 180 var before = flip ? 'after' : 'before'; 181 var after = flip ? 'before' : 'after'; 182 183 184 var css = { element:{}, letters:{} }; 185 186 css.element.base=options.element_class+ "-container " + options.fx.replace(/(\S+)/g, options.element_class + "-$1-container"); 187 css.element[before]=options.fx.replace(/(\S+)/g, options.element_class + "-$1-before-container"); 188 css.element[after]=options.fx.replace(/(\S+)/g, options.element_class + "-$1-after-container"); 189 190 css.letters.base = options.element_class; 191 css.letters[before] = options.fx.replace(/(\S+)/g, options.element_class + "-$1-before") 192 css.letters[after] = options.fx.replace(/(\S+)/g, options.element_class + "-$1-after") 193 194 this.config = $.extend( options, {'css':css} ); 195 } 196 197 LetterFxConfig.prototype.getConfig = function(){ 198 return this.config; 199 } 200 201 LetterFxConfig.parse=function(config){ 202 return (new LetterFxConfig( config )).getConfig(); 203 } 204 205 206 207 208$.fn.letterfx=function(config){ 209 210 config = LetterFxConfig.parse( config ); 211 212 return $(this).each(function(){ 213 var $element = $(this); 214 if (! $element.data('letterfx-obj') || $element.data('letterfx-obj').isDone() ){ 215 $element.data('letterfx-obj', new LetterFx( $element, config ) ); 216 } 217 }); 218 219}; 220 221$.fn.letterfx.sort={ 222 random:function(array){ 223 var currentIndex = array.length, temporaryValue, randomIndex; 224 225 // While there remain elements to shuffle... 226 while (0 !== currentIndex) { 227 228 // Pick a remaining element... 229 randomIndex = Math.floor(Math.random() * currentIndex); 230 currentIndex -= 1; 231 232 // And swap it with the current element. 233 temporaryValue = array[currentIndex]; 234 array[currentIndex] = array[randomIndex]; 235 array[randomIndex] = temporaryValue; 236 } 237 238 return array; 239 }, 240 reverse:function($array){ 241 return $array.toArray().reverse(); 242 } 243} 244 245$.fn.letterfx.patterns={ 246 letters:/(\S)/gi 247} 248 249// Plugin Configurables 250$.fn.letterfx.defaults = { 251 252 // Default fx 253 fx:'spin fly-top', 254 255 // defaults to selecting all characters 256 pattern:/(\S)/gi, 257 258 // switch from letter FX to word FX. 259 word:false, 260 261 // fx, like fly or fade, can happen in (eg fade-in) or out (eg fade-out). 262 // The default is in; change backwards to true to reverse the order of the effects. 263 backwards:false, 264 265 // defaults to injecting spans, can be any inline element 266 replacement:"<span>$1</span>", 267 268 //selector -- should match replacement above 269 selector:'span', 270 271 // letter fx start sequentially: letters start their fx one after another. 272 // this sets time between the letters 273 timing:50, 274 275 //duration of each fx 276 // options the same as css property for transition-duration ("1ms", "1s", etc) 277 fx_duration:"1s", 278 279 280 // stabile dimensions 281 // stabilize:true, 282 283 // sort callback for custom sorting elements 284 sort:function($letters){ return $letters; }, 285 286 287 // Callback when letter is done animating. Runs after each letter 288 onLetterComplete:function($letter, $element, LetterFXObj){}, 289 290 // Runs after all are done. 291 onElementComplete:function($element, LetterFXObj){}, 292 293 294 // what to do when a letter completes its animation. 295 // options include 296 // restore: return letter to plain text (default) 297 // destroy: get rid of the letter. 298 // stay: leave it as is. 299 // rewind: reverse the animation 300 letter_end:"restore", 301 302 303 // what to do when the entire element has completed all its letter effects 304 // options include: 305 // restore: return element to its pre-fx state (default) 306 // stay: do nothing 307 // destroy: get rid of the element... FOREVER 308 element_end:"restore", 309 310 // Restore container element back to original state. 311 // options: true, false, "element" ("element" waits until all letters complete fx before restoring) 312 restore:true, 313 314 // destroy element/letters after fx, useful on {out:true} fx 315 // options: true, false, "letters" ("letters" destroys each letter after fx, but elements original content may be restored after all letters complete fx) 316 destroy:false, 317 318 // default class for injected elements 319 element_class:'letterfx', 320 321 // placeholder values that are calculated on launch 322 css:{ 323 element:{ base:'', before:'', after:''}, 324 letters:{ base:'', before:'', after:''} 325 } 326 327 328 329}; 330 331}(jQuery)); 332
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.