Agreed. The spec is pretty clear on this:
http://wiki.jqueryui.com/Slider#specs
"change callback: triggers when the slider has stopped moving and has a new value (even if same as previous value), via mouse(mouseup) or keyboard(keyup) or value method/option"
To me this is exactly why we have event and event.originalEvent. The slidechange event should fire anytime the slider value changes (not only when the keyboard or mouse triggered that change), and event.originalEvent allows you to detect what triggered it.
I disagree. event.originalEvent is a weak splot in the API. Scott, I agree that we shouldn't even provide it in the first place. The triggered event should have all event properties exposed that you need.
How does it work as a wrapper if our custom event has a type of 'slidechange' but was triggered by an event with a type of 'keypress' or 'mousemove'? Where would you get that original event type?
Hi,
I think the change-event should always fire, also, if the event is
triggered programmaticly. there could be bound a lot of listeners (and
not just 1 wich don´t want to listen).
I suggest an option, that will extend the ui-event-object or the jquery
´s event-wrapper object
Let me explain this with the following code:
function carouselUpdatesSlider(e, ui){
if(ui.triggeredFrom != 'fromSlider'){
$('div.slider')
.slider('moveTo', ui.value, 'fromCarousel');
}
}
function sliderUpdatesCarousel(e, ui){
if(ui.triggeredFrom != 'fromCarousel'){
$('div.carousel')
.carousel('moveTo', ui.value, 'fromSlider');
}
}
$('div.carousel')
.bind('carouselchange', carouselUpdatesSlider);
$('div.slider')
.bind('sliderchange', sliderUpdatesCarousel);
I hope it´s clear, what i mean.
On Thu, Apr 2, 2009 at 9:15 AM, Richard D. Worth <rdw...@gmail.com> wrote:How does it work as a wrapper if our custom event has a type of 'slidechange' but was triggered by an event with a type of 'keypress' or 'mousemove'? Where would you get that original event type?
Why do you need the original event type?
It should be sufficient to have access to the event properties - having to check what the original event of a custom event was is a broken way of handling things to me.
On Thu, Apr 2, 2009 at 7:32 PM, alexander farkas <a.farkas.pm@googlemail.com> wrote:
Hi,
I think the change-event should always fire, also, if the event is
triggered programmaticly. there could be bound a lot of listeners (and
not just 1 wich don´t want to listen).
I suggest an option, that will extend the ui-event-object or the jquery
´s event-wrapper object
Let me explain this with the following code:
function carouselUpdatesSlider(e, ui){
if(ui.triggeredFrom != 'fromSlider'){
$('div.slider')
.slider('moveTo', ui.value, 'fromCarousel');
}
}
function sliderUpdatesCarousel(e, ui){
if(ui.triggeredFrom != 'fromCarousel'){
$('div.carousel')
.carousel('moveTo', ui.value, 'fromSlider');
}
}
$('div.carousel')
.bind('carouselchange', carouselUpdatesSlider);
$('div.slider')
.bind('sliderchange', sliderUpdatesCarousel);
I hope it´s clear, what i mean.
I agree. I already successfully implemented that solution in other plugins, notably the selectables in the dev branch (that come with keyboard selection).
In there, it was important to provide information wether a selection was triggered through the lasso selection or by clicking/keyboard, so the ui event has a very simple boolean 'lasso', so you check for ui.lasso == true/false. This worked out really well in all tests and demos and felt very simple and clean.
I guess I changed my opinion about reintroducing the param to not fire the event again.
I therefore vote for integrating this functionality - find a smart boolean and provide it through the ui object - this, after all, is *the* place to provide extra information about the event.
No need to build in a feature, or add an option, or an additional property to ui. This is just one example, with one event, in one plugin. The point is, we don't need to worry about whether or not anyone will ever need this information, nor how to present it. It's there. And they can use it.
On Thu, Apr 2, 2009 at 8:41 AM, Richard D. Worth <rdw...@gmail.com> wrote:No need to build in a feature, or add an option, or an additional property to ui. This is just one example, with one event, in one plugin. The point is, we don't need to worry about whether or not anyone will ever need this information, nor how to present it. It's there. And they can use it.
I completely agree with Richard's entire post, but I think this final paragraph really highlights why I think event.originalEvent is so useful. We've got two developers in this thread already giving examples where they've needed this functionality and I've seen plenty of requests for this on the jquery-ui group. We already have this functionality built into all our plugins in one consistent way, I don't see any reason to add special cases for each individual plugin and then have even code to implement, test, document and support.
Except that this destroys the whole concept of custom events. Why are we firing custom events? Because we want to provide a simple, unified event to our users when an interaction in the slider happened. Now wether we're suggesting the user should then *split* this information within this event into multiple events, or wether we just forget about the whole concept of custom events - it's exactly the same result. We're back at pure, vanilla JavaScript (ok ok, jQuery).
Again - we provide custom events because users need a reliable, jquerish way to be notified when an interaction happens or has happened. While the events are related to real events, and should share key information of the original event (i.e. mouse position, keyCode etc), they should never be meant to be *containers* of other events as part of our official API.
Maybe that's the problem. I'm not 100% up-to-date with your code (ui) but the event object we provide on the core, it's always a fixed version of an event (aka a wrapper).
Maybe you shouldn't even expose the event that triggered this custom event, they're just different events.
I don't agree with the "why not expose it" kind of approach. Encapsulation is indeed a good thing and in most cases, there's a way around that doesn't require to give out any existing data to the user.
If the slider changed its value, then why does it matter how (externally) ?
Hi Richard
The first post doesn't mention originalEvent, sorry if I don't fully get this things, Scott asked to chime in and I'm doing my best :)
As for the value changing problem. I'd add another method, one that changes the value and another that calls the first one AND propagates events.
On Thu, Apr 2, 2009 at 3:38 PM, Ariel Flesler <afle...@gmail.com> wrote:Hi Richard
The first post doesn't mention originalEvent, sorry if I don't fully get this things, Scott asked to chime in and I'm doing my best :)
The first post doesn't mention originalEvent, you're right. But it points at just one example of why you might want to know how the change was triggered. I pointed out another here
http://groups.google.com/group/jquery-ui-dev/msg/35142ed7cc188ad7
There are countless others. A dialog closing because the close method was called vs. the user clicked the 'X' with the mouse vs. they pressed the ESC key, is just one more.
As for the value changing problem. I'd add another method, one that changes the value and another that calls the first one AND propagates events.
There are multiple ways a slider value can change:
- keypress (UP, DOWN, LEFT, RIGHT, HOME, END)
- mouseup
- value option (or values option)
- value method (or values method)
Regardless of how it changes (the original source of the trigger), there need only be one event: change. This event fires any time the value changes. There's no propogation here. You shouldn't be able to change the value without this event firing. Because anyone listening to this event is interested in knowing whenever the value is changed. Only that listener knows whether they care about why or how it was changed, not the party triggering the change (whether programmatic or otherwise). That's why there should only be one event, and it's why it's a custom event. The type of that event is 'slidechange', meaning "the value of the slider changed". Inside that event callback, which has been passed the 'slidechange' event as the first parameter, it's quite useful to know what browser event (if any) originially triggered this custom event. Not only to know the type, but to actually have the event, along with all its properties, which is a different set of properties than the 'slidechange' event.