Initial commit

This commit is contained in:
2023-10-04 17:24:40 +02:00
commit 515c7259d8
144 changed files with 118578 additions and 0 deletions

21
static/LICENSE Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014-2018 Materialize
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

91
static/README.md Normal file
View File

@@ -0,0 +1,91 @@
<p align="center">
<a href="http://materializecss.com/">
<img src="http://materializecss.com/res/materialize.svg" width="150">
</a>
</p>
<h3 align="center">MaterializeCSS</h3>
<p align="center">
Materialize, a CSS Framework based on material design.
<br>
<a href="http://materializecss.com/"><strong>-- Browse the docs --</strong></a>
<br>
<br>
<a href="https://travis-ci.org/Dogfalo/materialize">
<img src="https://travis-ci.org/Dogfalo/materialize.svg?branch=master" alt="Travis CI badge">
</a>
<a href="https://badge.fury.io/js/materialize-css">
<img src="https://badge.fury.io/js/materialize-css.svg" alt="npm version badge">
</a>
<a href="https://cdnjs.com/libraries/materialize">
<img src="https://img.shields.io/cdnjs/v/materialize.svg" alt="CDNJS version badge">
</a>
<a href="https://david-dm.org/Dogfalo/materialize">
<img src="https://david-dm.org/Dogfalo/materialize/status.svg" alt="dependencies Status badge">
</a>
<a href="https://david-dm.org/Dogfalo/materialize#info=devDependencies">
<img src="https://david-dm.org/Dogfalo/materialize/dev-status.svg" alt="devDependency Status badge">
</a>
<a href="https://gitter.im/Dogfalo/materialize">
<img src="https://badges.gitter.im/Join%20Chat.svg" alt="Gitter badge">
</a>
</p>
## Table of Contents
- [Quickstart](#quickstart)
- [Documentation](#documentation)
- [Supported Browsers](#supported-browsers)
- [Changelog](#changelog)
- [Testing](#testing)
- [Contributing](#contributing)
- [Copyright and license](#copyright-and-license)
## Quickstart:
Read the [getting started guide](http://materializecss.com/getting-started.html) for more information on how to use materialize.
- [Download the latest release](https://github.com/Dogfalo/materialize/releases/latest) of materialize directly from GitHub. ([Beta](https://github.com/Dogfalo/materialize/releases/))
- Clone the repo: `git clone https://github.com/Dogfalo/materialize.git` (Beta: `git clone -b v1-dev https://github.com/Dogfalo/materialize.git`)
- Include the files via [cdnjs](https://cdnjs.com/libraries/materialize). More [here](http://materializecss.com/getting-started.html). ([Beta](https://cdnjs.com/libraries/materialize/1.0.0-beta))
- Install with [npm](https://www.npmjs.com): `npm install materialize-css` (Beta: `npm install materialize-css@next`)
- Install with [Bower](https://bower.io): `bower install materialize` ([DEPRECATED](https://bower.io/blog/2017/how-to-migrate-away-from-bower/))
- Install with [Atmosphere](https://atmospherejs.com): `meteor add materialize:materialize` (Beta: `meteor add materialize:materialize@=1.0.0-beta`)
## Documentation
The documentation can be found at <http://materializecss.com>. To run the documentation locally on your machine, you need [Node.js](https://nodejs.org/en/) installed on your computer.
### Running documentation locally
Run these commands to set up the documentation:
```bash
git clone https://github.com/Dogfalo/materialize
cd materialize
npm install
```
Then run `grunt monitor` to compile the documentation. When it finishes, open a new browser window and navigate to `localhost:8000`. We use [BrowserSync](https://www.browsersync.io/) to display the documentation.
### Documentation for previous releases
Previous releases and their documentation are available for [download](https://github.com/Dogfalo/materialize/releases).
## Supported Browsers:
Materialize is compatible with:
- Chrome 35+
- Firefox 31+
- Safari 9+
- Opera
- Edge
- IE 11+
## Changelog
For changelogs, check out [the Releases section of materialize](https://github.com/Dogfalo/materialize/releases) or the [CHANGELOG.md](CHANGELOG.md).
## Testing
We use Jasmine as our testing framework and we're trying to write a robust test suite for our components. If you want to help, [here's a starting guide on how to write tests in Jasmine](CONTRIBUTING.md#jasmine-testing-guide).
## Contributing
Check out the [CONTRIBUTING document](CONTRIBUTING.md) in the root of the repository to learn how you can contribute. You can also browse the [help-wanted](https://github.com/Dogfalo/materialize/labels/help-wanted) tag in our issue tracker to find things to do.
## Copyright and license
Code Copyright 2018 Materialize. Code released under the MIT license.

9067
static/css/materialize.css vendored Normal file

File diff suppressed because it is too large Load Diff

13
static/css/materialize.min.css vendored Normal file

File diff suppressed because one or more lines are too long

406
static/css/nouislider.css Normal file
View File

@@ -0,0 +1,406 @@
/*!
* Materialize v0.100.2 (http://materializecss.com)
* Copyright 2014-2015 Materialize
* MIT License (https://raw.githubusercontent.com/Dogfalo/materialize/master/LICENSE)
*/
/*! nouislider - 9.1.0 - 2016-12-10 16:00:32 */
/* Functional styling;
* These styles are required for noUiSlider to function.
* You don't need to change these rules to apply your design.
*/
.noUi-target,
.noUi-target * {
-webkit-touch-callout: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
-webkit-user-select: none;
-ms-touch-action: none;
touch-action: none;
-ms-user-select: none;
-moz-user-select: none;
user-select: none;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.noUi-target {
position: relative;
direction: ltr;
}
.noUi-base {
width: 100%;
height: 100%;
position: relative;
z-index: 1; /* Fix 401 */
}
.noUi-connect {
position: absolute;
right: 0;
top: 0;
left: 0;
bottom: 0;
}
.noUi-origin {
position: absolute;
height: 0;
width: 0;
}
.noUi-handle {
position: relative;
z-index: 1;
}
.noUi-state-tap .noUi-connect,
.noUi-state-tap .noUi-origin {
-webkit-transition: top 0.25s, right 0.25s, bottom 0.25s, left 0.25s;
transition: top 0.25s, right 0.25s, bottom 0.25s, left 0.25s;
}
.noUi-state-drag * {
cursor: inherit !important;
}
.noUi-handle-touch-area{
position: relative;
width: 44px;
height: 44px;
left: -15px;
top: -15px;
}
/* Painting and performance;
* Browsers can paint handles in their own layer.
*/
.noUi-base,
.noUi-handle {
-webkit-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
/* Slider size and handle placement;
*/
.noUi-horizontal {
height: 18px;
}
.noUi-horizontal .noUi-handle {
width: 34px;
height: 28px;
left: -17px;
top: -6px;
}
.noUi-vertical {
width: 18px;
}
.noUi-vertical .noUi-handle {
width: 28px;
height: 34px;
left: -6px;
top: -17px;
}
/* Styling;
*/
.noUi-target {
background: #cdcdcd;
border-radius: 4px;
border: 1px solid transparent;
}
.noUi-connect {
background: #26A69A;
-webkit-transition: background 450ms;
transition: background 450ms;
}
/* Handles and cursors;
*/
.noUi-draggable {
cursor: ew-resize;
}
.noUi-vertical .noUi-draggable {
cursor: ns-resize;
}
.noUi-handle {
border: 1px solid #D9D9D9;
border-radius: 3px;
background: #FFF;
cursor: default;
box-shadow: inset 0 0 1px #FFF,
inset 0 1px 7px #EBEBEB,
0 3px 6px -3px #BBB;
}
.noUi-active {
box-shadow: inset 0 0 1px #FFF,
inset 0 1px 7px #DDD,
0 3px 6px -3px #BBB;
}
/* Handle stripes
*/
.noUi-handle:before,
.noUi-handle:after {
content: "";
display: block;
position: absolute;
height: 14px;
width: 1px;
background: #E8E7E6;
left: 14px;
top: 6px;
}
.noUi-handle:after {
left: 17px;
}
.noUi-vertical .noUi-handle:before,
.noUi-vertical .noUi-handle:after {
width: 14px;
height: 1px;
left: 6px;
top: 14px;
}
.noUi-vertical .noUi-handle:after {
top: 17px;
}
/* Disabled state;
*/
[disabled] .noUi-connect {
background: #B8B8B8;
}
[disabled].noUi-target,
[disabled].noUi-handle,
[disabled] .noUi-handle {
cursor: not-allowed;
}
/* Base;
*
*/
.noUi-pips,
.noUi-pips * {
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.noUi-pips {
position: absolute;
color: #999;
}
/* Values;
*
*/
.noUi-value {
position: absolute;
text-align: center;
}
.noUi-value-sub {
color: #ccc;
font-size: 10px;
}
/* Markings;
*
*/
.noUi-marker {
position: absolute;
background: #CCC;
}
.noUi-marker-sub {
background: #AAA;
}
.noUi-marker-large {
background: #AAA;
}
/* Horizontal layout;
*
*/
.noUi-pips-horizontal {
padding: 10px 0;
height: 80px;
top: 100%;
left: 0;
width: 100%;
}
.noUi-value-horizontal {
-webkit-transform: translate3d(-50%,50%,0);
transform: translate3d(-50%,50%,0);
}
.noUi-marker-horizontal.noUi-marker {
margin-left: -1px;
width: 2px;
height: 5px;
}
.noUi-marker-horizontal.noUi-marker-sub {
height: 10px;
}
.noUi-marker-horizontal.noUi-marker-large {
height: 15px;
}
/* Vertical layout;
*
*/
.noUi-pips-vertical {
padding: 0 10px;
height: 100%;
top: 0;
left: 100%;
}
.noUi-value-vertical {
-webkit-transform: translate3d(0,50%,0);
transform: translate3d(0,50%,0);
padding-left: 25px;
}
.noUi-marker-vertical.noUi-marker {
width: 5px;
height: 2px;
margin-top: -1px;
}
.noUi-marker-vertical.noUi-marker-sub {
width: 10px;
}
.noUi-marker-vertical.noUi-marker-large {
width: 15px;
}
.noUi-tooltip {
display: block;
position: absolute;
border: 1px solid transparent;
border-radius: 3px;
background: #fff;
color: #000;
padding: 5px;
text-align: center;
}
.noUi-horizontal .noUi-tooltip {
-webkit-transform: translate(-50%, 0);
transform: translate(-50%, 0);
left: 50%;
bottom: 120%;
}
.noUi-vertical .noUi-tooltip {
-webkit-transform: translate(0, -50%);
transform: translate(0, -50%);
top: 50%;
right: 120%;
}
/* Materialize Styles */
.noUi-target {
border: 0;
border-radius: 0;
}
.noUi-horizontal {
height: 3px;
}
.noUi-vertical {
height: 100%;
width: 3px;
}
.noUi-horizontal .noUi-handle,
.noUi-vertical .noUi-handle {
width: 15px;
height: 15px;
border-radius: 50%;
box-shadow: none;
background-color: #26A69A;
border: none;
left: -5px;
top: -6px;
transition: width .2s cubic-bezier(0.215, 0.610, 0.355, 1.000),
height .2s cubic-bezier(0.215, 0.610, 0.355, 1.000),
left .2s cubic-bezier(0.215, 0.610, 0.355, 1.000),
top .2s cubic-bezier(0.215, 0.610, 0.355, 1.000);
}
.noUi-handle:before {
content: none;
}
.noUi-handle:after {
content: none;
}
.noUi-target .noUi-active.noUi-handle {
width: 3px;
height: 3px;
left: 0;
top: 0;
}
.noUi-target.noUi-horizontal .noUi-tooltip {
position: absolute;
height: 30px;
width: 30px;
top: -17px;
left: -2px;
background-color: #26A69A;
border-radius: 50%;
transition: border-radius .25s cubic-bezier(0.215, 0.610, 0.355, 1.000),
transform .25s cubic-bezier(0.215, 0.610, 0.355, 1.000);
transform: scale(.5) rotate(-45deg);
transform-origin: 50% 100%;
}
.noUi-target.noUi-horizontal .noUi-active .noUi-tooltip {
border-radius: 15px 15px 15px 0;
transform: rotate(-45deg) translate(23px, -25px);
}
.noUi-tooltip span {
width: 100%;
text-align: center;
color: #fff;
font-size: 12px;
opacity: 0;
position: absolute;
top: 6px;
left: -1px;
transition: opacity .25s cubic-bezier(0.215, 0.610, 0.355, 1.000);
}
.noUi-horizontal .noUi-tooltip span {
transform: rotate(45deg);
}
.noUi-vertical .noUi-tooltip span {
transform: rotate(135deg);
}
.noUi-target.noUi-vertical .noUi-tooltip {
position: absolute;
height: 30px;
width: 30px;
top: -17px;
left: -2px;
background-color: #26A69A;
border-radius: 50%;
transition: border-radius .25s cubic-bezier(0.215, 0.610, 0.355, 1.000),
transform .25s cubic-bezier(0.215, 0.610, 0.355, 1.000);
transform: scale(.5) rotate(-45deg);
transform-origin: 50% 100%;
}
.noUi-target.noUi-vertical .noUi-active .noUi-tooltip {
border-radius: 15px 15px 15px 0;
transform: rotate(-135deg) translate(35px, -10px);
}
.noUi-vertical .noUi-tooltip span {
width: 100%;
text-align: center;
color: #fff;
font-size: 12px;
transform: rotate(135deg);
opacity: 0;
position: absolute;
top: 7px;
left: -1px;
transition: opacity .25s cubic-bezier(0.215, 0.610, 0.355, 1.000);
}
.noUi-horizontal .noUi-active .noUi-tooltip span,
.noUi-vertical .noUi-active .noUi-tooltip span {
opacity: 1;
}

1
static/css/nouislider.min.css vendored Normal file
View File

@@ -0,0 +1 @@
.noUi-target,.noUi-target *{-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent;-webkit-user-select:none;-ms-touch-action:none;touch-action:none;-ms-user-select:none;-moz-user-select:none;user-select:none;-moz-box-sizing:border-box;box-sizing:border-box}.noUi-target{position:relative}.noUi-base,.noUi-connects{width:100%;height:100%;position:relative;z-index:1}.noUi-connects{overflow:hidden;z-index:0}.noUi-connect,.noUi-origin{will-change:transform;position:absolute;z-index:1;top:0;right:0;height:100%;width:100%;-ms-transform-origin:0 0;-webkit-transform-origin:0 0;-webkit-transform-style:preserve-3d;transform-origin:0 0;transform-style:flat}.noUi-txt-dir-rtl.noUi-horizontal .noUi-origin{left:0;right:auto}.noUi-vertical .noUi-origin{top:-100%;width:0}.noUi-horizontal .noUi-origin{height:0}.noUi-handle{-webkit-backface-visibility:hidden;backface-visibility:hidden;position:absolute}.noUi-touch-area{height:100%;width:100%}.noUi-state-tap .noUi-connect,.noUi-state-tap .noUi-origin{-webkit-transition:transform .3s;transition:transform .3s}.noUi-state-drag *{cursor:inherit!important}.noUi-horizontal{height:18px}.noUi-horizontal .noUi-handle{width:34px;height:28px;right:-17px;top:-6px}.noUi-vertical{width:18px}.noUi-vertical .noUi-handle{width:28px;height:34px;right:-6px;bottom:-17px}.noUi-txt-dir-rtl.noUi-horizontal .noUi-handle{left:-17px;right:auto}.noUi-target{background:#FAFAFA;border-radius:4px;border:1px solid #D3D3D3;box-shadow:inset 0 1px 1px #F0F0F0,0 3px 6px -5px #BBB}.noUi-connects{border-radius:3px}.noUi-connect{background:#3FB8AF}.noUi-draggable{cursor:ew-resize}.noUi-vertical .noUi-draggable{cursor:ns-resize}.noUi-handle{border:1px solid #D9D9D9;border-radius:3px;background:#FFF;cursor:default;box-shadow:inset 0 0 1px #FFF,inset 0 1px 7px #EBEBEB,0 3px 6px -3px #BBB}.noUi-active{box-shadow:inset 0 0 1px #FFF,inset 0 1px 7px #DDD,0 3px 6px -3px #BBB}.noUi-handle:after,.noUi-handle:before{content:"";display:block;position:absolute;height:14px;width:1px;background:#E8E7E6;left:14px;top:6px}.noUi-handle:after{left:17px}.noUi-vertical .noUi-handle:after,.noUi-vertical .noUi-handle:before{width:14px;height:1px;left:6px;top:14px}.noUi-vertical .noUi-handle:after{top:17px}[disabled] .noUi-connect{background:#B8B8B8}[disabled] .noUi-handle,[disabled].noUi-handle,[disabled].noUi-target{cursor:not-allowed}.noUi-pips,.noUi-pips *{-moz-box-sizing:border-box;box-sizing:border-box}.noUi-pips{position:absolute;color:#999}.noUi-value{position:absolute;white-space:nowrap;text-align:center}.noUi-value-sub{color:#ccc;font-size:10px}.noUi-marker{position:absolute;background:#CCC}.noUi-marker-sub{background:#AAA}.noUi-marker-large{background:#AAA}.noUi-pips-horizontal{padding:10px 0;height:80px;top:100%;left:0;width:100%}.noUi-value-horizontal{-webkit-transform:translate(-50%,50%);transform:translate(-50%,50%)}.noUi-rtl .noUi-value-horizontal{-webkit-transform:translate(50%,50%);transform:translate(50%,50%)}.noUi-marker-horizontal.noUi-marker{margin-left:-1px;width:2px;height:5px}.noUi-marker-horizontal.noUi-marker-sub{height:10px}.noUi-marker-horizontal.noUi-marker-large{height:15px}.noUi-pips-vertical{padding:0 10px;height:100%;top:0;left:100%}.noUi-value-vertical{-webkit-transform:translate(0,-50%);transform:translate(0,-50%);padding-left:25px}.noUi-rtl .noUi-value-vertical{-webkit-transform:translate(0,50%);transform:translate(0,50%)}.noUi-marker-vertical.noUi-marker{width:5px;height:2px;margin-top:-1px}.noUi-marker-vertical.noUi-marker-sub{width:10px}.noUi-marker-vertical.noUi-marker-large{width:15px}.noUi-tooltip{display:block;position:absolute;border:1px solid #D9D9D9;border-radius:3px;background:#fff;color:#000;padding:5px;text-align:center;white-space:nowrap}.noUi-horizontal .noUi-tooltip{-webkit-transform:translate(-50%,0);transform:translate(-50%,0);left:50%;bottom:120%}.noUi-vertical .noUi-tooltip{-webkit-transform:translate(0,-50%);transform:translate(0,-50%);top:50%;right:120%}.noUi-horizontal .noUi-origin>.noUi-tooltip{-webkit-transform:translate(50%,0);transform:translate(50%,0);left:auto;bottom:10px}.noUi-vertical .noUi-origin>.noUi-tooltip{-webkit-transform:translate(0,-18px);transform:translate(0,-18px);top:auto;right:28px}

23
static/css/style.css Normal file
View File

@@ -0,0 +1,23 @@
/* Custom Stylesheet */
/**
* Use this file to override Materialize files so you can update
* the core Materialize files in the future
*
* Made By MaterializeCSS.com
*/
.icon-block {
padding: 0 15px;
}
.icon-block .material-icons {
font-size: inherit;
}
/**** Custom styles for Range ****/
.noUi-tooltip span {
opacity: 1;
}
.noUi-target.noUi-horizontal .noUi-tooltip {
transform: scale(1) rotate(-45deg) translate(0px, 4px);
}

61
static/js/init.js Normal file
View File

@@ -0,0 +1,61 @@
document.addEventListener("DOMContentLoaded", function(event) {
var valuesForSlider = [2,3,4,5];
var format = {
to: function(value) {
return valuesForSlider[Math.round(value)];
},
from: function (value) {
return valuesForSlider.indexOf(Number(value));
}
};
var slider = document.getElementById('slider');
noUiSlider.create(slider, {
start: [2, 3],
connect: true,
tooltips: true,
step: 1,
range: {
'min': 0,
'max': valuesForSlider.length - 1
},
format: format
});
});
(function($){
$(function(){
$('.sidenav').sidenav();
}); // end of document ready
$(document).ready(function(){
// slider
// var valuesForSlider = [2,3,4,5];
// var slider = document.getElementById('slider');
// var format = {
// to: function(value) {
// return valuesForSlider[Math.round(value)];
// },
// from: function (value) {
// return valuesForSlider.indexOf(Number(value));
// }
// };
//
// noUiSlider.create(slider, {
// start: [3, 4],
// connect: true,
// step: 1,
// orientation: 'horizontal', // 'horizontal' or 'vertical'
// range: {
// 'min': 0,
// 'max': valuesForSlider.length - 1
// },
// format: wNumb({
// decimals: 0
// })
// });
});
})(jQuery); // end of jQuery name space

12374
static/js/materialize.js vendored Normal file

File diff suppressed because it is too large Load Diff

6
static/js/materialize.min.js vendored Normal file

File diff suppressed because one or more lines are too long

2282
static/js/nouislider.js Normal file

File diff suppressed because it is too large Load Diff

1
static/js/nouislider.min.js vendored Normal file

File diff suppressed because one or more lines are too long

381
static/js/wNumb.js Normal file
View File

@@ -0,0 +1,381 @@
(function(factory) {
if (typeof define === "function" && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else if (typeof exports === "object") {
// Node/CommonJS
module.exports = factory();
} else {
// Browser globals
window.wNumb = factory();
}
})(function() {
"use strict";
var FormatOptions = [
"decimals",
"thousand",
"mark",
"prefix",
"suffix",
"encoder",
"decoder",
"negativeBefore",
"negative",
"edit",
"undo"
];
// General
// Reverse a string
function strReverse(a) {
return a
.split("")
.reverse()
.join("");
}
// Check if a string starts with a specified prefix.
function strStartsWith(input, match) {
return input.substring(0, match.length) === match;
}
// Check is a string ends in a specified suffix.
function strEndsWith(input, match) {
return input.slice(-1 * match.length) === match;
}
// Throw an error if formatting options are incompatible.
function throwEqualError(F, a, b) {
if ((F[a] || F[b]) && F[a] === F[b]) {
throw new Error(a);
}
}
// Check if a number is finite and not NaN
function isValidNumber(input) {
return typeof input === "number" && isFinite(input);
}
// Provide rounding-accurate toFixed method.
// Borrowed: http://stackoverflow.com/a/21323330/775265
function toFixed(value, exp) {
value = value.toString().split("e");
value = Math.round(+(value[0] + "e" + (value[1] ? +value[1] + exp : exp)));
value = value.toString().split("e");
return (+(value[0] + "e" + (value[1] ? +value[1] - exp : -exp))).toFixed(exp);
}
// Formatting
// Accept a number as input, output formatted string.
function formatTo(
decimals,
thousand,
mark,
prefix,
suffix,
encoder,
decoder,
negativeBefore,
negative,
edit,
undo,
input
) {
var originalInput = input,
inputIsNegative,
inputPieces,
inputBase,
inputDecimals = "",
output = "";
// Apply user encoder to the input.
// Expected outcome: number.
if (encoder) {
input = encoder(input);
}
// Stop if no valid number was provided, the number is infinite or NaN.
if (!isValidNumber(input)) {
return false;
}
// Rounding away decimals might cause a value of -0
// when using very small ranges. Remove those cases.
if (decimals !== false && parseFloat(input.toFixed(decimals)) === 0) {
input = 0;
}
// Formatting is done on absolute numbers,
// decorated by an optional negative symbol.
if (input < 0) {
inputIsNegative = true;
input = Math.abs(input);
}
// Reduce the number of decimals to the specified option.
if (decimals !== false) {
input = toFixed(input, decimals);
}
// Transform the number into a string, so it can be split.
input = input.toString();
// Break the number on the decimal separator.
if (input.indexOf(".") !== -1) {
inputPieces = input.split(".");
inputBase = inputPieces[0];
if (mark) {
inputDecimals = mark + inputPieces[1];
}
} else {
// If it isn't split, the entire number will do.
inputBase = input;
}
// Group numbers in sets of three.
if (thousand) {
inputBase = strReverse(inputBase).match(/.{1,3}/g);
inputBase = strReverse(inputBase.join(strReverse(thousand)));
}
// If the number is negative, prefix with negation symbol.
if (inputIsNegative && negativeBefore) {
output += negativeBefore;
}
// Prefix the number
if (prefix) {
output += prefix;
}
// Normal negative option comes after the prefix. Defaults to '-'.
if (inputIsNegative && negative) {
output += negative;
}
// Append the actual number.
output += inputBase;
output += inputDecimals;
// Apply the suffix.
if (suffix) {
output += suffix;
}
// Run the output through a user-specified post-formatter.
if (edit) {
output = edit(output, originalInput);
}
// All done.
return output;
}
// Accept a sting as input, output decoded number.
function formatFrom(
decimals,
thousand,
mark,
prefix,
suffix,
encoder,
decoder,
negativeBefore,
negative,
edit,
undo,
input
) {
var originalInput = input,
inputIsNegative,
output = "";
// User defined pre-decoder. Result must be a non empty string.
if (undo) {
input = undo(input);
}
// Test the input. Can't be empty.
if (!input || typeof input !== "string") {
return false;
}
// If the string starts with the negativeBefore value: remove it.
// Remember is was there, the number is negative.
if (negativeBefore && strStartsWith(input, negativeBefore)) {
input = input.replace(negativeBefore, "");
inputIsNegative = true;
}
// Repeat the same procedure for the prefix.
if (prefix && strStartsWith(input, prefix)) {
input = input.replace(prefix, "");
}
// And again for negative.
if (negative && strStartsWith(input, negative)) {
input = input.replace(negative, "");
inputIsNegative = true;
}
// Remove the suffix.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice
if (suffix && strEndsWith(input, suffix)) {
input = input.slice(0, -1 * suffix.length);
}
// Remove the thousand grouping.
if (thousand) {
input = input.split(thousand).join("");
}
// Set the decimal separator back to period.
if (mark) {
input = input.replace(mark, ".");
}
// Prepend the negative symbol.
if (inputIsNegative) {
output += "-";
}
// Add the number
output += input;
// Trim all non-numeric characters (allow '.' and '-');
output = output.replace(/[^0-9\.\-.]/g, "");
// The value contains no parse-able number.
if (output === "") {
return false;
}
// Covert to number.
output = Number(output);
// Run the user-specified post-decoder.
if (decoder) {
output = decoder(output);
}
// Check is the output is valid, otherwise: return false.
if (!isValidNumber(output)) {
return false;
}
return output;
}
// Framework
// Validate formatting options
function validate(inputOptions) {
var i,
optionName,
optionValue,
filteredOptions = {};
if (inputOptions["suffix"] === undefined) {
inputOptions["suffix"] = inputOptions["postfix"];
}
for (i = 0; i < FormatOptions.length; i += 1) {
optionName = FormatOptions[i];
optionValue = inputOptions[optionName];
if (optionValue === undefined) {
// Only default if negativeBefore isn't set.
if (optionName === "negative" && !filteredOptions.negativeBefore) {
filteredOptions[optionName] = "-";
// Don't set a default for mark when 'thousand' is set.
} else if (optionName === "mark" && filteredOptions.thousand !== ".") {
filteredOptions[optionName] = ".";
} else {
filteredOptions[optionName] = false;
}
// Floating points in JS are stable up to 7 decimals.
} else if (optionName === "decimals") {
if (optionValue >= 0 && optionValue < 8) {
filteredOptions[optionName] = optionValue;
} else {
throw new Error(optionName);
}
// These options, when provided, must be functions.
} else if (
optionName === "encoder" ||
optionName === "decoder" ||
optionName === "edit" ||
optionName === "undo"
) {
if (typeof optionValue === "function") {
filteredOptions[optionName] = optionValue;
} else {
throw new Error(optionName);
}
// Other options are strings.
} else {
if (typeof optionValue === "string") {
filteredOptions[optionName] = optionValue;
} else {
throw new Error(optionName);
}
}
}
// Some values can't be extracted from a
// string if certain combinations are present.
throwEqualError(filteredOptions, "mark", "thousand");
throwEqualError(filteredOptions, "prefix", "negative");
throwEqualError(filteredOptions, "prefix", "negativeBefore");
return filteredOptions;
}
// Pass all options as function arguments
function passAll(options, method, input) {
var i,
args = [];
// Add all options in order of FormatOptions
for (i = 0; i < FormatOptions.length; i += 1) {
args.push(options[FormatOptions[i]]);
}
// Append the input, then call the method, presenting all
// options as arguments.
args.push(input);
return method.apply("", args);
}
function wNumb(options) {
if (!(this instanceof wNumb)) {
return new wNumb(options);
}
if (typeof options !== "object") {
return;
}
options = validate(options);
// Call 'formatTo' with proper arguments.
this.to = function(input) {
return passAll(options, formatTo, input);
};
// Call 'formatFrom' with proper arguments.
this.from = function(input) {
return passAll(options, formatFrom, input);
};
}
return wNumb;
});