-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
587 lines (542 loc) · 22.6 KB
/
index.html
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
<!DOCTYPE html>
<html>
<head>
<title>Utils.js</title>
<script src='jquery/jquery-3.1.0.min.js'></script>
<!-- <script src='jquery/jquery-ui.min.js'></script>-->
<script src='bootstrap/bootstrap.min.js'></script>
<link href='bootstrap/bootstrap.min.css' rel='stylesheet' />
<script src='utils/utils.js'></script>
<script src='utils/utils-ui.js'></script>
<script src='highlight/highlight.min.js'></script>
<link href='highlight/default.min.css' rel='stylesheet' />
<style>
.wrapper { margin-bottom: 10px; }
.btn { margin: 2px; }
#right_menu { position: absolute; width: 250px; top: 420px; right: 0px; }
</style>
<script src="Samples.js"></script>
</head>
<body>
<div id="right_menu" ></div>
<div id="header" class="container-fluid" style="height: 420px; background-color: #004225; font-size: 18px; font-weight: bold; color: white;" >
<div style="font-family: Courier New, Courier, monospace; margin: 30px auto; width: 200px; height: 200px; font-weight: bold; font-size: 150px; text-align: center; border: 2px solid #fff; border-radius: 10px; ">U</div>
<div style="margin: auto; width: 500px;">
<p style="text-align: justify; margin-bottom: 30px;">
utils.js is a toolkit for building dynamic DOM structures. Built on top of jQuery and Bootstrap it contains a range of functions for altering
and building the DOM dynamically. As well as wrappers for making AJAX requests.
</p>
</div>
<div style="margin: auto; width: 250px;">
<button class="selector-gitlink" style="width: 100%; font-size: 18px; font-weight: bold;" role="button">Download utils.js</button>
</div>
</div>
<div class="container wrapper" id="container-includes">
<h3>Using utils.js</h3>
<p>Just include the following in your page, the order is important here.<br />
I've made the assumption here that you are hosting it all locally and the directory structure is:<br />
<pre>
- root
|- bootstrap
| |- js files
| |- css files
|
|- jQuery
| |- js files
|
|- utils
| |- js files
|
|- page.htm
</pre>
</p>
<pre style="display: block;"><code class="html"><DOCTYPE !html>
<html>
<head>
<!-- jQuery + jQuery-ui -->
<script src='jquery/jquery-3.1.0.min.js'></script>
<!--<script src='jquery/jquery-ui.min.js'></script>-->
<!-- bootstrap + its CSS, you can switch the CSS out for any bootstrap template -->
<script src='bootstrap/bootstrap.min.js'></script>
<link href='bootstrap/bootstrap.min.css' rel='stylesheet' />
<!-- the actual utils -->
<script src='utils/utils.js'></script>
<script src='utils/utils-ui.js'></script>
</head>
<body>
</code></pre>
<p>Download the code from here</p>
<ul>
<li><a target="_blank" href="utils/utils.js">utils/utils.js</a></li>
<li><a target="_blank" href="utils/utils-ui.js">utils/utils-ui.js</a></li>
</ul>
</div>
<!-- utils.js -->
<div class="container wrapper" id="container-1">
<h3>Core Functionality</h3>
<div class="well">
<p>Very brief documentation about whats in utils.js</p>
<pre style="display: block;"><code class="javascript">$.utils.createUUID()
// returns a UUID
$.utils.toRGB(string:hex)
// converts a hex number into an object of the form { r:nn, g:nn, b:nn }
$.utils.vars.set(string:key, object:value, bool:fixed)
// adds a variable to the utils.vars object and controls whether it can be changed
$.utils.vars.get(string:key, bool:info)
// gets a value from the utils.vars object info returns the settign s as well as the value
$.utils.localStorage(string:appId, bool:persist)
// returns a refernce to either localStorage || sessionStorage that has associated functions for managing data
$.utils.ajaxOptions.set(object:options)
// sets global ajax options to avoid passing the same information into each calling
$.utils.ajax(object:options)
// calls $.ajax using global ajax options extended with what ever you pass in
$.utils.await(array:calls, func:complete)
// calls a function after a number of ajax calls have all completed
</code></pre>
</div>
</div>
</div>
<div class="container wrapper" id="container-0">
<h3>Core Functionality (utils.js)</h3>
<p>All core functionality is in utils.js, none of this directly effects the UI but contains a set of tools for data management.<br />utils.js has no dependencies on utils-ui.js</p>
<div class="well">
<p>Create a UUID, internally this is also used with a lot of the UI componants to provide unique identifiers for the elements</p>
<pre style="display: block;"><code class="javascript">$.utils.createUUID()
for (var i = 0; i < 3; i++)
{
document.write( "//<br />" + $.utils.createUUID());
}
<script>for (var i = 0; i < 3; i++) { document.write("<br />//" + $.utils.createUUID()); }</script>
</code></pre>
</div>
<div class="well">
<p>Assert that variable matches the expected type and that its in range</p>
<pre style="display: block;"><code class="javascript">$.utils.assert({ variable: (var), type: (string), min: (int), max: (int), allowNull: (bool)})
<script>document.write("$.utils.assert({ variable: 3, type: 'number', min: 0, max: 10}) //" + $.utils.assert({ variable: 3, type: "number", min: 0, max: 10 }));</script>
<script>document.write("$.utils.assert({ variable: 30, type: 'number', min: 0, max: 10}) //" + $.utils.assert({ variable: 30, type: "number", min: 0, max: 10 }));</script>
<script>document.write("$.utils.assert({ variable: 'foo', type: 'string'}) //" + $.utils.assert({ variable: "foo", type: "string" }));</script>
<script>document.write("$.utils.assert({ variable: $.utils, type: 'function'}) //" + $.utils.assert({ variable: $.utils, type: "function" }));</script>
<script>document.write("$.utils.assert({ variable: $.utils, type: 'object'}) //" + $.utils.assert({ variable: $.utils, type: "object" }));</script>
<script>document.write("$.utils.assert({ variable: null, type: 'object'}) //" + $.utils.assert({ variable: null, type: 'object' }));</script>
<script>document.write("$.utils.assert({ variable: null, type: 'object', allowNull: true}) //" + $.utils.assert({ variable: null, type: 'object', allowNull: true }));</script>
</code></pre>
</div>
<div class="well">
<p>A wrapper to allow standard settings to be used for all ajax calls. This can be set directly but a helper function is supplied to allow easy merging of settings. Subsequent calls can then be made by specifing only the minimum amount of information</p>
<pre style="display: block;"><code class="javascript">$.utils.ajaxOptions.set(object:options)
ajaxOptions: {
//
global: true,
// primarily for use when calling the same API over numerous calls,
// eg http://api.something.co.uk/
baseURL: "/",
// method to call, default is GET
type: "GET",
// encoding to use
contentType: "application/json",
// data to send with POST requests
data: "",
// would normally be specified per call, will be appended to baseURL,
// eg getData would call url http://api.something.co.uk/getData
path: "",
// useful for appending session / authentication keys to each call
beforeSend: function (xhr) { },
// called on successful completion, probably not useful as a global
success: function (data) { },
// called on error
error: function (data) { },
// just merge what we pass in with whats already there
set: function (options)
{
$.extend(this, options);
},
}
</code></pre>
</div>
<div class="well">
<p>Making ajax calls</p>
<pre style="display: block;"><code class="javascript">$.utils.ajax(object:options)
$.utils.ajax({
path: "postSomething",
data: { variable1: "sausages" },
success: function(data)
{
// process data
}
});
</code></pre>
</div>
<div class="well">
<p>Making multiple ajax calls, and waiting for them all to complete</p>
<pre style="display: block;"><code class="javascript">$.utils.await(array:calls, func:complete)
$.utils.await([
{
path: "getMethod",
},
{
path: "postMethod",
data: { variable1: "sausages" },
},
{
path: "postMethod",
data: { variable1: "bacon" },
}
], function()
{
// call this when all the calls have returned
}
);
</code></pre>
</div>
<div class="well">
<p>Peridoically calling the same AJAX endpoint</p>
<pre style="display: block;"><code class="javascript">$.utils.poll(object:options, int:frequency(s));
var callId = $.utils.poll({
path: "postSomething",
data: { variable1: "sausages" },
success: function(data)
{
// process data
}
},30);
// to cancel the repeat calls, keep hold of the id and pass it to clearInterval()
window.clearInterval(callId);
</code></pre>
</div>
<!-- Nav bar -->
<div class="container wrapper" id="container-ui">
<h3>UI Functionality (utils-ui.js)</h3>
<p>All UI functionality is included in utils-ui.js<br />utils-ui.js is dependent upon utils.js</p>
</div>
<div class="container wrapper" id="container-01">
<h3>Dialogues</h3>
<div class="well">
<p></p>
<button class="selector-alert">Alert</button>
<button class="selector-dialogue">Dialogue</button>
<div class="selector-code-collapse">
<button>Toggle Code Display</button>
<pre style="display: none;"><code class="html"><!-- no html -->
</code>
<code class="javascript">$("#container-01 button.selector-alert").bs_button().click(function ()
{
$.fn.alert("utils.js makes this so easy!");
});
$("#container-01 button.selector-dialogue").bs_button().click(function ()
{
var id = $.utils.createUUID();
var $content = $("<div />")
.append($("<ol />")
.append($("<li />").text("An"))
.append($("<li />").text("Ordered"))
.append($("<li />").text("List"))
.append($("<p />").text("This is just a <p /> tag to explain that the input below is using $.utils.labeledInput() to add content as the dialogue opens"))
.append($("<div />").addClass("text"))
);
$.fn.dialogue({
title: "Dialogue",
content: $content,
buttons: [
{ text: "Close", click: function ($modal) { $modal.dismiss(); } },
{ text: "Highlight <p />", click: function ($modal) { $modal.find("p").css({ color: "#f00" }) } },
{ text: "Alert", click: function () { $.fn.alert("utils.js makes this so easy!"); } },
],
open: function ($modal)
{
$modal.find(".text").labeledInput({ label: "Text input", placeholder: "Text field" });
}
});
});
</code></pre>
</div>
</div>
</div>
<!-- Nav bar -->
<div class="container wrapper" id="container-1">
<h3>Basic Navbar</h3>
<div class="well">
<p>Simple dropdown</p>
<nav></nav>
<div id="output-1" class="container"> </div>
<div class="selector-code-collapse">
<button>Toggle Code Display</button>
<pre style="display: none;"><code class="html"><div id="container">
<nav></nav>
</div>
</code>
<code class="javascript">$("#container nav").bs_navbar(
{
label: "Section 1",
groups: [
{
position: "right",
elements: [
$("<li />").bs_dropdown(
{
title: "Menu 1",
callback: function (data)
{
$("#output-1").html(data + ": Dropdown");
},
elements: [
{ text: "1st", data: "-1st- is just dull" },
{ text: "2nd", data: "Gorganzola is the best" },
{ text: "3rd", data: "Sausages are great" },
{ prior: "seperator", text: "1st after divider", data: "1st-after-divider" }
]
})
]
}
]
});
</code></pre>
</div>
</div>
</div>
<!-- advanced navbar -->
<div class="container wrapper" id="container-2">
<h3>Advanced Navbar</h3>
<div class="well">
<p>Including links, left and right aligned content</p>
<nav></nav>
<div id="output-2" class="container"> </div>
<div class="selector-code-collapse">
<button>Toggle Code Display</button>
<pre style="display: none;"><code class="html"><div id="container">
<nav></nav>
</div>
</code>
<code class="javascript">$("#container nav").bs_navbar(
{
callback: function (data)
{
$("#output-2").html(data + ": Global");
},
label: "Section 2",
groups: [
{
callback: function (data)
{
$("#output-2").html(data + ": Left");
},
position: "left",
elements: [
{ text: "Link 1", data: "Group1-Link1" },
{ text: "Link 2", data: "Group1-Link2" },
$("<li />").bs_dropdown(
{
title: "Menu 2",
callback: function (data)
{
$("#output-2").html(data + ": Dropdown");
},
elements: [
{ text: "1st", data: "-1st-" },
{ text: "2nd", data: "Gorganzola" },
{ text: "3rd", data: "Sausages" },
{ prior: "seperator", text: "1st after divider", data: "1st-after-divider" }
]
})
]
},
{
position: "right",
callback: function (data)
{
$("#output-2").html(data + ": Right");
},
elements: [
{ text: "Link 1", data: "Group2-Link1" },
{ text: "Link 2", data: "Group2-Link2" }
]
}
]
});
</code></pre>
</div>
</div>
</div>
<!-- content switcher -->
<div class="container wrapper" id="container-3">
<h3>Content Switcher</h3>
<div class="well">
<p>Pre-configured content switches on button click</p>
<button>Click Me! To change the text below</button>
<div id="switcher">
<div>This message will scroll round a pre-configured list, this is item 1</div>
<div>This is item 2, there is more to come</div>
<div>This is item 3, its the last one. After this it will go back to the start</div>
</div>
<div class="selector-code-collapse">
<button>Toggle Code Display</button>
<pre style="display: none;"><code class="html"><div id="container">
<button>Click me</button>
<div id="switcher">
<div>First content</div>
<div>Second content</div>
<div>Third content</div>
</div>
</div>
</code>
<code class="javascript">$("#container button").bs_button().click(function ()
{
$("#switcher").bs_switcher("next");
});
$("#switcher").bs_switcher();
</code></pre>
</div>
</div>
<!-- labeled input -->
<div class="container wrapper" id="container-4">
<h3>Labeled Input</h3>
<p>Password field is using right aligned label</p>
<div class="text"></div>
<div class="number"></div>
<div class="password"></div>
<div class="selector-code-collapse">
<button>Toggle Code Display</button>
<pre style="display: none;"><code class="html"><div id="container">
<div class="text"></div>
<div class="number"></div>
<div class="password"></div>
</div>
</code>
<code class="javascript">$("#container .text").labeledInput({ label: "Text input", placeholder: "Text field" });
$("#container .number").labeledInput({ label: "Number input", placeholder: "Number field", inputtype: "number" });
$("#container .password").labeledInput(
{
label: "Password input",
placeholder: "Password field",
inputtype: "password",
labelposition: "right",
labelcss: { textAlign: "left" }
}
);
</code></pre>
</div>
</div>
</div>
<!-- progress -->
<div class="container wrapper" id="container-5">
<h3>Progressbar</h3>
<div class="well">
<p>A progress bar for precentages (Range 0 - 100)</p>
<div class="percentage"></div>
<p>A progress bar for values (Range 25 - 80) NB: Only works for positive numbers</p>
<div class="number"></div>
<button data-value="25">Set to 25</button>
<button data-value="50">Set to 50</button>
<button data-value="75">Set to 75</button>
<br /><br />
<div class="selector-code-collapse">
<button>Toggle Code Display</button>
<pre style="display: none;"><code class="html"><div id="container">
<div class="percentage"></div>
<div class="number"></div>
<button data-value="25">Set to 25</button>
<button data-value="50">Set to 50</button>
<button data-value="75">Set to 75</button>
</div>
</code>
<code class="javascript">$("#container button").bs_button().click(function ()
{
$("#container div").bs_progress("update", $(this).data("value"));
});
$("#container div.percentage").bs_progress({ valuenow: 50 });
$("#container div.number").bs_progress({ valuenow: 75, valuemin: 25, valuemax: 80 });
</code></pre>
</div>
</div>
</div>
<!-- breadcrumbs -->
<div class="container wrapper" id="container-6">
<h3>Breadcrumbs</h3>
<div class="well">
<p>Breadcrumb trail of where the page is</p>
<div class="trail"></div>
<div class="selector-code-collapse">
<button>Toggle Code Display</button>
<pre style="display: none;"><code class="html"><div id="container">
<div></div>
</div>
</code>
<code class="javascript">$("#container .trail").bs_breadcrumb({
trail: [
{ text: "Home", link: "#" },
{ text: "Library", link: "https://google.co.uk" },
{ text: "Data" }
]
});
</code></pre>
</div>
</div>
</div>
<!-- tables -->
<div class="container wrapper" id="container-7">
<h3>Tables</h3>
<div class="well">
<p>Simple formatting for table data, sortable by clicking on column headers</p>
<div>
<table></table>
<div class="feedback">Data from clicked rows will be displayed here</div>
</div>
<div class="selector-code-collapse">
<button>Toggle Code Display</button>
<pre style="display: none;"><code class="html"><div id="container">
<table></table>
</div>
</code>
<code class="javascript">$("#container table").bs_table({
{
responsive: true, // default is true
titles: ["Firstname","Surname","Shoe size"],
data: [
["Joe","Blogs","8"],
["Kate","Doe","6"],
["Fred","Flintstone",null],
],
classes: ["hover", "table-striped"],
rowclick: function (colData)
{
alert(colData);
}
}
});
</code></pre>
</div>
</div>
</div>
<!-- notifications / alerts -->
<div class="container wrapper" id="container-8">
<h3>Alerts</h3>
<div class="well">
<p>Positionable information / alert messages</p>
<div>
<button class="selector-alert" data-position="fixed-bottom" data-type="danger">Show Bottom Danger</button>
<button class="selector-alert" data-position="fixed-top" data-type="info">Show Top Info</button>
<br /><br />
</div>
<div class="selector-code-collapse">
<button>Toggle Code Display</button>
<pre style="display: none;"><code class="html"><div id="container">
<button class="selector-alert" data-position="fixed-bottom" data-type="danger">Show Bottom Danger</button>
<button class="selector-alert" data-position="fixed-top" data-type="info">Show Top Info</button>
</div>
</code>
<code class="javascript">$("#container .selector-alert").bs_button().click(function ()
{
$.utils.bs_alert({
title: "Title in bold!",
msg: "Followed by the message",
position: $(this).data("position"),
type: $(this).data("type")
});
});
</code></pre>
</div>
</div>
</div>
<!-- padding at the bottom -->
<div style="height: 50px;"></div>
</body>
</html>