PageSourceSearch

https://outandabout.africa/wp-content/plugins/newzin_plugin/assets/js/animated.headline.js

js outandabout.africa collected 2026-10-08 13:15:43 UTC 7,161 bytes, 186 lines download raw bytes

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

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.