Js range slider

Js range slider with Buttons

by Mohan Dere

HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<div class="container">
  <h1>Jquery Button Range Slider Demo</h1>
  <h2>Example #1:</h2>
  <div id="demo-1"></div>
  <div id="demo-1-result">
    <h3>Result:</h3>
    <p>Selected range: <span class="rg"></span></p>
    <p>Value at Lower Bound : <span class="lb"></span></p>
    <p>Value at Upper Bound: <span class="ub"></span></p>
  </div>
  
  <h2>Example #2:</h2>
  <div id="demo-2"></div>
  <div id="demo-2-result">
    <h3>Result:</h3>
    <p>Selected range: <span class="rg"></span></p>
    <p>Value at Lower Bound : <span class="lb"></span></p>
    <p>Value at Upper Bound: <span class="ub"></span></p>
  </div>
  
</div>

CSS

.yo-button-range-slider{
  display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */
  display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
  display: -ms-flexbox;      /* TWEENER - IE 10 */
  display: -webkit-flex;     /* NEW - Chrome */
  display: flex;
}
.yo-btn {
  padding: 4px 16px;
  border: 1px solid #e0e0e0;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.42857143;
  text-align: center;
  vertical-align: middle;
  -ms-touch-action: manipulation;
  touch-action: manipulation;
  cursor: pointer;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  border-radius: 0;
  background: #fff;
  white-space: nowrap;
}


.yo-btn:last-child {
  border-right: 1px solid #e0e0e0;
}

.touch .yo-btn{
  white-space: normal;
}


@media screen and (max-width: 767px) {
  .yo-btn {
    font-size: 12px;
  }
}

.yo-range-btn.active{
  background: lightgray;
}
.yo-range-btn:focus,
.yo-range-btn.active{
  box-shadow: none;
  outline: 0 none !important;
}

JavaScript

// the semi-colon before function invocation is a safety net against concatenated
// scripts and/or other plugins which may not be closed properly.
;( function( $, window, document, undefined ) {

	"use strict";

		// Create the defaults once
		var pluginName = "jqButtonRangeSlider",
				defaults = {
					className: "yo-button-range-slider",
	      	sliderOptions: [],
		      template: '<% for ( var i = 0; i < sliderOptions.length; i++ ) { %> <button type="button" class="yo-btn yo-range-btn" value="<%=sliderOptions[i].value%>"><%=sliderOptions[i].name%></button><% } %>'
				};

		// The actual plugin constructor
		function JqButtonRangeSlider ( element, options ) {

			this.element = element;
			// future instances of the plugin
			this.settings = $.extend( {}, defaults, options );
			this._defaults = defaults;
			this._name = pluginName;
			this.init();
		}

		// Avoid JqButtonRangeSlider.prototype conflicts
		$.extend( JqButtonRangeSlider.prototype, {

			//Micro-Templating function
			tmpl: function(str, data){
		    // Figure out if we're getting a template, or if we need to
		    // load the template - and be sure to cache the result.
		    var fn = !/\W/.test(str) ?
		      cache[str] = cache[str] ||
		        tmpl(document.getElementById(str).innerHTML) :

		      // Generate a reusable function that will serve as a template
		      // generator (and which will be cached).
		      new Function("obj",
		        "var p=[],print=function(){p.push.apply(p,arguments);};" +

		        // Introduce the data as local variables using with(){}
		        "with(obj){p.push('" +

		        // Convert the template into pure JavaScript
		        str
		          .replace(/[\r\t\n]/g, " ")
		          .split("<%").join("\t")
		          .replace(/((^|%>)[^\t]*)'/g, "$1\r")
		          .replace(/\t=(.*?)%>/g, "',$1,'")
		          .split("\t").join("');")
		          .split("%>").join("p.push('")
		          .split("\r").join("\\'") + "');}return p.join('');");

		    //...