-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unknown
committed
Mar 17, 2019
1 parent
c3cc682
commit f262306
Showing
7 changed files
with
262 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
@supports (--css: variables) { | ||
input[type="range"].multirange { | ||
padding: 0; | ||
margin: 5px; | ||
display: inline-block; | ||
vertical-align: top; | ||
-webkit-appearance: none; | ||
background-color: transparent; | ||
} | ||
input[type="range"].multirange.original { | ||
position: absolute; | ||
} | ||
input[type="range"].multirange.original::-webkit-slider-thumb { | ||
position: relative; | ||
z-index: 2; | ||
} | ||
input[type="range"].multirange.original::-moz-range-thumb { | ||
transform: scale(1); | ||
/* FF doesn't apply position it seems */ | ||
z-index: 1; | ||
} | ||
input[type="range"].multirange::-moz-range-track { | ||
border-color: transparent; | ||
/* needed to switch FF to "styleable" control */ | ||
} | ||
input[type="range"].multirange.ghost { | ||
position: relative; | ||
background: var(--track-background); | ||
--track-background: linear-gradient(to right, rgb(189, 193, 199) var(--low), var(--range-color) 0, var(--range-color) var(--high), rgb(189, 193, 199) 0) no-repeat 0 45% / 100% 20%; | ||
--range-color: #bc9352; | ||
width: 300px; | ||
} | ||
input[type="range"].multirange.ghost::-webkit-slider-runnable-track { | ||
background: var(--track-background); | ||
} | ||
input[type="range"].multirange.ghost::-moz-range-track { | ||
background: var(--track-background); | ||
} | ||
input[type="range"].multirange::-webkit-slider-thumb { | ||
pointer-events: all; | ||
position: relative; | ||
z-index: 1; | ||
outline: 0; | ||
-webkit-appearance: none; | ||
border: none; | ||
width: 28px; | ||
height: 11px; | ||
background-image: url(../images/price-range.png)/* W3C */ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
(function() { | ||
"use strict"; | ||
|
||
var supportsMultiple = self.HTMLInputElement && "valueLow" in HTMLInputElement.prototype; | ||
|
||
var descriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value"); | ||
let price = document.querySelector(".rangePrice"); | ||
var multirange = function(input) { | ||
if (supportsMultiple || input.classList.contains("multirange")) { | ||
return; | ||
} | ||
|
||
var value = input.getAttribute("value"); | ||
var values = value === null ? [] : value.split(","); | ||
var min = +(input.min || 0); | ||
var max = +(input.max || 300); | ||
var ghost = input.cloneNode(); | ||
|
||
input.classList.add("multirange", "original"); | ||
ghost.classList.add("multirange", "ghost"); | ||
|
||
input.value = values[0] || min + (max - min) / 2; | ||
ghost.value = values[1] || min + (max - min) / 2; | ||
|
||
input.parentNode.insertBefore(ghost, input.nextSibling); | ||
|
||
Object.defineProperty(input, "originalValue", descriptor.get ? descriptor : { | ||
// Fuck you Safari >:( | ||
get: function() { return this.value; }, | ||
set: function(v) { this.value = v; } | ||
}); | ||
|
||
Object.defineProperties(input, { | ||
valueLow: { | ||
get: function() { return Math.min(this.originalValue, ghost.value); }, | ||
set: function(v) { this.originalValue = v; }, | ||
enumerable: true | ||
}, | ||
valueHigh: { | ||
get: function() { return Math.max(this.originalValue, ghost.value); }, | ||
set: function(v) { ghost.value = v; }, | ||
enumerable: true | ||
} | ||
}); | ||
|
||
if (descriptor.get) { | ||
// Again, fuck you Safari | ||
Object.defineProperty(input, "value", { | ||
get: function() { return this.valueLow + "," + this.valueHigh; }, | ||
set: function(v) { | ||
var values = v.split(","); | ||
this.valueLow = values[0]; | ||
this.valueHigh = values[1]; | ||
update(); | ||
}, | ||
enumerable: true | ||
}); | ||
} | ||
|
||
if (typeof input.oninput === "function") { | ||
ghost.oninput = input.oninput.bind(input); | ||
} | ||
|
||
function update() { | ||
ghost.style.setProperty("--low", 100 * ((input.valueLow - min) / (max - min)) + 1 + "%"); | ||
ghost.style.setProperty("--high", 100 * ((input.valueHigh - min) / (max - min)) - 1 + "%"); | ||
price.innerHTML = "$ " + parseFloat(input.value) + "M - $" + parseFloat(ghost.value) + "M"; | ||
} | ||
|
||
input.addEventListener("input", update); | ||
ghost.addEventListener("input", update); | ||
|
||
update(); | ||
} | ||
|
||
multirange.init = function() { | ||
[].slice.call(document.querySelectorAll("input[type=range][multiple]:not(.multirange)")).forEach(multirange); | ||
} | ||
|
||
if (typeof module === "undefined") { | ||
self.multirange = multirange; | ||
if (document.readyState == "loading") { | ||
document.addEventListener("DOMContentLoaded", multirange.init); | ||
} else { | ||
multirange.init(); | ||
} | ||
} else { | ||
module.exports = multirange; | ||
} | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.