PageSourceSearch

https://kiyctc.com.kp/assets/js/typed.js

js kiyctc.com.kp collected 2026-10-02 22:05:29 UTC 12,130 bytes, 438 lines download raw bytes

1// The MIT License (MIT)
2
3// Typed.js | Copyright (c) 2016 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		init: function() {
105			// begin the loop w/ first current string (global self.strings)
106			// current string will be passed as an argument each time after this
107			var self = this;
108			self.timeout = setTimeout(function() {
109				for (var i=0;i<self.strings.length;++i) self.sequence[i]=i;
110
111				// shuffle the array if true
112				if(self.shuffle) self.sequence = self.shuffleArray(self.sequence);
113
114				// Start typing
115				self.typewrite(self.strings[self.sequence[self.arrayPos]], self.strPos);
116			}, self.startDelay);
117		},
118
119		build: function() {
120			var self = this;
121			// Insert cursor
122			if (this.showCursor === true) {
123				this.cursor = $("<span class=\"typed-cursor\">" + this.cursorChar + "</span>");
124				this.el.after(this.cursor);
125			}
126			if (this.stringsElement) {
127				this.strings = [];
128				this.stringsElement.hide();
129				console.log(this.stringsElement.children());
130				var strings = this.stringsElement.children();
131				$.each(strings, function(key, value){
132					self.strings.push($(value).html());
133				});
134			}
135			this.init();
136		},
137
138		// pass current string state to each function, types 1 char per call
139		typewrite: function(curString, curStrPos) {
140			// exit when stopped
141			if (this.stop === true) {
142				return;
143			}
144
145			// varying values for setTimeout during typing
146			// can't be global since number changes each time loop is executed
147			var humanize = Math.round(Math.random() * (100 - 30)) + this.typeSpeed;
148			var self = this;
149
150			// ------------- optional ------------- //
151			// backpaces a certain string faster
152			// ------------------------------------ //
153			// if (self.arrayPos == 1){
154			//  self.backDelay = 50;
155			// }
156			// else{ self.backDelay = 500; }
157
158			// contain typing function in a timeout humanize'd delay
159			self.timeout = setTimeout(function() {
160				// check for an escape character before a pause value
161				// format: \^\d+ .. eg: ^1000 .. should be able to print the ^ too using ^^
162				// single ^ are removed from string
163				var charPause = 0;
164				var substr = curString.substr(curStrPos);
165				if (substr.charAt(0) === '^') {
166					var skip = 1; // skip atleast 1
167					if (/^\^\d+/.test(substr)) {
168						substr = /\d+/.exec(substr)[0];
169						skip += substr.length;
170						charPause = parseInt(substr);
171					}
172
173					// strip out the escape character and pause value so they're not printed
174					curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + ski
174p);
175				}
176
177				if (self.contentType === 'html') {
178					// skip over html tags while typing
179					var curChar = curString.substr(curStrPos).charAt(0)
180					if (curChar === '<' || curChar === '&') {
181						var tag = '';
182						var endTag = '';
183						if (curChar === '<') {
184							endTag = '>'
185						}
186						else {
187							endTag = ';'
188						}
189						while (curString.substr(curStrPos + 1).charAt(0) !== endTag) {
190							tag += curString.substr(curStrPos).charAt(0);
191							curStrPos++;
192							if (curStrPos + 1 > curString.length) { break; }
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
221					} else {
222
223						/* call before functions if applicable */
224						if (curStrPos === 0) {
225							self.options.preStringTyped(self.arrayPos);
226						}
227
228						// start typing each new char into existing string
229						// curString: arg, self.el.html: original text inside element
230						var nextString = curString.substr(0, curStrPos + 1);
231						if (self.attr) {
232							self.el.attr(self.attr, nextString);
233						} else {
234							if (self.isInput) {
235								self.el.val(nextString);
236							} else if (self.contentType === 'html') {
237								self.el.html(nextString);
238							} else {
239								self.el.text(nextString);
240							}
241						}
242
243						// add characters one by one
244						curStrPos++;
245						// loop the function
246						self.typewrite(curString, curStrPos);
247					}
248					// end of character pause
249				}, charPause);
250
251				// humanized value for typing
252			}, humanize);
253
254		},
255
256		backspace: function(curString, curStrPos) {
257			// exit when stopped
258			if (this.stop === true) {
259				return;
260			}
261
262			// varying values for setTimeout during typing
263			// can't be global since number changes each time loop is executed
264			var humanize = Math.round(Math.random() * (100 - 30)) + this.backSpeed;
265			var self = this;
266
267			self.timeout = setTimeout(function() {
268
269				// ----- this part is optional ----- //
270				// check string array position
271				// on the first string, only delete one word
272				// the stopNum actually represents the amount of chars to
273				// keep in the current string. In my case it's 14.
274				// if (self.arrayPos == 1){
275				//  self.stopNum = 14;
276				// }
277				//every other time, delete the whole typed string
278				// else{
279				//  self.stopNum = 0;
280				// }
281
282				if (self.contentType === 'html') {
283					// skip over html tags while backspacing
284					if (curString.substr(curStrPos).charAt(0) === '>') {
285						var tag = '';
286						while (curString.substr(curStrPos - 1).charAt(0) !== '<') {
287							tag -= curString.substr(curStrPos).charAt(0);
288							curStrPos--;
289							if (curStrPos < 0) { break; }
290						}
291						curStrPos--;
292						tag += '<';
293					}
294				}
295
296				// ----- continue important stuff ----- //
297				// replace text with base text + typed characters
298				var nextString = curString.substr(0, curStrPos);
299				if (self.attr) {
300					self.el.attr(self.attr, nextString);
301				} else {
302					if (self.isInput) {
303						self.el.val(nextString);
304					} else if (self.contentType === 'html') {
305						self.el.html(nextString);
306					} else {
307						self.el.text(nextString);
308					}
309				}
310
311				// if the number (id of character in current string) is
312				// less than the stop number, keep going
313				if (curStrPos > self.stopNum) {
314					// subtract characters one by one
315					curStrPos--;
316					// loop the function
317					self.backspace(curString, curStrPos);
318				}
319				// if the stop number has been reached, increase
320				// array position to next string
321				else if (curStrPos <= self.stopNum) {
322					self.arrayPos++;
323
324					if (self.arrayPos === self.strings.length) {
325						self.arrayPos = 0;
326
327						// Shuffle sequence again
328						if(self.shuffle) self.sequence = self.shuffleArray(self.sequence);
329
330						self.init();
331					} else
332						self.typewrite(self.strings[self.sequence[self.arrayPos]], curStrPos);
333				}
334
335				// humanized value for typing
336			}, humanize);
337
338		},
339		/**
340		 * Shuffles the numbers in the given array.
341		 * @param {Array} array
342		 * @returns {Array}
343		 */
344		shuffleArray: function(array) {
345			var tmp, current, top = array.length;
346			if(top) while(--top) {
347				current = Math.floor(Math.random() * (top + 1));
348				tmp = array[current];
349				array[current] = array[top];
350				array[top] = tmp;
351			}
352			return array;
353		},
354
355		// Start & Stop currently not working
356
357		// , stop: function() {
358		//     var self = this;
359
360		//     self.stop = true;
361		//     clearInterval(self.timeout);
362		// }
363
364		// , start: function() {
365		//     var self = this;
366		//     if(self.stop === false)
367		//        return;
368
369		//     this.stop = false;
370		//     this.init();
371		// }
372
373		// Reset and rebuild the element
374		reset: function() {
375			var self = this;
376			clearInterval(self.timeout);
377			var id = this.el.attr('id');
378			this.el.empty();
379			if (typeof this.cursor !== 'undefined') {
380        this.cursor.remove();
381      }
382			this.strPos = 0;
383			this.arrayPos = 0;
384			this.curLoop = 0;
385			// Send the callback
386			this.options.resetCallback();
387		}
388
389	};
390
391	$.fn.typed = function(option) {
392		return this.each(function() {
393			var $this = $(this),
394				data = $this.data('typed'),
395				options = typeof option == 'object' && option;
396			if (data) { data.reset(); }
397			$this.data('typed', (data = new Typed(this, options)));
398			if (typeof option == 'string') data[option]();
399		});
400	};
401
402	$.fn.typed.defaults = {
403		strings: ["These are the default values...", "You know what you should do?", "Use your own!", "Have a great day!"],
404		stringsElement: null,
405		// typing speed
406		typeSpeed: 0,
407		// time before typing starts
408		startDelay: 0,
409		// backspacing speed
410		backSpeed: 0,
411		// shuffle the strings
412		shuffle: false,
413		// time before backspacing
414		backDelay: 500,
415		// loop
416		loop: false,
417		// false = infinite
418		loopCount: false,
419		// show cursor
420		showCursor: true,
421		// character for cursor
422		cursorChar: "|",
423		// attribute to type (null == text)
424		attr: null,
425		// either html or text
426		contentType: 'html',
427		// call when done callback function
428		callback: function() {},
429		// starting callback function before each string
430		preStringTyped: function() {},
431		//callback for every typed string
432		onStringTyped: function() {},
433		// callback for reset
434		resetCallback: function() {}
435	};
436
437
438}(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.