Skip to main content

Search and Top Navigation

#2501 closed enhancement (fixed)

Opened March 13, 2008 03:16PM UTC

Closed March 17, 2008 06:07PM UTC

Last modified February 26, 2009 12:00PM UTC

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:
Description

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(this.properties[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[this.properties[index]] = parseInt($(this.handle[index]).css(this.properties[index]),10) + this.handleSize(index)/2;
	return result;
},

Could then be used like this:

.css(this.cssproperties(0))
.css(this.cssproperties(1))
Attachments (0)
Change History (5)

Changed March 14, 2008 02:53PM UTC by paul comment:1

owner: paulbraeker

Changed March 17, 2008 05:34PM UTC by joern comment:2

owner: braekerjoern

Changed March 17, 2008 06:07PM UTC by joern comment:3

resolution: → fixed
status: newclosed

Mostly implemented in [5065] and previous revisions.

Changed May 24, 2008 03:39AM UTC by comment:4

milestone: 1.2.4

Milestone 1.2.4 deleted

Changed February 26, 2009 12:00PM UTC by paul comment:5

milestone: → 1.5