Skip to content

Commit 81fc5c9

Browse files
committedSep 15, 2019
set background preview
1 parent 22d9af7 commit 81fc5c9

File tree

10 files changed

+146
-84
lines changed

10 files changed

+146
-84
lines changed
 

‎public/css/css/output.css

+29-20
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,31 @@ a {
190190
background-color: #f1f1f1; }
191191

192192
.palette {
193-
display: flex; }
193+
display: flex;
194+
flex-direction: column; }
195+
.palette__container {
196+
display: flex; }
194197
.palette__record {
198+
height: 100px;
195199
flex: 1;
196-
margin: 0 1rem; }
200+
margin: 0 1rem;
201+
border: 2px dashed black; }
202+
203+
.bg {
204+
width: 100%;
205+
position: fixed;
206+
top: 0;
207+
left: 0; }
208+
.bg__entire {
209+
height: 100vh;
210+
z-index: -3; }
211+
.bg__top {
212+
height: 50vh;
213+
z-index: -2; }
214+
.bg__bottom {
215+
top: 50%;
216+
height: 50vh;
217+
z-index: -2; }
197218

198219
.landing__label {
199220
margin-top: 10px;
@@ -221,6 +242,11 @@ a {
221242
border: 2px dashed black; }
222243
.landing__colorsample-main {
223244
width: 70%; }
245+
.landing__colorsample-heading {
246+
position: absolute;
247+
top: 50%;
248+
left: 30%;
249+
transform: translate(-50%, -50%); }
224250

225251
.landing__buttons {
226252
display: flex;
@@ -229,30 +255,13 @@ a {
229255
.landing__buttons button {
230256
margin: 0 5px; }
231257

232-
.landing__palette {
233-
margin-left: auto;
234-
margin-right: auto;
235-
margin-top: 30px;
236-
overflow: hidden;
237-
height: 180px; }
238-
239-
.landing__palette__record {
240-
border: 2px dashed black;
241-
height: 140px;
242-
margin-bottom: 10px;
243-
width: 23%;
244-
margin-left: 1%;
245-
margin-right: 1%;
246-
position: relative; }
247-
248-
.landing__palette__record__paragraph, .landing__colorsample__list {
258+
.landing__colorsample__list {
249259
width: 100%;
250260
position: absolute;
251261
top: 50%;
252262
left: 50%;
253263
transform: translate(-50%, -50%); }
254264

255-
.landing__palette__record__paragraph,
256265
.landing__colorsample__list li {
257266
font-size: 24px;
258267
color: white;

‎public/css/scss/components/_bg.scss

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.bg {
2+
width: 100%;
3+
position: fixed;
4+
top: 0;
5+
left: 0;
6+
7+
&__entire {
8+
height: 100vh;
9+
z-index: -3;
10+
}
11+
&__top {
12+
height: 50vh;
13+
z-index: -2;
14+
}
15+
&__bottom {
16+
top: 50%;
17+
height: 50vh;
18+
z-index: -2;
19+
}
20+
}
+6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
.palette {
22
display: flex;
3+
flex-direction: column;
34

5+
&__container {
6+
display: flex;
7+
}
48
&__record {
9+
height: 100px;
510
flex: 1;
611
margin: 0 1rem;
12+
border: 2px dashed black;
713
}
814
}

‎public/css/scss/main.scss

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
@import "components/modal";
1111
@import "components/tab";
1212
@import "components/palette";
13+
@import "components/bg";
1314

1415
@import "views/landing";
1516

‎public/css/scss/views/_landing.scss

+7-18
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
width: 70%;
2929
}
3030

31+
&-heading {
32+
position: absolute;
33+
top: 50%;
34+
left: 30%;
35+
transform: translate(-50%, -50%);
36+
}
37+
3138
height: 159px;
3239
border: 3px dashed black;
3340
position: relative;
@@ -41,31 +48,13 @@
4148
margin: 0 5px;
4249
}
4350
}
44-
&__palette {
45-
margin-left: auto;
46-
margin-right: auto;
47-
margin-top: 30px;
48-
overflow: hidden;
49-
height: 180px;
50-
}
51-
&__palette__record {
52-
border: 2px dashed black;
53-
height: 140px;
54-
margin-bottom: 10px;
55-
width: 23%;
56-
margin-left: 1%;
57-
margin-right: 1%;
58-
position: relative;
59-
}
60-
&__palette__record__paragraph,
6151
&__colorsample__list {
6252
width: 100%;
6353
position: absolute;
6454
top: 50%;
6555
left: 50%;
6656
transform: translate(-50%, -50%);
6757
}
68-
&__palette__record__paragraph,
6958
&__colorsample__list li {
7059
font-size: 24px;
7160
color: white;

‎public/html/views/main.html

+22-34
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
<div class="container text-center">
2-
<form data-ng-submit="fireColorReader()" class="form-inline">
3-
<div class="form-group">
4-
<label for="colorField" class="landing__label">Below enter color in HEX format</label>
5-
<input type="text" ng-model="selectedColor" class="form-control" id="colorField" required>
6-
</div>
7-
</form>
2+
<div class="form-group">
3+
<label for="colorField" class="landing__label">Below enter color in HEX format or chose new color</label>
4+
<input type="text" ng-model="selectedColor" class="form-control" id="colorField" required>
5+
</div>
86

97
<div class="landing__colorsample-container">
108
<div class="landing__colorsample-left">
11-
<div class="landing__colorsample-left-box" style="background-color: #{{selectedColor}}; filter: brightness(80%);"></div>
12-
<div class="landing__colorsample-left-box" style="background-color: #{{selectedColor}}; filter: brightness(60%);"></div>
13-
<div class="landing__colorsample-left-box" style="background-color: #{{selectedColor}}; filter: brightness(40%);"></div>
9+
<div class="landing__colorsample-left-box" data-ng-style="{ 'background-color': '#' + selectedColor }" style="filter: brightness(80%);"></div>
10+
<div class="landing__colorsample-left-box" data-ng-style="{ 'background-color': '#' + selectedColor }" style="filter: brightness(60%);"></div>
11+
<div class="landing__colorsample-left-box" data-ng-style="{ 'background-color': '#' + selectedColor }" style="filter: brightness(40%);"></div>
1412
</div>
1513
<div class="landing__colorsample-main">
16-
<div class="landing__colorsample" style="background-color: #{{selectedColor}}">
17-
<ul class="list-unstyled landing__colorsample__list">
18-
<li data-ng-repeat="n in convertedColors | orderBy: reverse : true | limitTo: 1">
19-
{{n.colorInHEX}} <br> {{n.colorInHSL}} <br> {{n.colorInRGB}}
20-
<li>
21-
</ul>
14+
<div class="landing__colorsample" data-ng-style="{ 'background-color': '#' + selectedColor }">
15+
<h3 class="landing__colorsample-heading">
16+
{{ selectedColor }}
17+
</h3>
2218
<color-picker ng-model="selectedColor" api="api" options="options"></color-picker>
2319
</div>
2420
</div>
2521
<div class="landing__colorsample-right">
26-
<div class="landing__colorsample-right-box" style="background-color: #{{selectedColor}}; filter: brightness(120%);"></div>
27-
<div class="landing__colorsample-right-box" style="background-color: #{{selectedColor}}; filter: brightness(140%);"></div>
28-
<div class="landing__colorsample-right-box" style="background-color: #{{selectedColor}}; filter: brightness(160%);"></div>
22+
<div class="landing__colorsample-right-box" data-ng-style="{ 'background-color': '#' + selectedColor }" style="filter: brightness(120%);"></div>
23+
<div class="landing__colorsample-right-box" data-ng-style="{ 'background-color': '#' + selectedColor }" style="filter: brightness(140%);"></div>
24+
<div class="landing__colorsample-right-box" data-ng-style="{ 'background-color': '#' + selectedColor }" style="filter: brightness(160%);"></div>
2925
</div>
3026
</div>
3127

@@ -42,33 +38,25 @@
4238
</select>
4339
</button>
4440
<button class="btn btn-default" data-ng-click="saveToPalette(selectedColor)">Save to palette</button>
45-
<button class="btn btn-default">Set as background</button>
46-
<button class="btn btn-default">Set as background 50%</button>
41+
<button class="btn btn-default" data-ng-click="setBackground('bgEntire')">Set as background</button>
42+
<button class="btn btn-default" data-ng-click="setBackground('bgTop')">Set as background 50% top</button>
43+
<button class="btn btn-default" data-ng-click="setBackground('bgBottom')">Set as background 50% bottom</button>
44+
<button class="btn btn-default" data-ng-click="setBackground('clear')">Clear backgrounds</button>
4745
</div>
4846
</div>
4947

50-
{{ palette }}
51-
52-
<!--
53-
<div class="container landing__palette">
5448
<div class="palette">
55-
<p class="help-block">Hey you! Your colors will stay in palette until you clear cache or click button below! {{ palette }}</p>
49+
<p class="help-block">Hey you! Your colors will stay in palette until you clear cache or click button below!</p>
5650
<div class="palette__container">
5751
<div class="palette__record"
58-
data-ng-repeat="n in palette | orderBy: reverse : true | limitTo: 8"
59-
style="background-color: {{n.inHEX}}">
60-
<p class="landing__palette__record__paragraph text-center">
61-
{{n.inHSL}} <br> {{n.inHEX}} <br>
62-
</p>
52+
data-ng-repeat="n in palette track by $index"
53+
data-ng-style="{'background-color':'#'+n}">
6354
</div>
6455
</div>
6556
</div>
66-
</div>
67-
-->
68-
6957

7058
<div class="landing__buttons">
71-
<button class="btn btn-success landing__palette__button--success" data-ng-click="clearCache()">Clear Palette</button>
59+
<button class="btn btn-success landing__palette__button--success" data-ng-click="clearEntirePalette()">Clear Palette</button>
7260
<button data-ng-if="logged" class="btn btn-success landing__palette__button--success" data-ng-click="savePalette()">Save Palette</button>
7361
<button data-ng-if="!logged" class="btn btn-success landing__palette__button--success" data-ng-click="openLogin()">Save Palette</button>
7462
</div>

‎public/index.html

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
</head>
2222
<body data-ng-app="app" data-ng-cloak="" data-ng-controller="external">
2323
<topbar></topbar>
24+
25+
<div class="bg bg__entire" data-ng-style="{'background-color': '#'+bgEntire}"></div>
26+
<div class="bg bg__top" data-ng-style="{'background-color': '#'+bgTop}"></div>
27+
<div class="bg bg__bottom" data-ng-style="{'background-color': '#'+bgBottom}"></div>
28+
2429
<div data-ng-view=""></div>
2530
<div class="modal__overlay" data-ng-if="modalLogin || modalRegister"></div>
2631
<div class="modal__outer" data-ng-if="modalLogin || modalRegister">

‎public/js/controllers/externalCtrl.js

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
$scope.modalLogin = stateService.get('modalLogin');
1313
$scope.modalRegister = stateService.get('modalRegister');
1414
$scope.logged = stateService.get('logged');
15+
$scope.bgEntire = stateService.get('bgEntire');
16+
$scope.bgTop = stateService.get('bgTop');
17+
$scope.bgBottom = stateService.get('bgBottom');
1518
});
1619

1720
$localForage.getItem('authorization')

‎public/js/controllers/mainCtrl.js

+49-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
.module('app')
66
.controller('mainCtrl', Controller);
77

8-
//$inject for minify issue
98
Controller.$inject = ['$scope', '$rootScope', '$localForage', 'stateService'];
109

1110
function Controller($scope, $rootScope, $localForage, stateService) {
@@ -26,14 +25,38 @@
2625
}
2726
};
2827

