Skip to content

Commit

Permalink
Fixed non linear rtl, +tests. Removed classVal.
Browse files Browse the repository at this point in the history
  • Loading branch information
leongersen committed May 11, 2014
1 parent 74591f4 commit cdeac7a
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 58 deletions.
50 changes: 34 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# noUiSlider

noUiSlider is lightweight plugin, developed to be a jQuery UI alternative. It features cross-browser support, a `just-another-input-type` style of getting and setting values, a wide range of options and support for a bunch of touch devices. It works wonders on Android phones, iPhone & iPad, Windows phone and touch-screen laptops and tablets. It works excellent on the desktop too; All modern browsers and IE7+ are supported. The end result? A lean, extendible and bloat-less plugin that'll just do its job. To add even more flexibility, noUiSlider is compatible with both jQuery and Zepto.js. Oh, and the licensing terms are simple: [just do what you want](http://refreshless.com/nouislider/terms-of-use).
noUiSlider is lightweight plugin, developed to be a jQuery UI alternative. It features cross-browser support, a `just-another-input-type` style of getting and setting values, a wide range of options and support for a bunch of touch devices. It works wonders on Android phones, iPhone & iPad, Windows phone and touch-screen laptops and tablets. It works excellent on the desktop too; All modern browsers and IE7+ are supported. The end result? A lean, extendible and bloat-less plugin that'll just do its job. To add even more flexibility, noUiSlider is compatible with both jQuery and Zepto.js. Oh, and the licensing terms are simple: [just do what you want](http://www.wtfpl.net/about/).

Documentation
-------
Expand All @@ -10,13 +10,13 @@ An extensive documentation, including **examples**, **options** and **configurat
Changes
-------

**Changelog for version 6.1.0:**
**Compatible with 6.0.0**
**Changelog for version 6.2.0:**
*(Compatible with 6.0.0)*

