PageSourceSearch

https://attach.io/wp-content/plugins/font_typed//js/typed.js

js attach.io collected 2026-10-03 20:18:24 UTC 13,665 bytes, 381 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   // typing speed
54        this.randomize = this.options.randomize;
55
56        // add a delay before typing starts
57        this.startDelay = this.options.startDelay;
58
59        // backspacing speed
60        this.backSpeed = this.options.backSpeed;
61
62        // amount of time to wait before backspacing
63        this.backDelay = this.options.backDelay;
64
65        // input strings of text
66        this.strings = this.options.strings;
67
68        // character number position of current string
69        this.strPos = 0;
70
71        // current array position
72        this.arrayPos = 0;
73
74        // number to stop backspacing on.
75        // default 0, can change depending on how many chars
76        // you want to remove at the time
77        this.stopNum = 0;
78
79        // Looping logic
80        this.loop = this.options.loop;
81        this.loopCount = this.options.loopCount;
82        this.curLoop = 0;
83
84        // for stopping
85        this.stop = false;
86
87        // custom cursor
88        this.cursorChar = this.options.cursorChar;
89
90        // All systems go!
91        this.build();
92    };
93
94    Typed.prototype = {
95
96        constructor: Typed
97
98        ,
99        init: function() {
100            // begin the loop w/ first current string (global self.string)
101            // current string will be passed as an argument each time after this
102            var self = this;
103            self.timeout = setTimeout(function() {
104                // Start typing
105                self.typewrite(self.strings[self.arrayPos], self.strPos);
106            }, self.startDelay);
107        }
108
109        ,
110        build: function() {
111            // Insert cursor
112            if (this.showCursor === true) {
113                this.cursor = $("<span class=\"typed-cursor\">" + this.cursorChar + "</span>");
114                this.el.after(this.cursor);
115            }
116            this.init();
117        }
118
119        // pass current string state to each function, types 1 char per call
120        ,
121        typewrite: function(curString, curStrPos) {
122            // exit when stopped
123            if (this.stop === true) {
124                return;
125            }
126
127            // varying values for setTimeout during typing
128            // can't be global since number changes each time loop is executed
129            var humanize = Math.round(Math.random() * (this.randomize )) + this.typeSpeed;
130            var self = this;
131
132            // ------------- optional ------------- //
133            // backpaces a certain string faster
134            // ------------------------------------ //
135            // if (self.arrayPos == 1){
136            //  self.backDelay = 50;
137            // }
138            // else{ self.backDelay = 500; }
139
140            // contain typing function in a timeout humanize'd delay
141            self.timeout = setTimeout(function() {
142                // check for an escape character before a pause value
143                // format: \^\d+ .. eg: ^1000 .. should be able to print the ^ too using ^^
144                // single ^ are removed from string
145                var charPause = 0;
146                var substr = curString.substr(curStrPos);
147                if (substr.charAt(0) === '^') {
148                    var skip = 1; // skip atleast 1
149                    if (/^\^\d+/.test(substr)) {
150                        substr = /\d+/.exec(substr)[0];
151                        skip += substr.length;
152                        charPause = parseInt(substr);
153                    }
154
155                    // strip out the escape character and pause value so they're not printed
156                    curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + ski
156p);
157                }
158
159                if (self.contentType === 'html') {
160                    // skip over html tags while typing
161                    if (curString.substr(curStrPos).charAt(0) === '<') {
162                        var tag = '';
163                        while (curString.substr(curStrPos).charAt(0) !== '>') {
164                            tag += curString.substr(curStrPos).charAt(0);
165                            curStrPos++;
166                        }
167                        curStrPos++;
168                        tag += '>';
169                    }
170                }
171
172                // timeout for any pause after a character
173                self.timeout = setTimeout(function() {
174                    if (curStrPos === curString.length) {
175                        // fires callback function
176                        self.options.onStringTyped(self.arrayPos);
177
178                        // is this the final string
179                        if (self.arrayPos === self.strings.length - 1) {
180                            // animation that occurs on the last typed string
181                            self.options.callback();
182
183                            self.curLoop++;
184
185                            // quit if we wont loop back
186                            if (self.loop === false || self.curLoop === self.loopCount)
187                                return;
188                        }
189
190                        self.timeout = setTimeout(function() {
191                            self.backspace(curString, curStrPos);
192                        }, self.backDelay);
193                    } else {
194
195                        /* call before functions if applicable */
196                        if (curStrPos === 0)
197                            self.options.preStringTyped(self.arrayPos);
198
199                        // start typing each new char into existing string
200                        // curString: arg, self.el.html: original text inside element
201                        var nextString = self.elContent + curString.substr(0, curStrPos + 1);
202                        if (self.attr) {
203                            self.el.attr(self.attr, nextString);
204                        } else {
205                            if (self.contentType === 'html') {
206                                self.el.html(nextString);
207                            } else {
208                                self.el.text(nextString);
209                            }
210                        }
211
212                        // add characters one by one
213                        curStrPos++;
214                        // loop the function
215                        self.typewrite(curString, curStrPos);
216                    }
217                    // end of character pause
218                }, charPause);
219
220                // humanized value for typing
221            }, humanize);
222
223        }
224
225        ,
226        backspace: function(curString, curStrPos) {
227            // exit when stopped
228            if (this.stop === true) {
229                return;
230            }
231
232            // varying values for setTimeout during typing
233            // can't be global since number changes each time loop is executed
234            var humanize = Math.round(Math.random() * (100 - 30)) + this.backSpeed;
235            var self = this;
236
237            self.timeout = setTimeout(function() {
238
239                // ----- this part is optional ----- //
240                // check string array position
241                // on the first string, only delete one word
242                // the stopNum actually represents the amount of chars to
243                // keep in the current string. In my case it's 14.
244                // if (self.arrayPos == 1){
245                //  self.stopNum = 14;
246                // }
247                //every other time, delete the whole typed string
248                // else{
249                //  self.stopNum = 0;
250                // }
251
252                if (self.contentType === 'html') {
253                    // skip over html tags while backspacing
254                    if (curString.substr(curStrPos).charAt(0) === '>') {
255                        var tag = '';
256                        while (curString.substr(curStrPos).charAt(0) !== '<') {
257                            tag -= curString.substr(curStrPos).charAt(0);
258                            curStrPos--;
259                        }
260                        curStrPos--;
261                        tag += '<';
262                    }
263                }
264
265                // ----- continue important stuff ----- //
266                // replace text with base text + typed characters
267                var nextString = self.elContent + curString.substr(0, curStrPos);
268                if (self.attr) {
269                    self.el.attr(self.attr, nextString);
270                } else {
271                    if (self.contentType === 'html') {
272                        self.el.html(nextString);
273                    } else {
274                        self.el.text(nextString);
275                    }
276                }
277
278                // if the number (id of character in current string) is
279                // less than the stop number, keep going
280                if (curStrPos > self.stopNum) {
281                    // subtract characters one by one
282                    curStrPos--;
283                    // loop the function
284                    self.backspace(curString, curStrPos);
285                }
286                // if the stop number has been reached, increase
287                // array position to next string
288                else if (curStrPos <= self.stopNum) {
289                    self.arrayPos++;
290
291                    if (self.arrayPos === self.strings.length) {
292                        self.arrayPos = 0;
293                        self.init();
294                    } else
295                        self.typewrite(self.strings[self.arrayPos
295], curStrPos);
296                }
297
298                // humanized value for typing
299            }, humanize);
300
301        }
302
303        // Start & Stop currently not working
304
305        // , stop: function() {
306        //     var self = this;
307
308        //     self.stop = true;
309        //     clearInterval(self.timeout);
310        // }
311
312        // , start: function() {
313        //     var self = this;
314        //     if(self.stop === false)
315        //        return;
316
317        //     this.stop = false;
318        //     this.init();
319        // }
320
321        // Reset and rebuild the element
322        ,
323        reset: function() {
324            var self = this;
325            clearInterval(self.timeout);
326            var id = this.el.attr('id');
327            this.el.after('<span id="' + id + '"/>')
328            this.el.remove();
329            this.cursor.remove();
330            // Send the callback
331            self.options.resetCallback();
332        }
333
334    };
335
336    $.fn.typed = function(option) {
337        return this.each(function() {
338            var $this = $(this),
339                data = $this.data('typed'),
340                options = typeof option == 'object' && option;
341            if (!data) $this.data('typed', (data = new Typed(this, options)));
342            if (typeof option == 'string') data[option]();
343        });
344    };
345
346    $.fn.typed.defaults = {
347        strings: ["These are the default values...", "You know what you should do?", "Use your own!", "Have a great day!"],
348        // typing speed
349        typeSpeed: 0,
350        // time before typing starts
351        startDelay: 0,
352        // backspacing speed
353        backSpeed: 0,
354        // time before backspacing
355        randomize: 100,
356        // time before backspacing
357        backDelay: 500,
358        // loop
359        loop: false,
360        // false = infinite
361        loopCount: false,
362        // show cursor
363        showCursor: true,
364        // character for cursor
365        cursorChar: "|",
366        // attribute to type (null == text)
367        attr: null,
368        // either html or text
369        contentType: 'html',
370        // call when done callback function
371        callback: function() {},
372        // starting callback function before each string
373        preStringTyped: function() {},
374        //callback for every typed string
375        onStringTyped: function() {},
376        // callback for reset
377        resetCallback: function() {}
378    };
379
380
381}(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.