mirror of
https://github.com/zombieFox/nightTab.git
synced 2024-11-29 19:43:43 +01:00
[refactor] improve link string handling
This commit is contained in:
parent
65333c24b9
commit
b7c80d12aa
@ -786,6 +786,14 @@ var helper = (function() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var removeSpaces = function(value) {
|
||||||
|
if (typeof value == "string") {
|
||||||
|
return value.trim().replace(/\s/g, "");
|
||||||
|
} else {
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// exposed methods
|
// exposed methods
|
||||||
return {
|
return {
|
||||||
e: e,
|
e: e,
|
||||||
@ -813,7 +821,8 @@ var helper = (function() {
|
|||||||
isHexNumber: isHexNumber,
|
isHexNumber: isHexNumber,
|
||||||
convertColor: convertColor,
|
convertColor: convertColor,
|
||||||
checkIfValidString: checkIfValidString,
|
checkIfValidString: checkIfValidString,
|
||||||
trimString: trimString
|
trimString: trimString,
|
||||||
|
removeSpaces: removeSpaces
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -950,14 +950,22 @@ var link = (function() {
|
|||||||
attr: [{
|
attr: [{
|
||||||
key: "class",
|
key: "class",
|
||||||
value: "link-panel-front"
|
value: "link-panel-front"
|
||||||
}, {
|
|
||||||
key: "href",
|
|
||||||
value: stagedLink.link.url
|
|
||||||
}, {
|
}, {
|
||||||
key: "tabindex",
|
key: "tabindex",
|
||||||
value: 1
|
value: 1
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
if (helper.checkIfValidString(stagedLink.link.url)) {
|
||||||
|
linkPanelFrontOptions.attr.push({
|
||||||
|
key: "href",
|
||||||
|
value: helper.removeSpaces(stagedLink.link.url)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
linkPanelFrontOptions.attr.push({
|
||||||
|
key: "href",
|
||||||
|
value: "#"
|
||||||
|
});
|
||||||
|
};
|
||||||
if (state.get.current().link.item.newTab) {
|
if (state.get.current().link.item.newTab) {
|
||||||
linkPanelFrontOptions.attr.push({
|
linkPanelFrontOptions.attr.push({
|
||||||
key: "target",
|
key: "target",
|
||||||
@ -1016,21 +1024,21 @@ var link = (function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var linkUrl = helper.node("div|class:link-url");
|
var linkUrl = helper.node("div|class:link-url");
|
||||||
var url;
|
var urlDisplayString;
|
||||||
if (helper.checkIfValidString(stagedLink.link.url)) {
|
if (helper.checkIfValidString(stagedLink.link.url)) {
|
||||||
url = helper.trimString(stagedLink.link.url.replace(/^https?\:\/\//i, "").replace(/\/+$/, ""));
|
urlDisplayString = helper.removeSpaces(stagedLink.link.url.replace(/^https?\:\/\//i, "").replace(/\/+$/, ""));
|
||||||
} else {
|
} else {
|
||||||
url = "";
|
urlDisplayString = "";
|
||||||
};
|
};
|
||||||
var linkUrlText = helper.makeNode({
|
var linkUrlText = helper.makeNode({
|
||||||
tag: "p",
|
tag: "p",
|
||||||
text: url,
|
text: urlDisplayString,
|
||||||
attr: [{
|
attr: [{
|
||||||
key: "class",
|
key: "class",
|
||||||
value: "link-url-text"
|
value: "link-url-text"
|
||||||
}, {
|
}, {
|
||||||
key: "title",
|
key: "title",
|
||||||
value: url
|
value: urlDisplayString
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
var linkControl = helper.node("div|class:link-control");
|
var linkControl = helper.node("div|class:link-control");
|
||||||
@ -1077,7 +1085,9 @@ var link = (function() {
|
|||||||
linkControl.appendChild(linkEdit);
|
linkControl.appendChild(linkEdit);
|
||||||
linkRemove.appendChild(linkRemoveIcon);
|
linkRemove.appendChild(linkRemoveIcon);
|
||||||
linkControl.appendChild(linkRemove);
|
linkControl.appendChild(linkRemove);
|
||||||
linkUrl.appendChild(linkUrlText);
|
if (helper.checkIfValidString(stagedLink.link.url)) {
|
||||||
|
linkUrl.appendChild(linkUrlText);
|
||||||
|
};
|
||||||
linkPanelBack.appendChild(linkUrl);
|
linkPanelBack.appendChild(linkUrl);
|
||||||
linkPanelBack.appendChild(linkControl);
|
linkPanelBack.appendChild(linkControl);
|
||||||
linkItem.appendChild(linkPanelFront);
|
linkItem.appendChild(linkPanelFront);
|
||||||
|
Loading…
Reference in New Issue
Block a user