+ Split out value methods into [$.classVal](https://github.com/leongersen/classVal). This is **included** in the release download.
+ `$.noUiSlider.Link` is now an alias to `$.Link`. The Link functionality has been moved into a new file. (also in the download).
+ Several bug fixes.
+ Added `to` and `from` to [number formatting](http://refreshless.com/nouislider/number-formatting)
+ Removed the previously added `.classVal` and replaced it with a lightweight solution.
+ Fixed a bug in non-linear stepping for RTL sliders. (#262)
+ Added checks for `min` and `max` in `range`. (#255)
+ Added the minified version in the source, so it can be managed with Bower. (#252)

**Changelog for version 6.0.0:**

Expand All @@ -30,24 +30,42 @@ Changes

Unit Testing
------------

Unit tests where added with noUiSlider 6. The event testing coverage isn't 100% yet, but coverage of the `Link` is extensive. More tests will be added eventually.
Unit tests where added with noUiSlider 6. Coverage of `$.Link` and value handling is near complete, but due to the sensitivity of events across browsers, event testing is a little lacking.

Version numbering
------------------------------
Version numbering follows the 'Semantic versioning' style.
Version numbering follows the 'Semantic versioning' style.
You'll find an excellent documentation at [Semver.org](http://semver.org/).

Compression and Error checking
------------------------------
**CSS** ([CSSMinifier](http://cssminifier.com/))
The stylesheet is trimmed to remove whitespace and comments to provide a `min` version.
The plugin code is checked using ([JsLint](http://jslint.com/)). Any remaining errors and warnings are intentional.

The plugin is compressed using the ([Google Closure Compiler](http://closure-compiler.appspot.com/home)). The source was adapted to facilitate the `ADVANCED_OPTIMIZATIONS` level. `$.Link` is merged into the file. On Windows, the folling BAT script can be used to run the compiler. On OS X or Linux enviroments, simply run the `java -jar` command from the command line.

```bat
@echo off
:: Set all paths as variables
set "jquery=.\externs\jquery-1.8.js"
set "link=..\source\Link.js"
set "source=..\source\jquery.nouislider.js"
set "result=..\source\jquery.nouislider.min.js"
:: Remove the existing file so we can be sure a new one is generated.
if exist %result% (
del %result%
)
echo "Removed %result%, ready."
PAUSE
**JS** ([Google Closure Compiler](http://closure-compiler.appspot.com/home))
The plugin is compressed using the Google Closure compiler. The source was adapted to facilitate the `ADVANCED_OPTIMIZATIONS` level.
java -jar .\compiler\compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --externs %jquery% --warning_level VERBOSE --js %link% --js %source% --js_output_file %result%
**Code** ([JsLint](http://jslint.com/))
The plugin code is checked using JsLint. Any remaining errors and warnings are intentional.
echo "Done."
PAUSE
```

Known issues
------------
Expand Down
6 changes: 2 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
"slide"
],
"main": [
"Link.js",
"jquery.nouislider.js",
"jquery.nouislider.min.js",
"jquery.nouislider.css"
],
"dependencies": {
"jquery": ">= 1.7.0",
"classval": ">= 0.1.0"
"jquery": ">= 1.7.0"
},
"ignore": [
"**/.*",
Expand Down
53 changes: 46 additions & 7 deletions jquery.nouislider.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ $.fn.noUiSlider - WTFPL - refreshless.com/nouislider/ */
// Cache the document selector;
/** @const */
doc = $(document),
// Make a backup of the original jQuery/Zepto .val() method.
/** @const */
$val = $.fn.val,
// Namespace for binding and unbinding slider events;
/** @const */
namespace = '.nui',
Expand Down Expand Up @@ -164,7 +167,10 @@ $.fn.noUiSlider - WTFPL - refreshless.com/nouislider/ */
function getStep ( options, value ){

var j = 1, a, b;
while ( value >= options.xPct[j] ){

// Find the proper step for rtl sliders by search in inverse direction.
// Fixes issue #262.
while ( (options.dir ? (100 - value) : value) >= options.xPct[j] ){
j++;
}

Expand Down Expand Up @@ -266,6 +272,12 @@ $.fn.noUiSlider - WTFPL - refreshless.com/nouislider/ */
throw new Error("noUiSlider: 'range' is not an object.");
}

// Catch missing start or end.
if ( entry['min'] === undefined ||
entry['max'] === undefined ) {
throw new Error("noUiSlider: Missing 'min' or 'max' in 'range'.");
}

// Loop all entries.
$.each( entry, function ( index, value ) {

Expand Down Expand Up @@ -506,15 +518,16 @@ $.fn.noUiSlider - WTFPL - refreshless.com/nouislider/ */
,margin: 0
}, tests;

// Tests are executed in the order they are presented here.
tests = {
'step': { r: false, t: testStep },
'range': { r: true, t: testRange },
'start': { r: true, t: testStart },
'snap': { r: false, t: testSnap },
'connect': { r: true, t: testConnect },
'direction': { r: true, t: testDirection },
'range': { r: true, t: testRange },
'snap': { r: false, t: testSnap },
'orientation': { r: false, t: testOrientation },
'margin': { r: false, t: testMargin },
'direction': { r: true, t: testDirection },
'behaviour': { r: true, t: testBehaviour },
'serialization': { r: true, t: testSerialization }
};
Expand Down Expand Up @@ -1235,6 +1248,35 @@ function closure ( target, options, originalOptions ){
});
}

// Access the internal getting and setting methods based on argument count.
function value ( ) {
return this[0][ !arguments.length ? 'vGet' : 'vSet' ].apply(this[0], arguments);
}

// Override the .val() method. Test every element. Is it a slider? Go to
// the slider value handling. No? Use the standard method.
// Note how $.fn.val extects 'this' to be an instance of $. For convenience,
// the above 'value' function does too.
$.fn.val = function ( ) {

// this === instanceof $

function valMethod( a ){
return a.hasClass(Classes[0]) ? value : $val;
}

var args = arguments,
first = $(this[0]);

if ( !arguments.length ) {
return valMethod(first).call(first);
}

// Return the set so it remains chainable
return this.each(function(){
valMethod($(this)).apply($(this), args);
});
};

// Remap the serialization constructor for legacy support.
/** @expose */
Expand All @@ -1246,7 +1288,4 @@ function closure ( target, options, originalOptions ){
return ( re ? rebuild : initialize ).call(this, options);
};

// Attach a classbased val handler.
$.classVal(Classes[0], 'vGet', 'vSet', false);

}( window['jQuery'] || window['Zepto'] ));
Loading

0 comments on commit cdeac7a

Please sign in to comment.