1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
// Copyright 2006 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @fileoverview A slider implementation that allows to select a value within a
* range by dragging a thumb. The selected value is exposed through getValue().
*
* To decorate, the slider should be bound to an element with the class name
* 'goog-slider-[vertical / horizontal]' containing a child with the classname
* 'goog-slider-thumb'.
*
* Decorate Example:
* <div id="slider" class="goog-slider-horizontal">
* <div class="goog-twothumbslider-thumb">
* </div>
* <script>
*
* var slider = new goog.ui.Slider;
* slider.decorate(document.getElementById('slider'));
*
* @author arv@google.com (Erik Arvidsson)
* @see ../demos/slider.html
*/
// Implementation note: We implement slider by inheriting from baseslider,
// which allows to select sub-ranges within a range using two thumbs. All we do
// is we co-locate the two thumbs into one.
goog.provide('goog.ui.Slider');
goog.provide('goog.ui.Slider.Orientation');
goog.require('goog.dom');
goog.require('goog.dom.a11y');
goog.require('goog.dom.a11y.Role');
goog.require('goog.ui.SliderBase');
goog.require('goog.ui.SliderBase.Orientation');
/**
* This creates a slider object.
* @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper.
* @constructor
* @extends {goog.ui.SliderBase}
*/
goog.ui.Slider = function(opt_domHelper) {
goog.ui.SliderBase.call(this, opt_domHelper);
this.rangeModel.setExtent(0);
};
goog.inherits(goog.ui.Slider, goog.ui.SliderBase);
/**
* Expose Enum of superclass (representing the orientation of the slider) within
* Slider namespace.
*
* @enum {string}
*/
goog.ui.Slider.Orientation = goog.ui.SliderBase.Orientation;
/**
* The prefix we use for the CSS class names for the slider and its elements.
* @type {string}
*/
goog.ui.Slider.CSS_CLASS_PREFIX = goog.getCssName('goog-slider');
/**
* CSS class name for the single thumb element.
* @type {string}
*/
goog.ui.Slider.THUMB_CSS_CLASS =
goog.getCssName(goog.ui.Slider.CSS_CLASS_PREFIX, 'thumb');
/**
* Returns CSS class applied to the slider element.
* @param {goog.ui.SliderBase.Orientation} orient Orientation of the slider.
* @return {string} The CSS class applied to the slider element.
* @protected
* @override
*/
goog.ui.Slider.prototype.getCssClass = function(orient) {
return orient == goog.ui.SliderBase.Orientation.VERTICAL ?
goog.getCssName(goog.ui.Slider.CSS_CLASS_PREFIX, 'vertical') :
goog.getCssName(goog.ui.Slider.CSS_CLASS_PREFIX, 'horizontal');
};
/** @override */
goog.ui.Slider.prototype.createThumbs = function() {
// find thumb
var element = this.getElement();
var thumb = goog.dom.getElementsByTagNameAndClass(
null, goog.ui.Slider.THUMB_CSS_CLASS, element)[0];
if (!thumb) {
thumb = this.createThumb_();
element.appendChild(thumb);
}
this.valueThumb = this.extentThumb = thumb;
};
/**
* Creates the thumb element.
* @return {HTMLDivElement} The created thumb element.
* @private
*/
goog.ui.Slider.prototype.createThumb_ = function() {
var thumb =
this.getDomHelper().createDom('div', goog.ui.Slider.THUMB_CSS_CLASS);
goog.dom.a11y.setRole(thumb, goog.dom.a11y.Role.BUTTON);
return /** @type {HTMLDivElement} */ (thumb);
};
|