| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<!-- |
| 4 |
Copyright 2010 The Closure Library Authors. All Rights Reserved. |
| 5 |
|
| 6 |
Use of this source code is governed by the Apache License, Version 2.0. |
| 7 |
See the COPYING file for details. |
| 8 |
--> |
| 9 |
<head> |
| 10 |
<title>goog.ui.Slider</title> |
| 11 |
<meta charset="utf-8"> |
| 12 |
<script src="../base.js"></script> |
| 13 |
<script> |
| 14 |
goog.require('goog.dom'); |
| 15 |
goog.require('goog.ui.Component'); |
| 16 |
goog.require('goog.ui.Slider'); |
| 17 |
</script> |
| 18 |
<link rel="stylesheet" href="css/demo.css"> |
| 19 |
<style> |
| 20 |
.goog-slider-vertical, |
| 21 |
.goog-slider-horizontal { |
| 22 |
background-color: ThreeDFace; |
| 23 |
position: relative; |
| 24 |
overflow: hidden; |
| 25 |
} |
| 26 |
.goog-slider-thumb { |
| 27 |
position: absolute; |
| 28 |
background-color: ThreeDShadow; |
| 29 |
overflow: hidden; |
| 30 |
} |
| 31 |
|
| 32 |
.goog-slider-vertical .goog-slider-thumb { |
| 33 |
left: 0; |
| 34 |
height: 20px; |
| 35 |
width: 100%; |
| 36 |
} |
| 37 |
|
| 38 |
.goog-slider-horizontal .goog-slider-thumb { |
| 39 |
top: 0; |
| 40 |
width: 20px; |
| 41 |
height: 100%; |
| 42 |
} |
| 43 |
.goog-slider-disabled { |
| 44 |
background-color: lightgray |
| 45 |
} |
| 46 |
#s-h { |
| 47 |
margin-bottom: 2em; |
| 48 |
} |
| 49 |
strong { |
| 50 |
display: block; |
| 51 |
margin-bottom: 3px; |
| 52 |
} |
| 53 |
</style> |
| 54 |
</head> |
| 55 |
<body> |
| 56 |
<h1>goog.ui.Slider</h1> |
| 57 |
|
| 58 |
<div id="s-h"> |
| 59 |
<strong>Horizontal Slider</strong> |
| 60 |
<div id="s1" class="goog-slider" style="width: 200px; height: 20px"> |
| 61 |
<!-- this line is here just to show that custom content can be added --> |
| 62 |
<div style="position:absolute;width:100%;top:9px;border:1px inset white; |
| 63 |
overflow:hidden;height:0"></div> |
| 64 |
<div class="goog-slider-thumb"></div> |
| 65 |
</div> |
| 66 |
<input type="checkbox" onclick="s.setMoveToPointEnabled(this.checked)"> |
| 67 |
MoveToPointEnabled |
| 68 |
<input type="checkbox" onclick="s.setEnabled(this.checked)" checked> |
| 69 |
Enable |
| 70 |
<br> |
| 71 |
<input type="text" value="0" id="out1" style="margin-left: 0px"> |
| 72 |
<input type="button" value="Set Value" onclick="setSliderValue(s, 'out1')"> |
| 73 |
</div> |
| 74 |
|
| 75 |
<div id="s-v"> |
| 76 |
<strong>Vertical Slider, inserted w/ script</strong> |
| 77 |
<label id="s2-label"> |
| 78 |
<input type="checkbox" onclick="s2.setMoveToPointEnabled(this.checked)"> |
| 79 |
MoveToPointEnabled |
| 80 |
</label> |
| 81 |
<input type="checkbox" onclick="s2.setEnabled(this.checked)" checked> |
| 82 |
Enable |
| 83 |
<br> |
| 84 |
<input type="text" value="0" id="out2" style="margin-left: 0px"> |
| 85 |
<input type="button" value="Set Value" onclick="setSliderValue(s2, 'out2')"> |
| 86 |
</div> |
| 87 |
<script> |
| 88 |
|
| 89 |
var el = document.getElementById('s1'); |
| 90 |
var s = new goog.ui.Slider; |
| 91 |
s.decorate(el); |
| 92 |
s.addEventListener(goog.ui.Component.EventType.CHANGE, function() { |
| 93 |
document.getElementById('out1').value = s.getValue(); |
| 94 |
}); |
| 95 |
|
| 96 |
|
| 97 |
var s2 = new goog.ui.Slider; |
| 98 |
s2.setOrientation(goog.ui.Slider.Orientation.VERTICAL); |
| 99 |
s2.createDom(); |
| 100 |
var el = s2.getElement(); |
| 101 |
el.style.width = '20px'; |
| 102 |
el.style.height = '200px'; |
| 103 |
s2.render(document.body); |
| 104 |
s2.setStep(null); |
| 105 |
s2.addEventListener(goog.ui.Component.EventType.CHANGE, function() { |
| 106 |
document.getElementById('out2').value = s2.getValue(); |
| 107 |
}); |
| 108 |
|
| 109 |
var label = document.getElementById('s2-label'); |
| 110 |
label.parentNode.insertBefore(el, label); |
| 111 |
|
| 112 |
function toggleSliderEnable(button, slider) { |
| 113 |
var buttonValue = slider.isEnabled() ? 'Enable Slider' : 'Disable Slider'; |
| 114 |
button.value = buttonValue; |
| 115 |
slider.setEnabled(!slider.isEnabled()); |
| 116 |
} |
| 117 |
|
| 118 |
function setSliderValue(slider, textId) { |
| 119 |
if (document.getElementById(textId)) { |
| 120 |
var value = document.getElementById(textId).value; |
| 121 |
window.console.log(value); |
| 122 |
slider.setValue(new Number(value)); |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
</script> |
| 127 |
</body> |
| 128 |
</html> |