-
-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an example on number formatting to examples
- Loading branch information
1 parent
a70cc83
commit f6de8a7
Showing
6 changed files
with
80 additions
and
3 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,36 @@ | ||
<?php sect('formatting'); ?> | ||
<h1>Number formatting</h1> | ||
|
||
<section> | ||
|
||
<div class="view"> | ||
|
||
<p>noUiSlider has a <code>format</code> option to configure both incoming and outgoing formatting.</p> | ||
|
||
<p>In this example, the slider format uses <strong>no decimals</strong>. The <code>tooltips</code> use <strong>one decimal</strong>.</p> | ||
|
||
<p>The <code>from</code> function takes a formatted value to parse. It gets a string and should return a number.</p> | ||
|
||
<p>The <code>to</code> function takes a number to format. It gets a number and should return a string.</p> | ||
|
||
<p>noUiSlider can optionally be used with the <code>wNumb</code> library for formatting. See <a href="/nouislider/number-formatting/">the documentation on number formatting</a> for more details.</p> | ||
|
||
<div class="example"> | ||
<div id="formatting-slider"></div> | ||
<span class="example-val" id="formatting-start"></span> | ||
<span class="example-val" id="formatting-end"></span> | ||
<?php run('formatting-format'); ?> | ||
<?php run('formatting'); ?> | ||
</div> | ||
</div> | ||
|
||
<div class="side"> | ||
<?php code('formatting-format'); ?> | ||
|
||
<div class="viewer-header">Slider with formatting</div> | ||
|
||
<div class="viewer-content"> | ||
<?php code('formatting'); ?> | ||
</div> | ||
</div> | ||
</section> |
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
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,8 @@ | ||
var formatForSlider = { | ||
from: function (formattedValue) { | ||
return Number(formattedValue); | ||
}, | ||
to: function(numericValue) { | ||
return Math.round(numericValue); | ||
} | ||
}; |
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,31 @@ | ||
var formatSlider = document.getElementById('formatting-slider'); | ||
|
||
noUiSlider.create(formatSlider, { | ||
// Values are parsed as numbers using the "from" function in "format" | ||
start: ['20.0', '80.0'], | ||
range: { | ||
'min': 0, | ||
'max': 100 | ||
}, | ||
format: formatForSlider, | ||
tooltips: { | ||
// tooltips are output only, so only a "to" is needed | ||
to: function(numericValue) { | ||
return numericValue.toFixed(1); | ||
} | ||
} | ||
}); | ||
|
||
// Values are parsed as numbers using the "from" function in "format" | ||
formatSlider.noUiSlider.set(['25.666', '57.66']); | ||
|
||
var formatValues = [ | ||
document.getElementById('formatting-start'), | ||
document.getElementById('formatting-end') | ||
]; | ||
|
||
formatSlider.noUiSlider.on('update', function (values, handle, unencoded) { | ||
// "values" has the "to" function from "format" applied | ||
// "unencoded" contains the raw numerical slider values | ||
formatValues[handle].innerHTML = values[handle] + '<br><strong>No format:</strong> ' + unencoded[handle]; | ||
}); |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.noUi-tooltip { | ||
#slider-hide .noUi-tooltip { | ||
display: none; | ||
} | ||
.noUi-active .noUi-tooltip { | ||
#slider-hide .noUi-active .noUi-tooltip { | ||
display: block; | ||
} |