Code Monkey home page Code Monkey logo

angular-slider's Introduction

DEPRECATED

I am unable to maintain or update this repository any more. If you know more well maintained forks, let me know so I can link it here.

PopSugar: https://github.com/PopSugar/angular-slider (updated to work in current Angular version)

Venturocket: http://github.com/venturocket/angular-slider (highly modified)

RzSlider: https://github.com/rzajac/angularjs-slider (rewritten in JavaScript)

angular-slider

Slider directive implementation for AngularJS, without jQuery dependencies. Requires AngularJS v1.1.4 or higher (optional isolate scope bindings support).

Example:

<ul>
    <li ng-repeat="item in items">
        <p>Name: {{item.name}}</p>
        <p>Cost: {{item.cost}}</p> 
        <slider floor="100" ceiling="1000" step="50" precision="2" ng-model="item.cost"></slider>
    </li>
</ul>

Range:

<ul>
    <li ng-repeat="position in positions">
        <p>Name: {{position.name}}</p>
        <p>Minimum Age: {{position.minAge}}</p> 
        <p>Maximum Age: {{position.maxAge}}</p> 
        <slider floor="10" ceiling="60" ng-model-low="position.minAge" ng-model-high="position.maxAge"></slider>
    </li>
</ul>

Formatting:

Raw data can be formatted as text using the translate attribute. In your controller:

$scope.currencyFormatting = function(value) { return value.toString() + " $" }

And your HTML:

<slider floor="100" ceiling="1000" step="50" precision="2" ng-model="item.cost" translate="currencyFormatting"></slider>

Usage:

Make sure to load AngularJS first, and then angular-slider.js. Also include the related angular-slider.css.

The module is named uiSlider. To enable it, you must simply list it as a dependency in your app. Example:

var app = angular.module('app', ['uiSlider', 'ngResource', ...]);

You can then use it in your templates like so:

<html ng-app='app'>
    ...
    <body>
        ...
        <slider ...></slider>
    </body>
</html>

Known issues:

  1. When applying filters or orders within an ng-repeat directive, the element can abruptly change its position when the value attached to the slider causes a filter to activate or the order to change. Example: In the above snippet, it would be a very bad idea to order the list by item.cost.

Roadmap:

  1. Touch events support
  2. Smooth curve heterogeneity
  3. Filters support

License: MIT

angular-slider's People

Contributors

prajwalkman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-slider's Issues

values as strings brakes input[type='number']

from what i can tell the slider sets the model value as string not as number, this breaks ngModel for input[type='number']
example:

<label for="min_price">Min: <input type="number" step="50" min="0" name="min_price" id="min_price" ng-model="min_price"></label>
<label for="max_price">Max: <input type="number" step="50" min="0" name="max_price" id="max_price" ng-model="max_price"></label>
<slider floor="0" ceiling="2000" step="50" ng-model-low="min_price" ng-model-high="max_price"></slider>

in the prev example the inputs appear as blank and dose not work at all

mouse up handler in scope[in Controller.js]

we need a function in scope[in Controller.js] to be called on mouse up [from angular-slider.js] so that we can send a request to server, but as of now we are sending request on slide[mouse move].. which causes several request and it overloads server

avoid namespace conflicts

As you can imagine, the translate attribute is used by several translate modules for angular-js, making this directive incompatible to them. How about giving it (and maybe all other directive attributes) a slider-prefix?

Have slider only fill in one way

Say you want to go from 0 to X and have it color blue everything up to X

Here's the hacky way I'm doing it now in CSS, it would be cool if it was a feature

slderHolder is a div the slider is in

.sliderHolder>.pointer {
display:none;
}
.sliderHolder>.pointer~.pointer {
display:inline-block;
}

Touch doesn't work when jQuery is loaded

If jQuery is loaded, then AngularJS uses jQuery but it seems that the Event object for jQuery doesn't provide a touches property, making the touch handling fail for angular-slider.

Logarithmic scale

There are cases where a logarithmic scale makes a lot of sense, e.g. price filter on a comparison site - where high definition is required at the low-end and not in the high-end.

