Commit 9bdcdcfe authored by Sven Franck's avatar Sven Franck

factory: added image rendering to header widget

parent 8a93e12c
......@@ -837,7 +837,12 @@
* "id": null,
* "title": "",
* "title_i18n":"",
* "fixed": true
* "fixed": true,
* "image": {
* "src": null,
* "alt": null,
* "alt_i18n": null
* }
* },
* "children": [],
* }
......@@ -846,25 +851,13 @@
* @return {object} object including fragment, child-selector, placeholder
*/
factory.widget.header = function (spec) {
var container, id, title, target, fragment;
var container, id, target, fragment;
container = document.createDocumentFragment();
id = spec.id || ((spec.data_url || "global") + "-header");
// generate title (needed for JQM), default to empty string
title = factory.element({
"type": "h1",
"direct": {"className": "translate ui-title"},
"attributes": {
"data-i18n": spec.title_i18n || "",
"role": "heading",
"aria-level": "1"
},
"logic": {"text": spec.title || "\u00A0"}
});
// button group wrappers and title (inserted before last wrapper!)
target = function (j, len) {
target = function (j, len, conf) {
switch (true) {
case (j === 0):
return factory.element({
......@@ -873,7 +866,28 @@
});
case (j === len - 1):
fragment = document.createDocumentFragment();
fragment.appendChild(title);
if (conf.img) {
fragment.appendChild(factory.element({
"type": "img",
"direct": {"src": conf.src},
"attributes": {"alt": conf.title},
"logic": {
"data-i18n": config.title_i18n ?
("[alt]" + config.title_i18n) : null
}
}));
} else {
fragment.appendChild(factory.element({
"type": "h1",
"direct": {"className": "translate ui-title"},
"attributes": {
"data-i18n": conf.title_i18n || "",
"role": "heading",
"aria-level": "1"
},
"logic": {"text": conf.title || "\u00A0"}
}));
}
fragment.appendChild(
factory.element({
"type": "div",
......@@ -909,7 +923,13 @@
"fragment": container,
"child_selector": container.querySelector("#" + id),
"target": target,
"target_selector": "last"
"target_selector": "last",
"spec": {
"img": spec.image,
"src": spec.src,
"title": spec.title || spec.alt,
"title_i18n": spec.title_i18n || spec.alt_i18n
}
};
};
......@@ -6187,10 +6207,12 @@
target = undefined;
if (response) {
// generate target for and append response
// NOTE: wrapper.spec is used for header only
if (wrapper.target) {
wrapper_selector = wrapper.target(
wrapper.child_selector.children.length,
kids.length
kids.length,
wrapper.spec
);
// NOTE: wrapper_selector will return a fragment (set to
// first/last-ElementChild or a DOM node
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment