Created
February 14, 2018 09:37
-
-
Save drjonnicholson/b6f20b6de84bf9bfd6f8f76ce22e01e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="u-slider-v1" data-orientation="vertical" data-step="1" data-default="1" data-min="0" data-max="10" style="height:200px;"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.u-slider-v1.ui-slider-vertical .ui-slider-handle { | |
top: auto !important; | |
left: 0.4em !important; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.