[refactor] improve string handling
This commit is contained in:
parent
294914f380
commit
8bb24e7afd
|
@ -153,7 +153,7 @@ var autoSuggest = (function() {
|
|||
document.removeEventListener("keydown", bind.navigateResults, false);
|
||||
},
|
||||
clickOut: function(event) {
|
||||
if (!(event.target.classList.contains("auto-suggest")) &&!(event.target.classList.contains("auto-suggest-list")) && !(event.target.classList.contains("auto-suggest-input"))) {
|
||||
if (!(event.target.classList.contains("auto-suggest")) && !(event.target.classList.contains("auto-suggest-list")) && !(event.target.classList.contains("auto-suggest-input"))) {
|
||||
render.close();
|
||||
};
|
||||
}
|
||||
|
@ -239,29 +239,29 @@ var autoSuggest = (function() {
|
|||
};
|
||||
|
||||
render.suggestItems = function() {
|
||||
var searchTerm = _currentInputOptions.input.value.replace(/^\s+/, "").replace(/\s+$/, "").toLowerCase();
|
||||
var searchTerm = helper.trimString(_currentInputOptions.input.value);
|
||||
var action = {
|
||||
fontawesomeIcon: function() {
|
||||
if (searchTerm == "" || searchTerm == undefined) {
|
||||
return fontawesome.icons;
|
||||
} else {
|
||||
if (helper.checkIfValidString(searchTerm)) {
|
||||
return fontawesome.icons.filter(function(item) {
|
||||
var match = false;
|
||||
if (item.name.toLowerCase().includes(searchTerm) || item.label.toLowerCase().includes(searchTerm)) {
|
||||
if (item.name.toLowerCase().includes(searchTerm.toLowerCase()) || item.label.toLowerCase().includes(searchTerm.toLowerCase())) {
|
||||
match = true;
|
||||
};
|
||||
item.search.forEach(function(item, index) {
|
||||
if (item.toLowerCase().includes(searchTerm)) {
|
||||
if (item.toLowerCase().includes(searchTerm.toLowerCase())) {
|
||||
match = true;
|
||||
};
|
||||
});
|
||||
item.styles.forEach(function(item, index) {
|
||||
if (item.toLowerCase().includes(searchTerm)) {
|
||||
if (item.toLowerCase().includes(searchTerm.toLowerCase())) {
|
||||
match = true;
|
||||
};
|
||||
});
|
||||
return match;
|
||||
});
|
||||
} else {
|
||||
return fontawesome.icons;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -172,7 +172,7 @@ var background = (function() {
|
|||
|
||||
render.feedback = {
|
||||
init: function() {
|
||||
if (helper.checkValueString(state.get.current().background.image.file.name)) {
|
||||
if (helper.checkIfValidString(state.get.current().background.image.file.name)) {
|
||||
render.feedback.current();
|
||||
} else {
|
||||
render.feedback.empty();
|
||||
|
|
|
@ -112,7 +112,7 @@ var clock = (function() {
|
|||
};
|
||||
if (state.get.current().header.clock.separator.show) {
|
||||
var separatorCharacter;
|
||||
if (helper.checkValueString(state.get.current().header.clock.separator.text)) {
|
||||
if (helper.checkIfValidString(state.get.current().header.clock.separator.text)) {
|
||||
separatorCharacter = helper.trimString(state.get.current().header.clock.separator.text);
|
||||
} else {
|
||||
separatorCharacter = ":";
|
||||
|
|
|
@ -129,7 +129,7 @@ var date = (function() {
|
|||
};
|
||||
if (state.get.current().header.date.separator.show) {
|
||||
var separatorCharacter;
|
||||
if (helper.checkValueString(state.get.current().header.date.separator.text)) {
|
||||
if (helper.checkIfValidString(state.get.current().header.date.separator.text)) {
|
||||
separatorCharacter = helper.trimString(state.get.current().header.date.separator.text);
|
||||
} else {
|
||||
separatorCharacter = ":";
|
||||
|
|
|
@ -37,7 +37,7 @@ var greeting = (function() {
|
|||
}
|
||||
};
|
||||
var string = message[state.get.current().header.greeting.type]();
|
||||
if (helper.checkValueString(state.get.current().header.greeting.name)) {
|
||||
if (helper.checkIfValidString(state.get.current().header.greeting.name)) {
|
||||
string = string + ", " + helper.trimString(state.get.current().header.greeting.name)
|
||||
};
|
||||
var greetingItem = helper.node("span|class:greeting-item");
|
||||
|
|
|
@ -373,7 +373,7 @@ var header = (function() {
|
|||
var headerSearchBody = helper.node("div|class:search-wrapper");
|
||||
var form = helper.node("form|class:search,action,method:get");
|
||||
var searchInput;
|
||||
if (helper.checkValueString(state.get.current().header.search.engine.custom.queryName)) {
|
||||
if (helper.checkIfValidString(state.get.current().header.search.engine.custom.queryName)) {
|
||||
searchInput = helper.node("input|class:search-input,type:search,placeholder:Find or Search,name:" + helper.trimString(state.get.current().header.search.engine.custom.queryName) + ",autocomplete:off,autocorrect:off,autocapitalize:off,spellcheck:false,tabindex:1");
|
||||
} else {
|
||||
searchInput = helper.node("input|class:search-input,type:search,placeholder:Find or Search,name:q,autocomplete:off,autocorrect:off,autocapitalize:off,spellcheck:false,tabindex:1");
|
||||
|
|
|
@ -767,7 +767,7 @@ var helper = (function() {
|
|||
};
|
||||
};
|
||||
|
||||
var checkValueString = function(value) {
|
||||
var checkIfValidString = function(value) {
|
||||
var result = false;
|
||||
if (typeof value == "string") {
|
||||
value = value.trim().replace(/\s/g, "");
|
||||
|
@ -812,7 +812,7 @@ var helper = (function() {
|
|||
isJsonString: isJsonString,
|
||||
isHexNumber: isHexNumber,
|
||||
convertColor: convertColor,
|
||||
checkValueString: checkValueString,
|
||||
checkIfValidString: checkIfValidString,
|
||||
trimString: trimString
|
||||
};
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ var layout = (function() {
|
|||
|
||||
render.title = function() {
|
||||
var title = helper.e("title");
|
||||
if (helper.checkValueString(state.get.current().layout.title)) {
|
||||
if (helper.checkIfValidString(state.get.current().layout.title)) {
|
||||
title.textContent = helper.trimString(state.get.current().layout.title);
|
||||
} else {
|
||||
title.textContent = "New tab";
|
||||
|
|
|
@ -709,7 +709,7 @@ var link = (function() {
|
|||
});
|
||||
|
||||
groupHeader.appendChild(groupHeaderItemControl);
|
||||
if (stagedGroup.group.name.show && helper.checkValueString(stagedGroup.group.name.text)) {
|
||||
if (stagedGroup.group.name.show && helper.checkIfValidString(stagedGroup.group.name.text)) {
|
||||
helper.addClass(groupHeader, "group-header-name");
|
||||
groupHeader.appendChild(groupHeaderItemName);
|
||||
};
|
||||
|
@ -916,7 +916,7 @@ var link = (function() {
|
|||
value: "link-item"
|
||||
}]
|
||||
};
|
||||
if (stagedLink.link.accent.by == "custom" || stagedLink.link.color.by == "custom" || helper.checkValueString(stagedLink.link.image)) {
|
||||
if (stagedLink.link.accent.by == "custom" || stagedLink.link.color.by == "custom" || helper.checkIfValidString(stagedLink.link.image)) {
|
||||
linkItemOptions.attr.push({
|
||||
key: "style",
|
||||
value: ""
|
||||
|
@ -940,7 +940,7 @@ var link = (function() {
|
|||
"--link-item-color: " + stagedLink.link.color.rgb.r + ", " + stagedLink.link.color.rgb.g + ", " + stagedLink.link.color.rgb.b + ";" +
|
||||
"--link-item-color-focus-hover: " + stagedLink.link.color.rgb.r + ", " + stagedLink.link.color.rgb.g + ", " + stagedLink.link.color.rgb.b + ";";
|
||||
};
|
||||
if (helper.checkValueString(stagedLink.link.image)) {
|
||||
if (helper.checkIfValidString(stagedLink.link.image)) {
|
||||
linkItemOptions.attr[1].value = linkItemOptions.attr[1].value + "--link-image-url: url(" + helper.trimString(stagedLink.link.image) + ");"
|
||||
};
|
||||
};
|
||||
|
@ -999,7 +999,7 @@ var link = (function() {
|
|||
};
|
||||
|
||||
var linkDisplayName;
|
||||
if (helper.checkValueString(stagedLink.link.name)) {
|
||||
if (helper.checkIfValidString(stagedLink.link.name)) {
|
||||
linkDisplayName = helper.node("p:" + helper.trimString(stagedLink.link.name) + "|class:link-display-name");
|
||||
} else {
|
||||
linkDisplayName = helper.node("p|class:link-display-name");
|
||||
|
@ -1045,11 +1045,11 @@ var link = (function() {
|
|||
linkDisplay.appendChild(linkDisplayVisual);
|
||||
};
|
||||
|
||||
if (helper.checkValueString(stagedLink.link.name)) {
|
||||
if (helper.checkIfValidString(stagedLink.link.name)) {
|
||||
linkDisplay.appendChild(linkDisplayName);
|
||||
};
|
||||
|
||||
if (helper.checkValueString(stagedLink.link.image)) {
|
||||
if (helper.checkIfValidString(stagedLink.link.image)) {
|
||||
linkPanelFront.appendChild(linkImage);
|
||||
};
|
||||
linkPanelFront.appendChild(linkDisplay);
|
||||
|
@ -1556,10 +1556,10 @@ var link = (function() {
|
|||
if (bookmarks.get().length > 0) {
|
||||
bookmarks.get().forEach(function(arrayItem, index) {
|
||||
var name;
|
||||
if (arrayItem.name.text == null || arrayItem.name.text == "") {
|
||||
name = "Unnamed group " + (index + 1);
|
||||
} else {
|
||||
if (helper.checkIfValidString(arrayItem.name.text)) {
|
||||
name = arrayItem.name.text;
|
||||
} else {
|
||||
name = "Unnamed group " + (index + 1);
|
||||
};
|
||||
var option = helper.makeNode({
|
||||
tag: "option",
|
||||
|
@ -2900,7 +2900,7 @@ var link = (function() {
|
|||
useStagedLink: true
|
||||
});
|
||||
var heading;
|
||||
if (helper.checkValueString(stagedLink.link.name)) {
|
||||
if (helper.checkIfValidString(stagedLink.link.name)) {
|
||||
heading = "Edit " + stagedLink.link.name;
|
||||
} else {
|
||||
heading = "Edit unnamed bookmark";
|
||||
|
@ -2954,10 +2954,10 @@ var link = (function() {
|
|||
useStagedGroup: true
|
||||
});
|
||||
var heading;
|
||||
if (stagedGroup.group.name.text == null || stagedGroup.group.name.text == "") {
|
||||
heading = "Edit unnamed group " + (stagedGroup.position.origin + 1);
|
||||
} else {
|
||||
if (helper.checkIfValidString(stagedGroup.group.name.text)) {
|
||||
heading = "Edit " + stagedGroup.group.name.text;
|
||||
} else {
|
||||
heading = "Edit unnamed group " + (stagedGroup.position.origin + 1);
|
||||
};
|
||||
var successAction = function() {
|
||||
var copyStagedGroup = JSON.parse(JSON.stringify(stagedGroup));
|
||||
|
@ -3005,7 +3005,7 @@ var link = (function() {
|
|||
stagedLink.link = JSON.parse(JSON.stringify(copyStagedLink.link));
|
||||
stagedLink.position = JSON.parse(JSON.stringify(copyStagedLink.position));
|
||||
var heading;
|
||||
if (helper.checkValueString(stagedLink.link.name)) {
|
||||
if (helper.checkIfValidString(stagedLink.link.name)) {
|
||||
heading = "Remove " + stagedLink.link.name;
|
||||
} else {
|
||||
heading = "Remove unnamed bookmark";
|
||||
|
@ -3052,10 +3052,10 @@ var link = (function() {
|
|||
stagedGroup.group = JSON.parse(JSON.stringify(copyStagedGroup.group));
|
||||
stagedGroup.position = JSON.parse(JSON.stringify(copyStagedGroup.position));
|
||||
var heading;
|
||||
if (stagedGroup.group.name.text == null || stagedGroup.group.name.text == "") {
|
||||
heading = "Remove unnamed group " + (stagedGroup.position.origin + 1);
|
||||
} else {
|
||||
if (helper.checkIfValidString(stagedGroup.group.name.text)) {
|
||||
heading = "Remove " + stagedGroup.group.name.text;
|
||||
} else {
|
||||
heading = "Remove unnamed group " + (stagedGroup.position.origin + 1);
|
||||
};
|
||||
var successAction = function() {
|
||||
var copyStagedGroup = JSON.parse(JSON.stringify(stagedGroup));
|
||||
|
|
|
@ -144,7 +144,7 @@ var search = (function() {
|
|||
|
||||
render.check = function() {
|
||||
var searchInput = helper.e(".search-input");
|
||||
if (helper.checkValueString(searchInput.value)) {
|
||||
if (helper.checkIfValidString(searchInput.value)) {
|
||||
mod.searching.open();
|
||||
} else {
|
||||
mod.searching.close();
|
||||
|
|
|
@ -2298,11 +2298,11 @@ var theme = (function() {
|
|||
mod.preset.all.forEach(function(arrayItem, index) {
|
||||
var displayFont = arrayItem.font.display.name + ":" + arrayItem.font.display.weight;
|
||||
var uiFont = arrayItem.font.ui.name + ":" + arrayItem.font.ui.weight;
|
||||
if (helper.checkValueString(arrayItem.font.display.name) && !allPresetFonts.includes(displayFont)) {
|
||||
if (helper.checkIfValidString(arrayItem.font.display.name) && !allPresetFonts.includes(displayFont)) {
|
||||
mod.font.loaded.push(arrayItem.font.display.name);
|
||||
allPresetFonts.push(displayFont);
|
||||
};
|
||||
if (helper.checkValueString(arrayItem.font.ui.name) && !allPresetFonts.includes(uiFont)) {
|
||||
if (helper.checkIfValidString(arrayItem.font.ui.name) && !allPresetFonts.includes(uiFont)) {
|
||||
mod.font.loaded.push(arrayItem.font.ui.name);
|
||||
allPresetFonts.push(uiFont);
|
||||
};
|
||||
|
@ -2316,7 +2316,7 @@ var theme = (function() {
|
|||
custom: {
|
||||
display: function() {
|
||||
var displayFont = helper.trimString(state.get.current().theme.font.display.name);
|
||||
if (!mod.font.loaded.includes(displayFont) && helper.checkValueString(displayFont)) {
|
||||
if (!mod.font.loaded.includes(displayFont) && helper.checkIfValidString(displayFont)) {
|
||||
mod.font.loaded.push(displayFont);
|
||||
WebFont.load({
|
||||
google: {
|
||||
|
@ -2328,7 +2328,7 @@ var theme = (function() {
|
|||
},
|
||||
ui: function() {
|
||||
var uiFont = helper.trimString(state.get.current().theme.font.ui.name);
|
||||
if (!mod.font.loaded.includes(uiFont) && helper.checkValueString(uiFont)) {
|
||||
if (!mod.font.loaded.includes(uiFont) && helper.checkIfValidString(uiFont)) {
|
||||
mod.font.loaded.push(uiFont);
|
||||
WebFont.load({
|
||||
google: {
|
||||
|
@ -2353,7 +2353,7 @@ var theme = (function() {
|
|||
display: {
|
||||
name: function() {
|
||||
var html = helper.e("html");
|
||||
if (helper.checkValueString(state.get.current().theme.font.display.name)) {
|
||||
if (helper.checkIfValidString(state.get.current().theme.font.display.name)) {
|
||||
html.style.setProperty("--theme-font-display-name", "\"" + helper.trimString(state.get.current().theme.font.display.name) + "\", \"Fjalla One\", sans-serif");
|
||||
} else {
|
||||
html.style.removeProperty("--theme-font-display-name");
|
||||
|
@ -2372,7 +2372,7 @@ var theme = (function() {
|
|||
ui: {
|
||||
name: function() {
|
||||
var html = helper.e("html");
|
||||
if (helper.checkValueString(state.get.current().theme.font.ui.name)) {
|
||||
if (helper.checkIfValidString(state.get.current().theme.font.ui.name)) {
|
||||
html.style.setProperty("--theme-font-ui-name", "\"" + helper.trimString(state.get.current().theme.font.ui.name) + "\", \"Open Sans\", sans-serif");
|
||||
} else {
|
||||
html.style.removeProperty("--theme-font-ui-name");
|
||||
|
@ -2456,7 +2456,7 @@ var theme = (function() {
|
|||
themePresetPreview.style.setProperty("--theme-preset-accent", arrayItem.accent.rgb.r + ", " + arrayItem.accent.rgb.g + ", " + arrayItem.accent.rgb.b);
|
||||
themePresetPreview.appendChild(themePresetAccent);
|
||||
|
||||
if (helper.checkValueString(arrayItem.name)) {
|
||||
if (helper.checkIfValidString(arrayItem.name)) {
|
||||
var themePresetName = helper.node("span:" + arrayItem.name + "|class:theme-preset-name");
|
||||
themePresetPreview.appendChild(themePresetName);
|
||||
};
|
||||
|
@ -2553,7 +2553,7 @@ var theme = (function() {
|
|||
var themeCustomAccent = helper.node("span|class:theme-custom-accent");
|
||||
themeCustomPreview.style.setProperty("--theme-custom-accent", arrayItem.accent.rgb.r + ", " + arrayItem.accent.rgb.g + ", " + arrayItem.accent.rgb.b);
|
||||
themeCustomPreview.appendChild(themeCustomAccent);
|
||||
if (helper.checkValueString(arrayItem.name)) {
|
||||
if (helper.checkIfValidString(arrayItem.name)) {
|
||||
themeCustomPreview.appendChild(helper.node("span:" + helper.trimString(arrayItem.name) + "|class:theme-custom-name"));
|
||||
};
|
||||
themeCustomButton.appendChild(themeCustomPreview);
|
||||
|
@ -2710,7 +2710,7 @@ var theme = (function() {
|
|||
useStagedTheme: true
|
||||
});
|
||||
var heading;
|
||||
if (helper.checkValueString(stagedThemeCustom.theme.name)) {
|
||||
if (helper.checkIfValidString(stagedThemeCustom.theme.name)) {
|
||||
heading = "Edit " + stagedThemeCustom.theme.name;
|
||||
} else {
|
||||
heading = "Edit unnamed theme";
|
||||
|
@ -2750,7 +2750,7 @@ var theme = (function() {
|
|||
stagedThemeCustom.position.index = JSON.parse(JSON.stringify(copyStagedThemeCustom.position.index));
|
||||
stagedThemeCustom.theme = JSON.parse(JSON.stringify(copyStagedThemeCustom.theme));
|
||||
var heading;
|
||||
if (helper.checkValueString(stagedThemeCustom.theme.name)) {
|
||||
if (helper.checkIfValidString(stagedThemeCustom.theme.name)) {
|
||||
heading = "Remove " + stagedThemeCustom.theme.name;
|
||||
} else {
|
||||
heading = "Remove unnamed theme";
|
||||
|
|
Loading…
Reference in New Issue