Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 267 lines (266 sloc) 10.664 kb
967359e @chrisdone added a demo, fixed a '
authored
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5 <title>JQuery Console Demo</title>
6 <meta name="Content-Type" content="text/html; charset=UTF-8">
c394fd2 @chrisdone Use jquery CDN in demo
authored
7 <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
967359e @chrisdone added a demo, fixed a '
authored
8 <script type="text/javascript" src="jquery.console.js"></script>
9 <!-- Everything beyond this point is user-customized -->
10 <script type="text/javascript">
11 $(document).ready(function(){
12 /* First console */
13 var console1 = $('<div class="console1">');
14 $('body').append(console1);
f680bb4 @spratt Fixed an bug where if the console did not define a welcome message, the ...
spratt authored
15 var controller1 = console1.console({
967359e @chrisdone added a demo, fixed a '
authored
16 promptLabel: 'Demo> ',
17 commandValidate:function(line){
18 if (line == "") return false;
19 else return true;
20 },
21 commandHandle:function(line){
22 return [{msg:"=> [12,42]",
23 className:"jquery-console-message-value"},
24 {msg:":: [a]",
25 className:"jquery-console-message-type"}]
26 },
27 autofocus:true,
28 animateScroll:true,
a87daa7 @chrisdone added extra example to demo.html
authored
29 promptHistory:true,
30 charInsertTrigger:function(keycode,line){
31 // Let you type until you press a-z
32 // Never allow zero.
33 return !line.match(/[a-z]+/) && keycode != '0'.charCodeAt(0);
34 }
967359e @chrisdone added a demo, fixed a '
authored
35 });
36 /* Second console */
37 var console2 = $('<div class="console2">');
38 $('body').append(console2);
421b5c1 added promptText function for setting the text of the current prompt
Chris Done authored
39 var controller2 = console2.console({
967359e @chrisdone added a demo, fixed a '
authored
40 promptLabel: 'JavaScript> ',
41 commandValidate:function(line){
42 if (line == "") return false;
43 else return true;
44 },
45 commandHandle:function(line){
46 try { var ret = eval(line);
47 if (typeof ret != 'undefined') return ret.toString();
48 else return true; }
49 catch (e) { return e.toString(); }
50 },
51 animateScroll:true,
a87daa7 @chrisdone added extra example to demo.html
authored
52 promptHistory:true,
53 welcomeMessage:'Enter some JavaScript expressions to evaluate.'
54 });
421b5c1 added promptText function for setting the text of the current prompt
Chris Done authored
55 controller2.promptText('5 * 4');
6c326e8 @spratt Fixed history bug.
spratt authored
56 /* Third console */
096d4c6 @spratt Added a hook to allow user to handle C-c, the user interrupt
spratt authored
57 var console3CancelFlag = false;
58 var console3 = $('<div class="console3">');
a87daa7 @chrisdone added extra example to demo.html
authored
59 $('body').append(console3);
f680bb4 @spratt Fixed an bug where if the console did not define a welcome message, the ...
spratt authored
60 var controller3 = console3.console({
a87daa7 @chrisdone added extra example to demo.html
authored
61 promptLabel: 'Echo> ',
62 commandValidate:function(line){
63 if (line == "") return false;
64 else return true;
65 },
66 commandHandle:function(line,report){
6fa359b @spratt Fixed input bug. User can no longer type while a command is running.
spratt authored
67 setTimeout(function() {
096d4c6 @spratt Added a hook to allow user to handle C-c, the user interrupt
spratt authored
68 if(!console3CancelFlag)
69 report(line);
70 else {
71 report([{msg:"User interrupt",
72 className:"jquery-console-message-error"}]);
73 console3CancelFlag = false;
74 }
6fa359b @spratt Fixed input bug. User can no longer type while a command is running.
spratt authored
75 },1000);
a87daa7 @chrisdone added extra example to demo.html
authored
76 },
096d4c6 @spratt Added a hook to allow user to handle C-c, the user interrupt
spratt authored
77 cancelHandle:function() {
78 console3CancelFlag = true;
79 },
a87daa7 @chrisdone added extra example to demo.html
authored
80 animateScroll:true,
967359e @chrisdone added a demo, fixed a '
authored
81 promptHistory:true
82 });
b0dac7d @chrisdone added fourth console example with multiple line input support
authored
83 /* Fourth console */
84 var console4 = $('<div class="console4">');
85 $('body').append(console4);
86 var controller4 = console4.console({
87 promptLabel: 'SQL> ',
88 continuedPromptLabel: ' -> ',
89 commandValidate:function(line){
90 if (line == "") return false;
91 else return true;
92 },
93 commandHandle:function(line,report){
94 if (line.match(/;$/)) {
95 controller4.continuedPrompt = false;
df4744f @chrisdone added alert to demonstrate getting a multi-line statement
authored
96 alert("Execute: " + line);
b0dac7d @chrisdone added fourth console example with multiple line input support
authored
97 return true;
98 } else {
99 controller4.continuedPrompt = true;
100 return;
101 }
102 },
103 promptHistory:true
104 });
9cdf6a3 @vietj add command completion feature
vietj authored
105 /* Fifth console */
106 var console5 = $('<div class="console1">');
107 $('body').append(console5);
108 var controller5 = console5.console({
109 promptLabel: 'Complete> ',
110 commandHandle:function(line){
111 if (line) {
112 return [{msg:"you typed " + line,className:"jquery-console-message-value"}];
113 } else {
114 var m = "type a color among (" + this.colors.join(", ") + ")";
115 return [{msg:m,className:"jquery-console-message-value"}];
116 }
117 },
118 colors: ["red","blue","green","black","yellow","white","grey"],
119 cols: 40,
120 completeHandle:function(prefix){
121 var colors = this.colors;
122 var ret = [];
123 for (var i=0;i<colors.length;i++) {
124 var color=colors[i];
125 if (color.lastIndexOf(prefix,0) === 0) {
126 ret.push(color.substring(prefix.length));
127 }
128 }
129 return ret;
130 }
c8812e4 @chr15m New method `report(msg, className)` allows external access to inject out...
chr15m authored
131 });
132 /* Sixth console */
133 var console6 = $('<div class="console6">');
134 $('body').append(console6);
135 var controller6 = console6.console({
136 promptLabel: 'Periodic> ',
137 commandValidate:function(line){
138 if (line == "") return false;
139 else return true;
140 },
141 commandHandle:function(line){
142 return [{msg:"=> [12,42]",
143 className:"jquery-console-message-value"},
144 {msg:":: [a]",
145 className:"jquery-console-message-type"}]
146 },
147 autofocus:true,
148 animateScroll:true,
149 promptHistory:true
150 });
151 var counter = 0;
152 setInterval(function() {
153 controller6.report([{msg:"The counter is at " + (counter++) + ".",
154 className:"jquery-console-message-value"},
155 {msg:(counter * 3) + " seconds have elapsed.",
156 className:"jquery-console-message-type"}]);
157 }, 3000);
967359e @chrisdone added a demo, fixed a '
authored
158 });
159 </script>
160 <style type="text/css" media="screen">
041787a @chrisdone Drop use of wbr, use word-wrap: break-word; — thanks, calebegg (refs #6)...
authored
161 div.console1,div.console2,div.console3 { word-wrap: break-word; }
967359e @chrisdone added a demo, fixed a '
authored
162 /* First console */
163 div.console1 { font-size: 14px }
562cec6 Remove whitespace [Gun.io WhitespaceBot]
Gun.io Whitespace Robot authored
164 div.console1 div.jquery-console-inner
096d4c6 @spratt Added a hook to allow user to handle C-c, the user interrupt
spratt authored
165 { width:900px; height:200px; background:#333; padding:0.5em;
967359e @chrisdone added a demo, fixed a '
authored
166 overflow:auto }
167 div.console1 div.jquery-console-prompt-box
168 { color:#fff; font-family:monospace; }
562cec6 Remove whitespace [Gun.io WhitespaceBot]
Gun.io Whitespace Robot authored
169 div.console1 div.jquery-console-focus span.jquery-console-cursor
967359e @chrisdone added a demo, fixed a '
authored
170 { background:#fefefe; color:#333; font-weight:bold }
171 div.console1 div.jquery-console-message-error
172 { color:#ef0505; font-family:sans-serif; font-weight:bold;
173 padding:0.1em; }
174 div.console1 div.jquery-console-message-value
175 { color:#1ad027; font-family:monospace;
176 padding:0.1em; }
177 div.console1 div.jquery-console-message-type
178 { color:#52666f; font-family:monospace;
179 padding:0.1em; }
180 div.console1 span.jquery-console-prompt-label { font-weight:bold }
181 /* Second console */
182 div.console2 { font-size: 14px; margin-top:1em }
562cec6 Remove whitespace [Gun.io WhitespaceBot]
Gun.io Whitespace Robot authored
183 div.console2 div.jquery-console-inner
096d4c6 @spratt Added a hook to allow user to handle C-c, the user interrupt
spratt authored
184 { width:900px; height:200px; background:#efefef; padding:0.5em;
967359e @chrisdone added a demo, fixed a '
authored
185 overflow:auto }
186 div.console2 div.jquery-console-prompt-box
187 { color:#444; font-family:monospace; }
562cec6 Remove whitespace [Gun.io WhitespaceBot]
Gun.io Whitespace Robot authored
188 div.console2 div.jquery-console-focus span.jquery-console-cursor
967359e @chrisdone added a demo, fixed a '
authored
189 { background:#333; color:#eee; font-weight:bold }
190 div.console2 div.jquery-console-message-error
191 { color:#ef0505; font-family:sans-serif; font-weight:bold;
192 padding:0.1em; }
193 div.console2 div.jquery-console-message-success
194 { color:#187718; font-family:monospace;
195 padding:0.1em; }
196 div.console2 span.jquery-console-prompt-label { font-weight:bold }
096d4c6 @spratt Added a hook to allow user to handle C-c, the user interrupt
spratt authored
197 /* Third console */
198 div.console3 { font-size: 14px; margin-top:1em }
562cec6 Remove whitespace [Gun.io WhitespaceBot]
Gun.io Whitespace Robot authored
199 div.console3 div.jquery-console-inner
096d4c6 @spratt Added a hook to allow user to handle C-c, the user interrupt
spratt authored
200 { width:900px; height:200px; background:#efefef; padding:0.5em;
201 overflow:auto }
202 div.console3 div.jquery-console-prompt-box
203 { color:#444; font-family:monospace; }
562cec6 Remove whitespace [Gun.io WhitespaceBot]
Gun.io Whitespace Robot authored
204 div.console3 div.jquery-console-focus span.jquery-console-cursor
096d4c6 @spratt Added a hook to allow user to handle C-c, the user interrupt
spratt authored
205 { background:#333; color:#eee; font-weight:bold }
206 div.console3 div.jquery-console-message-error
207 { color:#ef0505; font-family:sans-serif; font-weight:bold;
208 padding:0.1em; }
209 div.console3 div.jquery-console-message-success
210 { color:#187718; font-family:monospace;
211 padding:0.1em; }
b0dac7d @chrisdone added fourth console example with multiple line input support
authored
212 div.console3 span.jquery-console-prompt-label {
213 font-weight:bold }
214 /* Fourth console */
215 div.console4 { font-size: 14px; margin-top:1em }
562cec6 Remove whitespace [Gun.io WhitespaceBot]
Gun.io Whitespace Robot authored
216 div.console4 div.jquery-console-inner
b0dac7d @chrisdone added fourth console example with multiple line input support
authored
217 { width:900px; height:200px; background:#efefef; padding:0.5em;
218 overflow:auto }
219 div.console4 div.jquery-console-prompt-box
220 { color:#444; font-family:monospace; }
562cec6 Remove whitespace [Gun.io WhitespaceBot]
Gun.io Whitespace Robot authored
221 div.console4 div.jquery-console-focus span.jquery-console-cursor
b0dac7d @chrisdone added fourth console example with multiple line input support
authored
222 { background:#444; color:#eee; font-weight:bold }
223 div.console4 div.jquery-console-message-error
224 { color:#ef0505; font-family:sans-serif; font-weight:bold;
225 padding:0.1em; }
226 div.console4 div.jquery-console-message-success
227 { color:#187718; font-family:monospace;
228 padding:0.1em; }
229 div.console4 span.jquery-console-prompt-label { font-weight:bold }
c8812e4 @chr15m New method `report(msg, className)` allows external access to inject out...
chr15m authored
230 /* Sixth console */
231 div.console6 { font-size: 14px }
232 div.console6 div.jquery-console-inner
233 { width:900px; height:200px; background:#333; padding:0.5em;
234 overflow:auto }
235 div.console6 div.jquery-console-prompt-box
236 { color:#fff; font-family:monospace; }
237 div.console6 div.jquery-console-focus span.jquery-console-cursor
238 { background:#fefefe; color:#333; font-weight:bold }
239 div.console6 div.jquery-console-message-error
240 { color:#ef0505; font-family:sans-serif; font-weight:bold;
241 padding:0.1em; }
242 div.console6 div.jquery-console-message-value
243 { color:#1ad027; font-family:monospace;
244 padding:0.1em; }
245 div.console6 div.jquery-console-message-type
246 { color:#52666f; font-family:monospace;
247 padding:0.1em; }
248 div.console6 span.jquery-console-prompt-label { font-weight:bold }
967359e @chrisdone added a demo, fixed a '
authored
249 </style>
250 </head>
251 <body>
252 <noscript>
253 <p>
254 <strong>Please enable JavaScript or upgrade your browser.</strong>
255 </p>
256 </noscript>
257 <h1>Simple console demo</h1>
258 <p>Tested on:</p>
259 <ul>
260 <li>Internet Explorer 6</li>
261 <li>Opera 10.01</li>
262 <li>Chromium 4.0.237.0 (Ubuntu build 31094)</li>
263 <li>Firefox 3.5.8</li>
264 </ul>
265 </body>
266 </html>
Something went wrong with that request. Please try again.