Comments (14)
I'd like to second this request. What I suggest is a new attribute such as:
<slider on-end="MyFunction()">
I have a function that runs an AJAX call when the slider is used but I don't want the AJAX call running 20 times while the user is sliding. I only want it to run once when the user finishes sliding. If you could add an event attribute for this, we could run our code at the end of the event to process the ng-model value.
Thanks!
from angular-slider.
I agree this would be a good addition, maybe give it a wait-time attribute that will say if nothing else changes for a certain amount of milliseconds, go ahead and perform an action.
One possible thing you could do for now is watch your models you assigned and set a timeout to only execute if changes don't occur for a certain amount of time.
from angular-slider.
This should be an easy addition. The author already has an "onEnd()" event in the code. He just needs to include a couple lines of code to check if the "on-end" attribute exists, and if so, just run the attached function. The onEnd() event only runs when the user has lifted their finger from the slider (on a touch device) or has released the mouse button.
from angular-slider.
(bump)
Just came here to say this would be a great addition as well.
from angular-slider.
It is rather easy to achieve this without code modification. venturocket-angular-slider uses ngTouch for support both mouse/touchscreen so its $swipe service could be used as follows:
$timeout(function() {
$swipe.bind($('.input.low',iElement),{
//Scroll end event handler. See docs here: https://docs.angularjs.org/api/ngTouch/service/$swipe
end: function(event) {
//do something useful here
},
}) //$swipe.bind;
});
from angular-slider.
Another way to do it for now, similar to what @bjodasso said - watch the model:
$scope.$watch("myModel", function(newVal, oldVal) {
if (newVal != oldVal) {
// do something
}
});
from angular-slider.
I was successful using the code from radiophysicist -- although I had to remove the iElement argument. I'm not sure how that was supposed to work. Can someone explain it?
The jQuery class selector $('.input.low') works.
I was not successful using the method systemride describes. The newVal and oldVal were always different, so it always executed that "do something" code.
Thanks!
from angular-slider.
What about how it works, see docs here: https://docs.angularjs.org/api/ngTouch/service/$swipe
The code was taken from my custom directive controller so iElement was a reference to directive element. You could rewrite the selector as you need.
Also there are ngSwipeLeft and ngSwipeRight directives in the ngTouch module, it is probably possible to use them without messing with $swipe at all.
from angular-slider.
In addition it is worth to stop event propagation and to handle the case when swipe ends outside the widget. The code now may look as follows:
$timeout(function() {
//See docs here: https://docs.angularjs.org/api/ngTouch/service/$swipe
$swipe.bind(element),{
//Swipe start event handler
start: function(coords,event) {
//Prevent event propagation to parent elements
event.stopPropagation();
},
//Swipe end event
end: function() {
//Do something useful with final value here
},
//Swipe cancel event (for example, drag finished outside the widget)
cancel: function() {
//Reset ngModel value of widget to initial value here
}
}) //$swipe.bind;
});
from angular-slider.
How do you get the element in the $swipe.bind() function without depending on jquery?
from angular-slider.
To be able to specify a callback function in the same way as a translateFn:
Change the scope definition at 437 to:
scope: {
floor : '@', // the minimum possible value
ceiling : '@', // the maximum possible value
step : '@', // how wide is each step, omit or set to 0 for no steps
stepWidth : '@', // alias of step to avoid collisions
precision : '@', // how many decimal places do we care about
buffer : '@', // how close can the two knobs of a dual knob slider get?
stickiness : '@', // how sticky should the knobs feel...seriously, how did this get all sticky? gross
showSteps : '@', // show the step value bubbles?
ngModel : '=', // single knob/dual know low value binding
ngModelRange : '=', // dual knob high value binding
ngDisabled : '=', // should the slider be disabled?
ngChange : '&', // what should we do when a value is changed
translateFn : '&', // how to translate the values displayed in the bubbles
translateRangeFn : '&', // how to translate the range bubble
translateCombinedFn : '&', // how to translate the combined bubble
scaleFn : '&', // how to scale the values
inverseScaleFn : '&', // how to unscale the values
callbackFn : '&'
},
add after line 573:
// set up the callback function
if (attributes.callbackFn) {
attributes.$set('callbackFn', "" + attributes.callbackFn + "(value)");
}
Change onEnd() function at line1388 to:
function onEnd() {
// reset the offsets
stickyOffsetLow = 0;
stickyOffsetHigh = 0;
if (pointer) {
// if we have a pointer reference
// update all the elements in the DOM
setPointers();
adjustBubbles();
// the pointer is no longer active
pointer.removeClass('active');
}
if (typeof scope.callbackFn === "function") {
scope.callbackFn();
scope.$apply();
}
// reset the references
pointer = null;
ref = null;
dragRange = false;
}
from angular-slider.
I finally have a chance to revisit (and completely rewrite) the slider. My plan is to add in onEnd and onStart. Any other event hooks I should add?
from angular-slider.
Sorry - did anything ever happen regarding this issue?
from angular-slider.
Yeah, what happened with this?
from angular-slider.
Related Issues (20)
- Different styles for the pointers
- Bump angular dep to ~1.3 HOT 4
- function stepBubbles() missing from code HOT 2
- Style selected area of a single know slider HOT 1
- Extra label functionality HOT 4
- bubble.ceiling will not position correctly if parent DOM element uses a CSS transition on width
- low and high knobs coincide
- No Working on mobile HOT 4
- Max difference attribute?
- bind to a input box, cannot change the value HOT 2
- IE11 memory leak HOT 1
- Avoid very slow performance?
- Is this still active?
- Assignable ceil and floor
- Slider knob not moving with keyboard controls
- Where is the demo? HOT 7
- no demo and no CSS files
- Can be used in the 1.4.7 version of the angular
- npm publish ? HOT 1
- slider failed at display elements
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-slider.