123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535 |
- !function($){
- "use strict";
- var Typed = function(el, options){
- this.el = $(el);
- this.options = $.extend({}, $.fn.typed.defaults, options);
- this.baseText = this.el.text() || this.el.attr('placeholder') || '';
- this.typeSpeed = this.options.typeSpeed;
- this.startDelay = this.options.startDelay;
- this.backSpeed = this.options.backSpeed;
- this.backDelay = this.options.backDelay;
- this.strings = this.options.strings;
- this.strPos = 0;
- this.arrayPos = 0;
- this.stopNum = 0;
- this.loop = this.options.loop;
- this.loopCount = this.options.loopCount;
- this.curLoop = 0;
- this.stop = false;
- this.showCursor = this.isInput ? false : this.options.showCursor;
- this.cursorChar = this.options.cursorChar;
- this.isInput = this.el.is('input');
- this.attr = this.options.attr || (this.isInput ? 'placeholder' : null);
- this.build();
- };
- Typed.prototype = {
- constructor: Typed
- , init: function(){
-
-
- var self = this;
- self.timeout = setTimeout(function() {
-
- self.typewrite(self.strings[self.arrayPos], self.strPos);
- }, self.startDelay);
- }
- , build: function(){
-
- if (this.showCursor === true){
- this.cursor = $("<span class=\"typed-cursor\">" + this.cursorChar + "</span>");
- this.el.after(this.cursor);
- }
- this.init();
- }
- , typewrite: function(curString, curStrPos){
- if(this.stop === true)
- return;
- var humanize = Math.round(Math.random() * (100 - 30)) + this.typeSpeed;
- var self = this;
-
-
-
-
-
-
-
-
- self.timeout = setTimeout(function() {
-
-
-
- var charPause = 0;
- var substr = curString.substr(curStrPos);
- if (substr.charAt(0) === '^') {
- var skip = 1;
- if(/^\^\d+/.test(substr)) {
- substr = /\d+/.exec(substr)[0];
- skip += substr.length;
- charPause = parseInt(substr);
- }
-
- curString = curString.substring(0,curStrPos)+curString.substring(curStrPos+skip);
- }
-
- self.timeout = setTimeout(function() {
- if(curStrPos === curString.length) {
-
- self.options.onStringTyped(self.arrayPos);
-
- if(self.arrayPos === self.strings.length-1) {
-
- self.options.callback();
- self.curLoop++;
-
- if(self.loop === false || self.curLoop === self.loopCount)
- return;
- }
- self.timeout = setTimeout(function(){
- self.backspace(curString, curStrPos);
- }, self.backDelay);
- } else {
-
- if(curStrPos === 0)
- self.options.preStringTyped(self.arrayPos);
-
-
- var nextString = self.baseText + curString.substr(0, curStrPos+1);
- if (self.attr) {
- self.el.attr(self.attr, nextString);
- } else {
- self.el.text(nextString);
- }
-
- curStrPos++;
-
- self.typewrite(curString, curStrPos);
- }
-
- }, charPause);
-
- }, humanize);
- }
- , backspace: function(curString, curStrPos){
-
- if (this.stop === true) {
- return;
- }
-
-
- var humanize = Math.round(Math.random() * (100 - 30)) + this.backSpeed;
- var self = this;
- self.timeout = setTimeout(function() {
-
-
-
-
-
- if (self.arrayPos == 1) {
- self.stopNum = 17;
- self.backDelay = 500;
- }
- else if (self.arrayPos == 2) {
- self.stopNum = 54;
- }
- else{self.stopNum = 0;}
-
-
- var nextString = self.baseText + curString.substr(0, curStrPos);
- if (self.attr) {
- self.el.attr(self.attr, nextString);
- } else {
- self.el.text(nextString);
- }
-
-
- if (curStrPos > self.stopNum){
-
- curStrPos--;
-
- self.backspace(curString, curStrPos);
- }
-
-
- else if (curStrPos <= self.stopNum) {
- self.arrayPos++;
- if(self.arrayPos === self.strings.length) {
- self.arrayPos = 0;
- self.init();
- } else
- self.typewrite(self.strings[self.arrayPos], curStrPos);
- }
-
- }, humanize);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- , reset: function(){
- var self = this;
- clearInterval(self.timeout);
- var id = this.el.attr('id');
- this.el.after('<span id="' + id + '"/>')
- this.el.remove();
- this.cursor.remove();
-
- self.options.resetCallback();
- }
- };
- $.fn.typed = function (option) {
- return this.each(function () {
- var $this = $(this)
- , data = $this.data('typed')
- , options = typeof option == 'object' && option;
- if (!data) $this.data('typed', (data = new Typed(this, options)));
- if (typeof option == 'string') data[option]();
- });
- };
- $.fn.typed.defaults = {
- strings: ["These are the default values...", "You know what you should do?", "Use your own!", "Have a great day!"],
-
- typeSpeed: 0,
-
- startDelay: 0,
-
- backSpeed: 0,
-
- backDelay: 500,
-
- loop: false,
-
- loopCount: false,
-
- showCursor: true,
-
- cursorChar: "|",
-
- attr: null,
-
- callback: function() {},
-
- preStringTyped: function() {},
-
- onStringTyped: function() {},
-
- resetCallback: function() {}
- };
- }(window.jQuery);
- (function (factory) {
- if (typeof define === 'function' && define.amd) {
-
- define(['jquery'], factory);
- } else if (typeof exports === 'object') {
-
- factory(require('jquery'));
- } else {
-
- factory(jQuery);
- }
- }(function ($) {
- var pluses = /\+/g;
- function encode(s) {
- return config.raw ? s : encodeURIComponent(s);
- }
- function decode(s) {
- return config.raw ? s : decodeURIComponent(s);
- }
- function stringifyCookieValue(value) {
- return encode(config.json ? JSON.stringify(value) : String(value));
- }
- function parseCookieValue(s) {
- if (s.indexOf('"') === 0) {
-
- s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
- }
- try {
-
-
-
- s = decodeURIComponent(s.replace(pluses, ' '));
- return config.json ? JSON.parse(s) : s;
- } catch(e) {}
- }
- function read(s, converter) {
- var value = config.raw ? s : parseCookieValue(s);
- return $.isFunction(converter) ? converter(value) : value;
- }
- var config = $.cookie = function (key, value, options) {
-
- if (arguments.length > 1 && !$.isFunction(value)) {
- options = $.extend({}, config.defaults, options);
- if (typeof options.expires === 'number') {
- var days = options.expires, t = options.expires = new Date();
- t.setTime(+t + days * 864e+5);
- }
- return (document.cookie = [
- encode(key), '=', stringifyCookieValue(value),
- options.expires ? '; expires=' + options.expires.toUTCString() : '',
- options.path ? '; path=' + options.path : '',
- options.domain ? '; domain=' + options.domain : '',
- options.secure ? '; secure' : ''
- ].join(''));
- }
-
- var result = key ? undefined : {};
-
-
-
- var cookies = document.cookie ? document.cookie.split('; ') : [];
- for (var i = 0, l = cookies.length; i < l; i++) {
- var parts = cookies[i].split('=');
- var name = decode(parts.shift());
- var cookie = parts.join('=');
- if (key && key === name) {
-
- result = read(cookie, value);
- break;
- }
-
- if (!key && (cookie = read(cookie)) !== undefined) {
- result[name] = cookie;
- }
- }
- return result;
- };
- config.defaults = {};
- $.removeCookie = function (key, options) {
- if ($.cookie(key) === undefined) {
- return false;
- }
-
- $.cookie(key, '', $.extend({}, options, { expires: -1 }));
- return !$.cookie(key);
- };
- }));
- jQuery(document).ready(function($) {
-
- $(function dw_set_cookie() {
- var COOKIE = 'windhamdavid-cookie';
- var dwcookie = $.cookie(COOKIE);
- if (dwcookie == null) {
- $.cookie(COOKIE, 'yum-cookies', { expires: 7, path: '/'});
- $('.terminal-welcome').modal('show');
- $('.welcome').typed({
- strings: ['Hey,', 'Hello,\n^10Welcome to ^10my domain ^10...^10', 'Hello, \nWelcome to my little corner of the internet. \n^10It is nice to ', 'Hello, \nWelcome to my little corner of the internet. \nWhat is your name?^200\n'],
- typeSpeed: 30,
- backSpeed: 50,
- startDelay: 0,
- backDelay: 0,
- loop: false,
- loopCount: false,
- attr: null,
- callback: function(){
- dw_terminal();
- }
- });
- }
- else {
- $('.terminal').modal('show');
- if (localStorage.getItem('person') === null) {
- var person = 'anonymous person';
- }
- else {
- var person = localStorage.getItem('person');
- }
- $('.welcome-back-text').typed({
- strings: ['...', 'Welcome back ' +person],
- typeSpeed: 30,
- backSpeed: 10,
- startDelay: 0,
- backDelay: 100,
- loop: false,
- loopCount: false,
- attr: null,
- callback: function(){
- dw_terminal();
- }
- });
- }
- });
- (function ($){
- $.fn.cli = function(handler, prompt, effect){
- if (!prompt) prompt = '<span class="u">you</span><span class="at">@</span><span class="mee">david</span> > ';
- if (!effect) effect = $.fn.text;
- return this.each(function(){
- var self = $(this);
- function newline(){
- self.
- append('<p class=input><span class=prompt>'+prompt+'</span><span style=outline:none contenteditable></span></p>');
- try {
- $('[contenteditable]', self)[0].focus();
- }catch(e){
- }
- }
- newline();
- self.on('keydown', '[contenteditable]', function(evt){
- if (evt.keyCode === 13){
- $(this).removeAttr('contenteditable');
- effect.call($('<p class=response>').appendTo(self),handler(this.textContent || this.innerText));
- newline();
- return false;
- }
- });
- });
- };
- })(jQuery);
- function dw_shift() {
- $('.terminal-welcome').delay(5500).queue(function(thanks){
- $(this).modal('hide');
- thanks();
- });
- }
- function dw_contact() {
- $('.terminal-welcome').delay(2500).queue(function(thanks){
- window.location.assign("/contact/");
- });
- }
- function dw_terminal(){
- function type(text){
- var span = $('<span>').appendTo(this).after('<span id="blinker" style="background:green"> </span>');
- var style = $('<style>p.input {visibility: hidden} p.input.old {visibility: visible}</style>').appendTo('head');
- $('p.input').addClass('old');
- var progress = 0;
- var timer = setInterval (function(){
- span.text(text.substr(0, progress++));
- if (progress > text.length){
- $('#blinker').remove();
- style.remove();
- $('[contenteditable]')[0].focus();
- clearInterval(timer);
- }
- },100);
- }
- $('.thermo-intro').cli(function(text){
- if (text.length > 1) {
- localStorage.setItem('person', text),
- dw_shift();
- };
- return 'I will close this terminal now. Thank You ' +text;
- }, null, type);
- $('.thermo').cli(function(text){
- if (/exit/i.test(text)) {
- $('.terminal').modal('hide');
- }
- if (/contact/i.test(text)) {
- return "loading...",
- dw_contact();
- };
- if (/help/i.test(text)) return "I need somebody!";
- if (/hello/i.test(text)) return "Hello to you!";
- if (/what/i.test(text)) return "This is a website silly human";
- if (/and/i.test(text)) return "and what?";
- if (/who/i.test(text)) return "David A. Windham";
- if (/when/i.test(text)) return "Yesterday";
- if (/how/i.test(text)) return "JavaScript is a dynamic computer programming language";
- if (/why/i.test(text)) return "For fun";
- if (/you/i.test(text)) return "your mama";
- if (/cd ../i.test(text)) return "Oh, I see";
- if (/thermonuclear/i.test(text)) return "Wouldn't you prefer a nice game of chess?";
- if (text.length < 3) return "type 'exit' to close";
- return 'command not found: '+text;
- }, null, type);
- $('p.input').on('touchstart click', function(e) {
- e.preventDefault();
- $('[contenteditable]')[0].focus();
- });
- }
- });
|