in partnership with mediatemple

Ticket #984 (new enhancement)

Opened 3 weeks ago

Slider.js : optionnal onChange gets fired when the set method is called, even when the value has not changed

Reported by: challet Owned by:
Type: enhancement Priority: minor
Milestone: Mootools version 1.2 Component: Plugins
Keywords: Slider, onChange Cc:

Description

In Slider.js, the onChange event is fired after calling the set() method (via checkStep()).

I needed to fire the event even if the step value remains the same, but I can't do it from the outside without the risk of calling twice the onChange event.

So I patched Slider.js this way :

set: function(step,forceChange){
	if (!((this.range > 0) ^ (step < this.min))) step = this.min;
	if (!((this.range > 0) ^ (step > this.max))) step = this.max;
		
	this.step = Math.round(step);
	this.checkStep($chk(forceChange) && forceChange);
	this.end();
	this.fireEvent('onTick', this.toPosition(this.step));
	return this;
},


checkStep: function(forceChange){
	if (this.previousChange != this.step || forceChange){
		this.previousChange = this.step;
		this.fireEvent('onChange', this.step);
	}
}

I guess it might be useful for other people.

Note: See TracTickets for help on using tickets.