384 lines
13 KiB
HTML
384 lines
13 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"
|
|
xmlns:x2="http://www.w3.org/TR/xhtml2"
|
|
xmlns:role="http://www.w3.org/2005/01/wai-rdf/GUIRoleTaxonomy#"
|
|
xmlns:state="http://www.w3.org/2005/07/aaa">
|
|
<head>
|
|
<title>Yahoo! UI Library - Slider Widget</title>
|
|
<link rel="stylesheet" type="text/css" href="css/screen.css"></link>
|
|
<style type="text/css">
|
|
.dragPanel { position: absolute; background-color: #eeeeee; top: 200px; left: 20px; width: 320px; height: 180px; }
|
|
.dragPanel h4 { background-color: #bbbbbb; height: 10px; margin: 0px; cursor: move; }
|
|
input { font-size: 85%} .thumb { cursor:default; width:18px; height:18px; z-index: 9; position: absolute; left: 0px; }
|
|
.bg { position:absolute; left:10px; height:18px; width:146px; border: 0px solid #aaaaaa; }
|
|
.bg span, .bg p { cursor:default; position: relative; font-size: 2px; overflow: hidden; color: #aaaaaa; top: 4px; height: 10px; width: 4px; display: block; float:left; }
|
|
.bg span { border-top:1px solid #cccccc; border-bottom:1px solid #cccccc; }
|
|
.bg .lb { border-left:1px solid #cccccc; }
|
|
.bg .rb { border-right:1px solid #cccccc; }
|
|
#valdiv { position:absolute; top: 100px; left:10px; }
|
|
#rBG {-moz-outline: none; outline:0px none;top:30px}
|
|
#gBG {-moz-outline: none; outline:0px none;top:50px}
|
|
#bBG {-moz-outline: none; outline:0px none;top:70px}
|
|
#swatch { position:absolute; left:160px; top:34px; height:50px; width:50px; border:1px solid #aaaaaa; }
|
|
</style>
|
|
|
|
<!-- Nav and logger start -->
|
|
|
|
<script type="text/javascript" src="../../build/yahoo/yahoo.js" ></script>
|
|
<script type="text/javascript" src="../../build/event/event-min.js" ></script>
|
|
<script type="text/javascript" src="../../build/dom/dom-min.js" ></script>
|
|
<script type="text/javascript" src="../../build/dragdrop/dragdrop-min.js" ></script>
|
|
<script type="text/javascript" src="../../build/logger/logger-min.js" ></script>
|
|
<script type="text/javascript" src="../../build/animation/animation.js" ></script>
|
|
<script type="text/javascript" src="js/color.js" ></script>
|
|
<script type="text/javascript" src="js/key.js" ></script>
|
|
|
|
<script type="text/javascript" src="../../build/slider/slider-debug.js" ></script></head>
|
|
<body>
|
|
<div id="pageTitle"><h3>Slider Widget</h3></div>
|
|
|
|
<div id="container">
|
|
<div id="containerTop">
|
|
<div id="header"><img id="ylogo" src="img/logo.gif" /></div>
|
|
<div id="main">
|
|
|
|
<!-- Nav and logger start -->
|
|
|
|
<style type="text/css">
|
|
#logButtonHeader input { font-size: 80% }
|
|
|
|
/* logger default styles */
|
|
/* font size is controlled here: default 77% */
|
|
#yui-log {position:absolute;top:1em;right:1em;font-size:77%;text-align:left;}
|
|
/* width is controlled here: default 31em */
|
|
.yui-log {background-color:#AAA;border:1px solid black;font-family:monospace;z-index:9000;}
|
|
.yui-log p {margin:1px;padding:.1em;}
|
|
.yui-log button {font-family:monospace;}
|
|
.yui-log .yui-log-hd {padding:.5em;background-color:#575757;color:#FFF;}
|
|
/* height is controlled here: default 20em*/
|
|
.yui-log .yui-log-bd {width:100%;height:20em;background-color:#FFF;border:1px solid gray;overflow:auto;}
|
|
.yui-log .yui-log-ft {margin-top:.5em;margin-bottom:1em;}
|
|
.yui-log .yui-log-ft .yui-log-categoryfilters {}
|
|
.yui-log .yui-log-ft .yui-log-sourcefilters {width:100%;border-top:1px solid #575757;margin-top:.75em;padding-top:.75em;}
|
|
.yui-log .yui-log-btns {position:relative;float:right;bottom:.25em;}
|
|
.yui-log .yui-log-filtergrp {margin-right:.5em;}
|
|
.yui-log .info {background-color:#A7CC25;} /* A7CC25 green */
|
|
.yui-log .warn {background-color:#F58516;} /* F58516 orange */
|
|
.yui-log .error {background-color:#E32F0B;} /* E32F0B red */
|
|
.yui-log .time {background-color:#A6C9D7;} /* A6C9D7 blue */
|
|
.yui-log .window {background-color:#F2E886;} /* F2E886 tan */
|
|
|
|
|
|
</style>
|
|
|
|
<div id="rightbar">
|
|
<div id="rightBarPad">
|
|
<h3>Links</h3>
|
|
<div id="linkage">
|
|
<ul>
|
|
<li><a href="index.html?mode=dist">Basic Sliders</a></li>
|
|
<li><a href="basic.html?mode=dist">Scale Factor</a></li>
|
|
<li><a href="rgb.html?mode=dist">RGB Slider</a></li>
|
|
<li><a href="rgb2.html?mode=dist">Color Picker</a></li>
|
|
<!--
|
|
<li><a href="slider.html?mode=dist">All on one page</a></li>
|
|
-->
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
//<![CDATA[
|
|
YAHOO.example.logApp = function() {
|
|
return {
|
|
init: function() {
|
|
if (YAHOO.widget.Logger) {
|
|
var reader = new YAHOO.widget.LogReader( "logDiv",
|
|
{ newestOnTop: true, height: "400px" } );
|
|
|
|
reader._onClickPauseBtn(null, reader);
|
|
}
|
|
}
|
|
};
|
|
} ();
|
|
|
|
YAHOO.util.Event.on(window, "load", YAHOO.example.logApp.init);
|
|
//]]>
|
|
</script>
|
|
|
|
<div id="logDiv"></div>
|
|
|
|
</div>
|
|
</div>
|
|
<!-- Nav and logger end -->
|
|
|
|
|
|
<div id="content">
|
|
<div class="newsItem">
|
|
<h3>RGB Slider</h3>
|
|
<p>
|
|
The RGB slider implements three slider controls to generate a
|
|
RGB color. The background color of each slider is also
|
|
dynamically modified to reflect the colors that could be
|
|
generated by moving a single slider.
|
|
</p>
|
|
<strong>The logger is paused for performance reasons. Click "Resume" to re-enable it.</strong>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="ddRGB" class="dragPanel">
|
|
<h4 id="pickerHandle"> </h4>
|
|
<div id="rBG" class="bg" tabindex="1" hidefocus="true">
|
|
<div id="rthumb" class="thumb"><img src="img/vline.png" /></div>
|
|
</div>
|
|
|
|
<div id="gBG" class="bg" tabindex="2" hidefocus="true">
|
|
<div id="gthumb" class="thumb"><img src="img/vline.png" /></div>
|
|
</div>
|
|
|
|
<div id="bBG" class="bg" tabindex="3" hidefocus="true">
|
|
<div id="bthumb" class="thumb"><img src="img/vline.png" /></div>
|
|
</div>
|
|
|
|
|
|
<div id="valdiv">
|
|
<form name="rgbform">
|
|
<table border="0">
|
|
<tr>
|
|
<td>
|
|
RGB
|
|
</td>
|
|
<td>
|
|
<input autocomplete="off" tabindex="3" name="rval" id="rval" type="text" value="0" size="4" maxlength="4" />
|
|
<input autocomplete="off" tabindex="4" name="gval" id="gval" type="text" value="0" size="4" maxlength="4" />
|
|
<input autocomplete="off" tabindex="5" name="bval" id="bval" type="text" value="0" size="4" maxlength="4" />
|
|
</td>
|
|
<td>
|
|
<input tabindex="6" id="rgbSubmit" type="button" value="Update" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
Hex: #
|
|
</td>
|
|
<td>
|
|
<input autocomplete="off" tabindex="7" name="hexval" id="hexval" type="text" value="" size="6" maxlength="6" />
|
|
</td>
|
|
<td>
|
|
<input tabindex="8" id="hexSubmit" type="button" value="Update" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<input tabindex="9" id="resetButton" type="button" value="Reset" />
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</form>
|
|
</div>
|
|
|
|
<div id="swatch"> </div>
|
|
</div>
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
YAHOO.example.RGBSlider = function() {
|
|
|
|
var Event = YAHOO.util.Event;
|
|
var Dom = YAHOO.util.Dom;
|
|
var Color = YAHOO.util.Color;
|
|
var Slider = YAHOO.widget.Slider;
|
|
|
|
var r, g, b, dd;
|
|
|
|
function updateSliderColors() {
|
|
|
|
var curr, curg, curb;
|
|
|
|
curr = Math.min(r.getValue() * 2, 255);
|
|
curg = Math.min(g.getValue() * 2, 255);
|
|
curb = Math.min(b.getValue() * 2, 255);
|
|
|
|
YAHOO.log("updateSliderColor " + curr + ", " + curg + ", " + curb);
|
|
|
|
for (var i=0; i<34; i++) {
|
|
Dom.setStyle("rBG" + i, "background-color",
|
|
"rgb(" + (i*8) + "," + curg + "," + curb + ")");
|
|
|
|
Dom.setStyle("gBG" + i, "background-color",
|
|
"rgb(" + curr + "," + (i*8) + "," + curb + ")");
|
|
|
|
Dom.setStyle("bBG" + i, "background-color",
|
|
"rgb(" + curr + "," + curg + "," + (i*8) + ")");
|
|
}
|
|
|
|
Dom.setStyle("swatch", "background-color",
|
|
"rgb(" + curr + "," + curg + "," + curb + ")");
|
|
|
|
Dom.get("hexval").value = Color.rgb2hex(curr, curg, curb);
|
|
}
|
|
|
|
|
|
function listenerUpdate(whichSlider, newVal) {
|
|
newVal = Math.min(255, newVal);
|
|
Dom.get(whichSlider + "val").value = newVal;
|
|
updateSliderColors();
|
|
}
|
|
|
|
return {
|
|
|
|
userReset: function() {
|
|
var v;
|
|
var f = document.forms['rgbform'];
|
|
|
|
r.setValue(0);
|
|
g.setValue(0);
|
|
b.setValue(0);
|
|
},
|
|
|
|
rgbInit: function() {
|
|
|
|
r = Slider.getHorizSlider("rBG", "rthumb", 0, 128);
|
|
r.subscribe("change", function(newVal) { listenerUpdate("r", newVal*2); });
|
|
|
|
g = Slider.getHorizSlider("gBG", "gthumb", 0, 128);
|
|
g.subscribe("change", function(newVal) { listenerUpdate("g", newVal*2); });
|
|
|
|
b = Slider.getHorizSlider("bBG", "bthumb", 0, 128);
|
|
b.subscribe("change", function(newVal) { listenerUpdate("b", newVal*2); });
|
|
|
|
this.initColor();
|
|
|
|
dd = new YAHOO.util.DD("ddRGB");
|
|
dd.setHandleElId("pickerHandle");
|
|
},
|
|
|
|
initColor: function() {
|
|
var ch = " ";
|
|
|
|
d = document.createElement("P");
|
|
d.className = "rb";
|
|
r.getEl().appendChild(d);
|
|
d = document.createElement("P");
|
|
d.className = "rb";
|
|
g.getEl().appendChild(d);
|
|
d = document.createElement("P");
|
|
d.className = "rb";
|
|
b.getEl().appendChild(d);
|
|
|
|
for (var i=0; i<34; i++) {
|
|
d = document.createElement("SPAN");
|
|
d.id = "rBG" + i
|
|
// d.innerHTML = ch;
|
|
r.getEl().appendChild(d);
|
|
|
|
d = document.createElement("SPAN");
|
|
d.id = "gBG" + i
|
|
// d.innerHTML = ch;
|
|
g.getEl().appendChild(d);
|
|
|
|
d = document.createElement("SPAN");
|
|
d.id = "bBG" + i
|
|
// d.innerHTML = ch;
|
|
b.getEl().appendChild(d);
|
|
}
|
|
|
|
d = document.createElement("P");
|
|
d.className = "lb";
|
|
r.getEl().appendChild(d);
|
|
d = document.createElement("P");
|
|
d.className = "lb";
|
|
g.getEl().appendChild(d);
|
|
d = document.createElement("P");
|
|
d.className = "lb";
|
|
b.getEl().appendChild(d);
|
|
|
|
this.userUpdate();
|
|
},
|
|
|
|
hexUpdate: function(e) {
|
|
return this.userUpdate(e, true);
|
|
},
|
|
|
|
userUpdate: function(e, isHex) {
|
|
var v;
|
|
var f = document.forms['rgbform'];
|
|
|
|
if (isHex) {
|
|
var hexval = f["hexval"].value;
|
|
// shorthand #369
|
|
if (hexval.length == 3) {
|
|
var newval = "";
|
|
for (var i=0;i<3;i++) {
|
|
var a = hexval.substr(i, 1);
|
|
newval += a + a;
|
|
}
|
|
|
|
hexval = newval;
|
|
}
|
|
|
|
YAHOO.log("hexval:" + hexval);
|
|
|
|
if (hexval.length != 6) {
|
|
alert("illegal hex code: " + hexval);
|
|
} else {
|
|
var rgb = Color.hex2rgb(hexval);
|
|
// alert(rgb.toString());
|
|
if (Color.isValidRGB(rgb)) {
|
|
f['rval'].value = rgb[0];
|
|
f['gval'].value = rgb[1];
|
|
f['bval'].value = rgb[2];
|
|
}
|
|
}
|
|
}
|
|
|
|
// red
|
|
v = parseFloat(f['rval'].value);
|
|
v = ( isNaN(v) ) ? 0 : Math.round(v);
|
|
YAHOO.log("setValue, r: " + v);
|
|
r.setValue(Math.round(v) / 2);
|
|
|
|
v = parseFloat(f['gval'].value);
|
|
v = ( isNaN(v) ) ? 0 : Math.round(v);
|
|
YAHOO.log("setValue, g: " + g);
|
|
g.setValue(Math.round(v) / 2);
|
|
|
|
v = parseFloat(f['bval'].value);
|
|
v = ( isNaN(v) ) ? 0 : Math.round(v);
|
|
YAHOO.log("setValue, b: " + b);
|
|
b.setValue(Math.round(v) / 2);
|
|
|
|
|
|
updateSliderColors();
|
|
|
|
if (e) {
|
|
Event.stopEvent(e);
|
|
}
|
|
},
|
|
|
|
init: function() {
|
|
this.rgbInit();
|
|
Event.on("rgbForm", "submit", this.userUpdate);
|
|
Event.on("rgbSubmit", "click", this.userUpdate);
|
|
Event.on("hexSubmit", "click", this.hexUpdate, this, true);
|
|
Event.on("resetButton", "click", this.userReset);
|
|
}
|
|
|
|
|
|
};
|
|
}();
|
|
|
|
YAHOO.util.Event.on(window, "load",
|
|
YAHOO.example.RGBSlider.init, YAHOO.example.RGBSlider, true);
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|