Commit e4d1f20f authored by Sven Franck's avatar Sven Franck

jslint

parent b286b8c0
...@@ -4836,7 +4836,7 @@ ...@@ -4836,7 +4836,7 @@
zero_no_show = (no_limit === 0 && use_total !== 0) ? 1 : no_limit; zero_no_show = (no_limit === 0 && use_total !== 0) ? 1 : no_limit;
if (no_total) { if (no_total) {
min = ((no_limit + no_items === 0) ? use_total : min = ((no_limit + no_items === 0) ? use_total :
no_limit + no_items); no_limit + no_items);
total_records = ""; total_records = "";
} else { } else {
min = Math.min( min = Math.min(
...@@ -4966,8 +4966,8 @@ ...@@ -4966,8 +4966,8 @@
}; };
} }
// NOTE: currentTarget needed for bubbling (eg tree) // NOTE: currentTarget needed for bubbling (eg tree)
current = e.currentTarget; current = e.currentTarget === document ? undefined : e.currentTarget;
element = (current === document ? undefined : current) || e.target || e; element = current || e.target || e;
// NOTE: used to be if no popup/panel, use data-ref or data-url else if // NOTE: used to be if no popup/panel, use data-ref or data-url else if
// no href use data-url else href. Should work if element (button) does // no href use data-url else href. Should work if element (button) does
...@@ -4982,7 +4982,8 @@ ...@@ -4982,7 +4982,8 @@
"gadget": document.getElementById(id) "gadget": document.getElementById(id)
}; };
return util.mergeObject({ return util.mergeObject(
{
"form": response.gadget.getElementsByTagName("form")[0], "form": response.gadget.getElementsByTagName("form")[0],
"state": (response.gadget || {}).state "state": (response.gadget || {}).state
}, },
...@@ -5018,15 +5019,15 @@ ...@@ -5018,15 +5019,15 @@
* @param {object} data Data passed along with this (JQM) event * @param {object} data Data passed along with this (JQM) event
*/ */
app.parsePage = function (e, data) { app.parsePage = function (e, data) {
var page, base, create, config, raw_url, handle, clean_url, parsed_url, var page, base, config, raw_url, handle, clean_url, parsed_url, first;
destination, first;
if (data) { if (data) {
// update page title on backwards transition to the first page (still // update page title on backwards transition to the first page (still
// is in DOM, so no new page created, so no title update...) // is in DOM, so no new page created, so no title update...)
// TODO: not bulletproof i18n handling... we expect i18n to be defined // TODO: not bulletproof i18n handling... we expect i18n to be defined
if (typeof data.toPage === "object") { if (typeof data.toPage === "object") {
if ($.mobile.firstPage[0].getAttribute("data-url") === data.toPage[0].getAttribute("data-url")) { if ($.mobile.firstPage[0].getAttribute("data-url") ===
data.toPage[0].getAttribute("data-url")) {
app.setPageTitle("global_dict.home"); app.setPageTitle("global_dict.home");
} }
} }
...@@ -5052,7 +5053,8 @@ ...@@ -5052,7 +5053,8 @@
if (e) { if (e) {
page = util.getPage(raw_url.split("#").pop()); page = util.getPage(raw_url.split("#").pop());
base = page ? page.getAttribute("data-external-page") : null; base = page ? page.getAttribute("data-external-page") : null;
first = $.mobile.firstPage[0].getAttribute("data-url") === config.data_url; first = $.mobile.firstPage[0].getAttribute("data-url") ===
config.data_url;
if (first || (page && base) || raw_url === $.mobile.getDocumentUrl() || if (first || (page && base) || raw_url === $.mobile.getDocumentUrl() ||
data.options.role === "popup") { data.options.role === "popup") {
...@@ -5146,7 +5148,7 @@ ...@@ -5146,7 +5148,7 @@
// panel close (since default does not work on dynamic content // panel close (since default does not work on dynamic content
// TODO: integrate this into action if there is no other way! // TODO: integrate this into action if there is no other way!
.on("click", "div.ui-panel a.ui-panel-close", function (e) { .on("click", "div.ui-panel a.ui-panel-close", function () {
$(this).closest("div.ui-panel").panel("close"); $(this).closest("div.ui-panel").panel("close");
}) })
...@@ -5188,13 +5190,13 @@ ...@@ -5188,13 +5190,13 @@
// popup content loading // popup content loading
.find(".ui-popup, .ui-panel") .find(".ui-popup, .ui-panel")
.on("popupbeforeposition panelopen", function (e) { .on("popupbeforeposition panelopen", function (e) {
factory.util.generateDynamicContents(app.parseAction(e)); factory.util.generateDynamicContents(app.parseAction(e));
}); });
// remove focus from active elements on key-tab switches // remove focus from active elements on key-tab switches
window.onblur = function () { window.onblur = function () {
document.activeElement.blur(); document.activeElement.blur();
}; };
}; };
...@@ -5255,7 +5257,7 @@ ...@@ -5255,7 +5257,7 @@
}, },
//customValidations: util.declareJS(), //customValidations: util.declareJS(),
form: { form: {
onInvalid: function (error) { onInvalid: function () {
util.return_out(); util.return_out();
} }
} }
...@@ -5295,10 +5297,11 @@ ...@@ -5295,10 +5297,11 @@
**/ **/
util.format = function (str, spec) { util.format = function (str, spec) {
switch (spec.type) { switch (spec.type) {
case "integer": case "integer":
if (!isNaN(parseFloat(str)) && isFinite(str)) { if (!isNaN(parseFloat(str)) && isFinite(str)) {
return Math.round(str).toFixed(spec.digits); return Math.round(str).toFixed(spec.digits);
} }
return str;
} }
return str; return str;
}; };
...@@ -5332,7 +5335,7 @@ ...@@ -5332,7 +5335,7 @@
* @param {array} arr Path leading to a value * @param {array} arr Path leading to a value
* @return {string} value * @return {string} value
**/ **/
util.fetchByArray = function(obj, arr) { util.fetchByArray = function (obj, arr) {
var n, key; var n, key;
for (n = 0; n < arr.length; n += 1) { for (n = 0; n < arr.length; n += 1) {
...@@ -5644,7 +5647,7 @@ ...@@ -5644,7 +5647,7 @@
* @return {object} promise * @return {object} promise
**/ **/
app.content.set = function (content_dict, url_dict, create, purge) { app.content.set = function (content_dict, url_dict, create, purge) {
var pass, set_url_dict, set_content_dict; var pass;
if (!content_dict) { if (!content_dict) {
util.loader("", "status_dict.parse_error", "ban-circle"); util.loader("", "status_dict.parse_error", "ban-circle");
...@@ -5667,19 +5670,20 @@ ...@@ -5667,19 +5670,20 @@
// and go // and go
return storage.fetchConfigAttachment({ return storage.fetchConfigAttachment({
"storage": app.storage_dict.settings, "storage": app.storage_dict.settings,
"file": pass.url_dict.href ? app.storage_dict.property_dict.name_dict.gadgets : "file": (pass.url_dict.href ?
app.storage_dict.property_dict.name_dict.settings, app.storage_dict.property_dict.name_dict.gadgets :
app.storage_dict.property_dict.name_dict.settings),
"attachment": pass.url_dict.href || "attachment": pass.url_dict.href ||
app.storage_dict.property_dict.name_dict.configuration, app.storage_dict.property_dict.name_dict.configuration,
"pass": pass "pass": pass
}) })
.then(app.content.fields) .then(app.content.fields)
.then(app.content.test) .then(app.content.test)
.then(app.content.sample) .then(app.content.sample)
.then(app.content.total) .then(app.content.total)
.then(app.content.query) .then(app.content.query)
.then(app.content.make) .then(app.content.make)
.fail(app.util.error); .fail(app.util.error);
}; };
...@@ -5732,15 +5736,16 @@ ...@@ -5732,15 +5736,16 @@
// try to get 1 record for this portal_type // try to get 1 record for this portal_type
if (app.storage_dict.property_dict.allow_sample_data && pass.grant && if (app.storage_dict.property_dict.allow_sample_data && pass.grant &&
(pass.create !== false || pass.purge) && pass.config_dict.initial_query (pass.create !== false || pass.purge) &&
) { pass.config_dict.initial_query
) {
return storage.fetch({ return storage.fetch({
"pass": pass, "pass": pass,
"storage": "items", "storage": "items",
"query": storage.parseQuery( "query": storage.parseQuery(
{"limit": [0, 1]}, {"limit": [0, 1]},
pass.config_dict.portal_type_source pass.config_dict.portal_type_source
), )
}); });
} }
} }
...@@ -5766,43 +5771,47 @@ ...@@ -5766,43 +5771,47 @@
{"url": "data/" + pass.config_dict.portal_type_title + "_sample.json"} {"url": "data/" + pass.config_dict.portal_type_title + "_sample.json"}
) )
// STORE SAMPLE DATA HERE! // STORE SAMPLE DATA HERE!
.then(function (e) { .then(function (e) {
var response, i, len, promise_list, record; var response, i, len, promise_list, record;
response = util.parse(e.target.responseText); response = util.parse(e.target.responseText);
len = response.length; len = response.length;
promise_list = []; promise_list = [];
// NOTE: no more need to test for and fetch fields, because they // NOTE: no more need to test for and fetch fields, because they
// will be defined, as this method is only called inside the // will be defined, as this method is only called inside the
// content-loop. // content-loop.
// NOTE: do we still validate against field_dict? // NOTE: do we still validate against field_dict?
for (i = 0; i < len; i += 1) { for (i = 0; i < len; i += 1) {
record = response[i]; record = response[i];
record.portal_type = pass.config_dict.portal_type_source; record.portal_type = pass.config_dict.portal_type_source;
promise_list[i] = storage.write({ promise_list[i] = storage.write({
"sample_data": record, "sample_data": record,
"sample_store": true, "sample_store": true,
"state": {} "state": {}
}); });
} }
return RSVP.all(promise_list) return RSVP.all(promise_list)
.then(function(response_list) { .then(function (response_list) {
if (!response_list[0]) { if (!response_list[0]) {
app.util.loader("", "status_dict.internal_error", "ban-circle"); app.util.loader(
} else { "",
app.util.loader("", "status_dict.success", "check"); "status_dict.internal_error",
} "ban-circle"
// just return pass and continue );
return { } else {
"pass": pass app.util.loader("", "status_dict.success", "check");
}; }
}) // just return pass and continue
.fail(app.util.error); return {
}) "pass": pass
.fail(app.util.error); };
})
.fail(app.util.error);
})
.fail(app.util.error);
} }
} }
return { return {
...@@ -5874,10 +5883,10 @@ ...@@ -5874,10 +5883,10 @@
// TODO: get ALL RECORDS matching query (and make this if disappear ...) // TODO: get ALL RECORDS matching query (and make this if disappear ...)
if ((!app.storage_dict.property_dict.skip_total_records && if ((!app.storage_dict.property_dict.skip_total_records &&
pass.config_dict.skip_total_records !== true) && pass.config_dict.skip_total_records !== true) &&
(pass.grant || (pass.url_dict.mode === "new" || pass.purge) && ((pass.grant || (pass.url_dict.mode === "new" || pass.purge)) &&
(pass.state && pass.state.query._id === undefined) && (pass.state && pass.state.query._id === undefined) &&
pass.config_dict.initial_query) pass.config_dict.initial_query)
) { ) {
// reset limit from sampling [0,1] and store query // reset limit from sampling [0,1] and store query
pass.state.query.limit = []; pass.state.query.limit = [];
app.util.loader("", "status_dict.loading_total"); app.util.loader("", "status_dict.loading_total");
...@@ -5911,7 +5920,8 @@ ...@@ -5911,7 +5920,8 @@
// fetch full documents (unless force_field_definitions is set) // fetch full documents (unless force_field_definitions is set)
if (pass.create === false) { if (pass.create === false) {
if (!storage || (storage && !app.storage_dict.property_dict.force_field_definitions)) { if (!storage || (storage &&
!app.storage_dict.property_dict.force_field_definitions)) {
pass.state.query.include_docs = true; pass.state.query.include_docs = true;
} }
pass.state.query.limit = pass.store_limit; pass.state.query.limit = pass.store_limit;
...@@ -5919,9 +5929,10 @@ ...@@ -5919,9 +5929,10 @@
// only fetch columns based on gadget configuration // only fetch columns based on gadget configuration
} else { } else {
if (pass.data_dict.field_dict && if (pass.data_dict.field_dict &&
storage && app.storage_dict.property_dict.force_field_definitions && storage &&
app.storage_dict.property_dict.force_field_definitions &&
pass.config_dict.scheme pass.config_dict.scheme
) { ) {
pass.data_dict.field_list = storage.makeSelectList( pass.data_dict.field_list = storage.makeSelectList(
pass.config_dict.scheme pass.config_dict.scheme
); );
...@@ -5939,7 +5950,7 @@ ...@@ -5939,7 +5950,7 @@
// get items/item // get items/item
if (pass.grant && if (pass.grant &&
(pass.url_dict.mode !== "new" || !pass.config_dict.initial_query) (pass.url_dict.mode !== "new" || !pass.config_dict.initial_query)
) { ) {
app.util.loader("", "status_dict.loading_set"); app.util.loader("", "status_dict.loading_set");
return storage.fetch({ return storage.fetch({
"storage": "items", "storage": "items",
...@@ -6009,22 +6020,24 @@ ...@@ -6009,22 +6020,24 @@
} }
switch (route) { switch (route) {
case "input": case "input":
case "select": case "select":
case "textarea": case "textarea":
case "force_form_element": case "force_form_element":
generator = {"fragment": factory.widget.formElement(pass.content_dict)}; generator = {
break; "fragment": factory.widget.formElement(pass.content_dict)
case "divider": };
case "item": break;
generator = {"fragment": pass.content_dict.content}; case "divider":
break; case "item":
case (undefined): generator = {"fragment": pass.content_dict.content};
generator = {"fragment": document.createDocumentFragment()}; break;
break; case undefined:
default: generator = {"fragment": document.createDocumentFragment()};
generator = {"fragment": factory.element(pass.content_dict)}; break;
break; default:
generator = {"fragment": factory.element(pass.content_dict)};
break;
} }
} }
} }
...@@ -6101,7 +6114,7 @@ ...@@ -6101,7 +6114,7 @@
// add caption // add caption
if (quirk_dict.caption) { if (quirk_dict.caption) {
kids.push({ kids.push({
"generate":"widget", "generate": "widget",
"type": "controlbar", "type": "controlbar",
"property_dict": {"slot": quirk_dict.caption.slot || 1}, "property_dict": {"slot": quirk_dict.caption.slot || 1},
"children": [{ "children": [{
...@@ -6121,16 +6134,16 @@ ...@@ -6121,16 +6134,16 @@
} }
// add popup (local/global) // add popup (local/global)
switch(quirk_dict.need_popup) { switch (quirk_dict.need_popup) {
case "local": case "local":
if (util.getPage().querySelectorAll("div.local_popup") === null) { if (util.getPage().querySelectorAll("div.local_popup") === null) {
target.appendChild(factory.widget.popup({})); target.appendChild(factory.widget.popup({}));
} }
break; break;
case "global": case "global":
if (document.getElementById("global_popup") === null) { if (document.getElementById("global_popup") === null) {
document.documentElement.appendChild(factory.widget.popup({})); document.documentElement.appendChild(factory.widget.popup({}));
} }
break; break;
} }
} }
...@@ -6159,7 +6172,8 @@ ...@@ -6159,7 +6172,8 @@
kid.direct.href = kid.direct.href.replace("__id__", is_id); kid.direct.href = kid.direct.href.replace("__id__", is_id);
} else if (kid.property_dict) { } else if (kid.property_dict) {
// continue inheriting to all widgets // continue inheriting to all widgets
kid.property_dict.item_identifier = window.encodeURIComponent(is_id); kid.property_dict.item_identifier =
window.encodeURIComponent(is_id);
} }
} }
...@@ -6187,11 +6201,11 @@ ...@@ -6187,11 +6201,11 @@
if (kid.logic && kid.logic.setParam) { if (kid.logic && kid.logic.setParam) {
kid.direct.href += kid.direct.href.indexOf("?") > 0 ? "&" : "?"; kid.direct.href += kid.direct.href.indexOf("?") > 0 ? "&" : "?";
switch (kid.logic.setParam[1]) { switch (kid.logic.setParam[1]) {
case "location": case "location":
target = window.location.origin + target = window.location.origin +
window.location.pathname + window.location.pathname +
window.location.hash.split("?")[0]; window.location.hash.split("?")[0];
break; break;
} }
kid.direct.href += window.encodeURIComponent(kid.logic.setParam[0]) + kid.direct.href += window.encodeURIComponent(kid.logic.setParam[0]) +
"=" + window.encodeURIComponent(target); "=" + window.encodeURIComponent(target);
...@@ -6213,16 +6227,12 @@ ...@@ -6213,16 +6227,12 @@
// reference // reference
if (quirk_dict.reference) { if (quirk_dict.reference) {
switch (true) { if (!!kid.attribute) {
case !!kid.attributes: kid.attributes["data-reference"] = quirk_dict.reference;
kid.attributes["data-reference"] = quirk_dict.reference; } else if (!!kid.property_dict) {
break; kid.property_dict.reference = quirk_dict.reference;
case !!kid.property_dict: } else {
kid.property_dict.reference = quirk_dict.reference; kid.reference = quirk_dict.reference;
break;
default:
kid.reference = quirk_dict.reference;
break;
} }
} }
...@@ -6236,11 +6246,11 @@ ...@@ -6236,11 +6246,11 @@
// go-go-gadget-o-promise... // go-go-gadget-o-promise...
promise_list[i] = map.element(kid, wrapper, i) promise_list[i] = map.element(kid, wrapper, i)
.then(function(mapping) { .then(function (mapping) {
if (mapping.inherit) { if (mapping.inherit) {
return app.content.set({}, mapping); return app.content.set({}, mapping);
} }
return app.content.set(mapping) return app.content.set(mapping);
}) })
.fail(util.error); .fail(util.error);
} }
...@@ -6249,11 +6259,11 @@ ...@@ -6249,11 +6259,11 @@
return RSVP.all(promise_list) return RSVP.all(promise_list)
.then(function (response_list) { .then(function (response_list) {
var k, l, target, wrapper_selector, response, content; var k, l, done_target, wrapper_selector, response, content;
for (k = 0, l = response_list.length; k < l; k += 1) { for (k = 0, l = response_list.length; k < l; k += 1) {
response = response_list[k]; response = response_list[k];
target = undefined; done_target = undefined;
if (response) { if (response) {
// generate target for and append response // generate target for and append response
// NOTE: wrapper.spec is used for header only. // NOTE: wrapper.spec is used for header only.
...@@ -6268,9 +6278,10 @@ ...@@ -6268,9 +6278,10 @@
); );
// NOTE: wrapper_selector will return a fragment (set to // NOTE: wrapper_selector will return a fragment (set to
// first/last-ElementChild or a DOM node // first/last-ElementChild or a DOM node
target = wrapper_selector[wrapper.target_selector + "ElementChild"] done_target =
wrapper_selector[wrapper.target_selector + "ElementChild"]
|| wrapper_selector; || wrapper_selector;
target.appendChild(response); done_target.appendChild(response);
} }
content = wrapper_selector || response; content = wrapper_selector || response;
...@@ -6289,14 +6300,18 @@ ...@@ -6289,14 +6300,18 @@
if (util.testForString("ui-footer", last.className)) { if (util.testForString("ui-footer", last.className)) {
document.body.insertBefore(wrapper.fragment, last); document.body.insertBefore(wrapper.fragment, last);
} else { } else {
document.body.insertBefore(content, document.body.children[0]); document.body.insertBefore(
content,
document.body.children[0]
);
} }
} else { } else {
// TODO: terrible. what about footer/header/popup. // TODO: terrible. what about footer/header/popup.
if (content.querySelector("div.panel")) { if (content.querySelector("div.panel")) {
wrapper.fragment.appendChild(content); wrapper.fragment.appendChild(content);
} else { } else {
(wrapper.child_selector || wrapper.fragment).appendChild(content); (wrapper.child_selector || wrapper.fragment)
.appendChild(content);
} }
} }
} }
...@@ -6321,7 +6336,7 @@ ...@@ -6321,7 +6336,7 @@
} }
//and add new dynamic content //and add new dynamic content
update_target.appendChild(wrapper.fragment) update_target.appendChild(wrapper.fragment);
// CREATE // CREATE
} else { } else {
selector = wrapper.fragment.firstElementChild || wrapper.fragment; selector = wrapper.fragment.firstElementChild || wrapper.fragment;
...@@ -6339,7 +6354,7 @@ ...@@ -6339,7 +6354,7 @@
} }
// tuck to gadget // tuck to gadget
// WARNING: this should use data(), it is BAD practice to store like this // WARNING: this should use data(), it BAD to store like this
selector.state = pass.state; selector.state = pass.state;
// not auth, no mojo! // not auth, no mojo!
...@@ -6474,7 +6489,7 @@ ...@@ -6474,7 +6489,7 @@
level = spec.layout_level || 0; level = spec.layout_level || 0;
core = spec.link_core || (spec.fragment_list ? core = spec.link_core || (spec.fragment_list ?
spec.fragment_list.slice(0, level + 1).join("/") : ""); spec.fragment_list.slice(0, level + 1).join("/") : "");
return ("#" + core + "/" + window.encodeURIComponent(id) return ("#" + core + "/" + window.encodeURIComponent(id)
); );
...@@ -6599,7 +6614,7 @@ ...@@ -6599,7 +6614,7 @@
**/ **/
app.init.config = function (content_dict) { app.init.config = function (content_dict) {
var i, j, arr, promise_list, len, feature, feature_len, name, dict, var i, j, arr, promise_list, len, feature, feature_len, name, dict,
set, child_len, type, nav, language, target, initializer, solver; set, type, nav, language, target, initializer;
arr = app.empty_array; arr = app.empty_array;
promise_list = []; promise_list = [];
...@@ -6611,11 +6626,16 @@ ...@@ -6611,11 +6626,16 @@
// test support // test support
if (app.init.testSupport(feature.modernizr || [])) { if (app.init.testSupport(feature.modernizr || [])) {
set = feature.set_on;
feature_len = (feature.scheme || arr).length; feature_len = (feature.scheme || arr).length;
type = feature.type; type = feature.type;
initializer = feature.initializer; initializer = feature.initializer;
target = (set ? app[feature.set_on] = {} : undefined) || app; set = feature.set_on;
if (set) {
target = app[feature.set_on] = {};
} else {
target = app;
}
//target = (set ? app[set] = {} : undefined) || app;
// merge properties on target // merge properties on target
target.property_dict = util.mergeObject( target.property_dict = util.mergeObject(
...@@ -6633,25 +6653,26 @@ ...@@ -6633,25 +6653,26 @@
// TODO: Force browser language for i18n - not generic, remove // TODO: Force browser language for i18n - not generic, remove
switch (feature.handle) { switch (feature.handle) {
case "language": case "language":
nav = window.navigator; nav = window.navigator;
language = nav.userLanguage || nav.language; language = nav.userLanguage || nav.language;
if (language && target.property_dict.use_browser_language) { if (language && target.property_dict.use_browser_language) {
dict.fallbackLng = dict.lng; dict.fallbackLng = dict.lng;
dict.lng = language; dict.lng = language;
} }
break; break;
} }
// set promise and access to this module // set promise and access to this module
target[name] = promise_list[j] = initializer ? target[name] = promise_list[j] = initializer ?
window[type][feature.initializer](dict.property_dict) : window[type]; window[type][feature.initializer](dict.property_dict) :
window[type];
} }
} }
if ((feature.children || arr).length > 0) { if ((feature.children || arr).length > 0) {
promise_list[j + 1] = app.content.set(feature); promise_list[j + 1] = app.content.set(feature);
}; }
} }
return RSVP.all(promise_list); return RSVP.all(promise_list);
}; };
......
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