freqdec / fd-slider

An Unobtrusive Accessible Slider script that can also be used as an HTML5 Input Range polyfill solution
Other
264 stars 55 forks source link

Wiki AngularJs binding sample #42

Open heralight opened 11 years ago

heralight commented 11 years ago

A proposal to add to wiki or readme: To use fd-slider with AngularJs by a directive:

  .directive('fdSlider', ["$parse", function ($parse) {
        return function (scope, elm, attrs) {
            var scaleStr = attrs.scale || "{}";
            var scale = $.parseJSON(scaleStr);
            if ("fdSlider" in window) {
                fdSlider.createSlider({
                    // Associate an input
                    inp: elm[0],
                    // Declare a step
                    step: attrs.step || 1,
                    // Declare a maxStep (for keyboard users)
                    maxStep: attrs.step || 1,
                    // Min value
                    min: attrs.min || 1,
                    // Max value
                    max: attrs.max || 100,
                    // Define a scale (multiple points supported, I'm just using one for the
                    // demo)
                    scale: scale,
                    callbacks : {
                        "change": [function(inp) {
                            scope.$apply(attrs.sliderModel + "=" + inp.value);
                        }]
                    },
                    // Use the "jump to click point" animation
                    animation: "jump"
                });
            }
        };
    }]);

and a html sample:

 <input type="number" step="1" min="10" maxStep="100" max="30000"
                        scale='{"25": "10","50": "100","75": "1000","85": "3000","90": "10000"}'
                                slider-model="myScopeModel" fd-slider="" ng-model="myScopeModel"></div>

And thank you very much for your excellent plugin.

Alexandre Richonnier