Wrong pointer //range

Steps to reproduce.

  1. set max pointer to maximum value
  2. set low pointer to maximum value
  3. move one slider to lower value.
  4. Moving max pointer occurs moving of low poniter

Checked only in Chrome.Version 29.0.1547.76 m

Make `translate` more flexible

I would find it helpful if translate had the option of being model-aware in addition to being passed the 'dumb' numerical value of the slider.

For instance, with

$scope.obj = { cost: 25.00, units: 12345 } 
// where obj.units is the `ng-model`

I'd like translate to be able to resolve obj.cost * obj.units.

At the moment I have the following work around:

    $scope.translate = function(obj) {
        return function(val) {
            return "$" + (obj.cost * val);
        };
    };
<slider ng-model="obj.units" translate="translate(obj)" ...>

which works because of how translate is invoked.

Full support for this feature I think would expand the usefulness of this directive.

Thanks for your work.

Browser Support

I'm seeing that the demo doesn't work in IE8, is that right? Is there a plan to support it at some point?

How do I change handle color programically ?

I want to change the color of the handle programmatically. the CSS class is

CaptchaSlider .slider-handle {

background: red;

}

I would like to do this via jQuery like you changed the div RGB in your example.

$('#RGB').css('background' rgb(255,255,255));

Thanks,

Warren

Script crashes if clientX === 0 without touch screen

On row 262: eventX = event.clientX || event.touches[0].clientX;

When event.clientX === 0, it is considered false, and event.touches[0] are used instead. However, on a desktop, event.touches don't exist, so the script crashes with the message: "Uncaught TypeError: Cannot read property '0' of undefined".

add limitations to ranges

Can you please advise how can i added limitation to the slider
for example i have range slider that i don't want the user can choose value lower than 5.
i handled the left and the right parts, but can't handle the center part
image

but the center is not working when i get into 5 it stopped than you can pull and get to zero

image

this is the code i added to:

var centrer_range_left = scope[refHigh] - newValue;
var centrer_range_right = newValue - scope[refLow];

              if (newValue < 5 || newValue > 95 || newPercent >95 || newPercent < 5 || Math.abs(centrer_range_right - centrer_range_left) < 4 || Math.abs(centrer_range_right - centrer_range_left) == 0 )
              {
                return;
              }

Handlers do not get initial position ( fullBar.width == 0 at post-compile)

I am trying to use the directive in a plain html (only element is the slider), and after the scope 'settles' (rendering finishes), the two handles are in 0 position. It turns out that the value for the fullBar, on which the rest of the positioning is based has a value of 0.
For me it makes sense, since the dom rendering should not be done at the point of post-link (should it?), but i was wondering what container/wrapper style makes the examples actually work?!

Puzzled...

edit: it turns out the use of ng-repeat is the culprit...if i use one item, it has correct width (sadly that is no option for me right now, i need it bound to an array of items).

edit2: looking at the example source code i see that the slider is not used on the page as in the example, eg. not inside an ng-repeat directive...Is this a known issue?

AngularJS 1.2 - ignoring ng-bind-html-unsafe?

Hi,

I am trying your slider component in angular 1.2.
Unfortunately floor, ceiling and translate values are missing.

 <span ng-bind-html-unsafe="translate({value: floor})" class="bubble limit" style="opacity: 1;"></span>
  <span ng-bind-html-unsafe="translate({value: ceiling})" class="bubble limit" style="left: 497px; opacity: 1;"></span>
  <span class="bubble" ng-bind-html-unsafe="translate({value: ngModel})" style="left: 141px;"></span></slider>

Am i missing something here?

Kind Regards
Kay

No labels above the slider (on current value)

Hello.

I'm using the angular-slider and I have successfully made it work with my controller. However I'm not getting any labels above the slider as in the examples. I have followed the examples but without success.

screen shot 2013-10-29 at 11 02 40

HTML:

<slider ceiling='100' floor='0' ng-model-high='report.columns[$index].max' ng-model-low='report.columns[$index].min' precision='1' step='5'></slider>

