* Parse the `styleRules` option and run the test for each given rules, either pre-defined ones like `positive`, `negative` and `ranges`, or user defined callbacks within the `userDefined` attribute. * @private
()
| 1844 | * @private |
| 1845 | */ |
| 1846 | _parseStyleRules() { |
| 1847 | if (AutoNumericHelper.isUndefinedOrNullOrEmpty(this.settings.styleRules) || this.rawValue === '') { |
| 1848 | return; |
| 1849 | } |
| 1850 | |
| 1851 | // 'positive' attribute |
| 1852 | if (!AutoNumericHelper.isUndefinedOrNullOrEmpty(this.settings.styleRules.positive)) { |
| 1853 | if (this.rawValue >= 0) { |
| 1854 | this._addCSSClass(this.settings.styleRules.positive); |
| 1855 | } else { |
| 1856 | this._removeCSSClass(this.settings.styleRules.positive); |
| 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | // 'negative' attribute |
| 1861 | if (!AutoNumericHelper.isUndefinedOrNullOrEmpty(this.settings.styleRules.negative)) { |
| 1862 | if (this.rawValue < 0) { |
| 1863 | this._addCSSClass(this.settings.styleRules.negative); |
| 1864 | } else { |
| 1865 | this._removeCSSClass(this.settings.styleRules.negative); |
| 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | // 'ranges' attribute |
| 1870 | if (!AutoNumericHelper.isUndefinedOrNullOrEmpty(this.settings.styleRules.ranges) && this.settings.styleRules.ranges.length !== 0) { |
| 1871 | this.settings.styleRules.ranges.forEach(range => { |
| 1872 | if (this.rawValue >= range.min && this.rawValue < range.max) { |
| 1873 | this._addCSSClass(range.class); |
| 1874 | } else { |
| 1875 | this._removeCSSClass(range.class); |
| 1876 | } |
| 1877 | }); |
| 1878 | } |
| 1879 | |
| 1880 | // 'userDefined' attribute |
| 1881 | //TODO Also pass the old raw value as a parameter, and not only the new raw value |
| 1882 | if (!AutoNumericHelper.isUndefinedOrNullOrEmpty(this.settings.styleRules.userDefined) && this.settings.styleRules.userDefined.length !== 0) { |
| 1883 | this.settings.styleRules.userDefined.forEach(userObject => { |
| 1884 | if (AutoNumericHelper.isFunction(userObject.callback)) { |
| 1885 | // Test for the type of the `classes` attribute, which changes the function behavior |
| 1886 | if (AutoNumericHelper.isString(userObject.classes)) { |
| 1887 | // If 'classes' is a string, set it if `true`, remove it if `false` |
| 1888 | if (userObject.callback(this.rawValue)) { |
| 1889 | this._addCSSClass(userObject.classes); |
| 1890 | } else { |
| 1891 | this._removeCSSClass(userObject.classes); |
| 1892 | } |
| 1893 | } else if (AutoNumericHelper.isArray(userObject.classes)) { |
| 1894 | if (userObject.classes.length === 2) { |
| 1895 | // If 'classes' is an array with only 2 elements, set the first class if `true`, the second if `false` |
| 1896 | if (userObject.callback(this.rawValue)) { |
| 1897 | this._addCSSClass(userObject.classes[0]); |
| 1898 | this._removeCSSClass(userObject.classes[1]); |
| 1899 | } else { |
| 1900 | this._removeCSSClass(userObject.classes[0]); |
| 1901 | this._addCSSClass(userObject.classes[1]); |
| 1902 | } |
| 1903 | } else if (userObject.classes.length > 2) { |
no test coverage detected