This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtophat.js
75 lines (53 loc) · 2.19 KB
/
tophat.js
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
// stylesheet to be auto inserted
require("./tophat.css");
require("./vendor/matchMedia");
// import scripts
var utils = require("./utils/dom");
var body = document.body;
var config = require("./config");
// find or create the tophat element
var tophatElement = getTophatElement( "nice-tophat", config );
// create the cookie message element
var cookieElement = require("./cookie")( tophatElement, config );
// create the service elements
var serviceElement = require("./services")( tophatElement, config );
// create the evidence elements
var evidenceElement = require("./evidence")( tophatElement, serviceElement, config );
// create the profile elements
require("./profile")( tophatElement, serviceElement, config );
// find or create the global element
var globalElement = require("./global")( tophatElement, config );
// create the search form and prepend it to the global element
require("./search")( globalElement, serviceElement, config );
composeTophat( tophatElement, cookieElement, serviceElement, evidenceElement, globalElement, config );
// attach all the events to the tophat
require("./events")( document, tophatElement, serviceElement, config );
// notify scripts that tophat has loaded
if (document.onTophatReady) {
document.onTophatReady();
}
// helper functions
function getTophatElement( classname, config ) {
var el = utils.find( body, classname )[0];
if (!el) {
el = utils.create("<div role=\"banner\" class=\""+ classname +"\"></div>");
}
el.className = classname +
( config.internal ? " nice-internal" : "" ) +
( config.legacy ? " tophat-legacy" : "" );
return el;
}
function composeTophat( el, cookieElement, services, evidenceResources, globalMenu, config ) {
if (cookieElement) utils.appendElement( cookieElement, el );
utils.appendElement( services, el );
if (evidenceResources) utils.appendElement( evidenceResources, el );
if (globalMenu) utils.appendElement( globalMenu, el );
if ( config.service ) {
var className = "menu-" + config.service;
var active = utils.find( el, className )[0];
active.className += " active";
el.className += " " + className + "-active";
}
// attach the tophat to the top of the body
utils.prependElement( tophatElement, body );
}