File Editor
Directories:
.. (Back)
Files:
background.css
background.js
background.min.css
background.min.js
class-sinatra-customizer-control-background.php
Create New File
Create
Edit File: background.min.js
!function($){wp.customize.controlConstructor["sinatra-background"]=wp.customize.Control.extend({ready:function(){"use strict";var range,range_input,sinatra_range_input_number_timeout,control=this,value=control.setting._value;control.container.find(".background-image-advanced").hide(),control.container.on("change",".background-repeat select",(function(){control.saveValue("background-repeat",$(this).val())})),control.container.on("change click",".background-size input",(function(){control.saveValue("background-size",$(this).val())})),control.container.on("change click",".background-attachment input",(function(){control.saveValue("background-attachment",$(this).val())})),control.container.on("click",".background-image-upload-button",(function(e){var image=wp.media({multiple:!1,title:control.params.l10n.select_image,button:{text:control.params.l10n.use_image}}).open().on("select",(function(){var previewImage,imageUrl,imageID,preview,removeButton,uploadedImageJSON=image.state().get("selection").first().toJSON();previewImage=_.isUndefined(uploadedImageJSON.sizes)?uploadedImageJSON.url:_.isUndefined(uploadedImageJSON.sizes.medium)?_.isUndefined(uploadedImageJSON.sizes.thumbnail)?_.isUndefined(uploadedImageJSON.sizes.full)?uploadedImageJSON.url:uploadedImageJSON.sizes.full.url:uploadedImageJSON.sizes.thumbnail.url:uploadedImageJSON.sizes.medium.url,imageUrl=uploadedImageJSON.url,imageID=uploadedImageJSON.id,uploadedImageJSON.width,uploadedImageJSON.height,""!==imageUrl&&(control.container.find(".background-image-advanced").show(),control.container.find(".advanced-settings").removeClass("hidden").addClass("up")),control.saveValue("background-image",imageUrl),control.saveValue("background-image-id",imageID),preview=control.container.find(".placeholder, .thumbnail"),removeButton=control.container.find(".background-image-upload-remove-button"),preview.length&&preview.removeClass().addClass("thumbnail thumbnail-image").html('<img src="'+previewImage+'" alt="" />'),removeButton.length&&removeButton.show()}));e.preventDefault()})),control.container.on("click",".background-image-upload-remove-button",(function(e){var preview,removeButton;e.preventDefault(),control.saveValue("background-image",""),control.saveValue("background-image-id",""),preview=control.container.find(".placeholder, .thumbnail"),removeButton=control.container.find(".background-image-upload-remove-button"),control.container.find(".background-image-advanced").hide(),control.container.find(".advanced-settings").addClass("hidden").removeClass("up"),preview.length&&preview.removeClass().addClass("placeholder").html(control.params.l10n.placeholder),removeButton.length&&removeButton.hide()})),control.container.on("click",".advanced-settings",(function(e){$(this).toggleClass("up"),control.container.find(".background-image-advanced").toggle()})),control.container.find("input.sinatra-range-input").on("change keyup",(function(){control.autocorrect_range_input_number($(this),1e3,sinatra_range_input_number_timeout)})).on("focusout",(function(){control.autocorrect_range_input_number($(this),0,sinatra_range_input_number_timeout)})),control.container.find("input[type=range]").on("mousedown",(function(){range=$(this),range_input=range.parent().children(".sinatra-range-input"),value=range.attr("value"),range_input.val(value),range.mousemove((function(){value=range.attr("value"),range_input.val(value),clearTimeout(sinatra_range_input_number_timeout),sinatra_range_input_number_timeout=setTimeout((function(){control.saveValue(range.data("key"),value)}),25)}))}))},saveValue:function(property,value){var val=this.setting.get();value!==(val=val||{})[property]&&((val=JSON.parse(JSON.stringify(val)))[property]=value,this.setting.set(val))},autocorrect_range_input_number:function(input_number,timeout){var range_input=input_number,range=range_input.parent().find('input[type="range"]'),value=parseFloat(range_input.val()),reset=parseFloat(range.find(".sinatra-reset-range").attr("data-reset_value")),step=parseFloat(range_input.attr("step")),min=parseFloat(range_input.attr("min")),max=parseFloat(range_input.attr("max"));clearTimeout(timeout),timeout=setTimeout((function(){if(isNaN(value))return range_input.val(reset),void range.val(reset).trigger("change");step>=1&&value%1!=0&&(value=Math.round(value),range_input.val(value),range.val(value).trigger("change")),value>max&&(range_input.val(max),range.val(max).trigger("change")),value<min&&(range_input.val(min),range.val(min).trigger("change"))}),timeout),range.val(value).trigger("change"),this.saveValue(range.data("key"),value)}})}(jQuery);
Save Changes
Rename File
Rename