first commit
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).i18nextXHRBackend=e()}(this,function(){"use strict";function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var e=[],n=e.forEach,o=e.slice;function i(t){return n.call(o.call(arguments,1),function(e){if(e)for(var n in e)void 0===t[n]&&(t[n]=e[n])}),t}function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(t){return(a="function"==typeof Symbol&&"symbol"===r(Symbol.iterator)?function(t){return r(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":r(t)})(t)}function s(t,e){if(e&&"object"===a(e)){var n="",o=encodeURIComponent;for(var i in e)n+="&"+o(i)+"="+o(e[i]);if(!n)return t;t=t+(-1!==t.indexOf("?")?"&":"?")+n.slice(1)}return t}function l(t,e,n,o,i){o&&"object"===a(o)&&(i||(o._t=new Date),o=s("",o).slice(1)),e.queryStringParams&&(t=s(t,e.queryStringParams));try{var r;(r=XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0")).open(o?"POST":"GET",t,1),e.crossDomain||r.setRequestHeader("X-Requested-With","XMLHttpRequest"),r.withCredentials=!!e.withCredentials,o&&r.setRequestHeader("Content-type","application/x-www-form-urlencoded"),r.overrideMimeType&&r.overrideMimeType("application/json");var l=e.customHeaders;if(l="function"==typeof l?l():l)for(var u in l)r.setRequestHeader(u,l[u]);r.onreadystatechange=function(){r.readyState>3&&n&&n(r.responseText,r)},r.send(o)}catch(t){console&&console.log(t)}}function u(){return{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"/locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:JSON.parse,parsePayload:function(t,e,n){return function(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}({},e,n||"")},crossDomain:!1,ajax:l}}var c=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.init(t,n),this.type="backend"}var n,o,r;return n=e,(o=[{key:"init",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.services=t,this.options=i(e,this.options||{},u())}},{key:"readMulti",value:function(t,e,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath(t,e));var i=this.services.interpolator.interpolate(o,{lng:t.join("+"),ns:e.join("+")});this.loadUrl(i,n)}},{key:"read",value:function(t,e,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath([t],[e]));var i=this.services.interpolator.interpolate(o,{lng:t,ns:e});this.loadUrl(i,n)}},{key:"loadUrl",value:function(t,e){var n=this;this.options.ajax(t,this.options,function(o,i){if(i.status>=500&&i.status<600)return e("failed loading "+t,!0);if(i.status>=400&&i.status<500)return e("failed loading "+t,!1);var r,a;try{r=n.options.parse(o,t)}catch(e){a="failed parsing "+t+" to json"}if(a)return e(a,!1);e(null,r)})}},{key:"create",value:function(t,e,n,o){var i=this;"string"==typeof t&&(t=[t]);var r=this.options.parsePayload(e,n,o);t.forEach(function(t){var n=i.services.interpolator.interpolate(i.options.addPath,{lng:t,ns:e});i.options.ajax(n,i.options,function(t,e){},r)})}}])&&t(n.prototype,o),r&&t(n,r),e}();return c.type="backend",c});
|
||||
@@ -0,0 +1 @@
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.jqueryI18next=e()}(this,function(){"use strict";function t(t,a){function i(n,a,i){function r(t,n){return f.parseDefaultValueFromContent?e({},t,{defaultValue:n}):t}if(0!==a.length){var o="text";if(0===a.indexOf("[")){var l=a.split("]");a=l[1],o=l[0].substr(1,l[0].length-1)}if(a.indexOf(";")===a.length-1&&(a=a.substr(0,a.length-2)),"html"===o)n.html(t.t(a,r(i,n.html())));else if("text"===o)n.text(t.t(a,r(i,n.text())));else if("prepend"===o)n.prepend(t.t(a,r(i,n.html())));else if("append"===o)n.append(t.t(a,r(i,n.html())));else if(0===o.indexOf("data-")){var s=o.substr("data-".length),d=t.t(a,r(i,n.data(s)));n.data(s,d),n.attr(o,d)}else n.attr(o,t.t(a,r(i,n.attr(o))))}}function r(t,n){var r=t.attr(f.selectorAttr);if(r||void 0===r||!1===r||(r=t.text()||t.val()),r){var o=t,l=t.data(f.targetAttr);if(l&&(o=t.find(l)||t),n||!0!==f.useOptionsAttr||(n=t.data(f.optionsAttr)),n=n||{},r.indexOf(";")>=0){var s=r.split(";");a.each(s,function(t,e){""!==e&&i(o,e.trim(),n)})}else i(o,r,n);if(!0===f.useOptionsAttr){var d={};d=e({clone:d},n),delete d.lng,t.data(f.optionsAttr,d)}}}function o(t){return this.each(function(){r(a(this),t),a(this).find("["+f.selectorAttr+"]").each(function(){r(a(this),t)})})}var f=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};f=e({},n,f),a[f.tName]=t.t.bind(t),a[f.i18nName]=t,a.fn[f.handleName]=o}var e=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t},n={tName:"t",i18nName:"i18n",handleName:"localize",selectorAttr:"data-i18n",targetAttr:"i18n-target",optionsAttr:"i18n-options",useOptionsAttr:!1,parseDefaultValueFromContent:!0};return{init:t}});
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,8 @@
|
||||
/*!
|
||||
* jQuery Mousewheel 3.1.13
|
||||
*
|
||||
* Copyright 2015 jQuery Foundation and other contributors
|
||||
* Released under the MIT license.
|
||||
* http://jquery.org/license
|
||||
*/
|
||||
!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?module.exports=e:e(jQuery)}(function(u){var f,d,e=["wheel","mousewheel","DOMMouseScroll","MozMousePixelScroll"],t="onwheel"in window.document||9<=window.document.documentMode?["wheel"]:["mousewheel","DomMouseScroll","MozMousePixelScroll"],w=Array.prototype.slice;if(u.event.fixHooks)for(var i=e.length;i;)u.event.fixHooks[e[--i]]=u.event.mouseHooks;var c=u.event.special.mousewheel={version:"3.1.12",setup:function(){if(this.addEventListener)for(var e=t.length;e;)this.addEventListener(t[--e],n,!1);else this.onmousewheel=n;u.data(this,"mousewheel-line-height",c.getLineHeight(this)),u.data(this,"mousewheel-page-height",c.getPageHeight(this))},teardown:function(){if(this.removeEventListener)for(var e=t.length;e;)this.removeEventListener(t[--e],n,!1);else this.onmousewheel=null;u.removeData(this,"mousewheel-line-height"),u.removeData(this,"mousewheel-page-height")},getLineHeight:function(e){var t=u(e),i=t["offsetParent"in u.fn?"offsetParent":"parent"]();return i.length||(i=u("body")),parseInt(i.css("fontSize"),10)||parseInt(t.css("fontSize"),10)||16},getPageHeight:function(e){return u(e).height()},settings:{adjustOldDeltas:!0,normalizeOffset:!0}};function n(e){var t,i=e||window.event,n=w.call(arguments,1),o=0,l=0,s=0;if((e=u.event.fix(i)).type="mousewheel","detail"in i&&(s=-1*i.detail),"wheelDelta"in i&&(s=i.wheelDelta),"wheelDeltaY"in i&&(s=i.wheelDeltaY),"wheelDeltaX"in i&&(l=-1*i.wheelDeltaX),"axis"in i&&i.axis===i.HORIZONTAL_AXIS&&(l=-1*s,s=0),o=0===s?l:s,"deltaY"in i&&(o=s=-1*i.deltaY),"deltaX"in i&&(l=i.deltaX,0===s&&(o=-1*l)),0!==s||0!==l){if(1===i.deltaMode){var a=u.data(this,"mousewheel-line-height");o*=a,s*=a,l*=a}else if(2===i.deltaMode){var h=u.data(this,"mousewheel-page-height");o*=h,s*=h,l*=h}if(t=Math.max(Math.abs(s),Math.abs(l)),(!d||t<d)&&g(i,d=t)&&(d/=40),g(i,t)&&(o/=40,l/=40,s/=40),o=Math[1<=o?"floor":"ceil"](o/d),l=Math[1<=l?"floor":"ceil"](l/d),s=Math[1<=s?"floor":"ceil"](s/d),c.settings.normalizeOffset&&this.getBoundingClientRect){var r=this.getBoundingClientRect();e.offsetX=e.clientX-r.left,e.offsetY=e.clientY-r.top}return e.deltaX=l,e.deltaY=s,e.deltaFactor=d,e.deltaMode=0,n.unshift(e,o,l,s),f&&window.clearTimeout(f),f=window.setTimeout(m,200),(u.event.dispatch||u.event.handle).apply(this,n)}}function m(){d=null}function g(e,t){return c.settings.adjustOldDeltas&&"mousewheel"===e.type&&t%120==0}u.fn.extend({mousewheel:function(e){return e?this.on("mousewheel",e):this.trigger("mousewheel")},unmousewheel:function(e){return this.off("mousewheel",e)}})});
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n():"function"==typeof define&&define.amd?define(n):n()}(0,function(){"use strict";function e(e){var n=this.constructor;return this.then(function(t){return n.resolve(e()).then(function(){return t})},function(t){return n.resolve(e()).then(function(){return n.reject(t)})})}function n(){}function t(e){if(!(this instanceof t))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=undefined,this._deferreds=[],u(e,this)}function o(e,n){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,t._immediateFn(function(){var t=1===e._state?n.onFulfilled:n.onRejected;if(null!==t){var o;try{o=t(e._value)}catch(f){return void i(n.promise,f)}r(n.promise,o)}else(1===e._state?r:i)(n.promise,e._value)})):e._deferreds.push(n)}function r(e,n){try{if(n===e)throw new TypeError("A promise cannot be resolved with itself.");if(n&&("object"==typeof n||"function"==typeof n)){var o=n.then;if(n instanceof t)return e._state=3,e._value=n,void f(e);if("function"==typeof o)return void u(function(e,n){return function(){e.apply(n,arguments)}}(o,n),e)}e._state=1,e._value=n,f(e)}catch(r){i(e,r)}}function i(e,n){e._state=2,e._value=n,f(e)}function f(e){2===e._state&&0===e._deferreds.length&&t._immediateFn(function(){e._handled||t._unhandledRejectionFn(e._value)});for(var n=0,r=e._deferreds.length;r>n;n++)o(e,e._deferreds[n]);e._deferreds=null}function u(e,n){var t=!1;try{e(function(e){t||(t=!0,r(n,e))},function(e){t||(t=!0,i(n,e))})}catch(o){if(t)return;t=!0,i(n,o)}}var c=setTimeout;t.prototype["catch"]=function(e){return this.then(null,e)},t.prototype.then=function(e,t){var r=new this.constructor(n);return o(this,new function(e,n,t){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof n?n:null,this.promise=t}(e,t,r)),r},t.prototype["finally"]=e,t.all=function(e){return new t(function(n,t){function o(e,f){try{if(f&&("object"==typeof f||"function"==typeof f)){var u=f.then;if("function"==typeof u)return void u.call(f,function(n){o(e,n)},t)}r[e]=f,0==--i&&n(r)}catch(c){t(c)}}if(!e||"undefined"==typeof e.length)throw new TypeError("Promise.all accepts an array");var r=Array.prototype.slice.call(e);if(0===r.length)return n([]);for(var i=r.length,f=0;r.length>f;f++)o(f,r[f])})},t.resolve=function(e){return e&&"object"==typeof e&&e.constructor===t?e:new t(function(n){n(e)})},t.reject=function(e){return new t(function(n,t){t(e)})},t.race=function(e){return new t(function(n,t){for(var o=0,r=e.length;r>o;o++)e[o].then(n,t)})},t._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){c(e,0)},t._unhandledRejectionFn=function(e){void 0!==console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var l=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw Error("unable to locate global object")}();"Promise"in l?l.Promise.prototype["finally"]||(l.Promise.prototype["finally"]=e):l.Promise=t});
|
||||
+2164
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,59 @@
|
||||
;(function(){
|
||||
/* ========================================================================
|
||||
* Bootstrap: transition.js v3.0.2
|
||||
* http://getbootstrap.com/javascript/#transitions
|
||||
* ========================================================================
|
||||
* Copyright 2013 Twitter, Inc.
|
||||
*
|
||||
* 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.
|
||||
* ======================================================================== */
|
||||
|
||||
|
||||
+function ($) { "use strict";
|
||||
|
||||
// CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/)
|
||||
// ============================================================
|
||||
|
||||
function transitionEnd() {
|
||||
var el = document.createElement('bootstrap')
|
||||
|
||||
var transEndEventNames = {
|
||||
'WebkitTransition' : 'webkitTransitionEnd'
|
||||
, 'MozTransition' : 'transitionend'
|
||||
, 'OTransition' : 'oTransitionEnd otransitionend'
|
||||
, 'transition' : 'transitionend'
|
||||
}
|
||||
|
||||
for (var name in transEndEventNames) {
|
||||
if (el.style[name] !== undefined) {
|
||||
return { end: transEndEventNames[name] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// http://blog.alexmaccaw.com/css-transitions
|
||||
$.fn.emulateTransitionEnd = function (duration) {
|
||||
var called = false, $el = this
|
||||
$(this).one($.support.transition.end, function () { called = true })
|
||||
var callback = function () { if (!called) $($el).trigger($.support.transition.end) }
|
||||
setTimeout(callback, duration)
|
||||
return this
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$.support.transition = transitionEnd()
|
||||
})
|
||||
|
||||
}(jQuery);
|
||||
|
||||
})();
|
||||
+353
@@ -0,0 +1,353 @@
|
||||
(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
|
||||
/** @const */ FormatOptions = [
|
||||
'decimals',
|
||||
'thousand',
|
||||
'mark',
|
||||
'prefix',
|
||||
'postfix',
|
||||
'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 postfix.
|
||||
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.
|
||||
function toFixed ( value, decimals ) {
|
||||
var scale = Math.pow(10, decimals);
|
||||
return ( Math.round(value * scale) / scale).toFixed( decimals );
|
||||
}
|
||||
|
||||
|
||||
// Formatting
|
||||
|
||||
// Accept a number as input, output formatted string.
|
||||
function formatTo ( decimals, thousand, mark, prefix, postfix, 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 postfix.
|
||||
if ( postfix ) {
|
||||
output += postfix;
|
||||
}
|
||||
|
||||
// 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, postfix, 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 postfix.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice
|
||||
if ( postfix && strEndsWith(input, postfix) ) {
|
||||
input = input.slice(0, -1 * postfix.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 = {};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/** @constructor */
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
/** @export */
|
||||
return wNumb;
|
||||
|
||||
}));
|
||||
Reference in New Issue
Block a user