Opened 15 years ago

Closed 15 years ago

Last modified 14 years ago

#2501 closed enhancement (fixed)

ui.slider - Refactoring suggestions

Reported by: joern Owned by: joern
Priority: major Milestone: 1.5
Component: ui.core Version: 1.2.3
Keywords: Cc:
Blocked by: Blocking:


ui.slider currently contains quite a bit of duplicated code. A few suggestions for refactorings:

drag and moveTo contain a lot of the same code, eg. this is in both:

if(o.stepping) {
	var value = this.convertValue(modifier);
	value = Math.round(value / o.stepping) * o.stepping;
	modifier = this.translateValue(value);	

if(this.rangeElement) {
	if(this.currentHandle[0] == this.handle[0] && modifier >= this.translateValue(this.value(1))) modifier = this.translateValue(this.value(1));
	if(this.currentHandle[0] == this.handle[1] && modifier <= this.translateValue(this.value(0))) modifier = this.translateValue(this.value(0));

this.currentHandle.css([0], modifier);
if(this.rangeElement) this.updateRange();

Should be extracted to a single method.

Both value() and handleSize() contain code to find a handle:

$(handle != undefined ? this.handle[handle] || handle : this.currentHandle)

That could be extracted as well.

createRange and updateRange contain the same code to update CSS. createRange could use updateRange to avoid the duplication.

Both could use a method that returns an object with the necessary CSS properties, passing the index as an argument, something like this:

cssproperties: function(index) {
	var result = {};
	result[[index]] = parseInt($(this.handle[index]).css([index]),10) + this.handleSize(index)/2;
	return result;

Could then be used like this:


Change History (5)

comment:1 Changed 15 years ago by paul

Owner: changed from paul to braeker

comment:2 Changed 15 years ago by joern

Owner: changed from braeker to joern

comment:3 Changed 15 years ago by joern

Resolution: fixed
Status: newclosed

Mostly implemented in [5065] and previous revisions.

comment:4 Changed 15 years ago by (none)

Milestone: 1.2.4

Milestone 1.2.4 deleted

comment:5 Changed 14 years ago by paul

Milestone: 1.5
Note: See TracTickets for help on using tickets.