28+
vm.$watch('palette', newVal => {
29+
console.log('caught change');
30+
31+
if(newVal.length < 8) {
32+
const fillArr = new Array(8 - newVal.length);
33+
fillArr.fill('');
34+
vm.palette = vm.palette.concat(fillArr);
35+
console.log(vm.palette);
36+
}
37+
if(newVal.length > 8 && newVal.includes("")) {
38+
console.log('more than 8 and contain empty string');
39+
for(let i = 0; i < newVal.length; i++) {
40+
if(newVal[i] === '') {
41+
vm.palette.splice(i, 1);
42+
return;
43+
}
44+
}
45+
}
46+
});
47+
48+
vm.$watch('selectedColor', newVal => {
49+
if(newVal.includes('#')) {
50+
$scope.selectedColor = newVal.replace('#', '');
51+
}
52+
});
53+
2954
window.onload = () => { if(vm.api.open) vm.api.open() };
3055
setTimeout(() => { if(vm.api.open) vm.api.open(); }, 1000);
3156

3257
vm.openLogin = () => stateService.set('modalLogin', true);
3358

3459
vm.saveToPalette = color => {
35-
console.log(vm.palette, color);
36-
3760
if(vm.palette.includes(color)) {
3861
alert('this color is already within your palette');
3962
} else {
@@ -47,22 +70,37 @@
4770
if(vm.palette[i] === color) {
4871
vm.palette.splice(i, 1);
4972
$localForage.setItem('palette', vm.palette);
50-
//$scope.$apply();
5173
}
5274
}
5375
};
76+
77+
vm.setBackground = pos => {
78+
if(pos === 'clear') {
79+
stateService.set('bgEntire', 'edf2f0');
80+
stateService.set('bgTop', 'edf2f0');
81+
stateService.set('bgBottom', 'edf2f0');
82+
} else {
83+
stateService.set(pos, vm.selectedColor);
84+
}
85+
};
86+
5487
vm.clearEntirePalette = () => {
55-
$localForage.clear()
56-
.then(() => { vm.colorsFromCache = []; });
88+
$localForage.setItem('palette', [])
89+
.then(() => {
90+
$localForage.getItem('palette')
91+
.then(colors => {
92+
if(colors) {
93+
vm.palette = colors;
94+
} else {
95+
vm.palette = [];
96+
}
97+
});
98+
});
5799
};
58100

59101
$localForage.getItem('palette')
60102
.then(colors => {
61-
if(colors) vm.palette = colors;
103+
if(colors) console.log('eee', colors); vm.palette = colors;
62104
});
63-
64-
$rootScope.$on('colorChanged', (e, data) => {
65-
66-
});
67105
}
68106
})();

‎public/js/services/stateService.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
this.state = {
1010
modalLogin: false,
1111
modalRegister: false,
12-
logged: false
12+
logged: false,
13+
bgEntire: '',
14+
bgTop: '',
15+
bgBottom: ''
1316
};
1417
this.set = (property, value) => {
1518
this.state[property] = value;

0 commit comments

Comments
 (0)
Please sign in to comment.