Skip to content

Commit 82aa5ab

Browse files
Fixed topbar css
Aded InputComponents.js to take care (dynamically create, add events) of input elements.
1 parent 79a3c07 commit 82aa5ab

9 files changed

+144
-11
lines changed

build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function compile_page(){
5656

5757
.pipe(handlebars({encoding: 'utf8', debug: true, bustCache: true})
5858
.partials('./views/[!index]*.hbs').partials('./views/popups/*.hbs')
59-
//.helpers({ svg: hb_svg })
59+
.partials('./views/components/*.hbs')
6060
.helpers('./helpers/**/*.js')
6161
.data({
6262
projectSlug: 'pixel-editor',

css/_components.scss

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
.checkbox-holder {
2+
position:relative;
3+
width:15px;
4+
height:15px;
5+
display:block;
6+
7+
.checkbox {
8+
display: inline-block;
9+
cursor: pointer;
10+
padding-right: 1em;
11+
12+
.box {
13+
color: $basetext;
14+
background: darken($basecolor, 5%);
15+
border: none;
16+
padding: 0.5rem;
17+
border-radius: 0.5rem;
18+
box-sizing: border-box;
19+
margin-right: 0.5rem;
20+
display: inline-block;
21+
vertical-align: middle;
22+
border: solid 2px $basecolor;
23+
pointer-events: none;
24+
25+
svg {
26+
visibility: hidden;
27+
width: 1em;
28+
height: 1em;
29+
display: block;
30+
path {
31+
fill: $basetext;
32+
}
33+
}
34+
35+
}
36+
37+
//checked
38+
&.checked .box svg {
39+
visibility: visible;
40+
}
41+
42+
label {
43+
display: inline-block;
44+
pointer-events: none;
45+
} //hover label or box
46+
47+
&:hover:not(.disabled){
48+
border-color: $basecolor;
49+
}
50+
51+
&.disabled {
52+
cursor: not-allowed;
53+
.box svg path {fill: $basetext;}
54+
}
55+
}
56+
}

css/_main-menu.scss

+5-7
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ li#editor-info {
108108
display:inline;
109109
padding-right:20px;
110110
}
111+
112+
.checkbox-holder {
113+
display: inline;
114+
}
115+
111116
input {
112117
margin-left:10px;
113118
background-color:darken($basecolor, 6%);
@@ -122,12 +127,5 @@ li#editor-info {
122127
width:25px;
123128
height:15px;
124129
}
125-
126-
input[type=checkbox] {
127-
padding:1px;
128-
width:20px;
129-
height:20px;
130-
background-color:darken($basecolor, 5%) !important;
131-
}
132130
}
133131
}

css/pixel-editor.scss

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@import 'general';
33
@import 'zindex';
44
@import 'shake';
5+
@import 'components';
56
@import 'help';
67
@import 'layers';
78
@import 'canvas';

js/InputComponents.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const InputComponents = (() => {
2+
setInputEvents();
3+
4+
function setInputEvents() {
5+
// Make the checkboxes toggleable
6+
let checkboxes = document.getElementsByClassName("checkbox");
7+
for (let i=0; i<checkboxes.length; i++) {
8+
Events.on("click", checkboxes[i], toggleBox);
9+
}
10+
}
11+
12+
function toggleBox(event) {
13+
if (event.target.classList.contains("checked"))
14+
event.target.classList.remove("checked");
15+
else
16+
event.target.classList.add("checked");
17+
}
18+
19+
function createCheckbox(id, label) {
20+
let element = document.createElement("div");
21+
let inner = document.createElement("div");
22+
let hiddenInput = document.createElement("input");
23+
let box = document.createElement("div");
24+
let labelEl = document.createElement("label");
25+
26+
labelEl.innerHTML = label;
27+
box.innerHTML = '\
28+
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"\
29+
width="405.272px" height="405.272px" viewBox="0 0 405.272 405.272" style="enable-background:new 0 0 405.272 405.272;"\
30+
xml:space="preserve">\
31+
<g>\
32+
<path d="M393.401,124.425L179.603,338.208c-15.832,15.835-41.514,15.835-57.361,0L11.878,227.836\
33+
c-15.838-15.835-15.838-41.52,0-57.358c15.841-15.841,41.521-15.841,57.355-0.006l81.698,81.699L336.037,67.064\
34+
c15.841-15.841,41.523-15.829,57.358,0C409.23,82.902,409.23,108.578,393.401,124.425z"/>\
35+
</g>\
36+
</svg>';
37+
38+
element.className = "checkbox-holder";
39+
inner.className = "checkbox";
40+
hiddenInput.type = "hidden";
41+
box.className = "box";
42+
box.id = id;
43+
44+
inner.appendChild(labelEl);
45+
inner.appendChild(hiddenInput);
46+
inner.appendChild(box);
47+
element.appendChild(inner);
48+
49+
}
50+
51+
function updated() {
52+
setInputEvents();
53+
}
54+
55+
return {
56+
updated,
57+
createCheckbox
58+
}
59+
})();

js/pixel-editor.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/** UTILITY AND INPUT **/
1010
//=include Util.js
1111
//=include Events.js
12+
//=include InputComponents.js
1213
//=include Dialogue.js
1314
//=include History.js
1415
//=include Settings.js
@@ -70,9 +71,10 @@ PresetModule.instrumentPresetMenu();
7071

7172
//when the page is done loading, you can get ready to start
7273
window.onload = function () {
73-
//featureToggles.onLoad();
74-
74+
// First cursor update
7575
ToolManager.currentTool().updateCursor();
76+
// Apply checkboxes
77+
7678

7779
//check if there are any url parameters
7880
if (window.location.pathname.replace('/pixel-editor/','').length <= 1) {

svg/check.svg

+10
Loading

views/components/checkbox.hbs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="checkbox-holder">
2+
<div class="checkbox checked">
3+
<label>Snap to grid</label>
4+
<input type="hidden"/>
5+
<div class="box">{{svg "check"}}</div>
6+
</div>
7+
</div>

views/main-menu.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<li id="editor-info">
7070
<ul>
7171
<li><label><span>Tool size: </span><input type="text" width="10px"/></label></li>
72-
<li><label><span>Continuous: </span><input type="checkbox"/></label></li>
72+
<li>{{> checkbox}}</li>
7373
</ul>
7474
</li>
7575
</ul>

0 commit comments

Comments
 (0)