Set Max range dynamically.

I need to set max range dynamically. I am using slider five times in a page to filter table data. Data is coming from json and slider is working fine. I need to set the max range dynamically.

I have added static values in ceiling like this "ceiling="1000" and also set "upper_Range = 1000" in js file. I am trying to add these values dynamically so if the data having value in between 10 then max value need to be 10 and if data having value in between 100 then max value need to 100.

How can I do this. Please suggest.

Cannot start it

Hello! I'm new to angular. Made some tutorials here and there.
And I couldnt run slider in my project.
I included mi.js file before angular. Somehow i found out that i have to add 'uiSlider' to my app module dependencies (near my 'ngResource'). Then I added <slider...> to my template and got error in console
Error: Unknown provider: nProvider <- n <- sliderDirective
Now i dont know what to do :( Could you help me? And maybe add "Usage" section to README.md? Thank you!

Does not work with ng-show

When the slider is wrapped with-in an element that has an ng-show defaulted to false, the slider does not appear correctly initially.

Code example:
javascript:

var app = angular.module('practice', ['uiSlider']);

app.controller('sliderCtrl', function($scope) {
    $scope.name= "Temp";
    $scope.lowAge= 30;
    $scope.highAge= 45;
});

html:

<body ng-app="practice">
    <div ng-controller="sliderCtrl">
    Slider wanted?<input type="checkbox" ng-model="wantSlider" />
        <span ng-show="wantSlider">
            <p>Name: {{name}}</p>
                <p>Minimum Age: {{lowAge}}</p> 
                <p>Maximum Age: {{highAge}}</p> 
                 <slider floor="10" ceiling="60" ng-model-low="lowAge"
                            ng-model-high="highAge"></slider>
        </span>
       </div>
    <script src="app.js"></script>
</body>

With this code block the initial pointers will both be placed to the far left. Once I attempt to drag the pointers the slider is displayed correctly.
This bug has been verified on Chromium Version 28.0.1500.71 Ubuntu 12.04 (28.0.1500.71-0ubuntu1.12.04.1) and Firefox version 23.0 for Ubuntu 12.04

Option for vertical orientation?

Nice work! I like that there's no dependency on jQuery too.

If you're open to feature requests, the only thing "more" that I'd want in a slider is the ability to turn it vertical. What do you think?

No slider showing...

I tried using this for this ng-repeat:

<div ng-repeat="image in site.images | startFrom:currentPage*pageSize | limitTo:pageSize">
  <img class="siteImage"  width="{{image.width}}" height="{{image.height}}" ng-src="/images/{{site.name}}/{{image.file}}" ng-click="loadViewport(image._id, site.name, image.file, image.width, image.height)" />
  <slider floor="100" ceiling="{{image.height}}" step="1" precision="1" ng-model="image.height"></slider>
</div>

Everything is showing except the slider... all it renders for the slider is:

<slider floor="100" ceiling="384" step="1" precision="1" ng-model="image.height" class="ng-pristine ng-valid"></slider>

Range value error when max = min?

In range slider, when set max = min then can not set max value. In your example demo. Set min = 60 and max = 60 then can not re set max =50?
Thanks!

Custom labels possible?

Is it possible to have custom labels on the slider? I imagine I can pass an array of labels that can be used to label points on the slider.

Is this possible now? Thanks.

suppress slider navigation

Hi guys!
I'd like to disable the slider depending on a scope parameter, for example to suppress slider interaction referring selection. Is there a generic way to disable the interactivity of the slider directive? Or do I have to fix that within the angular-slider plugin? Thanks!

No text value on slider

Hi,

I'm using the slider with angularjs and Twitter Bootstrap 3.0, but I have not text value on it !

capture du 2014-01-09 10 24 05

this is mys code :

<div class="col-sm-2">Word Candidates :</div>
<div class="col-sm-10">
    <slider floor="0" ceiling="19" step="1" precision="1" ng-model="wordcandidates"></slider>
</div>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.