Skip to content

Commit 05bb5ac

Browse files
committed
[feature] add custom theme rename controls
1 parent 1a7b06f commit 05bb5ac

File tree

5 files changed

+93
-27
lines changed

5 files changed

+93
-27
lines changed

‎package-lock.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nighttab",
3-
"version": "4.12.1",
3+
"version": "4.13.0",
44
"description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.",
55
"main": "index.js",
66
"scripts":{

‎src/js/theme.js‎

Lines changed: 89 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,9 @@ var theme = (function(){
10941094
add: function(){
10951095
state.get.current().theme.custom.all.push(JSON.parse(JSON.stringify(stagedThemeCustom.theme)));
10961096
},
1097+
edit: function(){
1098+
state.get.current().theme.custom.all.splice(stagedThemeCustom.position.index,1,JSON.parse(JSON.stringify(stagedThemeCustom.theme)));
1099+
},
10971100
remove: function(copyStagedThemeCustom){
10981101
state.get.current().theme.custom.all.splice(stagedThemeCustom.position.index,1);
10991102
},
@@ -1463,7 +1466,9 @@ var theme = (function(){
14631466
varthemeCustomButton=helper.node("button|class:theme-custom-button button mb-0,tabindex:-1");
14641467
varthemeCustomPreview=helper.node("span|class:theme-custom-preview");
14651468
varthemeCustomControl=helper.node("div|class:theme-custom-control");
1466-
varthemeCustomRemove=helper.node("button|class:theme-custom-control-item theme-custom-control-item-remove button mb-0,tabindex:-2");
1469+
varthemeCustomEdit=helper.node("button|class:theme-custom-control-item theme-custom-control-item-remove button button-small mb-0,tabindex:-2");
1470+
varthemeCustomEditIcon=helper.node("spa|class:button-icon icon-edit");
1471+
varthemeCustomRemove=helper.node("button|class:theme-custom-control-item theme-custom-control-item-remove button button-small mb-0,tabindex:-2");
14671472
varthemeCustomRemoveIcon=helper.node("spa|class:button-icon icon-close");
14681473
varshadeSteps=4;
14691474
varrgb=arrayItem.color.rgb;
@@ -1505,7 +1510,9 @@ var theme = (function(){
15051510
};
15061511

15071512
themeCustomButton.appendChild(themeCustomPreview);
1513+
themeCustomEdit.appendChild(themeCustomEditIcon);
15081514
themeCustomRemove.appendChild(themeCustomRemoveIcon);
1515+
themeCustomControl.appendChild(themeCustomEdit);
15091516
themeCustomControl.appendChild(themeCustomRemove);
15101517
themeCustomTile.appendChild(themeCustomButton);
15111518
themeCustomTile.appendChild(themeCustomControl);
@@ -1535,6 +1542,11 @@ var theme = (function(){
15351542
control.render.class();
15361543
},false);
15371544

1545+
themeCustomEdit.addEventListener("click",function(){
1546+
menu.close();
1547+
render.custom.edit(copyStagedThemeCustom);
1548+
},false);
1549+
15381550
themeCustomRemove.addEventListener("click",function(){
15391551
menu.close();
15401552
render.custom.remove(copyStagedThemeCustom);
@@ -1546,28 +1558,39 @@ var theme = (function(){
15461558
themeCustomSaved.appendChild(helper.node("hr"));
15471559
};
15481560
},
1549-
add: function(){
1550-
varform=function(){
1551-
varform=helper.node("form|class:group-form");
1552-
varfieldset=helper.node("fieldset");
1553-
varinputWrap=helper.node("div|class:input-wrap");
1554-
varlabel=helper.node("label:Name|for:theme-name");
1555-
varinput=helper.node("input|id:theme-name,class:theme-name mb-0,type:text,tabindex:1,placeholder:Example theme,autocomplete:off,autocorrect:off,autocapitalize:off,spellcheck:false");
1556-
inputWrap.appendChild(label);
1557-
inputWrap.appendChild(input);
1558-
fieldset.appendChild(inputWrap);
1559-
form.appendChild(fieldset);
1560-
input.addEventListener("input",function(){
1561-
stagedThemeCustom.theme.name=this.value;
1562-
},false);
1563-
form.addEventListener("keydown",function(event){
1564-
if(event.keyCode==13){
1565-
event.preventDefault();
1566-
returnfalse;
1567-
};
1568-
},false);
1569-
returnform;
1561+
form: function(override){
1562+
varoptions={
1563+
useStagedTheme: null
15701564
};
1565+
if(override){
1566+
options=helper.applyOptions(options,override);
1567+
};
1568+
varform=helper.node("form|class:group-form");
1569+
varfieldset=helper.node("fieldset");
1570+
varinputWrap=helper.node("div|class:input-wrap");
1571+
varlabel=helper.node("label:Name|for:theme-name");
1572+
varinput=helper.node("input|id:theme-name,class:theme-name mb-0,type:text,tabindex:1,placeholder:Example theme,autocomplete:off,autocorrect:off,autocapitalize:off,spellcheck:false");
1573+
inputWrap.appendChild(label);
1574+
inputWrap.appendChild(input);
1575+
fieldset.appendChild(inputWrap);
1576+
form.appendChild(fieldset);
1577+
1578+
if(options.useStagedTheme){
1579+
input.value=stagedThemeCustom.theme.name;
1580+
};
1581+
1582+
input.addEventListener("input",function(){
1583+
stagedThemeCustom.theme.name=this.value;
1584+
},false);
1585+
form.addEventListener("keydown",function(event){
1586+
if(event.keyCode==13){
1587+
event.preventDefault();
1588+
returnfalse;
1589+
};
1590+
},false);
1591+
returnform;
1592+
},
1593+
add: function(){
15711594
varsuccessAction=function(){
15721595
stagedThemeCustom.theme.font=state.get.current().theme.font;
15731596
stagedThemeCustom.theme.color=state.get.current().theme.color;
@@ -1592,11 +1615,54 @@ var theme = (function(){
15921615
};
15931616
modal.open({
15941617
heading: "Save current Theme",
1618+
content: render.custom.form(),
1619+
successAction: successAction,
1620+
cancelAction: cancelAction,
1621+
actionText: "Save",
1622+
size: "small"
1623+
});
1624+
shade.open({
1625+
action: function(){
1626+
modal.close();
1627+
pagelock.unlock();
1628+
stagedThemeCustom.reset();
1629+
}
1630+
});
1631+
pagelock.lock();
1632+
},
1633+
edit: function(copyStagedThemeCustom){
1634+
stagedThemeCustom.position.index=JSON.parse(JSON.stringify(copyStagedThemeCustom.position.index));
1635+
stagedThemeCustom.theme=JSON.parse(JSON.stringify(copyStagedThemeCustom.theme));
1636+
varform=render.custom.form({
1637+
useStagedTheme: true
1638+
});
1639+
varheading;
1640+
if(stagedThemeCustom.theme.name!=null&&stagedThemeCustom.theme.name!=""){
1641+
heading="Edit "+stagedThemeCustom.theme.name;
1642+
}else{
1643+
heading="Edit unnamed theme";
1644+
};
1645+
varsuccessAction=function(){
1646+
mod.custom.edit();
1647+
data.save();
1648+
render.custom.clear();
1649+
render.custom.all();
1650+
shade.close();
1651+
pagelock.unlock();
1652+
stagedThemeCustom.reset();
1653+
};
1654+
varcancelAction=function(){
1655+
shade.close();
1656+
pagelock.unlock();
1657+
stagedThemeCustom.reset();
1658+
};
1659+
modal.open({
1660+
heading: heading,
15951661
successAction: successAction,
15961662
cancelAction: cancelAction,
15971663
actionText: "Save",
15981664
size: "small",
1599-
content: form()
1665+
content: form
16001666
});
16011667
shade.open({
16021668
action: function(){

‎src/js/version.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
varversion=(function(){
22

3-
varcurrent="4.12.1";
3+
varcurrent="4.13.0";
44

55
varname="Naughty Goose";
66

‎src/manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nightTab",
33
"short_name": "nightTab",
44
"description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.",
5-
"version": "4.12.1",
5+
"version": "4.13.0",
66
"manifest_version": 2,
77
"chrome_url_overrides":{
88
"newtab": "index.html"

0 commit comments

Comments
(0)