Skip to content

Commit 42abeb4

Browse files
jpenillazombieFox
authored andcommitted
[feature] randomly select background image from list of URLs
1 parent 07183bb commit 42abeb4

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

‎src/css/form.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ textarea{
77
font-size:1em;
88
font-family:var(--font-regular);
99
line-height:2em;
10-
height:5em;
10+
height:10em;
1111
min-height:2.5em;
1212
min-width:0;
1313
width:100%;

‎src/index.html‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,8 +1094,10 @@ <h1 class="menu-item-header-text">Image</h1>
10941094
</div>
10951095
<divclass="form-indent">
10961096
<divclass="input-wrap">
1097-
<inputid="control-background-image-url" class="control-background-image-url" type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" placeholder="https://" tabindex="-1">
1097+
<textareaid="control-background-image-url" class="control-background-image-url mb-0" spellcheck="false" placeholder="https://..." tabindex="-1"></textarea>
10981098
</div>
1099+
<pclass="control-background-image-url-helper form-helper small">Add one or more URLs separate by a space or on a new lines. If more than one is entered a random background image will be used on load.</p>
1100+
<hr>
10991101
<pclass="control-background-image-url-helper form-helper small">Unsplash can be used for random images, eg:</p>
11001102
<pclass="control-background-image-url-helper form-helper small"><i>https://source.unsplash.com/random/1920x1080/?night,day,sky</i></p>
11011103
<pclass="control-background-image-url-helper form-helper small">Change parameters after <i>.../ramdom/</i> for more options. Loading times may vary.</p>

‎src/js/background.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ var background = (function(){
8484
if(state.get().background.image.from=="file"){
8585
html.style.setProperty("--background-image","url("+state.get().background.image.file.data+")");
8686
}elseif(state.get().background.image.from=="url"){
87-
html.style.setProperty("--background-image","url("+state.get().background.image.url+")");
87+
if(/\s+/g.test(state.get().background.image.url)){
88+
varallUrls=state.get().background.image.url.split(/\s+/);
89+
varrandomUrl=allUrls[Math.floor(Math.random()*allUrls.length)];
90+
html.style.setProperty("--background-image","url("+randomUrl+")");
91+
}else{
92+
html.style.setProperty("--background-image","url("+state.get().background.image.url+")");
93+
};
8894
};
8995
}else{
9096
html.style.setProperty("--background-image","url()");

‎src/js/control.js‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,7 @@ var control = (function(){
21992199
},{
22002200
element: helper.e(".control-background-image-url"),
22012201
path: "background.image.url",
2202-
type: "text",
2202+
type: "textarea",
22032203
func: function(){
22042204
background.render.image();
22052205
}
@@ -2282,6 +2282,7 @@ var control = (function(){
22822282
checkbox: "change",
22832283
radio: "change",
22842284
text: "input",
2285+
textarea: "input",
22852286
number: "input",
22862287
range: "input",
22872288
color: "change",
@@ -2297,6 +2298,9 @@ var control = (function(){
22972298
text: function(object){
22982299
returnobject.element.value;
22992300
},
2301+
textarea: function(object){
2302+
returnobject.element.value;
2303+
},
23002304
number: function(object){
23012305
returnparseInt(object.element.value,10);
23022306
},
@@ -2354,6 +2358,12 @@ var control = (function(){
23542358
if(object.func){
23552359
object.func();
23562360
};
2361+
},
2362+
textarea: function(object,event){
2363+
changeValue(object);
2364+
if(object.func){
2365+
object.func();
2366+
};
23572367
}
23582368
};
23592369
object.element.addEventListener(eventType[object.type],function(event){
@@ -3134,6 +3144,18 @@ var control = (function(){
31343144
};
31353145
object.element.value=newValue;
31363146
},
3147+
textarea: function(object){
3148+
varnewValue=helper.getObject({
3149+
object: state.get(),
3150+
path: object.path
3151+
});
3152+
if(object.valueMod){
3153+
object.valueMod.slice().reverse().forEach(function(arrayItem,index){
3154+
newValue=valueMod[arrayItem](newValue,object.element);
3155+
});
3156+
};
3157+
object.element.value=newValue;
3158+
},
31373159
number: function(object){
31383160
object.element.value=helper.getObject({
31393161
object: state.get(),
@@ -3159,7 +3181,7 @@ var control = (function(){
31593181
}));
31603182
}
31613183
};
3162-
varsupportedType=["checkbox","radio","text","number","range","color"];
3184+
varsupportedType=["checkbox","radio","text","number","range","color","textarea"];
31633185
_allControl.forEach(function(arrayItem,index){
31643186
if(supportedType.includes(arrayItem.element.type)){
31653187
setValue[arrayItem.type](arrayItem);

0 commit comments

Comments
(0)