1/** 2 * Handle: main 3 * Version: 1.0.0 4 * Deps: jQuery 5 * Enqueue: true 6 * Author : anshul labs 7 */ 8 9jQuery(document).ready(function($){ 10 //set animation timing 11 var animationDelay = 2500, 12 //loading bar effect 13 barAnimationDelay = 3800, 14 barWaiting = barAnimationDelay - 3000, //3000 is the duration of the transition on the loading bar - set in the scss/css file 15 //letters effect 16 lettersDelay = 50, 17 //type effect 18 typeLettersDelay = 150, 19 selectionDuration = 500, 20 typeAnimationDelay = selectionDuration + 800, 21 //clip effect 22 revealDuration = 600, 23 revealAnimationDelay = 1500; 24 25 initHeadline(); 26 27 28 function initHeadline() { 29 //insert <i> element for each letter of a changing word 30 singleLetters($('.cd-headline.letters').find('b')); 31 //initialise headline animation 32 animateHeadline($('.cd-headline')); 33 } 34 35 function singleLetters($words) { 36 $words.each(function(){ 37 var word = $(this), 38 letters = word.text().split(''), 39 selected = word.hasClass('is-visible'); 40 for (i in letters) { 41 if(word.parents('.rotate-2').length > 0) letters[i] = '<em>' + letters[i] + '</em>'; 42 letters[i] = (selected) ? '<i class="in">' + letters[i] + '</i>': '<i>' + letters[i] + '</i>'; 43 } 44 var newLetters = letters.join(''); 45 word.html(newLetters).css('opacity', 1); 46 }); 47 } 48 49 function animateHeadline($headlines) { 50 var duration = animationDelay; 51 $headlines.each(function(){ 52 var headline = $(this); 53 54 if(headline.hasClass('loading-bar')) { 55 duration = barAnimationDelay; 56 setTimeout(function(){ headline.find('.cd-words-wrapper').addClass('is-loading') }, barWaiting); 57 } else if (headline.hasClass('clip')){ 58 var spanWrapper = headline.find('.cd-words-wrapper'), 59 newWidth = spanWrapper.width() + 10 60 spanWrapper.css('width', newWidth); 61 } else if (!headline.hasClass('type') ) { 62 //assign to .cd-words-wrapper the width of its longest word 63 var words = headline.find('.cd-words-wrapper b'), 64 width = 0; 65 words.each(function(){ 66 var wordWidth = $(this).width(); 67 if (wordWidth > width) width = wordWidth; 68 }); 69 headline.find('.cd-words-wrapper').css('width', width); 70 }; 71 72 //trigger animation 73 setTimeout(function(){ hideWord( headline.find('.is-visible').eq(0) ) }, duration); 74 }); 75 } 76 77 function hideWord($word) { 78 var nextWord = takeNext($word); 79 80 if($word.parents('.cd-headline').hasClass('type')) { 81 var parentSpan = $word.parent('.cd-words-wrapper'); 82 parentSpan.addClass('selected').removeClass('waiting'); 83 setTimeout(function(){ 84 parentSpan.removeClass('selected'); 85 $word.removeClass('is-visible').addClass('is-hidden').children('i').removeClass('in').addClass('out'); 86 }, selectionDuration); 87 setTimeout(function(){ showWord(nextWord, typeLettersDelay) }, typeAnimationDelay); 88 89 } else if($word.parents('.cd-headline').hasClass('letters')) { 90 var bool = ($word.children('i').length >= nextWord.children('i').length) ? true : false; 91 hideLetter($word.find('i').eq(0), $word, bool, lettersDelay); 92 showLetter(nextWord.find('i').eq(0), nextWord, bool, lettersDelay); 93 94 } else if($word.parents('.cd-headline').hasClass('clip')) { 95 $word.parents('.cd-words-wrapper').animate({ width : '2px' }, revealDuration, function(){ 96 switchWord($word, nextWord); 97 showWord(nextWord); 98 }); 99 100 } else if ($word.parents('.cd-headline').hasClass('loading-bar')){ 101 $word.parents('.cd-words-wrapper').removeClass('is-loading'); 102 switchWord($word, nextWord); 103 setTimeout(function(){ hideWord(nextWord) }, barAnimationDelay); 104 setTimeout(function(){ $word.parents('.cd-words-wrapper').addClass('is-loading') }, barWaiting); 105 106 } else { 107 switchWord($word, nextWord); 108 setTimeout(function(){ hideWord(nextWord) }, animationDelay); 109 } 110 } 111 112 function showWord($word, $duration) { 113 if($word.parents('.cd-headline').hasClass('type')) { 114 showLetter($word.find('i').eq(0), $word, false, $duration); 115 $word.addClass('is-visible').removeClass('is-hidden'); 116 117 } else if($word.parents('.cd-headline').hasClass('clip')) { 118 $word.parents('.cd-words-wrapper').animate({ 'width' : $word.width() + 10 }, revealDuration, function(){ 119 setTimeout(function(){ hideWord($word) }, revealAnimationDelay); 120 }); 121 } 122 } 123 124 function hideLetter($letter, $word, $bool, $duration) { 125 $letter.removeClass('in').addClass('out'); 126 127 if(!$letter.is(':last-child')) { 128 setTimeout(function(){ hideLetter($letter.next(), $word, $bool, $duration); }, $duration); 129 } else if($bool) { 130 setTimeout(function(){ hideWord(takeNext($word)) }, animationDelay); 131 } 132 133 if($letter.is(':last-child') && $('html').hasClass('no-csstransitions')) { 134 var nextWord = takeNext($word); 135 switchWord($word, nextWord); 136 } 137 } 138 139 function showLetter($letter, $word, $bool, $duration) { 140 $letter.addClass('in').removeClass('out'); 141 142 if(!$letter.is(':last-child')) { 143 setTimeout(function(){ showLetter($letter.next(), $word, $bool, $duration); }, $duration); 144 } else { 145 if($word.parents('.cd-headline').hasClass('type')) { setTimeout(function(){ $word.parents('.cd-words-wrapper').addClass('waiting'); }, 200);} 146 if(!$bool) { setTimeout(function(){ hideWord($word) }, animationDelay) } 147 } 148 } 149 150 function takeNext($word) { 151 return (!$word.is(':last-child')) ? $word.next() : $word.parent().children().eq(0); 152 } 153 154 function takePrev($word) { 155 return (!$word.is(':first-child')) ? $word.prev() : $word.parent().children().last(
155); 156 } 157 158 function switchWord($oldWord, $newWord) { 159 $oldWord.removeClass('is-visible').addClass('is-hidden'); 160 $newWord.removeClass('is-hidden').addClass('is-visible'); 161 } 162});
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.