Benutzer:Codeispoetry/quickbar2.js
Erscheinungsbild
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
/*global DOM, UserCfg, addOnloadHook, copySlotsRecursively */
var Quickbar = {
barTemplates: {
bar: {
id: 'p-quickbar',
className: 'portlet'
},
head: {
innerHTML: 'Quickbar'
},
body: {
id: 'p-quickbar',
className: 'pBody',
style: { fontSize: '75%' }
}
},
sectionTemplates: {
section: {
},
head: {
style: { display: 'none' }
},
body: {
}
},
fill: function () {
},
bardiv: null,
nextPortletId: 'p-navigation',
sections: {},
lastsection: null,
create: function () {
/* Hauptdiv */
Quickbar.bardiv = document.createElement('div');
copySlotsRecursively (Quickbar.bardiv, Quickbar.barTemplates.bar);
DOM.pasteBefore(DOM.get(Quickbar.nextPortletId), Quickbar.bardiv);
/* Titel */
var head = document.createElement('h5');
copySlotsRecursively (head, Quickbar.barTemplates.head);
Quickbar.bardiv.appendChild(head);
/* Body */
var body = document.createElement('div');
copySlotsRecursively (body, Quickbar.barTemplates.body);
Quickbar.bardiv.appendChild(body);
/* Initialisierung durchführen */
Quickbar.fill();
},
addSection: function (title) {
if (Quickbar.bardiv.lastChild.lastChild !== null) {
Quickbar.bardiv.lastChild.appendChild(document.createElement('hr'));
}
/* Hauptdiv */
var section = document.createElement('div');
section.id = 'qb-' + title;
copySlotsRecursively (section, Quickbar.sectionTemplates.section);
Quickbar.bardiv.lastChild.appendChild(section);
Quickbar.lastsection = section;
/* Titel */
var head = document.createElement('h6');
head.innerHTML = title;
copySlotsRecursively (head, Quickbar.sectionTemplates.head);
section.appendChild(head);
/* Body */
var body = document.createElement('div');
copySlotsRecursively (body, Quickbar.sectionTemplates.body);
section.appendChild(body);
return section;
},
addItem: function (parent, type, item) {
if (typeof parent === 'undefined' || parent === null) {
parent = Quickbar.lastsection;
}
if (!parent) {
throw ("no parent given and no section added yet");
}
if (!type) {
throw ("no type given");
}
var newitem = null;
switch (type) {
case 'line':
newitem = document.createElement('hr');
break;
case 'break':
newitem = document.createElement('br');
break;
case 'link':
newitem = document.createElement('a');
copySlotsRecursively(newitem, item);
break;
case 'html':
newitem = document.createElement('span');
newitem.innerHTML = item;
break;
case 'obj':
newitem = item;
break;
default:
throw ("unknown item type '" + type + "' given.");
}
parent.lastChild.appendChild(newitem);
parent.lastChild.appendChild(document.createTextNode(' '));
}
};
if (typeof UserCfg === 'object' && typeof UserCfg.Quickbar === 'object') {
copySlotsRecursively(Quickbar, UserCfg.Quickbar);
}
$ (Quickbar.create);