<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example: Dial With Interactive UI</title>
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/css/main.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="../../build/yui/yui-min.js"></script>
</head>
<body>
<!--
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
-->
<div id="doc">
<div id="hd">
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
</div>
<a href="#toc" class="jump">Jump to Table of Contents</a>
<h1>Example: Dial With Interactive UI</h1>
<div class="yui3-g">
<div class="yui3-u-3-4">
<div id="main">
<div class="content"><div class="intro">
<p>This <code>Dial</code> widget example shows the following:</p>
<ol>
<li>A demonstration of a large value range combined with fine increment control.</li>
<li>Setting UI strings before rendering</li>
<li>Setting configuration attributes</li>
<li>Construction-time event subscription allowing Dial to control an interactive UI</li>
<li>Calling one of Dial's value change methods from the click of a link. <code><a>Hubble</a></code></li>
</ol>
<p>Notice the Dial can traverse the entire 6,000+ pixels of the scene height, but by pulling the handle
farther away from the Dial's center while rotating, the user can get 1 pixel movements, without strain.
After the dial has focus, the following keys also opperate the Dial, arrow up/down/left/right, page up/down, home, end. The action of these keys can be controlled via <a href="index.html#attributes" title="YUI 3: Dial">Dial's configuration attributes</a>.</p>
</div>
<div class="example yui3-skin-sam">
<style>
#example_container {
position:relative;
}
#demo{
margin:0;
position:absolute;
top:321px;
left:0;
}
.controls {
position:absolute;
top:0;
left:328px;
margin:0 0 0 0;
color:#808080;
width:300px;
}
.controls a {
color:#4B78D9 !important;
cursor:pointer;
}
.intro-sentence{
font-size: 183%;
left: 0;
line-height: 0.9em;
position: absolute;
top: 273px;
width: 6em;
}
#view_frame{
position:relative;
height:500px;
width:300px;
border:solid 1px #cccccc;
overflow:hidden;
}
#scene{position:absolute;
left:0;
top:-6440px;
height:6440px;
width:100%;
background:url(../assets/dial/images/earth_to_hubble_bkg.png) repeat;
}
#altitude_mark {
border-top:solid 1px #CCCCCC;
left:-33px;
position:absolute;
top:403px;
width:30px;
}
#earth{
position:absolute;
left:0;
top:5834px;
height:214px;
width:300px;
}
#hubble{
position:absolute;
left:5px;
top:7px;
height:393px;
width:300px;
}
#stars{
position:absolute;
left:0;
top:0;
background:url(../assets/dial/images/stars.png) repeat;
height:5000px;
width:300px;
}
.label{
text-transform:uppercase;
width:100%;
letter-spacing:5px;
font-family:Verdana;
font-size:85%;
position:absolute;
left:0;
text-align:center;
}
.hubble{
bottom:6023px;
color:#612C88;
}
.thermosphere{
bottom:1290px;
color:#5A009D;
}
.mesosphere{
bottom:840px;
color:#570BFF;
}
.stratosphere{
bottom:540px;
color:#006999;
}
.troposphere{
bottom:477px;
color:#036585;
}
.ozone{
bottom:692px;
color:#005AAE;
}
.crust{
bottom:270px;
color:#4F2D00;
}
.mantle{
bottom:42px;
color:#897701;
}
</style>
<div id="example_container">
<div id="view_frame">
<div id="scene">
<div id="stars"></div>
<img id="hubble" src="http://yuilibrary.com/yui/docs/assets/dial/images/hubble.png"/>
<img id="earth" src="http://yuilibrary.com/yui/docs/assets/dial/images/mountain_earth.png"/>
<div class="label hubble">hubble</div>
<div class="label thermosphere">thermosphere</div>
<div class="label mesosphere">mesosphere</div>
<div class="label stratosphere">stratosphere</div>
<div class="label troposphere">troposphere</div>
<div class="label ozone">ozone</div>
<div class="label crust">crust</div>
<div class="label mantle">mantle</div>
</div>
</div>
<div class="controls">
<div class="intro-sentence">From Earth to <a id="a-hubble">Hubble</a></div>
<div id="altitude_mark"></div>
<div id="demo"></div>
</div>
</div>
<script>
YUI().use('dial', function(Y) {
var sceneH = Y.one('#scene').get('region').height,
subSea = 450,
viewFrameH = Y.one('#view_frame').get('region').height -2,
zeroPt = 100,
originY = -sceneH + subSea + viewFrameH - zeroPt;
Y.one('#scene').setStyle('top', originY + 'px');
/**
* The Dial's valueChange event is passed to this.
* sets the CSS top value of the pictoral scene of the earth to the hubble.
* This scene is an absolute positioned div inside another div with
* overflow set to hidden.
*/
setSceneY = function(e) {
Y.one('#scene').setStyle('top', (originY + (e.newVal * 10)) + 'px');
}
var dial = new Y.Dial({
min:-35,
max:559,
stepsPerRevolution:30,
value: 0,
diameter: 100,
minorStep: 1,
majorStep: 10,
decimalPlaces: 2,
strings:{label:'Altitude in Kilometers:', resetStr: 'Reset', tooltipHandle: 'Drag to set'},
// construction-time event subscription
after : {
valueChange: Y.bind( setSceneY, dial )
}
});
dial.render('#demo');
// Function that calls a method in Dial that sets its value to the value of the max config attribute
// Other methods available include,
// _setToMin(), _resetDial(), _incrMinor(), _decrMinor(), _incrMajor(), _decrMajor(),
var setDialToMax = function(e){
e.preventDefault();
this._setToMax();
}
// Subscribe to the click of the "Hubble" anchor, passing the dial as the 'this'
Y.on('click', setDialToMax, '#a-hubble', dial);
});
</script>
</div>
<h3 id="making-a-dial-drive-an-interactive-ui">Making a Dial Drive an Interactive UI</h3>
<p>The <code>valueChange</code> event of a <code>Dial</code> can be the means of controlling other UI displayed on a page.</p>
<h4 id="the-markup">The Markup</h4>
<p>
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the
page's <code><body></code> element or to a parent element of the widget in order to apply
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>.
</p>
<pre class="code prettyprint"><body class="yui3-skin-sam"> <!-- You need this skin class --></pre>
<p>The only markup requirement for the <code>Dial</code> itself is an element to contain the Dial.
The rest of the markup and CSS in this example is just for the Hubble telescope visualization.
</p>
<pre class="code prettyprint"><div id="demo"></div></pre>
<h4 id="the-javascript">The JavaScript</h4>
<p>This example builds on previous examples by showing how to modify the visible UI strings before the dial renders.</p>
<p>During instatiation of a Dial, several configuration attributes can be set (see the code-block below); note the construction-time event subscription:</p>
<pre class="code prettyprint">YUI().use('dial', function(Y) {
var sceneH = Y.one('#scene').get('region').height,
subSea = 450,
viewFrameH = Y.one('#view_frame').get('region').height -2,
zeroPt = 100,
originY = -sceneH + subSea + viewFrameH - zeroPt;
Y.one('#scene').setStyle('top', originY + 'px');
/**
* The Dial's valueChange event is passed to this.
* sets the CSS top value of the pictoral scene of the earth to the hubble.
* This scene is an absolute positioned div inside another div with
* overflow set to hidden.
*/
setSceneY = function(e) {
Y.one('#scene').setStyle('top', (originY + (e.newVal * 10)) + 'px');
}
var dial = new Y.Dial({
min:-35,
max:559,
stepsPerRevolution:30,
value: 0,
diameter: 100,
minorStep: 1,
majorStep: 10,
decimalPlaces: 2,
strings:{label:'Altitude in Kilometers:', resetStr: 'Reset', tooltipHandle: 'Drag to set'},
// construction-time event subscription
after : {
valueChange: Y.bind( setSceneY, dial )
}
});
dial.render('#demo');
// Function that calls a method in Dial that sets its value to the value of the max config attribute
// Other methods available include,
// _setToMin(), _resetDial(), _incrMinor(), _decrMinor(), _incrMajor(), _decrMajor(),
var setDialToMax = function(e){
e.preventDefault();
this._setToMax();
}
// Subscribe to the click of the "Hubble" anchor, passing the dial as the 'this'
Y.on('click', setDialToMax, '#a-hubble', dial);
});</pre>
<h5 id="the-event-handler">The Event Handler</h5>
<p>
Preceding the code that instantiates the <code>Dial</code> widget, declare the event handler.
We can use the value of the <code>Dial</code> to do whatever we want, but
in this example the event handler updates the CSS <code>top</code> property of the pictorial scene <code><div id="scene"></code> of Hubble's relationship to Earth.
This scene is moved up or down inside a framing element <code><div class="viewframe"></code> that has CSS <code>overflow:hidden;</code>.
The reason <code>e.newVal</code> is multiplied by <code>10</code> is so that the scene moves 10px for every 1 kilometer of the <code>Dial</code>'s value.
</p>
<pre class="code prettyprint">/**
* The Dial's valueChange event is passed to this.
* sets the CSS top value of the pictoral scene of the earth to the hubble.
* This scene is an absolute positioned div inside another div with
* overflow set to hidden.
*/
setSceneY = function(e) {
Y.one('#scene').setStyle('top', (originY + (e.newVal * 10)) + 'px');
}</pre>
<h3 id="complete-example-source">Complete Example Source</h3>
<pre class="code prettyprint"><!DOCTYPE HTML>
<html>
<script src="http://yui.yahooapis.com/3.10.3/build/yui/yui-min.js"></script>
<style>
#example_container {
position:relative;
}
#demo{
margin:0;
position:absolute;
top:321px;
left:0;
}
.controls {
position:absolute;
top:0;
left:328px;
margin:0 0 0 0;
color:#808080;
width:300px;
}
.controls a {
color:#4B78D9 !important;
cursor:pointer;
}
.intro-sentence{
font-size: 183%;
left: 0;
line-height: 0.9em;
position: absolute;
top: 273px;
width: 6em;
}
#view_frame{
position:relative;
height:500px;
width:300px;
border:solid 1px #cccccc;
overflow:hidden;
}
#scene{position:absolute;
left:0;
top:-6440px;
height:6440px;
width:100%;
background:url(../assets/dial/images/earth_to_hubble_bkg.png) repeat;
}
#altitude_mark {
border-top:solid 1px #CCCCCC;
left:-33px;
position:absolute;
top:403px;
width:30px;
}
#earth{
position:absolute;
left:0;
top:5834px;
height:214px;
width:300px;
}
#hubble{
position:absolute;
left:5px;
top:7px;
height:393px;
width:300px;
}
#stars{
position:absolute;
left:0;
top:0;
background:url(../assets/dial/images/stars.png) repeat;
height:5000px;
width:300px;
}
.label{
text-transform:uppercase;
width:100%;
letter-spacing:5px;
font-family:Verdana;
font-size:85%;
position:absolute;
left:0;
text-align:center;
}
.hubble{
bottom:6023px;
color:#612C88;
}
.thermosphere{
bottom:1290px;
color:#5A009D;
}
.mesosphere{
bottom:840px;
color:#570BFF;
}
.stratosphere{
bottom:540px;
color:#006999;
}
.troposphere{
bottom:477px;
color:#036585;
}
.ozone{
bottom:692px;
color:#005AAE;
}
.crust{
bottom:270px;
color:#4F2D00;
}
.mantle{
bottom:42px;
color:#897701;
}
</style>
<body class="yui3-skin-sam"> <!-- You need this skin class -->
<div id="example_container">
<div id="view_frame">
<div id="scene">
<div id="stars"></div>
<img id="hubble" src="http://yuilibrary.com/yui/docs/assets/dial/images/hubble.png"/>
<img id="earth" src="http://yuilibrary.com/yui/docs/assets/dial/images/mountain_earth.png"/>
<div class="label hubble">hubble</div>
<div class="label thermosphere">thermosphere</div>
<div class="label mesosphere">mesosphere</div>
<div class="label stratosphere">stratosphere</div>
<div class="label troposphere">troposphere</div>
<div class="label ozone">ozone</div>
<div class="label crust">crust</div>
<div class="label mantle">mantle</div>
</div>
</div>
<div class="controls">
<div class="intro-sentence">From Earth to <a id="a-hubble">Hubble</a></div>
<div id="altitude_mark"></div>
<div id="demo"></div>
</div>
</div>
</body>
<script>
YUI().use('dial', function(Y) {
var sceneH = Y.one('#scene').get('region').height,
subSea = 450,
viewFrameH = Y.one('#view_frame').get('region').height -2,
zeroPt = 100,
originY = -sceneH + subSea + viewFrameH - zeroPt;
Y.one('#scene').setStyle('top', originY + 'px');
/**
* The Dial's valueChange event is passed to this.
* sets the CSS top value of the pictoral scene of the earth to the hubble.
* This scene is an absolute positioned div inside another div with
* overflow set to hidden.
*/
setSceneY = function(e) {
Y.one('#scene').setStyle('top', (originY + (e.newVal * 10)) + 'px');
}
var dial = new Y.Dial({
min:-35,
max:559,
stepsPerRevolution:30,
value: 0,
diameter: 100,
minorStep: 1,
majorStep: 10,
decimalPlaces: 2,
strings:{label:'Altitude in Kilometers:', resetStr: 'Reset', tooltipHandle: 'Drag to set'},
// construction-time event subscription
after : {
valueChange: Y.bind( setSceneY, dial )
}
});
dial.render('#demo');
// Function that calls a method in Dial that sets its value to the value of the max config attribute
// Other methods available include,
// _setToMin(), _resetDial(), _incrMinor(), _decrMinor(), _incrMajor(), _decrMajor(),
var setDialToMax = function(e){
e.preventDefault();
this._setToMax();
}
// Subscribe to the click of the "Hubble" anchor, passing the dial as the 'this'
Y.on('click', setDialToMax, '#a-hubble', dial);
});
</script>
</html></pre>
</div>
</div>
</div>
<div class="yui3-u-1-4">
<div class="sidebar">
<div id="toc" class="sidebox">
<div class="hd">
<h2 class="no-toc">Table of Contents</h2>
</div>
<div class="bd">
<ul class="toc">
<li>
<a href="#making-a-dial-drive-an-interactive-ui">Making a Dial Drive an Interactive UI</a>
<ul class="toc">
<li>
<a href="#the-markup">The Markup</a>
</li>
<li>
<a href="#the-javascript">The JavaScript</a>
<ul class="toc">
<li>
<a href="#the-event-handler">The Event Handler</a>
</li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#complete-example-source">Complete Example Source</a>
</li>
</ul>
</div>
</div>
<div class="sidebox">
<div class="hd">
<h2 class="no-toc">Examples</h2>
</div>
<div class="bd">
<ul class="examples">
<li data-description="Create a Dial from existing markup on the page - a simple use case.">
<a href="dial-basic.html">Basic Dial</a>
</li>
<li data-description="Link a Dial with a text input field.">
<a href="dial-text-input.html">Dial Linked With Text Input</a>
</li>
<li data-description="Use image backgrounds to control the visual display of a Dial.">
<a href="dial-image-background.html">Dial With Image Background</a>
</li>
<li data-description="Use images to surround a Dial instance and provide additional styling.">
<a href="dial-image-surrounding.html">Dial With a Surrounding Image</a>
</li>
<li data-description="This example employs Dial to drive an interactive UI.">
<a href="dial-interactive.html">Dial With Interactive UI</a>
</li>
<li data-description="This example shows how to use Dial to animate an image sprite.">
<a href="duck.html">Image Sprite Animation with Dial</a>
</li>
</ul>
</div>
</div>
<div class="sidebox">
<div class="hd">
<h2 class="no-toc">Examples That Use This Component</h2>
</div>
<div class="bd">
<ul class="examples">
<li data-description="Use the HSL color picker to select a new color. Then chose the color type you like best.">
<a href="../color/hsl-picker.html">HSL Color Picker</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script>
YUI.Env.Tests = {
examples: [],
project: '../assets',
assets: '../assets/dial',
name: 'dial-interactive',
title: 'Dial With Interactive UI',
newWindow: '',
auto: false
};
YUI.Env.Tests.examples.push('dial-basic');
YUI.Env.Tests.examples.push('dial-text-input');
YUI.Env.Tests.examples.push('dial-image-background');
YUI.Env.Tests.examples.push('dial-image-surrounding');
YUI.Env.Tests.examples.push('dial-interactive');
YUI.Env.Tests.examples.push('duck');
YUI.Env.Tests.examples.push('hsl-picker');
</script>
<script src="../assets/yui/test-runner.js"></script>
</body>
</html>