Skip to content

Instantly share code, notes, and snippets.

@ixth
Created April 16, 2012 13:16
Show Gist options
  • Save ixth/2398704 to your computer and use it in GitHub Desktop.
Save ixth/2398704 to your computer and use it in GitHub Desktop.
jQuery.UI extended slider widget
(function ($) {
$.widget('ui.tooltipSlider', $.ui.slider, {
options: {
'formatTooltip': function (value) {
return value;
}
},
_create: function () {
$.ui.slider.prototype._create.apply(this, arguments);
this._formatTooltip = this.options.formatTooltip;
this.tooltips = $(document.createElement('span')).addClass('ui-slider-tooltip').appendTo(this.handles);
},
_setOption: function (key, value) {
$.ui.slider.prototype._setOption.apply(this, arguments);
if (key === 'formatTooltip') {
this._formatTooltip = value;
}
},
_refreshValue: function () {
var self = this;
$.ui.slider.prototype._refreshValue.apply(this, arguments);
if (this.tooltips && this.options.values && this.options.values.length ) {
self.tooltips.each(function(i, j) {
this.innerHTML = self._formatTooltip(self.values(i));
});
}
}
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment