Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | 2x 2x 2x 116x 116x 2x 116x 2x 2x 6x 6x 6x 6x 116x 116x 116x 4x 138x 2x 22x 76x 24x 126x 126x 126x 126x 126x 126x 126x 98x 98x 98x 98x 98x 98x 98x | /**
* Copyright 2019 Adobe. All rights reserved.
* This file is licensed to you 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 REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import {ExtensibleSlider, Slider} from './Slider';
import range from '../templates/range';
import {commons, transform} from '../../../coral-utils';
import {Decorator} from '../../../coral-decorator';
/**
@class Coral.RangedSlider
@classdesc A Ranged Slider
@htmltag coral-rangedslider
@extends {Slider}
*/
const RangedSlider = Decorator(class extends ExtensibleSlider {
/**
Ranged sliders are always filled.
@type {Boolean}
@default true
@htmlattribute filled
@htmlattributereflected
*/
get filled() {
return true;
}
set filled(value) {
if (!transform.booleanAttr(value)) {
commons._log('warn', 'Coral.RangedSlider: filled can not be set to false.');
}
}
/**
This field's current value.
@type {String}
@default ""
@htmlattribute value
*/
get value() {
return this.startValue;
}
set value(value) {
this.startValue = value;
}
/**
The starting value of the range.
@type {String}
@default '1'
@emits {change}
@htmlattribute startValue
*/
get startValue() {
return this.values[0] || '1';
}
set startValue(value) {
// Snap value to step
value = String(this._snapValueToStep(transform.number(value), this.min, this.max, this.step));
const values = this.values;
values[0] = value;
this.values = values;
// in order to keep the reset value in sync, we need to handle the "startvalue" attribute of the inner input
const input = this._elements.inputs[0];
const valueAttribute = this.getAttribute('startvalue') || this.getAttribute('value');
input[valueAttribute ? 'setAttribute' : 'removeAttribute']('value', valueAttribute);
}
/**
The ending value of the range.
@type {String}
@default '100'
@emits {change}
@htmlattribute endValue
*/
get endValue() {
return this.values[1] || '100';
}
set endValue(value) {
// Snap value to step
value = String(this._snapValueToStep(transform.number(value), this.min, this.max, this.step));
const values = this.values;
values[1] = value;
this.values = values;
// in order to keep the reset value in sync, we need to handle the "endvalue" attribute of the inner input
const input = this._elements.inputs[1];
const valueAttribute = this.getAttribute('endvalue');
input[valueAttribute ? 'setAttribute' : 'removeAttribute']('value', valueAttribute);
}
/**
The current values of the ranged slider.
@type {Array.<String>}
@default [{@link Coral.RangedSlider#startValue},{@link Coral.RangedSlider#endValue}]
@emits {change}
*/
get values() {
return this._values;
}
set values(values) {
this._values = values;
}
/** @private */
_getHighestValue() {
return Math.max.apply(null, this.values);
}
/** @private */
_getLowestValue() {
return Math.min.apply(null, this.values);
}
/** @override */
_updateValue(handle, val) {
const idx = this._elements.handles.indexOf(handle);
if (idx === 0) {
if (val > parseFloat(this.values[1])) {
val = this.values[1];
}
this._elements.rightInput.min = val;
this._elements.rightHandle.setAttribute('aria-valuemin', val);
} else {
if (val < parseFloat(this.values[0])) {
val = this.values[0];
}
this._elements.leftInput.max = val;
this._elements.leftHandle.setAttribute('aria-valuemax', val);
}
const resValue = [this.values[0], this.values[1]];
resValue[idx] = val;
const oldValues = this.values;
this.values = resValue;
const newValues = this.values;
if (oldValues.join(':') !== newValues.join(':')) {
this.trigger('change');
}
}
/** @override */
_getTemplate() {
return range;
}
/**
Inherited from {@link BaseFormField#clear}.
*/
clear() {
this.startValue = this.min;
this.endValue = this.max;
}
/**
Inherited from {@link BaseFormField#reset}.
*/
reset() {
// since the 'value' property is not reflected, form components use it to restore the initial value. When a
// component has support for values, this method needs to be overwritten
const initialStartValue = this.getAttribute('startvalue') || this.getAttribute('value');
const initialEndValue = this.getAttribute('endvalue');
this.startValue = transform.string(initialStartValue);
this.endValue = transform.string(initialEndValue);
}
static get _attributePropertyMap() {
return commons.extend(super._attributePropertyMap, {
startvalue: 'startValue',
endvalue: 'endValue'
});
}
/** @ignore */
static get observedAttributes() {
return super.observedAttributes.concat([
'startvalue',
'endvalue'
]);
}
/** @ignore */
render() {
super.render();
this.classList.add('_coral-Slider--range');
// Set filled attribute by default
this.setAttribute('filled', '');
}
});
export default RangedSlider;
|