File Editor
Directories:
.. (Back)
Files:
class-sinatra-customizer-control-range.php
range.css
range.js
range.min.css
range.min.js
Create New File
Create
Edit File: range.min.js
!function($){"use strict";wp.customize.controlConstructor["sinatra-range"]=wp.customize.Control.extend({ready:function(){var control=this,setting=control.setting.get();control.container.find(".sinatra-range-wrapper").rangeControl({id:control.params.id,unit:control.params.unit,value:setting,responsive:control.params.responsive,change:function(){control.save()}})},save:function(){var value={},devices=this.params.responsive;if(!1===devices||void 0===devices||0==devices.length)value.value=parseFloat(this.container.find(".sinatra-range-input").val());else for(var device in devices)value[device]=parseFloat(this.container.find(".control-responsive."+device+" .sinatra-range-input").val());this.container.find(".sinatra-control-unit").length&&(value.unit=this.container.find(".sinatra-control-unit input:checked").val()),this.setting.set(value)}}),function($,undef){var RangeControl;RangeControl={options:{id:!1,option:!1,responsive:!1,unit:!1,value:!1,change:!1},_create:function(){var el=this.element;this.unit=el.find(".sinatra-control-wrap").attr("data-unit"),this._addListeners(),"object"==typeof this.options.responsive&&this._initResponsiveControls(),!1!==this.options.unit&&this._initUnit()},_addListeners:function(){var range,input,value,newVal,self=this;self.element.change((function(event){$.isFunction(self.options.change)&&self.options.change.call(this,event)})),self.element.on("keyup input paste",".sinatra-range-input",(function(){self._autocorrectSlider($(this))})).on("focusout",(function(){self._autocorrectSlider($(this))})),self.element.on("click","input[type=range]",(function(){range=$(this),input=range.parent().children(".sinatra-range-input"),newVal=range.val(),value!==newVal&&(value=newVal,input.val(newVal).change())})),self.element.on("mousedown","input[type=range]",(function(){range=$(this),input=range.parent().children(".sinatra-range-input"),range.mousemove((function(){newVal=range.val(),value!==newVal&&(value=newVal,input.val(newVal).change())}))})),self.element.on("mouseup","input[type=range]",(function(){$(this).off("mousemove")})),self.element.on("click",".sinatra-reset-range",(function(){var $el;self.element.find(".sinatra-reset-range").each((function(index,el){$el=$(el),self.unit=$el.data("reset_unit"),$el.closest(".sinatra-range-wrapper").find('.sinatra-control-unit input[type="radio"][value="'+$el.data("reset_unit")+'"]').click(),$el.siblings("input").val($el.data("reset_value"))})),self.element.change()})),self.element.on("click",".sinatra-control-unit input",(function(){var $unit=$(this);self.element.find('.sinatra-control-wrap input[type="range"]').each((function(index,el){$(this).attr("min",$unit.data("min")),$(this).attr("max",$unit.data("max")),$(this).attr("step",$unit.data("step"))})),"px"!==$unit.val()||"rem"!==self.unit&&"em"!==self.unit?"rem"!==$unit.val()&&"em"!==$unit.val()||"px"!==self.unit||(self.element.find("input.sinatra-range-input").each((function(index,el){$(el).val($(el).val()/16),self._autocorrectSlider($(el))})),self.unit=$unit.val()):(self.element.find("input.sinatra-range-input").each((function(index,el){$(el).val(Math.floor(16*$(el).val())),self._autocorrectSlider($(el))})),self.unit=$unit.val())}))},_autocorrectSlider:function(range_input){var range=range_input.parent().find('input[type="range"]'),value=parseFloat(range_input.val()),step=parseFloat(range_input.attr("step")),min=parseFloat(range_input.attr("min")),max=parseFloat(range_input.attr("max"));isNaN(value)?range.change():(step>=1&&value%1!=0&&(value=Math.round(value),range_input.val(value),range.val(value).change()),value>max&&(range_input.val(max),range.val(max).change()),value<min&&(range_input.val(min),range.val(min).change()),range.val(value).change())},_initResponsiveControls:function(){var el=this.element;el.find(".sinatra-control-wrap");if(el.addClass("sinatra-control-responsive"),el.find(".customize-control-title").length){var $switcher=$('<ul class="sinatra-responsive-switchers"></ul>');for(var device in this.options.responsive)$switcher.append('<li class="'+device+'"><span class="preview-'+device+'" data-device="'+device+'"><span class="sinatra-tooltip small-tooltip">'+device+'</span><i class="'+this.options.responsive[device].icon+'"></i></span></li>');el.find(".customize-control-title").append($switcher)}},_initUnit:function(){var wrap=this.element.find(".sinatra-control-wrap"),template=wp.template("sinatra-control-unit"),data={unit:this.options.unit,id:this.options.id,option:this.options.option,selected:wrap.attr("data-unit")};"object"==typeof this.options.unit?($(template(data)).insertBefore(wrap),void 0!==this.options.value.unit&&wrap.parent().find("#"+this.options.id+"-"+this.options.value.unit+"-unit").click()):"string"==typeof this.options.unit&&$('<span class="sinatra-range-unit">'+this.options.unit+"</span>").insertAfter(wrap.find(".sinatra-range-input")),wrap.parent().find(".sinatra-control-unit input:checked").click()}},$.widget("sinatra.rangeControl",RangeControl)}(jQuery)}(jQuery);
Save Changes
Rename File
Rename