Skip to content

Instantly share code, notes, and snippets.

@drjonnicholson
Created February 14, 2018 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drjonnicholson/b6f20b6de84bf9bfd6f8f76ce22e01e0 to your computer and use it in GitHub Desktop.
Save drjonnicholson/b6f20b6de84bf9bfd6f8f76ce22e01e0 to your computer and use it in GitHub Desktop.
/**
* Slider wrapper.
*
* @author Htmlstream
* @version 1.0
*
*/
;
(function ($) {
'use strict';
$.HSCore.components.HSSlider = {
/**
*
*
* @var Object _baseConfig
*/
_baseConfig: {
dateFormat: 'dd.mm.yy',
prevText: '<i class="fa fa-angle-left"></i>',
nextText: '<i class="fa fa-angle-right"></i>'
},
/**
*
*
* @var jQuery pageCollection
*/
pageCollection: $(),
/**
* Initialization of Slider wrapper.
*
* @param String selector (optional)
* @param Object config (optional)
*
* @return jQuery pageCollection - collection of initialized items.
*/
init: function (selector, config) {
this.collection = selector && $(selector).length ? $(selector) : $();
if (!$(selector).length) return;
this.config = config && $.isPlainObject(config) ?
$.extend({}, this._baseConfig, config) : this._baseConfig;
this.config.itemSelector = selector;
this.initSlider();
return this.pageCollection;
},
initSlider: function () {
//Variables
var $self = this,
config = $self.config,
collection = $self.pageCollection;
//Actions
this.collection.each(function (i, el) {
//Variables
var $this = $(el),
$resultContainer = $this.data('result-container'),
rangeBoolean = $this.data('range'),
minVal = $this.data('min'),
maxVal = $this.data('max'),
defaultVal = $this.data('default'),
orientation = $this.data('orientation'),
step = $this.data('step');
$this.slider({
range: rangeBoolean == 1 ? true : 'min',
min: minVal,
max: maxVal,
orientation: orientation ? orientation : 'horizontal',
step: step ? step : 1,
values: rangeBoolean == 1 ? JSON.parse('[' + defaultVal + ']') : false,
value: defaultVal ? defaultVal : false,
slide: function (event, ui) {
if (rangeBoolean == 1) {
$('#' + $resultContainer).text(ui.values[0] + ' - ' + ui.values[1]);
} else {
$('#' + $resultContainer).text(ui.value);
}
}
});
if (rangeBoolean == 1) {
$('#' + $resultContainer).text($this.slider('values', 0) + ' - ' + $this.slider('values', 1));
}
//Actions
collection = collection.add($this);
});
}
};
})(jQuery);
<div class="u-slider-v1" data-orientation="vertical" data-step="1" data-default="1" data-min="0" data-max="10" style="height:200px;"></div>
.u-slider-v1.ui-slider-vertical .ui-slider-handle {
top: auto !important;
left: 0.4em !important;
}
@webDeveloper67
Copy link

webDeveloper67 commented Apr 8, 2019

Hello
I'm new to programming. Could you please provide some information about what the above code does or how we can use it in out code?
Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment