Repository navigation
Expand file tree
/
Copy pathtype.js
More file actions
169 lines (144 loc) · 4.04 KB
/
Copy pathtype.js
File metadata and controls
169 lines (144 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
function Console(configuration){
var TextArrayLength;
var CurrentLineNumber = 0;
var LineIdentifiers = [];
//an array of text to type
var text;
var intervalSpeed;
var cursorBlinkSpeed;
var target;
var textColor;
var cursorColor;
var currentCursorColor;
var typeResponseModeEnabled;
var animationDone = false;
//GIANT TODO: CHECK FOR BOUNDS!!
if(configuration.text !== undefined)
{
text = configuration.text;
TextArrayLength = text.length;
BuildLineIdentifiersArray(TextArrayLength);
}
if(configuration.target !== undefined)
{
//a javascript object representing the div that will act as container for shell.
target = configuration.target;
}
if(configuration.speed !== undefined)
{
intervalSpeed = configuration.speed;
}
else
{
//default speed is 1 charachter per 200 ms.
intervalSpeed = 200
};
if(configuration.cursorBlinkSpeed !== undefined)
{
cursorBlinkSpeed = configuration.cursorBlinkSpeed;
}
else
{
//cursor will blink every 100 ms.
cursorBlinkSpeed = 100;
}
if(configuration.textColor !== undefined)
{
textColor = configuration.textColor;
}
else
{
textColor = "black";
}
if(configuration.cursorColor !== undefined)
{
cursorColor = configuration.cursorColor;
}
else
{
cursorColor = "gray";
}
this.RunConsole = function(){
SetupAndRun();
};
function AddText()
{
var line = text[CurrentLineNumber];
if(line === undefined){
//End the recursion array bounds exceeded, place cursor at bottom.
animationDone = true;
ResetCursorMoveToNextLine();
PlaceCursorOnDom();
return;
}
currentLine = line.split('');
currentShellIdString = LineIdentifiers[CurrentLineNumber];
characterNumber = 0;
PlaceTextLineSectionOnDom(currentShellIdString);
PlaceCursorOnDom();
typeLine(currentLine, currentShellIdString, characterNumber);
}
function getNextCursorColor()
{
if(currentCursorColor == "white")
{
currentCursorColor = cursorColor;
}
else
{
currentCursorColor = "white";
}
return currentCursorColor;
}
function BlinkCursor()
{
cursorbgColor = getNextCursorColor();
$("#cursor").animate({backgroundColor:cursorbgColor},{duration:150});
}
function BuildLineIdentifiersArray(NumLines)
{
for(var i = 0; i < NumLines; i++)
{
LineIdentifiers.push("ShellLineNumber" + i);
}
}
function typeLine(currentLine, currentLineIdentifier, currentCharacterNumber)
{
if(currentCharacterNumber == currentLine.length)
{
ResetCursorMoveToNextLine();
AddText();
return;
}
else
{
var c = currentLine[characterNumber];
$("#" + currentLineIdentifier).append(c);
characterNumber++;
window.setTimeout(function() { typeLine(currentLine,currentLineIdentifier,characterNumber); },intervalSpeed);
}
}
function PlaceCursorOnDom()
{
target.append("<div style=\"background-color: " + cursorColor + ";\" id=\"cursor\" ></div>");
}
function PlaceTextLineSectionOnDom(currentShellIdString)
{
target.append("<div class=\"shellLine\" style=\" color:" + textColor + "; \" id=\"" + currentShellIdString + "\"></div>");
}
function SetupAndRun()
{
target.css("white-space","nowrap");
window.setInterval(BlinkCursor, cursorBlinkSpeed);
AddText();
}
function ResetCursorMoveToNextLine()
{
CurrentLineNumber++;
$("#cursor").remove();
if(!animationDone)
{
target.append("<br />");
}
}
}