mankz
29 Jun 2010, 11:30 AM
Here's a basic plugin which adds color to the background area between two slider handles. Only intented for use with 2 slider handles. The color is defined in the CSS but can also be updated by using the setColor method.
21173
Drop the attached folder into the examples folder of Ext 3.2.
PS. Not very well tested :)
JS:
Ext.ns('Ext.ux.slider');
Ext.ux.slider.Highlight = Ext.extend(Object, {
init: function(slider) {
this.slider = slider;
var that = this;
// Overwrite moveThumb method to update element after animated slide
if (slider.vertical) {
slider.moveThumb = function(index, v, animate) {
var thumb = this.thumbs[index],
el = thumb.el;
if (!animate || this.animate === false) {
el.setBottom(v);
} else {
el.shift({bottom: v, stopFx: true, duration:.35, callback : that.syncElementSize, scope : that});
}
}
} else {
slider.moveThumb = function(index, v, animate){
var thumb = this.thumbs[index].el;
if(!animate || this.animate === false){
thumb.setLeft(v);
}else{
thumb.shift({left: v, stopFx: true, duration:.35, callback : that.syncElementSize, scope : that});
}
};
}
slider.on({
scope : this,
afterrender : this.onAfterRender,
drag : this.syncElementSize,
dragend : this.syncElementSize,
changecomplete : this.syncElementSize,
destroy : this.destroy
});
},
onAfterRender : function(s) {
this.el = s.innerEl.createChild({
cls : 'ext-ux-slider-highlight'
});
this.syncElementSize();
},
syncElementSize : function() {
var s = this.slider;
if (s.vertical) {
var thumb1Bottom = s.thumbs[0].el.getBottom(true),
thumb2Bottom = s.thumbs[1].el.getBottom(true),
thumb1Top = s.thumbs[0].el.getTop(true),
thumb2Top = s.thumbs[1].el.getTop(true),
highlightTop = Math.min(thumb1Bottom, thumb2Bottom);
this.el.setTop(highlightTop);
this.el.setHeight(Math.max(thumb1Top, thumb2Top) - highlightTop);
} else {
var thumb1Right = s.thumbs[0].el.getRight(true),
thumb2Right = s.thumbs[1].el.getRight(true),
thumb1Left = s.thumbs[0].el.getLeft(true),
thumb2Left = s.thumbs[1].el.getLeft(true),
highlightLeft = Math.min(thumb1Right, thumb2Right);
this.el.setLeft(highlightLeft);
this.el.setWidth(Math.max(thumb1Left, thumb2Left) - highlightLeft);
}
},
destroy : function() {
this.slider.un({
scope : this,
afterrender : this.onRender,
drag : this.syncElementSize,
dragend : this.syncElementSize,
changecomplete : this.syncElementSize,
destroy : this.destroy
});
this.el.destroy();
},
setColor : function(color) {
this.el.setStyle('background-color', color);
}
});
CSS:
.ext-ux-slider-highlight {
position: absolute;
background : yellow;
overflow:hidden;
}
.x-slider-vert .ext-ux-slider-highlight {
width:6px;
left:8px;
}
.x-slider-horz .ext-ux-slider-highlight {
height:6px;
top:8px;
}
21173
Drop the attached folder into the examples folder of Ext 3.2.
PS. Not very well tested :)
JS:
Ext.ns('Ext.ux.slider');
Ext.ux.slider.Highlight = Ext.extend(Object, {
init: function(slider) {
this.slider = slider;
var that = this;
// Overwrite moveThumb method to update element after animated slide
if (slider.vertical) {
slider.moveThumb = function(index, v, animate) {
var thumb = this.thumbs[index],
el = thumb.el;
if (!animate || this.animate === false) {
el.setBottom(v);
} else {
el.shift({bottom: v, stopFx: true, duration:.35, callback : that.syncElementSize, scope : that});
}
}
} else {
slider.moveThumb = function(index, v, animate){
var thumb = this.thumbs[index].el;
if(!animate || this.animate === false){
thumb.setLeft(v);
}else{
thumb.shift({left: v, stopFx: true, duration:.35, callback : that.syncElementSize, scope : that});
}
};
}
slider.on({
scope : this,
afterrender : this.onAfterRender,
drag : this.syncElementSize,
dragend : this.syncElementSize,
changecomplete : this.syncElementSize,
destroy : this.destroy
});
},
onAfterRender : function(s) {
this.el = s.innerEl.createChild({
cls : 'ext-ux-slider-highlight'
});
this.syncElementSize();
},
syncElementSize : function() {
var s = this.slider;
if (s.vertical) {
var thumb1Bottom = s.thumbs[0].el.getBottom(true),
thumb2Bottom = s.thumbs[1].el.getBottom(true),
thumb1Top = s.thumbs[0].el.getTop(true),
thumb2Top = s.thumbs[1].el.getTop(true),
highlightTop = Math.min(thumb1Bottom, thumb2Bottom);
this.el.setTop(highlightTop);
this.el.setHeight(Math.max(thumb1Top, thumb2Top) - highlightTop);
} else {
var thumb1Right = s.thumbs[0].el.getRight(true),
thumb2Right = s.thumbs[1].el.getRight(true),
thumb1Left = s.thumbs[0].el.getLeft(true),
thumb2Left = s.thumbs[1].el.getLeft(true),
highlightLeft = Math.min(thumb1Right, thumb2Right);
this.el.setLeft(highlightLeft);
this.el.setWidth(Math.max(thumb1Left, thumb2Left) - highlightLeft);
}
},
destroy : function() {
this.slider.un({
scope : this,
afterrender : this.onRender,
drag : this.syncElementSize,
dragend : this.syncElementSize,
changecomplete : this.syncElementSize,
destroy : this.destroy
});
this.el.destroy();
},
setColor : function(color) {
this.el.setStyle('background-color', color);
}
});
CSS:
.ext-ux-slider-highlight {
position: absolute;
background : yellow;
overflow:hidden;
}
.x-slider-vert .ext-ux-slider-highlight {
width:6px;
left:8px;
}
.x-slider-horz .ext-ux-slider-highlight {
height:6px;
top:8px;
}