PageSourceSearch

https://sproutloud.com/wp-content/plugins/typed//js/typed.js?ver=6.6.2

js sproutloud.com collected 2026-10-02 10:10:54 UTC 15,615 bytes, 434 lines download raw bytes

1// The MIT License (MIT)
2
3// Typed.js | Copyright (c) 2014 Matt Boldt | www.mattboldt.com
4
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21// THE SOFTWARE.
22
23
24
25
26! function($) {
27
28    "use strict";
29
30    var Typed = function(el, options) {
31
32        // chosen element to manipulate text
33        this.el = $(el);
34
35        // options
36        this.options = $.extend({}, $.fn.typed.defaults, options);
37
38        // attribute to type into
39        this.isInput = this.el.is('input');
40        this.attr = this.options.attr;
41
42        // show cursor
43        this.showCursor = this.isInput ? false : this.options.showCursor;
44
45        // text content of element
46        this.elContent = this.attr ? this.el.attr(this.attr) : this.el.text()
47
48        // html or plain text
49        this.contentType = this.options.contentType;
50
51        // typing speed
52        this.typeSpeed = this.options.typeSpeed;
53
54        // add a delay before typing starts
55        this.startDelay = this.options.startDelay;
56
57        // backspacing speed
58        this.backSpeed = this.options.backSpeed;
59
60        // amount of time to wait before backspacing
61        this.backDelay = this.options.backDelay;
62
63        // div containing strings
64        this.stringsElement = this.options.stringsElement;
65
66        // input strings of text
67        this.strings = this.options.strings;
68
69        // character number position of current string
70        this.strPos = 0;
71
72        // current array position
73        this.arrayPos = 0;
74
75        // number to stop backspacing on.
76        // default 0, can change depending on how many chars
77        // you want to remove at the time
78        this.stopNum = 0;
79
80        // Looping logic
81        this.loop = this.options.loop;
82        this.loopCount = this.options.loopCount;
83        this.curLoop = 0;
84
85        // for stopping
86        this.stop = false;
87
88        // custom cursor
89        this.cursorChar = this.options.cursorChar;
90
91        // shuffle the strings
92        this.shuffle = this.options.shuffle;
93        // the order of strings
94        this.sequence = [];
95
96        // All systems go!
97        this.build();
98    };
99
100    Typed.prototype = {
101
102        constructor: Typed
103
104        ,
105        init: function() {
106            // begin the loop w/ first current string (global self.strings)
107            // current string will be passed as an argument each time after this
108            var self = this;
109            self.timeout = setTimeout(function() {
110                for (var i=0;i<self.strings.length;++i) self.sequence[i]=i;
111
112                // shuffle the array if true
113                if(self.shuffle) self.sequence = self.shuffleArray(self.sequence);
114
115                // Start typing
116                self.typewrite(self.strings[self.sequence[self.arrayPos]], self.strPos);
117            }, self.startDelay);
118        }
119
120        ,
121        build: function() {
122            var self = this;
123            // Insert cursor
124            if (this.showCursor === true) {
125                this.cursor = $("<span class=\"typed-cursor\">" + this.cursorChar + "</span>");
126                this.el.after(this.cursor);
127            }
128            if (this.stringsElement) {
129                self.strings = [];
130                this.stringsElement.hide();
131                var strings = this.stringsElement.find('p');
132                $.each(strings, function(key, value){
133                    self.strings.push($(value).html());
134                });
135            }
136            this.init();
137        }
138
139        // pass current string state to each function, types 1 char per call
140        ,
141        typewrite: function(curString, curStrPos) {
142            // exit when stopped
143            if (this.stop === true) {
144                return;
145            }
146
147            // varying values for setTimeout during typing
148            // can't be global since number changes each time loop is executed
149            var humanize = Math.round(Math.random() * (100 - 30)) + this.typeSpeed;
150            var self = this;
151
152            // ------------- optional ------------- //
153            // backpaces a certain string faster
154            // ------------------------------------ //
155            // if (self.arrayPos == 1){
156            //  self.backDelay = 50;
157            // }
158            // else{ self.backDelay = 500; }
159
160            // contain typing function in a timeout humanize'd delay
161            self.timeout = setTimeout(function() {
162                // check for an escape character before a pause value
163                // format: \^\d+ .. eg: ^1000 .. should be able to print the ^ too using ^^
164                // single ^ are removed from string
165                var charPause = 0;
166                var substr = curString.substr(curStrPos);
167                if (substr.charAt(0) === '^') {
168                    var skip = 1; // skip atleast 1
169                    if (/^\^\d+/.test(substr)) {
170                        substr = /\d+/.exec(substr)[0];
171                        skip += substr.length;
172                        charPause = parseInt(substr);
173                    }
174
175                    // strip out the escape character and pause value so they're not printed
176                    curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + skip);
177                }
178
179                if (self.contentType === 'html') {
180                    // skip over html tags while typing
181                    var curChar = curString.substr(curStrPos).charAt(0)
182                    if (curChar === '<' || curChar === '&') {
183                        var tag = '';
184                        var endTag = '';
185                        if (curChar === '<') {
186                            endTag = '>'
187                        } else {
188                            endTag = ';'
189                        }
190                        while (curString.substr(curStrPos).charAt(0) !== endTag) {
191                            tag += curString.substr(curStrPos).charAt(0);
192                            curStrPos++;
193                        }
194                        curStrPos++;
195                        tag += endTag;
196                    }
197                }
198
199                // timeout for any pause after a character
200                self.timeout = setTimeout(function() {
201                    if (curStrPos === curString.length) {
202                        // fires callback function
203                        self.options.onStringTyped(self.arrayPos);
204
205                        // is this the final string
206                        if (self.arrayPos === self.strings.length - 1) {
207                            // animation that occurs on the last typed string
208                            self.options.callback();
209
210                            self.curLoop++;
211
212                            // quit if we wont loop back
213                            if (self.loop === false || self.curLoop === self.loopCount)
214                                return;
215                        }
216
217                        self.timeout = setTimeout(function() {
218                            self.backspace(curString, curStrPos);
219                        }, self.backDelay);
220                    } else {
221
222                        /* call before functions if applicable */
223                        if (curStrPos === 0)
224                            self.options.preStringTyped(self.arrayPos);
225
226                        // start typing each new char into existing string
227                        // curString: arg, self.el.html: original text inside element
228                        var nextString = curString.substr(0, curStrPos + 1);
229                        if (self.attr) {
230                            self.el.attr(self.attr, nextString);
231                        } else {
232                            if (self.isInput) {
233                                self.el.val(nextString);
234                            } else if (self.contentType === 'html') {
235                                self.el.html(nextString);
236                            } else {
237                                self.el.text(nextString);
238                            }
239                        }
240
241                        // add characters one by one
242                        curStrPos++;
243                        // loop the function
244                        self.typewrite(curString, curStrPos);
245                    }
246                    // end of character pause
247                }, charPause);
248
249                // humanized value for typing
250            }, humanize);
251
252        }
253
254        ,
255        backspace: function(curString, curStrPos) {
256            // exit when stopped
257            if (this.stop === true) {
258                return;
259            }
260
261            // varying values for setTimeout during typing
262            // can't be global since number changes each time loop is executed
263            var humanize = Math.round(Math.random() * (100 - 30)) + this.backSpeed;
264            var self = this;
265
266            self.timeout = setTimeout(function() {
267
268                // ----- this part is optional ----- //
269                // check string array position
270                // on the first string, only delete one word
271                // the stopNum actually represents the amount of chars to
272                // keep in the current string. In my case it's 14.
273                // if (self.arrayPos == 1){
274                //  self.stopNum = 14;
275                // }
276                //every other time, delete the whole typed string
277                // else{
278                //  self.stopNum = 0;
279                // }
280
281                if (self.contentType === 'html') {
282                    // skip over html tags while backspacing
283                    if (curString.substr(curStrPos).charAt(0) === '>') {
284                        var tag = '';
285                        while (curString.substr(curStrPos).charAt(0) !== '<') {
286                            tag -= curString.substr(curStrPos).charAt(0);
287                            curStrPos--;
288                        }
289                        curStrPos--;
290                        tag += '<';
291                    }
292                }
293
294                // ----- continue important stuff ----- //
295                // replace text with base text + typed characters
296                var nextString = curString.substr(0, curStrPos);
297                if (self.attr) {
298                    self.el.attr(self.attr, nextString);
299                } else {
300                    if (self.isInput) {
301                        self.el.val(nextString);
302                    } else if (self.contentType === 'html') {
303                        self.el.html(nextString);
304                    } else {
305                        self.el.text(nextString);
306                    }
307                }
308
309                // if the number (id of character in current string) is
310                // less than the stop number, keep going
311                if (curStrPos > self.stopNum) {
312                    // subtract characters one by one
313                    curStrPos--;
314                    // loop the function
315                    self.backspace(curString, curStrPos);
316                }
317                // if the stop number has been reached, increase
318                // array position to next string
319                else if (curStrPos <= self.stopNum) {
320                    self.arrayPos++;
321
322                    if (self.arrayPos === self.strings.length) {
323                        self.arrayPos = 0;
324
325                        // Shuffle sequence again
326                        if(self.shuffle) self.sequence = self.shuffleArray(self.sequence);
327
328                        self.init();
329                    } else
330                        self.typewrite(self.strings[self.sequence[self.arrayPos
330]], curStrPos);
331                }
332
333                // humanized value for typing
334            }, humanize);
335
336        }
337        /**
338         * Shuffles the numbers in the given array.
339         * @param {Array} array
340         * @returns {Array}
341         */
342        ,shuffleArray: function(array) {
343            var tmp, current, top = array.length;
344            if(top) while(--top) {
345                current = Math.floor(Math.random() * (top + 1));
346                tmp = array[current];
347                array[current] = array[top];
348                array[top] = tmp;
349            }
350            return array;
351        }
352
353        // Start & Stop currently not working
354
355        // , stop: function() {
356        //     var self = this;
357
358        //     self.stop = true;
359        //     clearInterval(self.timeout);
360        // }
361
362        // , start: function() {
363        //     var self = this;
364        //     if(self.stop === false)
365        //        return;
366
367        //     this.stop = false;
368        //     this.init();
369        // }
370
371        // Reset and rebuild the element
372        ,
373        reset: function() {
374            var self = this;
375            clearInterval(self.timeout);
376            var id = this.el.attr('id');
377            this.el.after('<span id="' + id + '"/>')
378            this.el.remove();
379            if (typeof this.cursor !== 'undefined') {
380                this.cursor.remove();
381            }
382            // Send the callback
383            self.options.resetCallback();
384        }
385
386    };
387
388    $.fn.typed = function(option) {
389        return this.each(function() {
390            var $this = $(this),
391                data = $this.data('typed'),
392                options = typeof option == 'object' && option;
393            if (!data) $this.data('typed', (data = new Typed(this, options)));
394            if (typeof option == 'string') data[option]();
395        });
396    };
397
398    $.fn.typed.defaults = {
399        strings: ["These are the default values...", "You know what you should do?", "Use your own!", "Have a great day!"],
400        stringsElement: null,
401        // typing speed
402        typeSpeed: 0,
403        // time before typing starts
404        startDelay: 0,
405        // backspacing speed
406        backSpeed: 0,
407        // shuffle the strings
408        shuffle: false,
409        // time before backspacing
410        backDelay: 500,
411        // loop
412        loop: false,
413        // false = infinite
414        loopCount: false,
415        // show cursor
416        showCursor: true,
417        // character for cursor
418        cursorChar: "|",
419        // attribute to type (null == text)
420        attr: null,
421        // either html or text
422        contentType: 'html',
423        // call when done callback function
424        callback: function() {},
425        // starting callback function before each string
426        preStringTyped: function() {},
427        //callback for every typed string
428        onStringTyped: function() {},
429        // callback for reset
430        resetCallback: function() {}
431    };
432
433
434}(window.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.