Skip to content

Commit eede922

Browse files
committed
A working version, if not perfect
1 parent 7c2e2e9 commit eede922

File tree

3 files changed

+81
-14
lines changed

3 files changed

+81
-14
lines changed

dojo/colormix.css

+15-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,21 @@ h1 { font-size: 3em; font-weight: bolder; }
5454
}
5555

5656
#slider {
57-
float: left;
58-
margin: 5px 5px 5px 220px;
59-
width: 433px;
57+
/*margin: 5px;
58+
width: 433px;*/
59+
width: 100%;
60+
}
61+
62+
#controls {
63+
margin-left: 223px;
64+
width: 424px;
65+
height: 127px;
66+
text-align: center;
67+
}
68+
69+
#leftControls, #rightControls {
70+
width: 190px;
71+
text-align: center;
6072
}
6173

6274
#resultCol {

dojo/colormix.html

+11-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
<header>
1313
<h1>Color Mixer</h1>
1414
</header>
15+
<section id="instructions">
16+
<p>Dojo has a nice convenient utility for mixing two colors, including balancing towards one of the colors. This little demo shows off the color picker as well as balancing.</p>
17+
<p>How to work with it:</p>
18+
<ul>
19+
<li>Drag the slider left and right to adjust the balance of the mix.</li>
20+
<li>Click on one of the top color blocks to display a color picker, which you can use to directly select a color.</li>
21+
<li>Use either of the randomize buttons to set the color at random (duh)</li>
22+
</ul>
23+
</section>
1524
<section id="loading">
1625
Loading, please wait...
1726
</section>
@@ -22,8 +31,8 @@ <h1>Color Mixer</h1>
2231
<span id="rightCol" class="colorpane"> </span>
2332
<span id="rightPal" class="colorpane"> </span>
2433
</div>
25-
<div class="colorwrap">
26-
<span id="slider"> </span>
34+
<div>
35+
<div id="controls"></div>
2736
</div>
2837
<div class="colorwrap">
2938
<span id="resultCol" class="colorpane"> </span>
@@ -37,7 +46,6 @@ <h1>Color Mixer</h1>
3746
<script type="text/javascript">
3847
// Dojo Config -- MUST be before Dojo comes in
3948
var djConfig = {
40-
parseOnLoad: true,
4149
isDebug: true
4250
};
4351
</script>

dojo/colormix.js

+55-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
// Dojo Requires
66
dojo.require('dojo.Stateful');
77
dojo.require('dijit.ColorPalette');
8+
dojo.require('dijit.form.Button');
89
dojo.require('dijit.form.HorizontalSlider');
10+
dojo.require('dijit.form.TextBox');
11+
dojo.require('dijit.layout.BorderContainer');
12+
dojo.require('dijit.layout.ContentPane');
913

1014
// Variables
11-
// (I realize global isn't always great, but this is just a simple demo)
12-
var left, right, slider, result;
15+
// (I realize global isn't a great idea, but this is just a simple demo)
16+
var controls, left, right, slider, result, output;
1317

1418
// Functions
15-
1619
// rndCol: Just a simple way to get a random color
1720
function rndCol() {
1821
var i, cols = new Array(3);
@@ -28,7 +31,6 @@ function rndCol() {
2831
function colChange(prop, oldCol, newCol) {
2932
// Set the node's background
3033
var node = this.get('displayNode'), newColHex = newCol.toHex();
31-
console.log('colChange', this, prop, oldCol, newCol);
3234

3335
// If we have the same color, we can just get out
3436
if (oldCol && newCol && oldCol.toHex() === newColHex) return;
@@ -54,12 +56,13 @@ function mixCols(val) {
5456
var leftCol = left.get('color'),
5557
rightCol = right.get('color');
5658

57-
console.log('mixCols()');
5859
if (!leftCol || !rightCol) {
5960
// Just dump out for now
6061
return;
6162
}
6263

64+
output.innerHTML = val;
65+
6366
// TODO Animate
6467
result.set('color', dojo.blendColors(leftCol, rightCol, val));
6568
}
@@ -84,14 +87,55 @@ dojo.ready(function(){
8487
displayNode: dojo.byId('resultCol')
8588
});
8689

90+
controls = new dijit.layout.BorderContainer({}, 'controls');
91+
92+
var lp = new dijit.layout.ContentPane({
93+
id: 'leftControls',
94+
region: 'left'
95+
});
96+
controls.addChild(lp);
97+
var btl = new dijit.form.Button({
98+
label: "Randomize Left Color",
99+
onClick: function () {
100+
left.set('color', rndCol());
101+
}
102+
});
103+
lp.containerNode.appendChild(btl.domNode);
104+
105+
var rp = new dijit.layout.ContentPane({
106+
id: 'rightControls',
107+
region: 'right'
108+
});
109+
controls.addChild(rp);
110+
var btr = new dijit.form.Button({
111+
label: "Randomize Right Color",
112+
onClick: function () {
113+
right.set('color', rndCol());
114+
}
115+
});
116+
rp.containerNode.appendChild(btr.domNode);
117+
118+
var ft = new dijit.layout.ContentPane({
119+
id: 'footer',
120+
region: 'bottom'
121+
});
122+
controls.addChild(ft);
123+
87124
// Build a slider
88125
slider = new dijit.form.HorizontalSlider({
126+
id: 'slider',
89127
value: 0.5,
90128
minimum: 0,
91129
maximum: 1,
92130
//intermediateChanges: true,
93131
onChange: mixCols
94-
}, 'slider');
132+
});
133+
ft.containerNode.appendChild(slider.domNode);
134+
135+
// Show some info
136+
output = dojo.create('span');
137+
ft.containerNode.appendChild(dojo.create('span', {innerHTML: 'Slider value: '}));
138+
ft.containerNode.appendChild(output);
95139

96140
// Set up some events
97141
left.watch('color', colChangeAndMix);
@@ -106,7 +150,8 @@ dojo.ready(function(){
106150

107151
// Mmm, events
108152
dojo.connect(disp, "onclick", function () {
109-
palNode.style.visibility = 'visible';
153+
vis = palNode.style.visibility;
154+
palNode.style.visibility = vis === 'visible' ? 'hidden' : 'visible';
110155
});
111156
dojo.connect(pal, 'onChange', function (col) {
112157
palNode.style.visibility = 'hidden';
@@ -118,7 +163,9 @@ dojo.ready(function(){
118163
item.set('color', rndCol());
119164
});
120165

121-
// Show it all
166+
// Get the show on the road
167+
//dojo.byId('controls').appendChild(controls.domNode);
168+
controls.startup();
122169
dojo.byId('loading').style.display = 'none';
123170
dojo.byId('content').style.display = '';
124171
}); // dojo.ready

0 commit comments

Comments
 (0)