headfoot.js 10.3 KB
Newer Older
1
var menu = [{'name':'Informationen', 'combos':[{'name':'Projekte', 'link':'/project'}, {'name':'Über das M4_LAB', 'link':'/projectoverview?projectID=1'}], 'type':'dropdown', 'link':'#'},{'name':'Zusammenarbeit', 'combos':[{'name':'Mailinglisten', 'link':'/mailinglists'},{'name':'Videokonferenzen', 'link':'/videoconference.html'}, {'name':'...', 'link':'#'}], 'type':'dropdown', 'link':'#'},{'name':'Events', 'combos':[{'name':'Veranstaltungen der HfT', 'link':'http://www.hft-stuttgart.de/Aktuell/Veranstaltungen/'}, {'name':'...', 'link':'#'}], 'type':'dropdown', 'link':'#'},{'name':'Bürgerbeteiligung', 'combos':[{'name':'...', 'link':'#'}, {'name':'...', 'link':'#'}], 'type':'dropdown', 'link':'#'},{'name':'Login', 'combos':[], 'type':'loginbutton', 'link':'/account/'}];
2
3
4
5
6

var hft_links = [{'url':'#', 'name':'Kontakt'},{'url':'#', 'name':'Impressum'},{'url':'#', 'name':'Datenschutz'}]

var socialmedias = [{'url':'https://twitter.com/HFT_Presse', 'name': 'fa-twitter'}, {'url':'https://www.facebook.com/HfTStuttgart/', 'name': 'fa-facebook-square'}, {'url':'https://www.instagram.com/hft_stuttgart/', 'name': 'fa-instagram'}, {'url':'https://de.linkedin.com/school/hochschule-f%C3%BCr-technik-stuttgart-%E2%80%93-university-of-applied-sciences/', 'name': 'fa-linkedin'}, {'url':'https://www.youtube.com/channel/UCi0_JfF2qMZbOhOnNH5PyHA', 'name': 'fa-youtube'}];

Wolfgang Knopki's avatar
Wolfgang Knopki committed
7
var footer_images = [{'src':'/images/demo/bbf_logo.png', 'alt':'BMBF'}, {'src':'/images/demo/ihs_logo.jpg', 'alt':'Innovative Hochschule'}]
8
9
10
11
12

function prependChild(parent,child){
    parent.insertBefore(child, parent.childNodes[0]);
}

Wolfgang Knopki's avatar
Wolfgang Knopki committed
13
function userAuthenticated(){
14
15
16
    let params = new URLSearchParams(window.location.search);
    if(params.get('isAuthenticatedUser')){
        return true;
17
    }else if(document.getElementById('loginswitch')){   //relikt login via OAuth
Wolfgang Knopki's avatar
Wolfgang Knopki committed
18
19
20
        if(document.getElementById('loginswitch').getAttribute('authenticated') == '1'){
            return true;
        }
21
22
23
24
    }else{
        return false;
    }
}
Wolfgang Knopki's avatar
Wolfgang Knopki committed
25
26


Wolfgang Knopki's avatar
Wolfgang Knopki committed
27
28
29
30
31
32
33
34
function readCookie(cname) {
  var name = cname + "=";
  var decodedCookie = decodeURIComponent(document.cookie);
  var ca = decodedCookie.split(';');
  for(var i = 0; i <ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
Wolfgang Knopki's avatar
Wolfgang Knopki committed
35
    }
Wolfgang Knopki's avatar
Wolfgang Knopki committed
36
37
38
39
40
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
Wolfgang Knopki's avatar
Wolfgang Knopki committed
41
42
}

Wolfgang Knopki's avatar
Wolfgang Knopki committed
43
function sendRequest(URL){
Wolfgang Knopki's avatar
Wolfgang Knopki committed
44
    console.log(document.cookie);
Wolfgang Knopki's avatar
Wolfgang Knopki committed
45
46
    let xhr = new XMLHttpRequest();
    xhr.open("POST", URL, true);
Wolfgang Knopki's avatar
Wolfgang Knopki committed
47
    let token = readCookie("XSRF-TOKEN");
Wolfgang Knopki's avatar
Wolfgang Knopki committed
48
49
50
51
52
53
    //Send the proper header information along with the request
    xhr.setRequestHeader('X-CSRF-TOKEN', token);
    xhr.send();
}


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
/* function head()
 * creates header and prepends it to the documents body
 */

function head(){
    let headerdiv = document.createElement('div');
    let alertdiv = document.createElement('div');
    headerdiv.classList.add("wrapper","row1");
    let navheader = document.createElement('header');
    navheader.id = "header";
    navheader.classList.add("clear");
    let alertbutton = document.createElement('button');
    alertbutton.type = "button";
    alertbutton.classList.add("close");
    alertbutton.setAttribute("data-dismiss", "alert");
    alertbutton.innerHTML = "&times;";
    alertdiv.innerHTML="<strong>Disclaimer</strong> This website is under construction and in prototype-phase. It is not for public use."
    prependChild(alertdiv, alertbutton);
    alertdiv.classList.add('alert','alert-danger', 'alert-dismissible', 'fade','show');
    alertdiv.style = "text-align:center;";
    navheader.appendChild(alertdiv);
    let navbar = document.createElement('nav');
    navbar.classList.add("navbar", "navbar-default");
    let fluiddiv = document.createElement('div');
    fluiddiv.classList.add("container-fluid");
    let navbardiv = document.createElement('div');
    navbardiv.classList.add("navbar-header");
    let navelements = document.createElement('ul');
    navelements.id="navelemente";
    let logos = document.createElement('li');
    let link_m4lab = document.createElement('a');
85
    link_m4lab.href = "/";
Wolfgang Knopki's avatar
Wolfgang Knopki committed
86
    link_m4lab.innerHTML = "<img src='/images/demo/m4lab_logo.jpg' alt='Logo Innovationslabor M4_LAB'>";
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    logos.appendChild(link_m4lab);
    navelements.appendChild(logos);
    for(let j = 0; j<menu.length; j++){
        let headitem = document.createElement('li');
        let itemtype = menu[j].type;
        headitem.classList.add("nav-item")
        let headlink = document.createElement('a');
        headlink.href=menu[j].link;
        headlink.id="navbarDropdown" + j;
        headlink.classList.add('nav-link');
        headlink.setAttribute("role", "button");
        if(itemtype=='dropdown'){
            headitem.classList.add("dropdown");
            headlink.classList.add('dropdown-toggle');
            headlink.setAttribute("data-toggle", "dropdown");
            headlink.setAttribute("aria-haspopup", "true");
            headlink.setAttribute("aria-expanded", "false");
        }
        headlink.innerHTML=menu[j].name;
        if(itemtype=='dropdown'){
            let combodiv = document.createElement('div');
108
            combodiv.id=headlink.id+"_par";
109
110
111
112
113
            combodiv.setAttribute("aria-labelledby",headlink.id);
            combodiv.classList.add("dropdown-menu");
            for(let k = 0; k< menu[j].combos.length; k++){
                let combolink = document.createElement('a');
                combolink.classList.add("dropdown-item");
Wolfgang Knopki's avatar
Wolfgang Knopki committed
114
                if(userAuthenticated() || typeof user !== 'undefined'){ //either logged in the old way or logged in using SAML
115
116
117
118
119
                    if(menu[j].combos[k].link.includes('?')){
                        combolink.href = menu[j].combos[k].link + "&isAuthenticatedUser=true";
                    }else{    
                        combolink.href = menu[j].combos[k].link + "?isAuthenticatedUser=true";
                    }
120
121
122
                }else{
                    combolink.href = menu[j].combos[k].link;
                }
123
124
125
                combolink.innerHTML = menu[j].combos[k].name;
                combodiv.appendChild(combolink);
            }
126
            headitem.appendChild(combodiv);
127
128
129
130
131
        }else if(itemtype=='loginbutton'){
            if(userAuthenticated()){
                headlink.innerHTML="Account";
                headlink.href="/account/";
            }
132
            headlink.classList.remove("nav-link");
133
134
            headlink.classList.add("btn");
            headlink.classList.add("btn-outline-dark");
135
136
137
138
139
140
141
142
143
144
145
146
147
148
        }
        headitem.appendChild(headlink);
        navelements.appendChild(headitem);
    }
    let searchitem = document.createElement('li');
    searchitem.classList.add("nav-item");
    let searchinput = document.createElement('input');
    searchinput.value='Suche...'
    searchinput.type="text";
    searchinput.classList.add("nav-item-suchfeld");
    searchinput.setAttribute('onFocus', "this.value=(this.value=='search...')? '' : this.value");
    searchitem.appendChild(searchinput);
    let magnifier = document.createElement('input');
    magnifier.type="image"
Wolfgang Knopki's avatar
Wolfgang Knopki committed
149
    magnifier.src="/images/Lupe_grau.png";
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
    magnifier.width="25";
    magnifier.height="25";
    magnifier.alt="";
    magnifier.id="sf_submit";
    magnifier.value="search";
    searchitem.appendChild(magnifier);
    navelements.appendChild(searchitem);
    navbardiv.appendChild(navelements);
    fluiddiv.appendChild(navbardiv);
    navbar.appendChild(fluiddiv);
    navheader.appendChild(navbar);
    headerdiv.appendChild(navheader);
    prependChild(document.body, headerdiv);
};

/* function foot()
 * creates footer and appends it to the documents body
 */

function foot(){
    let footerdiv = document.createElement('div');
    footerdiv.id="homepage";
    footerdiv.classList.add("last", "clear");
    footerdiv.innerHTML = "<hr>";
    let containerdiv = document.createElement('div');
    containerdiv.classList.add('flex-container');
    let hftlink = document.createElement('a');
    hftlink.classList.add("col-md-3");
    hftlink.setAttribute('style','flex-basis: 400px;');
    hftlink.href="https://www.hft-stuttgart.de";
    let hftimage = document.createElement('img');
Wolfgang Knopki's avatar
Wolfgang Knopki committed
181
    hftimage.src="/images/demo/hft_logo.jpg"; 
182
183
184
185
186
187
188
189
190
191
192
193
    hftimage.alt="Logo der Hochschule für Technik Stuttgart";
    hftimage.height= '75';
    hftlink.appendChild(hftimage);
    containerdiv.appendChild(hftlink);
    let contactdiv = document.createElement('div');
    contactdiv.classList.add("col-md-3", "footer-unten")
    contactdiv.setAttribute('style',"flex-basis:400px");
    contactdiv.innerHTML="Hochschule für Technik Stuttgart";
    let rowdiv = document.createElement('div');
    rowdiv.classList.add("row");
    for(let i = 0; i<hft_links.length; i++){
        let coldiv = document.createElement('div');
Wolfgang Knopki's avatar
Wolfgang Knopki committed
194
        coldiv.classList.add("contactrow", "footer-unten");
195
196
        let collink = document.createElement('a');
        collink.innerHTML = hft_links[i].name;
Wolfgang Knopki's avatar
Wolfgang Knopki committed
197
        collink.classList.add("contact-lower")
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
        collink.href = hft_links[i].url;
        coldiv.appendChild(collink)
        rowdiv.appendChild(coldiv);
    }
    contactdiv.appendChild(rowdiv);
    containerdiv.appendChild(contactdiv);
    let socialdiv = document.createElement('div');
    socialdiv.classList.add("col-md-3");
    socialdiv.setAttribute('style','flex-basis: 400px;');
    let socialrow = document.createElement('div');
    socialrow.id="socialmediabuttons";
    for(let j = 0; j< socialmedias.length; j++){
        let sociallink = document.createElement('a');
        sociallink.href = socialmedias[j].url;
        let socialcontent = document.createElement('i');
        socialcontent.classList.add("fab", socialmedias[j].name);
        sociallink.appendChild(socialcontent);
        socialrow.appendChild(sociallink);
216
        socialrow.innerHTML+="&nbsp;";
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
    }
    socialdiv.appendChild(socialrow);
    containerdiv.appendChild(socialdiv);
    let imagediv = document.createElement('div');
    imagediv.classList.add("col-md-3");
    imagediv.setAttribute("style", "flex-basis:400px;");
    for (let k = 0; k< footer_images.length; k++){
        let image = document.createElement('img');
        image.src = footer_images[k].src;
        image.width="100";
        image.height= "50";
        image.alt = footer_images[k].alt;
        imagediv.appendChild(image);
    }
    containerdiv.appendChild(imagediv);
    footerdiv.appendChild(containerdiv);
    document.body.appendChild(footerdiv);
};


head();
foot();